Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add timeout for clingo #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions gunfolds/utils/clingo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ def run_clingo(command,
"""
if pnum is None:
pnum = PNUM
ctrl = clngo.Control(["--warn=no-atom-undefined","--configuration=tweety", "-t", str(int(pnum)) + ",split", "-n", str(capsize)])
ctrl = clngo.Control(
["--warn=no-atom-undefined", "--configuration=tweety", "-t", str(int(pnum)) + ",split", "-n", str(capsize)])
if not exact:
ctrl.configuration.solve.opt_mode = "opt"
ctrl.add("base", [], command.decode())
ctrl.ground([("base", [])])
models = []
with ctrl.solve(yield_=True, async_=True) as handle:
while not handle.wait(timeout): pass
for model in handle:
models.append([str(atom) for atom in model.symbols(shown=True)])
cost = ctrl.statistics["summary"]["costs"]
Expand All @@ -57,9 +59,9 @@ def run_clingo(command,
if num_opt == 0.0:
return {}, cost
else:
return models, cost
return models, cost
return models, cost


def clingo(command, exact=True,
convert=msl_jclingo2g,
Expand Down Expand Up @@ -99,7 +101,7 @@ def clingo(command, exact=True,
timeout=timeout,
capsize=capsize,
pnum=pnum)
if result[0]=={} or result[0]==[]:
if result[0] == {} or result[0] == []:
return {}
else:
if not exact:
Expand Down