390 likes | 563 Views
CS 4700: Foundations of Artificial Intelligence. Carla P. Gomes gomes@cs.cornell.edu Module: CSP2 (Reading R&N: Chapter 5). Encodings Global Constraints Redundant Constraints Streamlining Complexity. Case Study. Latin Squares: An Abstraction for Real World Applications.
E N D
CS 4700:Foundations of Artificial Intelligence Carla P. Gomes gomes@cs.cornell.edu Module: CSP2 (Reading R&N: Chapter 5)
Encodings • Global Constraints • Redundant Constraints • Streamlining • Complexity
Latin Squares: An Abstraction for Real World Applications 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)
Each fiber optic link supports a large number of wavelengths Nodes are capable of photonic switching --dynamic wavelength routing -- which involves the setting of the wavelengths. Fiber Optic Networks Nodes connect point to point fiber optic links • Wavelength • Division • Multiplexing (WDM) • the most promising • technology for the • next generation of • wide-area • backbone networks.
preassigned channels Routing in Fiber Optic Networks Input Ports Output Ports 1 1 2 2 3 3 4 4 Routing Node How can we achieve conflict-free routing in each node of the network? Dynamic wavelength routingis an NP-hard 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); Input Port Output Port Output ports 1 1 2 2 3 3 Input ports 4 4 CONFLICT FREE LATIN ROUTER Application Example: Routers in Fiber Optic Networks Dynamic wavelength routingin Fiber Optic Networks can be directly mapped into theLatin Square Completion Problem.
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 A D E BC C B A E D D C B A E E A C D B B E D C A (*) Already in use in this sub-plot
teams • 1 2 3 4 5 6 • X • R4 • R2 • R3 • R1 • R5 • 1 • 2 • 3 • 4 • 5 • 6 • X • R2 • R5 • R3 • R1 • R4 teams • X • R2 • R3 • R1 • R5 • R4 • R2 • R5 • R3 • X • R4 • R1 • R5 • R3 • R1 • R4 • X • R2 • R3 • R4 • R5 • R1 • R2 • X Underlying Latin Square structure Characterizes many real world applications Scheduling and timetabling Sudoku Many more applications…
Latin Squares: An Abstraction for Real World Applications 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. How do you generate a Latin square, say a 5x5? Is it computationally hard? Latin Square (Order 4)
Completing Latin Squares: A Hard Computational Problem 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: Deciding if a Latin Square is completable is NP-Complete
Variables - • Constraints - Graph Coloring Problem Latin Square Completion as a Binary CSP How do we represent the Latin Square problem as a binary CSP?
Domain Reduction in LSCP Forward Checking Arc Consistency
1 Time Period I II III IV Courses 1,6 2 3,5 4,7 2 7 6 3 5 4 Scheduling of Final Exams 1 2 7 6 3 5 4 What are the constraints between courses? Find a valid coloring
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…
[ vs. for Binary CSP] [ vs. for Binary CSP] row column Latin Square Completion as an n-ary CSP • Variables - • Constraints - Why would we use this formulation?
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)
Matching on a Bipartite graph Two solutions: All-different constraint (Matching on a bipartite graph) we can update the domains of the column variables Analogously, we can update the domains of the other variables Exploiting Structure in QCP ALLDIFF as Global Constraint
Exploiting Structure Arc Consistency vs. All Diff AllDiff Solves up to order 40 Size search space Arc Consistency (Binary CSP) Solves up to order 20 Size search space
Global Constraints: alldiff • Example: • X1: 1,2,3 X6: 1,2,3,4,5,6,7,8,9 • X2: 1,2,3,4,5,6 X7: 1,2,3,4,5,6,7,8,9 • X3: 1,2,3,4,5,6,7,8,9 X8: 1,2,3 • X4: 1,2,3,4,5,6 X9: 1,2,3,4,5,6 • X5: 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
Global Constraints: alldiff • Variables X1, X5 and X8 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. X1: 1,2,3 X2:1,2,3,4,5,6 X3:1,2,3,4,5,6,7,8,9 X4:1,2,3,4,5,6 X5: 1,2,3 X6:1,2,3,4,5,6,7,8,9 X7:1,2,3,4,5,6,7,8,9 X8: 1,2,3 X9:1,2,3,4,5,6 X1: 1,2,3 X2:1,2,3,4,5,6 X3:1,2,3,4,5,6,7,8,9 X4:1,2,3,4,5,6 X5: 1,2,3 X6:1,2,3,4,5,6,7,8,9 X7:1,2,3,4,5,6,7,8,9 X8: 1,2,3 X9:1,2,3,4,5,6
Global Constraints: alldiff • In this case, these prunings could be obtained, by maintaining (strong) 4-consistency. • For example, analysing variables X1, X2, X5 and X8, it would be “easy” to verify that from the d4 potential assignments of values to them, no assignment would include X2=1, X2=2, nor X2=3, thus leading to the prunning of X2 domain. • However, such maintenance is usually very expensive, computationally. For each combination of 4 variables, d4 tuples whould be checked, with complexity O(d4). • 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!
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
Maximum Matching 1 A B D 2 A = 1 B = 2 C = 3 D = 4 E = 5 C E 3 4 5 6 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]).
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.
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. • 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.
1 A B D 2 3 C E 4 5 6 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-3may befiltered out!
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.
A/B 1/2 1 D A B 3 2 C E C D/E 4/5 3 6 4 5 6 Global Constraints: all_diff • A-1-B-2-A is an even alternating cycle; • By permutation of variables A and B, the solution <A,B,C,D,E> = <1,2,3,4,5> becomes <A,B,C,D,E> = <2,1,3,4,5> • 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). With these grouping the graph becomes much more compact
A/B 1/2 3 C C D/E 4/5 6 A/B 1/2 3 D/E 4/5 6 Global Constraints: all_diff • Analysis of the compacted graph shows that • 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/2andC - 1/2may also be filtered. The compact graph may thus be further simplified to
1 2 A D B 3 4 C C E 5 6 A/B 1/2 3 D/E 4/5 6 Global Constraints: all_diff • By expanding back the simplified compact graph, one gets the graph on the rightthat 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
1 2 D A B B D A 3 1 4 C C E E 2 5 ? 3 6 4 5 6 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 constraintcannot be satisfied.
A B D D B A 1 2 C C E E 1 3 2 4 3 5 4 6 5 6 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. Arc A-4does 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.
D A B D B A 1 1 2 2 C C E E 3 3 4 4 5 5 6 6 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-5do not belong to even alternating paths or alternating cycles.
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
Catalog of global constraints (300+) http://www.emn.fr/xinfo/sdemasse/gccat/