-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbrute_force_cutting_graph.py
executable file
·43 lines (36 loc) · 1.57 KB
/
brute_force_cutting_graph.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
#!/usr/bin/env python
import argparse, glob, sys, time
from pathlib import Path
from utils import helper_funcs, graph_funcs
def parse_args():
parser = argparse.ArgumentParser()
#parser.add_argument('-p', type=str, default=None,
# help='path to DQVA directory')
parser.add_argument('-g', type=str, default=None,
help='Graph file name')
args = parser.parse_args()
return args
def main():
args = parse_args()
graphfiles = glob.glob(args.g)
for gfile in graphfiles:
graphtype = gfile.split('/')[-2]
graphname = gfile.split('/')[-1].strip('.txt')
G = graph_funcs.graph_from_file(gfile)
print('graphtype: {}, graphname: {}'.format(graphtype, graphname))
print('Loaded graph with {} nodes'.format(len(G.nodes)))
start = time.time()
opt_strs, opt_mis = helper_funcs.brute_force_search_memory_efficient(G)
end = time.time()
print('Finished brute force search in {:.3f} min'.format((end - start) / 60))
outdir = 'benchmark_graphs/brute_force_outputs/{}/'.format(graphtype)
Path(outdir).mkdir(parents=True, exist_ok=True)
outfile = outdir + graphname + '_brute_force.out'
with open(outfile, 'w') as fn:
fn.write('{}, {}\n'.format(graphtype, graphname))
fn.write('Optimal MIS is {}\n'.format(opt_mis))
fn.write('Optimal MIS:\n')
for bitstr in opt_strs:
fn.write('\t{}, valid: {}\n'.format(bitstr, graph_funcs.is_indset(bitstr, G)))
if __name__ == '__main__':
main()