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
def run(self): ''' Runs the example. ''' ctl = Control() ctl.load("example.lp") ctl.ground([("base", [])], context=self) ctl.solve(on_model=print)
def main(self, ctl: Control, files: Sequence[str]): ''' Main function of the application. ''' for path in files: ctl.load(path) if not files: ctl.load("-") ctl.ground([("base", [])], context=self) ctl.solve()
def main(self, ctl: Control, files): prg = Program() ctl.register_observer(ProgramObserver(prg)) for f in files: ctl.load(f) if not files: ctl.load('-') ctl.ground([("base", [])]) fct, ukn = well_founded(prg) print('Facts:') print(f'{" ".join(map(str, fct))}') print('Unknown:') print(f'{" ".join(map(str, ukn))}') ctl.solve()
def main(self, ctl: Control, files: Sequence[str]): ''' Main function implementing branch and bound optimization. ''' if not files: files = ["-"] for file_ in files: ctl.load(file_) ctl.add("bound", ["b"], ":- #sum { V,I: _minimize(V,I) } >= b.") ctl.ground([("base", [])]) while cast(SolveResult, ctl.solve(on_model=self._on_model)).satisfiable: print("Found new bound: {}".format(self._bound)) ctl.ground([("bound", [Number(cast(int, self._bound))])]) if self._bound is not None: print("Optimum found")