Ejemplo n.º 1
0
    def test_system_from_pyfuzzy_changing_a_single_rule_from_model(self):
        "test if work changing a single rule, but from model"

        from fuzzy_modeling.models import RuleModel

        from fuzzy.Rule import Rule
        from fuzzy.operator.Input import Input
        from fuzzy.norm.AlgebraicProduct import AlgebraicProduct

        CER = AlgebraicProduct()

        pyfuzzy_system_expected = self._createSystem()
        new_pyfuzzy_system = self._createSystem()
        system_model = SystemModel.from_pyfuzzy(self._createSystem())

        output_a = new_pyfuzzy_system.variables["a"]
        output_a.name = 'a'
        a_right_fast = output_a.adjectives["right_fast"]
        a_right_fast.name = 'right_fast'

        far_right = Rule(
            adjective=a_right_fast,
            # it gets its value from here
            operator=Input(new_pyfuzzy_system.variables["Phi"].
                           adjectives["up_more_right"]),
            CER=CER)
        far_right.name = 'far right'

        rule_model = RuleModel.from_pyfuzzy(far_right, new_pyfuzzy_system,
                                            system_model)
        new_rule = rule_model.get_pyfuzzy(new_pyfuzzy_system)
        # new_rule.operator = Input(new_pyfuzzy_system.variables["Phi"].adjectives["up_more_right"])
        new_pyfuzzy_system.rules['far right'] = new_rule

        self._test_rules_adj_in_out_adjs(new_pyfuzzy_system)

        import math
        input_dict = {}
        input_dict["X"] = 0.0  #: position [m]
        input_dict["dX_dT"] = 0.0  #: velocity [m/s]
        input_dict["Phi"] = math.radians(45.0)  #: angle [rad]
        input_dict["dPhi_dT"] = math.radians(0.0)  #: angle velocity [rad/s]

        i_dict1 = input_dict.copy()
        i_dict2 = input_dict.copy()

        output_dict1 = {
            'a': 0.0  #: acceleration [m/s²]
        }
        output_dict2 = {
            'a': 0.0  #: acceleration [m/s²]
        }

        pyfuzzy_system_expected.calculate(i_dict1, output_dict1)
        new_pyfuzzy_system.calculate(i_dict2, output_dict2)

        self.assertEquals(output_dict1['a'], output_dict2['a'])
Ejemplo n.º 2
0
    def add_rule(self, opr_adjs, adjective):
        """
        Adds a decision rule to the knowledge base.

        :Parameters:
          opr_adjs
            The input adjectives
          adjective
            The output adjective
        """
        adj1, adj2 = opr_adjs
        rule_num = len(self.rules) + 1
        self.rules[str(rule_num)] = Rule(
            adjective=adjective,
            # it gets its value from here
            operator=Compound(self.__AND__(), Input(adj1), Input(adj2)))
Ejemplo n.º 3
0
    def get_pyfuzzy(self, system=None):
        """
        Return the Pyfuzzy class of this model
        """
        # try:
        adjective = self._get_adj_instance(system)
        # except:
        #     adjective = self.adjective.get_pyfuzzy()

        cer = self.cer.get_pyfuzzy()
        operator = self.operator.get_pyfuzzy(system=system)

        rule = Rule(adjective=adjective,
                    operator=operator,
                    certainty=self.certainty,
                    CER=cer)

        return rule
