-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
86 lines (75 loc) · 2.19 KB
/
run.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import sys
from AHP import *
try:
cFile = sys.argv[1]
dFile = sys.argv[2]
except:
print("INVALID INPUT")
sys.exit()
session = AHP(cFile, dFile)
session.criList = []
session.degList = []
deg = session.degCount # 4
N = session.criCount # 9
print("Degree = " + str(deg * 2 + 1))
print("Criteria = " + str(N))
for i in range(0, N):
for j in range(i + 1, N):
print('Enter which criterion (A or B) is relatively more important:')
print('A. ' + session.criList[i])
print('B. ' + session.criList[j])
char = str(input())
print()
print('How would you describe this relative importance? ')
for k in range(1, 8):
print('[' + str(k) + '] ' + session.degList[k])
deg = int(input())
if(char == 'A'):
session.compMat[i][j] = AHP.getTFN(deg)
session.compMat[j][i] = AHP.invTFN(deg)
else:
session.compMat[i][j] = AHP.invTFN(deg)
session.compMat[j][i] = AHP.getTFN(deg)
print()
print('Fuzzy comparison matrix:')
for x in range(N):
for y in range(N):
print(str(session.compMat[x][y]), end = ' ')
print()
print()
print('Fuzzy geometric mean for each row:')
r = []
for x in range(N):
p1, p2, p3 = 1, 1, 1
for y in range(N):
p1, p2, p3 = p1 * session.compMat[x][y][0], p2 * session.compMat[x][y][1], p3 * session.compMat[x][y][2]
p1, p2, p3 = p1**(1/N), p2**(1/N), p3**(1/N)
r.append((p1, p2, p3))
print(session.criList[x] + " = " + str(r[x]))
print()
print('Relative fuzzy weight for each criterion:')
f = []
l, m, u = 0, 0, 0
for i in range(N):
l, m, u = l + r[i][0], m + r[i][1], u + r[i][2]
for i in range(N):
f.append((r[i][0] / u, r[i][1] / m, r[i][2] / l))
print(session.criList[i] + " = " + str(f[i]))
print()
print('Defuzzification by COA method:')
d = []
for i in range(N):
d.append((f[i][0] + f[i][1] + f[i][2]) / 3)
for i in range(N):
print(session.criList[i] + " = " + str(d[i]))
print()
print('Normalized weights for each criterion:')
w = []
s = 0
for i in range(N):
s = s + d[i]
for i in range(N):
w.append(d[i] / s)
for i in range(N):
print(session.criList[i] + " = " + str(w[i]))
print()