Sum under clingo semantics¶
&sum{lt1 : c1;...;ltn : cn} <> l0
This atom sums up all linear terms in the set. It can be seen as a generalization of clingo sum aggregates as it similarly removes undefined elements, and therefore always returns a value. It can be used in the head and in the body.
Example
price(frame,15).
price(bag,5).
selected(frame).
{ selected(bag) }.
&sum{V} = price(P) :- selected(P), price(P,V).
&sum{price(P) : selected(P)} = price(total).
#show selected/1.
&show{price/1}.
Executing
flingo examples/config_optional.lp
Answer: 1
selected(frame) val(price(total),15) val(price(frame),15)
Answer: 2
selected(frame) selected(bag) val(price(bag),5) val(price(total),20) val(price(frame),15)
To see the behavior in presence of undefined integer variables, consider following example
price(frame,15).
pricelimit(14).
selected(frame).
{ selected(bag) }.
&sum{V} = price(P) :- selected(P), price(P,V).
:- &sum { price(P) : selected(P) } >= L,
pricelimit(L).
#show selected/1.
&show{price/1}.
flingo examples/config_pricelimit_sum.lp 0
UNSATISFIABLE