Top Banner
Constraint Constraint Satisfaction Satisfaction Introduction to Introduction to Artificial Intelligence Artificial Intelligence COS302 COS302 Michael L. Littman Michael L. Littman Fall 2001 Fall 2001
30

Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Dec 14, 2015

Download

Documents

Serena Thorton
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Constraint SatisfactionConstraint Satisfaction

Introduction toIntroduction toArtificial IntelligenceArtificial Intelligence

COS302COS302

Michael L. LittmanMichael L. Littman

Fall 2001Fall 2001

Page 2: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

AdministrationAdministration

HW 1 due, HW 2 assigned (3 HW 1 due, HW 2 assigned (3 question parts!)question parts!)

Page 3: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Example CSPExample CSP

3-coloring: color each node R,B,G. 3-coloring: color each node R,B,G. Connected pairs must differ.Connected pairs must differ.

V3

V4

V2

V6

V5 V1

Page 4: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Formal DefinitionFormal Definition

Constraint satisfaction problem Constraint satisfaction problem (CSP): {V, D, C}.(CSP): {V, D, C}.

V is set of variables V1…Vn.V is set of variables V1…Vn.

Each variable assigned a value from Each variable assigned a value from the domain D.the domain D.

C is set of constraints: each a list of C is set of constraints: each a list of vars, legal assignment set.vars, legal assignment set.

Page 5: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

CSP for Graph ProblemCSP for Graph Problem

V = {V1, V2, V3, V4, V5, V6}V = {V1, V2, V3, V4, V5, V6}

D = {R, G, B}D = {R, G, B}

C = {(V1, V5) : { C = {(V1, V5) : { (B,R), (B,G), (R,B), (B,R), (B,G), (R,B), (R,G), (G,B), (G,R)(R,G), (G,B), (G,R) }, },

(V2, V5) :{ (V2, V5) :{ (B,R), (B,G), (R,B), (B,R), (B,G), (R,B), (R,G), (G,B), (G,R)(R,G), (G,B), (G,R) }, },

… … }}

Page 6: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Solve via SearchSolve via Search

In a state, variables V1 through Vk In a state, variables V1 through Vk are assigned and V{k+1} through are assigned and V{k+1} through Vn are unassigned.Vn are unassigned.

Start state: All unassigned.Start state: All unassigned.

G(s): All assigned, constraints G(s): All assigned, constraints satisfied.satisfied.

N(s): One more assignedN(s): One more assigned

Page 7: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Search ExampleSearch Example

ss00 = ?????? = ??????

N(sN(s00) = {R?????, G?????, B?????}) = {R?????, G?????, B?????}

What search algorithms could we What search algorithms could we use?use?

BFS? DFS?BFS? DFS?

Page 8: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

DFS Looks DumbDFS Looks Dumb

V3

V4

V2

V6

V5 V1

Page 9: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Making DFS SmarterMaking DFS Smarter

Like A*, we can use a little bit of Like A*, we can use a little bit of generic knowledge to guide the generic knowledge to guide the search process. Idea?search process. Idea?

h(s) = infinity if constraints violated h(s) = infinity if constraints violated by partial assignmentby partial assignment

Don’t make an assignment if it Don’t make an assignment if it violates constraintsviolates constraints

Don’t peek.

Page 10: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Consistency CheckingConsistency Checking

Still flails a bit…Still flails a bit…

V3

V4

V2

V6

V5 V1

V4

V3 V2

Page 11: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Forward CheckingForward Checking

Track set of (remaining) legal values Track set of (remaining) legal values for each variable. Fail if any for each variable. Fail if any variable’s set goes empty.variable’s set goes empty.

How express this as a heuristic How express this as a heuristic function h(s)?function h(s)?

Page 12: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Let’s Try ItLet’s Try It

Yay!Yay!

V3

V4

V2

V6

V5 V1

Page 13: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Computational OverheadComputational Overhead

How would you implement forward How would you implement forward checking?checking?

Could the “empty domain” Could the “empty domain” calculation be performed calculation be performed incrementally?incrementally?

Page 14: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Constraint PropagationConstraint Propagation

As values are eliminated from a As values are eliminated from a variable’s domain, this can start a variable’s domain, this can start a cascade effect on other variables.cascade effect on other variables.

Expensive operation, so often Expensive operation, so often performed only before search performed only before search begins. Can be quite powerful…begins. Can be quite powerful…

Page 15: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Constraint PropagationConstraint Propagation

Solved without searchSolved without search

V3

V4

V2

V6

V5 V1

Page 16: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Example CSPsExample CSPs

Graph coloringGraph coloring• Real applications include hundreds Real applications include hundreds

of thousands of nodesof thousands of nodes

VLSI board layoutVLSI board layout

8 queens, cryptarithmetic8 queens, cryptarithmetic

Visual scene interpretation: WaltzVisual scene interpretation: Waltz

Minesweeper…Minesweeper…

Page 17: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Minesweeper ExampleMinesweeper Example

Number is count of bombs in 8 Number is count of bombs in 8 adjacent cellsadjacent cells

00

2211

111100

00 00

00 00

11 11

Page 18: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Minesweeper CSPMinesweeper CSP

V = { V1, …, V8 }, D = {B, S}V = { V1, …, V8 }, D = {B, S}

