def run(files: Sequence[str], parts: Parts, assign: Externals = ()): ''' Loads the given files into a control object, grounds the given program parts, and assign the given externals to the given truth values. ''' ctl = Control() print(' loading files:') for file_ in files: print(f' - {file_}') ctl.load(file_) print(' grounding:') for part in parts: print(f' - {part_str(part)}') ctl.ground([part]) if assign: print(' assigning externals:') for sym, truth in assign: print(f' - {sym}={truth}') ctl.assign_external(sym, truth) print(' solutions:') ctl.solve(on_model=lambda m: print(f' - {m}'))
def main(self, ctl: Control, files: Sequence[str]): ''' The main function implementing incremental solving. ''' if not files: files = ["-"] for file_ in files: ctl.load(file_) ctl.add("check", ["t"], "#external query(t).") conf = self._conf step = 0 ret: Optional[SolveResult] = None while ((conf.imax is None or step < conf.imax) and (ret is None or step < conf.imin or ((conf.istop == "SAT" and not ret.satisfiable) or (conf.istop == "UNSAT" and not ret.unsatisfiable) or (conf.istop == "UNKNOWN" and not ret.unknown)))): parts = [] parts.append(("check", [Number(step)])) if step > 0: ctl.release_external(Function("query", [Number(step - 1)])) parts.append(("step", [Number(step)])) else: parts.append(("base", [])) ctl.ground(parts) ctl.assign_external(Function("query", [Number(step)]), True) ret, step = cast(SolveResult, ctl.solve()), step + 1