def test_rule_block(self) -> None: rb = fl.RuleBlock(name="rb", description="a rule block", rules=[fl.Rule.create("if a then z")]) self.assertEqual(fl.PythonExporter().to_string(rb), fl.PythonExporter().rule_block(rb)) self.assertEqual( fl.PythonExporter().rule_block(rb), """\ fl.RuleBlock( name="rb", description="a rule block", enabled=True, conjunction=None, disjunction=None, implication=None, activation=None, rules=[fl.Rule.create("if a then z", engine)] )""") rb.rules.append(fl.Rule.create("if b then y")) self.assertEqual( fl.PythonExporter().rule_block(rb), """\ fl.RuleBlock( name="rb", description="a rule block", enabled=True, conjunction=None, disjunction=None, implication=None, activation=None, rules=[ fl.Rule.create("if a then z", engine), fl.Rule.create("if b then y", engine) ] )""")
def test_single_line_indent(self) -> None: engine = fl.Engine("engine", "single line export to FLL", [fl.InputVariable("A", "variable A")], [fl.OutputVariable("Z", "variable Z")], [fl.RuleBlock("R", "rule block R")]) self.assertEqual( fl.FllExporter(separator="; ", indent='\t').engine(engine), "Engine: engine; " "\tdescription: single line export to FLL; " "InputVariable: A; " "\tdescription: variable A; " "\tenabled: true; " "\trange: -inf inf; " "\tlock-range: false; " "OutputVariable: Z; " "\tdescription: variable Z; " "\tenabled: true; " "\trange: -inf inf; " "\tlock-range: false; " "\taggregation: none; " "\tdefuzzifier: none; " "\tdefault: nan; " "\tlock-previous: false; " "RuleBlock: R; " "\tdescription: rule block R; " "\tenabled: true; " "\tconjunction: none; " "\tdisjunction: none; " "\timplication: none; " "\tactivation: none; ")
def test_engine(self) -> None: engine = fl.Engine( name="engine", description="an engine", input_variables=[ fl.InputVariable(name="input_variable", description="an input variable", minimum=0, maximum=1, terms=[fl.Triangle("A")]) ], output_variables=[ fl.OutputVariable(name="output_variable", description="an output variable", minimum=0, maximum=1, terms=[fl.Triangle("A")]) ], rule_blocks=[ fl.RuleBlock(name="rb", description="a rule block", rules=[fl.Rule.create("if a then z")]) ]) self.assertEqual(fl.FllExporter().to_string(engine), fl.FllExporter().engine(engine)) self.assertEqual( fl.FllExporter().engine(engine), """\ Engine: engine description: an engine InputVariable: input_variable description: an input variable enabled: true range: 0 1 lock-range: false term: A Triangle nan nan nan OutputVariable: output_variable description: an output variable enabled: true range: 0 1 lock-range: false aggregation: none defuzzifier: none default: nan lock-previous: false term: A Triangle nan nan nan RuleBlock: rb description: a rule block enabled: true conjunction: none disjunction: none implication: none activation: none rule: if a then z """)
def test_rule_block(self) -> None: rb = fl.RuleBlock(name="rb", description="a rule block", rules=[fl.Rule.create("if a then z")]) self.assertEqual(fl.FllExporter().to_string(rb), fl.FllExporter().rule_block(rb)) self.assertEqual(fl.FllExporter().rule_block(rb), """\ RuleBlock: rb description: a rule block enabled: true conjunction: none disjunction: none implication: none activation: none rule: if a then z""")
fl.Triangle("cheap", 0.000, 5.000, 10.000), fl.Triangle("average", 10.000, 15.000, 20.000), fl.Triangle("generous", 20.000, 25.000, 30.000) ]) ] engine.rule_blocks = [ fl.RuleBlock( name="mamdani", description="Mamdani inference", enabled=True, conjunction=fl.Minimum(), disjunction=fl.Maximum(), implication=fl.Minimum(), activation=fl.General(), rules=[ fl.Rule.create( "if service is poor or food is rancid then Tip is cheap", engine), fl.Rule.create("if service is good then Tip is average", engine), fl.Rule.create( "if service is excellent or food is delicious then Tip is generous with 0.500", engine), fl.Rule.create( "if service is excellent and food is delicious then Tip is generous", engine) ]) ] service = engine.input_variable("service") food = engine.input_variable("food") propina = engine.output_variable("Tip")
terms=[ fl.Constant("cheap", 5.000), fl.Constant("average", 15.000), fl.Constant("generous", 25.000) ] ) ] engine.rule_blocks = [ fl.RuleBlock( name="mamdani", description="Mamdani inference", enabled=True, conjunction=fl.AlgebraicProduct(), disjunction=fl.AlgebraicSum(), implication=fl.Minimum(), activation=fl.General(), rules=[ fl.Rule.create("if service is poor or food is rancid then mTip is cheap", engine), fl.Rule.create("if service is good then mTip is average", engine), fl.Rule.create("if service is excellent or food is delicious then mTip is generous with 0.500", engine), fl.Rule.create("if service is excellent and food is delicious then mTip is generous", engine) ] ), fl.RuleBlock( name="takagiSugeno", description="Takagi-Sugeno inference", enabled=True, conjunction=fl.AlgebraicProduct(), disjunction=fl.AlgebraicSum(), implication=None, activation=fl.General(),
terms=[ fl.Gaussian("PlusAboutTenPercent", 1.100, 0.020), fl.Gaussian("PlusAboutFifteenPercent", 1.150, 0.020), fl.Gaussian("PlusAboutTwentyPercent", 1.200, 0.020) ]) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=fl.AlgebraicProduct(), disjunction=fl.Maximum(), implication=fl.Minimum(), activation=fl.General(), rules=[ fl.Rule.create( "if FoodQuality is Bad and Service is Bad then Tip is AboutTenPercent and CheckPlusTip is PlusAboutTenPercent", engine), fl.Rule.create( "if FoodQuality is Bad and Service is Good then Tip is AboutFifteenPercent and CheckPlusTip is PlusAboutFifteenPercent", engine), fl.Rule.create( "if FoodQuality is Good and Service is Bad then Tip is AboutFifteenPercent and CheckPlusTip is PlusAboutFifteenPercent", engine), fl.Rule.create( "if FoodQuality is Good and Service is Good then Tip is AboutTwentyPercent and CheckPlusTip is PlusAboutTwentyPercent", engine) ]) ]
enabled=True, minimum=0.000, maximum=1.000, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("Automatic"), lock_previous=False, terms=[ fl.Concave("b", 0.500, 0.400), fl.Concave("a", 0.240, 0.250), fl.Concave("c", 0.900, 1.000) ] ) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=None, disjunction=None, implication=None, activation=fl.General(), rules=[ fl.Rule.create("if X is small then Ramps is a and Sigmoids is a and ZSShapes is a and Concaves is a", engine), fl.Rule.create("if X is medium then Ramps is b and Sigmoids is b and ZSShapes is b and Concaves is b", engine), fl.Rule.create("if X is large then Ramps is c and Sigmoids is c and ZSShapes is c and Concaves is c", engine) ] ) ]
engine.output_variables = [ fl.OutputVariable(name="output", description="", enabled=True, minimum=0.000, maximum=1.000, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("line1", [-1.000, -1.000], engine), fl.Linear("line2", [1.000, -1.000], engine) ]) ] engine.rule_blocks = [ fl.RuleBlock(name="", description="", enabled=True, conjunction=None, disjunction=None, implication=None, activation=fl.General(), rules=[ fl.Rule.create("if input is low then output is line1", engine), fl.Rule.create("if input is high then output is line2", engine) ]) ]
enabled=True, minimum=-0.785, maximum=0.785, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("out1mf1", [0.000, 0.000, 1.000, 0.000], engine), fl.Linear("out1mf2", [0.000, 1.000, 0.000, 0.000], engine) ]) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=None, disjunction=None, implication=None, activation=fl.General(), rules=[ fl.Rule.create("if distance is near then control is out1mf1", engine), fl.Rule.create("if distance is far then control is out1mf2", engine) ]) ]
) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=fl.Minimum(), disjunction=None, implication=None, activation=fl.General(), rules=[ fl.Rule.create("if LDLLevel is Low and HDLLevel is LowHDL then HeartDiseaseRisk is MediumRisk", engine), fl.Rule.create("if LDLLevel is Low and HDLLevel is ModerateHDL then HeartDiseaseRisk is LowRisk", engine), fl.Rule.create("if LDLLevel is Low and HDLLevel is HighHDL then HeartDiseaseRisk is NoRisk", engine), fl.Rule.create("if LDLLevel is LowBorderline and HDLLevel is LowHDL then HeartDiseaseRisk is MediumRisk", engine), fl.Rule.create("if LDLLevel is LowBorderline and HDLLevel is ModerateHDL then HeartDiseaseRisk is LowRisk", engine), fl.Rule.create("if LDLLevel is LowBorderline and HDLLevel is HighHDL then HeartDiseaseRisk is LowRisk", engine), fl.Rule.create("if LDLLevel is Borderline and HDLLevel is LowHDL then HeartDiseaseRisk is HighRisk", engine), fl.Rule.create("if LDLLevel is Borderline and HDLLevel is ModerateHDL then HeartDiseaseRisk is MediumRisk", engine), fl.Rule.create("if LDLLevel is Borderline and HDLLevel is HighHDL then HeartDiseaseRisk is LowRisk", engine), fl.Rule.create("if LDLLevel is HighBorderline and HDLLevel is LowHDL then HeartDiseaseRisk is HighRisk", engine), fl.Rule.create("if LDLLevel is HighBorderline and HDLLevel is ModerateHDL then HeartDiseaseRisk is HighRisk", engine), fl.Rule.create("if LDLLevel is HighBorderline and HDLLevel is HighHDL then HeartDiseaseRisk is MediumRisk", engine), fl.Rule.create("if LDLLevel is High and HDLLevel is LowHDL then HeartDiseaseRisk is ExtremeRisk", engine), fl.Rule.create("if LDLLevel is High and HDLLevel is ModerateHDL then HeartDiseaseRisk is HighRisk", engine), fl.Rule.create("if LDLLevel is High and HDLLevel is HighHDL then HeartDiseaseRisk is MediumRisk", engine) ] ) ]
def test_engine(self) -> None: engine = fl.Engine( name="engine", description="an engine", input_variables=[ fl.InputVariable(name="input_variable", description="an input variable", minimum=0, maximum=1, terms=[fl.Triangle("A")]) ], output_variables=[ fl.OutputVariable(name="output_variable", description="an output variable", minimum=0, maximum=1, terms=[fl.Triangle("A")]) ], rule_blocks=[ fl.RuleBlock(name="rb", description="a rule block", rules=[fl.Rule.create("if a then z")]) ]) self.assertEqual(fl.PythonExporter().to_string(engine), fl.PythonExporter().engine(engine)) self.assertEqual(second=fl.PythonExporter().engine(engine), first="""\ import fuzzylite as fl engine = fl.Engine( name="engine", description="an engine" ) engine.input_variables = [ fl.InputVariable( name="input_variable", description="an input variable", enabled=True, minimum=0, maximum=1, lock_range=False, terms=[fl.Triangle("A", nan, nan, nan)] ) ] engine.output_variables = [ fl.OutputVariable( name="output_variable", description="an output variable", enabled=True, minimum=0, maximum=1, lock_range=False, aggregation=None, defuzzifier=None, lock_previous=False, terms=[fl.Triangle("A", nan, nan, nan)] ) ] engine.rule_blocks = [ fl.RuleBlock( name="rb", description="a rule block", enabled=True, conjunction=None, disjunction=None, implication=None, activation=None, rules=[fl.Rule.create("if a then z", engine)] ) ] """)
fl.RuleBlock( name="mamdani", description="mamdani inference", enabled=True, conjunction=fl.Minimum(), disjunction=fl.Maximum(), implication=fl.Minimum(), activation=fl.General(), rules=[ fl.Rule.create( "if dist is tocant and var_dist is molt_gran_neg then POWER is max", engine), fl.Rule.create( "if dist is tocant and var_dist is gran_neg then POWER is molta", engine), fl.Rule.create( "if dist is tocant and var_dist is petita_neg then POWER is bastant", engine), fl.Rule.create( "if dist is tocant and var_dist is zero then POWER is una_mica", engine), fl.Rule.create( "if dist is tocant and var_dist is positiva then POWER is res", engine), fl.Rule.create( "if dist is a_prop and var_dist is molt_gran_neg then POWER is molta", engine), fl.Rule.create( "if dist is a_prop and var_dist is gran_neg then POWER is bastant", engine), fl.Rule.create( "if dist is a_prop and var_dist is petita_neg then POWER is una_mica", engine), fl.Rule.create( "if dist is a_prop and var_dist is zero then POWER is una_mica", engine), fl.Rule.create( "if dist is a_prop and var_dist is positiva then POWER is res", engine), fl.Rule.create( "if dist is lluny and var_dist is molt_gran_neg then POWER is bastant", engine), fl.Rule.create( "if dist is lluny and var_dist is gran_neg then POWER is una_mica", engine), fl.Rule.create( "if dist is lluny and var_dist is petita_neg then POWER is una_mica", engine), fl.Rule.create( "if dist is lluny and var_dist is zero then POWER is res", engine), fl.Rule.create( "if dist is lluny and var_dist is positiva then POWER is res", engine), fl.Rule.create( "if dist is molt_lluny and var_dist is molt_gran_neg then POWER is una_mica", engine), fl.Rule.create( "if dist is molt_lluny and var_dist is gran_neg then POWER is una_mica", engine), fl.Rule.create( "if dist is molt_lluny and var_dist is petita_neg then POWER is una_mica", engine), fl.Rule.create( "if dist is molt_lluny and var_dist is zero then POWER is res", engine), fl.Rule.create( "if dist is molt_lluny and var_dist is positiva then POWER is res", engine) ])
fl.RuleBlock( name="", description="", enabled=True, conjunction=fl.AlgebraicProduct(), disjunction=None, implication=None, activation=fl.General(), rules=[ fl.Rule.create( "if in_n1 is in1mf1 and in_n2 is in2mf1 then out1 is out1mf1", engine), fl.Rule.create( "if in_n1 is in1mf1 and in_n2 is in2mf2 then out1 is out1mf2", engine), fl.Rule.create( "if in_n1 is in1mf1 and in_n2 is in2mf3 then out1 is out1mf3", engine), fl.Rule.create( "if in_n1 is in1mf2 and in_n2 is in2mf1 then out1 is out1mf4", engine), fl.Rule.create( "if in_n1 is in1mf2 and in_n2 is in2mf2 then out1 is out1mf5", engine), fl.Rule.create( "if in_n1 is in1mf2 and in_n2 is in2mf3 then out1 is out1mf6", engine), fl.Rule.create( "if in_n1 is in1mf3 and in_n2 is in2mf1 then out1 is out1mf7", engine), fl.Rule.create( "if in_n1 is in1mf3 and in_n2 is in2mf2 then out1 is out1mf8", engine), fl.Rule.create( "if in_n1 is in1mf3 and in_n2 is in2mf3 then out1 is out1mf9", engine) ])
fl.RuleBlock( name="", description="", enabled=True, conjunction=fl.Minimum(), disjunction=fl.Maximum(), implication=fl.Minimum(), activation=fl.General(), rules=[ fl.Rule.create( "if temp is cold and flow is soft then cold is openSlow and hot is openFast", engine), fl.Rule.create( "if temp is cold and flow is good then cold is closeSlow and hot is openSlow", engine), fl.Rule.create( "if temp is cold and flow is hard then cold is closeFast and hot is closeSlow", engine), fl.Rule.create( "if temp is good and flow is soft then cold is openSlow and hot is openSlow", engine), fl.Rule.create( "if temp is good and flow is good then cold is steady and hot is steady", engine), fl.Rule.create( "if temp is good and flow is hard then cold is closeSlow and hot is closeSlow", engine), fl.Rule.create( "if temp is hot and flow is soft then cold is openFast and hot is openSlow", engine), fl.Rule.create( "if temp is hot and flow is good then cold is openSlow and hot is closeSlow", engine), fl.Rule.create( "if temp is hot and flow is hard then cold is closeSlow and hot is closeFast", engine) ])
enabled=True, minimum=0.000, maximum=1.000, lock_range=False, aggregation=fl.Maximum(), defuzzifier=fl.Centroid(200), lock_previous=False, terms=[ fl.Triangle("LOW", 0.000, 0.250, 0.500), fl.Triangle("MEDIUM", 0.250, 0.500, 0.750), fl.Triangle("HIGH", 0.500, 0.750, 1.000) ]) ] engine.rule_blocks = [ fl.RuleBlock(name="", description="", enabled=True, conjunction=None, disjunction=None, implication=fl.Minimum(), activation=fl.General(), rules=[ fl.Rule.create("if Ambient is DARK then Power is HIGH", engine), fl.Rule.create( "if Ambient is MEDIUM then Power is MEDIUM", engine), fl.Rule.create("if Ambient is BRIGHT then Power is LOW", engine) ]) ]
fl.RuleBlock( name="", description="", enabled=True, conjunction=fl.AlgebraicProduct(), disjunction=None, implication=None, activation=fl.General(), rules=[ fl.Rule.create( "if input1 is in1mf1 and input2 is in2mf1 then output is out1mf1", engine), fl.Rule.create( "if input1 is in1mf1 and input2 is in2mf2 then output is out1mf2", engine), fl.Rule.create( "if input1 is in1mf1 and input2 is in2mf3 then output is out1mf3", engine), fl.Rule.create( "if input1 is in1mf1 and input2 is in2mf4 then output is out1mf4", engine), fl.Rule.create( "if input1 is in1mf1 and input2 is in2mf5 then output is out1mf5", engine), fl.Rule.create( "if input1 is in1mf1 and input2 is in2mf6 then output is out1mf6", engine), fl.Rule.create( "if input1 is in1mf2 and input2 is in2mf1 then output is out1mf7", engine), fl.Rule.create( "if input1 is in1mf2 and input2 is in2mf2 then output is out1mf8", engine), fl.Rule.create( "if input1 is in1mf2 and input2 is in2mf3 then output is out1mf9", engine), fl.Rule.create( "if input1 is in1mf2 and input2 is in2mf4 then output is out1mf10", engine), fl.Rule.create( "if input1 is in1mf2 and input2 is in2mf5 then output is out1mf11", engine), fl.Rule.create( "if input1 is in1mf2 and input2 is in2mf6 then output is out1mf12", engine), fl.Rule.create( "if input1 is in1mf3 and input2 is in2mf1 then output is out1mf13", engine), fl.Rule.create( "if input1 is in1mf3 and input2 is in2mf2 then output is out1mf14", engine), fl.Rule.create( "if input1 is in1mf3 and input2 is in2mf3 then output is out1mf15", engine), fl.Rule.create( "if input1 is in1mf3 and input2 is in2mf4 then output is out1mf16", engine), fl.Rule.create( "if input1 is in1mf3 and input2 is in2mf5 then output is out1mf17", engine), fl.Rule.create( "if input1 is in1mf3 and input2 is in2mf6 then output is out1mf18", engine), fl.Rule.create( "if input1 is in1mf4 and input2 is in2mf1 then output is out1mf19", engine), fl.Rule.create( "if input1 is in1mf4 and input2 is in2mf2 then output is out1mf20", engine), fl.Rule.create( "if input1 is in1mf4 and input2 is in2mf3 then output is out1mf21", engine), fl.Rule.create( "if input1 is in1mf4 and input2 is in2mf4 then output is out1mf22", engine), fl.Rule.create( "if input1 is in1mf4 and input2 is in2mf5 then output is out1mf23", engine), fl.Rule.create( "if input1 is in1mf4 and input2 is in2mf6 then output is out1mf24", engine), fl.Rule.create( "if input1 is in1mf5 and input2 is in2mf1 then output is out1mf25", engine), fl.Rule.create( "if input1 is in1mf5 and input2 is in2mf2 then output is out1mf26", engine), fl.Rule.create( "if input1 is in1mf5 and input2 is in2mf3 then output is out1mf27", engine), fl.Rule.create( "if input1 is in1mf5 and input2 is in2mf4 then output is out1mf28", engine), fl.Rule.create( "if input1 is in1mf5 and input2 is in2mf5 then output is out1mf29", engine), fl.Rule.create( "if input1 is in1mf5 and input2 is in2mf6 then output is out1mf30", engine), fl.Rule.create( "if input1 is in1mf6 and input2 is in2mf1 then output is out1mf31", engine), fl.Rule.create( "if input1 is in1mf6 and input2 is in2mf2 then output is out1mf32", engine), fl.Rule.create( "if input1 is in1mf6 and input2 is in2mf3 then output is out1mf33", engine), fl.Rule.create( "if input1 is in1mf6 and input2 is in2mf4 then output is out1mf34", engine), fl.Rule.create( "if input1 is in1mf6 and input2 is in2mf5 then output is out1mf35", engine), fl.Rule.create( "if input1 is in1mf6 and input2 is in2mf6 then output is out1mf36", engine) ])
lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("cheap", [0.000, 0.000, 5.000], engine), fl.Linear("average", [0.000, 0.000, 15.000], engine), fl.Linear("generous", [0.000, 0.000, 25.000], engine) ]) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=None, disjunction=fl.Maximum(), implication=None, activation=fl.General(), rules=[ fl.Rule.create( "if service is poor or food is rancid then tip is cheap", engine), fl.Rule.create("if service is average then tip is average", engine), fl.Rule.create( "if service is good or food is delicious then tip is generous", engine) ]) ]
terms=[ fl.Constant("Low", 10.000), fl.Constant("Medium", 15.000), fl.Constant("High", 20.000) ] ) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=fl.EinsteinProduct(), disjunction=None, implication=None, activation=fl.General(), rules=[ fl.Rule.create("if FoodQuality is extremely Bad and Service is extremely Bad then CheapTip is extremely Low and AverageTip is very Low and GenerousTip is Low", engine), fl.Rule.create("if FoodQuality is Good and Service is extremely Bad then CheapTip is Low and AverageTip is Low and GenerousTip is Medium", engine), fl.Rule.create("if FoodQuality is very Good and Service is very Bad then CheapTip is Low and AverageTip is Medium and GenerousTip is High", engine), fl.Rule.create("if FoodQuality is Bad and Service is Bad then CheapTip is Low and AverageTip is Low and GenerousTip is Medium", engine), fl.Rule.create("if FoodQuality is Good and Service is Bad then CheapTip is Low and AverageTip is Medium and GenerousTip is High", engine), fl.Rule.create("if FoodQuality is extremely Good and Service is Bad then CheapTip is Low and AverageTip is Medium and GenerousTip is very High", engine), fl.Rule.create("if FoodQuality is Bad and Service is Good then CheapTip is Low and AverageTip is Medium and GenerousTip is High", engine), fl.Rule.create("if FoodQuality is Good and Service is Good then CheapTip is Medium and AverageTip is Medium and GenerousTip is very High", engine), fl.Rule.create("if FoodQuality is very Bad and Service is very Good then CheapTip is Low and AverageTip is Medium and GenerousTip is High", engine), fl.Rule.create("if FoodQuality is very very Good and Service is very very Good then CheapTip is High and AverageTip is very High and GenerousTip is extremely High", engine) ] ) ]
lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("Automatic"), lock_previous=False, terms=[fl.Function.create("diff", "fabs(outputFx-trueFx)", engine)] ) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=None, disjunction=None, implication=None, activation=fl.General(), rules=[ fl.Rule.create("if inputX is NEAR_1 then outputFx is f1", engine), fl.Rule.create("if inputX is NEAR_2 then outputFx is f2", engine), fl.Rule.create("if inputX is NEAR_3 then outputFx is f3", engine), fl.Rule.create("if inputX is NEAR_4 then outputFx is f4", engine), fl.Rule.create("if inputX is NEAR_5 then outputFx is f5", engine), fl.Rule.create("if inputX is NEAR_6 then outputFx is f6", engine), fl.Rule.create("if inputX is NEAR_7 then outputFx is f7", engine), fl.Rule.create("if inputX is NEAR_8 then outputFx is f8", engine), fl.Rule.create("if inputX is NEAR_9 then outputFx is f9", engine), fl.Rule.create("if inputX is any then trueFx is fx and diffFx is diff", engine) ] ) ]
fl.Bell("negBig", -5.000, 1.670, 8.000), fl.Bell("negSmall", -1.670, 1.670, 8.000), fl.Bell("posSmall", 1.670, 1.670, 8.000), fl.Bell("posBig", 5.000, 1.670, 8.000) ]) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=fl.Minimum(), disjunction=fl.Maximum(), implication=fl.Minimum(), activation=fl.General(), rules=[ fl.Rule.create( "if angle is small and velocity is small then force is negBig", engine), fl.Rule.create( "if angle is small and velocity is big then force is negSmall", engine), fl.Rule.create( "if angle is big and velocity is small then force is posSmall", engine), fl.Rule.create( "if angle is big and velocity is big then force is posBig", engine) ]) ]
description="", enabled=True, minimum=0.000, maximum=30.000, lock_range=False, aggregation=fl.Maximum(), defuzzifier=fl.Centroid(200), lock_previous=False, terms=[ fl.Triangle("cheap", 0.000, 5.000, 10.000), fl.Triangle("average", 10.000, 15.000, 20.000), fl.Triangle("generous", 20.000, 25.000, 30.000) ]) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=fl.Minimum(), disjunction=fl.Maximum(), implication=fl.Minimum(), activation=fl.General(), rules=[ fl.Rule.create("if service is poor then tip is cheap", engine), fl.Rule.create("if service is good then tip is average", engine), fl.Rule.create("if service is excellent then tip is generous", engine) ]) ]
maximum=1.000, lock_range=False, aggregation=fl.Maximum(), defuzzifier=fl.WeightedAverage("Automatic"), lock_previous=False, terms=[fl.Constant("left", 0.333), fl.Constant("right", 0.666)]) ] engine.rule_blocks = [ fl.RuleBlock(name="mamdani", description="", enabled=True, conjunction=None, disjunction=None, implication=fl.AlgebraicProduct(), activation=fl.General(), rules=[ fl.Rule.create("if obstacle is left then mSteer is right", engine), fl.Rule.create("if obstacle is right then mSteer is left", engine) ]), fl.RuleBlock( name="takagiSugeno", description="", enabled=True, conjunction=None, disjunction=None, implication=None, activation=fl.General(), rules=[
terms=[ fl.Constant("close_fast", -0.900), fl.Constant("close_slow", -0.500), fl.Constant("no_change", 0.000), fl.Constant("open_slow", 0.300), fl.Constant("open_fast", 0.900) ]) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=fl.AlgebraicProduct(), disjunction=None, implication=None, activation=fl.General(), rules=[ fl.Rule.create("if level is okay then valve is no_change", engine), fl.Rule.create("if level is low then valve is open_fast", engine), fl.Rule.create("if level is high then valve is close_fast", engine), fl.Rule.create( "if level is okay and rate is positive then valve is close_slow", engine), fl.Rule.create( "if level is okay and rate is negative then valve is open_slow", engine) ]) ]
fl.RuleBlock( name="mamdani", description="", enabled=True, conjunction=fl.Minimum(), disjunction=fl.Maximum(), implication=fl.Minimum(), activation=fl.General(), rules=[ # Left laser near section fl.Rule.create("if Left_Laser is near and Right_Laser is near and Front_Laser is near \ then Rotation is very_right and Velocity is reverse", avoidance_engine), fl.Rule.create("if Left_Laser is near and Right_Laser is near and Front_Laser is medium \ then Rotation is straight_ahead and Velocity is normal", avoidance_engine), fl.Rule.create("if Left_Laser is near and Right_Laser is near and Front_Laser is far \ then Rotation is straight_ahead and Velocity is fast", avoidance_engine), fl.Rule.create("if Left_Laser is near and Right_Laser is medium and Front_Laser is near \ then Rotation is very_right and Velocity is reverse", avoidance_engine), fl.Rule.create("if Left_Laser is near and Right_Laser is medium and Front_Laser is medium \ then Rotation is right and Velocity is slow", avoidance_engine), fl.Rule.create("if Left_Laser is near and Right_Laser is medium and Front_Laser is far \ then Rotation is very_right and Velocity is normal", avoidance_engine), fl.Rule.create("if Left_Laser is near and Right_Laser is far and Front_Laser is near \ then Rotation is very_right and Velocity is reverse", avoidance_engine), fl.Rule.create("if Left_Laser is near and Right_Laser is far and Front_Laser is medium \ then Rotation is very_right and Velocity is slow", avoidance_engine), fl.Rule.create("if Left_Laser is near and Right_Laser is far and Front_Laser is far \ then Rotation is very_right and Velocity is normal", avoidance_engine), # Left laser medium fl.Rule.create("if Left_Laser is medium and Right_Laser is near and Front_Laser is near \ then Rotation is very_left and Velocity is reverse", avoidance_engine), fl.Rule.create("if Left_Laser is medium and Right_Laser is near and Front_Laser is medium \ then Rotation is very_left and Velocity is slow", avoidance_engine), fl.Rule.create("if Left_Laser is medium and Right_Laser is near and Front_Laser is far \ then Rotation is very_left and Velocity is slow", avoidance_engine), fl.Rule.create("if Left_Laser is medium and Right_Laser is medium and Front_Laser is near \ then Rotation is very_right and Velocity is reverse", avoidance_engine), fl.Rule.create("if Left_Laser is medium and Right_Laser is medium and Front_Laser is medium \ then Rotation is right and Velocity is normal", avoidance_engine), fl.Rule.create("if Left_Laser is medium and Right_Laser is medium and Front_Laser is far \ then Rotation is very_right and Velocity is normal", avoidance_engine), fl.Rule.create("if Left_Laser is medium and Right_Laser is far and Front_Laser is near \ then Rotation is very_right and Velocity is reverse", avoidance_engine), fl.Rule.create("if Left_Laser is medium and Right_Laser is far and Front_Laser is medium \ then Rotation is very_right and Velocity is slow", avoidance_engine), fl.Rule.create("if Left_Laser is medium and Right_Laser is far and Front_Laser is far \ then Rotation is very_right and Velocity is normal", avoidance_engine), # Left laser far fl.Rule.create("if Left_Laser is far and Right_Laser is near and Front_Laser is near \ then Rotation is very_left and Velocity is reverse", avoidance_engine), fl.Rule.create("if Left_Laser is far and Right_Laser is near and Front_Laser is medium \ then Rotation is very_left and Velocity is slow", avoidance_engine), fl.Rule.create("if Left_Laser is far and Right_Laser is near and Front_Laser is far \ then Rotation is very_left and Velocity is normal", avoidance_engine), fl.Rule.create("if Left_Laser is far and Right_Laser is medium and Front_Laser is near \ then Rotation is very_left and Velocity is reverse", avoidance_engine), fl.Rule.create("if Left_Laser is far and Right_Laser is medium and Front_Laser is medium \ then Rotation is left and Velocity is normal", avoidance_engine), fl.Rule.create("if Left_Laser is far and Right_Laser is medium and Front_Laser is far \ then Rotation is left and Velocity is normal", avoidance_engine), fl.Rule.create("if Left_Laser is far and Right_Laser is far and Front_Laser is near \ then Rotation is very_right and Velocity is reverse", avoidance_engine), fl.Rule.create("if Left_Laser is far and Right_Laser is far and Front_Laser is medium \ then Rotation is right and Velocity is normal", avoidance_engine), fl.Rule.create("if Left_Laser is far and Right_Laser is far and Front_Laser is far \ then Rotation is straight_ahead and Velocity is normal", avoidance_engine), ] )
fl.Linear("FifteenPercent", [0.000, 0.000, 15.000], engine), fl.Linear("TwentyPercent", [0.000, 0.000, 20.000], engine) ]) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=fl.Minimum(), disjunction=None, implication=None, activation=fl.General(), rules=[ fl.Rule.create( "if FoodQuality is Bad and Service is Bad then Tip is TenPercent", engine), fl.Rule.create( "if FoodQuality is Bad and Service is Good then Tip is FifteenPercent", engine), fl.Rule.create( "if FoodQuality is Good and Service is Bad then Tip is FifteenPercent", engine), fl.Rule.create( "if FoodQuality is Good and Service is Good then Tip is TwentyPercent", engine) ]) ]
lock_range=False, aggregation=fl.Maximum(), defuzzifier=fl.Centroid(200), lock_previous=False, terms=[ fl.Triangle("close_fast", -1.000, -0.900, -0.800), fl.Triangle("close_slow", -0.600, -0.500, -0.400), fl.Triangle("no_change", -0.100, 0.000, 0.100), fl.Triangle("open_slow", 0.400, 0.500, 0.600), fl.Triangle("open_fast", 0.800, 0.900, 1.000) ] ) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=fl.AlgebraicProduct(), disjunction=fl.AlgebraicSum(), implication=fl.AlgebraicProduct(), activation=fl.General(), rules=[ fl.Rule.create("if level is low then valve is open_fast", engine), fl.Rule.create("if level is high then valve is close_fast", engine), fl.Rule.create("if level is good and change is rising then valve is close_slow", engine), fl.Rule.create("if level is good and change is falling then valve is open_slow", engine) ] ) ]
fl.RuleBlock( name="", description="", enabled=True, conjunction=fl.Minimum(), disjunction=fl.Maximum(), implication=fl.Minimum(), activation=fl.General(), rules=[ fl.Rule.create("if AllInputTerms is A then AllOutputTerms is T", engine), fl.Rule.create("if AllInputTerms is B then AllOutputTerms is S", engine), fl.Rule.create("if AllInputTerms is C then AllOutputTerms is R", engine), fl.Rule.create("if AllInputTerms is D then AllOutputTerms is Q", engine), fl.Rule.create("if AllInputTerms is E then AllOutputTerms is P", engine), fl.Rule.create("if AllInputTerms is F then AllOutputTerms is O", engine), fl.Rule.create("if AllInputTerms is G then AllOutputTerms is N", engine), fl.Rule.create("if AllInputTerms is H then AllOutputTerms is M", engine), fl.Rule.create("if AllInputTerms is I then AllOutputTerms is L", engine), fl.Rule.create("if AllInputTerms is J then AllOutputTerms is K", engine), fl.Rule.create("if AllInputTerms is K then AllOutputTerms is J", engine), fl.Rule.create("if AllInputTerms is L then AllOutputTerms is I", engine), fl.Rule.create("if AllInputTerms is M then AllOutputTerms is H", engine), fl.Rule.create("if AllInputTerms is N then AllOutputTerms is G", engine), fl.Rule.create("if AllInputTerms is O then AllOutputTerms is F", engine), fl.Rule.create("if AllInputTerms is P then AllOutputTerms is E", engine), fl.Rule.create("if AllInputTerms is Q then AllOutputTerms is D", engine), fl.Rule.create("if AllInputTerms is R then AllOutputTerms is C", engine), fl.Rule.create("if AllInputTerms is S then AllOutputTerms is B", engine), fl.Rule.create("if AllInputTerms is T then AllOutputTerms is A", engine) ])
engine.output_variables = [ fl.OutputVariable(name="steer", description="direction to steer the vehicle to", enabled=True, minimum=0.000000000, maximum=1.000000000, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Constant("left", 0.333000000), fl.Constant("right", 0.666500000) ]) ] engine.rule_blocks = [ fl.RuleBlock(name="steer_away", description="steer away from obstacles", enabled=True, conjunction=None, disjunction=None, implication=None, activation=fl.General(), rules=[ fl.Rule.create("if obstacle is left then steer is right", engine), fl.Rule.create("if obstacle is right then steer is left", engine) ]) ]
-354.770, -113.680, 327.650, 85.270, -1.000, -3.010, 0.000, 0.000 ], engine) ]) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="", enabled=True, conjunction=None, disjunction=None, implication=None, activation=fl.General(), rules=[ fl.Rule.create("if pole_length is mf1 then out is outmf1", engine), fl.Rule.create("if pole_length is mf2 then out is outmf2", engine), fl.Rule.create("if pole_length is mf3 then out is outmf3", engine), fl.Rule.create("if pole_length is mf4 then out is outmf4", engine), fl.Rule.create("if pole_length is mf5 then out is outmf5", engine), fl.Rule.create("if pole_length is mf6 then out is outmf6", engine), fl.Rule.create("if pole_length is mf7 then out is outmf7", engine), fl.Rule.create("if pole_length is mf8 then out is outmf8", engine), fl.Rule.create("if pole_length is mf9 then out is outmf9", engine), fl.Rule.create("if pole_length is mf10 then out is outmf10", engine), fl.Rule.create("if pole_length is mf11 then out is outmf11", engine) ]) ]