-
Notifications
You must be signed in to change notification settings - Fork 0
/
crit.py
69 lines (57 loc) · 1.73 KB
/
crit.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
import sys
import bgqshared
import contextlib
import ast
offset = (-2,1,0,1,2)
class DummyFile(object):
def write(self, x): pass
@contextlib.contextmanager
def nostdout():
save_stdout = sys.stdout
sys.stdout = DummyFile()
yield
sys.stdout = save_stdout
#path_len will be a measure of how conclicted the path is
#(using that third number in the conflict links tuple)
def path_len(path, conflictlinks):
length = 0
for i in range(len(conflictlinks)):
if conflictlinks[i][0] in path:
length += conflictlinks[i][1]
return length
#create path from pt1 to pt2
def path(pt1, pt2):
l1 = list()
l1.append(pt1)
l1.append(pt2)
p = bgqshared.determineLinkSetPatrick(l1)
return p
def main(comm1,comm2):
conflict_dict = []
with nostdout():
conflict_dict = bgqshared.main(comm1,comm2,1)
comm1_points = bgqshared.readNodeSet(comm1)
max_len = 0
max_path = []
endpoints = ()
#measure each point to point distance
for x in comm1_points:
if x[4] == 1:
continue
for a in offset:
for b in offset:
for c in offset:
for d in offset:
x_prime = (x[0]+a,x[1]+b,x[2]+c,x[3]+d,0)
if x_prime in comm1_points:
p = path(x, x_prime)
l = path_len(p,conflict_dict)
if l > max_len:
max_len = l
max_path = p
endpoints = (x,x_prime)
# print endpoints
# print max_path
print "{}".format(max_len)
if __name__ == "__main__":
sys.exit(main(sys.argv[1],sys.argv[2]))