Presentation is loading. Please wait.

Presentation is loading. Please wait.

Constraint Programming

Similar presentations


Presentation on theme: "Constraint Programming"— Presentation transcript:

1 Constraint Programming
Peter van Beek Computer Science

2 Outline Introduction Constraint propagation Backtracking search
Global constraints Symmetry Modeling

3 Some additional resources
“Handbook of Constraint Programming,” edited by F. Rossi, P. van Beek, T. Walsh “Constraint-Based Local Search”, by Pascal Van Hentenryck and Laurent Michel Integrated Methods for Optimization, by John N. Hooker “Programming with Constraints,” by Kim Marriott, Peter J. Stuckey “Principles of Constraint Programming,” by Krzysztof Apt “Constraint Processing,” by Rina Dechter

4 Outline Introduction Constraint propagation Backtracking search
Global constraints Symmetry Modeling

5 What is constraint programming?
Idea: Solve a problem by stating constraints on acceptable solutions Advantages: constraints often a natural part of problems especially true of difficult combinatorial problems once problem is modeled using constraints, wide selection of solution techniques available

6 What is constraint programming?
Constraint programming is similar to mathematical programming declarative user states the constraints general purpose constraint solver, often based on backtracking search, is used to solve the constraints Constraint programming is similar to computer programming extensible user-defined constraints allows user to program a strategy to search for a solution

7 What is constraint programming?
Constraint programming is a collection of core techniques Modeling deciding on variables/domains/constraints improving the efficiency of a model Solving local consistency constraint propagation global constraints search backtracking search hybrid methods

8 Constraint programming methodology
Constraint programming is a problem-solving methodology Model problem Solve model specify in terms of constraints on acceptable solutions define/choose constraint model: variables, domains, constraints define/choose search algorithm define/choose heuristics Constraint Satisfaction Problem

9 Constraint satisfaction problem (CSP)
A CSP is defined by: a set of variables {x1, …, xn} a set of values for each variable dom(x1), …, dom(xn) a set of constraints {C1, …, Cm} A solution to a CSP is a complete assignment to all the variables that satisfies the constraints Given a CSP: determine whether it has a solution or not find one solution find all solutions find an optimal solution, given some cost function

10 Example domains and constraints
Reals, linear constraints 3x + 4y ≤ 7, 5x – 3y + z = 2 Guassian elimination, linear programming Integers, linear constraints integer linear programming, branch-and-bound Boolean values, clauses Here: finite domains rich constraint languages user-defined constraints global constraints

11 Constraint languages Usual arithmetic operators:
=, , , < , > ,  , + , , *, /, absolute value, exponentiation e.g., 3x + 4y  7, 5x3 – x*y = 9 Usual logical operators: , , ,  e.g., (x = 1)  (y = 2), x  y  z, (3x + 4y  7)  (x*y = z) Global constraints: e.g., alldifferent(x1, …, xn) Table constraints

12 Alldifferent constraint
Consists of: set of variables {x1, …, xn} Satisfied iff: each of the variables is assigned a different value

13 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 7 6 1 9 8 4 2

14 Sudoku 5 3 7 6 1 9 8 4 2 … x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13

15 Sudoku 5 3 7 6 1 9 8 4 2 dom(xi) = {1, …, 9}, for all i = 1, …, 81
alldifferent(x1, x2, x3, x4, x5, x6, x7, x8, x9) alldifferent(x1, x10, x19, x28, x37, x46, x55, x64, x73) alldifferent(x1, x2, x3, x10, x11, x12, x19, x20, x21) x1 = 5, x2 = 3, x5 = 7, …, x81 = 9

16 Example: Boolean satisfiability
(x1  x2  x4)  (x2  x4  x5)  (x3  x4  x5) Given a Boolean formula, does there exist a satisfying assignment

17 Constraint model variables: x1, x2 , x3 , x4 , x5 domains:
{true, false} constraints: (x1  x2  x4) (x2  x4  x5) (x3  x4  x5) (x1  x2  x4)  (x2  x4  x5)  (x3  x4  x5)

18 Example: n-queens Place n-queens on an n  n board so that no pair of queens attacks each other

19 Constraint model 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 x1 x2 x3 x4 1 2 3 4

20 Example: 4-queens Q Q Q Q x1 x2 x3 x4 A solution x1 = 2 x2 = 4 x3 = 1

