Introduction to Constraint Programming

95
Introduction to Constraint Programming Mohsen Salarrezaei Advanced Linear programming Course Sharif University of Technology Autumn 2010

description

Introduction to Constraint Programming. Mohsen Salarrezaei Advanced Linear programming Course Sharif University of Technology Autumn 2010. Outline. Introduction Constraint propagation Backtracking search Some application Global constraints Symmetry Modeling. The Tutorial. - PowerPoint PPT Presentation

Transcript of Introduction to Constraint Programming

Page 1: Introduction to Constraint Programming

Introduction to Constraint Programming

Mohsen SalarrezaeiAdvanced Linear programming CourseSharif University of Technology

Autumn 2010

Page 2: Introduction to Constraint Programming

Outline

• Introduction• Constraint propagation• Backtracking search• Some application• Global constraints• Symmetry• Modeling

Page 3: Introduction to Constraint Programming

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?

Page 4: Introduction to Constraint Programming

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

Page 5: Introduction to Constraint Programming

Constraint programming Began in 1980s By computer programmers

Constraints Satisfaction Problem(CSP) 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

Page 6: Introduction to Constraint Programming

Comparison of CP/IP• Branch and Prune

– Prune: eliminate infeasible configurations– Branch: decompose into subproblems

• Prune– Carefully examine constraints to reduce possible variable values

• Branch– Use heuristics based on feasibility info

• Main focus:constraints and feasibility

• Branch and Bound– Bound: eliminate suboptimal solutions– Branch: decompose into subproblems

• Bound– Use (linear) relaxation of problem (+ cuts)

• Branch– Use information from relaxation

• Main focus: objective function and optimality

Page 7: Introduction to Constraint Programming

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?

Page 8: Introduction to Constraint Programming

OPL example

enum Country {Belgium,Denmark,France,Germany,Netherlands,Luxembourg};

enum Colors {blue,red,yellow,gray};var Colors color[Country];

solve { color[France] <> color[Belgium]; color[France] <> color[Luxembourg]; color[France] <> color[Germany]; color[Luxembourg] <> color[Germany]; color[Luxembourg] <> color[Belgium]; color[Belgium] <> color[Netherlands]; color[Belgium] <> color[Germany]; color[Germany] <> color[Netherlands]; color[Germany] <> color[Denmark];};

• Variables non-numeric

• Constraints are non-linear

• Looks nothing like IP!

• Perfectly legal CP

Page 9: Introduction to Constraint Programming

Example constraint systems/languages

System Description

ILOG / OPL C++ class library

Comet Programming language & system

Eclipse Logic programming

Choco Java class library

HAL Logic programming

Oz Functional programming

Page 10: Introduction to Constraint Programming

Strength of CP’s Modelling

• Don’t need to linear constraints• Don’t need to special structure• Since there is no need for a linear relaxation,

the language can represent much more directly (no need for big-M IP formulations.

• It’s very very easy to modeling for everybody(don’t need to OR knowledge)

Page 11: Introduction to Constraint Programming

11

Integer constraints• Usual arithmetic operators:

– =, , , < , > , , + , , *, /, absolute value, exponentiation– e.g., 3x + 4y 7, 5x3 – x*y = 9

• Usual logical operators:– , , , (or “if … then”)– e.g., if x = 1 then y = 2, x y z, (3x + 4y 7) (x*y = z)

• Global constraints:– alldifferent(x1, …, xn)– ordered([A,B,C,D])– cardinality(x1, …, xn, l, u)– minlist([A,B,C,D], 3)– occurrences(…)

Page 12: Introduction to Constraint Programming

more example: Sudoku

Each Sudoku has a unique solution that can be reached logically without guessing. Enter digits from 1 to 9 into the blank spaces. Every row must contain one of each digit. So must every column, as must every 3x3 square.

5 3 76 1 9 5

9 8 68 6 34 8 3 17 2 6

6 2 84 1 9 5

8 7 9

Page 13: Introduction to Constraint Programming

Sudokuusing CP;int n=9;dvar int x[1..n][1..n] in 1..9;subject to{ forall(i in 1..n) allDifferent(all(j in 1..9)x[i][j]); forall(j in 1..n) allDifferent(all(i in 1..9)x[i][j]); forall(i in 1..3) forall(j in 1..3) allDifferent(all(k in 3*i-2..3*i,h in

3*j-2..3*j)x[k][h]);}

5 3 76 1 9 5

9 8 68 6 34 8 3 17 2 6

6 2 84 1 9 5

8 7 9

Page 14: Introduction to Constraint Programming

more example: n Queens

• Place n-queens on an n n board so that no pair of queens attacks each other

Page 15: Introduction to Constraint Programming

n Queens : Solution

using CP;int n=8;dvar int x[1..n]in 1..n;

subject to{ allDifferent(all(i in 1..n) x[i]); forall(i in 1..n-1) forall(j in i+1..n) abs(x[i]-x[j])!=j-i; }

Page 16: Introduction to Constraint Programming

Optimization with CP

1) Find a feasible solution x2) Z=c(x)3) Add constraint c(x)<z4)If found a feasible solution x Goto 2) Else Return last z