Ejemplo n.º 4
0
def _createSystem():
    """
    \brief Crea el conjunto de reglas y valores para el controlador
    \details Este comando no es necesario utilizarlo
    """
    from fuzzy.InputVariable import InputVariable
    from fuzzy.OutputVariable import OutputVariable
    from fuzzy.fuzzify.Plain import Plain
    from fuzzy.defuzzify.COG import COG
    from fuzzy.Adjective import Adjective
    from fuzzy.set.Polygon import Polygon

    system = fuzzy.System.System()

    #----------------------------------------------------------------------------------------------------------------
    # Valores de entrada
    #----------------------------------------------------------------------------------------------------------------
    input_temp = InputVariable(fuzzify=Plain())

    system.variables["error"] = input_temp

    in1_set = Polygon()
    in1_set.add(x=-6000, y=0.0)  # porque debe iniciar y finalizar en cero
    in1_set.add(x=-5000, y=1.0)
    in1_set.add(x=-4000, y=0.5)
    in1_set.add(x=-3000, y=0.0)
    in1 = Adjective(in1_set)
    input_temp.adjectives["MGN"] = in1

    in2_set = Polygon()
    in2_set.add(x=-4500, y=0.0)
    in2_set.add(x=-3000, y=1.0)
    in2_set.add(x=-2000, y=0.0)
    in2 = Adjective(in2_set)
    input_temp.adjectives["GN"] = in2

    in3_set = Polygon()
    in3_set.add(x=-3000, y=0.0)
    in3_set.add(x=-2000, y=1.0)
    in3_set.add(x=-1000, y=0.0)
    in3 = Adjective(in3_set)
    input_temp.adjectives["N"] = in3

    in4_set = Polygon()
    in4_set.add(x=-2000, y=0.0)
    in4_set.add(x=-1000, y=1.0)
    in4_set.add(x=0, y=0.0)
    in4 = Adjective(in4_set)
    input_temp.adjectives["Z"] = in4

    in5_set = Polygon()
    in5_set.add(x=-1000, y=0.0)
    in5_set.add(x=1000, y=1.0)
    in5_set.add(x=5000, y=1.0)
    in5_set.add(x=6000, y=0.0)  # porque debe iniciar y finalizar en cero
    in5 = Adjective(in5_set)
    input_temp.adjectives["P"] = in5

    #----------------------------------------------------------------------------------------------------------------
    # Valores de salida
    #----------------------------------------------------------------------------------------------------------------
    output_temp = OutputVariable(defuzzify=COG())

    system.variables["vel"] = output_temp
    output_temp.failsafe = 0.0  # let it output 0.0 if no COG available

    out1_set = Polygon()
    out1_set.add(x=-200, y=0.0)  # porque debe iniciar y finalizar en cero
    out1_set.add(x=-120, y=1.0)
    out1_set.add(x=250, y=0.0)
    out1 = Adjective(out1_set)
    output_temp.adjectives["VMB"] = out1

    out2_set = Polygon()
    out2_set.add(x=30, y=0.0)
    out2_set.add(x=355, y=1.0)
    out2_set.add(x=600, y=0.0)
    out2 = Adjective(out2_set)
    output_temp.adjectives["VB"] = out2

    out3_set = Polygon()
    out3_set.add(x=255, y=0.0)
    out3_set.add(x=600, y=1.0)
    out3_set.add(x=950, y=0.0)
    out3 = Adjective(out3_set)
    output_temp.adjectives["VM"] = out3

    out4_set = Polygon()
    out4_set.add(x=600, y=0.0)
    out4_set.add(x=875, y=1.0)
    out4_set.add(x=1130, y=0.0)
    out4 = Adjective(out4_set)
    output_temp.adjectives["VA"] = out4

    out5_set = Polygon()
    out5_set.add(x=950, y=0.0)
    out5_set.add(x=1300, y=1.0)
    out5_set.add(x=1500, y=0.0)  # porque debe iniciar y finalizar en cero
    out5 = Adjective(out5_set)
    output_temp.adjectives["VMA"] = out5

    #----------------------------------------------------------------------------------------------------------------
    # Reglas
    #----------------------------------------------------------------------------------------------------------------
    from fuzzy.Rule import Rule
    from fuzzy.norm.Min import Min
    from fuzzy.operator.Input import Input
    from fuzzy.operator.Compound import Compound

    rule1 = Rule(
        adjective=system.variables["vel"].adjectives["VMA"],
        operator=Input(system.variables["error"].adjectives["MGN"]),
    )
    system.rules["rule1"] = rule1

    rule2 = Rule(
        adjective=system.variables["vel"].adjectives["VA"],
        operator=Input(system.variables["error"].adjectives["GN"], ),
    )
    system.rules["rule2"] = rule2

    rule3 = Rule(
        adjective=system.variables["vel"].adjectives["VM"],
        operator=Input(system.variables["error"].adjectives["N"], ),
    )
    system.rules["rule3"] = rule3

    rule4 = Rule(
        adjective=system.variables["vel"].adjectives["VB"],
        operator=Input(system.variables["error"].adjectives["Z"], ),
    )
    system.rules["rule4"] = rule4

    rule5 = Rule(
        adjective=system.variables["vel"].adjectives["VMB"],
        operator=Input(system.variables["error"].adjectives["P"], ),
    )
    system.rules["rule5"] = rule5

    return system
