Skip to content

Commit 4f90350

Browse files
committed
using single script
1 parent 38f75aa commit 4f90350

9 files changed

Lines changed: 504 additions & 39 deletions

File tree

.github/workflows/build.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,29 @@ jobs:
3333
- name: Sample Hashcount run
3434
run: |
3535
cd scripts
36-
python run_hashcount_on_modelcounting.py -i mccmc2021_track1_058.cnf
36+
python run_hashcount.py -i mccmc2021_track1_058.cnf
3737
3838
- name: Sample Hashcount run
3939
run: |
4040
cd scripts
41-
python run_hashcount_on_itemmining.py -i vote.cnf
41+
python run_hashcount.py -i minimal_vote.cnf
4242
4343
- name: Sample ProjEnum Run
4444
run: |
4545
cd scripts
4646
python run_projenum.py -i mccmc2021_track1_058.cnf
4747
48+
- name: Sample ProjEnum Run
49+
run: |
50+
cd scripts
51+
python run_projenum.py -i minimal_vote.cnf
52+
53+
- name: Sample MinLB Run
54+
run: |
55+
cd scripts
56+
python run_minlb.py -i mccmc2021_track1_058.cnf
57+
4858
- name: Sample MinLB Run
4959
run: |
5060
cd scripts
51-
python run_minlb.py -i mccmc2021_track1_058.cnf
61+
python run_minlb.py -i minimal_vote.cnf

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ First `cd scripts`:
3636

3737
The command to run ``HashCount`` on model counting benchmark:
3838
```
39-
python run_hashcount_on_modelcounting.py -i mccmc2021_track1_058.cnf
40-
```
41-
The command to run ``HashCount`` on item mining benchmark:
42-
```
43-
python run_hashcount_on_itemmining.py -i vote.cnf
39+
python run_hashcount.py -i mccmc2021_track1_058.cnf
4440
```
4541

4642
## Run ProjEnum

scripts/compute_dlp.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,23 @@ def compute_disjunctive_program(file_name):
1111
file_pointer = open(file_name, 'r')
1212
output_file_pointer = open(output_file, 'w')
1313
for line in file_pointer:
14-
if line.startswith("c"):
15-
continue
16-
elif line.startswith("p cnf"):
14+
if line.startswith("p cnf"):
1715
l = line.split()
1816
output_file_pointer.write("%rule size: {0}\n".format(int(l[-1])))
1917
# print("The number of literals: {0} and clauses: {1} [Unpreprocessed]".format(l[-2], l[-1]))
18+
elif line.startswith("c ind"):
19+
# for some benchmarks (e.g., item mining), we can compute independent support easily
20+
# prepare independent support file
21+
IS_file = open("IS_dlp_" + file_name, 'w')
22+
numbers = [int(x) for x in line.split()[2:] if int(x) != 0]
23+
IS_str = "c ind "
24+
for item in numbers:
25+
IS_str += "v{0} ".format(item)
26+
IS_str += "0\n"
27+
IS_file.write(IS_str)
28+
IS_file.close()
29+
elif line.startswith("c"):
30+
continue
2031
else:
2132
l = line.split()
2233
lit_list = []

scripts/minimal_vote.cnf

Lines changed: 437 additions & 0 deletions
Large diffs are not rendered by default.

scripts/propagator.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,36 @@
3535

3636
transaction_id += 1
3737

38-
asp_file_name = "dlp_" + file_name
39-
IS_file_name = "IS_dlp_" + file_name
38+
# asp_file_name = "dlp_" + file_name
39+
# IS_file_name = "IS_dlp_" + file_name
4040
cut_file_name = "minimal_" + file_name
41-
asp_file = open(asp_file_name, 'w')
42-
IS_file = open(IS_file_name, 'w')
41+
# asp_file = open(asp_file_name, 'w')
42+
# IS_file = open(IS_file_name, 'w')
4343
cut_file = open(cut_file_name, 'w')
4444
cut_str = "p cnf {0} {1}\n".format(int(max(union_of_items)) + transaction_id - 1, transaction_id - 1)
4545
cut_file.write(cut_str)
4646
transaction_id = int(max(union_of_items))
4747

48+
IS_str = "c ind "
49+
for item in union_of_items:
50+
IS_str += "{0} ".format(item)
51+
IS_str += "0\n"
52+
cut_file.write(IS_str)
53+
4854
for index, transaction in enumerate(transaction_items):
49-
rule_str = "t({0})".format(index + 1)
55+
# rule_str = "t({0})".format(index + 1)
5056
clause_str = "{0} ".format(transaction_id + index + 1)
5157
if len(transaction_items) > 0:
52-
rule_str += "".join("; i(" + str(_) + ")" for _ in transaction)
58+
# rule_str += "".join("; i(" + str(_) + ")" for _ in transaction)
5359
clause_str += "".join(str(_) + " " for _ in transaction)
54-
rule_str += ".\n"
60+
# rule_str += ".\n"
5561
clause_str += "0\n"
56-
asp_file.write(rule_str)
62+
# asp_file.write(rule_str)
5763
cut_file.write(clause_str)
5864

5965

60-
IS_str = "c ind "
61-
for item in union_of_items:
62-
IS_str += "i({0}) ".format(item)
63-
IS_str += "0\n"
64-
IS_file.write(IS_str)
65-
IS_file.close()
66-
asp_file.close()
66+
# IS_file.close()
67+
# asp_file.close()
6768
cut_file.close()
6869

