10.02.2013 Views

A User's Guide to gringo, clasp, clingo, and iclingo

A User's Guide to gringo, clasp, clingo, and iclingo

A User's Guide to gringo, clasp, clingo, and iclingo

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

following form:<br />

#base.<br />

#cumulative constant.<br />

#volatile constant.<br />

Via “#base.,” the subsequent part of a logic program is declared as static, that is, it<br />

is processed only once at the beginning of an incremental computation. In contrast,<br />

“#cumulative constant.” <strong>and</strong> “#volatile constant.” are used <strong>to</strong> declare<br />

a (symbolic) constant as a placeholder for incremental step numbers. In the<br />

parts of a logic program below a #cumulative statement, constant is in each<br />

step replaced with the current step number, <strong>and</strong> the resulting rules, facts, <strong>and</strong> integrity<br />

constraints are accumulated over a whole incremental computation. While the replacement<br />

of constant is similar, a logic program part below a #volatile statement is<br />

local <strong>to</strong> steps, that is, all rules, facts, <strong>and</strong> integrity constraints computed in one step are<br />

dismissed before the next incremental step. Note that the type of a logic program part<br />

(static, cumulative, or volatile) is determined by the last #base, #cumulative, or<br />

#volatile statement preceding it.<br />

During an incremental computation, all static program parts are grounded first,<br />

while cumulative <strong>and</strong> volatile parts are grounded step-wise, replacing constants<br />

with successive step numbers starting from 1. Note that due <strong>to</strong> <strong>gringo</strong>’s grounding<br />

algorithm, rules are not grounded twice using the same substitution of global variables<br />

(the incremental constant is treated like a global constant here). After a grounding<br />

step, <strong>clasp</strong> is usually invoked via an internal interface (like with <strong>clingo</strong>), <strong>and</strong> the<br />

incremental computation s<strong>to</strong>ps after a step in which at least one answer set has been<br />

found by <strong>clasp</strong>. This default behavior can be readapted via comm<strong>and</strong> line options<br />

(cf. Section 5.3). For obtaining a well-defined incremental computation result, it is<br />

important that (ground) head a<strong>to</strong>ms within static, cumulative, <strong>and</strong> volatile program<br />

parts are distinct from each other, <strong>and</strong> they must also be different from step <strong>to</strong> step<br />

(see [19] for details). In Section 4.3, we provide a typical example in which these<br />

conditions naturally hold.<br />

Example 3.18. For now, consider this simple Schur number example:<br />

1 #base.<br />

2 p(5).<br />

3 #cumulative k.<br />

4 1 { p(k,1..P) : p(P) } 1.<br />

5 :- p(X,P), p(Y,P), X

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!