Skip to content

Commit 2f36535

Browse files
authored
Merge pull request #9 from rkkautsar/refactor
Clean-up project and import/export feature
2 parents b8e36b4 + c0e1171 commit 2f36535

File tree

191 files changed

+4268
-4353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+4268
-4353
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,9 @@ ENV/
8787

8888
# Rope project settings
8989
.ropeproject
90+
91+
# Emacs backup files
92+
*~
93+
94+
# Benchmark-tool output
95+
output

Pipfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
lxml = "*"
10+
jinja2 = "*"
11+
12+
[requires]
13+
python_version = "3"

Pipfile.lock

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
3+
!*/
4+
!examples/*
5+
!.gitignore
6+

benchmarks/asp

Lines changed: 0 additions & 1 deletion
This file was deleted.

benchmarks/dynasp

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .clasp import clasp
2+
from .claspar import claspar
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
'''
2+
Created on Jan 17, 2010
3+
4+
@author: Roland Kaminski
5+
'''
6+
7+
import os
8+
import re
9+
import sys
10+
import codecs
11+
12+
clasp_re = {
13+
"models" : ("float", re.compile(r"^(c )?Models[ ]*:[ ]*(?P<val>[0-9]+)\+?[ ]*$")),
14+
"choices" : ("float", re.compile(r"^(c )?Choices[ ]*:[ ]*(?P<val>[0-9]+)\+?[ ]*$")),
15+
"time" : ("float", re.compile(r"^Real time \(s\): (?P<val>[0-9]+(\.[0-9]+)?)$")),
16+
"conflicts" : ("float", re.compile(r"^(c )?Conflicts[ ]*:[ ]*(?P<val>[0-9]+)\+?[ ]*\(Analyzed:[ ]*(\d+(\.\d+)?)\)")),
17+
"conflicts_analyzed" : ("float", re.compile(r"^(c )?Conflicts[ ]*:[ ]*([0-9]+)\+?[ ]*\(Analyzed:[ ]*(?P<val>\d+(\.\d+)?)\)")),
18+
"conflict": ("float", re.compile(r"^(c[ ]*)?Conflict[ ]*:[ ]*(?P<val>[0-9]+)\+?[ ]*\(Average[ ]Length:[ ]*(\d+(\.\d+)?)[ ]*Ratio:[ ]*(\d+(\.\d+)?)%[ ]*\)")),
19+
"conflict_avg_length": ("float", re.compile(r"^(c[ ]*)?Conflict[ ]*:[ ]*([0-9]+)\+?[ ]*\(Average[ ]Length:[ ]*(?P<val>\d+(\.\d+)?)[ ]*Ratio:[ ]*(\d+(\.\d+)?)%[ ]*\)")),
20+
"conflict_ratio": ("float", re.compile(r"^(c[ ]*)?Conflict[ ]*:[ ]*([0-9]+)\+?[ ]*\(Average[ ]Length:[ ]*(\d+(\.\d+)?)[ ]*Ratio:[ ]*(?P<val>\d+(\.\d+)?)%[ ]*\)")),
21+
"restarts" : ("float", re.compile(r"^(c )?Restarts[ ]*:[ ]*(?P<val>[0-9]+)\+?[ ]*")),
22+
"restarts_avg" : ("float", re.compile(r"^(c )?Restarts[ ]*:[ ]*([0-9]+)\+?[ ]*\(Average:[ ]*(?P<val>\d+(\.\d+)?)[ ]*Last:[ ]*\d+(\.\d+)?[ ]*\)")),
23+
"restarts_last" : ("float", re.compile(r"^(c )?Restarts[ ]*:[ ]*([0-9]+)\+?[ ]*\(Average:[ ]*(\d+(\.\d+)?)[ ]*Last:[ ]*(?P<val>\d+(\.\d+))?[ ]*\)")),
24+
"optimum" : ("string", re.compile(r"^(c )?Optimization[ ]*:[ ]*(?P<val>(-?[0-9]+)( -?[0-9]+)*)[ ]*$")),
25+
"status" : ("string", re.compile(r"^(s )?(?P<val>SATISFIABLE|UNSATISFIABLE|UNKNOWN|OPTIMUM FOUND)[ ]*$")),
26+
"interrupted" : ("string", re.compile(r"(c )?(?P<val>INTERRUPTED!)")),
27+
"error" : ("string", re.compile(r"^\*\*\* clasp ERROR: (?P<val>.*)$")),
28+
"memerror" : ("string", re.compile(r"^Maximum VSize (?P<val>exceeded): sending SIGTERM then SIGKILL")),
29+
"lemmas_del" : ("float", re.compile(r"^(c )?Lemmas[ ]*:[ ]*([0-9]+)\+?[ ]*\(Deleted:[ ]*(?P<val>\d+(\.\d+)?)\)")),
30+
"lemmas" : ("float", re.compile(r"^(c )?Lemmas[ ]*:[ ]*(?P<val>[0-9]+)\+?[ ]*\(Deleted:[ ]*(\d+(\.\d+)?)\)")),
31+
"lemmas_binary" : ("float", re.compile(r"^(c[ ]*)?Binary[ ]*:[ ]*(?P<val>[0-9]+)\+?[ ]*\(Ratio:[ ]*(\d+(\.\d+)?)%\)")),
32+
"lemmas_binary_ratio" : ("float", re.compile(r"^(c[ ]*)?Binary[ ]*:[ ]*([0-9]+)\+?[ ]*\(Ratio:[ ]*(?P<val>\d+(\.\d+)?)%\)")),
33+
"lemmas_ternary" : ("float", re.compile(r"^(c[ ]*)?Ternary[ ]*:[ ]*(?P<val>[0-9]+)\+?[ ]*\(Ratio:[ ]*(\d+(\.\d+)?)%\)")),
34+
"lemmas_ternary_ratio" : ("float", re.compile(r"^(c[ ]*)?Ternary[ ]*:[ ]*([0-9]+)\+?[ ]*\(Ratio:[ ]*(?P<val>\d+(\.\d+)?)%\)")),
35+
"backjumps": ("float", re.compile(r"^(c[ ]*)?Backjumps[ ]*:[ ]*(?P<val>[0-9]+)\+?[ ]*\(Average:[ ]*(\d+(\.\d+)?)[ ]*Max:[ ]*(\d+(\.\d+)?)[ ]*Sum:[ ]*(\d+(\.\d+)?)\)")),
36+
"backjumps_avg": ("float", re.compile(r"^(c[ ]*)?Backjumps[ ]*:[ ]*([0-9]+)\+?[ ]*\(Average:[ ]*(?P<val>\d+(\.\d+)?)[ ]*Max:[ ]*(\d+(\.\d+)?)[ ]*Sum:[ ]*(\d+(\.\d+)?)\)")),
37+
"backjumps_max": ("float", re.compile(r"^(c[ ]*)?Backjumps[ ]*:[ ]*([0-9]+)\+?[ ]*\(Average:[ ]*(\d+(\.\d+)?)[ ]*Max:[ ]*(?P<val>\d+(\.\d+)?)[ ]*Sum:[ ]*(\d+(\.\d+)?)\)")),
38+
"backjumps_sum": ("float", re.compile(r"^(c[ ]*)?Backjumps[ ]*:[ ]*([0-9]+)\+?[ ]*\(Average:[ ]*(\d+(\.\d+)?)[ ]*Max:[ ]*(\d+(\.\d+)?)[ ]*Sum:[ ]*(?P<val>\d+(\.\d+)?)\)")),
39+
"variables": ("float", re.compile(r"^(c[ ]*)?Variables[ ]*:[ ]*(?P<val>[0-9]+)\+?[ ]*\(Eliminated:[ ]*(\d+(\.\d+)?)[ ]*Frozen:[ ]*(\d+(\.\d+)?)[ ]*\)")),
40+
"variables_eliminated": ("float", re.compile(r"^(c[ ]*)?Variables[ ]*:[ ]*([0-9]+)\+?[ ]*\(Eliminated:[ ]*(?P<val>\d+(\.\d+)?)[ ]*Frozen:[ ]*(\d+(\.\d+)?)[ ]*\)")),
41+
"variables_frozen": ("float", re.compile(r"^(c[ ]*)?Variables[ ]*:[ ]*([0-9]+)\+?[ ]*\(Eliminated:[ ]*(\d+(\.\d+)?)[ ]*Frozen:[ ]*(?P<val>\d+(\.\d+)?)[ ]*\)")),
42+
"constraints": ("float", re.compile(r"^(c[ ]*)?Constraints[ ]*:[ ]*(?P<val>[0-9]+)\+?[ ]*\(Binary:[ ]*(\d+(\.\d+)?)%[ ]*Ternary:[ ]*(\d+(\.\d+)?)%[ ]*Other:[ ]*(\d+(\.\d+)?)%[ ]*\)")),
43+
"constraints_binary": ("float", re.compile(r"^(c[ ]*)?Constraints[ ]*:[ ]*([0-9]+)\+?[ ]*\(Binary:[ ]*(?P<val>\d+(\.\d+)?)%[ ]*Ternary:[ ]*(\d+(\.\d+)?)%[ ]*Other:[ ]*(\d+(\.\d+)?)%[ ]*\)")),
44+
"constraints_ternary": ("float", re.compile(r"^(c[ ]*)?Constraints[ ]*:[ ]*([0-9]+)\+?[ ]*\(Binary:[ ]*(\d+(\.\d+)?)%[ ]*Ternary:[ ]*(?P<val>\d+(\.\d+)?)%[ ]*Other:[ ]*(\d+(\.\d+)?)%[ ]*\)")),
45+
"constraints_other": ("float", re.compile(r"^(c[ ]*)?Constraints[ ]*:[ ]*([0-9]+)\+?[ ]*\(Binary:[ ]*(\d+(\.\d+)?)%[ ]*Ternary:[ ]*(\d+(\.\d+)?)%[ ]*Other:[ ]*(?P<val>\d+(\.\d+)?)%[ ]*\)"))
46+
}
47+
48+
def clasp(root, runspec, instance):
49+
"""
50+
Extracts some clasp statistics.
51+
"""
52+
53+
timeout = runspec.project.job.timeout
54+
res = { "time": ("float", timeout) }
55+
for f in [instance.instance + ".txt", instance.instance + ".watcher"]:
56+
#for f in [instance.instance"runsolver.solver", "runsolver.watcher"]:
57+
for line in codecs.open(os.path.join(root, f), errors='ignore', encoding='utf-8'):
58+
for val, reg in clasp_re.items():
59+
m = reg[1].match(line)
60+
if m: res[val] = (reg[0], float(m.group("val")) if reg[0] == "float" else m.group("val"))
61+
break
62+
63+
#print res["time"][1]
64+
if "memerror" in res:
65+
res["error"] = ("string", "std::bad_alloc")
66+
res["status"] = ("string", "UNKNOWN")
67+
del res["memerror"]
68+
if res["time"][1] >= timeout and not "status" in res:
69+
#res["error"] = ("string", "timeout")
70+
res["status"] = ("string", "UNKNOWN")
71+
result = []
72+
error = not "status" in res or ("error" in res and res["error"][1] != "std::bad_alloc")
73+
memout = "error" in res and res["error"][1] == "std::bad_alloc"
74+
status = res["status"][1] if "status" in res else None
75+
timedout = memout or error or status == "UNKNOWN" or (status == "SATISFIABLE" and "optimum" in res) or res["time"][1] >= timeout or "interrupted" in res;
76+
if timedout: res["time"] = ("float", timeout)
77+
if error:
78+
sys.stderr.write("*** ERROR: Run {0} failed with unrecognized status or error!\n".format(root))
79+
exit(1)
80+
result.append(("error", "float", int(error)))
81+
result.append(("timeout", "float", int(timedout)))
82+
result.append(("memout", "float", int(memout)))
83+
84+
if "optimum" in res and not " " in res["optimum"][1]:
85+
result.append(("optimum", "float", float(res["optimum"][1])))
86+
del res["optimum"]
87+
if "interrupted" in res: del res["interrupted"]
88+
if "error" in res: del res["error"]
89+
for key, val in res.items(): result.append((key, val[0], val[1]))
90+
return result

runscripts/runscript-all.xml renamed to benchmarks/examples/clasp/runscript-all.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<runscript output="output">
1+
<runscript output="benchmark/examples/clasp/output">
22

33
<machine name="houat" cpu="[email protected]" memory="24GB"/>
44
<machine name="zuse" cpu="[email protected]" memory="24GB"/>
55

6-
<config name="seq-generic" template="templates/seq-generic.sh"/>
7-
<system name="clasp" version="1.3.2" measures="clasp" config="seq-generic">
6+
<config name="seq-generic" template="benchmarks/examples/clasp/templates/seq-generic.sh"/>
7+
<system name="clasp" version="1.3.2" measures="benchmarks.examples.clasp.resultparsers.clasp" config="seq-generic">
88
<!-- optionally allows for tagging settings -->
99
<setting name="default" tag="seq" cmdline="--stats 1"/>
1010
<setting name="vsids" tag="seq" cmdline="--stats --heu=vsids 1"/>
@@ -15,26 +15,26 @@
1515
<setting name="norest" tag="seq" cmdline="--stats --restarts=no 1"/>
1616
</system>
1717

18-
<config name="pbs-generic" template="templates/pbs-generic.sh"/>
19-
<system name="claspar" version="2.1.0" measures="claspar" config="pbs-generic">
20-
<setting name="one-as" tag="par one-as" cmdline="--stats 1" ppn="2" procs="1 2 4 8" pbstemplate="templates/impi.pbs"/>
21-
<setting name="all-as" tag="par all-as" cmdline="--stats -q 0" ppn="2" procs="1 2 4 8" pbstemplate="templates/impi.pbs"/>
18+
<config name="pbs-generic" template="benchmarks/examples/clasp/templates/pbs-generic.sh"/>
19+
<system name="claspar" version="2.1.0" measures="benchmarks.examples.clasp.resultparsers.claspar" config="pbs-generic">
20+
<setting name="one-as" tag="par one-as" cmdline="--stats 1" ppn="2" procs="1 2 4 8" pbstemplate="benchmarks/examples/clasp/templates/impi.pbs"/>
21+
<setting name="all-as" tag="par all-as" cmdline="--stats -q 0" ppn="2" procs="1 2 4 8" pbstemplate="benchmarks/examples/clasp/templates/impi.pbs"/>
2222
</system>
2323

2424
<seqjob name="seq-generic" timeout="120" runs="1" parallel="8"/>
2525
<pbsjob name="pbs-generic" timeout="120" runs="1" script_mode="timeout" walltime="23:59:59"/>
2626

2727
<benchmark name="seq-suite">
28-
<folder path="benchmarks/clasp">
28+
<folder path="benchmarks/examples/clasp/instances">
2929
<ignore prefix="pigeons"/>
3030
</folder>
31-
<files path="benchmarks/clasp">
31+
<files path="benchmarks/examples/clasp/instances">
3232
<add file="pigeons/pigeonhole10-unsat.lp"/>
3333
<add file="pigeons/pigeonhole11-unsat.lp"/>
3434
</files>
3535
</benchmark>
3636
<benchmark name="pbs-suite">
37-
<folder path="benchmarks/clasp"/>
37+
<folder path="benchmarks/examples/clasp/instances"/>
3838
</benchmark>
3939

4040
<project name="clasp-big" job="seq-generic">
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sudoku_team1/sudokusolver.sh
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import sys
2+
import numpy as np
3+
4+
def convert_nativ_to_dense(N, i, j, n):
5+
n = N**2*(i-1) + N*(j-1) + (n-1) + 1
6+
return str(n) + " "
7+
8+
def read_inital_values(file_name, N):
9+
file_ptr = open(file_name)
10+
out_file = open("sudoku.cnf", "w+")
11+
i = 1
12+
for line in file_ptr.readlines():
13+
if line.startswith("|"):
14+
line = line.replace("| ", "")
15+
line = line.replace(" |" , "")
16+
line = line.replace("\n", "")
17+
numbers = line.split()
18+
for j, nn in enumerate(numbers):
19+
if nn != "_" and nn != "__" and nn != "___":
20+
nn = int(nn)
21+
out_file.write(str(convert_nativ_to_dense(N, i, j+1, nn)) + "0\n")
22+
i += 1
23+
file_ptr.close()
24+
out_file.close()
25+
26+
def get_model_information(file_name):
27+
file_ptr = open(file_name)
28+
for line in file_ptr.readlines():
29+
if "puzzle size:" in line:
30+
N_sqrt = int(line.split(" ")[-1].split("x")[-1])
31+
N = N_sqrt * N_sqrt
32+
break
33+
34+
file_ptr.close()
35+
return N, N_sqrt
36+
37+
def main():
38+
file_name = sys.argv[1]
39+
N, N_sqrt = get_model_information(file_name)
40+
read_inital_values(file_name, N)
41+
print(N_sqrt)
42+
43+
44+
45+
46+
if __name__ == "__main__":
47+
main()
48+
49+
50+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import numpy as np
2+
import sys
3+
#import birkhoff as bi
4+
5+
f = open("out.txt")
6+
nn = int(sys.argv[1])
7+
N = nn**2
8+
9+
def convert_dense_to_native(clause, N=4):
10+
clause -= 1
11+
first = clause % N**2
12+
i = (clause - (first))/N**2 + 1
13+
second = first % N
14+
j = (first - second)/N + 1
15+
n = second + 1
16+
return i, j, n
17+
18+
sodoku = np.zeros( (N, N) )
19+
for line in f.readlines():
20+
if line[0] == "v":
21+
clauses = line[2:].split(" ")
22+
for n in clauses:
23+
n = int(n)
24+
if n>0:
25+
i, j, n = convert_dense_to_native(n, N=N)
26+
sodoku[i-1][j-1] = n
27+
28+
#result = bi.birkhoff_von_neumann_decomposition(2*sodoku/(N*(N+1)))
29+
#for c, p in result:
30+
# print("coeff ", (N+1)*N*c/2)
31+
# print("m: ", p)
32+
33+
34+
35+
36+
f_out = open("result.txt", "w+")
37+
f_out.writelines("experiment: generator (Time: 0.1 s)\n")
38+
f_out.writelines("number of tasks: 1\n")
39+
f_out.writelines("task: 1\n")
40+
f_out.writelines("puzzle size: " + str(nn)+"x"+str(nn)+"\n")
41+
42+
def make_numb_str(n, N):
43+
numb_str = str(int(n))
44+
while len(numb_str) < N:
45+
numb_str = " " + numb_str
46+
return numb_str
47+
48+
a = len(str(int(np.max(sodoku))))
49+
50+
sep_line = nn*("+" + nn*a*"-" + (nn+1)*"-") + "+"
51+
for i in range(N):
52+
if (i % nn) == 0:
53+
f_out.writelines(sep_line+"\n")
54+
line = "|"
55+
for j in range(N):
56+
line += " " + make_numb_str(sodoku[i][j], a)
57+
if (j + 1 ) % nn == 0:
58+
line += " |"
59+
f_out.writelines(line+"\n")
60+
f_out.writelines(sep_line+"\n")
61+
f_out.close()
Binary file not shown.

0 commit comments

Comments
 (0)