Choice of representation Zykov recurrence [Zykov 49]: take a non-edge e , s . In the optimal coloring: � = x f x s � = � = � = x i x e Variables 12 / 46
Choice of representation Zykov recurrence [Zykov 49]: take a non-edge e , s . In the optimal coloring: � = x f s ◮ either e and s take a different color, so adding the edge would not hurt � = � = � = � = x i e Variables 12 / 46
Choice of representation Zykov recurrence [Zykov 49]: take a non-edge e , s . In the optimal coloring: � = x f s ◮ either e and s take a different color, so adding the edge would not hurt = ◮ or e and s take the same color, so merging them � = � = � = (adding an equality constraint) would not hurt x i e Variables 12 / 46
Choice of representation Zykov recurrence [Zykov 49]: take a non-edge e , s . In the optimal coloring: ◮ either e and s take a different color, so adding the edge would not hurt x e , s ∈ { = , � = } ◮ or e and s take the same color, so merging them (adding an equality constraint) would not hurt Instead of assigning colors to nodes, we can assign { = , � = } to non-edges x e , i ∈ { = , � = } Variables 12 / 46
Choice of representation Zykov recurrence [Zykov 49]: take a non-edge e , s . In the optimal coloring: ◮ either e and s take a different color, so adding the edge would not hurt x e , s ∈ { = , � = } ◮ or e and s take the same color, so merging them (adding an equality constraint) would not hurt Instead of assigning colors to nodes, we can assign { = , � = } to non-edges x e , i ∈ { = , � = } No color symmetry anymore! Variables 12 / 46
Choice of representation Zykov recurrence [Zykov 49]: take a non-edge e , s . In the optimal coloring: ◮ either e and s take a different color, so adding the edge would not hurt x e , s ∈ { = , � = } ◮ or e and s take the same color, so merging them (adding an equality constraint) would not hurt Instead of assigning colors to nodes, we can assign { = , � = } to non-edges x e , i ∈ { = , � = } No color symmetry anymore! But stating the constraints is difficult Variables 12 / 46
The best variable viewpoint is the one that... Variables 13 / 46
The best variable viewpoint is the one that... ...induces the smallest search tree Variables 13 / 46
The best variable viewpoint is the one that... ...induces the smallest search tree ...induces the “best” set of constraints Variables 13 / 46
The best variable viewpoint is the one that... ...induces the smallest search tree ...induces the “best” set of constraints What is a good constraint set? Variables 13 / 46
Outline Language 1 Variables 2 Constraints 3 Expression tree Global constraints Constraint solving Modeling 4 Constraints 14 / 46
Combining constraints (logically) Constraints 15 / 46
Combining constraints (logically) Most logic operators ◮ can be used as a relation ( x � = y ) Constraints 15 / 46
Combining constraints (logically) Most logic operators ◮ can be used as a relation ( x � = y )... ◮ or as a predicate (( x � = y ) = ⇒ y ≤ 12) Constraints 15 / 46
Combining constraints (logically) Most logic operators ◮ can be used as a relation ( x � = y )... ◮ or as a predicate (( x � = y ) = ⇒ y ≤ 12) Two different constraints: x � = y and ( x � = y ) ⇐ ⇒ z (reification) Constraints 15 / 46
Combining constraints (logically) Most logic operators ◮ can be used as a relation ( x � = y )... ◮ or as a predicate (( x � = y ) = ⇒ y ≤ 12) Two different constraints: x � = y and ( x � = y ) ⇐ ⇒ z (reification) ( x � = y ) = ⇒ y ≤ 12 ( x � = y ) ⇐ ⇒ z encoded as z = ⇒ ( y ≤ 12) Which you can write ( x � = y ) = ⇒ y ≤ 12 (and let the system insert extra variables) Constraints 15 / 46
Combining constraints (functionally) Constraints 16 / 46
Combining constraints (functionally) There are also function operators that must be combined similarly ◮ For instance ( | x − y | ∗ z ) ≤ ( z + 12) ( | x − y | ∗ z ) ≤ ( z + 12) ( x − y ) = a 1 encoded as | a 1 | = a 2 a 2 ∗ z = a 3 z + 12 = a 4 a 3 ≤ a 4 Constraints 16 / 46
Expression Tree Constraints - Root of the expression tree C1 = (X+Y < 5) | (X+3 < Y) C2 = AllDiff([x,y,z]) C3 = Sum([a,b,c,d]) >= e Predicates & functions - Internal nodes P = X+Y # arythmetic value Q = X+3 <= Y # truth (logic) value Variables - Leaves of the expression tree X = Variable(0,10) X = Variable([1,3,5,7]) Constraints 17 / 46
XKCD Knapsack Constraints 18 / 46
XKCD Knapsack from Numberjack import * price = [215, 275, 335, 355, 420, 580] appetizers = ["Mixed Fruit", "French Fries", "Side Salad", "Hot Wings", "Mozzarella Sticks", "Sample Plate"] total = 1505 num_appetizers = len(appetizers) quantities = [Variable(0, 1505/price[i], ’#’+appetizers[i]) for i in range(num_appetizers)] model = Model( Sum([quantities[i] * price[i] for i in range(num_appetizers)]) == total ) solver = model.load(’Mistral2’) solver.startNewSearch() while solver.getNextSolution() == SAT: print "\nSOLUTION:\n", "\n".join("%s x %s ($%.2lf)" % (quantities[i], \ appetizers[i], price[i] / 100.0) for i in xrange(num_appetizers)) Constraints 19 / 46
XKCD Knapsack Sum([quantities[i] * price[i] for i in range(num_appetizers)]) == total Constraints 20 / 46
XKCD Knapsack Sum([quantities[i] * price[i] for i in range(num_appetizers)]) == total = � total ∗ . . . ∗ q 1 p 1 q n p n Constraints 20 / 46
Solution Solution 1: 7 × Mixed Fruit ($2.15) 0 × French Fries ($2.75) 0 × Side Salad ($3.35) 0 × Hot Wings ($3.55) 0 × Mozzarella Sticks ($4.20) 0 × Sample Plate ($5.80) Solution 2: 1 × Mixed Fruit ($2.15) 0 × French Fries ($2.75) 0 × Side Salad ($3.35) 2 × Hot Wings ($3.55) 0 × Mozzarella Sticks ($4.20) 1 × Sample Plate ($5.80) Constraints 21 / 46
Global constraints CP languages contain a number of keywords for specific relations on variables Constraints 22 / 46
Global constraints CP languages contain a number of keywords for specific relations on variables AllDifferent AllDifferent ( x 1 , . . . , x n ) ⇐ ⇒ ∀ 1 ≤ i < j ≤ n x i � = x j Constraints 22 / 46
Global constraints CP languages contain a number of keywords for specific relations on variables AllDifferent AllDifferent ( x 1 , . . . , x n ) ⇐ ⇒ ∀ 1 ≤ i < j ≤ n x i � = x j x = 3 , 5 , 1 , 2 , 7 satisfies AllDifferent ¯ x = 3 , 5 , 1 , 2 , 5 does not satisfy AllDifferent ¯ Constraints 22 / 46
Global constraints CP languages contain a number of keywords for specific relations on variables AllDifferent AllDifferent ( x 1 , . . . , x n ) ⇐ ⇒ ∀ 1 ≤ i < j ≤ n x i � = x j x = 3 , 5 , 1 , 2 , 7 satisfies AllDifferent ¯ x = 3 , 5 , 1 , 2 , 5 does not satisfy AllDifferent ¯ Element Element ( x 0 , . . . , x n − 1 , y , z ) ⇐ ⇒ x y = z Constraints 22 / 46
Global constraints CP languages contain a number of keywords for specific relations on variables AllDifferent AllDifferent ( x 1 , . . . , x n ) ⇐ ⇒ ∀ 1 ≤ i < j ≤ n x i � = x j x = 3 , 5 , 1 , 2 , 7 satisfies AllDifferent ¯ x = 3 , 5 , 1 , 2 , 5 does not satisfy AllDifferent ¯ Element Element ( x 0 , . . . , x n − 1 , y , z ) ⇐ ⇒ x y = z x = 3 , 5 , 1 , 2 , 5 , y = 1 , z = 5 satisfies Element ¯ x = 3 , 5 , 1 , 2 , 5 , y = 2 , z = 5 does not satisfy Element ¯ Constraints 22 / 46
Map Coloring D ( x f ) : blue D ( x s ) : blue green red � = x f x s � = � = � = x i x e D ( x i ) : blue D ( x e ) : blue red yellow red green Constraints 23 / 46
Map Coloring D ( x f ) : blue D ( x s ) : blue green red x f x s Alldifferent � = x i x e D ( x i ) : blue D ( x e ) : blue red yellow red green Constraints 23 / 46
Constraint solver Constraints 24 / 46
Constraint solver Search Develop a search tree (depth first). Select a variable x , a value v in its domain and branch on x = v or x � = v Constraints 24 / 46
Constraint solver Search Develop a search tree (depth first). Select a variable x , a value v in its domain and branch on x = v or x � = v Inference At every node of the tree, the domains of the variables are reduced Every constraint makes local deductions Constraints 24 / 46
Constraint solver Search Develop a search tree (depth first). Select a variable x , a value v in its domain and branch on x = v or x � = v Inference At every node of the tree, the domains of the variables are reduced Every constraint makes local deductions Consistent iff every value of every variable is in a support Domain reductions from a constraint might trigger reduction by another constraint Constraints 24 / 46
Constraint solver Search Develop a search tree (depth first). Select a variable x , a value v in its domain and branch on x = v or x � = v Inference At every node of the tree, the domains of the variables are reduced Every constraint makes local deductions Consistent iff every value of every variable is in a support Domain reductions from a constraint might trigger reduction by another constraint constraint propagation Constraints 24 / 46
Example: binary constraint Constraints 25 / 46
Example: binary constraint What inference can the inequality x f � = x e make? Constraints 25 / 46
Example: binary constraint What inference can the inequality x f � = x e make? A support: a value v ∈ D ( x f ) and a value w ∈ D ( x e ) with v � = w Constraints 25 / 46
Example: binary constraint What inference can the inequality x f � = x e make? A support: a value v ∈ D ( x f ) and a value w ∈ D ( x e ) with v � = w Propagation of x f � = x e As long as the domain D ( x f ) has two distinct values, then x e could take any value x f ∈ { b , r } , x e ∈ { b , r , g } : there is no correct domain reduction Constraints 25 / 46
Example: binary constraint What inference can the inequality x f � = x e make? A support: a value v ∈ D ( x f ) and a value w ∈ D ( x e ) with v � = w Propagation of x f � = x e As long as the domain D ( x f ) has two distinct values, then x e could take any value x f ∈ { b , r } , x e ∈ { b , r , g } : there is no correct domain reduction If D ( x f ) = { v } then x e cannot take the value v x f ∈ { b } , x e ∈ { b , r , g } = ⇒ x f ∈ { b } , x e ∈ { r , g } Constraints 25 / 46
Search Tree x f ∈ { b , g } x s ∈ { b , r } x e ∈ { b , r , g , y } x i ∈ { b , r } Constraints 26 / 46
Search Tree x f ∈ { b , g } x s ∈ { b , r } x e ∈ { b , r , g , y } x i ∈ { b , r } x f = b x f ∈ { b } x s ∈ { b , r } x e ∈ { b , r , g , y } x i ∈ { b , r } Constraints 26 / 46
Search Tree x f ∈ { b , g } x s ∈ { b , r } x e ∈ { b , r , g , y } x i ∈ { b , r } x f = b x f ∈ { b } x s ∈ { r } x e ∈ { r , g , y } x i ∈ { r } Constraints 26 / 46
Search Tree x f ∈ { b , g } x s ∈ { b , r } x e ∈ { b , r , g , y } x i ∈ { b , r } x f = b x f ∈ { b } x s ∈ { r } x e ∈ { r , g , y } x i ∈ { } Constraints 26 / 46
Search Tree x f ∈ { b , g } x s ∈ { b , r } x e ∈ { b , r , g , y } x i ∈ { b , r } x f = b x f � = b x f ∈ { b } x s ∈ { r } x f ∈ { g } x s ∈ { b , r } Fail! x e ∈ { r , g , y } x i ∈ { } x e ∈ { b , r , y } x i ∈ { b , r } Constraints 26 / 46
Search Tree x f ∈ { b , g } x s ∈ { b , r } x e ∈ { b , r , g , y } x i ∈ { b , r } x f = b x f � = b x f ∈ { b } x s ∈ { r } x f ∈ { g } x s ∈ { b , r } Fail! x e ∈ { r , g , y } x i ∈ { } x e ∈ { b , r , y } x i ∈ { b , r } x s = b x f ∈ { g } x s ∈ { b } x e ∈ { b , r , y } x i ∈ { r } Constraints 26 / 46
Example: global constraint Constraints 27 / 46
Example: global constraint � = x f x s ∈ { b , g } x f � = x s ∈ { b , r } � = ∈ { b , r } x i x i Constraints 27 / 46
Example: global constraint � = x f x s ∈ { b , g } x f Every inequality is consistent � = x s ∈ { b , r } � = ∈ { b , r } x i x i Constraints 27 / 46
Example: global constraint � = x f x s ∈ { b , g } x f Every inequality is consistent � = x s ∈ { b , r } � = ∈ { b , r } x i AllDifferent is not consistent! x i Propagation of AllDifferent (¯ x ) x f g A support is a perfect matching in the graph x s b x i r Constraints 27 / 46
Example: global constraint � = x f x s ∈ { b , g } x f Every inequality is consistent � = x s ∈ { b , r } � = ∈ { b , r } x i AllDifferent is not consistent! x i Propagation of AllDifferent (¯ x ) x f g A support is a perfect matching in the graph The edge ( x f , b ) does not belong to any perfect matching x s b AllDifferent( x f , x s , x i ) is consistent for x f ∈ { g } x s ∈ { b , r } x i ∈ { b , r } x i r Constraints 27 / 46
Search Tree (AllDifferent) x f ∈ { b , g } x s ∈ { b , r } x e ∈ { b , r , g , y } x i ∈ { b , r } Constraints 28 / 46
Search Tree (AllDifferent) x f ∈ { g } x s ∈ { b , r } x e ∈ { b , r , g , y } x i ∈ { b , r } Constraints 28 / 46
Search Tree (AllDifferent) x f ∈ { g } x s ∈ { b , r } x e ∈ { b , r , g , y } x i ∈ { b , r } x s = b x f ∈ { g } x s ∈ { b } x e ∈ { b , r , y } x i ∈ { r } Constraints 28 / 46
Propagation algorithm Every constraint has a propagation algorithm Constraints 29 / 46
Propagation algorithm Every constraint has a propagation algorithm How do we know what inference we can expect from a propagation algorithm? Constraints 29 / 46
Propagation algorithm Every constraint has a propagation algorithm How do we know what inference we can expect from a propagation algorithm? Arc consistency Every possible deduction w.r.t a single constraint on its variable’s domain Constraints 29 / 46
Propagation algorithm Every constraint has a propagation algorithm How do we know what inference we can expect from a propagation algorithm? Arc consistency Every possible deduction w.r.t a single constraint on its variable’s domain For every value v of every variable x Constraints 29 / 46
Propagation algorithm Every constraint has a propagation algorithm How do we know what inference we can expect from a propagation algorithm? Arc consistency Every possible deduction w.r.t a single constraint on its variable’s domain For every value v of every variable x ◮ Does there exist a support for x = v (a solution of the constraint involving x = v ) ◮ Otherwise, remove v from D ( x ) Constraints 29 / 46
Propagation algorithm Every constraint has a propagation algorithm How do we know what inference we can expect from a propagation algorithm? Arc consistency Every possible deduction w.r.t a single constraint on its variable’s domain For every value v of every variable x ◮ Does there exist a support for x = v (a solution of the constraint involving x = v ) ◮ Otherwise, remove v from D ( x ) The bigger (more global) the stronger! Constraints 29 / 46
Propagation algorithm Every constraint has a propagation algorithm How do we know what inference we can expect from a propagation algorithm? Arc consistency Every possible deduction w.r.t a single constraint on its variable’s domain For every value v of every variable x ◮ Does there exist a support for x = v (a solution of the constraint involving x = v ) ◮ Otherwise, remove v from D ( x ) The bigger (more global) the stronger! (and the slower...) Constraints 29 / 46
Outline Language 1 Variables 2 Constraints 3 Modeling 4 Ex: Golomb Ruler Modeling 30 / 46
The art of modeling Techniques to strenghthen propagation Common sub-expressions Global constraints Implied constraints Symmetry breaking Dominance Modeling 31 / 46
Recommend
More recommend