Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Filtering Algorithms for Global Constraints Classes of Constraints - - PowerPoint PPT Presentation
Filtering Algorithms for Global Constraints Classes of Constraints - - PowerPoint PPT Presentation
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Filtering Algorithms for Global Constraints Classes of Constraints Application-Based Graph-Based Mats Carlsson Filtering Algorithms Adding
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Outline
Constraint Programming Systems Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometry Matching Theory Flow Theory Scheduling Theory Final Remarks References
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Constraint Programming Systems
◮ constraint network: domain variables and
constraints
◮ propagation loop ◮ search procedure
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
The CP View
Problem = conjunction of constraints
◮ constraint = subproblem ◮ trivial constraint: x < y ◮ complex constraint: all different([x1, . . . , xn]): the
xi variables must be pairwise different
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Problem Solving
Problem solving = propagation + search
◮ every constraint C comes with a filtering algorithm
(FA), aka. propagator
◮ the FA removes values that do not belong to any
solution of C from the domains of the variables
◮ the propagation loop applies FA’s until a fixpoint is
reached
◮ the search procedure adds tentative constraints at
such fixpoints
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Strength of Filtering
Notions of Consistency
◮ arc-consistency (AC): all values that do not belong
to any solution of C are removed (perfect filtering)
◮ sometimes called generalized arc-consistency
(GAC) in the context of non-binary constraints
◮ a weaker form, bound-consistency (BC), adjusts
the lower and upper bounds of domains
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Strength of Filtering
Example [Puget 1998]
Constraint Network all different([x, y, z, u, v, w]) x ∈ [3, 4], y = 7, z ∈ [2, 5], u ∈ [2, 7], v ∈ [1, 3], w ∈ [3, 4] Arc-Consistent Domains x ∈ [3, 4], y = 7, z ∈ {2, 5}, u ∈ {2, 5, 6}, v ∈ [1, 2], w ∈ [3, 4] Bound-Consistent Domains x ∈ [3, 4], y = 7, z ∈ [2, 5], u ∈ [2, 6], v ∈ [1, 2], w ∈ [3, 4]
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Outline
Constraint Programming Systems Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometry Matching Theory Flow Theory Scheduling Theory Final Remarks References
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Global Constraints
Definition
C is a global constraint iff C is ...
◮ a non-binary constraint ◮ a conjunction of elementary constraints ◮ an abstraction for which we can have a FA with a
global view
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Global Constraints
Advantages
expressiveness they correspond to common structures in combinatorial problems reusability a library of global constraints is a library
- f reusable software components
efficiency they admit powerful filtering algorithms
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Outline
Constraint Programming Systems Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometry Matching Theory Flow Theory Scheduling Theory Final Remarks References
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
An Application-Based Classification
◮ order constraints ◮ value constraints ◮ partitioning constraints ◮ timetabling constraints ◮ graph constraints ◮ scheduling constraints ◮ data constraints
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Some Order Constraints
min(x, [y1, . . . , yn]) max(x, [y1, . . . , yn]) min n(x, k, [y1, . . . , yn]) x is the kth smallest value max n(x, k, [y1, . . . , yn]) x is the kth largest value sorting([x1, . . . , xn], [y1, . . . , yn]) [y1, . . . , yn] is a permutation of [x1, . . . , xn] in nondecreasing order. lex chain([t1, . . . , tn]) [t1, . . . , tn] is a sequence of tuples in lexicographic order.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Some Value Constraints
among(k, [y1, . . . , yn], [v1, . . . , vm]) k vars in [y1, . . . , yn] take values in [v1, . . . , vm] common(k, l, [x1, . . . , xn], [y1, . . . , ym]) k vars in [x1, . . . , xn] take values in [y1, . . . , ym], and l vars in [y1, . . . , ym] take values in [x1, . . . , xn] same([x1, . . . , xn], [y1, . . . , yn]) [x1, . . . , xn] is a permutation of [y1, . . . , yn]
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Some Partitioning Constraints
all different([x1, . . . , xn]) ∀i, j : xi = xj symmetric all different([x1, . . . , xn]) ∀i, j : xi = xj ∧ (xi = j ≡ xj = i) nvalue(k, [x1, . . . , xn]) xi take k different values gcc([x1, . . . , xn], [(v1, c1), . . . , (vm, cm)]) value vj occurs cj times in [x1, . . . , xn]
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Some Timetabling Constraints
change(k, [x1, . . . , xn], ◦) xi ◦ xi+1 holds k times inflexion(k, [x1, . . . , xn]) the sequence order switches from strictly increasing to strictly decreasing (or vice versa) k times
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Some Graph Constraints
Successor Notation [x1, . . . , xn] means from node i we go to node xi Predecessor Notation [x1, . . . , xn] means we came to node i from node xi cycle(k, [x1, . . . , xn]) there are k cycles in [x1, . . . , xn] inverse([x1, . . . , xn], [y1, . . . , yn]) [x1, . . . , xn] is the successor notation of a path, and [y1, . . . , yn] is its predecessor notation
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Some Scheduling Constraints
Task Notation task(s, d, e, r, m) means a task with start time s, duration d, end time e, resource consumption r, and machine assignment m cumulative([t1, . . . , tn], l) n tasks are scheduled on a single machine so that at any time, the total resource consumption does not exceed l cumulatives([t1, . . . , tn], [l1, . . . , lm]) n tasks are scheduled on m machines so that at any time, the total resource consumption of machine i does not exceed li
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Some Data Constraints
element(i, [v1, . . . , vm], x) vi = x table([t1, . . . , tm], [r1, . . . , rn]) each tuple ti is a member
- f the (ground) relation [r1, . . . , rn]
case(template, [t1, . . . , tm], dag) each tuple ti is a member of the (ground) relation encoded by dag
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
A Graph-Theoretic Classification
[Beldiceanu 2000a]
Global Constraints as Graph Properties of Structured Networks of Elementary Constraints of the Same Type
◮ Find out the basic constituents of the global
constraint.
◮ Classify the properties of each basic constituent. ◮ Understand how the properties interact.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
A Graph-Theoretic Classification
A Simple Global Constraint
Initial network
Arcs are associated with elementary constraints. Final network
Ask properties of sub-graph of elementary constraints that still hold.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
A Graph-Theoretic Classification
Graph Generators
LOOP
- SELF
- PATH
CHAIN
- CIRCUIT
- CYCLE
- PRODUCT
- SYMMETRIC PRODUCT
- GRID
- CLIQUE
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
A Graph-Theoretic Classification
Graph Characteristics
NVERTEX |V(G)| NEDGE |E(G)| NSOURCE number of vertices without predecessor NSINK number of vertices without successor NCC number of connected components of G MIN NCC number of vertices of smallest c.c. of G MAX NCC number of vertices of largest c.c. of G NSCC number of strongly connected components of G MIN NSCC number of vertices of smallest s.c.c. of G MAX NSCC number of vertices of largest s.c.c. of G
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
A Graph-Theoretic Classification
Graph Properties and Graph Invariants
◮ A graph property is a relation
C ◦ V, ◦ ∈ {≤, ≥, =, =}, where C is a graph characteristic and V is a domain variable.
◮ A graph invariant is a relation on graph
characteristics that is valid for a class of graphs. They form necessary conditions.
◮ Example:
MIN NSCC = MAX NSCC ⇒ NVERTEX ≥ MIN NSCC + MAX NSCC
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
A Graph-Theoretic Classification
The Global Constraint “Space”
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
A Graph-Theoretic Classification
Example: nvalue(NVAL, VARS)
arguments NVAL : dvar, VARS : collection(var − dvar) restrictions 0 ≤ NVAL ≤ |VARS| arc input variables arc generator clique arc constraint VARS.var[1] = VARS.var[2] graph properties NSCC = NVAL example nvalue(3, {var − 3, var − 1, var − 7, var − 1})
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
A Graph-Theoretic Classification
Example: nvalue(3, {var − 3, var − 1, var − 7, var − 1})
Initial network: variables unbound
- V1
=
- =
- =
- =
- V2
=
- =
- =
- V3
=
- =
- V4
=
- Final network: variables instantiated, NSCC = 3
- 3
=
- 1
=
- =
- 7
=
- 1
=
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
A Graph-Theoretic Classification
A Catalog of Global Constraints [BelCarRam05]
◮ 235 constraints described explicitly (by Prolog
facts).
◮ Reference pages and figures generated
automatically from Prolog facts.
◮ 157 graph invariants identified. ◮ About 30 arc generators. ◮ About 30 graph properties.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Outline
Constraint Programming Systems Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometry Matching Theory Flow Theory Scheduling Theory Final Remarks References
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Adding Redundant Constraints
Constraint Network x = y, x = z1, . . . , x = zn y = z1, . . . , y = zn z1 = z2, . . . , z2 = zn · · · zn−1 = zn D(x) = D(y) = {0, 1} Propagation
- Nothing. But either x = 0, y = 1 or x = 1, y = 0, so no
- ther variables can take these values. So we can
remove them from the other variables.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Adding Redundant Constraints
Constraint Network all different([x, y, z1, . . . , zn]) D(x) = D(y) = {0, 1} Propagation 0 and 1 are removed from D(z1), . . . , D(zn).
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
GAC-Schema
GAC-Schema [Bessi` ere & R´ egin 1997]
◮ A generic framework for achieving AC for any
constraint.
◮ You just have to provide a way of computing a
solution.
◮ Works incrementally (notion of support).
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
GAC-Schema
Providing Solutions
◮ List of allowed tuples. ◮ List of forbidden tuples. ◮ Any algorithm, e.g. constraint checker. ◮ Solver re-entrance.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
GAC-Schema
Key Idea
tuple partial solution of the constraint support ground, valid tuple
◮ while the tuple is valid: do nothing ◮ otherwise, search for a new support
for the values it contains
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
GAC-Schema
Complexity
◮ For n variables, d values, S the cost of seeking a
support, AC is achieved in O(ndS).
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Finite Automata
[Beldiceanu, Carlsson & Petit 2004]
◮ Writing a constraint checker is much easier than
writing a filtering algorithm.
◮ A checker can often be expressed as a finite
automaton with counters.
◮ A finite automaton can be generalized to deal with
variable sequences, constraining the sequence to be recognized by the automaton.
◮ We have implemented a generic global
constraints, parameterized by a given finite automaton.
◮ Under certain conditions, the constraint achieves
AC.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Finite Automata
Example: inflexion(k, [x1, . . . , xn])
Definition Holds if k is the number of times that the sequence
- rder switches between strictly increasing and strictly
decreasing. Example inflexion(4, [3, 3, 1, 4, 5, 5, 6, 5, 5, 6, 3]) holds since we have the four subsequences 314, 565, 6556 and 563, which all contain such a switch.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Finite Automata
Automaton for inflexion
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Computational Geometry
Sweep [Beldiceanu 2000b]
◮ Standard technique in the design of efficient
algorithms.
◮ Used in filtering algorithms [Beldiceanu &
Carlsson 2001].
◮ For pruning a conjunction of constraints with two
shared variables.
◮ For instance, the constraint that a rectange does
not overlap with a set of other rectangles.
◮ disjoint2([r1, . . . , rn]) expresses n such constraints.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Computational Geometry
Sweep for Line Intersections
Iteration:
- 1. Move to the
next event point.
- 2. Update the
sweep line status.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Computational Geometry
Sweep: Forbidden Regions
Definition The forbidden region of constraint C wrt. x and y are the two intervals [x, x] and [y, y] such that: ∀x ∈ [x, x], y ∈ [y, y] : C(x, y, . . .) is false Example The forbidden region of all different wrt. x and y is:
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Computational Geometry
Sweep: Example
Task: adjust min(x) for a set
- f forbidden regions wrt. x
and y.
◮ Sweep line: x. ◮ Sweep line status: for
each y value, #forbidden regions containing (x, y).
◮ x = 0 is infeasible.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Computational Geometry
Sweep: Example
Task: adjust min(x) for a set
- f forbidden regions wrt. x
and y.
◮ Sweep line: x. ◮ Sweep line status: for
each y value, #forbidden regions containing (x, y).
◮ x = 1 is infeasible.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Computational Geometry
Sweep: Example
x = 0, . . . , 3 are infeasible, but x = 4 is feasible.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Matching Theory
all different([x1, . . . , xn]) [R´ egin 1994]
◮ A matching is a set of edges with distinct
endpoints.
◮ A matching M covers X if every vertex in X is an
endopint of M.
◮ A solution to all different(X) is a matching M
between X and its values such that M covers X.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Matching Theory
all different([x1, . . . , xn])
Berge’s Theorem An edge belongs to some maximum matching iff, for an arbitrary matching, it belongs to:
◮ either an even alternating path beginning
at a free vertex,
◮ or an even alternating cycle.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Matching Theory
all different([x1, . . . , xn]): Example [R´ egin 1994]
Domains x1 ∈ {1, 2} x2 ∈ {2, 3} x3 ∈ {1, 3} x4 ∈ {3, 4} x5 ∈ {2, 4, 5, 6} x6 ∈ {5, 6, 7}
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Matching Theory
all different([x1, . . . , xn]): Example [R´ egin 1994]
Matching
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Matching Theory
all different([x1, . . . , xn]): Example [R´ egin 1994]
Alternating Paths and Cycles
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Matching Theory
all different([x1, . . . , xn]): Example [R´ egin 1994]
Arc Consistent Domains x1 ∈ {1, 2} x2 ∈ {2, 3} x3 ∈ {1, 3} x4 ∈ {4} x5 ∈ {5, 6} x6 ∈ {5, 6, 7}
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Matching Theory
all different([x1, . . . , xn]): Complexity
◮ AC in O(n3/2d) from scratch. ◮ AC in O(knd) incrementally. ◮ BC in O(n + d) from scratch.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Matching Theory
An Auxiliary Constraint for Sudoku [Simonis 2005]
◮ Nine constraints: one for each value v ∈ [1, 9]. ◮ Each value v must occur exactly once in each row
and column.
◮ A matching between rows and columns. ◮ A special case of the colored matrix aka.
cardinality matrix constraint.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Matching Theory
An Auxiliary Constraint for Sudoku
- 1. Create row and column vertices.
- 2. Create edge (i, j) if v ∈ Mij.
- 3. Find a maximal matching.
- 4. Identify strongly connected components (SCCs)
in the reoriented graph.
- 5. Remove edges (i, j) connecting distinct SCCs.
- 6. Remove v from the corresponding Mij.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Flow Theory
gcc([x1, . . . , xn], [(v1, c1), . . . , (vm, cm)]) [R´ egin 1996]
◮ Value vj occurs cj times in [x1, . . . , xn]. ◮ Modelled as a flow from [v1, . . . , vm] to [x1, . . . , xn]. ◮ Arcs that cannot belong to a feasible flow
correspond to infeasible values.
◮ Infeasible arcs discovered in a way similar to
all different.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Flow Theory
gcc([x1, . . . , xn], [(v1, c1), . . . , (vm, cm)]): Example [R´ egin 1996]
Value Graph
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Flow Theory
gcc([x1, . . . , xn], [(v1, c1), . . . , (vm, cm)]): Example [R´ egin 1996]
A Feasible Flow
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Flow Theory
gcc([x1, . . . , xn], [(v1, c1), . . . , (vm, cm)]): Example [R´ egin 1996]
Feasible Arcs Only
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Flow Theory
gcc([x1, . . . , xn], [(v1, c1), . . . , (vm, cm)]): Complexity
◮ AC in O(n3/2m) from scratch. ◮ BC in O(n + m) from scratch.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Flow Theory
An Auxiliary Constraint for Sudoku [Simonis 2005]
◮ Consider the conjunction of a column (row) and a
3x3 box.
◮ One sets of six variables must use the same
values as another set of six values.
◮ A special case of same with cardinality. ◮ AC is achieved by solving a flow problem.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Scheduling Theory
Common Notions
unary resource A non-sharable resource (machine). discrete resource A resource (machine) that is sharable up to a fixed capacity. task An activity to be placed in time, consuming some amount of resource on some machine.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Scheduling Theory
Filtering Algorithms for Unary Resources
Let Ω be a set of tasks and i, j ∈ Ω be single tasks. Edge-Finding Rules to infer that i must be scheduled before (after) all tasks in Ω, which allows to adjust the start (completion) time of i. Not-First/Not-Last Rules to infer that i cannot be scheduled before (after) all tasks in Ω, which allows to adjust the start (completion) time of i. Detectable Precedences Rules to infer that i must be scheduled before (after) j, which allows to adjust the start (completion) times of i and j. Can all be done in O(n log n) [Vil´ ım 2004].
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Outline
Constraint Programming Systems Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometry Matching Theory Flow Theory Scheduling Theory Final Remarks References
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Some Pitfalls
Designing Constraints
◮ Allow parameters to be variables (not integers) for
better expressive power, e.g.: element(i, [v1, . . . , vm], x) cumulative([t1, . . . , tn], l) gcc([x1, . . . , xn], [(v1, c1), . . . , (vm, cm)])
◮ Group related parameters into collection of
- bjects, cf.:
cumulative( [t1, . . . , tn], l) cumulative( [s1, . . . , sn], [d1, . . . , dn], [e1, . . . , en], [r1, . . . , rn], l)
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Some Pitfalls
Complexity
◮ Complexity results assume no aliasing among
parameters.
◮ Complexity of what case:
◮ worst-case ◮ average-case
◮ Complexity of what operation:
◮ one run of the algorithm from scratch ◮ one run of the algorithm after some change ◮ reaching a leaf without backtracking ◮ exploring the whole tree
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Some Pitfalls
Complexity
The complexity of the algorithm depends on the cost
- f some services provided by the constraint kernel:
◮ adjusting domain bounds ◮ checking v ∈ D(x) ◮ removing v from D(x) ◮ given v ∈ D(x), finding the next value is
important, e.g. for SCC analysis These costs should be independent of the domain size.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Implementation Issues
Stateful Propagators
If a FA does not have state, each time it wakes up it has to:
◮ Parse and check the parameters. ◮ Allocate and deallocate memory. ◮ Create the necessary datastructures. ◮ Sacrifice any opportunity for being incremental.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Implementation Issues
Incrementality
◮ Examples of opportunities for being incremental:
◮ Maintain partitioning of parameters as (ground,
nonground).
◮ Arithmetic constraints can detect in O(1) time that
nothing can be pruned.
◮ all different reuses and augments the previous
graph and matching.
◮ gcc reuses and augments the previous graph and
flow.
◮ case does not revisit failed DAG nodes. ◮ disjoint2 maintains a witness for the sides of each
rectangle to avoid sweeps.
◮ ≤lex remembers where it exited the automaton.
◮ Problems with incrementality:
◮ Only valid while in the same branch. ◮ Normally, recompute from scratch upon
backtracking.
◮ If too much has changed, incrementality costs
more than recomputation.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Implementation Issues
Domination
◮ General idea: find a rule saying “if object o1 is
valid (cannot be pruned), then object o2 is also valid”.
◮ We say that o1 dominates o2. ◮ Example use: in disjoint2, for rectangles sharing
the same min(x), plus other conditions.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Implementation Issues
Fixpoints and Aliasing
Should the FA reach a fixpoint or not?
◮ Sometimes easy to achieve, sometimes not. ◮ Last resort: enclose the whole FA in a fixpoint
loop.
◮ Constraint kernel should accommodate fixpoint as
well as non-fixpoint FAs.
◮ Aliased parameters (possible in some host
languages) destroy fixpoint properties.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Methodology Issues
Performance Analysis
◮ Several complexity measures are relevant:
non-incremental one run of the algorithm from scratch incremental one run of the algorithm after some change amortized reaching a leaf without backtracking
◮ How to evaluate performance:
◮ worst-case complexity analysis ◮ benchmarking the FA in isolation ◮ benchmarking the FA in context of an application
◮ My favorite presentation method: scatter plots.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Methodology Issues
Debugging
◮ Writing a FA is tedious and error-prone. Common
errors:
- 1. false instances are accepted
- 2. too much pruning (loss of solutions)
- 3. too little pruning (loss of propagation)
◮ Debugging methodology: generate random
instances.
◮ Compare FA with an alternative, equivalent
implementation.
◮ Run FA once and compare domains. ◮ Collect all solutions and compare their numbers. ◮ Randomize domains as well as variable order and
value order.
◮ Study small instances to get inspiration about
more filtering rules.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
Outline
Constraint Programming Systems Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometry Matching Theory Flow Theory Scheduling Theory Final Remarks References
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
References
Jean-Charles R´ egin. A filtering algorithm for constraints of difference in CSP .
- Proc. AAAI-94, 1994.
Jean-Charles R´ egin. Generalized Arc Consistency for gcc Constraint.
- Proc. AAAI-96, 1996.
Christian Bessi` ere & Jean-Charles R´ egin. Arc Consistency for General Constraint Networks: Preliminary Results
- Proc. IJCAI-97, 1997.
Jean-Charles R´ egin. The Symmetric all different Constraint.
- Proc. IJCAI-99, 1999.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
References
Nicolas Beldiceanu. Global constraints as graph properties on structured network of elementary constaints of the same type.
- Proc. CP
, 2000. Nicolas Beldiceanu, Mats Carlsson, Jean-Xavier Rampon, Charlotte Truchet. Graph Invariants as Necessary Conditions for Global Constraints. SICS Technical Report T2005-07, 2005. Nicolas Beldiceanu, Mats Carlsson, Jean-Xavier Rampon. Global Constraint Catalog. SICS Technical Report T2005-08, 2005.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
References
Nicolas Beldiceanu, Mats Carlsson, Thierry Petit. Deriving filtering algorithms from constraint checkers.
- Proc. CP
, LNCS 3258, 2004. Helmut Simonis. Sudoku as a Constraint Problem.
- Proc. Workshop on Modelling and Reformulating
Constraint Satisfaction Problems at CP , 2005. Petr Vil´ ım. O(n log n) filtering algorithmsfor unary resource constraint.
- Proc. CP-AI-OR, 2004.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
References
Nicolas Beldiceanu. Sweep as a Generic Pruning Technique.
- Proc. TRICS Workshop at CP
, 2000. Nicolas Beldiceanu, Mats Carlsson. Sweep as a generic pruning technique applied to the non-overlapping rectangles constraint.
- Proc. CP
, 2001.
Filtering Algorithms for Global Constraints Mats Carlsson Constraint Programming Global Constraints Classes of Constraints Application-Based Graph-Based Filtering Algorithms Adding Redundant Constraints GAC-Schema Finite Automata Computational Geometr Matching Theory Flow Theory Scheduling Theory Final Remarks References
References
Jean-Franc ¸ois Puget. A fast algorithm for the bound consistency of all different constraints.
- Proc. AAAI-98, 1998.
kurt Mehlhorn & Sven Thiel. Faster Algorithms for Bound-Consistency of the sorting and the all different Constraints.
- Proc. CP
, 2000. Irit Katriel & Sven Thiel. Fast Bound Consistency for the gcc Constraint.
- Proc. CP