Page 17: Introduction to Constraint Programming

Outline

• Introduction• Constraint propagation• Backtracking search• Some application• Global constraints• Symmetry• Modeling

Page 18: Introduction to Constraint Programming

Place numbers 1 through 8 on nodes, where each number appears exactly once and no connected nodes have consecutive numbers

?

?

?

?

?

?

??

Acknowledgement: Patrick Prosser

Page 19: Introduction to Constraint Programming

Backtracking search

Which nodes are hardest to number?

?

?

?

?

?

?

??

Guess a value, but be prepared to backtrack

Page 20: Introduction to Constraint Programming

Backtracking search

?

?

?

?

?

?

??

Which nodes are hardest to number?

Page 21: Introduction to Constraint Programming

Backtracking search

Which are the least constraining values to use?

?

?

?

?

?

?

??

Values 1 & 8

Page 22: Introduction to Constraint Programming

Backtracking search

Symmetry means we don’t need to consider: 8 1

?

1

?

?

8

?

??

Page 23: Introduction to Constraint Programming

Inference/propagation

We can now eliminate many values for other nodes

?

1

?

?

8

?

??

{1,2,3,4,5,6,7,8}

Page 24: Introduction to Constraint Programming

Inference/propagation

By symmetry

?

1

?

?

8

?

??

{3,4,5,6}

{3,4,5,6}

Page 25: Introduction to Constraint Programming

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

{3,4,5,6}

{1,2,3,4,5,6,7,8}

Page 26: Introduction to Constraint Programming

Inference/propagation

By symmetry

?

1

?

?

8

?

??

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

Page 27: Introduction to Constraint Programming

Inference/propagation

?

1

?

?

8

?

??

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

{3,4,5,6,7} {2,3,4,5,6}

Page 28: Introduction to Constraint Programming

Inference/propagation

?

1

?

?

8

?

27

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

Page 29: Introduction to Constraint Programming

Inference/propagation

?

1

?

?

8

?

27

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

{3,4,5,6}

And propagate

Page 30: Introduction to Constraint Programming

Inference/propagation

?

1

?

?

8

?

27

{3,4,5}

{3,4,5}

{4,5,6}

{4,5,6}

Guess a value, but be prepared to backtrack

Page 31: Introduction to Constraint Programming

Inference/propagation

3

1

?

?

8

?

27

{3,4,5}

{4,5,6}

{4,5,6}

Guess a value, but be prepared to backtrack

Page 32: Introduction to Constraint Programming

Inference/propagation

3

1

?

?

8

?

27

{3,4,5}

{4,5,6}

{4,5,6}

And propagate

Page 33: Introduction to Constraint Programming

Inference/propagation

3

1

?

?

8

?

27

{4,5}

{5,6}

{4,5,6}

More propagation?

Page 34: Introduction to Constraint Programming

Enforcing local consistency: constraint propagation

• Here, focus on: Given a constraint, remove a value from the domain of a variable if it cannot be part of a solution according to that constraint

Page 35: Introduction to Constraint Programming

ac() : boolean1. Q all variable/constraint pairs (x, C) 2. while Q {} do3. select and remove a pair (x, C) from Q4. if revise(x, C) then5. if dom(x) = {}6. return false7. else8. add pairs to Q9. return true

Generic arc consistency algorithm

revise(x, C) : boolean1. change false2. for each v dom(x) do3. if t C s.t. t[x] = v

then4. remove v from

dom(x)5. change true6. return change

Page 36: Introduction to Constraint Programming

ac() : boolean1. Q all variable/constraint pairs (x, C) 2. while Q {} do3. select and remove a pair (x, C) from Q4. if revise(x, C) then5. if dom(x) = {}6. return false7. else8. add pairs to Q9. return true

Generic arc consistency algorithm

revise(x, C) : boolean1. change false2. for each v dom(x) do3. if t C s.t. t[x] = v

