def test_term(self) -> None: term: fl.Term = fl.Triangle("A", 0.0, 1.0, 2.0, 0.5) self.assertEqual(fl.PythonExporter().to_string(term), fl.PythonExporter().term(term)) self.assertEqual(fl.PythonExporter().term(term), "fl.Triangle(\"A\", 0.000, 1.000, 2.000, 0.500)") term = fl.Discrete("B", [0.0, 0.0, 0.5, 1.0, 1.0, 0.0]) self.assertEqual(fl.PythonExporter().to_string(term), fl.PythonExporter().term(term)) self.assertEqual( fl.PythonExporter().term(term), "fl.Discrete(\"B\", [0.000, 0.000, 0.500, 1.000, 1.000, 0.000])") term = fl.Function("C", "x + 1") self.assertEqual(fl.PythonExporter().to_string(term), fl.PythonExporter().term(term)) self.assertEqual(fl.PythonExporter().term(term), "fl.Function.create(\"C\", \"x + 1\", engine)") term = fl.Linear("D", [0.0, 1.0, 2.0, -fl.inf, fl.inf]) self.assertEqual(fl.PythonExporter().to_string(term), fl.PythonExporter().term(term)) self.assertEqual( fl.PythonExporter().term(term), "fl.Linear(\"D\", [0.000, 1.000, 2.000, -fl.inf, fl.inf], engine)")
fl.Gaussian("low", -5.000, 4.000), fl.Gaussian("high", 5.000, 4.000) ]) ] 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",
minimum=-0.785, maximum=0.785, lock_range=False) ] engine.output_variables = [ fl.OutputVariable(name="control", description="", 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",
fl.Bell("in2mf6", 17.910, 0.824, 1.734) ]) ] engine.output_variables = [ fl.OutputVariable( name="output", description="", enabled=True, minimum=0.000, maximum=3.100, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("out1mf1", [-0.048, 1.456, 2.222], engine), fl.Linear("out1mf2", [-0.218, -0.305, 2.042], engine), fl.Linear("out1mf3", [0.026, -0.141, 3.067], engine), fl.Linear("out1mf4", [0.052, -0.150, 3.419], engine), fl.Linear("out1mf5", [0.113, -0.189, 4.339], engine), fl.Linear("out1mf6", [2.543, 0.361, -2.738], engine), fl.Linear("out1mf7", [2.517, -6.809, 23.353], engine), fl.Linear("out1mf8", [-0.208, -0.394, 4.472], engine), fl.Linear("out1mf9", [-0.046, -0.300, 4.452], engine), fl.Linear("out1mf10", [-0.006, -0.217, 4.195], engine), fl.Linear("out1mf11", [0.089, -0.254, 4.992], engine), fl.Linear("out1mf12", [-0.033, 0.103, -2.012], engine), fl.Linear("out1mf13", [1.355, 1.228, -5.678], engine), fl.Linear("out1mf14", [-0.245, -0.124, 3.753], engine), fl.Linear("out1mf15", [-0.099, -0.111, 3.304], engine), fl.Linear("out1mf16", [-0.052, -0.163, 3.560], engine),
]) ] engine.output_variables = [ fl.OutputVariable( name="out", description="", enabled=True, minimum=-10.000, maximum=10.000, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("outmf1", [ 168.400, 31.000, -188.050, -49.250, -1.000, -2.700, 0.000, 0.000 ], engine), fl.Linear("outmf2", [ 233.950, 47.190, -254.520, -66.580, -1.000, -2.740, 0.000, 0.000 ], engine), fl.Linear("outmf3", [ 342.940, 74.730, -364.370, -95.230, -1.000, -2.780, 0.000, 0.000 ], engine), fl.Linear("outmf4", [ 560.710, 130.670, -582.960, -152.240, -1.000, -2.810, 0.000, 0.000 ], engine), fl.Linear("outmf5", [ 1213.880, 300.190, -1236.900, -322.800, -1.000, -2.840, 0.000,
fl.Trapezoid("Bad", 0.000, 1.000, 3.000, 7.000), fl.Trapezoid("Good", 3.000, 7.000, 10.000, 11.000) ]) ] engine.output_variables = [ fl.OutputVariable(name="Tip", description="", enabled=True, minimum=10.000, maximum=20.000, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("TenPercent", [0.000, 0.000, 10.000], 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(),
] ) ] engine.output_variables = [ fl.OutputVariable( name="output", description="", enabled=True, minimum=0.000, maximum=1.500, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("out1mf1", [-0.912, 2.517, 0.061], engine), fl.Linear("out1mf2", [-2.153, -2.204, -4.037], engine), fl.Linear("out1mf3", [-0.107, -0.148, 1.920], engine), fl.Linear("out1mf4", [-0.088, -0.071, 1.593], engine), fl.Linear("out1mf5", [-0.098, -0.040, 1.361], engine), fl.Linear("out1mf6", [-0.068, -0.027, 1.617], engine), fl.Linear("out1mf7", [-1.901, -0.081, 0.185], engine), fl.Linear("out1mf8", [16.651, 11.713, 6.803], engine), fl.Linear("out1mf9", [-4.152, -1.033, -4.755], engine), fl.Linear("out1mf10", [-0.123, 0.004, 0.861], engine), fl.Linear("out1mf11", [-0.102, 0.006, 0.816], engine), fl.Linear("out1mf12", [-0.089, 0.038, 0.515], engine), fl.Linear("out1mf13", [-0.074, 0.082, -0.061], engine), fl.Linear("out1mf14", [-0.009, -0.173, 4.841], engine), fl.Linear("out1mf15", [-7.995, -2.818, 17.910], engine), fl.Linear("out1mf16", [0.674, 0.745, -2.167], engine),
fl.Triangle("right", 0.333000000, 0.666000000, 1.000000000) ]) ] 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.Linear("left", [0.000000000, 0.333000000], engine), fl.Linear("right", [0.000000000, 0.666500000], engine) ]) ] 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.Trapezoid("delicious", 7.000, 9.000, 10.000, 15.000) ]) ] engine.output_variables = [ fl.OutputVariable(name="tip", description="", enabled=True, minimum=-30.000, maximum=30.000, 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(
fl.Triangle("AboutFour", 3.000, 4.000, 5.000), fl.Triangle("AboutFive", 4.000, 5.000, 6.000) ]) ] engine.output_variables = [ fl.OutputVariable(name="ApproxXCubed", description="", enabled=True, minimum=-5.000, maximum=5.000, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("TangentatNegFive", [75.000, 250.000], engine), fl.Linear("TangentatNegFour", [48.000, 128.000], engine), fl.Linear("TangentatNegThree", [27.000, 54.000], engine), fl.Linear("TangentatNegTwo", [12.000, 16.000], engine), fl.Linear("TangentatNegOne", [3.000, 2.000], engine), fl.Linear("TangentatZero", [0.000, 0.000], engine), fl.Linear("TangentatOne", [3.000, -2.000], engine), fl.Linear("TangentatTwo", [12.000, -16.000], engine), fl.Linear("TangentatThree", [27.000, -54.000], engine), fl.Linear("TangentatFour", [48.000, -128.000], engine), fl.Linear("TangentatFive", [75.000, -250.000],
0.875000000) ]) ] engine.output_variables = [ fl.OutputVariable( name="out1", description="", enabled=True, minimum=-0.334000000, maximum=1.000000000, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("out1mf1", [-0.035000000, 0.002000000, -0.352000000], engine), fl.Linear("out1mf2", [0.044000000, 0.079000000, -0.028000000], engine), fl.Linear("out1mf3", [-0.024000000, 0.024000000, -1.599000000], engine), fl.Linear("out1mf4", [-0.067000000, 0.384000000, 0.007000000], engine), fl.Linear("out1mf5", [0.351000000, -0.351000000, -3.663000000], engine), fl.Linear("out1mf6", [-0.079000000, -0.044000000, 3.909000000], engine), fl.Linear("out1mf7", [0.012000000, -0.012000000, -0.600000000], engine), fl.Linear("out1mf8", [-0.384000000, 0.067000000, 10.158000000], engine), fl.Linear("out1mf9", [-0.002000000, 0.035000000, -1.402000000],
fl.Bell("in4mf2", 3.000, 3.000, 2.000) ]) ] engine.output_variables = [ fl.OutputVariable( name="out", description="", enabled=True, minimum=-10.000, maximum=10.000, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("outmf1", [41.373, 10.030, 3.162, 4.288, 0.339], engine), fl.Linear("outmf2", [40.409, 10.053, 3.162, 4.288, 0.207], engine), fl.Linear("outmf3", [41.373, 10.030, 3.162, 4.288, 0.339], engine), fl.Linear("outmf4", [40.409, 10.053, 3.162, 4.288, 0.207], engine), fl.Linear("outmf5", [38.561, 10.177, 3.162, 4.288, -0.049], engine), fl.Linear("outmf6", [37.596, 10.154, 3.162, 4.288, -0.181], engine), fl.Linear("outmf7", [38.561, 10.177, 3.162, 4.288, -0.049], engine), fl.Linear("outmf8", [37.596, 10.154, 3.162, 4.288, -0.181], engine), fl.Linear("outmf9", [37.596, 10.154, 3.162, 4.288, 0.181], engine), fl.Linear("outmf10", [38.561, 10.177, 3.162, 4.288, 0.049], engine), fl.Linear("outmf11", [37.596, 10.154, 3.162, 4.288, 0.181],
fl.Bell("in4mf2", 0.400, 0.400, 2.000) ]) ] engine.output_variables = [ fl.OutputVariable( name="out", description="", enabled=True, minimum=-10.000, maximum=10.000, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("outmf1", [1.015, 2.234, -12.665, -4.046, 0.026], engine), fl.Linear("outmf2", [1.161, 1.969, -9.396, -6.165, 0.474], engine), fl.Linear("outmf3", [1.506, 2.234, -12.990, -1.865, 1.426], engine), fl.Linear("outmf4", [0.734, 1.969, -9.381, -4.688, -0.880], engine), fl.Linear("outmf5", [0.734, 2.234, -12.853, -6.110, -1.034], engine), fl.Linear("outmf6", [1.413, 1.969, -9.485, -6.592, 1.159], engine), fl.Linear("outmf7", [1.225, 2.234, -12.801, -3.929, 0.366], engine), fl.Linear("outmf8", [0.985, 1.969, -9.291, -5.115, -0.195], engine), fl.Linear("outmf9", [0.985, 1.969, -9.292, -5.115, 0.195], engine), fl.Linear("outmf10", [1.225, 2.234, -12.802, -3.929, -0.366], engine),
fl.Bell("in1mf4", 2.727, 1.214, 2.047) ]) ] engine.output_variables = [ fl.OutputVariable( name="out1", description="", enabled=True, minimum=-10.000, maximum=10.000, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("out1mf1", [0.155, -2.228, -8.974], engine), fl.Linear("out1mf2", [-0.312, -7.705, -9.055], engine), fl.Linear("out1mf3", [-0.454, -4.437, 6.930], engine), fl.Linear("out1mf4", [0.248, -1.122, 5.081], engine), fl.Linear("out1mf5", [-6.278, 25.211, 99.148], engine), fl.Linear("out1mf6", [5.531, 105.916, 157.283], engine), fl.Linear("out1mf7", [19.519, 112.333, -127.796], engine), fl.Linear("out1mf8", [-5.079, 34.738, -143.414], engine), fl.Linear("out1mf9", [-5.889, 27.311, 116.585], engine), fl.Linear("out1mf10", [21.517, 97.266, 93.802], engine), fl.Linear("out1mf11", [9.198, 79.853, -118.482], engine), fl.Linear("out1mf12", [-6.571, 23.026, -87.747], engine), fl.Linear("out1mf13", [0.092, -1.126, -4.527], engine), fl.Linear("out1mf14", [-0.304, -4.434, -6.561], engine), fl.Linear("out1mf15", [-0.166, -6.284, 7.307], engine), fl.Linear("out1mf16", [0.107, -2.028, 8.159], engine)
fl.Gaussian("large", 1.500, 0.200) ]) ] engine.output_variables = [ fl.OutputVariable( name="out", description="", enabled=True, minimum=-10.000, maximum=10.000, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("outmf1", [32.166, 5.835, 3.162, 3.757, 0.000, 0.000], engine), fl.Linear("outmf2", [39.012, 9.947, 3.162, 4.269, 0.000, 0.000], engine), fl.Linear("outmf3", [45.009, 13.985, 3.162, 4.666, 0.000, 0.000], engine) ]) ] engine.rule_blocks = [ fl.RuleBlock(name="", description="", enabled=True, conjunction=None, disjunction=None, implication=None, activation=fl.General(), rules=[
] ) ] engine.output_variables = [ fl.OutputVariable( name="theta", description="", enabled=True, minimum=0.000, maximum=0.000, lock_range=False, aggregation=None, defuzzifier=fl.WeightedAverage("TakagiSugeno"), lock_previous=False, terms=[ fl.Linear("out1mf", [-0.022, -0.500, 0.315], engine), fl.Linear("out1mf", [-0.022, -0.500, 0.315], engine), fl.Linear("out1mf", [-0.022, -0.500, 0.315], engine), fl.Linear("out1mf", [0.114, -0.500, 0.785], engine), fl.Linear("out1mf", [0.114, -0.500, 0.785], engine), fl.Linear("out1mf", [0.114, -0.500, 0.785], engine), fl.Linear("out1mf", [-0.022, -0.500, 1.256], engine), fl.Linear("out1mf", [-0.022, -0.500, 1.256], engine), fl.Linear("out1mf", [-0.022, -0.500, 1.256], engine) ] ) ] engine.rule_blocks = [ fl.RuleBlock( name="", description="",