Ejemplo n.º 5
0
def _createSystem():
    import fuzzy.System
    system = fuzzy.System.System(
        description=
        """This fuzzy system is to control the inverted pendulum into an upright position as well as
at the position X=0.

It also is used to demonstrate some features of pyfuzzy.
This is the reason, it uses different fuzzy norm in normally
symmetrical rules.""")

    from fuzzy.norm.AlgebraicProduct import AlgebraicProduct
    from fuzzy.norm.AlgebraicSum import AlgebraicSum
    from fuzzy.fuzzify.Plain import Plain
    from fuzzy.defuzzify.COG import COG
    # set defuzzification method and default norms
    INF = AlgebraicProduct()
    ACC = AlgebraicSum()
    COM = AlgebraicSum()
    CER = AlgebraicProduct()
    COG = COG(INF=INF, ACC=ACC, failsafe=0., segment_size=0.5)

    from fuzzy.InputVariable import InputVariable
    from fuzzy.OutputVariable import OutputVariable
    from fuzzy.Adjective import Adjective
    from fuzzy.set.Polygon import Polygon

    angle = InputVariable(fuzzify=Plain(),
                          description='angle',
                          min=0.,
                          max=360.,
                          unit='degrees')
    system.variables['Phi'] = angle
    angle.adjectives['up_more_right'] = Adjective(
        Polygon([(0., 0.), (30., 1.), (60., 0.)]))
    angle.adjectives['up_right'] = Adjective(
        Polygon([(30., 0.), (60., 1.), (90., 0.)]))
    angle.adjectives['up'] = Adjective(
        Polygon([(60., 0.), (90., 1.), (120., 0.)]))
    angle.adjectives['up_left'] = Adjective(
        Polygon([(90., 0.), (120., 1.), (150., 0.)]))
    angle.adjectives['up_more_left'] = Adjective(
        Polygon([(120., 0.), (150., 1.), (180., 0.)]))
    angle.adjectives['down_more_left'] = Adjective(
        Polygon([(180., 0.), (210., 1.), (240., 0.)]))
    angle.adjectives['down_left'] = Adjective(
        Polygon([(210., 0.), (240., 1.), (270., 0.)]))
    angle.adjectives['down'] = Adjective(
        Polygon([(240., 0.), (270., 1.), (300., 0.)]))
    angle.adjectives['down_right'] = Adjective(
        Polygon([(270., 0.), (300., 1.), (330., 0.)]))
    angle.adjectives['down_more_right'] = Adjective(
        Polygon([(300., 0.), (330., 1.), (360., 0.)]))

    angle_velocity = InputVariable(fuzzify=Plain(),
                                   description='angle velocity',
                                   min=-600.,
                                   max=600.,
                                   unit='degrees per second')
    system.variables['dPhi_dT'] = angle_velocity
    angle_velocity.adjectives['cw_fast'] = Adjective(
        Polygon([(-600., 1.), (-300., 0.)]))
    angle_velocity.adjectives['cw_slow'] = Adjective(
        Polygon([(-600., 0.), (-300., 1.), (0., 0.)]))
    angle_velocity.adjectives['stop'] = Adjective(
        Polygon([(-300., 0.), (0., 1.), (300., 0.)]))
    angle_velocity.adjectives['ccw_slow'] = Adjective(
        Polygon([(0., 0.), (300., 1.), (600., 0.)]))
    angle_velocity.adjectives['ccw_fast'] = Adjective(
        Polygon([(300., 0.), (600., 1.)]))

    position = InputVariable(fuzzify=Plain(),
                             description='position',
                             min=-20.,
                             max=20.,
                             unit='meter')
    system.variables['X'] = position
    position.adjectives['left_far'] = Adjective(
        Polygon([(-20., 1.), (-10., 0.)]))
    position.adjectives['left_near'] = Adjective(
        Polygon([(-20., 0.), (-5., 1.), (0., 0.)]))
    position.adjectives['stop'] = Adjective(
        Polygon([(-5., 0.), (0., 1.), (5., 0.)]))
    position.adjectives['right_near'] = Adjective(
        Polygon([(0., 0.), (5., 1.), (20., 0.)]))
    position.adjectives['right_far'] = Adjective(
        Polygon([(10., 0.), (20., 1.)]))

    velocity = InputVariable(fuzzify=Plain(),
                             description='velocity',
                             min=-10.,
                             max=10.,
                             unit='meter per second')
    system.variables['dX_dT'] = velocity
    velocity.adjectives['left_fast'] = Adjective(
        Polygon([(-10., 1.), (-5., 0.)]))
    velocity.adjectives['left_slow'] = Adjective(
        Polygon([(-10., 0.), (-2., 1.), (0., 0.)]))
    velocity.adjectives['stop'] = Adjective(
        Polygon([(-2., 0.), (0., 1.), (2., 0.)]))
    velocity.adjectives['right_slow'] = Adjective(
        Polygon([(0., 0.), (2., 1.), (10., 0.)]))
    velocity.adjectives['right_fast'] = Adjective(
        Polygon([(5., 0.), (10., 1.)]))

    acceleration = OutputVariable(defuzzify=COG,
                                  description='acceleration',
                                  min=-50.,
                                  max=50.,
                                  unit='meter per second^2')
    system.variables['a'] = acceleration
    acceleration.adjectives['left_fast'] = a_left_fast = Adjective(Polygon([
        (-50., 0.), (-20., 1.), (-10., 0.)
    ]),
                                                                   COM=COM)
    acceleration.adjectives['left_slow'] = a_left_slow = Adjective(Polygon([
        (-20., 0.), (-10., 1.), (0., 0.)
    ]),
                                                                   COM=COM)
    acceleration.adjectives['stop'] = a_stop = Adjective(Polygon([(-10., 0.),
                                                                  (0., 1.),
                                                                  (10., 0.)]),
                                                         COM=COM)
    acceleration.adjectives['right_slow'] = a_right_slow = Adjective(Polygon([
        (0., 0.), (10., 1.), (20., 0.)
    ]),
                                                                     COM=COM)
    acceleration.adjectives['right_fast'] = a_right_fast = Adjective(Polygon([
        (10., 0.), (20., 1.), (50., 0.)
    ]),
                                                                     COM=COM)

    from fuzzy.Rule import Rule
    from fuzzy.norm.Max import Max
    #from fuzzy.norm.Min import Min
    #from fuzzy.norm.BoundedDifference import BoundedDifference
    #from fuzzy.norm.DrasticSum import DrasticSum
    from fuzzy.norm.EinsteinSum import EinsteinSum
    from fuzzy.norm.DombiUnion import DombiUnion
    from fuzzy.operator.Compound import Compound
    from fuzzy.operator.Input import Input
    from fuzzy.operator.Not import Not

    system.rules['stop'] = Rule(
        adjective=a_stop,
        # it gets its value from here
        operator=Compound(
            Max(),
            Compound(AlgebraicProduct(),
                     Input(system.variables["Phi"].adjectives["up"]),
                     Input(system.variables["dPhi_dT"].adjectives["stop"])),
            Compound(AlgebraicProduct(),
                     Input(system.variables["Phi"].adjectives["up_right"]),
                     Input(
                         system.variables["dPhi_dT"].adjectives["ccw_slow"])),
            Compound(AlgebraicProduct(),
                     Input(system.variables["Phi"].adjectives["up_left"]),
                     Input(
                         system.variables["dPhi_dT"].adjectives["cw_slow"]))),
        CER=CER)

    system.rules['tilts right'] = Rule(
        adjective=a_right_slow,
        # it gets its value from here
        operator=Compound(
            AlgebraicProduct(),
            Not(
                Compound(
                    AlgebraicProduct(),
                    Compound(
                        AlgebraicSum(),
                        Input(system.variables["X"].adjectives["left_near"]),
                        Input(system.variables["X"].adjectives["left_far"])),
                    Compound(
                        EinsteinSum(),
                        Input(
                            system.variables["dX_dT"].adjectives["left_slow"]),
                        Input(system.variables["dX_dT"].adjectives["left_fast"]
                              ))), ),
            Input(system.variables["Phi"].adjectives["up_right"])),
        CER=CER)

    system.rules['tilts left'] = Rule(
        adjective=a_left_slow,
        # it gets its value from here
        operator=Compound(
            AlgebraicProduct(),
            Not(
                Compound(
                    AlgebraicProduct(),
                    Compound(
                        AlgebraicSum(),
                        Input(system.variables["X"].adjectives["right_near"]),
                        Input(system.variables["X"].adjectives["right_far"])),
                    Compound(
                        DombiUnion(0.25),
                        Input(system.variables["dX_dT"].
                              adjectives["right_slow"]),
                        Input(system.variables["dX_dT"].
                              adjectives["right_fast"]))), ),
            Input(system.variables["Phi"].adjectives["up_left"])),
        CER=CER)

    system.rules['far right'] = Rule(
        adjective=a_right_fast,
        # it gets its value from here
        operator=Input(system.variables["Phi"].adjectives["up_more_right"]),
        CER=CER)

    system.rules['far left'] = Rule(
        adjective=a_left_fast,
        # it gets its value from here
        operator=Input(system.variables["Phi"].adjectives["up_more_left"]),
        CER=CER)

    system.rules['accelerate cw if down'] = Rule(
        adjective=a_right_slow,
        # it gets its value from here
        operator=Compound(
            AlgebraicProduct(),
            Input(system.variables["Phi"].adjectives["down"]),
            Compound(
                AlgebraicProduct(),
                Input(system.variables["dPhi_dT"].adjectives["cw_slow"]),
                Input(system.variables["dPhi_dT"].adjectives["cw_slow"]),
            )),
        CER=CER)

    system.rules['accelerate ccw if down'] = Rule(
        adjective=a_left_slow,
        # it gets its value from here
        operator=Compound(
            AlgebraicProduct(),
            Input(system.variables["Phi"].adjectives["down"]),
            Compound(
                AlgebraicProduct(),
                Input(system.variables["dPhi_dT"].adjectives["ccw_slow"]),
                Input(system.variables["dPhi_dT"].adjectives["ccw_slow"]),
            )),
        CER=CER)

    return system