then4. remove v from

dom(x)5. change true6. return change

variable xyz

domain {1, 2, 3}{1, 2, 3}{1, 2, 3}

C1: x < yconstraints

C2: y < z

Page 37: Introduction to Constraint Programming

Outline

• Introduction• Constraint propagation• Backtracking search• Some application• Global constraints• Symmetry• Modeling

Page 38: Introduction to Constraint Programming

Constraint model for 4-queens

4

3

2

1

x1 x2 x3 x4

variables: x1, x2 , x3 , x4

domains: {1, 2, 3, 4}

constraints: x1 x2 | x1 – x2 | 1 x1 x3 | x1 – x3 | 2 x1 x4 | x1 – x4 | 3 x2 x3 | x2 – x3 | 1 x2 x4 | x2 – x4 | 2 x3 x4 | x3 – x4 | 1

Page 39: Introduction to Constraint Programming

Forward checking (FC) on 4-queens

Q

Q

Q

Q

Q

Q

Page 40: Introduction to Constraint Programming

Search tree for 4-queens

x1

x2

x3

x4

x1=1

(1,1,1,1) (4,4,4,4)(2,4,1,3) (3,1,4,2)

x1= 4

Page 41: Introduction to Constraint Programming

Heuristics for backtracking algorithms

• Variable ordering (very important)– what variable to branch on next

• Value ordering (can be important)– given a choice of variable, what order to try values

Page 42: Introduction to Constraint Programming

Variable ordering

• Domain dependent heuristics• Domain independent heuristics• Static variable ordering

– fixed before search starts• Dynamic variable ordering

– chosen during search

Page 43: Introduction to Constraint Programming

Variable ordering: Possible goals

• Minimize the underlying search space– static ordering example:

• suppose x1, x2, x3, x4 with domain sizes 2, 4, 8, 16• compare static ordering x1, x2, x3, x4 vs x4, x3, x2, x1

• Minimize expected depth of any branch• Minimize expected number of branches• Minimize size of search space explored by

backtracking algorithm– intractable to find “best” variable

Page 44: Introduction to Constraint Programming

Variable ordering: Basic idea

• Assign a heuristic value to a variable that estimates how difficult it is to find a satisfying value for that variable

• Principle: most likely to fail first– or don’t postpone the hard part

Page 45: Introduction to Constraint Programming

Others methods for solving CP

• Local search algorithms• The Min-Conflicts Heuristic(MCH)• The GSAT Algorithm• ….

• For study more methods see [1].

Page 46: Introduction to Constraint Programming

Outline

• Introduction• Constraint propagation• Backtracking search• Some application• Global constraints• Symmetry• Modeling

Page 47: Introduction to Constraint Programming

CP can hybrid with other OR’s method

• create a relaxation of the CP problem in the form of an OR model

• Hybrid with branch-and-price algorithms uses CP for “column generation”

• Hybrid with Benders decomposition uses CP for “row generation”

Page 48: Introduction to Constraint Programming
Page 49: Introduction to Constraint Programming

computational results for combine CP and Branch and price

Page 50: Introduction to Constraint Programming

Problems that has been solved by hybrid op CP and branch and price

• Generalized Assignment Problem

• airline crew assignment• crew rostering• transit bus crew

scheduling• aircraft scheduling

• vehicle routing problem• network design• employee timetabling• physician scheduling• traveling tournament

problem

Page 51: Introduction to Constraint Programming

computational results for combine CP and Benders decomposition

Page 52: Introduction to Constraint Programming

Problems that has been solved by hybrid op CP and Benders decomposition

• Planning and Scheduling problem

• minimal perturbation scheduling problem

• circuit verification problems

• min-cost planning and disjunctive scheduling

• steel production scheduling

• batch scheduling in a chemical plant

• scheduling of computer processors

Page 53: Introduction to Constraint Programming

Other applicaton

• Use propagation stage in each node for solving MIP in B&B algorithm.

• Use CP for finding feasible neighberhood in Local search algorithms(Tabu search,SA,…)

• Use CP for convert of childerens in crossover operator in GA to feasible points.

• For finding initial solution in other OR methods.

Page 54: Introduction to Constraint Programming

Outline

• Introduction• Constraint propagation• Backtracking search• Some application• Global constraints• Symmetry• Modeling

Page 55: Introduction to Constraint Programming

Global constraints

• A global constraint is a constraint that can be specified over an arbitrary number of variables

• Advantages:– captures common

constraint patterns– efficient, special purpose

