-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchecker.py
More file actions
152 lines (119 loc) · 3.91 KB
/
checker.py
File metadata and controls
152 lines (119 loc) · 3.91 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from dimacs import *
import os
from time import time
def checkBFS(f):
def checkLexBFS(G, vs): # funkcja do sprawdzania poprawności lexBFS z konspektu, poprawiona intendacja
n = len(G)
pi = [None] * n
for i, v in enumerate(vs):
pi[v] = i
for i in range(n-1):
for j in range(i+1, n-1):
Ni = G[vs[i]].out
Nj = G[vs[j]].out
verts = [pi[v] for v in Nj - Ni if pi[v] < i]
if verts:
viable = [pi[v] for v in Ni - Nj]
if not viable or min(verts) <= min(viable):
return False
return True
dirs = os.listdir("graphs-lab4/")
passed = failed = 0
i = 0
a = time()
for fol in dirs:
dir = os.listdir("graphs-lab4/" + fol)
for graph in dir:
print(graph)
V, E = loadWeightedGraph("graphs-lab4/" + fol + '/' + graph)
G, vs = f(V, E)
if checkLexBFS(G, vs):
print("Test " + str(i) + ": Passed")
passed += 1
else:
print("Test " + str(i) + ": WRONG answer")
failed += 1
i += 1
print("Time: " + str(time() - a) + " s")
print("Passed: " + str(passed))
print("Failed: " + str(failed))
def chordal_checker(f):
passed = failed = 0
dir = os.listdir("graphs-lab4/chordal")
i = 0
a = time()
for graph in dir:
print(graph)
V, E = loadWeightedGraph("graphs-lab4/chordal/" + graph)
sol = readSolution("graphs-lab4/chordal/" + graph)
res = f(V, E)
if int(res) == int(sol):
print("Test " + str(i) + ": Passed")
passed += 1
else:
print("Test " + str(i) + ": WRONG answer")
failed += 1
i += 1
print("Time: " + str(time() - a) + " s")
print("Passed: " + str(passed))
print("Failed: " + str(failed))
def maxclique_checker(f):
passed = failed = 0
dir = os.listdir("graphs-lab4/maxclique")
i = 0
a = time()
for graph in dir:
print(graph)
V, E = loadWeightedGraph("graphs-lab4/maxclique/" + graph)
sol = readSolution("graphs-lab4/maxclique/" + graph)
res = f(V, E)
if int(res) == int(sol):
print("Test " + str(i) + ": Passed")
passed += 1
else:
print("Test " + str(i) + ": WRONG answer")
failed += 1
i += 1
print("Time: " + str(time() - a) + " s")
print("Passed: " + str(passed))
print("Failed: " + str(failed))
def color_checker(f):
passed = failed = 0
dir = os.listdir("graphs-lab4/coloring")
i = 0
a = time()
for graph in dir:
print(graph)
V, E = loadWeightedGraph("graphs-lab4/coloring/" + graph)
sol = readSolution("graphs-lab4/coloring/" + graph)
res = f(V, E)
if int(res) == int(sol):
print("Test " + str(i) + ": Passed")
passed += 1
else:
print("Test " + str(i) + ": WRONG answer")
failed += 1
i += 1
print("Time: " + str(time() - a) + " s")
print("Passed: " + str(passed))
print("Failed: " + str(failed))
def min_vcover_checker(f):
passed = failed = 0
dir = os.listdir("graphs-lab4/vcover")
i = 0
a = time()
for graph in dir:
print(graph)
V, E = loadWeightedGraph("graphs-lab4/vcover/" + graph)
sol = readSolution("graphs-lab4/vcover/" + graph)
res = f(V, E)
if int(res) == int(sol):
print("Test " + str(i) + ": Passed")
passed += 1
else:
print("Test " + str(i) + ": WRONG answer")
failed += 1
i += 1
print("Time: " + str(time() - a) + " s")
print("Passed: " + str(passed))
print("Failed: " + str(failed))