9 January 2007 Constraints - Finite Domains 1 Module on Constraints The module consists of 4 courses...
-
date post
21-Dec-2015 -
Category
Documents
-
view
213 -
download
0
Transcript of 9 January 2007 Constraints - Finite Domains 1 Module on Constraints The module consists of 4 courses...
9 January 2007 Constraints - Finite Domains 1
Module on Constraints
Themoduleconsistsof4coursesdepictedbelowandof3ECTSeach.
Course:TopicsinFiniteDomainConstraints Dates:9Jan–25Jan Lecturer:PedroBarahona
Course:ConstraintsoverSetsandOptimisation Dates:9Jan–25Jan Lecturer:FranciscoAzevedo
Course:ConstraintsonContinuousDomains Dates:6Feb–22Feb Lecturer:JorgeCruz
Course:FuzzyConstraints Dates:6Feb–22Feb Lecturer:JoãoMouraPires
9 January 2007 Constraints - Finite Domains 2
Constraints – Finite Domains
Course:TopicsinFiniteDomainConstraints
Implementation of constraint solvers: indexical constraints. Constructiveapproach for combining constraints. Constructive disjunction, and cardinalityconstraints. Global constraints: their specification and implementation. Redundant constraints: advantages and disadvantages of their use inscheduling,planningandotherresourcemanagementapplications.
Course:ConstraintsoverSetsandOptimisation
Representationofsetsandmultisets.Setvariablesandsetfeatures(maximum,minimum and cardinality). Operations on sets (set union, intersection,difference,disjointness,complement),relatedconstraintsandtheirpropagation.Sets of sets: representation with union functions. Set constraint solvers:ConjuntoandCardinal.Applications:Setcoveringandpartitioning,timetabling,digitalcircuits.ComparisonwithSAT.Optimization.Branchandboundandlocalsearch.
9 January 2007 Constraints - Finite Domains 3
Constraints – Finite Domains
Course:ConstraintsonContinuousDomains
Representationofcontinuousdomains(intervals,boxes)andbasicoperations.Intervalanalysis:intervalarithmetic,intervalextensionsofrealfunctionsandtheinterval Newton method. Constraint propagation: narrowing functions andconstraintprojections.ConstraintdecompositionmethodandNewtonconstraintmethod. Consistency criteria for continuous domains: local consistency(interval,hullandbox)andhigherorderconsistency(3B,boundandglobalhull).Introductiontodifferentialequations..
Course:FuzzyConstraints
Introduction to fuzzy sets theory and to Possibility Theory. Generalization ofCSP to FCSP. Fuzzy constraints and their dual interpretation. Min-FCSP.Constraintpropagationinmin-FCSP.Solvingmin-FCSP.Refiningmin-FCSPbydiscriminand leximin-FCSP.Complexity issues.V(alued)-CSPandS(emiring)-CSPasgeneralframeworks.Specialcasesofthesegeneralframeworks(Min-FCSP,Sigma-CSP,Max-CSPandLexicographicCSP);theircomplexity.
9 January 2007 Constraints - Finite Domains 4
Constraints – Finite Domains
Evaluation
FinalGrade:Averageofthe4modules
TypeofEvaluation:Typicallytakehomeexam
Timetable:TuesdaysandThursdays,10:00–12:00
Room:232-II
9 January 2007 Constraints - Finite Domains 5
Constraints – Finite Domains
ConstraintSolvers
• IndexicalConstraints
• Bounds,NodeandArcConsistency
• ReifiedConstraints
• DisjuctiveConstraints
• Ask&TellConstraintMechanisms
9 January 2007 Constraints - Finite Domains 6
Indexical Constraints
Akey issue inConstraint(Logic)Programmingsystem, is the implementation
of the underlying Constraint Solvers. A number of features of these solvers
mustbetakenintoaccount:
Theeaseinrepresentingdomainsandgenericconstraints;
The possibility of controling constraint propagation in the ways
appropriatetotheapplications;
The possibility of combining simpler constraints into more complex
constraints;
Thetransparencyoftheimplementation(glass-box)allowingtheusersto
acceed the primitive constraints in order to implement user specific
constraintsandvariableandvalueheuristics.
9 January 2007 Constraints - Finite Domains 7
Indexical Constraints
An adequate way of satisfying all these constraints has been the use of
constraintsolversbasedinindexicalconstraints.
This is, for example, the methodology adopted in the implementation of
SICStus(aswellasGNUProlog),specificallyintheirfinitedomainsmodule.
Indexicalconstraintshaveacompactandintegratedapproachtorepresenting
boththedomainsandtheconstraintsoftheproblemvariables.
To be useful, indexical constraints require that variables domains have an
ordering. In fact,SICStus requires that the domainsare finite subsets of the
integers.
Sincemostconstraintsarearithmetic, constraintpropagationaims ingeneral
atachievingboundsarc-consistency.
9 January 2007 Constraints - Finite Domains 8
Indexical Constraints
Introductory example:
Let us consider the non-strict inequality constraint,, applied to variablesA
andBwhoseinitialdomainsarerespectively2000to5000and1000to4000.
InSICStussyntax
A in 2000..5000, B in 1000..4000, A #=< B
Thisexamplewillenableananalysisoftheadvantagesanddisadvantagesof
thepossibleimplementationmethods,namelytoissuessuchas
Maintainingthevariablesdomains;
Representingtheconstraints;
Theadequatepropagationoftheseconstraints
9 January 2007 Constraints - Finite Domains 9
Indexical Constraints
A in 2000..5000, B in 1000..4000, A #=< B
Concerningthedomains,afirst issueiswhethertoadoptarepresentationby
intensionorbyextension.Noticethatduringpropagationdomainsmayonlybe
reduced,theyneverincrease!
Therepresentationbyextensionmaintainsexplicitely, insomedatastructure,
allcurrentvalues in thedomains.Asdomainsmayonlydecrease,suchdata
structuremaybestatic,forexampleaBooleanvector(bitarray).
Such option suffers from many disadvantages. For example detection of
failures (i.e. empty domains) requires either the traversal of the whole data
structure(3000memorypositions!),orthemaintenanceof“bitcounters”.
9 January 2007 Constraints - Finite Domains 10
Indexical Constraints
A in 2000..5000, B in 1000..4000, A #=< B
Given the importance of an effective detection of failures, and the memory
overhead(domainvaluesmayusuallyberepresentedinamorecompactform)
it is thus more adequate, for a general purpose solver, to adopt a
representationbyintension.
In thebeginning,onemayalwaysconsiderexplicit limits for thedomains,all
thatisrequiredindomainsdeclaration.
Detectionof failure is thenverysimple:the upper limit of a domain cannot
be less than the lower limit.
This representation ismostefficientwhendomainsarekeptconvex (i.e.with
noholes)bymaintainingsimpleboundsconsistency.
9 January 2007 Constraints - Finite Domains 11
Indexical Constraints
A in 2000..5000, B in 1000..4000, A #=< B
Most usual constraints maintain such convexity, namely inequality (and
equality)constraintsonarithmeticexpressions.
ConstraintA #=< Bissatisfiableaslongastheminimumvalueofthedomain
ofA(inshort,thelowerboundofA)isnotgreaterthantheupperboundofB.
On the other hand, no value from the domain ofA may be higher then the
upperboundofB,i.e.theupperboundofAmustbenogreaterthantheupper
boundofB.Similarly, the lowerboundofBmustbenot less than the lower
boundofA).
A #=< BAB1000 5000
AB1000 5000
2000 4000
9 January 2007 Constraints - Finite Domains 12
Indexical Constraints
A in 2000..5000, B in 1000..4000, A #=< B
As these operations are quite common (e.g. in numerical applications), it is
necessary tomake the appropriate connection between these operations on
theupper/lowerboundsand theconstraints thatenforce them toachieve the
adequatepropagation.
Inindexicalconstraints,thislinkisachievedbyspecifyingdomainsboundsas
afunctionofotherbounds.
Constraints are thus represented by expressions on the variables bounds.
Sincethedomainscanonlybereduced,suchconstraintsareimplementedby
representing the bounds of variables as a function of the bounds of other
variablesandmax/minoperationstoimplementintersection.
9 January 2007 Constraints - Finite Domains 13
Indexical Constraints
A in 2000..5000, B in 1000..4000, A #=< B
PostingtheconstraintA #=< BchangestheinitialdomainsofvariablesAand
B
DomainofA 2000 .. 5000 inf .. max(B)
...i.e. max(A) = min(5000, max(B)) = max(B)
DomainofB 1000 .. 4000 min(A) .. sup
...i.e. min(B) = max(1000, min(A)) = min(A)
Theconstraintisthusimplicitelymaintainedas
A in 2000 .. 4000 inf ..max(B)
B in 2000 .. 4000 min(A) ..sup
A #< BAB1000 5000
AB1000 5000
2000 4000
9 January 2007 Constraints - Finite Domains 14
Indexical Constraints
A in 2000..5000, B in 1000..4000, A #=< B
Theimplicitconstraintrepresentation
o A in 2000 .. 4000 inf ..max(B)
o B in 2000 .. 4000 min(A) ..sup
also allows the intended propagation. Whenever the upper bound of B
changes (i.e.decreases!),suchcondition ispropagated tovariableA,whose
upperboundalsodecreases(from5000to4000).Comparisonwiththe lower
boundofA(2000)detectswhenthedomainofAbecomesempty!
Propagation fromA toB is similar. Any change in the lower bound ofA is
propagated to the lower bound ofB. Changes inA’s upper bound andB’s
lowerboundarenotpropagated.
9 January 2007 Constraints - Finite Domains 15
Indexical Constraints
PropagationmaybeobservedintheintroductionofanewvariableC,
constrainingB,
C in 3000..3500, B #= C
0 A in 2000 .. 4000 inf ..max(B)
B in 2000 .. 4000 min(A) ..sup
UponpostingthedomainofC
1 C in 3000 .. 3500
UponpostingtheconstraintB #= C
2a C in 3000 .. 3500 min(B) .. max(B)
2b B in 2000 .. 4000 [min(C)..max(C) min(A)..sup)]
2000 .. 4000 max(min(C),min(A)) .. min(max(C),sup)
3000 .. 3500 max(min(C),min(A)) .. max(C)
2c A in 2000 .. 3500 inf ..max(B)
Simplificationsaremade, ifpossible.TheupperboundofB issimplified,but
not its lower bound (the greater of the lower bounds of A and C is not
determinedyet).
9 January 2007 Constraints - Finite Domains 16
Indexical Constraints
Of course, the user must not be concerned, in general, with this low level
implementation.
The most usual constraints, concerning the usual arithmetic operations and
relationaloperations,aredirectlycompiledinindexicalconstraints.
For example, constraint A + B #= C is compiled in the following indexical
constraints
C in min(A)+min(B) .. max(A)+max(B)
A in min(C)-max(B) .. max(C)-min(B)
B in min(C)-max(A) .. max(C)-min(A)
Notice the monotonic nature of domain operations. The lower bound of A
increaseswith the increaseof the lowerboundofCand thedecreaseof the
upperboundofB.
9 January 2007 Constraints - Finite Domains 17
Indexical Constraints
The previous examples show that the type of consistency maintained by
indexical constraints in constraintsof equality (#= ) and inequality, strict or
not,(#< , #=< , #> and #>=)is,bydefault,bounds(orinterval)consistency.
The default compilation of the constraints only affects the bounds of the
domainsofthevariables.
Nevertheless, there is the possibility of imposing other types of consistency
adequate for many other constraints, namely node consistency and arc
consistency.
Thesetypesofconsistencyhaveonlyinterestwhenitisimportanttoconsider
concave domains (with “holes”), as for example in the queens and graph
colouringproblems.
9 January 2007 Constraints - Finite Domains 18
Indexical Constraints
Concavities are possibly introduced by disequality constraints (#\=). Let us
consider,forexample,
A in 1..9, B in 3..5, A #\= B
This disequality constraint has to be represented through set complement
operations,notintersection.AdoptingSICStussyntax
A in \dom(B) andB in \dom(A)
Thisoperationraisesproblemsregardingmonotonicity,sincewhenthedomain
ofonevariabledecreasesthedomainsoftheotherwouldincrease!
• A in 1 .. 9 \dom(B)
• B in 3 .. 5 \dom(A)
9 January 2007 Constraints - Finite Domains 19
Indexical Constraints
A in 1..9, B in 3..5, A #\= B
A in 1 .. 9 \dom(B) ; B in 3 .. 5 \dom(A)
For this reason, complement operations are “frozen” until the domains to be
complementedarereducedtosingletons.
Thisactuallyimplementsnodeconsistency,themostusefulcriteriontohandle
disequalityconstraints(inisolation).
WhenthedomainofBbecomesasingleton,B = 3forexample,thedomainof
A becomesconcave,beingrepresentedbysetunion.InSICStussyntax
?- A in 1..9, B in 3..5, A #\= B, B #=3, fd_dom(B,S).
B = 3, S = {3}, A in(1..2)\/(4..9) ?
9 January 2007 Constraints - Finite Domains 20
Indexical Constraints
Arcconsistencyrequires thatwhenever thedomainofavariable(notonly its
bounds) is changed, a check is made on whether the other variables still
maintainsupport.
(Generalised) Arc consistency is thus implemented by specifying in the
indexicalconstraintsthedomainoftheothervariables.
Forexample,inSICStussyntax,ifitisrequiredtomaintainarcconsistencyon
the previous sum constraint, the constraint can be specified by the user by
meansofthefollowingFDpredicate
sum(A,B,C)+:
A in dom(C) - dom(B),
B in dom(C) - dom(A),
C in dom(A) + dom(B).
9 January 2007 Constraints - Finite Domains 21
Indexical Constraints
User defined constraints in SICStus (by means of FD predicates) is thus
similar to the predicate definitions in Prolog, with a different “neck” operator
(“+:”ratherthanthePrologoperator“:-”).
There are however some differences, namely there are no alternative
“clauses”,i.e.nobacktrackinginconstraintdefinitions.
Usingthepreviousdefinitionwewouldget,
?- A in 1..6, A#\=3,A#\=4,A#\=5, B in 1..2, sum(A,B,C).
A in(1..2) \/ {6}, B in 1..2, C in(2..4)\/(7..8) ?
% A+B#= C C in 1..8
?- C in 1..9, C#\=5,C#\=6,C#\=7, B in 0..2, sum(A,B,C).
C in(1..4)\/(8..9), B in 0..2, A in(-1..4)\/(6..9) ?
% A+B#= C A in -1..9
9 January 2007 Constraints - Finite Domains 22
Specifying Indexical Constraints
Indexical expressions may only appear in the “body” of FD predicate
definitions. Such limitation is due to the different execution mechanisms
between thehost language (Prolog)and theFDmodule inSICStus. In fact,
giventhesumdefinition
sum(A,B,C)+: A in dom(C) - dom(B), B in dom(C) - dom(A), C in dom(A) + dom(B).
itisintendedthat,intheFDmodule,thedomainsofA/B/Carere-evaluatedby
updatesonthedomainsofC,B/C,A/A,B.
In contrast with Prolog execution, the primitives appearing in indexical
expressions(e.g.dom,max,min,etc)shouldberegardedasreactive agents
(tochanges).
9 January 2007 Constraints - Finite Domains 23
Specifying Indexical Constraints - Terms
Inadditiontotheprimitivesalreadyexamplified,indexicalexpressionsmaybe
formedwithFDterms.BeingXadomainvariableandD(X)itscurrentdomain,
thebasicFDtermsare
min(X) minimumofD(X)
max(X) maximumofD(X)
card(X) cardinalityofD(X)
X value(integer)ofX.Theexpressionisonly
evaluatedwhenXisinstantiated.
I aninteger
inf minusinfinity
sup plusinfinity
9 January 2007 Constraints - Finite Domains 24
Specifying Indexical Constraints - Terms
FD terms, basic or not, may be combined through arithmetic operators into
compound FD terms. Denoting by T1/T2 arbitrary FD terms, and by
D(T1)/D(T2) their current “domains”, the following compound termsmay be
formed(andevaluatedbyintervalarithmetic)
-T1 I-negationofD(T1)
T1+T2 I-sumofD(T1)andD(T2)
T1-T2 I-differenceofD(T1)andD(T2)
T1*T2 I-productofD(T1)andD(T2),D(T2)>=0
T1/>T2 D(T1)divD(T2),withoutboundrounding,
T1/<T2 withD(T2)>=0
T1 mod T2 D(T1)modD(T2)
9 January 2007 Constraints - Finite Domains 25
Specifying Indexical Constraints - Ranges
FD terms are used in indexical constraints to define ranges for the domain
variables,thatmustbeintersectedwiththecurrentdomainsofthesevariables.
Ingeneral,indexicalconstraintstaketheform
X in R
whereRisarangedefinedbythefollowinggrammar:
Thebasic rangesarethefollowing
dom(X) D(X)
{T1,...,Tn} setoftermsTi
T1 .. T2 intervalboundbytermsTi
where X denotes a domain variable and Ti an FD term. Other terms may
subsequentlybeobtainedbycomposition.
9 January 2007 Constraints - Finite Domains 26
Specifying Indexical Constraints - Ranges
DenotingbyRiarangeandbyD(Ri)thecorrespondingdomain,thefollowing
operatorsareusedtocomposeterms
R1/\R2 intersectionofD(R1)andD(R2)
R1\/R2 unionofD(R1)eD(R2)
\R1 complementofD(R1)
R1+R2 (T2) I-sumofD(R1)andD(R2)(orD(T2))
-R1 I-negationofD(R1)
R1-R2 e R1-T2 I-differenceofD(R1)andD(R2)(D(T2))
R1 mod R2 (T2) I-modofD(R1)andD(R2)(D(T2))
R1 ? R2 ifR1\=thenD(R2)else
unionof(X,R1,R2) unionofD(Sk):eachSk isobtained fromR2
replacingXforthek-thelementofR1.
9 January 2007 Constraints - Finite Domains 27
Indexical Constraints – Example (1)
Example 1:adjust(X,Z,K,N)
ForvariablesXandZ,withdomain1toN,makeXtobeshiftedfromZbya
valueK(0=<K<N),withrewrapping.
This kind of adjust enables that, while enumerating Z in the “standard”
increasingorder,Xisenumeratedwiththe“shifted”ordering.
Forexample,letusassumeN=15andK=5,i.e.that
whileZisenumeratedwiththestandardincreasingorder
Xisenumeratedwiththeordershiftedby5
X 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5
Z 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
9 January 2007 Constraints - Finite Domains 28
Indexical Constraints – Example (1)
Example 1:adjust(X,Z,K,N)
NoticethatX=((Z+K+N-1)modN)+1andZ=((X-K+N-1)modN)+1.Forexample,
forZ=7X=12asintended
X = (7+5+15-1) mod 15 +1 = 26 mod 15 +1 = 11 +1 = 12
Z = (12-5+15-1) mod 15 + 1= 21 mod 15 + 1= 6 +1 = 7
Hence, we may formulate the correspondence between X and Z with the
followingspecification
Solution 1:adjust(X,Z,K,N)+:
X in ((dom(Z)+K+N-1) mod N)+1,
Z in ((dom(X)-K+N-1) mod N)+1.
X 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5
Z 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
9 January 2007 Constraints - Finite Domains 29
Indexical Constraints – Example (1)
Example 1:adjust(X,Z,K,N)
Infact,themodoperationisunnecessary,ifXandZaredefinedover1..N.All
thatisrequiredis,foreachvalueZtoaddK.Sincethismayresultabovethe
upperboundofX,sometimesNmustbesubtracted.
Forexample:
forZ=7 X1=7+5=12andX2=7+5-15=-3
forZ=11 X1=11+5=16andX2=11+5-15=1
X 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5
Z 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
9 January 2007 Constraints - Finite Domains 30
Indexical Constraints – Example (1)
Byusingtheunionofthetwointervals,oneresultingfromsimplyaddingKand
theotherbyaddingKandsubtractingN,theadequatevalueofXisthus
obtained.Thisleadstothesimplerformulation.
Solution 2:adjust(X,Z,K,N)+:
X in (dom(Z)+ K) \/ (dom(Z)+ K - N),
Z in (dom(X)- K) \/ (dom(X)- K + N).
Left as Exercise:EnumerateYfromcentretothe“edges”asbelow.
Y 15 13 11 9 7 5 3 1 2 4 6 8 10 12 14
Z 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
9 January 2007 Constraints - Finite Domains 31
Indexical Constraints – Example (2)
Example 2:no_attack(L1,C1,L2,C2)
Two queens, placed in rows L1 and L2 (constants) and columns C1 e C2
(domainvariables)shouldnotattackeachother,i.e.
C1 \= C2 and L1+C1 \= L2+C2 and L1+C1 \= L2+C2.
Solution 1:no_attack(L1,C1,L2,C2)+:
C1 in \({C2} \/ {C2+L2-L1} \/ {C2+L1-L2}),
C2 in \({C1} \/ {C1+L1-L2} \/ {C1+L2-L1}).
Insuchapproach,as thedomainvariablesappear ina negative “context” (\
{C}) the constraint is frozen until C is instantiated. Hence, this formulation
guaranteesthemaintenanceofnode consistency.
Inalternative,onemayspecifyarc consistency.
9 January 2007 Constraints - Finite Domains 32
Indexical Constraints – Example (2)
Example 2:no_attack(L1,C1,L2,C2)
Solution 2:no_attack(L1,C1,L2,C2)+:
C1 in unionof(Y, dom(C2), \({Y} \/ {Y+L2-L1} \/ {Y+L1-L2})),
C2 in unionof(X, dom(C1), \({X} \/ {X+L1-L2} \/ {X+L2-L1})).
Here,wegetarcconsistencybyallowingaqueentobeinapositionthatisnot
under the attack of at least one possible position of the other queen, which
supportstheformer.
Forexample,thedomainofC1isobtainedbytheunionofallvaluesthatare
“safe” for some value in the domain ofC2, through a range expression that
takesinturnallvaluesofthedomainofC2,renamingthemasY
C1 in unionof(Y,dom(C2),...).
9 January 2007 Constraints - Finite Domains 33
Indexical Constraints – Example (2)
Example 2:no_attack(L1,C1,L2,C2)
The third approach below optimises arc consistency in this problem. Taking
intoaccountthatapositioninaqueenisalwayssupportedbyaqueenwith4
or more positions available, arc consistency is only evaluated when the
cardinalityofthedomaindropsbelow4.
Solution 3: no_attack(L1,C1,L2,C2)+:
C1 in ( 4..card(C2)) ? (inf..sup) \/
unionof(Y,dom(C2),\({Y} \/ {Y+L2-L1} \/ {Y+L1-
L2})),
C2 in (4..card(C1)) ? (inf..sup) \/
unionof(X,dom(C1),\({X} \/ {X+L1-L2} \/ {X+L2-L1})).
In fact, C1 is constrained to be either inf..sup (when the cardinality of C2
(card(C2)is>=4)orunionof(Y,... ), otherwise.
9 January 2007 Constraints - Finite Domains 34
Disjunctive Constraints
In general, the execution of a CLP problem includes a search phase with
backtracking on the enumeration of the variables when the constraints and
their propagation is not sufficient to eliminate redundant values from the
variablesdomains.
This backtracking occurs in the enumeration phase,whenall the constraints
arealreadyposted,i.e.Thereisnobacktrackingonconstraintposting.
However,whenconstraintsarespecifiedbyintension,themostnaturalwayto
combinethemisthroughthedisjunctionofthedifferentalternatives.
Onemustthenidentifythebestwaytospecifydisjunction.
9 January 2007 Constraints - Finite Domains 35
Disjunctive Constraints
Example:
Giventwotasks,T1andT2,withstartingtimesS1andS2anddurationD1and
D2,garanteethattheydonotoverlap.
Anaturalimplementionofthisconstraintisthroughtheequivalentdisjunction
T2doesnotstartbeforetheendofT1;or
T1doesnotstartbeforetheendofT2
Thespecificationof thisconstraint,namely thedisjunctionof thealternatives,
may use the usual disjunction of Prolog clauses (and the associated
backtracking)
disjoint(S1,S2,D1,D2) :- S1 + D1 #=< S2.
disjoint(S1,S2,D1,D2) :- S2 + D2 #=< S1.
9 January 2007 Constraints - Finite Domains 36
Disjunctive Constraints
Problem(Vars):-
Declaration of Variables and Domains,
Specification of Constraints,
Labelling of the Variables.
This formulation raises the problem of interaction between backtrack
mechanismsmadeeither
Onthephaseofspecificationandpostingofconstraints;and
Ontheenumerationphaseofthevariables.
Withk non-overlaping tasks, therearek*(k-1)/2 combinationsofprecedence
between pairs of tasks.With50 tasks,k = 50, therewill be50*49/2 = 1225
constraintsand21225waysofcombiningthem(infactonly50! are distinct).
9 January 2007 Constraints - Finite Domains 37
Disjunctive Constraints
Problem(Vars):-
Declaration of Variables and Domains,
Specification of Constraints,
Labelling of the Variables.
Hencethetwoalternatives:
Either1singleproblemwithkvariables,withcomplexityO(dk);or
amodelwithalternative“problems”on thesamevariables leading tok!
problemsonthesevariables,withcomplexityO(k! dk).
Althougheachof thek!problems in thesecondmodelaremoreconstrained
than the single one of the first model, the huge number of problems
corresponding to an ordering of the task makes this formulation very
inneficient.
9 January 2007 Constraints - Finite Domains 38
Reified Constraints
Abetterformulationusesasinglespecificationofalltheconstraintalternatives,
avoidingthebacktrackingofmultipleconstraintdefinitions.
Suchformulationcanbeobtainedthroughconstraints reification.
The basic idea of constraint reification is to associate its satisfaction to a
booleanvariable0/1,andmakethisvariableaccessibletotheprogramlevel.
ForexampleassociatingconstraintsC1andC2tobooleanvariablesB1andB2,
thedisjunctionoftheseconstraintsmaybespecifiedbymeansofconstraint
B1 + B2 #>= 1
9 January 2007 Constraints - Finite Domains 39
Reified Constraints
Oncedefinedthisbasicmeta-levelmechanismofreifiedconstraints,itsscope
canbeenlarged forother typesofcombinationsofconstraints,namely those
requiringsomecountings.
Forexample,iffromthe20constraintsC1,..., C20atleast10mustbesatisfied,
insteadofspecifying,
C1020=184 756alternativecombinationsof10outof20oftheC1toC20
constraints
theonlyadditionalspecificationsrequiredare
the20constraints,C1toC20
theconstraintsreificationtoBooleanvariablesB1toB20
the“counting”constraintB1 + B2 + ... + B20 #>= 10
9 January 2007 Constraints - Finite Domains 40
Reified Constraints - Ask & Tell Mechanisms
To efficiently exploit the correspondance between a constraint C and a
BooleanvariableB,Ask & Tellmechanismsmustbedefined:
Tellmechanisms
Tell(C)-Posttheconstraint
Tell(~C)-Postthe“negation”oftheconstraint
Askmechanisms
Ask(C)-Checktheentailmentoftheconstraint
Ask(~C)-Checktheentailmentofitsnegation.
For example, to impose that one and only one of constraintsC1 andC2 is
satisfiedallthe4abovesituationsmustbeimplemented.
9 January 2007 Constraints - Finite Domains 41
Reified Constraints - Ask & Tell Mechanisms
Ask(C1) / Ask(C2)succeeds
Once detected the satisfaction of one of the constraints, the negation of the
otherconstraintmustbeposted,i.e.tell(~R2) / tell(~R1).
Ask(~C1) / Ask(~C2)succeeds
Once detected the satisfaction of the negation of one of the constraints, the
otherconstraintmustbeposted,i.e.tell(C2) / tell(C1).
Itisthusimportanttoseehowreifiedconstraints,andtheunderlyingAsk&Tell
mechanismsmaybespecified,notonly inbuilt-inpredefinedconstraints,but
alsoforuserdefinedconstraints.
9 January 2007 Constraints - Finite Domains 42
Specification of Ask & Tell Mechanisms
In SICStus the association between constraints and boolean variables is
specifiedthroughthebuilt-inoperator“#<=>”
C #<=> B.
whereBisthebooleanvariableandCtheconstraint.
Somebuilt-inconstraintsarepre-defined.Suchisthecaseoflinearnumerical
constraints.Asanapplication,tasksnon-overlappingasdescribedbeforecan
bespecifiedwithnoalternativeclausesas
disjoint(S1, S2, D1, D2) :-
(S1 + D1 #=< S2) #<=> B1, % T1 before T2
(S2 + D2 #=< S1) #<=> B2, % T2 before T1
B1 + B2 #>= 1.
9 January 2007 Constraints - Finite Domains 43
Specification of Ask & Tell Mechanisms
Forconstraintsdefinedbytheuser,theappropriateAsk & Tellconditionsmust
alsobedefined.
For instance, letusconsidertheconstraintofdifferencebetweentwodomain
variables.
ThetwoTellmechanismsareimposedbypropagatingindexicalspecifications,
that includeboth thepositivedefinitions (‘+:’), already known,aswell as the
negativedefinitions(‘-:’)
’x\\=y’(X,Y) +: ’x\\=y’(X,Y) -:
X in \{Y}, X in dom(Y),
Y in \{X}. Y in dom(X).
9 January 2007 Constraints - Finite Domains 44
Specification of Ask & Tell Mechanisms
TheAskmechanismsareimposedbychecking indexicals,bothpositive(‘+?’)
’x\\=y’(X,Y)+?
X in \dom(Y).
andnegative(‘-?’)
’x\\=y’(X,Y) -?
X in {Y}.
The intended behaviour to propagating and checking indexicals, imposes
some constraints on the expressions that can be used on the “body” of the
definitions,aswellastotheirexecution.
Someoftheselimitationsarepresentednext.
9 January 2007 Constraints - Finite Domains 45
Ask & Tell Propagation
Propagating Indexicals (Trigger)
APropagatingIndexicalX in Risscheduledforexecutionwhenever
Itbecomesmonotonicforthefirsttime
Itisrescheduledwhenever,foranothervariableYappearinginR
o ThedomainofYischangedandYappearsinRintheformcard(Y)
oudom(Y);
o The upper/lower bounds ofY change andY appears inR in the
formmax(Y)/min(Y).
9 January 2007 Constraints - Finite Domains 46
Ask & Tell Propagation
Propagating Indexicals (Result)
GivensomevariableX referredto inan indexicalconstraint,anddenotingby
M(X)thevalueoftheconstraintinthecurrentstateofmemoryandbyI(X)the
intervalbetweenthelowerandupperboundsofX,then
IfM(X)isdisjointfromI(X),thereisacontradiction.
If I(X) is within M(X), there are no values in the current domain of X
incompatible with the indexical constraints, whose execution is
suspended,untilthesituationbecomes“ground”.
Otherwise, the indexical constraint is added to the constraints overX,
whosedomainwillbepruned.
9 January 2007 Constraints - Finite Domains 47
Ask & Tell Propagation
Propagating Indexicals: Examples
Example 1: Constraint X in \{Y} in the positive propagating indexical is
suspendeduntilitgetsmonotonic,i.e.untilYgetsinstantiated.
In this case, the constraint is either contradictory, or is propagated,
pruningthevalueofYfromthedomainofX.
Example 2:ConstraintX in dom(Y), in thenegativepropagating indexical is
inherentlymonotonic.
WhilstYhasvaluesinitsdomain,X isgettingprunned.
If the domains of X and Y become disjunct, then the negation of the
constraintofdifferencefails!
When thedomainofYgetsground, thensodoes thedomainofXand
theconstraintsucceeds.
9 January 2007 Constraints - Finite Domains 48
Ask & Tell Propagation
Checking Indexicals (Trigger)
A checking indexical X in R is triggered for execution in the following
conditions
Itbecomesanti-monotonicforthefirsttime
Itisrescheduledwhenever,
o ThedomainofX hasbeenprunedorgotground;
o The domain of another variable Y, appearing in R in the form
card(Y)ordom(Y),ispruned;
o Theupper/lower boundsof another variableY, appearing inR in
theformmax(Y)/min(Y),ispruned.
9 January 2007 Constraints - Finite Domains 49
Ask & Tell Propagation
Checking Indexicals (Result)
GivensomevariableXreferrredtoinanindexicalconstraint,anddenotingby
M(X)thevalueoftheconstraintinthecurrentstateofmemoryandbyI(X)the
intervalbetweenthelowerandupperboundsofX,then
If I(X) is contained inM(X), thenno valueofXmay turn the constraint
false, as M(X) may only “increase size” (anti-monotonic). Hence the
constraintisentailed.
If I(X) isdisjoint fromM(X)andM(X) isground thentheconstraintmay
nolongerbesatisfied,andisdisentailed.
Otherwise,thecheckingindexicalissuspended.
9 January 2007 Constraints - Finite Domains 50
Ask & Tell Propagation
Checking Indexicals: Examples
Example 1: Constraint X in \dom(Y) in the positive checking indexical is
inherentlyanti-monotonic(thevaluesof\dom(Y)mayonlyincreaseasdom(Y)
decreasesduringexecution).
Hence,thepositivecheckingindexicalsucceedsassoonasthedomain
ofXhasnoelementsincommonwiththedomainofY.
Example 2:ConstraintX in {Y}, in thenegativechecking indexicalonlygets
anti-monotonicwhenYbecomesgroundtosomevalue.
WhilstXhasthisvalueinitsdomaintheconstraintsuspends.
IfXonlyhasthisvalueinitsdomainthenegativecheckingsucceeds,i.e.
theconstraintofdifferencefails.
9 January 2007 Constraints - Finite Domains 51
Ask & Tell - Example
Example: Strict Inequality Constraints
Ascanbecheckedeasily,thefollowingdefinitionsofpropagatingand
checkingindexicalsareadequatetoreifyaconstraintofstrictinequalityofthe
form
’x\\<y’(X,Y) #<=> B
’x\\<y’(X,Y)+: X in inf .. max(Y)-1, Y in min(X)+1 .. sup.
’x\\<y’(X,Y)-: % x>=y
X in min(Y) .. sup,
Y in inf .. max(X).
’x\\<y’(X,Y)+? X in inf .. min(Y)-1, Y in max(X)+1 .. sup.
’x\\<y’(X,Y)-? X in max(Y).. sup,
Y in inf .. min(X).