Constraint programming
https://www.coursera.org/learn/discrete-optimization
General introduction
Constraint programming is an optimization technique that emerged from the field of artificial intelligence. It is characterized by two key ideas: To express the optimization problem at a high level to reveal its structure and to use constraints to reduce the search space by removing, from the variable domains, values that cannot appear in solutions.
Computation paradigm:
- Use constraint to reduce the set of values that each variable can take.
- Make a choice when no deduction can be performed. (assign a value to a variable)
- Choices can be wrong. Then the solver backtracks, tries another value.
Branch and prune:
Branch: decompose the problem into subproblem and explore the subproblems. (try all possible values of a variable until a solution is found or it can be proved that no solution exists.)
Prune: reduce the search space as much as possible. Use constraints to remove, from the variable domains, value that cannot belong to any solution.
A constraint just does two things:
- Feasibility checking. A constraint checks if it can be satisfied given the values in the domains of its variables.
- Pruning. If satisfiable, a constraint determines which values in the domains cannot be part of any solution.
The propagation engine(pseudocode)
def propagate ()
repeat until no constraint can remove any value from the domain of its variable
select a constraint c
if c is infeasible
return False
else
prune ()
return True
global constraint:
Sometimes if you take the constraints one by one to check feasibility, it will lose some information. Because the constraints are not independent, so global constraint help you to consider all the constraints at the same time and make it earlier to prune the infeasibility.
Optimize:
Impose a constraint that the next solution must be better.
Symmetric breaking constraint:
-impose an ordering on the variables
-impose a lexicographic constraint
Redundant constraint:
Motivation: they do not exclude any solution, but they reduce the search space. They express the properties not captured by the model.
-boost the propagation of other constraints
-provide a more global view
-combine existing constraint
Dual modeling:
Sometimes there are multiple ways to modeling the problem. And the two models may have complementary strengths. Some constraints are easier to express in one model and other in another one. Dual modeling is the idea of stating multiple models of a problem and linking them with constraints.
First-fail principle
Try first where you are most likely to fail. Do not spend time doing easy stuff first and avoid redoing the difficult part.
Variable-value labeling:
- Choose the variable to assign
- Choose the value to assign
-first fail principle: choose the variable with smallest domain
-reconsider the selection of the variable after each choice(the variable ordering is dynamic)
-value ordering: often choose a value that leaves as many options as possible to the other variables
Value-variable labeling:
- Choose the value to assign
- Choose the variable to assign
-you may know that value must be assigned
-often the case in scheduling and resource allocation problems
Domain splitting
Sometimes assign a value to a variable is too strong(too arbitrary). so, we can split the domain of the value into two parts and decide which part should we choose. It is a much weaker commitment.
Randomization and restarts
Sometimes it is not obvious ordering. The key idea of randomization is to try a random ordering and if no solution is found after some limit(e.g. limit searching time), restart the search.
some problems and models
the 8-queens problem
Problem statement:
Place 8 queens on the chessboard so that none of them attack each other.
Two queens attack each other if they are in the same row, column or diagonal.
Model:
Coloring the map
Problem statement:
Color a map so that no two adjacent territories receive the same color.
(It has been proved by Kenneth Appel and Wolfgang Haken that every map can be colored with just 4 colors.)
Model:
Send more money
Problem statement:
Assign different digits to letters to satisfy the addition: send+more=money
Model:
Linear constraint over integers:
Consider a constraint
a1x1+a2x2+…+anxn>=b1y1+…+bnyn
a,b are positive constants
x,y are variables with domain D(x) and D(y)
Feasibility test:
l=a1max(D(x1))+…+anmax(D(xn))>=b1min(D(y1))+…+bnmin(D(yn))=r
Pruning:
aixi>=r-(l-aimax(D(xi)))
biyi<=l-(r-bimin(D(yi)))
magic series
Problem statement:
A series S=(S0,S1…,Sn)is magic if Si represents the number of occurrence of i in S
Model:
Redundant constraint:
Sum(i in D) series[i]=n
Sum(i in D)series[i]*i=n
Stable marriages:
Problem statement:
There are a set of men and women. Every man or woman should provide a ranking of the women or men. A marriage between A and B is stable provided that: if A prefer another woman C over B, then C must prefer her husband over A. and if B prefer another man D over A, then D must prefer his wife over B.
Model:
Balanced incomplete block design
Problem statement:
Input:(v,b,r,k,l)
Output: a v by b 0/1 matrix with exactly r ones per row and k ones per column, and the dot product of any two rows or columns is l
Model:
Car sequencing
Problem statement:
There are many cars on the assembly line. And cars require specific options like leather seats or some other thing. There is also capacity constraint on the production line. For example, at most 2 of 5 successive cars can require a leather seat. You should sequence all cars such that the capacity constraints are satisfied.
Model:
Magic square problem
Problem statement:
Place all different numbers in a square such that all rows, columns, diagonals sum to the same number.
Model: