Package fuzzy :: Module Variable
[hide private]
[frames] | no frames]

Source Code for Module fuzzy.Variable

 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  """Base class for any kind of fuzzy variable.""" 
19  __revision__ = "$Id: Variable.py,v 1.16 2010-02-17 19:57:13 rliebscher Exp $" 
20   
21   
22 -class Variable(object):
23 """Base class for any kind of fuzzy variable. 24 Returns as output the previous input value. 25 26 @ivar description: Description of the fuzzy variable 27 @type description: string 28 @ivar min: minimum value (not strictly enforced, but useful for some external tools) 29 @type min: float 30 @ivar max: maximum value (not strictly enforced, but useful for some external tools) 31 @type max: float 32 @ivar unit: Unit of the values 33 @type unit: string 34 """ 35
36 - def __init__(self, description='', min=0., max=1., unit='', adjectives = None):
37 """ 38 @param description: Description of the fuzzy variable 39 @type description: string 40 @param min: minimum value (not strictly enforced, but useful for some external tools) 41 @type min: float 42 @param max: maximum value (not strictly enforced, but useful for some external tools) 43 @type max: float 44 @param unit: Unit of the values 45 @type unit: string 46 """ 47 self.adjectives = adjectives or {} 48 self.__value = None 49 self.description = description 50 self.min = min 51 self.max = max 52 self.unit = unit
53
54 - def setValue(self, value):
55 """Just store the value.""" 56 self.__value = value
57
58 - def getValue(self):
59 """Return previous input value.""" 60 return self.__value
61
62 - def reset(self):
63 """Reset meberships of adjectives for new calculation step.""" 64 for adjective in self.adjectives.values(): 65 adjective.reset()
66
67 - def getName(self, system):
68 """Lookup the name given this variable in the given system""" 69 return system.findVariableName(self)
70
71 - def __repr__(self):
72 """Return representation of instance. 73 74 @return: representation of instance 75 @rtype: string 76 """ 77 params = [] 78 self._repr_params(params) 79 return "%s.%s(%s)" % (self.__class__.__module__, self.__class__.__name__, ", ".join(params))
80
81 - def _repr_params(self, params):
82 """Helper for representation of instance. 83 84 Add all own params to given list in params. 85 """ 86 if self.description: params.append("description=%s" % repr(self.description)) 87 if self.min != 0.: params.append("min=%s" % self.min) 88 if self.max != 1.: params.append("max=%s" % self.max) 89 if self.unit: params.append("unit=%s" % repr(self.unit)) 90 if self.adjectives: params.append("adjectives=%s" % repr(self.adjectives))
91