-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
42 lines (36 loc) · 1.46 KB
/
test.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
import os
import pandas as pd
from utils import *
from main import *
def get_files_size_ordered(dirpath):
return sorted((os.path.join(basedir, filename)
for basedir, dirs, files in os.walk(dirpath) for filename in files),
key=os.path.getsize)
def main():
args = arguments()
df = pd.DataFrame(
columns=['file', 'nodes', 'edges', 'clique_size', 'time'])
files = get_files_size_ordered('test/')
try:
for f in files:
graph = read_dimacs_graph(f)
try:
with time_limit(args.time):
solution, extime = branch_and_bound(graph).solve()
df = df.append({'file': f,
'nodes': graph.number_of_nodes(),
'edges': graph.number_of_edges(),
'clique_size': solution[0],
'time': extime
}, ignore_index=True)
except Exception:
df = df.append({'file': f,
'nodes': graph.number_of_nodes(),
'edges': graph.number_of_edges(),
'clique_size': '-',
'time': 'Timeout'
}, ignore_index=True)
finally:
df.to_csv('test_results.csv', index=False, sep='|')
if __name__ == '__main__':
main()