If the ic library is not loaded when this query is invoked, then the information propagated by Propia is that X=1. If, on the other hand, ic is loaded, then more common information is propagated. Not only does Propia propagate X=1 but also the domain of Y is tightened fromp(1,3). p(1,4). ?- p(X,Y) infers most.
-inf..inf
to
3..4
. (In this case the additional common information is that
Y ≠ 0, Y ≠ 1, Y ≠ 2 and so on for all values except 3
and 4!)Goal
in an ECLiPSe program, can be transformed into a
constraint by annotating it thus: Goal infers Parameter
.
Different behaviours can be specified with different parameters, viz:
Goal infers most
Goal infers unique
Goal infers consistent
crossword
in the examples code directory.
There are 72 ways to complete the crossword grid with words from the
accompanying directory.
For finding all 72 solutions,
the comparative performance of the different annotations is given in the
table Comparing Annotations.
The example program also illustrates the effect of specifying the waking conditions for Propia. By only waking a Propia constraint when it becomes instantiated, the time to solve the crossword problem can be changed considerably. For example by changing the annotation from
Annotation CPU time (secs) consistent 13.3 unique 2.5 most 9.8 ac 0.3
Table 15.1: Comparing Annotations
Goal infers most
to
suspend(Goal,4,Goal->inst) infers most
the time needed to find all solutions goes down from 10 seconds to
just one second.infers consistent
. To find the best Propia
annotation it is necessary to experiment with the current problem
using realistic data sets.
Propia extracts information from a procedure which may be defined by multiple ECLiPSe clauses. The information to be extracted is controlled by the Propia annotation.
Figure 15.3: Transforming Procedures to Constraints
p(X,Y) infers most
, first the goal p(X,Y)
is in effect
evaluated in the normal way by ECLiPSe.
However Propia does not stop at the first solution, but continues to
find more and more solutions, each time combining the information from
the solutions retrieved.
When all the information has been accumulated, Propia propagates this
information (either by narrowing the domains of variables in the goal,
or partially instantiating them).member(X,[a,b,c])
is
to further instantiate the term yielding member(a,[a,b,c])
.
This instantiated term represents the (first) solution to the goal.
% Definition of logical conjunction conj(1,1,1). conj(1,0,0). conj(0,1,0). conj(0,0,0). conjtest(X,Z) :- conj(X,Y,Z) infers most, X=Y. |
If the ic library is loaded more information can be extracted, because the MSG of 0 and 1 is a variable with domain[eclipse]: conjtest(X,Z). X = X Z = X Delayed goals: conj(X, X, X) infers most Yes (0.00s cpu)
0..1
.
Thus the result of the above example is not only to equate X and Z
but to associate with them the domain 0..1
.Goal infers Parameter
Parameter
,
of OutTerm and S. Call it MSG
infers most
is being handled, the class of terms admitted
for the MSG is the biggest class expressible in terms of the currently
loaded solvers. In case ic is loaded, this includes variable
domain, but otherwise it includes any ECLiPSe term without variable
attributes.infers consistent
by admitting only the
two terms ⊤ and ⊥ in the MSG class.
infers unique
is a variation of the algorithm in which the
first step OutTerm := ⊤ is changed to finding a first solution
S to Goal and initialising OutTerm := S.member(Var,List) infers Parameter
will
always terminate, if each call of member(Var,List)
does, even in
case
member(Var,List)
has infinitely many solutions!
Propia computes the Most Specific Generalisation (MSG) of the set of solutions to a procedure. It does so without, necessarily, backtracking through all the solutions to the procedure. The MSG depends upon the annotation of the Propia call.
Figure 15.4: Most Specific Generalisation
Goal infers most
prunes
the variable domains so every value is supported by values in the
domains of the other variables. If every problem constraint was
annotated this way, then Propia would enforce arc consistency.infers ac
to make Propia run
more efficiently. When called with parameter infers ac
,
Propia simply finds all solutions and
applies n-ary arc-consistency to the resulting tables.member
, exampled above, which may have an infinite number of
solutions.