# Path: fuzzy/set/Function.py
# class Function(Set):
#     """Base class for any fuzzy set defined by a function (not a polygon)."""
# 
#     # if converted if linear polygon form use
#     # at least x pieces
#     _resolution = 25 #: segments when converting into a polygon
# 
# Path: fuzzy/set/SFunction.py
# class SFunction(Function):
#     r"""
#     Realize a S-shaped fuzzy set::
#                  __
#                 /|
#                / |
#               /| |
#             _/ | |
#              | a |
#              |   |
#              delta
# 
#     See also U{http://pyfuzzy.sourceforge.net/test/set/SFunction.png}
#     
#     @ivar a: center of set.
#     @type a: float
#     @ivar delta: absolute distance between x-values for minimum and maximum.
#     @type delta: float
#     """
# 
#     def __init__(self,a=0.0,delta=1.0):
#         """Initialize a S-shaped fuzzy set.
# 
#         @param a: center of set
#         @type a: float
#         @param delta: absolute distance between x-values for minimum and maximum
#         @type delta: float
#         """
#         super(SFunction, self).__init__()
#         self.a = a
#         self.delta = delta
# 
#     def __call__(self,x):
#         """Return membership of x in this fuzzy set.
#            This method makes the set work like a function.
#            
#            @param x: value for which the membership is to calculate
#            @type x: float
#            @return: membership
#            @rtype: float
#            """
#         a = self.a
#         d = self.delta
#         if x <= a-d:
#             return 0.0
#         if x <= a:
#             t = (x-a+d)/(2.0*d)
#             return 2.0*t*t
#         if x <= a+d:
#             t = (a-x+d)/(2.0*d)
#             return 1.0-2.0*t*t
#         return 1.0
# 
#     def getCOG(self):
#         """Return center of gravity."""
#         raise Exception("COG of SFunction uncalculable")
# 
#     class __IntervalGenerator(Function.IntervalGenerator):
#         def __init__(self,set):
#             self.set = set
# 
#         def nextInterval(self,prev,next):
#             a = self.set.a
#             d = self.set.delta
#             if prev is None:
#                 if next is None:
#                     return a-d
#                 else:
#                     return min(next,a-d)
#             else:
#                 # right of our area of interest
#                 if prev >= a+d:
#                     return next
#                 else:
#                     # maximal interval length
#                     stepsize = 2.0*d/Function._resolution
#                     if next is None:
#                         return min(a+d,prev + stepsize)
#                     else:
#                         if next - prev > stepsize:
#                             # split interval in n equal sized interval of length < stepsize
#                             return min(a+d,prev+(next-prev)/(int((next-prev)/stepsize)+1.0))
#                         else:
#                             return next
# 
#     def getIntervalGenerator(self):
#         return self.__IntervalGenerator(self)
# 
# Path: fuzzy/set/ZFunction.py
# class ZFunction(SFunction):
#     r"""Realize a Z-shaped fuzzy set::
#            __
#              \
#              |\
#              | \
#              | |\
#              | | \__
#              | a |
#              |   |
#              delta
# 
#     see also U{http://pyfuzzy.sourceforge.net/test/set/ZFunction.png}
#     
#     @ivar a: center of set.
#     @type a: float
#     @ivar delta: absolute distance between x-values for minimum and maximum.
#     @type delta: float
#     """
# 
#     def __init__(self,a=0.0,delta=1.0):
#         """Initialize a Z-shaped fuzzy set.
# 
#         @param a: center of set
#         @type a: float
#         @param delta: absolute distance between x-values for minimum and maximum
#         @type delta: float
#         """
#         super(ZFunction, self).__init__(a,delta)
# 
# 
#     def __call__(self,x):
#         """Return membership of x in this fuzzy set.
#            This method makes the set work like a function.
#            
#            @param x: value for which the membership is to calculate
#            @type x: float
#            @return: membership
#            @rtype: float
#            """
#         return 1.0 - SFunction.__call__(self,x)


