0% found this document useful (0 votes)
14 views

JU Ch5

This document discusses constraint satisfaction problems (CSPs). It defines CSPs as problems where the state is defined by variables that take on values from predefined domains, and the goal is to assign values such that a set of constraints are satisfied. It provides examples of map coloring CSPs and discusses representing CSPs as constraint graphs. It also describes standard search techniques for solving CSPs, including backtracking search and local search, and methods for improving their efficiency like variable ordering heuristics, forward checking, and the min-conflicts heuristic.

Uploaded by

abebemako302
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

JU Ch5

This document discusses constraint satisfaction problems (CSPs). It defines CSPs as problems where the state is defined by variables that take on values from predefined domains, and the goal is to assign values such that a set of constraints are satisfied. It provides examples of map coloring CSPs and discusses representing CSPs as constraint graphs. It also describes standard search techniques for solving CSPs, including backtracking search and local search, and methods for improving their efficiency like variable ordering heuristics, forward checking, and the min-conflicts heuristic.

Uploaded by

abebemako302
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 26

Introduction to Artificial Intelligence

(Comp551)
1

JIMMA UNIVERSITY
JIMMA INSTITUTE OF TECHNOLOGY
DEPARTMENT OF COMPUTING

CHAPTER FIVE
CONSTRAINT SATISFACTION PROBLEMS
Topics we will cover
2

Constraint Satisfaction Problems (CSPs)


Backtracking Search for CSPs
Local Search for CSPs
Constraint Satisfaction Problems (CSPs)
3

 In Standard search problem:


 State is any data structure that supports:
 Successor function,
 Heuristic function, and
 Goal test.
 CSPs are a special kind of problem:
 States defined by values of a fixed set of variables.
 Goal test defined by set of constraints on variable values.
 In Constraint satisfaction problems(CSPs):
 State is defined by variables Xi with values from domain Di.
 Goal Test is a set of constraints specifying allowable
combinations of values for subsets of variables.
 Allows useful general-purpose algorithms with more
power than standard search algorithms.
Example: Map-Coloring (1)
4
 As an example we will consider the map-colouring problem.
 No two adjacent regions have the same colour.

Figure: A map showing the regions of Australia

 Variables: WA, NT, Q, NSW, V, SA, T


 Domains: D = {red,green,blue}
i
 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)}
Example: Map-Coloring (2)
5
 Here we introduce two pieces of important terminology:
 Complete: a complete state is one in which all variables have
been assigned a value.
 Consistent: a consistent state is one that does not violate any
of the specified constraints.

 Solutions are complete and consistent assignments, e.g.,


WA=red, NT=green, Q=red, NSW=green, V=red, SA=blue,
T=green
Example: Map Coloring
6
 Color a map with three colors so that adjacent countries have different