21 A closer look at constraints
An assignment (also called an instantiation) x = a, where a  dom(x), A tuple t over an ordered set of variables {x1, …, xk} is an ordered list of values (a1, …, ak) such that ai  dom(xi), i = 1, …, k can be viewed as a set of assignments {x1 = a1, …, xk = ak} Given a tuple t, notation t[xi] selects out the value for variable xi; i.e.,t[xi] = ai

22 A closer look at constraints
Each constraint C is a relation a set of tuples over some ordered subset of the variables, denoted by vars(C) specifies the allowed combinations of values for the variables in vars(C) The size of vars(C) is known as the arity of the constraint a unary constraint has an arity of 1 a binary constraint has an arity of 2 a non-binary constraint has arity greater than 2

23 Example Let intensional Then extensional (table constraint)
dom(x1) = {1, 2, 3, 4}, dom(x2) = {1, 2, 3, 4} C be the constraint x1  x2  | x1 – x2 |  1 Then vars(C) = {x1, x2} tuples in C = {(1,3), (1,4), (2,4), (3,1), (4,1), (4,2)} C is a binary constraint intensional extensional (table constraint)

24 Example constraint systems/languages

25 Application areas scheduling logistics planning rostering timetabling
vehicle routing bioinformatics configuration assembly line sequencing cellular frequency assignment airport counter and gate allocation airline crew scheduling

26 Some commercial applications

27 Outline Introduction Constraint propagation Backtracking search
Global constraints Soft constraints Symmetry Modeling

28 Fundamental insight: Local consistency
A local inconsistency is an instantiation of some of the variables that satisfies the relevant constraints but: cannot be extended to one or more additional variables so cannot be part of any solution Has led to: definitions of conditions that characterize the level of local consistency of a CSP algorithms which enforce these levels of local consistency by removing inconsistencies from the CSP effective backtracking algorithms for finding solutions to a CSP that maintain a level of local consistency during the search

29 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 Example of local consistency: arc consistency

30 Local consistency: arc consistency
Given a constraint C, a value a  dom(x) for a variable x  vars(C) has: a domain support in C if there exists a t  C such that t[x] = a and t[y]  dom(y), for every y  vars(C) i.e., there exists values for each of the other variables (from their respective domains) such that the constraint is satisfied A constraint C is: arc consistent iff for each x  vars(C), each value a  dom(x) has a domain support in C A CSP is: arc consistent if every constraint is arc consistent A CSP can be made arc consistent by repeatedly removing unsupported values from the domains of its variables

31 Arc consistency’s other names
domain consistency hyper-arc consistency generalized arc consistency (GAC)

32 Generic arc consistency algorithm
ac() : boolean Q  all variable/constraint pairs (x, C) while Q  {} do select and remove a pair (x, C) from Q if revise(x, C) then if dom(x) = {} return false else add pairs to Q return true revise(x, C) : boolean change  false for each v  dom(x) do if  t  C s.t. t[x] = v then remove v from dom(x) change  true return change

33 Generic arc consistency algorithm
ac() : boolean Q  all variable/constraint pairs (x, C) while Q  {} do select and remove a pair (x, C) from Q if revise(x, C) then if dom(x) = {} return false else add pairs to Q return true variable x y z domain {1, 2, 3} constraints C1: x < y C2: y < z revise(x, C) : boolean change  false for each v  dom(x) do if  t  C s.t. t[x] = v then remove v from dom(x) change  true return change

34 4-queens: Is it arc consistent?
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 x1 x2 x3 x4 Q Q 1 Q Q 2 Q Q 3 Q Q 4

35 Improvements Much work on efficient algorithms for table constraints
Special purpose algorithms for global constraints (coming later)

36 Other forms of local consistency
bounds consistency singleton consistency many, many more …

37 Outline Introduction Constraint propagation Backtracking search
Global constraints Symmetry Modeling

38 Constraint programming methodology
Model problem Solve model specify in terms of constraints on acceptable solutions define/choose constraint model: variables, domains, constraints define/choose search algorithm define/choose heuristics

39 Backtracking search CSPs often solved using backtracking search
Many techniques for improving efficiency of a backtracking search algorithm branching strategies, constraint propagation, nogood recording, non-chronological backtracking (backjumping), heuristics for variable and value ordering, portfolios and restart strategies

40 Backtracking search A backtracking search is a depth-first traversal of a search tree search tree is generated as the search progresses search tree represents alternative choices that may have to be examined in order to find a solution method of extending a node in the search tree is often called a branching strategy

