182 KiB
182 KiB
In [26]:
import numpy as np
from skfuzzy import control as ctrl
level = ctrl.Antecedent(np.arange(1.5, 9.0, 0.1), "level")
flow = ctrl.Antecedent(np.arange(0, 0.6, 0.01), "flow")
influx = ctrl.Consequent(np.arange(0, 0.6, 0.01), "influx")
In [27]:
import skfuzzy as fuzz
level["low"] = fuzz.zmf(level.universe, 2, 4)
level["average"] = fuzz.trapmf(level.universe, [2, 4, 6, 8])
level["high"] = fuzz.smf(level.universe, 6, 8)
level.view()
flow["low"] = fuzz.zmf(flow.universe, 0.2, 0.3)
flow["average"] = fuzz.trapmf(flow.universe, [0.15, 0.25, 0.35, 0.45])
flow["high"] = fuzz.smf(flow.universe, 0.3, 0.4)
flow.view()
influx["low"] = fuzz.zmf(influx.universe, 0.2, 0.3)
influx["average"] = fuzz.trapmf(influx.universe, [0.15, 0.25, 0.35, 0.45])
influx["high"] = fuzz.smf(influx.universe, 0.3, 0.4)
influx.view()
In [28]:
rule1 = ctrl.Rule(level["low"] & flow["high"], influx["high"])
rule2 = ctrl.Rule(level["low"] & flow["average"], influx["high"])
rule3 = ctrl.Rule(level["low"] & flow["low"], influx["average"])
rule4 = ctrl.Rule(level["average"] & flow["high"], influx["high"])
rule5 = ctrl.Rule(level["average"] & flow["average"], influx["average"])
rule6 = ctrl.Rule(level["average"] & flow["low"], influx["average"])
rule7 = ctrl.Rule(level["high"] & flow["high"], influx["average"])
rule8 = ctrl.Rule(level["high"] & flow["average"], influx["low"])
rule9 = ctrl.Rule(level["high"] & flow["low"], influx["low"])
rule1.view()
Out[28]:
In [29]:
influx_ctrl = ctrl.ControlSystem(
[
rule1,
rule2,
rule3,
rule4,
rule5,
rule6,
rule7,
rule8,
rule9,
]
)
influxes = ctrl.ControlSystemSimulation(influx_ctrl)
In [32]:
influxes.input["level"] = 2.5
influxes.input["flow"] = 0.4
influxes.compute()
influxes.print_state()
influxes.output["influx"]
Out[32]:
In [31]:
influx.view(sim=influxes)