-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuzzy.py
54 lines (48 loc) · 1.32 KB
/
fuzzy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#Main and discover centroid functions
#Matheus da Rosa
#22/09/2011
import fuzzy_input
import fuzzy_output
def discover_centroid(degree):
ret = [0]*180
num = 0
den = 0
#small curve
for i in range(0,120,10):
if (fuzzy_output.output_small(i) < degree[0]):
ret[i] = fuzzy_output.output_small(i)
else:
ret[i] = degree[0]
#medium curve
for i in range(120,140,10):
if (fuzzy_output.output_medium(i) < degree[1]):
ret[i] = fuzzy_output.output_medium(i)
else:
ret[i] = degree[1]
#big curve
for i in range(140,160,10):
if (fuzzy_output.output_big(i) < degree[2]):
ret[i] = fuzzy_output.output_big(i)
else:
ret[i] = degree[2]
#very big curve
for i in range(160,180,10):
if (fuzzy_output.output_verybig(i) < degree[3]):
ret[i] = fuzzy_output.output_verybig(i)
else:
ret[i] = degree[3]
#calculate centroid
for i in range(0,180,10):
num += ret[i]*i
den += ret[i]
return (num/den)
if __name__ == "__main__":
while 1:
val = input("Put the weight of cargo:")
vinput = [0,0,0,0]
vinput[0] = fuzzy_input.input_small(val)
vinput[1] = fuzzy_input.input_medium(val)
vinput[2] = fuzzy_input.input_big(val)
vinput[3] = fuzzy_input.input_verybig(val)
i = discover_centroid(vinput)
print "Centroide %s" %(i)