An Introduction to CP
CP = A technique to solve CSPs and COPs ■ CSP = Constraint Satisfaction Problem ■ COP = Constraint Optimization Problem ■ It. Problema di Soddisfacimento/Ottimizzazione di/con Vincoli A declarative approach ■ Model & then solve (a bit like MIP) ■ Model = variables + constraints ■ Rich set of constraints (much more than linear in-equalities) Is it worth learning?
■ Netherlands railways: 5,500 trains per day ■ In 2009: timetable complete redesign (OR and CP) ■ Less delay, more trains, profit increase: ~\$75M
■ Port of Singapore: > 200 shipping lines, > 600 connected ports ■ Problem: yard location assignment, loading plans ■ For years, the Yard planning system (CP based) assisted the job
■ Rosetta-Philae mission ■ In 2014, first (partially successful) probe landing on a Comet ■ Probe-spacecraft communication pre-scheduled via CP
A few reasons for using CP: ■ Rich modeling language ■ Fast prototyping ■ Easy to maintain (modifications are simple) ■ Extensible (new constraints, customizable search...) ■ Very good framework for hybrid approaches Overall: ■ It's a good solution technique! ■ Especially for messy, real-world, problems
Before we tackle complex stuff Let's take our first steps...
4 available colors, different colors for contiguous regions How would you solve it?
4 available colors, different colors for contiguous regions ■ Pick and color a region ■ Pick another region, choose a compatible color ■ Rinse & repeat
4 available colors, different colors for contiguous regions Eventually we find something like this
■ Think of that as "Poor's man sudoku" ■ Different numbers (1 to 4) on rows and columns 2 3 3 4 How would you solve it?
■ Think of that as "Poor's man sudoku" ■ Different numbers (1 to 4) on rows and columns 2 3 3 4 ■ Pick a cell, insert compatible value ■ Rinse & repeat
■ Think of that as "Poor's man sudoku" ■ Different numbers (1 to 4) on rows and columns 2 3 3 2 1 4 What now?
■ Think of that as "Poor's man sudoku" ■ Different numbers on rows and columns 2 3 3 2 1 4 ■ Clear one of more moves ■ Restart to insert numbers
■ Think of that as "Poor's man sudoku" ■ Different numbers on rows and columns 1 3 2 4 3 2 1 4 4 2 3 1 3 1 2 4 Eventually, we find something like this
You see? There is a pattern. ■ We reason on the constraints to narrow down the possible choice ■ We make (and unmake) some choices The core ideas in Constraint Programming are the same! To the point that for many people: CP = constraint reasoning + search
You see? There is a pattern. ■ We reason on the constraints to narrow down the possible choice ■ We make (and unmake) some choices The core ideas in Constraint Programming are the same! But I am not many people! I think this formula is much better: CP = model + constraint reasoning + search ■ CP is a declarative approach, remember? ■ So it all starts with a declarative model In the next slides we will focus on each of the three aspects
CP = model + ...
■ First, we need to define the kind of problem we are interested in: where: ■ is a set of variables ■ is a single variable ■ In principle: any kind of variable! ■ is a set of domains ■ takes values in ■ is a set of constraints
Constraint scope (Italian: ambito) ■ A constraint is defined over a subset of of the variables ■ is called the scope of the constraint Tuple ■ A tuple or arity is just a sequence of values Relation ■ Let be a sequence of sets ■ A relation over is a subset of the Cartesian product. I.e.:
Constraint ■ A constraint is a relation over the domains of . I.e.: Here's the main idea: ■ A tuple in the Cartesian product = an assignment of the variables ■ A constraint is just a list of feasible assignments A bit abstract, so let's make an example
Variables: Domains: , Constraints:
A solution for a CSP is an assignment of all the variables that is feasible for all constraints. Formally: where: ■ is the projection of over ■ = sequence of values assigned by to variables in
A solution for a CSP is an assignment of all the variables that is feasible for all constraints. Formally: The solutions in our example: , , , A CSP with no solution is called infeasible.
Any kind of domain?
Any kind of domain? In practice: ■ Integer variables ■ Real variables ■ Set variables! (e.g. ) ■ Graph variables! ■ ... In this course: ■ Strong emphasis on finite, integer domains ■ The most studied case
Any kind of constraints?
Any kind of constraints? ■ With finite domain variables, yes! ■ We can actually list all the feasible assignments This is called extensional representation ■ Very general ■ Possibly inconvenient and inefficient (large domains) We may prefer a symbolic or intensional representation: ■ More compact, more clear, less general
Intensional forms are made possible by Constraint libraries ■ Constraint library = collection of constraint types Our first constraint library: Equality: ■ Notation: ■ Semantic: satisfied if is equal to Disequality: ■ Notation: ■ Semantic: satisfied if is not equal to
Variables and domains: ■ , for each region Constraints: ■ if region and are contiguous
2 3 3 4 Variables and domains: ■ , for each cell ■ = row index, = column index Constraints: ■ ■
2 3 3 4 Variables and domains: ■ , for each cell = row index, = column index ■ Constraints: ■ is cell is pre-filled with value
CP = model + constraint reasoning + ...
2 3 3 3 4 ■ We would never put a 3 there (not compatible) ■ Can we formalize this deduction? Main idea: reason on the domains
2 3 3 1 2 4 3 4 ■ ■ ■
2 3 3 1 4 ■ The only possible value for is 1
Filtering for = removing provably infeasible values from the domains of the variables in the constraint scope ■ Alternative terms: pruning, propagation ■ My convention: ■ Pruning = the act of removing a single value ■ Filtering = the process that guides pruning ■ Propagation = later! ■ Italian: propagation = propagazione
Filtering for = removing provably infeasible values from the domains of the variables in the constraint scope ■ For constraints in extensional form: ■ General methods (we will see them later) ■ For constraints in intensional form: ■ Specialized filtering algorithms ■ Those are specified in the constraint library ■ Alternative names: filtering rules, propagators
Equality constraint: ■ Rule 1: ■ Rule 2: Examples: ■ Before filtering: ■ After filtering:
Disequality constraint: ■ Rule 1: ■ Rule 2: Examples: ■ Before filtering: ■ After filtering:
1 2 1 2 1 2 2 3 4 3 4 3 4 1 2 1 2 1 2 3 3 4 3 4 3 4 1 2 1 2 1 2 3 3 4 3 4 3 4 1 2 1 2 1 2 4 3 4 3 4 3 4 ■ All original domains are ■ Let's filter all the constraints in order ■ By row and then column
1 1 2 1 2 2 3 4 3 4 3 4 1 2 1 2 1 2 3 3 4 3 4 3 4 1 2 1 2 1 2 3 3 4 3 4 3 4 1 2 1 2 1 2 4 3 4 3 4 3 4 ■ Constraint prunes 2 from
1 1 1 2 2 3 4 3 4 3 4 1 2 1 2 1 2 3 3 4 3 4 3 4 1 2 1 2 1 2 3 3 4 3 4 3 4 1 2 1 2 1 2 4 3 4 3 4 3 4 ■ Constraint prunes 2 from
1 1 1 2 3 4 3 4 3 4 1 2 1 2 1 3 3 4 3 4 3 4 1 2 1 2 1 2 3 3 4 3 4 3 4 1 2 1 1 2 4 3 4 3 4 3 4 ■ Constraints and prune a lot
1 1 1 2 3 4 3 3 4 1 2 1 2 1 3 4 4 1 2 1 2 1 2 3 4 4 1 2 1 2 4 3 ■ By filtering all constraints in order, we get this Can we do more?
1 1 1 2 3 4 3 3 4 1 2 1 2 1 3 4 4 1 2 1 2 1 2 3 4 4 1 2 1 2 4 3 ■ Yep: and are now singletons ■ Hence, our filtering rules for the constraints can be triggered ■ If we do, we can filter more
Propagation = the process by which filtering from one constraint may enable filtering from another constraint ■ Propagation is controlled by a propagation algorithm
Algorithm: AC1 dirty = true while dirty: dirty = false for : if : dirty = true Where is a procedure that: ■ Given the current variable domains... ■ ...Applies the filtering algorithm of ... ■ ...And then returns the updated domains
AC1 always converges to a fix point, which is independent on the constraint processing order. Proof: We will prove the result in two steps: ■ First, we show that AC1 always terminates... ■ ...When no more pruning can be done ■ Second, we show that the processing order does not matter The proof relies on some properties of
The function filter( ) is inflationary, i.e.: ■ True because a filtering algorithm can only remove domains values ■ Caveat: ■ Technically, is inflationary w.r.t. the order ■ Hence, the term may sound a bit misleading Consequence: AC1 always terminates ■ In the worst case, when becomes empty
Recommend
More recommend