1515
1616def solve (
1717 sentence : And [Or [Var ]],
18- extra_args : t .Sequence [str ] = []
18+ extra_args : t .Sequence [str ] = ()
1919) -> t .Optional [Model ]:
2020 """Run kissat to compute a satisfying assignment.
2121
@@ -31,7 +31,8 @@ def solve(
3131 )
3232 assert os .path .isfile (SOLVER ), "Cannot seem to find kissat solver."
3333
34- args = [SOLVER ] + extra_args
34+ args = [SOLVER ]
35+ args .extend (extra_args )
3536
3637 var_labels = dict (enumerate (sentence .vars (), start = 1 ))
3738 var_labels_inverse = {v : k for k , v in var_labels .items ()}
@@ -65,13 +66,14 @@ def solve(
6566 if 's SATISFIABLE' not in log :
6667 raise RuntimeError ("Something went wrong. Log:\n \n {}" .format (log ))
6768
68- log = [line .strip () for line in log .split ('\n ' )]
69+ log_lines = [line .strip () for line in log .split ('\n ' )]
6970
70- model = [line [2 :] for line in log if line [:2 ] == 'v ' ] # Variable lines
71- model = ' ' .join (model ).split (' ' ) # Combine lines and split out literals
72- assert '0' == model [- 1 ], "Error: Last entry should be a 0\n %s" % str (model )
73- model = model [:- 1 ]
74- model = map (int , model ) # Individual numbered literals
75- model = {var_labels [abs (lit )]: lit > 0 for lit in model }
71+ variable_lines = [line [2 :] for line in log_lines if line [:2 ] == 'v ' ]
72+ lit_strings = ' ' .join (variable_lines ).split (' ' )
73+ assert '0' == lit_strings [- 1 ], \
74+ "Error: Last entry should be a 0\n %s" % str (lit_strings )
75+ lit_strings = lit_strings [:- 1 ]
76+ literals = map (int , lit_strings ) # Individual numbered literals
77+ model = {var_labels [abs (lit )]: lit > 0 for lit in literals }
7678
7779 return model
0 commit comments