from fuzzy.set.Function import Function
from fuzzy.set.SFunction import SFunction
from fuzzy.set.ZFunction import ZFunction

        @param a: center of set
        @type a: float
        @param delta: absolute distance between x-values for minimum and maximum
        @type delta: float
        """
        super(PiFunction,self).__init__()
        self.a = a
        self.delta = delta

    def __call__(self,x):
        """Return membership of x in this fuzzy set.
           This method makes the set work like a function.
           
           @param x: value for which the membership is to calculate
           @type x: float
           @return: membership
           @rtype: float
           """
        a = self.a
        d = self.delta/2.0
        if x < a:
            return SFunction(a-d,d)(x)
        else:
            return ZFunction(a+d,d)(x)

    def getCOG(self):
        """Return center of gravity."""
        return self.a


# Path: fuzzy/set/Function.py
# class Function(Set):
#     """Base class for any fuzzy set defined by a function (not a polygon)."""
# 
#     # if converted if linear polygon form use
#     # at least x pieces
#     _resolution = 25 #: segments when converting into a polygon
# 
# Path: fuzzy/set/SFunction.py
# class SFunction(Function):
#     r"""
#     Realize a S-shaped fuzzy set::
#                  __
#                 /|
#                / |
#               /| |
#             _/ | |
#              | a |
#              |   |
#              delta
# 
#     See also U{http://pyfuzzy.sourceforge.net/test/set/SFunction.png}
#     
#     @ivar a: center of set.
#     @type a: float
#     @ivar delta: absolute distance between x-values for minimum and maximum.
#     @type delta: float
#     """
# 
#     def __init__(self,a=0.0,delta=1.0):
#         """Initialize a S-shaped fuzzy set.
# 
#         @param a: center of set
#         @type a: float
#         @param delta: absolute distance between x-values for minimum and maximum
#         @type delta: float
#         """
#         super(SFunction, self).__init__()
#         self.a = a
#         self.delta = delta
# 
#     def __call__(self,x):
#         """Return membership of x in this fuzzy set.
#            This method makes the set work like a function.
#            
#            @param x: value for which the membership is to calculate
#            @type x: float
#            @return: membership
#            @rtype: float
#            """
#         a = self.a
#         d = self.delta
#         if x <= a-d:
#             return 0.0
#         if x <= a:
#             t = (x-a+d)/(2.0*d)
#             return 2.0*t*t
#         if x <= a+d:
#             t = (a-x+d)/(2.0*d)
#             return 1.0-2.0*t*t
#         return 1.0
# 
#     def getCOG(self):
#         """Return center of gravity."""
#         raise Exception("COG of SFunction uncalculable")
# 
#     class __IntervalGenerator(Function.IntervalGenerator):
#         def __init__(self,set):
#             self.set = set
# 
#         def nextInterval(self,prev,next):
#             a = self.set.a
#             d = self.set.delta
#             if prev is None:
#                 if next is None:
#                     return a-d
#                 else:
#                     return min(next,a-d)
#             else:
#                 # right of our area of interest
#                 if prev >= a+d:
#                     return next
#                 else:
#                     # maximal interval length
#                     stepsize = 2.0*d/Function._resolution
#                     if next is None:
#                         return min(a+d,prev + stepsize)
#                     else:
#                         if next - prev > stepsize:
#                             # split interval in n equal sized interval of length < stepsize
#                             return min(a+d,prev+(next-prev)/(int((next-prev)/stepsize)+1.0))
#                         else:
#                             return next
# 
#     def getIntervalGenerator(self):
#         return self.__IntervalGenerator(self)
# 
# Path: fuzzy/set/ZFunction.py
# class ZFunction(SFunction):
#     r"""Realize a Z-shaped fuzzy set::
#            __
#              \
#              |\
#              | \
#              | |\
#              | | \__
#              | a |
#              |   |
#              delta
# 
#     see also U{http://pyfuzzy.sourceforge.net/test/set/ZFunction.png}
#     
#     @ivar a: center of set.
#     @type a: float
#     @ivar delta: absolute distance between x-values for minimum and maximum.
#     @type delta: float
#     """
# 
#     def __init__(self,a=0.0,delta=1.0):
#         """Initialize a Z-shaped fuzzy set.
# 
#         @param a: center of set
#         @type a: float
#         @param delta: absolute distance between x-values for minimum and maximum
#         @type delta: float
#         """
#         super(ZFunction, self).__init__(a,delta)
# 
# 
#     def __call__(self,x):
#         """Return membership of x in this fuzzy set.
#            This method makes the set work like a function.
#            
#            @param x: value for which the membership is to calculate
#            @type x: float
#            @return: membership
#            @rtype: float
#            """
#         return 1.0 - SFunction.__call__(self,x)


# Path: fuzzy/set/PiFunction.py
from fuzzy.set.Function import Function
from fuzzy.set.SFunction import SFunction
from fuzzy.set.ZFunction import ZFunction


        @param a: center of set
        @type a: float
        @param delta: absolute distance between x-values for minimum and maximum
        @type delta: float
        """
        super(PiFunction,self).__init__()
        self.a = a
        self.delta = delta

    def __call__(self,x):
        """Return membership of x in this fuzzy set.
           This method makes the set work like a function.
           
           @param x: value for which the membership is to calculate
           @type x: float
           @return: membership
           @rtype: float
           """
        a = self.a
        d = self.delta/2.0
        if x < a:
            return SFunction(a-d,d)(x)
        else:
            return ZFunction(a+d,d)(x)

    def getCOG(self):
        """Return center of gravity."""
        return self.a


    class __IntervalGenerator(Function.IntervalGenerator):