Package fuzzy :: Package set :: Module Trapez
[hide private]
[frames] | no frames]

Source Code for Module fuzzy.set.Trapez

  1  # -*- coding: utf-8 -*- 
  2  # 
  3  # Copyright (C) 2009  Rene Liebscher 
  4  # 
  5  # This program is free software; you can redistribute it and/or modify it under 
  6  # the terms of the GNU Lesser General Public License as published by the Free  
  7  # Software Foundation; either version 3 of the License, or (at your option) any 
  8  # later version. 
  9  # 
 10  # This program is distributed in the hope that it will be useful, but WITHOUT  
 11  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 12  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 
 13  # details. 
 14  #  
 15  # You should have received a copy of the GNU Lesser General Public License 
 16  # along with this program; if not, see <http://www.gnu.org/licenses/>.  
 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 
27 28 -class Trapez(Polygon):
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() # update polygon
63 64 # pylint: disable=E0211,W0212 65 @prop
66 - def y_max(): #@NoSelf
67 """y-value at top of the trapezoid 68 @type: float""" 69 def fget(self): # pylint: disable=W0612,C0111 70 return self._y_max
71 def fset(self, value): # pylint: disable=W0612,C0111 72 self._y_max = float(value) 73 self._update() 74 return locals() 75 76 # pylint: disable=E0211,W0212 77 @prop
78 - def y_min(): #@NoSelf
79 """y-value outside the trapezoid 80 @type: float""" 81 def fget(self): # pylint: disable=W0612,C0111 82 return self._y_min 83 def fset(self, value): # pylint: disable=W0612,C0111 84 self._y_min = float(value) 85 self._update() 86 return locals() 87 88 # pylint: disable=E0211,W0212 89 @prop
90 - def m1(): #@NoSelf
91 """x-value of left top of trapezoid 92 @type: float""" 93 def fget(self): # pylint: disable=W0612,C0111 94 return self._m1 95 def fset(self, value): # pylint: disable=W0612,C0111 96 self._m1 = float(value) 97 self._update() 98 return locals() 99 100 # pylint: disable=E0211,W0212 101 @prop
102 - def m2(): #@NoSelf
103 """x-value of right top of trapezoid 104 @type: float""" 105 def fget(self): # pylint: disable=W0612,C0111 106 return self._m2 107 def fset(self, value): # pylint: disable=W0612,C0111 108 self._m2 = float(value) 109 self._update() 110 return locals() 111 112 # pylint: disable=E0211,W0212 113 @prop
114 - def alpha(): #@NoSelf
115 """distance of left corner to m1 116 @type: float""" 117 def fget(self): # pylint: disable=W0612,C0111 118 return self._alpha 119 def fset(self, value): # pylint: disable=W0612,C0111 120 self._alpha = float(value) 121 self._update() 122 return locals() 123 124 # pylint: disable=E0211,W0212 125 @prop
126 - def beta(): #@NoSelf
127 """distance of right corner to m2 128 @type: float""" 129 def fget(self): # pylint: disable=W0612,C0111 130 return self._beta 131 def fset(self, value): # pylint: disable=W0612,C0111 132 self._beta = float(value) 133 self._update() 134 return locals() 135
136 - def _update(self):
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
145 - def add(self, x, y, where=Polygon.END):
146 """Don't let anyone destroy our trapezoid.""" 147 raise FuzzyException()
148
149 - def remove(self, x, where=Polygon.END):
150 """Don't let anyone destroy our trapezoid.""" 151 raise FuzzyException()
152
153 - def clear(self):
154 """Don't let anyone destroy our trapezoid.""" 155 raise FuzzyException()
156
157 - def __repr__(self):
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