11
CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore, Percy Liang, Luke Zettlemoyer

CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew

Embed Size (px)

Citation preview

Page 1: CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew

CSPs

Tamara BergCS 590-133 Artificial Intelligence

Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore, Percy Liang, Luke Zettlemoyer

Page 2: CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew

Constraint Satisfaction Problems(Chapter 6)

Page 3: CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew

What is search for?• Assumptions: single agent,

deterministic, fully observable, discrete environment

• Search for planning– The path to the goal is the

important thing– Paths have various costs, depths

• Search for assignment– Assign values to variables while

respecting certain constraints– The goal (complete, consistent

assignment) is the important thing

Page 4: CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew

Constraint satisfaction problems (CSPs)

• Definition:– Xi is a set of variables {X1 ,… Xn}

– Di is a set of domains {D1 ,... Dn} one for each variable– C is a set of constraints that specify allowable combinations of

values– Solution is a complete, consistent assignment

• How does this compare to the “generic” tree search formulation?– A more structured representation for states, expressed in a

formal representation language– Allows useful general-purpose algorithms with more power

than standard search algorithms • by eliminating large portions of search space (identifying var/val

combinations that violate constraints).

Page 5: CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew

Example: Map Coloring

• Variables: WA, NT, Q, NSW, V, SA, T • Domains: {red, green, blue}• Constraints: adjacent regions must have different colors

e.g., WA ≠ NT, or (WA, NT) in {(red, green), (red, blue), (green, red), (green, blue), (blue, red), (blue, green)}

Page 6: CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew

Example: Map Coloring

• Solutions are complete and consistent assignments, e.g., WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green

Page 7: CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew

Example: n-queens problem

• Put n queens on an n × n board with no two queens in the same row, column, or diagonal

Page 8: CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew

Example: N-Queens

• Variables: Xij

• Domains: {0, 1}

• Constraints:

i,j Xij = N

(Xij, Xik) {(0, 0), (0, 1), (1, 0)}

(Xij, Xkj) {(0, 0), (0, 1), (1, 0)}

(Xij, Xi+k, j+k) {(0, 0), (0, 1), (1, 0)}

(Xij, Xi+k, j–k) {(0, 0), (0, 1), (1, 0)}

Xij

Page 9: CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew

N-Queens: Alternative formulation

• Variables: Qi

• Domains: {1, … , N}

• Constraints: i, j non-threatening (Qi , Qj)

Q2

Q1

Q3

Q4

Page 10: CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew

Example: Cryptarithmetic

• Variables: T, W, O, F, U, R X1, X2

• Domains: {0, 1, 2, …, 9}• Constraints:

O + O = R + 10 * X1

W + W + X1 = U + 10 * X2

T + T + X2 = O + 10 * F

Alldiff(T, W, O, F, U, R)T ≠ 0, F ≠ 0

X2 X1

Page 11: CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew

Example: Sudoku

• Variables: Xij

• Domains: {1, 2, …, 9}

• Constraints:Alldiff(Xij in the same unit)

Xij