Constraint Programming: Michael Trick Carnegie Mellon
Constraint Programming: Michael Trick Carnegie Mellon
Michael Trick
(actually 75% Pascal Van Hentenryck, 20% Irv Lustig, 5% Trick)
Carnegie Mellon
Outline
Motivation
An Overview of Constraint Programming
Constraint Programming at Work
Getting Started
Sports Scheduling
Manufacturing
Perspectives
Combinatorial Optimization
Many, many practical applications
Resource allocation, scheduling, routing
Properties
Computationally difficult
Technical and modeling expertise needed
Experimental in nature
Important ($$$) in practice
Many solution techniques
Integer programming
Specialized methods
Local search/metaheuristics
Constraint programming
Constraint programming
Began in 1980s from AI world
Prolog III (Marseilles, France)
CLP(R)
CHIP (ECRC, Germany)
Application areas
Scheduling, sequencing, resource and personnel
allocation, etc. etc.
Active research area
Specialized conferences (CP, CP/AI-OR, …)
Journal (Constraints)
Companies
Constraint Programming
Two main contributions
A new approach to combinatorial optimization
Orthogonal and complementary to standard OR methods
Combinatorial versus numerical
A new language for combinatorial optimization
Rich language for constraints
Language for search procedures
Vertical extensions
The Tutorial
Goal: to provide an introduction
What is constraint programming?
What is it good for?
How does it compare to integer
programming?
How easy is it to use?
What is the underlying technology?
Constraint Programming
Constraint programming by example
Illustrate rich language
Contrast with integer programming
Illustrate some underlying technologies
Disclaimers
Can’t cover all of CP
I want to make you curious
Language/system used
Could use many; choose OPL
Modeling in Constraint
Programming
A rich constraint language
Arithmetic, higher-order, logical constraints
Global constraints for natural substructures
Specification of a search procedure
Definition of search tree to explore
Specification of search strategy
Comparison of CP/IP
Branch and Prune Branch and Bound
Prune: eliminate Bound: eliminate
infeasible configurations suboptimal solutions
Branch: decompose into Branch: decompose into
subproblems subproblems
Prune Bound
Carefully examine Use (linear) relaxation of
constraints to reduce problem (+ cuts)
possible variable values Branch
Branch Use information from
Use heuristics based on relaxation
feasibility info Main focus: objective
Main focus:constraints function and optimality
and feasibility
Illustrative artificial example
Color a map of (part of) Europe:
Belgium, Denmark, France, Germany,
Netherlands, Luxembourg
No two adjacent countries same color
Is four colors enough?
OPL example
enum Country
{Belgium,Denmark,France,Germany,Netherlands,Luxem
bourg};
Variables non-
enum Colors {blue,red,yellow,gray}; numeric
var Colors color[Country];
solve {
Constraints are
color[France] <> color[Belgium]; non-linear
color[France] <> color[Luxembourg];
color[France] <> color[Germany];
color[Luxembourg] <> color[Germany];
Looks nothing
color[Luxembourg] <> color[Belgium]; like IP!
color[Belgium] <> color[Netherlands];
color[Belgium] <> color[Germany];
color[Germany] <> color[Netherlands];
Perfectly legal
color[Germany] <> color[Denmark]; CP
};
Constraint Programming
Domain store Constraints
For each variable: Capture interesting
what is the set of and well studied
substructures
possible values?
Need to
If empty for any
Determine if
variable, then constraint is feasible
infeasible WRT the domain
store
If singleton for any Prune “impossible”
variable, then values from the
solution domains
Constraints
Can have differing techniques to
“handle” a constraint type:
3x+10y+2z + 4w = 4
x in {0,1}, y in {0,1,2}, z in {0,1,2}, w in {0,1}
Simple bound on sizes gives y in {0}
More complicated handling gives
x in {0}, y in {0}, z in {0,2}, w in {0,1}
Constraint Solving
General algorithm is
Repeat
select a constraint c
if c is infeasible wrt domain store
return infeasible
else apply pruning algorithm of c
Until no value can be removed
Branching
Once the constraint solving is done, if
the problem is not infeasible nor are the
domains singletons, then apply the
search method
Choose a variable x with non-singleton
domain (d1, d2, … di)
Foreach d in (d1, d2, … di)
add constraint x=di to problem and
solve
Show OPL solving coloring
problem
Strength of CP
Since there is no need for a linear
relaxation, the language can represent
much more directly (no need for big-M
IP formulations.
Examples of formulation
abilities
Facility location: want a constraint that
customer j can be assigned to warehouse i
only if warehouse open. (y[i]=1 if warehouse
i open)
IP: x[i,j] is 1 if cust j assigned to i
x[i,j] <= y[i]
CP:x[j] is the warehouse cust j assigned to (not
a 0,1 variable)
y[x[j]] = 1;
Similar example
Routing type constraints.
Let x[i] be the ith customer visited and
d[i,j] be distance from i to j
x4 4
x5 5
Alldifferent feasibility and
pruning
Pruning? Which edges are in no
matching?
x1
1 Domain is sharply
x2 reduced
2
x3 3
x4 4
x5 5
Global constraints
Many different types of constraints have
specialized routines
distribute(card,value,base): the
number of times value[i] appears in base is
card[i]
circuit(succ) : the values in succ form
a hamiltonian circuit (so if you follow the
sequence 1, succ[1], succ[succ[1]] etc, you
will get a loop through 1..n.
Global constraints
Many others, and new ones being
created all the time
Strengthen and expand the language
Make modeling easier and more natural
System is faster at finding solutions
Details hidden to user
Vertical language extensions
Can add constraints and definitions to
make modeling even more natural
Ideas remain the same: there are
domains and constraints; constraints
check for feasibility and prune domains;
a search strategy guides the system in
finding solutions
Scheduling
Want concepts of jobs, machines,
“before”, “after”, jobs requiring
machines, and so on.
Easy to extend
Example of scheduling
forall(j in Jobs)
forall(t in 1..nbTasks-1)
task[j,t] precedes task[j,t+1];
forall(j in Jobs)
forall(t in Tasks)
task[j,t] requires tool[resource[j,t]];
Search Strategy
Combined with model, search strategies
are integral to constraint systems.
Allow choice of branching variables or
more powerful search strategies
Can be key in solving problems
Two steps
Specify tree to search
Specify how to explore the tree
Example of Search Strategies
forall(s in Stores ordered by increasing
regretdmax(cost[s]))
tryall(w in Warehouses ordered by increasing
supplyCost[s,w]) supplier[s] = w; };
subject to {
forall (i in Slots)
i-rnge<=slot[i] <= i+rnge; /*Must be in range */
alldifferent(slot); /*must choose different slots */
forall (i in Slots)
revslot[slot[i]] = i;
};
Personal use
Tremendous help in my work on sports
scheduling: much easier to formulate
idiosyncratic constraints
Very fast to create prototypes
Competitive (at least!) to IP approaches
Result
Formulation is much easier than IP
formulation
Gets good solutions much faster than IP
Is competitive in proving optimality
Finding optimal solutions
Constraint programs can find optimal
solutions. Typically works by finding a
feasible solution and adding a
constraint that future solutions must be
better than it. Repeat until infeasible:
the last solution found is optimal
Perspectives
Many solution techniques
Integer programming
Constraint programming
Local search
Combinations
Which to use?
Comparing IP and CP
Complementary technologies
Integer programming
Objective function: relaxations
Constraint programming
Feasibility: domain reductions
Might need to experiment with both
CP particularly useful when IP formulation is
hard or relaxation does not give much
information
Combining Methods
Local and Global Search
Use CP/IP for very large neighborhood
search (take a solution, remove large
subset, find optimal completion)
Combining CP and IP
Use LP as constraint handler
Use CP as subproblem solver in branch and
price
……
Conclusions
Constraint programming should become a
part of every OR person’s toolkit
Combinations of CP and IP represent a “big
thing” in future techniques
Blurring of lines between optimization and
heuristics
This talk at
http://mat.gsia.cmu.edu/INFORMS/cp.ppt