cs 4700: foundations of artificial intelligence

39
Carla P. Gomes CS4700 CS 4700: Foundations of Artificial Intelligence Carla P. Gomes [email protected] Module: CSP2 (Reading R&N: Chapter 5)

Upload: candid

Post on 05-Jan-2016

34 views

Category:

Documents


0 download

DESCRIPTION

CS 4700: Foundations of Artificial Intelligence. Carla P. Gomes [email protected] Module: CSP2 (Reading R&N: Chapter 5). Encodings Global Constraints Redundant Constraints Streamlining Complexity. Case Study. Latin Squares: An Abstraction for Real World Applications. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS 4700: Foundations of  Artificial Intelligence

Carla P. GomesCS4700

CS 4700:Foundations of Artificial Intelligence

Carla P. [email protected]

Module: CSP2

(Reading R&N: Chapter 5)

Page 2: CS 4700: Foundations of  Artificial Intelligence

Carla P. GomesCS4700

Encodings

Global Constraints

Redundant Constraints

Streamlining

Complexity

Page 3: CS 4700: Foundations of  Artificial Intelligence

Carla P. GomesCS4700

Case Study

Page 4: CS 4700: Foundations of  Artificial Intelligence

Carla P. GomesCS4700

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

Page 5: CS 4700: Foundations of  Artificial Intelligence

Carla P. GomesCS4700

Fiber Optic Networks

Nodes are capable of photonic switching --dynamic wavelength routing --

which involves the setting of the wavelengths.

Nodesconnect point to point

fiber optic links

Each fiber optic link supports alarge number of wavelengths

Wavelength

Division

Multiplexing (WDM)

the most promising

technology for the

next generation of

wide-area

backbone networks.

Page 6: CS 4700: Foundations of  Artificial Intelligence

Carla P. GomesCS4700

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 Ports Output Ports1

2

3

4

1

2

3

4

preassigned channels

Page 7: CS 4700: Foundations of  Artificial Intelligence

Carla P. GomesCS4700

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 FREELATIN ROUTER

Inp

ut

po

rts

Output ports

3

1

2

4

Input Port Output Port

1

2

43

Page 8: CS 4700: Foundations of  Artificial Intelligence

Carla P. GomesCS4700

Design of Statistical ExperimentsDesign 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 BB C

C B A E D

D C BB A E

E A C D B

B E D C A

(*) Already in use (*) Already in use in this sub-plotin this sub-plot

Page 9: CS 4700: Foundations of  Artificial Intelligence

1

2

3

4

5

6

1 2 3 4 5 6

R2

X

R4

R1

R3

R5

XR1R5R4R3

R2R4R1R3R5

R1XR3R5R2

R5R3XR2R4

R4R5R2XR1

R3R2R4R1X

teams

team

s

Scheduling and timetabling

Many more applications…Sudoku

Underlying Latin Square structureCharacterizes many real world applications

Page 10: CS 4700: Foundations of  Artificial Intelligence

Carla P. GomesCS4700

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 generatea Latin square, say a 5x5?Is it computationally hard?

Page 11: CS 4700: Foundations of  Artificial Intelligence

Carla P. GomesCS4700

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 ifa Latin Squareis completableis NP-Complete

Page 12: CS 4700: Foundations of  Artificial Intelligence

Carla P. GomesCS4700

How to Encode the Latin Square Completion

as a CSP?

Page 13: CS 4700: Foundations of  Artificial Intelligence

Latin Square Completion as a Binary CSP

Latin Square Completion as a Binary CSP

)2(nO

}...,,2,1{, njix

....,,2,1,;,, njijicellofcolorjix

)3(nO

njjkki

xjixji ,...,1,1,...,1,,),(

niikjk

xjixji ,...,1,1,...,1,,),(

•Variables -

•Constraints -

How do we represent theLatin Square problem as a binary

CSP?

Graph Coloring Problem

Page 14: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Forward Checking Arc Consistency

Domain Reduction in LSCP

Page 15: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Other Examples of Applications of Graph Coloring

Other Examples of Applications of Graph Coloring

Page 16: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Scheduling of Final ExamsScheduling of Final Exams

1

7 2

36

5 4

What are the constraints between courses?Find a valid coloring

1

7 2

36

5 4

TimePeriod

IIIIIIIV

Courses

1,62

3,54,7

Page 17: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Frequency AssignmentsFrequency 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…

Page 18: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Other RepresentationsOther Representations

Page 19: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Latin Square Completion as an n-ary CSP

Latin Square Completion as an n-ary CSP

• Variables -

• Constraints -

}...,,2,1{, njix

....,,2,1,;,, njijicellofcolorjix

....,,2,1);,,...,2,

,1,

( ninixix

ixalldiff

....,,2,1);,,...,,2

,,1

( njjnxjx

jxalldiff

)2(nO

)(nO

row

column

[ vs. for Binary CSP])2(nO

[ vs. for Binary CSP])3(nO

Why would we use this formulation?

Page 20: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Exploiting Structure for Domain ReductionExploiting 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)

Page 21: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Exploiting Structure in QCPALLDIFF 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)

Page 22: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Exploiting StructureArc Consistency vs. All Diff

Arc Consistency(Binary CSP)

Solves up to order 20Size search space

40020

AllDiffSolves up to order 40

Size searchspace 160040

Page 23: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: alldiffGlobal 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

Page 24: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: alldiffGlobal 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

Page 25: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: alldiffGlobal 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!

Page 26: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: all_diffGlobal 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

Page 27: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: all_diffGlobal 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

Page 28: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: all_diffGlobal 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 orvertex 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.

Page 29: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: all_diffGlobal 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.

Page 30: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: all_diffGlobal 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

Page 31: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: all_diffGlobal 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.

Page 32: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: all_diffGlobal 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).

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

Page 33: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: all_diffGlobal 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

Page 34: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: all_diffGlobal 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

Page 35: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: all_diffGlobal 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

?

Page 36: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: all_diffGlobal 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.

Page 37: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global Constraints: all_diffGlobal 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

Page 38: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Global ConstraintsGlobal 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

Page 39: CS 4700: Foundations of  Artificial Intelligence

C. P. Gomes

Catalog of global constraints (300+)Catalog of global constraints (300+)

Constraint Structure/technique

alldifferent bipartite matching [Régin, 1994]

symmetric-alldifferent general matching [Régin, 1999]

soft-alldifferent matching [Petit, Régin & Bessière, 2001], minimum-cost flow [van Hoeve, 2004]

Cardinality matrix network flow, transportation problem [Régin & Gomes, 2004]

cardinality network flow [Régin, 1999, 2002]

soft-cardinality minimum-cost flow [van Hoeve, Pesant & Rousseau, 2005], [Milano & Zanarini, 2006]

open-cardinality network flow [van Hoeve & Régin, 2006]

knapsack/sum dynamic programming [Trick, 2003]

regular directed acyclic graph [Pesant, 2004]

soft-regular shortest paths [van Hoeve, Pesant & Rousseau, 2005]

circuit network flow [Kaya & Hooker, 2006]

sequence dedicated algorithm [van Hoeve, Pesant, Rousseau & Sabharwal, 2006]

disjunctive/cumulative dedicated algorithm [Carlier & Pinson, 1994] [Mercier & Van Hentenryck, 2006]

inter-distance dedicated algorithm [Quimper, Lopez-Ortiz & Pesant, 2006]

. . . . . .

http://www.emn.fr/xinfo/sdemasse/gccat/