-
Notifications
You must be signed in to change notification settings - Fork 1
/
calculateComplexity.py
89 lines (74 loc) · 2.6 KB
/
calculateComplexity.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
87
88
89
import os
from statistics import mean
import numpy as np
def getfileList(targetfolderpath):
names = []
Allfile = {}
# for dirpath in os.walk(targetfolderpath):
# i = 1
# print(Allfile)
NodeList = os.listdir(targetfolderpath)
for node in NodeList:
new_path = targetfolderpath + "/" + str(node)
edgelist = os.listdir(new_path)
edgelist.sort()
Allfile[node] = edgelist
return Allfile
node_num_all = []
edge_num_all = []
node_num_mean = []
edge_num_mean = []
nodeBigger100 = [0,0,0]
for i in range(1, 4):
node_num = []
edge_num = []
path = f"RandomCaseFiles/Section_{i}"
AllFileInOneSection = getfileList(path)
for NodeInfo in AllFileInOneSection.keys():
j = 0
GraphListInfo = AllFileInOneSection[NodeInfo]
li = [ii for ii, x in enumerate(NodeInfo) if x == "_"]
node = int(NodeInfo[li[0]+1: li[1]])
node_num.append(node)
if node >= 100:
nodeBigger100[i-1] += 10
while j < len(AllFileInOneSection[NodeInfo]):
control_graph_path = f"RandomCaseFiles/Section_{i}/{NodeInfo}/{GraphListInfo[j]}"
flow_graph_path = f"RandomCaseFiles/Section_{i}/{NodeInfo}/{GraphListInfo[j+1]}"
valve_txt = f"RandomCaseFiles/Section_{i}/{NodeInfo}/{GraphListInfo[j+2]}"
index1 = GraphListInfo[j].index('|')
index2 = GraphListInfo[j].index('_')
edge_num.append(int(GraphListInfo[j][index1+1: index2]))
j += 3
print(node_num)
print(edge_num)
node_num_mean.append(mean(node_num))
edge_num_mean.append(mean(edge_num))
node_num_all.append(node_num)
edge_num_all.append(edge_num)
folder_path = f"RandomCaseFiles/"
complexity_all = []
for i in range(len(edge_num_all)):
for count in range(len(edge_num_all[i])):
comp = edge_num_all[i][count] + node_num_all[i][count//10] * 2
complexity_all.append(comp)
# average edge and node number for each cluster
edge_num_avg = []
for ii in edge_num_all:
edge_num_avg.append(mean(ii))
node_num_avg = []
for ii in node_num_all:
node_num_avg.append(mean(ii))
print("Average Node number: ", node_num_mean)
print("Average Edge number: ", edge_num_mean)
print("Node number bigger than 100: ", nodeBigger100)
complexity = []
for i in range(len(node_num_avg)):
complexity.append(2*node_num_avg[i]+edge_num_avg[i])
print("Average Complexity: ", complexity)
outpath = f"{folder_path}/CompleixtyInfo.txt"
if not os.path.exists(folder_path):
os.makedirs(folder_path)
with open(outpath, 'w') as f:
for ii in complexity_all:
f.writelines(f"{ii}\n")