-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.py
79 lines (69 loc) · 1.35 KB
/
check.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
#!/usr/bin/python
# coding=utf-8
import sys
import copy
import math
import random
# import argparse
"""
Adjust these parameters by hand.
the argparse package will not run on attu.cs.washington.edu
"""
gFile = str(sys.argv[1]) # test input graphs
mapFile = str(sys.argv[2]) # output mapping
def AddNode(G,a):
if(a[0] in G):
G[a[0]].append(a[1]);
else:
G[a[0]]=[a[1]];
if(not(a[1] in G)):
G[a[1]]=[];
def readGraph(fname):
f=open(fname);
G1=dict();
G2=dict();
chk=-1;
for lin in f.readlines():
l=lin.lstrip().rstrip();
l=l.split();
l=[int(a) for a in l];
if((l[0]==0) and (l[1]==0)):
chk=1;
continue;
if(chk<0):
AddNode(G1,l);
else:
AddNode(G2,l);
f.close();
return [G1,G2];
def readMap(fname):
f=open(fname);
Map=dict();
for lin in f.readlines():
l=lin.lstrip().rstrip();
l=l.split();
l=[int(a) for a in l];
Map[l[0]]=l[1];
f.close();
return Map;
def CheckMap(M,G1,G2):
try:
n = M.keys();
n1 = [M[a] for a in n];
if(not(len(n1) == len(set(n1)))):
return False;
for i in n:
for j in n:
if(not (i==j)):
if(not((j in G2[i]))==(M[j] in G1[M[i]])):
return False;
return True;
except KeyError:
print("Bad Input: Invalid Node Id");
return False;
def main():
Res=readGraph(gFile);
Map=readMap(mapFile);
print(CheckMap(Map,Res[0],Res[1]));
if __name__ == "__main__":
main()