Title: CS 4700: Foundations of Artificial Intelligence
1CS 4700Foundations of Artificial Intelligence
- Carla P. Gomes
- gomes_at_cs.cornell.edu
- Module
- CSP2
- (Reading RN Chapter 5)
2- Encodings
- Global Constraints
- Redundant Constraints
- Streamlining
- Complexity
3 4Latin 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)
5Fiber 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.
6Routing 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 routing is an NP-hard problem.
7 Application Example Routers in Fiber Optic
Networks
Dynamic wavelength routing in Fiber Optic
Networks can be directly mapped into the Latin
Square Completion Problem.
8Design 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 B C 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
9Underlying Latin Square structure Characterizes
many real world applications
Scheduling and timetabling
Sudoku
Many more applications
10Latin 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)
11Completing 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
12How to Encode the Latin Square Completionas a
CSP?
13Latin Square Completion as a Binary CSP
How do we represent the Latin Square problem as
a binary CSP?
14Domain Reduction in LSCP
Forward Checking
Arc Consistency
15Other Examples of Applications of Graph Coloring
16Scheduling of Final Exams
1
2
7
3
6
5
4
What are the constraints between courses? Find a
valid coloring
17Scheduling 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.
18Frequency 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
19Index 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.
20Other Representations
21Latin Square Completion as an n-ary CSP
- Variables -
-
- Constraints -
Why would we use this formulation?
22Exploiting 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)
23Exploiting Structure in QCP ALLDIFF as Global
Constraint
24Exploiting Structure Arc Consistency vs. All Diff
25Global 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
26Global 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
27Global 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 X21, X22, nor X23,
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!
28Global 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
29Global Constraints all_diff
- Example A,B 1..2, C 1..3, D 2..5, E
3..6, - all_diff(A,B,C,D,E).
30Global 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.
31Global 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.
32Global 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!
33Global 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.
34Global Constraints all_diff
- A-1-B-2-A is an even alternating cycle
- By permutation of variables A and B, the
solution ltA,B,C,D,Egt lt1,2,3,4,5gt becomes
ltA,B,C,D,Egt lt2,1,3,4,5gt - 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
35Global 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/2 and C - 1/2 may also be filtered.
The compact graph may thus be further simplified
to
36Global Constraints all_diff
- By expanding back the simplified compact graph,
one gets the graph on the right that
Which immediately sets C3 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
37Global 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.
38Global 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-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.
39Global 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.
40Global Constraints
- Alldiff ? example of a global constraint.
- Global since they typically involve several
variables and constraints - (as in the alldiff). Poor choice of namethey
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
41Catalog of global constraints (300)
http//www.emn.fr/xinfo/sdemasse/gccat/