Week 4 - CSP - 's solution

advertisement

CS188 – Week 4 Discussion Note

Nuttapong Chentanez

Constraints Satisfaction Problem (CSP)

Set of variables: X

1

, X

2

, …. , X n

Each variables has a non-empty domain D i

of possible values

Set of constraints: C

1

, C

2

, …., C m involve some subset of variables

Consistent assignment, Complete assignment

Solution = Complete & Consistent assignment

How to solve CSP?

Pick a variable, then pick a value that is consistent, go to the next variable, until all variables are assigned or consistent assignment does not exist. Does the order of variable chosen matter? How many possible assignments (in term of |D i

| )?

Pseudo-Code

CSP-solve(numUnassigned)

If (numUnassigned == 0):

Found = True;

Solution = (X

1

, …., X n

)

Done

Pick an unassigned variable, X i

Pick a consistent value from d i

If (can’t): return

remaining Di

X i

= d i

PruneDomains()

CSP-solve(numUnassigned – 1)

X i

= unassigned

CSP-wrapper()

Set X

1

… X n

to unassigned

Found = False

CSP-solve(n)

Heuristics for solving CSP

Picking variables:

1. Minimum remaining values (MRV) – Pick variable with smallest number of values it can be, that still consistent. Why?

2. Degree Heuristic – Pick variable that involves in largest number of constraints. Why?

Picking value for a variable:

1. Least-constraining value. Pick X i

that rules out fewest choices for neighboring variables in the constraint graph. Why?

Pruning (Constraint Propagation) – Early detection of failure that can be implied (cheaply) from current assignment of variables.

Forward Checking:

When assign X i

, look at each unassigned variable X j that is connected to X i

, delete the value of X j

that inconsistent with the chosen value of X i.

If any empty, fail immediately. If one value left, assign the value to

X j

and then check the neighbors of X j

. When would this be useful?

Arc Consistency for (X i

Xj):

(X i

X j

) is consistent if for every value of X i

there is some value of X j

that is consistent

What’s the cost of checking if (X i

X j

) is consistent, in terms of |D i

|, |D j

| & how to check?

Does X i

X j

implies X j

X i

?

This improves the performance of the algorithm significantly. A partial assignment is arc-consistent if all arcs are consistent. k-consistency of a CSP:

If for any consistent assignment to a subset of size k-1 of variables, it’s possible to assign the value of the k th variable consistently. How to check?

Strongly k-consistent, if is 1..k consistent. If we know a CSP is strongly n-consistent, how to solve CSP, at what cost?

Can use k-consistent to reduce domain, but can be costly

Problems:

Sample CSP Problem

(Modified from a homework from AI class of U of

Pittsburgh)

Each variable can be {0..9}. The edge between variables (a,b) with label C indicates the constraints (a mod C == b mod C) List the variables, domain, and binary constraints:

List the remaining possible values of each variable that can be inferred after the assignment of {x = 2, y = 0, t

= 0} by

1.

Forward checking

2.

Arc consistency

Find one solution to this CSP

Converting Arbitrary Constraints to Binary

Constraints

Cryptography

SEND

MORE

====

MONEY

Write the variables, the domains and the constraint graph. Annotate each constraints.

Convert this problem into binary constraints. Ideas?

How many variables you need to introduce? What are their domains? Constraints?

Download