File: brave-lua.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 (46 lines) | stat: -rw-r--r-- 877 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
35
36
37
38
39
40
41
42
43
44
45
46
#script(lua)

Model, SolveResult = gringo.Model, gringo.SolveResult

brave = {}

function on_model(m)
    for _, x in ipairs(m:atoms(Model.ATOMS)) do
        if x:name() == "holds" then
            brave[tostring(x:args()[1])] = true
        end
    end
end

function is_brave(x)
    if brave[tostring(x)] then
        return 1
    else
        return 0
    end
end

function main(prg)
    local n = 0
    prg:ground({{"base", {}}})
    while prg:solve(nil, on_model) == SolveResult.SAT do
        if n > 10 then break end
        n = n + 1
        prg:ground({{"brave", {}}})
    end
    local ans = ""
    for x, _ in pairs(brave) do
        if ans ~= "" then
            ans = ans .. ", "
        end
        ans = ans .. tostring(x)
    end
    print(string.format("brave consequences: %s", ans))
end

#end.

#program brave.

:- not holds(X) : atom(X), @is_brave(X) == 0.