colors ({red, green, blue}.
 Assume that initially region B is colored with Red and Region C with
Blue.
A C variables:
G A, B, C, D, E, F, G
B

?
D
constraints: “no
neighboring regions
?

F
E have the same
?

color”
?

?
Exercise: Coloring Problem
7

Use at most three colors (red, green and blue) to


color the given map?
Constraint Graph
8

 Another way of visualising CSPs is by using a


constraint graph.
 Constraint graph: nodes are variables, arcs are constraints.
 Binary CSP: each constraint relates(links) only two variables.

Figure - The map-coloring problem represented as a constraint graph.


Varieties of CSPs
9
 It is possible to categorise CSPs based on the type of variable
they use and on the size of their domains:
1. Discrete variables
 In a discrete CSP, the variables take on discrete values.
 There are two types of discrete CSP:
 Finite domains: means can take on a limited number of
discrete values.
 For example, the {red,green,blue} domain
 Infinite domains: Some discrete variables can have infinite
domains.
 integers, natural numbers,strings, etc.

2. Continuous variables
 In a continuous CSP, variables can take one from a continuous
range of values.
 For example, real numbers are continuous.
 e.g., start/end times for Hubble Space Telescope observations
Varieties of CSPs
10

 We can also categorise CSPs based on the type of


their constraints.
 There are three types of constraint we can have:
Unary constraints involve a single variable,
 e.g., SA ≠ green
Binary constraints involve pairs of variables,
 e.g., SA ≠ WA

Higher-order constraints involve 3 or more


variables
 The more variables that are involved in a constraint, the
harder the problem is to solve.
 Problems with higher-order constraints are the hardest
class of problems.
Standard Search Formulations
11

In fact, there are two ways of formulating any


search problem:
 Incremental formulation:
 Start with empty state, iteratively assign values.
 Backtracking = depth-first search with one variable assigned per node.
 Complete-state formulation:
 Start with complete state, iteratively change values.
 Local search with min-conflicts is usually effective in practice.

Search Techniques for CSPs


 The search technique that we use for CSPs depends on
what formulation we use:
 Incremental formulation → Backtracking search
 Complete-state formulation → Local search
Backtracking Search
12

 Backtracking Search:
 The most common technique for solving incremental
formulations of CSPs.
 Basically a depth-first search with a single variable assigned at
each level of the tree.
 If no legal assignments are possible then we backtrack to try
other branches of the tree.
 Variable assignments are commutative, i.e., Commutative
simply means that the order of operations does not
matter.
[ WA = red followed by NT = green ] is the same as
[ NT = green followed by WA = red ]
 Only need to consider assignments to a single variable at
each node
 b = d and there are dn leaves
(b=branching factor, d=size of domain, n = number of variables)
Backtracking example (1)
13
Backtracking example (2)
14
Backtracking example (3)
15
Backtracking example (4)
16
Improving Efficiency of Backtracking Search
17

In the description of backtracking search, we did not


address the following questions:
 Which variable to pick at each level?

 In what order should we consider child nodes?


 What are implications of current assignment
for other unassigned variables?
It turns out that:
 These factors all have a big influence on the efficiency of
backtracking search, and
 By making the right choices of variable/value we can make
dramatic improvements in efficiency.
Rules for Improving Efficiency
18

The rules can be summarised as follows:


 MRV (Minimum Remaining Values)
 Most constraining variable
 Least constraining value

MRV (Minimum Remaining Values)


 Choose the variable with the fewest remaining legal
values.
Most Constraining Variable
19

Tie-breaker among most constrained variables.


Most constraining variable:
 Choose the variable with the most constraints on
remaining variables.
Least Constraining Value
20

Given a variable, choose the least constraining


value:
 The one that rules out the fewest values in the
remaining unassigned variables.
Forward Checking
21

Another way to improve the efficiency of


backtracking search is to use a technique
known as forward checking.
With forward checking,
 Each time a variable X is assigned,
 We check each variable Y that is linked by a
constraint to X, and
 Delete from Y’s domain any value that is
inconsistent with the value chosen for X.
Forward Checking
22

 For example, Table below we see the progress of the map-


colouring search for Australia using forward checking.

Table: The forward checking algorithm applied to the Australia map-colouring problem
 Finally we reach a state where we can see that there are no legal values
for SA, which would cause the algorithm to backtrack immediately.
Local search for CSPs
23

 For complete-state formulation we start with complete


states , i.e. all variables assigned.
 Local search techniques typically work with complete states.

 To apply to CSPs:
 Allow states with unsatisfied constraints – start with random state.
 Operators reassign variable values.

 Variable selection: randomly select any conflicted


variable.
 Value selection by min-conflicts heuristic:
 Choose value that violates the fewest constraints.
 i.e., hill-climb with h(n) = total number of violated constraints.
Local Search Example: 4-Queens
24

 States: 4 queens in 4 columns (44 = 256 states)


 Actions: move queen in column
 Goal test: no attacks
 Evaluation: h(n) = number of attacks

 Given random initial state, can solve n-queens in almost


constant time for arbitrary n with high probability
8-Queens Example
1 2
• Use min-conflicts
2 2
heuristic and
2 2
rearrange the
1 1 queens such that
3 3 they are not
2 2 attacking each
2 3 other
1 1
1 1
3 2
2 3
3 3
1 0
2 2
1 1
2 1
Summary
26
 CSPs are a special kind of problem:
 States defined by values of a fixed set of variables.
 Goal test defined by set of constraints on variable values.

 Incremental formulation:
 Start with empty state, iteratively assign values.
 Backtracking = depth-first search with one variable assigned per node.
 Heuristics help significantly:
 MRV (Minimum Remaining Values)
 Most constraining variable
 Least constraining value

 Complete-state formulation
 Start with complete state, iteratively change values.
 Local search with min-conflicts is usually effective in practice.

You might also like