41 Generic backtracking algorithm
treeSearch( i : integer ) : integer if all variables assigned a value then return 0 // solution found x  getNextVariable( ) backtrackLevel  i for each branching constraint bi do post( bi ) if propagate( bi ) then backtrackLevel  treeSearch( i + 1 ) undo( bi ) if backtrackLevel < i then return backtrackLevel backtrackLevel  getBacktrackLevel() setNogoods()

42 Outline Introduction Constraint propagation Backtracking search
branching strategies constraint propagation non-chronological backtracking nogood recording heuristics for variable and value ordering portfolios and restart strategies Global constraints Symmetry Modeling

43 Branching strategies …
A node p = {b1, …, bj} in the search tree is a set of branching constraints, where bi, 1 ≤ i ≤ j, is the branching constraint posted at level i in search tree A node p is extended by posting a branching constraint to ensure completeness, the constraints posted on all the branches from a node must be mutually exclusive and exhaustive p = {b1, …, bj} p  {bj+1} 1 k

44 Popular branching strategies
Running example: let x be the variable branched on, let dom(x) = {1, …, 6} Enumeration (or d-way branching) variable x is instantiated in turn to each value in its domain e.g., x = 1 is posted along the first branch, x = 2 along second branch, … Binary choice points (or 2-way branching) variable x is instantiated to some value in its domain e.g., x = 1 is posted along the first branch, x  1 along second branch, respectively Domain splitting constraint posted splits the domain of the variable e.g., x  3 is posted along the first branch, x > 3 along second branch, respectively

45 Other branching strategies
Posting non-unary branching constraints, branching strategies that are specific to class of problems Example: job shop scheduling must schedule a set of tasks t1, …, tk on a set of resources let xi be a variable representing the starting time of task ti let di be the fixed duration of task ti idea: serialize the tasks that share a resource consider two task t1 and t2 which share a resource post the constraint x1 + d1 <= x2 along one branch post the constraint x2 + d2 <= x1 along the other branch

46 Outline Introduction Constraint propagation Backtracking search
branching strategies constraint propagation non-chronological backtracking nogood recording heuristics for variable and value ordering portfolios and restart strategies Global constraints Symmetry Modeling

47 Constraint propagation
Effective backtracking algorithms for constraint programming maintain a level of local consistency during the search; i.e., perform constraint propagation A generic scheme to maintain a level of local consistency in a backtracking search is to perform constraint propagation at each node in the search tree if any domain of a variable becomes empty, inconsistent so backtrack

48 Constraint propagation
Backtracking search integrated with constraint propagation has two important benefits 1. removing inconsistencies during search can dramatically prune the search tree by removing deadends and by simplifying the remaining sub-problem 2. some of the most important variable ordering heuristics make use of the information gathered by constraint propagation

49 Maintaining a level of local consistency
Definitions of local consistency can be categorized by whether: only unary constraints need to be posted during constraint propagation; sometimes called domain filtering higher arity constraints may need to be posted In implementations of backtracking domains represented extensionally posting and retracting unary constraints can be done very efficiently important that algorithms for enforcing a level of local consistency be incremental

50 Some backtracking algorithms
Chronological backtracking (BT) naïve backtracking: performs no constraint propagation, only checks a constraint if all of its variables have been instantiated; chronologically backtracks Forward checking (FC) maintains arc consistency on all constraints with exactly one uninstantiated variable; chronologically backtracks Maintaining arc consistency (MAC) maintains arc consistency on all constraints with at least one uninstantiated variable; chronologically backtracks Conflict-directed backjumping (CBJ) backjumps; no constraint propagation

51 Constraint model for 4-queens
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 x1 x2 x3 x4 1 2 3 4

52 Search tree for 4-queens
x1=1 x1= 4 x1 x2 x3 x4 (1,1,1,1) (2,4,1,3) (3,1,4,2) (4,4,4,4)

53 Chronological backtracking (BT)
Q Q Q Q Q Q

54 Forward checking (FC) Q
Enforce arc consistency on constraints with exactly one variable uninstantiated 4 3 2 1 x1 x2 x3 x4 Q { x1 = 1} constraints: x1  x2  |x1 – x2|  1 x1  x3  |x1 – x3|  2 x1  x4  |x1 – x4|  3

55 Forward checking (FC) on 4-queens
Q Q Q Q

