PRINCIPLES OF SOFT COMPUTING LAB-8
Snehalatha - AP21110011455
CSE-U
Write python Program to realize Fuzzy Sets arithmetic.
CODE:
# Define Fuzzy Set class
class FuzzySet:
def __init__(self, elements):
[Link] = elements
def union(self, other):
result = {}
for element in [Link]() | [Link]():
result[element] = max([Link](element, 0), [Link](element, 0))
return FuzzySet(result)
def intersection(self, other):
result = {}
for element in [Link]() & [Link]():
result[element] = min([Link][element], [Link][element])
return FuzzySet(result)
def complement(self):
result = {element: 1 - membership for element, membership in [Link]()}
return FuzzySet(result)
def __repr__(self):
return str([Link])
A = FuzzySet({'x1': 0.5, 'x2': 0.8, 'x3': 0.2})
B = FuzzySet({'x1': 0.6, 'x2': 0.4, 'x3': 0.9})
print("Fuzzy Set A:", A)
print("Fuzzy Set B:", B)
union_result = [Link](B)
print("Union of A and B:", union_result)
intersection_result = [Link](B)
print("Intersection of A and B:", intersection_result)
complement_result = [Link]()
print("Complement of A:", complement_result)
OUTPUT:
Fuzzy Set A: {'x1': 0.5, 'x2': 0.8, 'x3': 0.2}
Fuzzy Set B: {'x1': 0.6, 'x2': 0.4, 'x3': 0.9}
Union of A and B: {'x1': 0.6, 'x2': 0.8, 'x3': 0.9}
Intersection of A and B: {'x1': 0.5, 'x2': 0.4, 'x3': 0.2}
Complement of A: {'x1': 0.5, 'x2': 0.19999999999999996, 'x3': 0.8}