Download presentation
Presentation is loading. Please wait.
1
Carla P. Gomes CS4700 CS 4700: Foundations of Artificial Intelligence Carla P. Gomes gomes@cs.cornell.edu Module: CSP2 (Reading R&N: Chapter 5)
2
Carla P. Gomes CS4700 Encodings Global Constraints Redundant Constraints Streamlining Complexity
3
Carla P. Gomes CS4700 Case Study
4
Carla P. Gomes CS4700 Given an N X N matrix, and given N colors, a Latin Square of order N is a colored matrix, such that: -all cells are colored. - each color occurs exactly once in each row. - each color occurs exactly once in each column. Latin Square (Order 4) Latin Squares: An Abstraction for Real World Applications
5
Carla P. Gomes CS4700 Fiber Optic Networks Nodes are capable of photonic switching --dynamic wavelength routing -- which involves the setting of the wavelengths. Nodes connect point to point fiber optic links Each fiber optic link supports a large number of wavelengths Wavelength Division Multiplexing (WDM) the most promising technology for the next generation of wide-area backbone networks.
6
Carla P. Gomes CS4700 Routing in Fiber Optic Networks Routing Node How can we achieve conflict-free routing in each node of the network? Dynamic wavelength routing is an NP-hard problem. Input PortsOutput Ports 1 2 3 4 1 2 3 4 preassigned channels
7
Carla P. Gomes CS4700 Application Example: Routers in Fiber Optic Networks Application Example: Routers in Fiber Optic Networks Dynamic wavelength routing in Fiber Optic Networks can be directly mapped into the Latin Square Completion Problem. each channel cannot be repeated in the same input port (row constraints); each channel cannot be repeated in the same output port (column constraints); CONFLICT FREE LATIN ROUTER Input ports Output ports 3 1 2 4 Input PortOutput Port 1 2 4 3
8
Carla P. Gomes CS4700 Design of Statistical Experiments We have 5 treatments for growing beans. We want to know what treatments are effective in increasing yield, and by how much. The objective is to eliminate bias and distribute the treatments somewhat evenly over the test plot. Latin Square Analysis of Variance B A D E B C C B A E D B D C B A E E A C D B B E D C A (*) Already in use in this sub-plot
9
123456123456 1 2 3 4 5 6 R2 X R4 R1 R3 R5 XR1R5R4R3 R2R4R1R3R5 R1XR3R5R2 R5R3 X R2 R4 R5R2 X R1 R3R2R4 R1 X teams Scheduling and timetabling Many more applications… Sudoku Underlying Latin Square structure Characterizes many real world applications
10
Carla P. Gomes CS4700 Given an N X N matrix, and given N colors, a Latin Square of order N is a colored matrix, such that: -all cells are colored. - each color occurs exactly once in each row. - each color occurs exactly once in each column. Latin Square (Order 4) Latin Squares: An Abstraction for Real World Applications How do you generate a Latin square, say a 5x5? Is it computationally hard?
11
Carla P. Gomes CS4700 Given a partial assignment of colors (10 colors in this case), can the partial quasigroup (latin square) be completed so we obtain a full quasigroup? Example: Completing Latin Squares: A Hard Computational Problem Deciding if a Latin Square is completable is NP-Complete
12
Carla P. Gomes CS4700 How to Encode the Latin Square Completion as a CSP?
13
Latin Square Completion as a Binary CSP Variables - Constraints - How do we represent the Latin Square problem as a binary CSP? Graph Coloring Problem
14
C. P. Gomes Forward CheckingArc Consistency Domain Reduction in LSCP
15
C. P. Gomes Other Examples of Applications of Graph Coloring
16
C. P. Gomes Scheduling of Final Exams 1 7 2 36 54 What are the constraints between courses? Find a valid coloring 1 7 2 36 54 Time Period I II III IV Courses 1,6 2 3,5 4,7
17
C. P. Gomes Scheduling of Final Exams How can the final exams at Cornell be scheduled so that no student has two exams at the same time? A vertex correspond to a course; An edge between two vertices denotes that there is at least one common Student in the courses they represent; Each time slot for a final exam is represented by a different color. A coloring of the graph corresponds to a valid schedule of the exams.
18
C. P. Gomes Frequency Assignments T.V. channels 2 through 13 are assigned to stations in North America so that no no two stations within 150 miles can operate on the same channel. How can the assignment of channels be modeled as a graph coloring? A vertex corresponds to one station; There is a edge between two vertices if they are located within 150 miles of each other Coloring of graph --- corresponds to a valid assignment of channels; each color represents a different channel. Many other problems can be represented as graph coloring…
19
C. P. Gomes Index Registers In efficient compilers the execution of loops can be sped up by storing frequently used variables temporarily in index registers in the central processing unit, instead of the regular memory. For a given loop, how many index registers are needed? Each vertex corresponds to a variable in the loop. An edge between two vertices denotes the fact that the corresponding variables must be stored in index registers at the same time during the execution of the loop. Chromatic number of the graph gives the number of index registers needed.
20
C. P. Gomes Other Representations
21
C. P. Gomes Latin Square Completion as an n-ary CSP Variables - Constraints - row column [ vs. for Binary CSP] Why would we use this formulation?
22
C. P. Gomes Exploiting Structure for Domain Reduction A very successful strategy for domain reduction in CSP is to exploit the structure of groups of constraints and treat them as a sub-problem. Example using Network Flow Algorithms: All-different constraints (Alldiff)
23
C. P. Gomes Exploiting Structure in QCP ALLDIFF as Global Constraint Two solutions: we can update the domains of the column variables Analogously, we can update the domains of the other variables Matching on a Bipartite graph All-different constraint (Matching on a bipartite graph)
24
C. P. Gomes Exploiting Structure Arc Consistency vs. All Diff Arc Consistency (Binary CSP) Solves up to order 20 Size search space AllDiff Solves up to order 40 Size search space
25
C. P. Gomes Global Constraints: alldiff Example: X 1 : 1,2,3X 6 : 1,2,3,4,5,6,7,8,9 X 2 : 1,2,3,4,5,6X 7 : 1,2,3,4,5,6,7,8,9 X 3 : 1,2,3,4,5,6,7,8,9X 8 : 1,2,3 X 4 : 1,2,3,4,5,6X 9 : 1,2,3,4,5,6 X 5 : 1,2,3 It is clear that constraint propagation based on maintenance of node-, arc- or even path-consistency would not eliminate any redundant label. Yet, it is very easy to infer such elimination with a global view of the constraint! Example from Pedro Barahona
26
C. P. Gomes Global Constraints: alldiff Variables X 1, X 5 and X 8 may only take values 1, 2 and 3. Since there are 3 values for 3 variables, these must be assigned these values which must then be removed from the domain of the other variables. Now, variables X2, X4 and X9 may only take values 4, 5 e 6, that must be removed from the other variables domains. X 1 : 1,2,3 X 2 : 1,2,3,4,5,6 X 3 : 1,2,3,4,5,6,7,8,9 X 4 : 1,2,3,4,5,6 X 5 : 1,2,3 X 6 : 1,2,3,4,5,6,7,8,9 X 7 : 1,2,3,4,5,6,7,8,9 X 8 : 1,2,3X 9 : 1,2,3,4,5,6 X 1 : 1,2,3 X 2 : 1,2,3,4,5,6 X 3 : 1,2,3,4,5,6,7,8,9 X 4 : 1,2,3, 4,5,6 X 5 : 1,2,3 X 6 : 1,2,3,4,5,6,7,8,9 X 7 : 1,2,3,4,5,6,7,8,9 X 8 : 1,2,3X 9 : 1,2,3,4,5,6
27
C. P. Gomes Global Constraints: alldiff In this case, these prunings could be obtained, by maintaining (strong) 4-consistency. For example, analysing variables X 1, X 2, X 5 and X 8, it would be “easy” to verify that from the d 4 potential assignments of values to them, no assignment would include X 2 =1, X 2 =2, nor X 2 =3, thus leading to the prunning of X 2 domain. However, such maintenance is usually very expensive, computationally. For each combination of 4 variables, d 4 tuples whould be checked, with complexity O(d 4 ). In fact, in some cases, n-strong consistency would be required, so its naïf maintenance would be exponential on the number of variables, exactly what one would like to avoid in search!
28
C. P. Gomes Global Constraints: all_diff Key Ideas: Formulate the problem as “Matching” on a bipartite graph: For each variable-value pair, there is an arc in the bipartite graph. A subset of arcs of a graph is called a matching, if no two arcs have a vertex in common. A matching of maximum cardinality is called a maximum matching. Note that when we have a bipartite graph a matchibng that covers all the nodes is a maximum matching. For any solution of the all_diff constraint there is one and only one maximum matching. See Regin AAAI 1994
29
C. P. Gomes Global Constraints: all_diff Example: A,B:: 1..2, C:: 1..3, D:: 2..5, E:: 3..6, all_diff([A,B,C,D,E]). A B C D E 1 2 3 4 5 6 A = 1 B = 2 C = 3 D = 4 E = 5 Maximum Matching
30
C. P. Gomes Global Constraints: all_diff Given a CSP P, it is diff-arc-consistent iff every arc belongs to a matching which covers all the nodes of the graph associated with P. Given a matching M, an arc in M is a matching arc. Every arc not in M is free. A node or vertex is matched if it is incident to a matching arc and free otherwise. An alternating path or cycle is a simple path or cycle whose arcs or edges are alternately matching and free. The length of an alternating path or cycle is the number of arcs or edges it contains. An arc or edge which belongs to every matching is vital.
31
C. P. Gomes Global Constraints: all_diff The propagation (domain filtering) is done according to the following principles: If an arc does not belong to any maximal matching, then it does not belong to any all_diff solution. Given a maximal matching, an arc belongs to any maximal matching iff it belongs (Berge 1970): To an even alternating cycle; or To an even alternating path, starting at a free node. Given a CSP P, it is diff-arc-consistent iff every arc belongs to a matching which covers all the nodes of the graph associated with P.
32
C. P. Gomes Global Constraints: all_diff Example: For the maximal matching (MM) shown 6 is a free node; 6-E-5-D-4 is an even alternating path, alternating arcs from the MM (E-5, D-4) with arcs not in the MM (D-5, E-6); A-1-B-2-A is an even alternating cycle; E-3 does not belong to any even alternating cycle E-3 does not belong to any even alternating path starting in a free node (6) E-3 may be filtered out! A B C D E 1 2 3 4 5 6
33
C. P. Gomes Global Constraints: all_diff Compaction Before this analysis, the graph may be “compacted”, aggregating, into a single node, “equivalent nodes”, i.e. those belonging to even alternating cycles. Intuitively, for any solution involving these variables and values, a different solution may be obtained by permutation of the corresponding assignments.
34
C. P. Gomes Global Constraints: all_diff A-1-B-2-A is an even alternating cycle; By permutation of variables A and B, the solution = becomes = Hence, nodes A e B, as well as nodes 1 and 2 may be grouped together (as may the nodes D/E and 4/5). A/B C 4/5 3 6 D/E 1/2 A B C D E 1 2 3 4 5 6 With these grouping the graph becomes much more compact
35
C. P. Gomes Global Constraints: all_diff Analysis of the compacted graph shows that A/B C 4/5 3 6 D/E 1/2 A/B C 4/5 3 6 D/E 1/2 Arc D/E - 3 may be filtered out (notice that despite belonging to cycle D/E - 3 - C - 1/2 - D/E, this cycle is not alternating. Arcs D/E - 1/2 and C - 1/2 may also be filtered. The compact graph may thus be further simplified to
36
C. P. Gomes Global Constraints: all_diff By expanding back the simplified compact graph, one gets the graph on the right that A/B C 4/5 3 6 D/E 1/2 Which immediately sets C=3 and, more generaly, filters the initial domains to A,B :: 1..2, C:: 1,2,3, D:: 2,3,4,5, E:: 3,4,5,6 A B C D E 1 2 3 4 5 6
37
C. P. Gomes Global Constraints: all_diff Upon elimination of some labels (arcs), possibly due to other constraints, the all_diff constraint propagates such prunings, incrementally. There are 3 situations to consider: Elimination of a vital arc (the only arc connecting a variable node with a value node): The constraint cannot be satisfied. A B C D E 1 2 3 4 5 6 A B C D E 1 2 3 4 5 6 ?
38
C. P. Gomes Global Constraints: all_diff Elimination of a non-vital arc which is a not member to the maximal matching Eliminate the arcs that do not belong any more to an alternating cycle or path. A B C D E 1 2 3 4 5 6 A B C D E 1 2 3 4 5 6 Arc A-4 does not belong to the even alternating path started in node 6. D-5 also leaves this path, but it still belongs to an even alternating cycle.
39
C. P. Gomes Global Constraints: all_diff Elimination of a non-vital arc which is not a member to the maximal matching Determine a new maximal matching and restart from there. A new maximal matching includes arcs D-5 and E-6. In this matching, arcs E-4 and E-5 do not belong to even alternating paths or alternating cycles. A B C D E 1 2 3 4 5 6 A B C D E 1 2 3 4 5 6
40
C. P. Gomes Global Constraints Alldiff example of a “global constraint.” “Global” – since they typically involve several variables and constraints (as in the alldiff). Poor choice of name…they are still local… Global constraints encapsulate a sub-problem, (typically, why?) solved efficiently (polytime). Network flow algorithms are used for several global constraints. Lots of global constraints, e.g., element constraint, cardinality constraint, sequence constraint, etc, etc Active Research Area
41
C. P. Gomes Catalog of global constraints (300+) ConstraintStructure/technique alldifferentbipartite matching [Régin, 1994] symmetric- alldifferent general matching [Régin, 1999] soft-alldifferentmatching [Petit, Régin & Bessière, 2001], minimum-cost flow [van Hoeve, 2004] Cardinality matrixnetwork flow, transportation problem [Régin & Gomes, 2004] cardinalitynetwork flow [Régin, 1999, 2002] soft-cardinality minimum-cost flow [van Hoeve, Pesant & Rousseau, 2005], [Milano & Zanarini, 2006] open-cardinalitynetwork flow [van Hoeve & Régin, 2006] knapsack/sumdynamic programming [Trick, 2003] regulardirected acyclic graph [Pesant, 2004] soft-regularshortest paths [van Hoeve, Pesant & Rousseau, 2005] circuitnetwork flow [Kaya & Hooker, 2006] sequencededicated algorithm [van Hoeve, Pesant, Rousseau & Sabharwal, 2006] disjunctive/cumulati ve dedicated algorithm [Carlier & Pinson, 1994] [Mercier & Van Hentenryck, 2006] inter-distancededicated algorithm [Quimper, Lopez-Ortiz & Pesant, 2006]... http://www.emn.fr/xinfo/sdemasse/gccat/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.