1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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
55 """Just store the value."""
56 self.__value = value
57
59 """Return previous input value."""
60 return self.__value
61
63 """Reset meberships of adjectives for new calculation step."""
64 for adjective in self.adjectives.values():
65 adjective.reset()
66
68 """Lookup the name given this variable in the given system"""
69 return system.findVariableName(self)
70
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
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