search - kth.se · id2204, l06, christian schulte, ict, kth . 4 . improving propagation idea:...
TRANSCRIPT
![Page 1: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/1.jpg)
Search Lecture 06, 2015-04-16
ID2204: Constraint Programming
Christian Schulte [email protected] Software and Computer Systems School of Information and Communication Technology KTH – Royal Institute of Technology Stockholm, Sweden
![Page 2: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/2.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 2
Overview
Reminder improved constraint propagation events realistic constraint propagation improving constraint propagation further
Search branching exploration
Outlook
![Page 3: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/3.jpg)
Reminder
![Page 4: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/4.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 4
Improving Propagation
Idea: propagator narrows domain of some (few) variables
re-propagate only propagators sharing variables
Maintain a set of “dirty” propagators not known whether fixpoint all other propagators have fixpoint computed
![Page 5: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/5.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 5
Propagator Variables
Variables var(p) of propagator p variables of interest
No input considered on other variables No output computed on other variables
![Page 6: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/6.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 6
Improved Propagation
propagate((V,U,P), so)
s := s0; N := P; while N ≠ do
choose p N; s’ := p(s); N := N – {p}; MV := { x V | s(x) ≠ s’(x) }; DP := { q P | exists x var(q): x MV }; N := N DP; s := s’; return s;
![Page 7: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/7.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 7
Loop Invariant
Loop maintains for all p P-N p(s) = s after termination (N = ): for all p P p(s) = s Obligations
holds initially is actually invariant
![Page 8: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/8.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 8
What Is Computed
Fixpoint follows from loop invariant
Largest simultaneous fixpoint as for naïve propagation
proofs works exactly as before sequence of stores not strictly decreasing sufficient: store sequence and decreasing and finite (to
prove next)
![Page 9: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/9.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 9
Termination
Insight: if MV=, then p removed from N if MV≠, then p(s)<s
Consider pairs (si,Ni) with
si the value of s at i-th iteration Ni the value of N at i-th iteration
strictly decreasing wrt well-founded lexicographic order of (S,<) and (2P,)
![Page 10: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/10.jpg)
Improving Propagation
Further
![Page 11: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/11.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 11
Subsumed Propagators
Propagator p subsumed by store s, iff for all s’ ≤ s : p(s’)=s’
all stronger stores are fixpoints p entailed by s s subsumes p (s entails p)
![Page 12: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/12.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 12
Weak Idempotence
A function f X X is idempotent on x X if
f(f(x)) = f(x) statement on just one element
For a propagator: if p is idempotent on s, it does not mean that p is idempotent on s’ with s’ ≤ s
![Page 13: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/13.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 13
Status Messages
Solution: propagator returns status and tells result
propagator p is function p S SM × S with SM := {fix, nofix, subsumed}
![Page 14: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/14.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 14
Propagator with Status
Assume propagator p and store s if p(s) = (fix, s’), then s’ is fixpoint for p if p(s) = (subsumed, s’), then s’ subsumes p if p(s) = (nofix, s’), then no further knowledge always safe (as before)
![Page 15: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/15.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 15
Improved Propagation
propagate((V,U,P), so) s := s0; N := P; while N ≠ do choose p N; (ms,s’):= p(s); N := N – {p}; if ms=subsumed then P := P –{p}; end MV := { x V | s(x) ≠ s’(x) }; DP := { q P | exists x var(q): x MV }; if ms=fix then DP := DP –{p}; end N := N DP; s := s’; return (P,s);
![Page 16: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/16.jpg)
Propagation Events
![Page 17: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/17.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 17
Propagation Events
Many propagators simple to decide whether still at fixpoint for changed
domain based on how domain has changed
How domain changes described by propagation event
or just event
![Page 18: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/18.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 18
Events
Typical events fix(x) x becomes assigned min(x) minimum of x changes max(x) maximum of x changes any(x) domain of x changes
Clearly overlap fix(x) occurs: min(x) or max(x) occur any(x) occurs min(x) or max(x) occur: any(x) occurs
![Page 19: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/19.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 19
Events on Store Change
events(s,s') = { any(x) | s'(x) s(x) } { min(x) | min s'(x) > min s(x) } { max(x) | max s'(x) < max s(x) } { fix(x) | |s'(x)|=1 and |s(x)|>1 }
where s' s
![Page 20: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/20.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 20
Events are Monotonic
If s'' s' and s' s then events(s,s'') = events(s,s') events(s',s'')
Event occurs on change from s to s''
occurs on change from s to s', or occurs on change from s' to s''
![Page 21: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/21.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 21
Propagator for ≤
Propagator p≤ for x ≤ y p≤ (s) = { x { ns(x) | n ≤ max(s(y)) }, y { ns(y) | n ≥ min(s(x)) }}
good one: es(p≤) = { max(y), min(x) } but also: es(p≤) = { any(y), any(x)}
![Page 22: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/22.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 22
Propagator for ≠
Propagator p≠ for x ≠ y p≠(s) = { x s(x) - single(s(y)), y s(y) - single(s(x))}
where: single({n}) = {n} single(N) = (otherwise)
good one: es(p≠) = { fix(y), fix(x) } but also: es(p≠) = { any(y), any(x)}
![Page 23: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/23.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 23
Taking Advantage from Event Sets
Base decision of propagators to re-propagate on event sets rather than on modified variables
DP := { q P | events(s,s’) es(q) ≠};
![Page 24: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/24.jpg)
More Optimizations
![Page 25: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/25.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 25
Priorities
Choose propagator according to cost: cheapest first according to expected impact general: first-in first-out (queue)
![Page 26: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/26.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 26
Propagator Rewriting
Another observation: propagator for max(x,y)=z and values for x are smaller than for y Replace by propagator for y=z
![Page 27: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/27.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 27
Summary: Optimizing Propagation
Fixpoint knowledge avoids useless execution idempotence, subsumption, events knowledge provided by propagator
More details on optimizing propagation and
propagation in systems Finite Domain Constraint Programming Systems, Christian
Schulte, Mats Carlsson. In: Francesca Rossi, Peter van Beek, Toby Walsh, editors,
Handbook of Constraint Programming, Foundations of Artificial Intelligence, pages 495-526. Elsevier Science Publishers, 2006.
![Page 28: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/28.jpg)
Search
![Page 29: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/29.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 29
Search
Branching defines the search tree what are properties for a branching? what is a search tree?
Exploration how to explore the search tree? first solution search best solution search
![Page 30: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/30.jpg)
Branching
![Page 31: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/31.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 31
Branching
How to define branching in our model branching suggests new constraints for decomposition operational formulation: new propagators
Branching makes decision based on current
store but also on propagators first-fail: variable with smallest domain most-constrained first
![Page 32: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/32.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 32
Properties
Search tree constructed by branching finite tree decreasing no solutions lost complete no solutions duplicated non-overlapping
![Page 33: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/33.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 33
Some Notation
Set of propagators
P := S S
functions from store to store contracting monotonic
Set of constraint models
M
![Page 34: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/34.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 34
Simplification
In the following we assume that the set of variables V and the universe U is fixed
Propagation is referred to by propagate(P,s) for propagator set P and store s and returns
pair of propagator set and store
![Page 35: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/35.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 35
Branching
A branching b is a function from propagators and a store to tuples of finite propagator sets
b(P, s) = (P1, …, Pn) where
Pi P and finite called i-th alternative
![Page 36: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/36.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 36
Branching: Properties
Assume (s not failed) A = sol((V, U, P),s) Ai = sol((V, U, PPi),s) complete: A1 … An = A non-overlapping: AiAj = for i≠j decreasing: if propagate(PPi,s)=(P’,s’) then s’ < s
![Page 37: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/37.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 37
Extending Models
A constraint model is a quadruple (V, U, P, b)
variables V universe (values) U propagators P branching b
![Page 38: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/38.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 38
Search Tree
A search tree for a constraint model (V, U, P, b) consists of nodes
(P’,s) with P’ set of propagators, s store Root of tree is propagate(P,sinit) where sinit(x) := U for all xV
![Page 39: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/39.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 39
Search Tree
For all leaves (P,s): either s failed or b(P,s) = () (“solved”)
For all inner nodes (P,s): s is not failed if b(P,s)= (P1,…, Pn) then node has children propagate(PP1,s), …, propagate(PPn,s)
![Page 40: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/40.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 40
Search Tree: Properties
Invariant: nodes of search tree (P,s): either s failed or s sim. fixpoint of P
If node (P1,s1) below (P2,s2) on same path: s1 < s2
Search tree is finite due to decreasing
![Page 41: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/41.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 41
Optimizing
For constraint propagation do not start by assuming all propagators dirty only those added by branching are dirty
remember: we start from simultaneous fixpoint (search tree invariant)
Propagate function takes set of dirty and non-dirty propagators as input
![Page 42: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/42.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 42
Assignments vs. Solved Nodes
Notice difference a solved node does not mean that for all variables x we have that s(x) is singleton!
![Page 43: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/43.jpg)
Assign and Remove Propagators
Needed for branchings are propagators that assign variable x to a value remove value for a variable x
For smallest possible value
assign-min(s,x)(y) := if y=x then {min(s(x))} else s(y) remove-min(s,x)(y) := if y=x then s(x)-{min(s(x))} else s(y)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 43
![Page 44: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/44.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 44
First-fail
b(P,s) := if exists x with card(s(x)) > 1 and
card(s(x)) smallest then
({assign-min(s,x)}, {remove-min(s,x)}) else
()
![Page 45: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/45.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 45
Summary: Branching
Branching defines search tree complete non-overlapping decreasing
Search tree consists of propagators and store after propagation leaves are failed or solved is finite
![Page 46: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/46.jpg)
Exploration
![Page 47: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/47.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 47
Depth-first Exploration
dfe(P,s) = (P’,s’) := propagate(P,s); if s’ failed then s’ else
case b(P’,s’) of () then s’ [] (P1,P2) then
s’’ := dfe(P’P1,s’); if s’’ failed then dfe(P’P2,s’) else s’’ end
end
end
![Page 48: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/48.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 48
Search in Gecode
Objects created for models as spaces Spaces provide methods for search
status returns status clone returns copy commit commits to alternative
Straightforward see documentation
![Page 49: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/49.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 49
State Restoration
Search must restore state backtrack to previous state
Approaches trailing remember changes undo changes recomputation recompute state copying store additional copy
![Page 50: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/50.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 50
Trailing
Dominating approach Advantages
remembers exactly what has changed
Disadvantages complicated (all operations must be trail aware) requires additional techniques (time-stamping, …) difficult to combine with concurrency
![Page 51: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/51.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 51
Recomputation
Remember path for nodes path starts at some copy c recompute by redoing branching on c for all nodes compute single fixpoint known as batch recomputation
Advantage memory usage problem independent
Disadvantage efficiency overhead
![Page 52: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/52.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 52
Copying
Advantages simple allows for concurrency/parallelism
Disadvantages needs way too much memory
![Page 53: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/53.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 53
State Restoration in Gecode
Hybrid of copying and recomputation Read in “Modeling and Programming with
Gecode” Adaptive recomputation
remember copy in middle of path
![Page 54: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/54.jpg)
Summary: Principles
![Page 55: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/55.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 55
Summary: Constraint Propagation and
Search Models for
constraint propagation branching sketch for exploration
Most important concepts CSPs constraint models propagators propagation loop
![Page 56: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/56.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 56
More on Models and Principles…
Excellent book with much more detail, inspired some of the material here
Krzysztof Apt, Principles of Constraint Programming. Cambridge University Press, 2003.
Available in FORUM library
![Page 57: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/57.jpg)
Outlook
![Page 58: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/58.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 58
Common Constraints
Common constraints reified, arithmetic, element, distinct, regular, … …and other global constraints
How are they used for modeling How are they propagated What makes them global Propagation strength
![Page 59: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/59.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 59
Linear Equality
Propagator for
where ai, d integers, ai ≠ 0
How to propagate cheaply bounds information? for each variable xi consider how small and how large it
possibly can be restrict us here to ax + by = d
dxa in
i i 1
![Page 60: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/60.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 60
Element Constraint
Element constraint a[[x]] = y array of integers a variables x and y value of y is value of a at x-th position in particular: 0 ≤ x < elements in a
In Gecode element(this, a, x, y);
also for arrays of variables
![Page 61: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/61.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 61
Distinct: Basic Question
Propagating in domain-consistent fashion need to consider all solutions naïve: too much memory, too much time
Is there a better way
in general no but for particular constraints: yes! but element is simple, for more difficult?
![Page 62: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/62.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 62
Golomb Rulers
Find n ticks ti on ruler such that distance between ticks pairwise distinct length of ruler minimal
Extremely hard problem applications in cristalography, …
t0 t1 t2 t3 t4 t5
![Page 63: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/63.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 63
Cardinality Constraint
Distinct: variables can take a particular value at most once
Generalization: lower and upper bounds on how often a value can be taken by variables
Use: shift assignment worker: variables describe shift to work boss: sets minimum and maximum requirements on
workers per shift
![Page 64: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/64.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 64
Channeling/Assignment Constraints
Suppose variables xi and yi (0 i < n) channel(xi, yi) holds, iff xi = j yj = i (0 i < n)
Use: dual models (permutation problems)
queen i is in row j row j contains queen i post constraints on both set of variables
![Page 65: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/65.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 65
Lex Constraints
Suppose variables xi and yi (0 i < n) lex(xi, yi) holds, iff (x0, …, xn-1) lexicographically smaller than (y0, …, yn-1)
Use: symmetry breaking
in particular: matrix models (magic square)
![Page 66: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/66.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 66
Regular Constraint
Suppose variables xi (0 i < n) regular(xi , r) holds, iff the string x0…xn-1 forms a word from the language of the regular expression r
Use: describe patterns formed by variable
sequences
![Page 67: Search - kth.se · ID2204, L06, Christian Schulte, ICT, KTH . 4 . Improving Propagation Idea: propagator narrows domain of some (few) variables re-propagate only propagators sharing](https://reader034.vdocuments.site/reader034/viewer/2022042419/5f35969c08744b30bd70d318/html5/thumbnails/67.jpg)
2015-04-16 ID2204, L06, Christian Schulte, ICT, KTH 67
Goal
Understand and apply modeling abstractions modeling techniques
Understand propagation techniques