Flingo Language¶
Language Constructs¶
flingo atoms have the following forms, explore the links below for details on each construct.
- Sum under clingo semantics
&sum{lt1 : c1;...;ltn : cn} <> l0 - Sum under strict semantics
&sus{lt1 : c1;...;ltn : cn} <> l0 - Assignments
&in{lb..ub} =: x - Defined
&df{x} - Minimum and maximum aggregates
&min{lt1 : c1;...;ltn : cn} <> l0 &max{lt1 : c1;...;ltn : cn} <> l0
Note
lti,lb, andubare linear terms.ciis a conjunction of literals foribetween 0 andn.xis the name of a variable.<>is one of<=,=,!=,<,>, or>=.
Showing assignments¶
Use the &show{v1/a1; ...; vn/an} directive to control which variable
assignments are shown. In this directive, vi is the function name and ai is
its arity.
Example
&show{x/0; price/1}
The term x/0 shows the variable named x, while price/1 shows all
variables of the form price(<argument>).
If the directive is absent, all variables are shown. Use &show{} to hide all
variables.
Choices¶
Similarly to the language of clingo, flingo allows for choice rules in the head of a rule. Choices have the following form:
&fun{ lt1 :: ca1 : c1;...ltn :: can : cn} <> lt0
fun is either sum, sus, min, or max,
lti are linear terms, cai are regular atoms that may be chosen, and
ci are conjunctions of literals for i between 0 and n,
and <> is either <=,=,!=,<,>, or >=.
Example
As an example program
part(sportsframe). price(sportsframe,15). type(sportsframe,frame).
part(standardframe). price(standardframe,14). type(standardframe,frame).
part(fancysaddle). price(fancysaddle,6). type(fancysaddle,saddle).
part(standardsaddle). price(standardsaddle,5). type(standardsaddle,saddle).
&sum{V} = price(P) :- price(P,V).
pricelimit(20).
&sum{price(P) :: selected(P) : part(P)} <= X :- pricelimit(X).
:- selected(P), selected(P'), P<P',
type(P,T), type(P',T).
:- type(_,T), { selected(P) : type(P,T) }0.
#show selected/1.
&show{}.
Using a choice, we can now express in one line, that we may freely select parts such that the price limit is respected. We further restrict solutions such that every type has something selected and there is only one option per type selected.
Calling
flingo examples/config_pricelimit_choice.lp 0
Answer: 1
selected(standardframe) selected(fancysaddle)
Answer: 2
selected(standardframe) selected(standardsaddle)
Answer: 3
selected(sportsframe) selected(standardsaddle)
For another example, we replace from the program above the choice rule and the price limit with
maxlimit(14).
&max{price(P) :: selected(P) : part(P)} <= X :- maxlimit(X).
Calling
flingo examples/config_pricelimit_choice.lp 0
Answer: 1
selected(standardframe) selected(standardsaddle)
Answer: 2
selected(standardframe) selected(fancysaddle)