C = { C = { (V1, V2) : { (B,S), (S,B) },(V1, V2) : { (B,S), (S,B) },

(V1, V2, V3): {(S,S,B), (S,B,S), (V1, V2, V3): {(S,S,B), (S,B,S), (B,S,S)}, (B,S,S)}, …}…}

00

2211

111100

00 00

00 00

11 11

V1V1V2V2

V3V3

V4V4

V8V8 V7V7 V6V6 V5V5

Page 19: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Using CSP to DecideUsing CSP to Decide

00

2211

111100

00 00

00 00

11 11

V1V1V2V2

SS

V4V4

V8V8 V7V7 SS V5V5

How can we check if a value is How can we check if a value is forced?forced?

Page 20: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Waltz AlgorithmWaltz Algorithm

Each “Y” intersection can be either Each “Y” intersection can be either concave or convex. Global concave or convex. Global interpretation is key. interpretation is key.

Page 21: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

SchedulingScheduling

Big, important use of CSPs.Big, important use of CSPs.• Makes multi-million dollar decisions Makes multi-million dollar decisions

in many industries.in many industries.• Used in space mission planning.Used in space mission planning.• Military uses.Military uses.

Large state spacesLarge state spaces

Page 22: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Generic CSP AlgorithmGeneric CSP Algorithm

• If all values assigned and no If all values assigned and no constraints violated, doneconstraints violated, done

• Apply consistency checkingApply consistency checking• If deadend, backtrackIf deadend, backtrack• Select variable to be assignedSelect variable to be assigned• Select value for the variableSelect value for the variable• Assign variable and recurseAssign variable and recurse

Page 23: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Search HeuristicsSearch Heuristics

Have some freedom in what variable Have some freedom in what variable to assign nextto assign next

• Most constrained variableMost constrained variable• Most constraining variableMost constraining variable

Freedom in value to assign to that Freedom in value to assign to that variablevariable

• Least constraining valueLeast constraining value

Page 24: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Implementing CPImplementing CP

Fundamental question:Fundamental question:• Given a constraint involving variables V1…Given a constraint involving variables V1…

Vk and possible values P1…Pk, remove Vk and possible values P1…Pk, remove impossible valuesimpossible values

For i = 1 to kFor i = 1 to kfor each val in Pifor each val in Pi

if not possible(V1…V{i-1} { val } if not possible(V1…V{i-1} { val } V{i+1}…Vk, legalset)V{i+1}…Vk, legalset)

Vi -= { val }, restartVi -= { val }, restartReturn P1…PkReturn P1…Pk

Page 25: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

What’s “possible”?What’s “possible”?

Possible(V1…Vk, legalset)Possible(V1…Vk, legalset)

For l1…lk in legalsetFor l1…lk in legalset

fail = 0fail = 0

For i = 1 to kFor i = 1 to k

if li not in Vi, fail = 1if li not in Vi, fail = 1

if fail == 0, return TRUEif fail == 0, return TRUE

Return FALSEReturn FALSE

Page 26: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Formalizing Other CSPsFormalizing Other CSPs

CryptogramsCryptograms

Paint by NumbersPaint by Numbers

Crossword PuzzlesCrossword Puzzles

Four on the FloorFour on the Floor

BattleshipsBattleships

Page 27: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

What to LearnWhat to Learn

Definition of a CSP: relationship to Definition of a CSP: relationship to search.search.

How to formalize problems as CSPsHow to formalize problems as CSPs

Use of improvements like Use of improvements like consistency checking and forward consistency checking and forward checkingchecking

Page 28: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Homework 2Homework 2

1.1. Consider the heuristic for Rush Hour of counting the Consider the heuristic for Rush Hour of counting the cars blocking the ice cream truck and adding one. (a) cars blocking the ice cream truck and adding one. (a) Show this is a relaxation by giving conditions for an Show this is a relaxation by giving conditions for an illegal move and showing what was eliminated. (b) For illegal move and showing what was eliminated. (b) For the board on the next page, show an optimal the board on the next page, show an optimal sequence of boards sequence of boards en routeen route to the goal. Label each to the goal. Label each board with the f value from the heuristic.board with the f value from the heuristic.

2.2. Describe an improved heuristic for Rush Hour. (a) Describe an improved heuristic for Rush Hour. (a) Explain why it is admissible. (b) Is it a relaxation? (c) Explain why it is admissible. (b) Is it a relaxation? (c) Label the boards from 1b with the f values from your Label the boards from 1b with the f values from your heuristic.heuristic.

Page 29: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Rush Hour ExampleRush Hour Example

Page 30: Constraint Satisfaction Introduction to Artificial Intelligence COS302 Michael L. Littman Fall 2001.

Homework 2 (cont.)Homework 2 (cont.)

3.3. Consider the 3-coloring problem on a graph Consider the 3-coloring problem on a graph with n nodes with the additional constraint with n nodes with the additional constraint that there that there notnot be exactly 2 nodes colored be exactly 2 nodes colored blue. (a) The most direct constraint for this blue. (a) The most direct constraint for this involves all n nodes. How large is the involves all n nodes. How large is the corresponding legal assignment set for this corresponding legal assignment set for this constraint? (b) Explain how to specify this constraint? (b) Explain how to specify this constraint more compactly by breaking it constraint more compactly by breaking it down into a set of simpler constraints. How down into a set of simpler constraints. How many constraints do you add and how large many constraints do you add and how large is the legal assignment set for each one?is the legal assignment set for each one?