constraint propagation algorithms can be designed

Page 56: Introduction to Constraint Programming

Alldifferent constraint

• Consists of:– set of variables {x1, …, xn}

• Satisfied iff:– each of the variables is assigned a different

value

Page 57: Introduction to Constraint Programming

Knapsack constraint

• Consists of:– set of variables {x1, …, xn}

– a scalar value ci for each xi

– two scalar values L and U• Satisfied iff:

– L ci xi Ui =1

n

Page 58: Introduction to Constraint Programming

Knapsack: example of domain consistency

• Suppose knapsack constraint 80 27x1 + 37x2 + 45x3 + 53x4 82where:

dom(x1) = {0, 1, 2, 3}dom(x2) = {0, 1, 2, 3}dom(x3) = {0, 1, 2, 3}dom(x4) = {0, 1, 2, 3}

• Enforcing domain consistency yields

dom(x1) = {0, 1, 3}dom(x2) = {0, 1}dom(x3) = {0, 1}dom(x4) = {0, 1}

• Example of a propagator that solves an NP-Complete problem using a pseudo-polynomial algorithm based on dynamic programming

Page 59: Introduction to Constraint Programming

Element constraint

• Consists of:• an array of variables x = [x1, …, xn]• an integer variable i • a variable y with arbitrary finite domain

• Satisfied iff:• xi = y

Page 60: Introduction to Constraint Programming

Assignment Problem• Assign four workers W1,W2,W3,W4 to four products such that each

worker works on one product and each product is produced by one worker. Effectiveness of production is given by the following table(e.g.,worker W1 produces P1 with effectivness 7) and the total effectiveness must be 19 at least.

Page 61: Introduction to Constraint Programming

Assignment Problem : Solution

Page 62: Introduction to Constraint Programming

Inverse constraintSmall Example: 10 cars in sequence. The order for

assembly is 1, 2, ..., 10. A car must be painted within 3 positions of its assembly order. For instance, car 5 can be painted in positions 2 through 8 inclusive. Cars 1, 5, and 9 are red; 2, 6, and 10 are blue; 3 and 7 green; and 4 and 8 are yellow. Initial sequence 1, 2, ... 10 corresponds to color pattern RBGYRBGYRB and has 9 purgings. The sequence 2,1,5,3,7,4,8,6,10,9 corresponds to color pattern BRRGGYYBBR and has 5 purgings.

Page 63: Introduction to Constraint Programming

Constraint Program

int n=…;int rnge=…;int ncolor=…;range Slots 1..n;var Slots slot[1..n];var Slots revslot[1..n];int color[1..n]= …;minimize sum (j in 1..n-1) (color[revslot[j]] <> color[revslot[j+1]])

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;};

Page 64: Introduction to Constraint Programming

Outline

• Introduction• Constraint propagation• Backtracking search• Some application• Global constraints• Symmetry• Modeling

Page 65: Introduction to Constraint Programming

Symmetry in constraint models

• Many constraint models contain symmetry–variables are “interchangeable”–values are “interchangeable”–variable-value symmetry

• As a result, when searching for a solution:–search tree contains many equivalent subtrees– if a subtree does not contain a solution, neither will

equivalent subtrees elsewhere in the tree– failing to recognize equivalent subtrees results in needless

search

Page 66: Introduction to Constraint Programming

Example of value symmetry: 3-coloringvariables: v1, v2 , v3 , v4 , v5

domains: {1, 2, 3}

constraints: v1 v2 v1 v3 v2 v4 v3 v4 v3 v5 v4 v5

v2

v3

v1

v5

v4

Page 67: Introduction to Constraint Programming

Example of value symmetry: 3-coloring

A solution

v1 = 1 v2 = 2 v3 = 2 v4 = 1 v5 = 3

v2

v3

v1

v5

v4

Mapping

Page 68: Introduction to Constraint Programming

Example of value symmetry: 3-coloring

Another solution

v1 = 1 v2 = 2 v3 = 2 v4 = 1 v5 = 3

v2

v3

v1

v5

v4

Page 69: Introduction to Constraint Programming

Example of value symmetry: 3-coloringA partial non-solution

v1 = 1 v2 = 2 v3 = 3

v2

v3

v1

v5

v4Another partial non-solution

v1 = 1 v2 = 2 v3 = 3

And so on …

Page 70: Introduction to Constraint Programming

Example of variable-value symmetry: 4-queens

4

3

2

1

x1 x2 x3 x4

variables: x1, x2 , x3 , x4

