File: iclingo-py.lp

package info (click to toggle)
gringo 4.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,260 kB
  • ctags: 10,755
  • sloc: cpp: 55,049; python: 629; yacc: 569; sh: 124; makefile: 23
file content (34 lines) | stat: -rw-r--r-- 987 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#script (python) 

from gringo import *

def on_model(model):
    print "Model: ", model.atoms()

def get(val, default):
    return val if val != None else default

def main(prg):
    imin   = get(prg.get_const("imin"), 1)
    imax   = prg.get_const("imax")
    istop  = get(prg.get_const("istop"), "SAT")
    iquery = get(prg.get_const("iquery"), 1)
    
    step = 1
    
    parts = []
    parts.append(("base", []))
    while True:
        if imax != None and step > imax: break
        parts.append(("cumulative", [step]))
        if step >= iquery: 
            parts.append(("volatile", [step]))
        prg.ground(parts)
        parts = []
        prg.release_external(Fun("query", [step-1]))
        if step >= iquery: 
            prg.assign_external(Fun("query", [step]), True)
        ret = prg.solve(None, on_model)
        if step >= imin and ((istop == "SAT" and ret == SolveResult.SAT) or (istop == "UNSAT" and ret != SolveResult.SAT)): break
        step = step+1
#end.