-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslate_dimacs.py
37 lines (31 loc) · 942 Bytes
/
translate_dimacs.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
import sys
input = sys.stdin.read()
words = input.split("resultdimacs: ")
# transform comment lines into dictionary
translator = dict()
commentlines = list(filter(lambda x: len(x) != 0 and x[0] == "c", words[0].split("\n")))
for c in commentlines:
if "->" in c:
items = c[2:].split('->') # chop off first two chars & split by the arrow
sat = items[0].strip()
dimacs = int(items[1])
translator[dimacs] = sat
# loop through each result & translate using dictionary
results = words[1].split(" 0\n")
numsat = len(results)-1 # remove empty trail
for n in range(numsat):
clauses = results[n].split()
# print("SOL_CODE:")
for clause in clauses:
c = int(clause.strip())
neg = False
if c < 0:
c = -c
neg = True
if c in translator:
sat_code = translator[c]
to_add = "~"+sat_code if neg else sat_code
print(" " + to_add + " ",end="")
print("\n")
# print("NUMSAT: " + str(numsat) )
# sys.stdout.write(sat_out)