#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May 15 08:50:35 2023
@author: kanizfatema
"""
def getMembershipstuffing(service):
degree = {}
if service < 0 or service > 1:
degree["small"] = 0
degree["large"] = 0
elif service <=.4:
degree["small"] = 1
degree["large"] = 0
elif service>.4 and service<.8:
degree["small"] = float((.8-service)*(1/(.8-.4)))
degree["large"] = float((service-.40)*1.0/(.80-.40))
elif service >= .80 and service <= 1:
degree["small"] = 0
degree["large"] = 1
return degree
def getMembershipfunding(food):
degree = {}
if food < 0 or food > 1:
degree["in"] = 0
degree["mar"] = 0
degree["ade"] = 0
elif food <= .2:
degree["in"] = 1
degree["mar"] = 0
degree["ade"] = 0
elif food > .2 and food < 0.4:
degree["in"] = float((.4-food)*(1/(.4-.2)))
degree["mar"] = float((food-.20)*1.0/(.40-.20))
degree["ade"] = 0
elif food >= .4 and food < 0.6:
degree["in"] = 0
degree["mar"] = 1
degree["ade"] = 0
elif food >= .6 and food < 0.8:
degree["in"] = 0
degree["mar"] = float((.8-food)*(1/(.8-.6)))
degree["ade"] = float((food-.60)*1.0/(.80-.60))
elif food >= .80 and food <= 1:
degree["in"] = 0
degree["mar"] = 0
degree["ade"] = 1
return degree
#def crispInput(val,base):
def ruleEvalationAssessment(stuffing,funding):
cheap = max(funding["ade"],stuffing["small"])
average = min(funding["mar"],stuffing["large"])
generous = funding["in"]
return cheap,average,generous
def defuzzificationAssessment(low,normal,high):
#cog formula
up = 0
down = 0
x = 0
print(low,normal,high)
while x <= 1:
d = x*100
if(x >= 0 and x <= 0.2):
up = up + d*low
down = down + low
elif (x > 0.2 and x <= 0.4):
up = up + d*max(low,normal)
down = down + max(low,normal)
elif (x > 0.4 and x <= 0.6):
up = up + d*normal
down = down + normal
elif (x > 0.6 and x <= .8):
up = up + d*max(normal,high)
down = down + max(normal,high)
else:
up = up + d*high
down = down + high
x = x + 0.1
return up/down
#input
#ser, foodd = 6, 3
funding, stuffing = 0.35, 0.6
fuzzyfunding = getMembershipfunding(funding)
fuzzystuffing = getMembershipstuffing(stuffing)
low,normal,high = ruleEvalationAssessment(fuzzystuffing,fuzzyfunding)
conAssessment = defuzzificationAssessment(low,normal,high)
print("Fuzzified Continuous Assessment: ",conAssessment)