Docsity

Constraint Satisfaction Problems: Understanding and Solving CSPs, Slides of Artificial Intelligence

Partial preview of the text

Download Constraint Satisfaction Problems: Understanding and Solving CSPs and more Slides Artificial Intelligence in PDF only on Docsity!

Constraint Satisfaction Problems

Chapter 5

Chapter 5

1

Outline

CSP examples

Backtracking search for CSPs

Problem structure and problem decomposition

Local search for CSPs

Chapter 5

2

Australia Western Example: Map-Coloring

Territory Northern

Australia South

Queensland

New South Wales

Victoria

Tasmania

Variables

W A

N T

Q

N SW

V

SA

T

Domains

D

i

=

red, green, blue

Constraints

: adjacent regions must have different colors

e.g.,

W A

N T

(if the language allows this), or

W A, N T

red, green

red, blue

green, red

green, blue

Chapter 5

4

Example: Map-Coloring contd.

Australia Western

Territory Northern

Australia South

Queensland

New South Wales

Victoria

Tasmania

Solutions

are assignments satisfying all constraints, e.g.,

W A

(^) red, N T

green, Q

(^) red, N SW

(^) green, V

red, SA

blue, T

(^) green

Chapter 5

5

docsity.co

Varieties of CSPs

Discrete variables

finite domains; size

d ⇒ O ( d n )

complete assignments

e.g., Boolean CSPs, incl. Boolean satisfiability (NP-complete)

infinite domains (integers, strings, etc.)

e.g., job scheduling, variables are start/end days for each job

need a

constraint language

, e.g.,

StartJob

1

  • 5

StartJob

3

linear

constraints solvable,

nonlinear

undecidable

Continuous variables

e.g., start/end times for Hubble Telescope observations

linear constraints solvable in poly time by LP methods

Chapter 5

7

Varieties of constraints

Unary

constraints involve a single variable,

e.g.,

SA

green

Binary

constraints involve pairs of variables,

e.g.,

SA

W A

Higher-order

constraints involve 3 or more variables,

e.g., cryptarithmetic column constraints

Preferences

(soft constraints), e.g.,

red

is better than

green

often representable by a cost for each variable assignment

constrained optimization problems

Chapter 5

8

Real-world CSPs

Assignment problems

e.g., who teaches what class

Timetabling problems

e.g., which class is offered when and where?

Notice that many real-world problems involve real-valued variablesFloorplanningFactory schedulingTransportation schedulingSpreadsheetsHardware configuration

Chapter 5

10

Standard search formulation (incremental)

♦ States are defined by the values assigned so far Let’s start with the straightforward, dumb approach, then fix it

Initial state

: the empty assignment,

Successor function

: assign a value to an unassigned variable

that does not conflict with current assignment. ⇒

fail if no legal assignments (not fixable!)

Goal test

: the current assignment is complete

  1. Every solution appears at depth1) This is the same for all CSPs!

n

with

n

variables

use depth-first search

    1. Path is irrelevant, so can also use complete-state formulation

b

= (

n

`

d

at depth

`

, hence

n

! d

n

leaves!!!!

Chapter 5

11

Backtracking search

function

Backtracking-Search

( csp

)

returns

solution/failure

return

Recursive-Backtracking

( { }

, (^) csp

)

function

Recursive-Backtracking

( assignment

, (^) csp

)

returns

soln/failure

if

assignment

is complete

then return

assignment

var

(^) ←

(^) Select-Unassigned-Variable

( Variables

[ csp

], (^) assignment

, (^) csp

)

for each

value

in

Order-Domain-Values

( var

, (^) assignment

, (^) csp

)

do

if

value

is consistent with

assignment

given

Constraints

[ csp

] then

add

{ var

=

value

}

to

assignment

result

(^) ←

(^) Recursive-Backtracking

( assignment

, (^) csp

)

if

result

6

failure

then return

result

remove

{ var

=

value

}

from

assignment

return

failure

Chapter 5

13

Backtracking example

Chapter 5

14

Backtracking example

Chapter 5

16

Backtracking example

Chapter 5

17

Minimum remaining values

Minimum remaining values (MRV):

choose the variable with the fewest legal values

Chapter 5

19

Degree heuristic

Degree heuristic: Tie-breaker among MRV variables

choose the variable with the most constraints on remaining variables

Chapter 5

20