def __init__(self, log=None): "Create a solver object." self.tempfile = tempfile.TemporaryFile() self.p = picosat.picosat_init() picosat.picosat_set_verbosity(self.p, 100) picosat.picosat_measure_all_calls(self.p) self.f = picosat.picosat_set_output(self.p, self.tempfile) self.decision_limit = -1 self.last_sat_result = None
def __call__(self, solver): """Handle Options""" pico = solver.pico if self.random_seed is not None: picosat.picosat_set_seed(pico, self.random_seed) if self.preprocessing is True: picosat.picosat_set_plain(pico, 0) else: picosat.picosat_set_plain(pico, 1) if self.propagation_limit is not None: picosat.picosat_set_propagation_limit(pico, self.propagation_limit) if self.more_important_lit is not None: for x in self.more_important_lit: lit = solver._get_var_id(x) #pylint: disable=protected-access picosat.picosat_set_more_important_lit(pico, lit) if self.less_important_lit is not None: for x in self.less_important_lit: lit = solver._get_var_id(x) #pylint: disable=protected-access picosat.picosat_set_less_important_lit(pico, lit) if self.global_default_phase is not None: picosat.picosat_set_global_default_phase(pico, self.global_default_phase) if self.output is not None: self._log_file_handler = picosat.picosat_set_output( pico, self.output) if self.enable_trace_generation: rv = picosat.picosat_enable_trace_generation(pico) if rv == 0: raise PysmtValueError("Picosat: Cannot enable Trace" " Generation") if self.verbosity > 0: picosat.picosat_set_verbosity(pico, self.verbosity)
def __call__(self, solver): """Handle Options""" pico = solver.pico if self.random_seed is not None: picosat.picosat_set_seed(pico, self.random_seed) if self.preprocessing is True: picosat.picosat_set_plain(pico, 0) else: picosat.picosat_set_plain(pico, 1) if self.propagation_limit is not None: picosat.picosat_set_propagation_limit(pico, self.propagation_limit) if self.more_important_lit is not None: for x in self.more_important_lit: lit = solver._get_var_id(x) #pylint: disable=protected-access picosat.picosat_set_more_important_lit(pico, lit) if self.less_important_lit is not None: for x in self.less_important_lit: lit = solver._get_var_id(x) #pylint: disable=protected-access picosat.picosat_set_less_important_lit(pico, lit) if self.global_default_phase is not None: picosat.picosat_set_global_default_phase(pico, self.global_default_phase) if self.output is not None: self._log_file_handler = picosat.picosat_set_output(pico, self.output) if self.enable_trace_generation: rv = picosat.picosat_enable_trace_generation(pico) if rv == 0: raise PysmtValueError("Picosat: Cannot enable Trace" " Generation") if self.verbosity > 0: picosat.picosat_set_verbosity(pico, self.verbosity)
import picosat with open("/tmp/log", "w") as fout: p = picosat.picosat_init() picosat.picosat_set_verbosity(p, 100) f = picosat.picosat_set_output(p, fout) picosat.picosat_measure_all_calls(p) picosat.picosat_inc_max_var(p) picosat.picosat_add(p, 1) picosat.picosat_add(p, -1) picosat.picosat_add(p, 0) assert picosat.picosat_sat(p, -1) == picosat.PICOSAT_SATISFIABLE picosat.picosat_message(p, 0, "End") picosat.picosat_flushout(f) picosat.picosat_reset(p) print("Done.")