0% found this document useful (0 votes)
12 views5 pages

Assignment AI T

The document implements a fuzzy logic system to determine tips based on quality and service ratings. It defines fuzzy variables, membership functions, and rules for calculating tips, and tests the system with five different cases. The output shows the computed tip amounts for each test case.

Uploaded by

shakibtuhin8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

Assignment AI T

The document implements a fuzzy logic system to determine tips based on quality and service ratings. It defines fuzzy variables, membership functions, and rules for calculating tips, and tests the system with five different cases. The output shows the computed tip amounts for each test case.

Uploaded by

shakibtuhin8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import numpy as np

import skfuzzy as fuzz


from skfuzzy import control as ctrl
import [Link] as plt

# Define fuzzy variables


quality = [Link]([Link](0, 11, 1), 'quality')
service = [Link]([Link](0, 11, 1), 'service')
tip = [Link]([Link](0, 26, 1), 'tip')

# Membership functions
quality['very poor'] = [Link]([Link], [0, 0, 1])
quality['poor'] = [Link]([Link], [0, 0, 5])
quality['acceptable'] = [Link]([Link], [0, 5, 10])
quality['amazing'] = [Link]([Link], [5, 10, 10])
quality['very amazing'] = [Link]([Link], [10, 10, 10])

service['very bad'] = [Link]([Link], [0, 0, 1])


service['bad'] = [Link]([Link], [0, 0, 5])
service['decent'] = [Link]([Link], [0, 5, 10])
service['great'] = [Link]([Link], [5, 10, 10])
service['very great'] = [Link]([Link], [10, 10, 10])

tip['low'] = [Link]([Link], [0, 0, 13])


tip['medium'] = [Link]([Link], [0, 13, 25])
tip['high'] = [Link]([Link], [13, 25, 25])

# Define 9 rules
rule1 = [Link](quality['very poor'] & service['very bad'],
tip['low'])
rule2 = [Link](quality['very poor'] & service['bad'], tip['low'])
rule3 = [Link](quality['poor'] & service['decent'], tip['low'])
rule4 = [Link](quality['acceptable'] & service['decent'],
tip['medium'])
rule5 = [Link](quality['acceptable'] & service['great'],
tip['medium'])
rule6 = [Link](quality['amazing'] & service['decent'], tip['high'])
rule7 = [Link](quality['amazing'] & service['great'], tip['high'])
rule8 = [Link](quality['very amazing'] & service['great'],
tip['high'])
rule9 = [Link](quality['very amazing'] & service['very great'],
tip['high'])

# Control system
tipping_ctrl = [Link]([
rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9
])
tipping = [Link](tipping_ctrl)

# 5 manually defined test cases


print("\nTest Case 1:")
[Link]['quality'] = 1
[Link]['service'] = 1
[Link]()
print(f"Tip: {[Link]['tip']:.2f}")
[Link](sim=tipping)

print("\nTest Case 2:")


[Link]['quality'] = 2
[Link]['service'] = 5
[Link]()
print(f"Tip: {[Link]['tip']:.2f}")
[Link](sim=tipping)

print("\nTest Case 3:")


[Link]['quality'] = 5
[Link]['service'] = 5
[Link]()
print(f"Tip: {[Link]['tip']:.2f}")
[Link](sim=tipping)

print("\nTest Case 4:")


[Link]['quality'] = 8
[Link]['service'] = 7
[Link]()
print(f"Tip: {[Link]['tip']:.2f}")
[Link](sim=tipping)

print("\nTest Case 5:")


[Link]['quality'] = 10
[Link]['service'] = 10
[Link]()
print(f"Tip: {[Link]['tip']:.2f}")
[Link](sim=tipping)

Test Case 1:
Tip: 11.91

Test Case 2:
Tip: 10.33

Test Case 3:
Tip: 12.67

Test Case 4:
Tip: 14.72

Test Case 5:
Tip: 21.00

You might also like