0% found this document useful (0 votes)
44 views21 pages

Understanding Constraint Satisfaction Problems

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

Understanding Constraint Satisfaction Problems

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

Previous Search Problems

• Search-Based Problem Solving:


– Focuses on navigating a state space, where each state may or may not represent a partial
or complete solution.

– Heuristics and search strategies are used to find paths leading to a goal state.

• Constraint Satisfaction Problem:


– Involves systematically assigning values to variables while satisfying all constraints.

– Constraints guide the process to prune inconsistent paths early, making the search space
more structured and manageable.
Constraint Satisfaction Problem
• A constraint satisfaction problem (or CSP) has three components V, D, C
– V is defined by a set of variables, X1, X2, …, Xn
– C is a set of constraints, C1, C2, …, Cm
– Each variable Xi has a nonempty domain Di of possible values.
– Each constraint Ci consists of a pair <scope, rel>, where scope is a tuple of
variables and rel is the relation, either represented explicitly or abstractly.
– X1 and X2 both have the domain {A, B}
– <(X1, X2), X1 ≠ X2>
– <(X1, X2), (A, B)>
Constraint Satisfaction Problem
• Each state in a CSP is defined by an assignment of values to some or all of the
variables.

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


legal assignment.

• A complete assignment is one in which every variable is assigned.

• A solution to a CSP is consistent and complete assignment.

• Allows useful general-purpose algorithms with more power than standard


search algorithms.
• V = {WA, NT, SA, Q, NSW, V, T}

• D = {red, green, blue}

• C = {adjacent nodes should not have


same color}
– E.g. WA ≠ NT
– E.g: (WA, NT) = {(red, green), (red,
blue), (green, red), …}

• Constraint graph: Nodes are


variables, arcs are constraints

• Binary CSP: Each constraint relates


two variables.
Types of Constraint
• 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


Backtracking Search for CSPs
Improving Backtracking Efficiency
• General-purpose methods can give huge gains in speed:
– Which variable should be assigned next?

– In what order should its values be tried?

– Can we detect inevitable failure early?


Minimum remaining value
• Choose the variable with the fewest legal values
Most Constraining Variable

• Choose the variable with the most constraints on remaining variables.


Least Constraining Value

• Given a variable to assign, choose the least constraining value:


– The one that rules out the fewest values in the remaining variables
Forward Checking (Filtering)
• Idea
– Keep track of remaining legal values for unassigned variables

– Terminate search when any variable has no legal values


Map Coloring (Forward Checking / Filtering)

WA NT Q NSW V SA T

Initial domains RGB RGB RGB RGB RGB RGB RGB

After WA = red R GB RGB RGB RGB GB RGB

After Q = green R B G RB RGB B RGB

After V = blue R B G R B RGB

After V = G R B G R G
Cryptarithmetic Problem
• Type of Constraint Satisfaction
S E N D
Problem
+ M O R E

• Constraints
M O N E Y
– No two letters have same value

– Sum of digits must be as shown in


problem 9 5 6 7

– No leading zeros are allowed + 1 0 8 5

– Digits that can be assigned to a


1 0 6 5 2
word/alphabet (0-9) range
N-Queen Problem
• Type of Constraint Satisfactory Problem in AI

• ‘NxN’ square grid board

• ‘N’ Queens needs to be placed on them

• Following constraints needs to be satisfied


– No row should contain more than one queen

– No column should contain more than one queen

– No diagonal should contain more than one queen

– There should be no row/column without any queen


4-Queen Problem (Backtracking)

Q1 Q1 Q1 Q1

………………
………………
Adversarial Search
• Adversarial search in AI is a type of search strategy used to make optimal
decisions in situations where there is an opponent or adversary, such as in two-
player games (e.g., chess, checkers).

• The goal is to find the best possible move for a player while considering that
the opponent is trying to counteract and minimize that player's success.

• Perfect decision (e.g. Chess, Tic-Tac-Toe)

• Imperfect decision (e.g. Card game)


Minimax Search Algorithm
• Consider the following two
MAX
player game tree in which the
static scores are given from the
MIN
first players point of view.

• Apply the Minimax search


MAX
algorithm and compute the value
of the root of the tree.

• Also find the most convenient


10 9 14 18 5 4 50 3
path for Max Node.
Minimax Search Algorithm
• Generate the whole game tree to leaves
• Apply utility (payoff) function to leaves 10 MAX

• Uses DFS for expanding the tree


10 5 MIN
• Back-up values from leaves toward the
root:
– a Max node computes the maximum value
14
18 5 50 MAX
10
from its child values
– a Min node computes the minimum value
from its child values

• When value reaches the root: optimal


10 9 14 18 5 4 50 3
move is determined.
Alpha Beta Pruning Algorithm
• The problem with minimax search is that the number of game states it has to
examine is exponential in the number of moves.
Alpha Beta Pruning Algorithm
• Alpha(α) – Beta(β) proposes to find the optimal
path without looking at every node in the game 10 MAX(α)
tree.

• Max contains Alpha(α) and Min contains 10 5 MIN(β)


Beta(β) bound during the calculation.

• In both Min and Max node, we return when α


>=β which compares with its parent node only. 10 14 5 MAX(α)

• Both minimax and Alpha(α) – Beta(β) cut-off


give same path.

• Alpha(α) – Beta(β) gives optimal solution as it


10 9 14 18 5 4 50 3
takes less time to get the value for the root node.
Exercise

You might also like