Ejemplo n.º 6
0
def _createSystem():
    from fuzzy.InputVariable import InputVariable
    from fuzzy.OutputVariable import OutputVariable
    from fuzzy.fuzzify.Plain import Plain
    from fuzzy.defuzzify.COG import COG
    from fuzzy.defuzzify.LM import LM
    from fuzzy.Adjective import Adjective
    from fuzzy.set.Polygon import Polygon

    system = fuzzy.System.System()

    #----------------------------------------------------------------------------------------------------------------
    # input temperature
    #----------------------------------------------------------------------------------------------------------------
    input_temp = InputVariable(fuzzify=Plain())

    system.variables["InputTemp"] = input_temp

    int1_set = Polygon()
    int1_set.add(x=-80, y=0.0)
    int1_set.add(x=0.0, y=1.0)
    int1_set.add(x=10, y=0.0)
    int1 = Adjective(int1_set)
    input_temp.adjectives["z"] = int1

    int2_set = Polygon()
    int2_set.add(x=0, y=0.0)
    int2_set.add(x=15, y=1.0)
    int2_set.add(x=30, y=0.0)
    int2 = Adjective(int2_set)
    input_temp.adjectives["s"] = int2

    int3_set = Polygon()
    int3_set.add(x=15, y=0.0)
    int3_set.add(x=30, y=1.0)
    int3_set.add(x=80, y=0.0)
    int3 = Adjective(int3_set)
    input_temp.adjectives["t"] = int3

    #----------------------------------------------------------------------------------------------------------------
    # input wind
    #----------------------------------------------------------------------------------------------------------------
    input_wind = InputVariable(fuzzify=Plain())

    system.variables["InputWind"] = input_wind

    inw1_set = Polygon()
    inw1_set.add(x=0, y=0.0)
    inw1_set.add(x=10.0, y=1.0)
    inw1_set.add(x=20, y=0.0)
    inw1 = Adjective(inw1_set)
    input_wind.adjectives["s"] = inw1

    inw2_set = Polygon()
    inw2_set.add(x=10, y=0.0)
    inw2_set.add(x=30, y=1.0)
    inw2_set.add(x=50, y=0.0)
    inw2 = Adjective(inw2_set)
    input_wind.adjectives["m"] = inw2

    inw3_set = Polygon()
    inw3_set.add(x=30, y=0.0)
    inw3_set.add(x=50, y=1.0)
    inw3_set.add(x=150, y=0.0)
    inw3 = Adjective(inw3_set)
    input_wind.adjectives["v"] = inw3

    #----------------------------------------------------------------------------------------------------------------
    # output => pocitova teplota
    #----------------------------------------------------------------------------------------------------------------
    output_clothes = OutputVariable(defuzzify=COG())

    system.variables["o"] = output_clothes
    output_clothes.failsafe = 0.0  # let it output 0.0 if no COG available

    # out1_set = Polygon()
    # out1_set.add(x = -80, y= 0.0)
    # out1_set.add(x = 0, y= 1.0)
    # out1_set.add(x = 10, y= 0.0)
    # out1 = Adjective(out1_set)
    # output_clothes.adjectives["vz"] = out1

    out2_set = Polygon()
    out2_set.add(x=-80, y=0.0)
    out2_set.add(x=0, y=1.0)
    out2_set.add(x=10, y=0.0)
    out2 = Adjective(out2_set)
    output_clothes.adjectives["z"] = out2

    out3_set = Polygon()
    out3_set.add(x=0, y=0.0)
    out3_set.add(x=15, y=1.0)
    out3_set.add(x=30, y=0.0)
    out3 = Adjective(out3_set)
    output_clothes.adjectives["s"] = out3

    out4_set = Polygon()
    out4_set.add(x=15, y=0.0)
    out4_set.add(x=30, y=1.0)
    out4_set.add(x=80, y=0.0)
    out4 = Adjective(out4_set)
    output_clothes.adjectives["t"] = out4

    # out5_set = Polygon()
    # out5_set.add(x = 30, y= 0.0)
    # out5_set.add(x = 40, y= 1.0)
    # out5_set.add(x = 50, y= 0.0)
    # out5 = Adjective(out5_set)
    # output_clothes.adjectives["vt"] = out5

    #----------------------------------------------------------------------------------------------------------------
    # Definition der Regeln
    #----------------------------------------------------------------------------------------------------------------
    from fuzzy.Rule import Rule
    from fuzzy.norm.Min import Min
    from fuzzy.operator.Input import Input
    from fuzzy.operator.Compound import Compound

    rule1 = Rule(adjective=system.variables["o"].adjectives["z"],
                 operator=Compound(
                     Min(),
                     Input(system.variables["InputTemp"].adjectives["z"]),
                     Input(system.variables["InputWind"].adjectives["v"])))
    system.rules["rule1"] = rule1

    rule2 = Rule(adjective=system.variables["o"].adjectives["z"],
                 operator=Compound(
                     Min(),
                     Input(system.variables["InputTemp"].adjectives["z"]),
                     Input(system.variables["InputWind"].adjectives["m"])))
    system.rules["rule2"] = rule2

    rule3 = Rule(adjective=system.variables["o"].adjectives["z"],
                 operator=Compound(
                     Min(),
                     Input(system.variables["InputTemp"].adjectives["z"]),
                     Input(system.variables["InputWind"].adjectives["s"])))
    system.rules["rule3"] = rule3

    rule4 = Rule(adjective=system.variables["o"].adjectives["z"],
                 operator=Compound(
                     Min(),
                     Input(system.variables["InputTemp"].adjectives["s"]),
                     Input(system.variables["InputWind"].adjectives["v"])))
    system.rules["rule4"] = rule4

    rule5 = Rule(adjective=system.variables["o"].adjectives["s"],
                 operator=Compound(
                     Min(),
                     Input(system.variables["InputTemp"].adjectives["s"]),
                     Input(system.variables["InputWind"].adjectives["m"])))
    system.rules["rule5"] = rule5

    rule6 = Rule(adjective=system.variables["o"].adjectives["s"],
                 operator=Compound(
                     Min(),
                     Input(system.variables["InputTemp"].adjectives["s"]),
                     Input(system.variables["InputWind"].adjectives["s"])))
    system.rules["rule6"] = rule6

    rule7 = Rule(adjective=system.variables["o"].adjectives["s"],
                 operator=Compound(
                     Min(),
                     Input(system.variables["InputTemp"].adjectives["t"]),
                     Input(system.variables["InputWind"].adjectives["v"])))
    system.rules["rule7"] = rule7

    rule8 = Rule(adjective=system.variables["o"].adjectives["t"],
                 operator=Compound(
                     Min(),
                     Input(system.variables["InputTemp"].adjectives["t"]),
                     Input(system.variables["InputWind"].adjectives["m"])))
    system.rules["rule8"] = rule8

    rule9 = Rule(adjective=system.variables["o"].adjectives["t"],
                 operator=Compound(
                     Min(),
                     Input(system.variables["InputTemp"].adjectives["t"]),
                     Input(system.variables["InputWind"].adjectives["s"])))
    system.rules["rule9"] = rule9

    return system
