-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem.py
More file actions
55 lines (42 loc) · 1.39 KB
/
problem.py
File metadata and controls
55 lines (42 loc) · 1.39 KB
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
import sys
from node import Node
from printing import draw_graph
from mis import MinimalIndependentSet
from vc import VertexColoring
from helper import mis_violation_check, vc_violation_check
# GLOBALS
nodelist = []
def readinput(inputfile='simple'):
fil = open('input/{0}.txt'.format(inputfile), 'r')
first = fil.readline()
nodes = int(first.split(' ')[0])
edges = int(first.split(' ')[1])
print "Nodes:", nodes, "Edges:", edges
for i in range(nodes):
line = fil.readline().strip()
node = Node(int(line.split(' ')[0]), float(line.split(' ')[1]), float(line.split(' ')[2]))
nodelist.append(node)
for i in range(edges):
line = fil.readline().strip()
node1 = nodelist[int(line.split(' ')[0])]
node2 = nodelist[int(line.split(' ')[1])]
node1.addedge(node2)
node2.addedge(node1)
def main(algorithm='vc', file='simple', M=50, K=3):
# Readings
readinput(file)
# Algorithms and violationresults
if algorithm == 'vc':
VertexColoring(nodelist, M, K)
else:
MinimalIndependentSet(nodelist, M)
# Print to screen
draw_graph(nodelist)
if __name__ == '__main__':
try:
if sys.argv[1] == 'vc':
main(algorithm=sys.argv[1], file=sys.argv[2], M=int(sys.argv[3]), K=int(sys.argv[4]))
elif sys.argv[1] == 'mis':
main(algorithm=sys.argv[1], file=sys.argv[2], M=int(sys.argv[3]))
except Exception:
print 'Usage:\n\npython problem.py mis file M\n\n\t or\n\npython problem.py vc file M K'