MII_Labs_Mochalov_PI-33/lab12/LinguisticVariable.py

25 lines
717 B
Python
Raw Permalink Normal View History

2024-05-11 02:04:28 +04:00
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}