56 Maintaining arc consistency (MAC)
Enforce arc consistency on constraints with at least one variable uninstantiated { x1 = 1} 4 3 2 1 x1 x2 x3 x4 Q 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 ?

57 Maintaining arc consistency (MAC) on 4-queens

58 Outline Introduction Constraint propagation Backtracking search
branching strategies constraint propagation non-chronological backtracking nogood recording heuristics for variable and value ordering portfolios and restart strategies Global constraints Symmetry Modeling

59 Non-chronological backtracking
Upon discovering a deadend, a backtracking algorithm must retract some previously posted branching constraint chronological backtracking: only the most recently posted branching constraint is retracted non-chronological backtracking: algorithm backtracks to and retracts the closest branching constraint which bears some responsibility for the deadend

60 Conflict-directed backjumping (CBJ)
{x1 = 1} x1 x3 x4 x2 Q 4 3 2 1 x1 {x1 = 1, x2 = 3} Q x2 Q x1 {x1 = 1, x2 = 3 , x4 = 2} x2 x3

61 Outline Introduction Constraint propagation Backtracking search
branching strategies constraint propagation non-chronological backtracking nogood recording heuristics for variable and value ordering portfolios and restart strategies Global constraints Symmetry Modeling

62 Nogood recording One of the most effective techniques known for improving the performance of backtracking search on a CSP is to add redundant (implied) constraints a constraint is redundant if set of solutions does not change when constraint is added Three methods: add hand-crafted constraints during modeling apply a consistency algorithm before solving learn constraints while solving  nogood recording

63 Nogood recording A nogood is a set of assignments and branching constraints that is not consistent with any solution i.e., there does not exist a solutionan assignment of a value to each variable that satisfies all the constraintsthat also satisfies all the assignments and branching constraints in the nogood

64 Example nogoods: 4-queens
3 2 1 Q x1 x3 x4 x2 Set of assignments {x1 = 1, x2 = 3} is a nogood to rule out the nogood, the redundant constraint  (x1 = 1  x2 = 3) could be recorded, which is just x1  1  x2  3 recorded constraints can be checked and propagated just like the original constraints But {x1 = 1, x2 = 3} is not a minimal nogood

65 Nogood recording If the CSP had included the nogood as a constraint, deadend would not have been visited Idea: record nogoods that might be useful later in the search

66 Discovering nogoods Discover nogoods when: Tricky when:
during backtracking search when current set of assignments and branching constraints fails during backtracking search when nogoods have been discovered for every branch set of assignments {x1 = 1, x2 = 1} is a nogood set of assignments {x1 = 1, x2 = 2} is a nogood set of assignments {x1 = 1, x2 = 3} is a nogood set of assignments {x1 = 1, x2 = 4} is a nogood  {x1 = 1} is a nogood Tricky when: backtracking algorithm maintains a level of local consistency in the presence of global constraints Standard in SAT solvers Currently not yet widely used for solving general CSPs

67 Outline Introduction Constraint propagation Backtracking search
branching strategies constraint propagation non-chronological backtracking nogood recording heuristics for variable and value ordering portfolios and restart strategies Global constraints Symmetry Modeling

68 Heuristics for backtracking algorithms
Variable ordering (very important) what variable to branch on next examples: impact-based (measure reduction in search space) conflict-based (measure how often a variable appears in a failed constraint) activity-based (measure how often the domain of a variable is reduced) Value ordering (can be important) given a choice of variable, what order to try values example: choose first the values that are most likely to succeed

69 Outline Introduction Constraint propagation Backtracking search
branching strategies constraint propagation non-chronological backtracking nogood recording heuristics for variable and value ordering portfolios and restart strategies Global constraints Symmetry Modeling

70 Portfolios Observation: Backtracking algorithms can be quite brittle, performing well on some instances but poorly on other similar instances Portfolios of algorithms have been proposed and shown to improve performance We are the last Dodos on the planet, so I’ve put all of our eggs safely into this basket…

71 Portfolios: Definitions
Given a set of backtracking algorithms and a time deadline d, a portfolio P for a single processor is a sequence of pairs, A restart strategy portfolio is a portfolio where,

72 Restart strategy portfolio
Randomize backtracking algorithm randomize selection of a value randomize selection of a variable A restart strategy (t1, t2, t3, …, tm) is a sequence idea: randomized backtracking algorithm is run for t1 steps. If no solution is found within that cutoff, the algorithm is restarted and run for t steps, and so on