domains: {1, 2, 3, 4}

constraints: x1 x2 | x1 – x2 | 1 x1 x3 | x1 – x3 | 2 x1 x4 | x1 – x4 | 3 x2 x3 | x2 – x3 | 1 x2 x4 | x2 – x4 | 2 x3 x4 | x3 – x4 | 1

Page 71: Introduction to Constraint Programming

Symmetries for 4-queens21 3 4

5 6 7

10

9

8

11

12

13

14

15

16

913

5 1

14

10

6

11

15

2

7 3

16

12

8 4

15

16

14

13

12

11

10

78

9

6 5

4 3 2 1

84 12

16

3 7 11

62

15

10

14

1 5 9 13

14

13

15

169 1

011

65

12

7 81 2 3 4

34 2 1

8 7 6

11

12

5

10

9

16

15

14

13

12

16

8 415

11

7

10

14

3

6 213

9 5 1

51 9 132 6 1

073

14

11

154 8 1

216

horizontal axis vertical axis diagonal 1 diagonal 2

identity rotate 90 rotate 180 rotate 270

Page 72: Introduction to Constraint Programming

Example of variable-value symmetry: 4-queens

Q x1 x2 x3 x4

4

3

2

1

A partial non-solution x1 = 1Another partial non-solution x4 = 4

x1 = 1

x1 1

x4 = 4 x4 4

Page 73: Introduction to Constraint Programming

A formal definition of symmetry

• Let P be a CSP where– V = {x1, …, xn} is the set of variables

– D = dom(x1) dom(xn) is the set of values

• A (solution) symmetry of P is a permutation of the set V D that preserves the set of solutions of P– special cases:

• value ordering symmetry• variable ordering symmetry

Page 74: Introduction to Constraint Programming

Symmetries and permutations21 3 4

5 6 7

10

9

8

11

12

13

14 15 16

identity

( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 )

( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 )

( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 )

( 13 14 15 16 9 10 11 12 5 6 7 8 1 2 3 4 )

14

13

15

169 1

011

65

12

7 81 2 3 4

horizontal axis

Page 75: Introduction to Constraint Programming

Symmetries and permutations21 3 4

5 6 7

10

9

8

11

121

314

15

16

identity

14

13

15

169 1

011

65

12

7 81 2 3 4

horizontal axis

x1 x2 x3 x4

4321

x1 = 1 x1 = 1x1 = 2 x1 = 2…

15

16

14

131

211

10

78

9

6 54 3 2 1

rotate 180

x1 = 1 x1 = 4x1 = 2 x1 = 3…

x1 = 1 x4 = 4x1 = 2 x4 = 3…

x1 x2 x3 x4

4321

Page 76: Introduction to Constraint Programming

Mitigating symmetry in constraint models

• Reformulate the constraint model to reduce or eliminate symmetry– e.g., use set variables

• Break symmetry by adding constraints to model– leave at least one solution– eliminate some/all symmetric solutions and non-solutions

• Break symmetry during backtracking search algorithm– recognize and ignore some/all symmetric parts of the search tree dynamically while

searching

Page 77: Introduction to Constraint Programming

Breaking symmetry by adding constraints to model: 3-coloring

variables: v1, v2 , v3 , v4 , v5

domains: {1, 2, 3}

constraints: vi vj if vi and vj

are adjacent

v2

v3

v1

v5

v4

fixing colors in a single clique

Page 78: Introduction to Constraint Programming

Breaking symmetry by adding constraints to model: 4-queens

4

3

2

1

x1 x2 x3 x4

variables: x1, x2 , x3 , x4

domains: {1, 2, 3, 4}

constraints: xi xi | xi – xj | | i – j |break horizontal symmetry by adding x1 ≤ 2break vertical symmetry by adding x2 ≤ x3

but …

Page 79: Introduction to Constraint Programming

Danger of adding symmetry breaking constraints

Q

Q

Q

Q x1 x2 x3 x4

4

3

2

1

QQ

Q

Q

x1 x2 x3 x4

4

3

2

1

adding x2 ≤ x3 removes this solution

adding x1 ≤ 2 removes this solution

Page 80: Introduction to Constraint Programming

Breaking symmetry during backtracking search

• Let g() be a permutation• Let p be a node in the search tree

– a set of assignments and branching constraints• Suppose node p is to be extended by x = v• Post the constraint:

(p g(p) x v) g(x v)

Page 81: Introduction to Constraint Programming

Breaking symmetry during backtracking search: 4-queens

x1 = 1

x1 1

