forked from zhaoyu-li/G4SATBench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_stats.py
56 lines (42 loc) · 1.59 KB
/
calc_stats.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
import argparse
import glob
import os
import networkx as nx
import networkx.algorithms.community as nx_comm
import glob
import random
from tqdm import tqdm
from g4satbench.utils.utils import parse_cnf_file, VIG, VCG, LCG, clean_clauses
from collections import defaultdict
terms = ['n_vars', 'n_clauses', 'vig-clustering_coefficient', 'vig-modularity', 'vcg-modularity', 'lcg-modularity']
def calc_stats(f):
n_vars, clauses = parse_cnf_file(f)
clauses = clean_clauses(clauses)
vig = VIG(n_vars, clauses)
vcg = VCG(n_vars, clauses)
lcg = LCG(n_vars, clauses)
return {
'n_vars': n_vars,
'n_clauses': len(clauses),
'vig-clustering_coefficient': nx.average_clustering(vig),
'vig-modularity': nx_comm.modularity(vig, nx_comm.louvain_communities(vig)),
'vcg-modularity': nx_comm.modularity(vcg, nx_comm.louvain_communities(vcg)),
'lcg-modularity': nx_comm.modularity(lcg, nx_comm.louvain_communities(lcg)),
}
def main():
parser = argparse.ArgumentParser()
parser.add_argument('data_dir', type=str, help='Directory with sat data')
opts = parser.parse_args()
print(opts)
print('Calculating statistics...')
all_files = sorted(glob.glob(opts.data_dir + '/**/*.cnf', recursive=True))
all_files = [os.path.abspath(f) for f in all_files if 'augmented' not in f]
stats = defaultdict(int)
for f in tqdm(all_files):
s = calc_stats(f)
for t in terms:
stats[t] += s[t]
for t in terms:
print('%30s\t%10.2f' % (t, stats[t] / len(all_files)))
if __name__ == '__main__':
main()