1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """Realize a trapezoid-shaped fuzzy set."""
20
21 __revision__ = "$Id: Trapez.py,v 1.19 2010-10-29 19:24:41 rliebscher Exp $"
22
23
24 from fuzzy.set.Polygon import Polygon
25 from fuzzy.utils import prop
26 from fuzzy.Exception import FuzzyException
29 r"""
30 Realize a trapezoid-shaped fuzzy set::
31 _____ _____ y_max
32 / \
33 /| |\
34 / | | \
35 / | | \
36 _/ | | \_ y_min
37 | m1 m2 |
38 | | | |
39 alpha| |beta
40
41 See also U{http://pyfuzzy.sourceforge.net/demo/set/Trapez.png}
42 """
43
44 - def __init__(self, m1=-0.5, m2=0.5, alpha=0.5, beta=0.5, y_max=1.0, y_min=0.0):
45 """
46 Initialize a trapezoid-shaped fuzzy set.
47
48 @param y_max: y-value at top of the trapezoid (1.0)
49 @param y_min: y-value outside the trapezoid (0.0)
50 @param m1: x-value of left top of trapezoid (-0.5)
51 @param m2: x-value of right top of trapezoid (0.5)
52 @param alpha: distance of left corner to m1 (0.5)
53 @param beta: distance of right corner to m2 (0.5)
54 """
55 super(Trapez, self).__init__()
56 self._y_max = float(y_max)
57 self._y_min = float(y_min)
58 self._m1 = float(m1)
59 self._m2 = float(m2)
60 self._alpha = float(alpha)
61 self._beta = float(beta)
62 self._update()
63
64
65 @prop
67 """y-value at top of the trapezoid
68 @type: float"""
69 def fget(self):
70 return self._y_max
71 def fset(self, value):
72 self._y_max = float(value)
73 self._update()
74 return locals()
75
76
77 @prop
79 """y-value outside the trapezoid
80 @type: float"""
81 def fget(self):
82 return self._y_min
83 def fset(self, value):
84 self._y_min = float(value)
85 self._update()
86 return locals()
87
88
89 @prop
91 """x-value of left top of trapezoid
92 @type: float"""
93 def fget(self):
94 return self._m1
95 def fset(self, value):
96 self._m1 = float(value)
97 self._update()
98 return locals()
99
100
101 @prop
103 """x-value of right top of trapezoid
104 @type: float"""
105 def fget(self):
106 return self._m2
107 def fset(self, value):
108 self._m2 = float(value)
109 self._update()
110 return locals()
111
112
113 @prop
115 """distance of left corner to m1
116 @type: float"""
117 def fget(self):
118 return self._alpha
119 def fset(self, value):
120 self._alpha = float(value)
121 self._update()
122 return locals()
123
124
125 @prop
127 """distance of right corner to m2
128 @type: float"""
129 def fget(self):
130 return self._beta
131 def fset(self, value):
132 self._beta = float(value)
133 self._update()
134 return locals()
135
137 """update polygon"""
138 p = super(Trapez, self)
139 p.clear()
140 p.add(self._m1-self._alpha, self._y_min)
141 p.add(self._m1, self._y_max)
142 p.add(self._m2, self._y_max)
143 p.add(self._m2+self._beta, self._y_min)
144
146 """Don't let anyone destroy our trapezoid."""
147 raise FuzzyException()
148
150 """Don't let anyone destroy our trapezoid."""
151 raise FuzzyException()
152
154 """Don't let anyone destroy our trapezoid."""
155 raise FuzzyException()
156
158 """Return representation of instance.
159
160 @return: representation of instance
161 @rtype: string
162 """
163 return "%s.%s(m1=%s, m2=%s, alpha=%s, beta=%s, y_max=%s, y_min=%s)" % (
164 self.__class__.__module__,
165 self.__class__.__name__,
166 self._m1,
167 self._m2,
168 self._alpha,
169 self._beta,
170 self._y_max,
171 self._y_min,
172 )
173