x4 = 4 x4 4

General form: (p g(p) x v) g(x v)

p

Here (p is empty): (x v) g(x v)

So, post: (x1 1) (x1 4 x4 1 x4 4)

Page 82: Introduction to Constraint Programming

Outline

• Introduction• Constraint propagation• Backtracking search• Some application• Global constraints• Symmetry• Modeling

Page 83: Introduction to Constraint Programming

Unfortunately…

• Often easy to state a model• Much harder is to design an efficient model

given a solver– even harder still to design an efficient model +

solver + heuristics

Page 84: Introduction to Constraint Programming

Importance of the constraint model

“In integer programming, formulating a ‘good’ model is of crucial importance to solving the model.”

G. L. Nemhauser and L. A. Wolsey Handbook in OR & MS, 1989

“Same for constraint programming.”

Helmut Simonis, expert CP modeler

Page 85: Introduction to Constraint Programming

Measures for comparing models

• How easy is it to• write down,• understand,• modify, debug,• communicate?

• How computationally difficult is it to solve?

Page 86: Introduction to Constraint Programming

Computational difficulty?

• What is a good model depends on algorithm• Choice of variables defines search space• Choice of constraints defines

– how search space can be reduced – how search can be guided

Page 87: Introduction to Constraint Programming

Computational complexity

• How hard is it to solve a CSP instance?• Class of all CSP instances is NP-hard

– if CSPs can be solved efficiently (polynomially), then so can Boolean satisfiability, set covering, partition, traveling salesperson problem, graph coloring, …

– so unlikely efficient general-purpose algorithms exists

Page 88: Introduction to Constraint Programming

Should we give up?

“While a method for computing the solutions to NP-complete problems using a reasonable amount of time remains undiscovered, computer scientists and programmers still frequently encounter NP-complete problems. An expert programmer should be able to recognize an NP-complete problem so that he or she does not unknowingly waste time trying to solve a problem which so far has eluded generations of computer scientists.”

Wikipedia, 2009

Page 89: Introduction to Constraint Programming

An exponential curve

size of instance

time

(sec

onds

)

Page 90: Introduction to Constraint Programming

Another exponential curve

Instances that arise in practice

Acce

ptab

le

solv

ing

time

Page 91: Introduction to Constraint Programming

Improving model efficiency

• Reformulate the model– change the denotation of the variables

• Given a model:– add redundant variables– add redundant constraints– add symmetry-breaking

Page 92: Introduction to Constraint Programming

Reformulate the model

• Change the denotation of the variables– i.e., what does assigning a value to a variable mean

in terms of the original problem?• Example: 4-queens

– xi = j means place the queen in column i, row j

– xi = j means place the queen in row i, column j– x = [i, j] means place the queen in row i, column j– xij = 0 means there is no queen in row i, column j

Page 93: Introduction to Constraint Programming

Adding redundant (auxiliary) variables

• Variables that are abstractions of other variables– e.g, decision variables

suppose x has domain {1,…,10} add Boolean variable to represent decisions

(x < 5), (x 5)• Variables that represent constraints (reified constraints)

– e.g., associate a decision variable x with a constraint so that x takes the value 1 if the constraint is satisfied and 0 otherwise

suppose there is the constraint: (y1 + d1 ≤ y2 ) (y2 + d2 ≤ y1) add Boolean variable to represent (y1 + d1 ≤ y2 )

Page 94: Introduction to Constraint Programming

Adding redundant constraints

• Improve computational efficiency of model by adding “right” constraints

– dead-ends encountered earlier in search process

• Three methods:– apply a local consistency enforcing algorithm before solving– learn constraints (nogoods) while solving– add hand-crafted constraints during modeling

• Can often be explained as projections of conjunctions of a subset of the existing constraints

Page 95: Introduction to Constraint Programming

Refrences[1] F.Rossi,P.Van Beek,T.Walsh,“FOUNDATIONS OF ARTIFICIAL

INTELLIGENCE”,Handbook of constraint programming, Elsevier,2006.

[2] Krzysztof R. Apt,” Principles of Constraint Programming”, Cambridge University Press 2003

[3] M. Milano, P. Van hentenryck,“hybrid optimization”, Springer Optimization and Its Applications, VOLUME 45,2010.

[4]Ian P.Gent, Karen E.Petrie, Jean-Franc¸oisPuget,” Symmetry in Constraint Programming”, Handbook of Constraint Programming,2006.

[5]www.book2down.com/Handbook+of+Constraint+Programming-pdf-6.html