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

CSP

AI notes having constraints
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

CSP

AI notes having constraints
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

ARTIFICIAL INTELLIGENCE

Department of Computer Science and Engineering

Indian Institute of Information Technology, Ranchi


OUTLINE
Constraint Satisfaction Problem (CSP)
What is CSP?
Constraint graph
Variety of CSPs
Variety of Constraints
Why CSP solvers needed?
Different Solutions for CSP
Backtracking Search
Improving Backtracking Search
Propagating Constraints
Arc Consistency
CONSTRAINT SATISFACTION
PROBLEMS(CSPS)
Standard Search Problem:
⚫ State is a “Black Box” – any old data structure
⚫ That supports goal test, evaluation, successor

CSP
⚫ 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 values
Simple example of formal-representation language
Allows useful general-purpose algorithms with more power
than standard search algorithms.
CONSTRAINT SATISFACTION 4

PROBLEMS (CSPS)
A Constraint satisfaction problem consists of three components X, D, C:

X is a set of variables, {X1,X2,…..Xn}

*
D is a set of domains, {D1,D2,…..Dn}
C is a set of constraints that specify allowable combination of values.
Each constraint is represented as Ci=(Scope, Relation)

Each domain Di consists of a set of allowable values, {v1,v2,v3….vk}, for


variable Xi.

A state of the problem is defined by an assignment of values to some or


all of the variable, {Xi = vi, Xj = vj ……)
CONSTRAINT SATISFACTION 5

PROBLEMS (CSPS)
A solution to a CSP is a complete assignment that satisfies all the constraints.

An assignment that does not violate any constraints is called consistent or legal

*
Assignment.

A complete assignment is one in which every variable is mentioned.

Partial assignment means that it is an assignment only to a subset of the variable.


EXAMPLE: MAP COLORING PROBLEM
6

Colouring each region


of a map in such a way that
No neighboring regions

*
have the same color.
7

EXAMPLE SOLUTION

*
8

WHY CSP SOLVERS NEEDED?

*
9

WHY CSP SOLVERS NEEDED?

In regular state-space search we can only ask: is this


specific state a goal? No? What about this one?

*
With CSPs, once we find out that a partial assignment is
not a solution, we can immediately discard further
refinements of the partial assignment.
10

CONSTRAINT GRAPH

*
11

VARIETIES OF CSPS

*
12

VARIETIES OF CONSTRAINS

*
REAL WORLD CSPS 13

*
GENERAL FORM OF THE CSPS 14

Many problems in AI can be considered as problems of the constraint satisfaction, in


which the goal state satisfies a given set of constraints.

*
CSPs can be solved by any search strategies.
CSP basic procedure:
1. Until a complete solution is found or until all the paths have led to lead ends, do select an unexpanded
node of the search graph
2.The constraints inference rules are applied to the selected node to generate all the possible new
constraints.
3. If the set of constraints contains a contradiction, then it is reported that this path is dead end.
4. If the set of constraints describes a complete solution has been found, then the rules are applied to
generate.
5. If neither a constraint nor a complete solution has been found, then the rules are applied to generate new
partial solutions. These partial solutions are inserted into the search graph.
STANDARD SEARCH FORMULATION
15

*
BACKTRACKING SEARCH 16

CSPs can be solved by a specialized version of the depth-first


search.
Key intuitions:

*
⚫ We can build up to a solution by searching through the space of
partial assignments though the single variable assignment.
⚫ Order in which we assign the variables does not matter
Eventually they all have to be assigned.
⚫ If during the process of building up a solution we falsify a constraint,
we can immediately reject all possible ways of extending the current
partial assignment and Backtrack.
BACKTRACKING SEARCH (CONTI..) 17

Idea 1: One variable at a time


⚫ Variable assignments are commutative, so fix ordering.
i.e.[WA= red then NT= green] same as [NT=green then WA=red]
⚫ Only need to consider assignment to a single variable at each step.

*
Idea 2: Check constraints to go
-- i.e. consider only values which do not conflict with
previous assignments.
-- Might have to do some computation to check the
constraints, then we get one step at a time towards the goal, i.e.
Incremental goal test.

Backtracking search is a basic uninformed search algorithm for solving


CSPs.
Can solve n-queen for n=25 or n=100.
BACKTRACKING SEARCH (CONTI..) 18

The term Backtrack search is used for Depth-first search


that chooses values for one variable at a time and
backtracks when no legal values left to assign.

*
BACKTRACKING SEARCH (CONTI..)
19

*
BACKTRACKING SEARCH (CONTI..)
20

*
BACKTRACKING SEARCH (CONTI..)
21

*
BACKTRACKING SEARCH
ISSUES….

Plain backtracking is an uninformed


algorithm
⚫ Do not expect it to be very effective for large
problems
We cure the poor performance of uninformed
search algorithms by supplying them with
domain-specific heuristics functions derived
from our knowledge of the problem
BACKTRACKING SEARCH
(CONTI..) 23

*
BACKTRACKING SEARCH (CONTI..)
24

*
BACKTRACKING SEARCH (CONTI..)
25

*
BACKTRACKING SEARCH
(CONTI..) 26

*
27

IMPROVING BACKTRACKING SEARCH

We can solve CSPs efficiently without such

*
domain-specific knowledge
VARIABLE ORDERING 28

(WHICH CITY TO COLOR FIRST?)

By default Backtracking algorithms simply selects the next unassigned variables

*
in the order given by the variable list. However, the static ordering seldom results
in the most efficient search. Also, called as Fail-first heuristic, because it picks a
variable i.e. most likely to cause a failure soon, thereby pruning the tree.
VARIABLE ORDERING 29

(WHICH CITY TO COLOR FIRST?)

*
The MRV heuristic does not help at all in choosing the first region to
color, because initially every region has three legal colors.

Degree heuristic attempts to reduce the branching factor on future


choices by selecting the variable that involved in the largest number of
constraints on other unassigned variables.
VARIABLE ORDERING
30
(WHICH CITY TO COLOR FIRST?)
Degree heuristic attempts to reduce the branching factor on future choices by
selecting the variable that involved in the largest number of constraints on
other unassigned variables.

*
VALUE ORDERING 31

(WHICH COLOR TO CHOSE FIRST?)


Least Constrained Value:

*
Once the variable has been selected the algorithm must decide on
the order in which to examine its value. It prefers the value that
eliminate the fewest choices for the neighboring in constraint
graph.
VALUE ORDERING 32

(WHICH COLOR TO CHOSE FIRST?)


Least Constrained Value:

*
Thank You!!

You might also like