73 Restart strategies Let f(t) be the probability a randomized backtracking algorithm A on instance x stops after taking exactly t steps f(t) is called the runtime distribution of algorithm A on instance x Given the runtime distribution of an instance, the optimal restart strategy for that instance is given by (t*, t*, t*, …), for some fixed cutoff t* A fixed cutoff strategy is an example of a non-universal strategy: designed to work on a particular instance

74 Universal restart strategies
Non-universal strategies are open to catastrophic failure In contrast to non-universal strategies, universal strategies are designed to be used on any instance Luby strategy Walsh strategy (1, 1, 2, 1, 1, 2, 4, 1, 1, 2, 1, 1, 2, 4, 8, 1, …)  grows linearly (1, r, r2, r3, …), r > 1  grows exponentially

75 Summary: backtracking search
CSPs often solved using backtracking search Many techniques for improving efficiency of a backtracking search algorithm branching strategies, constraint propagation, nogood recording, non-chronological backtracking (backjumping), heuristics for variable and value ordering, portfolios and restart strategies Best combinations of these techniques give robust backtracking algorithms that can routinely solve large, hard instances that are of practical importance

76 Outline Introduction Constraint propagation Backtracking search
Global constraints Symmetry Modeling

77 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

78 Alldifferent constraint
Consists of: set of variables {x1, …, xn} Satisfied iff: each of the variables is assigned a different value

79 Alldifferent: example of arc consistency
Suppose alldifferent(x1, x2, x3, x4) where: dom(x1) = {b, c, d, e} dom(x2) = {b, d} dom(x3) = {a, b, c, d} dom(x4) = {b, d} Enforcing arc consistency yields dom(x1) = {c, e} dom(x3) = {a, c}

80 Alldifferent: algorithm for arc consistency
General idea: based on matching theory applied to variable-value graph Suppose alldifferent(x1, x2, x3, x4) where: dom(x1) = {b, c, d, e} dom(x2) = {b, d} dom(x3) = {a, b, c, d} dom(x4) = {b, d} Construct variable-value graph x1 x2 x3 x4 a b c d e

81 Alldifferent: algorithm for arc consistency
A matching is a subset of the edges such that no two edges share a vertex. A matching covers a set of vertices if each vertex participates in an edge. A matching that covers the variables is a solution to the constraint x1 x2 x3 x4 a b c d e

82 Alldifferent: algorithm for arc consistency
An alldifferent contraint is arc consistent if every edge in the variable-value graph belongs to some matching that covers the variables Remove edges/values that do not belong to some covering matching Example: x b x1 x2 x3 x4 a b c d e

83 Alldifferent: algorithm for arc consistency
An alldifferent constraint is arc consistent if every edge in the variable-value graph belongs to some matching that covers the variables Remove edges/values that do not belong to some covering matching Example: x b So, remove b from dom(x1) x1 x2 x3 x4 a b c d e

84 Other global constraints
Regular constraint applications: rostering and sequencing problems Cumulative constraint applications: scheduling Stretch constraint Optimization global constraints Many, many more …

85 Outline Introduction Constraint propagation Backtracking search
Global constraints Symmetry Modeling

86 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

87 Example of variable symmetry: scheduling
A, B, C, D, E domains {1, …, m} constraints D  A + 3 D  B + 3 E  C + 3 E  D + 1 alldifferent(A, B, C, D, E) 3 1 A B D C E dependency DAG Variables A and B are symmetric

88 Example of value symmetry: 3-coloring
variables: v1, v2 , v3 , v4 , v5 domains: {1, 2, 3} constraints: v1  v2 v1  v3 v2  v4 v3  v4 v3  v5 v4  v5 v1 v2 v3 v4 v5

89 Example of value symmetry: 3-coloring
A solution v1 = 1 v2 = 2 v3 = 2 v4 = 1 v5 = 3 v1 v2 v3 v4 Mapping v5

90 Example of value symmetry: 3-coloring
Another solution v1 = 1 v2 = 2 v3 = 2 v4 = 1 v5 = 3 v1 v2 v3 v4 v5

91 Example of value symmetry: 3-coloring
A partial non-solution v1 = 1 v2 = 2 v3 = 3 v1 v2 v3 v4 Another partial non-solution v1 = 1 v2 = 2 v3 = 3 v5 And so on …

