25 lines
717 B
Python
25 lines
717 B
Python
from FuzzySet import FuzzySet
|
|
|
|
|
|
class LinguisticVariable:
|
|
def __init__(self, name: str):
|
|
self.name = name
|
|
self.fuzzy_sets: dict[str, FuzzySet] = {}
|
|
|
|
def add_fuzzy_set(self, name: str, a: float, b: float, c: float, d: float):
|
|
if not (a <= b <= c <= d):
|
|
return
|
|
|
|
if name in self.fuzzy_sets:
|
|
fuzzy = self.fuzzy_sets[name]
|
|
fuzzy.a = a
|
|
fuzzy.b = b
|
|
fuzzy.c = c
|
|
fuzzy.d = d
|
|
else:
|
|
self.fuzzy_sets[name] = FuzzySet(name, a, b, c, d)
|
|
return self
|
|
|
|
def get_all_supplies(self, x: float) -> dict[str, float]:
|
|
return {i: self.fuzzy_sets[i].affiliation(x) for i in self.fuzzy_sets}
|