def _createSystem():
    '''
    Definition des Fuzzy-Systems:

        1. Eingangsvariable Phi
        2. Eingangsvariable dPhi_dT
        3. Ausgangsvariable a
        4. Definition der Regeln
    '''
    from fuzzy.InputVariable import InputVariable
    from fuzzy.OutputVariable import OutputVariable
    from fuzzy.fuzzify.Plain import Plain
    from fuzzy.defuzzify.COG import COG
    from fuzzy.Adjective import Adjective
    from fuzzy.set.Polygon import Polygon

    system = fuzzy.System.System()

    #----------------------------------------------------------------------------------------------------------------
    # Definition des Drehwinkels als Eingang
    #----------------------------------------------------------------------------------------------------------------
    input_temp = InputVariable(fuzzify=Plain())

    system.variables["Phi"] = input_temp

    in1_set = Polygon()
    in1_set.add(x=-22.5, y=0.0)
    in1_set.add(x=0.0, y=1.0)
    in1_set.add(x=22.5, y=0.0)
    in1 = Adjective(in1_set)
    input_temp.adjectives["eN"] = in1

    in2_set = Polygon()
    in2_set.add(x=0.0, y=0.0)
    in2_set.add(x=22.5, y=1.0)
    in2_set.add(x=45.0, y=0.0)
    in2 = Adjective(in2_set)
    input_temp.adjectives["pk"] = in2

    in3_set = Polygon()
    in3_set.add(x=22.5, y=0.0)
    in3_set.add(x=45.0, y=1.0)
    in3_set.add(x=67.5, y=0.0)
    in3 = Adjective(in3_set)
    input_temp.adjectives["pm"] = in3

    in4_set = Polygon()
    in4_set.add(x=45.0, y=0.0)
    in4_set.add(x=67.5, y=1.0)
    in4_set.add(x=90.0, y=1.0)
    in4_set.add(x=180.0, y=0.0)
    in4 = Adjective(in4_set)
    input_temp.adjectives["pg"] = in4

    in5_set = Polygon()
    in5_set.add(x=-45.0, y=0.0)
    in5_set.add(x=-67.5, y=1.0)
    in5_set.add(x=-90.0, y=1.0)
    in5_set.add(x=-180.0, y=0.0)
    in5 = Adjective(in5_set)
    input_temp.adjectives["ng"] = in5

    in6_set = Polygon()
    in6_set.add(x=-22.5, y=0.0)
    in6_set.add(x=-45.0, y=1.0)
    in6_set.add(x=-67.5, y=0.0)
    in6 = Adjective(in6_set)
    input_temp.adjectives["nm"] = in6

    in7_set = Polygon()
    in7_set.add(x=-0.0, y=0.0)
    in7_set.add(x=-22.5, y=1.0)
    in7_set.add(x=-45.0, y=0.0)
    in7 = Adjective(in7_set)
    input_temp.adjectives["nk"] = in7

    #----------------------------------------------------------------------------------------------------------------
    # Definition der Winkelgeschwindigkeit als Eingang
    #----------------------------------------------------------------------------------------------------------------
    input_tempa = InputVariable(fuzzify=Plain())

    system.variables["dPhi_dT"] = input_tempa

    in1a_set = Polygon()
    in1a_set.add(x=-11.25, y=0.0)
    in1a_set.add(x=0.0, y=1.0)
    in1a_set.add(x=11.25, y=0.0)
    in1a = Adjective(in1a_set)
    input_tempa.adjectives["eN"] = in1a

    in2a_set = Polygon()
    in2a_set.add(x=0.0, y=0.0)
    in2a_set.add(x=11.25, y=1.0)
    in2a_set.add(x=22.5, y=0.0)
    in2a = Adjective(in2a_set)
    input_tempa.adjectives["pk"] = in2a

    in3a_set = Polygon()
    in3a_set.add(x=11.25, y=0.0)
    in3a_set.add(x=22.50, y=1.0)
    in3a_set.add(x=33.75, y=0.0)
    in3a = Adjective(in3a_set)
    input_tempa.adjectives["pm"] = in3a

    in4a_set = Polygon()
    in4a_set.add(x=22.5, y=0.0)
    in4a_set.add(x=33.75, y=1.0)
    in4a_set.add(x=45.0, y=1.0)
    in4a_set.add(x=90.0, y=0.0)
    in4a = Adjective(in4a_set)
    input_tempa.adjectives["pg"] = in4a

    in5a_set = Polygon()
    in5a_set.add(x=-0.0, y=0.0)
    in5a_set.add(x=-11.25, y=1.0)
    in5a_set.add(x=-22.5, y=0.0)
    in5a = Adjective(in5a_set)
    input_tempa.adjectives["nk"] = in5a

    in6a_set = Polygon()
    in6a_set.add(x=-11.25, y=0.0)
    in6a_set.add(x=-22.50, y=1.0)
    in6a_set.add(x=-33.75, y=0.0)
    in6a = Adjective(in6a_set)
    input_tempa.adjectives["nm"] = in6a

    in7a_set = Polygon()
    in7a_set.add(x=-22.5, y=0.0)
    in7a_set.add(x=-33.75, y=1.0)
    in7a_set.add(x=-45.0, y=1.0)
    in7a_set.add(x=-90.0, y=0.0)
    in7a = Adjective(in7a_set)
    input_tempa.adjectives["ng"] = in7a

    #----------------------------------------------------------------------------------------------------------------
    # Definition der Horizontalbeschleunigung als Ausgang
    #----------------------------------------------------------------------------------------------------------------
    output_temp = OutputVariable(defuzzify=COG())

    system.variables["a"] = output_temp
    output_temp.failsafe = 0.0  # let it output 0.0 if no COG available

    out1_set = Polygon()
    out1_set.add(x=-0.25, y=0.0)
    out1_set.add(x=0.0, y=1.0)
    out1_set.add(x=0.25, y=0.0)
    out1 = Adjective(out1_set)
    output_temp.adjectives["eN"] = out1

    out2_set = Polygon()
    out2_set.add(x=0.00, y=0.0)
    out2_set.add(x=0.25, y=1.0)
    out2_set.add(x=0.50, y=0.0)
    out2 = Adjective(out2_set)
    output_temp.adjectives["pk"] = out2

    out3_set = Polygon()
    out3_set.add(x=0.25, y=0.0)
    out3_set.add(x=0.50, y=1.0)
    out3_set.add(x=0.75, y=0.0)
    out3 = Adjective(out3_set)
    output_temp.adjectives["pm"] = out3

    out4_set = Polygon()
    out4_set.add(x=0.50, y=0.0)
    out4_set.add(x=0.75, y=1.0)
    out4_set.add(x=1.0, y=1.0)
    out4_set.add(x=2.0, y=0.0)
    out4 = Adjective(out4_set)
    output_temp.adjectives["pg"] = out4

    out5_set = Polygon()
    out5_set.add(x=0.00, y=0.0)
    out5_set.add(x=-0.25, y=1.0)
    out5_set.add(x=-0.50, y=0.0)
    out5 = Adjective(out5_set)
    output_temp.adjectives["nk"] = out5

    out6_set = Polygon()
    out6_set.add(x=-0.25, y=0.0)
    out6_set.add(x=-0.50, y=1.0)
    out6_set.add(x=-0.75, y=0.0)
    out6 = Adjective(out6_set)
    output_temp.adjectives["nm"] = out6

    out7_set = Polygon()
    out7_set.add(x=-0.50, y=0.0)
    out7_set.add(x=-0.75, y=1.0)
    out7_set.add(x=-1.0, y=1.0)
    out7_set.add(x=-2.0, y=0.0)
    out7 = Adjective(out7_set)
    output_temp.adjectives["ng"] = out7

    #----------------------------------------------------------------------------------------------------------------
    # Definition der Regeln
    #----------------------------------------------------------------------------------------------------------------
    from fuzzy.Rule import Rule
    from fuzzy.norm.Min import Min
    from fuzzy.operator.Input import Input
    from fuzzy.operator.Compound import Compound

    rule1 = Rule(adjective=system.variables["a"].adjectives["pk"],
                 operator=Compound(
                     Min(), Input(system.variables["Phi"].adjectives["nk"]),
                     Input(system.variables["dPhi_dT"].adjectives["eN"])))
    system.rules["rule1"] = rule1

    rule2 = Rule(
        adjective=system.variables["a"].adjectives["nk"],
        operator=Input(system.variables["Phi"].adjectives["pk"], ),
    )
    system.rules["rule2"] = rule2

    rule3 = Rule(
        adjective=system.variables["a"].adjectives["pm"],
        operator=Input(system.variables["Phi"].adjectives["nm"], ),
    )
    system.rules["rule3"] = rule3

    rule4 = Rule(
        adjective=system.variables["a"].adjectives["nm"],
        operator=Input(system.variables["Phi"].adjectives["pm"], ),
    )
    system.rules["rule4"] = rule4

    rule5 = Rule(
        adjective=system.variables["a"].adjectives["pg"],
        operator=Input(system.variables["Phi"].adjectives["ng"], ),
    )
    system.rules["rule5"] = rule5

    rule6 = Rule(
        adjective=system.variables["a"].adjectives["ng"],
        operator=Input(system.variables["Phi"].adjectives["pg"], ),
    )
    system.rules["rule6"] = rule6

    return system