6970
# ctl.load(asp_file_name)
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ def run(cmd, timeout, ttl = 3, silent = False):
2626
os.system("cp {0} {1}".format(args.i, temp_file))
2727
input_file = os.path.basename(temp_file)
2828

29+
if os.path.exists(f"IS_dlp_{input_file}"):
30+
os.remove(f"IS_dlp_{input_file}")
31+
2932
cmd = 'python compute_dlp.py -i {0}'.format(input_file)
3033
out = run(cmd, 100)
31-
# print(" === Computing independent suport === ")
32-
cmd = 'python compute_independent_support.py -i dlp_{0}'.format(input_file)
33-
out = run(cmd, 250)
34+
if not os.path.exists(f"IS_dlp_{input_file}"):
35+
# print(" === Computing independent suport === ")
36+
cmd = 'python compute_independent_support.py -i dlp_{0}'.format(input_file)
37+
out = run(cmd, 250)
38+
3439
# print(" === Running HashCount === ")
3540
cmd = './hashcount --useind IS_dlp_{0} --asp dlp_{0}'.format(input_file)
3641
out = run(cmd, 5000)
@@ -42,6 +47,6 @@ def run(cmd, timeout, ttl = 3, silent = False):
4247
print("hashcount: {0}".format(line))
4348

4449
if cnt is None:
45-
print("No estimate found in the hashcount.")
50+
print("No estimate found from hashcount.")
4651

4752
os.system(f'rm -f {input_file} dlp_{input_file} IS_dlp_{input_file}')

scripts/run_hashcount_on_itemmining.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ def run(cmd, timeout, ttl = 3, silent = False):
3939
print("hashcount: {0}".format(line))
4040

4141
if cnt is None:
42-
print("No estimate found in the hashcount.")
42+
print("No estimate found from hashcount.")
4343

4444
os.system(f'rm -f {input_file} IS_dlp_{input_file} dlp_{input_file}')

scripts/run_minlb.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import subprocess as sp
33
parser = argparse.ArgumentParser()
44
parser.add_argument('-i','--i', help='input CNF file', required=True)
5+
parser.add_argument('-thresh','--thresh', help='threshold cut size', default=25, required=False)
56
args = parser.parse_args()
67
file_name = args.i
78

@@ -26,6 +27,9 @@ def run(cmd, timeout, ttl = 3, silent = False):
2627
os.system("cp {0} {1}".format(args.i, temp_file))
2728
input_file = os.path.basename(temp_file)
2829

30+
if os.path.exists(f"IS_dlp_{input_file}"):
31+
os.remove(f"IS_dlp_{input_file}")
32+
2933
cmd = 'python compute_dlp.py -i {0}'.format(input_file)
3034
out = run(cmd, 100)
3135
# print(" === Computing a cut === ")
@@ -36,7 +40,7 @@ def run(cmd, timeout, ttl = 3, silent = False):
3640
# out = run(cmd, 100)
3741

3842
cut_size = None
39-
threshold = 50
43+
threshold = int(args.thresh)
4044
cut_string = ""
4145
for line in out.splitlines():
4246
if line.startswith("c the size of cut:"):
@@ -70,12 +74,13 @@ def run(cmd, timeout, ttl = 3, silent = False):
7074
if cnt is None:
7175
print("No estimate found in the projenum.")
7276

73-
os.system(f'rm -f {input_file} cut_{input_file} minimal_{input_file}')
77+
os.system(f'rm -f {input_file} cut_{input_file} dlp_{input_file} minimal_{input_file}')
7478
else:
75-
# we can run Hashcount
76-
# print(" === Computing independent suport === ")
77-
cmd = 'python compute_independent_support.py -i dlp_{0}'.format(input_file)
78-
out = run(cmd, 250)
79+
# we run Hashcount
80+
if not os.path.exists(f"IS_dlp_{input_file}"):
81+
# print(" === Computing independent suport === ")
82+
cmd = 'python compute_independent_support.py -i dlp_{0}'.format(input_file)
83+
out = run(cmd, 250)
7984
# print(" === Running HashCount === ")
8085
cmd = './hashcount --useind IS_dlp_{0} --asp dlp_{0}'.format(input_file)
8186
out = run(cmd, 5000)
@@ -90,4 +95,4 @@ def run(cmd, timeout, ttl = 3, silent = False):
9095
if cnt is None:
9196
print("No estimate found in the hashcount.")
9297

93-
os.system(f'rm -f {input_file} dlp_{input_file} IS_dlp_{input_file}')
98+
os.system(f'rm -f {input_file} dlp_{input_file} IS_dlp_{input_file} minimal_{input_file} {new_input_file}')

scripts/run_minlb_on_itemmining.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def run(cmd, timeout, ttl = 3, silent = False):
3131

3232
out = run(cmd, 100)
3333
# print(" === Computing a cut === ")
34-
cmd = './td -decot 100 -decow 100 -tmpdir . -cs 3500 minimal_{0}'.format(input_file)
34+
cmd = './td -decot 100 -decow 100 -tmpdir . -cs 4000 minimal_{0}'.format(input_file)
3535
out = run(cmd, 120)
3636
cut_size = None
3737
cut_string = ""

0 commit comments

Comments
 (0)