Constraint Satisfaction Problems: Definitions and Naive Search - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Constraint Satisfaction Problems: Definitions and Naive Search

Description:

Map Colouring is a typical 'Constraint Satisfaction Problem (CSP) ... Can discard the map, and just use the graph. Edge means 'must have a different colour than' ... – PowerPoint PPT presentation

Number of Views:180
Avg rating:3.0/5.0
Slides: 28
Provided by: andrew490
Category:

less

Transcript and Presenter's Notes

Title: Constraint Satisfaction Problems: Definitions and Naive Search


1
Constraint Satisfaction ProblemsDefinitions and
Naive Search
  • G51IAI Introduction to AI
  • Andrew Parkes
  • http//www.cs.nott.ac.uk/ajp/

2
Map Colouring
  • Given a map of countries
  • Assign a colour to each country
  • such that
  • IF two countries share a border THEN they
    are given different colours
  • We can only use a limited number of colours
  • Alternatively, we must use the minimal possible
    number of colours

3
Map Colouring Example
  • Consider some square countries
  • How many colours are needed?

4
Example 3 colours?
Take the 3 colours to be red, green, blue
How would you be sure that you have not missed
out some possible 3 colouring?
Need some complete search method!
NO COLOUR LEFT!
5
Example 4 colours?
WITH JUST ONE MORE COLOUR IT IS POSSIBLE
NO COLOUR LEFT!
6
Motivations
  • Map Colouring is a specific problem
  • so why care?
  • Map Colouring is a typical Constraint
    Satisfaction Problem (CSP)
  • CSPs have many uses
  • scheduling
  • timetabling
  • window (task pane) manager in a GUI
  • and many other common optimization problems with
    industrial applications

7
Scope
  • Russell-Norvig (AIMA) Chapter 5
  • We will just cover parts of sections
  • 5.1 Constraint Satisfaction Problems
  • 5.2 Backtracking Search for CSP, etc
  • The intention of this part of the module is only
    to give the a brief summary of the basic ideas of
    CSPs

8
Potential Follow-up
  • Module G5BAIP Artificial Intelligence
    Programming
  • http//www.cs.nott.ac.uk/rxq/teaching.htmg5baip
  • CSPs and advanced search methods for CSPs
  • Constraint Programming
  • A different programming paradigm
  • you tell it what to solve, the system decides
    how to solve
  • a program to solve Sudoku can be only 20 lines of
    code!
  • e.g. constraints on each row that all numbers in
    a row are different is just forall( j in
    1..9 ) alldifferent( all(i in 1..9) posi,j )
  • Very different from the usual paradigms
  • Procedural (Fortran, Pascal, C)
  • Object-Oriented (C, Java, C)
  • Functional (Lisp, ML, Haskell)
  • Commercialised by ILOG, www.ilog.com, and others

9
From Maps to CSPs
  • Will convert the map colouring into general idea
    of a CSP
  • Assign values
  • such that
  • the assigned values satisfy some constraints

10
Map Colouring
  • Firstly add some labels

11
Map Colouring Constraints
  • Graphs are more common than maps so convert to
    a graph
  • Edge means share a border

12
Graph Colouring
  • Can discard the map, and just use the graph
  • Edge means must have a different colour than

13
Graph 3-Colouring
  • Node, or variable, must be given a value from
    the set of colours r, g , b
  • E.g. B b
  • Edge between two nodes ? only allowed pairs of
    values from the set (r,g), (r,b), (g, r),
    (g, b), (b, r), (b, g)

14
From 3-colouring to CSP
  • Generalise from the form of the 3-colouring
    problem to a
  • Constraint Satisfaction Problem (CSP)
  • Each node, or variable, must be assigned a
    value from a given fixed set of allowed values
  • usually called the domain, D
  • Edge between two nodes ? only allowed pairs of
    values from some given fixed set of allowed pairs
    of values
  • the edge is called a constraint
  • and is synonymous with a set of allowed pairs

15
Constraints Explicit vs. Implicit
  • Edge between two nodes is a constraint
  • A constraint is an explicit set of pairs of
    allowed pairs of values
  • Usually, represented implicitly by means of a
    mathematical constraint such as
  • x ! y
  • x y 2
  • x 2 lt y

16
Solving a CSP
  • We can take the domains to be finite
  • Suppose, have n variables and, each variable is
    given a value from a set D
  • Suppose size of D is d
  • Number of possible assignments is d
    d d ... d dn
  • Exponential in problem size
  • Combinatorial Explosion Again!

17
Generate-and-Test
  • Generate all possible assignments
  • Test each assignment to see if it satisfies all
    the constraints
  • This is very inefficient
  • We can do a lot better

18
Partial Assignments
  • Total assignment
  • every variable is assigned a value
  • Partial Assignment
  • some, none, or all are assigned values

19
Search Methods
  • If want a complete search method then it is
    standard to use depth-first search with partial
    assignments
  • Work with Partial Assignments
  • Start with the empty assignment
  • Generate children by adding a value for one more
    variable
  • Analogy path-finding we started with the
    empty path, and then added one more segment at
    each time
  • We already did this with the map colouring at the
    start of the lecture!

20
Backtracking Search
  • In the DFS we generated all children
  • This has the disadvantage of needing extra space
    to store them
  • e.g. suppose that have blocks world with 1000
    blocks
  • Backtracking search delay the creation of the
    children until they are needed
  • instead just remember that we also need to create
    them

21
Backtracking Search Animation
  • Nodes are not created until they are ready to be
    used to reduce memory usage

A
2nd child of A is not created immediately,just
remember that it is there
B
E
D
C
22
Can we 2-colour a Triangle?
  • Can we assign values from r , g with the
    following variables and constraints?
  • Obviously not!
  • But how can we see this using search?

23
Can we 2-colour a Triangle?
  • Can we assign values from r , g to nodes A,
    B, and C
  • Generate-and-Test Colour nodes in the order,
    A, B, C

A
Ag
Ar
All the attempts to generate a satisfying
assignment fail
B
Br
Bg
Etc, etc
C
C
Cr
Cr
Cg
Cg
Fail
Fail
Fail
Fail
24
Early Failure
  • Suppose a partial assignment fails i.e. violates
    a constraint
  • Whatever values we eventually give to the so-far
    un-assigned variables the constraint will stay
    violated, and the solution will fail
  • In the backtracking search
  • as soon as a constraint is violated by the
    current partial assignment then we can prune the
    search

25
Can we 2-colour a Triangle?
  • Naive Backtracking Search
  • Backtracking with pruning of bad partial
    assignments

A
Ag
Ar
B
Br
Bg
C
Fail
Cr
Cg
Did not have to try values for C
Fail
Fail
26
Summary
  • Constraint Satisfaction Problems
  • Motivations
  • Example Map Colouring
  • Informal Definition
  • Combinatorial Explosion
  • Partial Assignments
  • DFS and naive backtracking search

27
Questions?
Write a Comment
User Comments (0)
About PowerShow.com