92 Example of variable-value symmetry: 4-queens
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 x1 x2 x3 x4 1 2 3 4

93 Symmetries for 4-queens
2 1 3 4 5 6 7 10 9 8 11 12 13 14 15 16 9 13 5 1 14 10 6 11 15 2 7 3 16 12 8 4 15 16 14 13 12 11 10 7 8 9 6 5 4 3 2 1 8 4 12 16 3 7 11 6 2 15 10 14 1 5 9 13 identity rotate 90 rotate 180 rotate 270 14 13 15 16 9 10 11 6 5 12 7 8 1 2 3 4 3 4 2 1 8 7 6 11 12 5 10 9 16 15 14 13 12 16 8 4 15 11 7 10 14 3 6 2 13 9 5 1 5 1 9 13 2 6 10 7 3 14 11 15 4 8 12 16 horizontal axis vertical axis diagonal 1 diagonal 2

94 Example of variable-value symmetry: 4-queens
A partial non-solution x1 = 1 x1 x2 x3 x4 Another partial non-solution x4 = 4 Q 1 x1 = 1 x1  1 x4 = 4 x4  4 2 3 4

95 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

96 Symmetries and permutations
2 1 3 4 5 6 7 10 9 8 11 12 13 14 15 16 ( ) identity 13 14 15 16 ( ) 9 10 11 12 5 6 7 8 ( ) 1 2 3 4 horizontal axis

97 Symmetries and permutations
x1 x2 x3 x4 2 1 3 4 5 6 7 10 9 8 11 12 13 14 15 16 1 15 16 14 13 12 11 10 7 8 9 6 5 4 3 2 1 x1 = 1  x1 = 1 x1 = 2  x1 = 2 x1 = 1  x4 = 4 x1 = 2  x4 = 3 2 3 4 identity rotate 180 x1 x2 x3 x4 1 13 14 15 16 x1 = 1  x1 = 4 x1 = 2  x1 = 3 2 9 10 11 12 3 5 6 7 8 4 1 2 3 4 horizontal axis

98 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

99 Breaking symmetry by adding constraints to model: scheduling
variables A, B, C, D, E domains {1, …, m} constraints D  A + 3 D  B + 3 E  C + 3 E  D + 1 alldifferent(A, B, C, D, E) 3 1 A B D C E dependency DAG B  A + 1

100 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 v1 v2 v3 v4 fixing colors in a single clique v5

101 Breaking symmetry by adding constraints to model: 4-queens
variables: x1, x2 , x3 , x4 domains: {1, 2, 3, 4} constraints: xi  xi  | xi – xj |  | i – j | x1 x2 x3 x4 1 2 3 break horizontal symmetry by adding x1 ≤ 2 4 break vertical symmetry by adding x2 ≤ x3 but …

102 Danger of adding symmetry breaking constraints
Q x1 x2 x3 x4 4 3 2 1 x1 x2 x3 x4 Q 1 Q 2 Q 3 Q 4 adding x2 ≤ x3 removes this solution adding x1 ≤ 2 removes this solution

103 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)

104 Breaking symmetry during backtracking search: 4-queens
p x1 = 1 x1  1 x4 = 4 x4  4 General form: (p  g(p)  x  v)  g(x  v) Here (p is empty): (x  v)  g(x  v) So, post: (x1  1)  (x1  4  x4  1  x4  4)

105 Outline Introduction Constraint propagation Backtracking search
Global constraints Symmetry Modeling

106 Constraint programming
Model problem specify in terms of constraints on acceptable solutions define variables (denotations) and domains define constraints in some language Solve model define algorithm design heuristics CSP

107 Example constraint systems/languages

108 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

109 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

110 Improving model efficiency
Reformulate the model change the denotation of the variables Given a model: add redundant variables add redundant constraints add a redundant model redundant (or implied): does not change the set of solutions and hence are logically redundant add symmetry-breaking add dominance constraints symmetry-breaking and dominance do change the set of solutions must leave at least one solution (satisfaction) or an optimal solution (optimization)

111 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 = means there is no queen in row i, column j

112 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 )

113 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

114 Adding redundant models
Consider two alternative constraint models for the same problem example: 4-queens Combine into one constraint model channeling constraints xi = j  yj = i for all i, j 4 3 2 1 x1 x3 x4 x2 y4 y3 y2 y1 1 3 4 2


Download ppt "Constraint Programming"

Similar presentations


Ads by Google