Professional Documents
Culture Documents
UNIT – III
Constraint Satisfaction problems-
Backtracking search for CSP’s,
Local search for CSP Game Playing:
Adversial search,
Games,
Minimax algorithm,
optimal decisions in multiplayer games,
Alpha-Beta pruning,
Evaluation functions,
cutting of search.
Constraint Satisfaction problems
Constraint satisfaction is a technique where a problem is solved when its values satisfy
certain constraints or rules of the problem.
Formally speaking, a constraint satisfaction problem (or CSP) is defined by a set of
Variables XI, X2,. . . , Xn, and a set of constraints, C1, C2,…..Cm.
Each variable Xi has a nonempty domain Di of possible values.
Each constraint Ci involves some subset of the variables and specifies the allowable
combinations of values for that subset.
A state of the problem is defined by an assignment of values to some or all of the
variables, {Xi = vi, Xj = vj, . . .).
In constraint satisfaction, domains are the spaces where the variables reside, following
the problem specific constraints.
Solving Constraint Satisfaction Problems
Constraint satisfaction includes those problems which contains some constraints while
solving the problem. CSP includes the following problems:
Graph Coloring
Sudoku Playing
n-queen problem
Latin square Problem etc.
1. Graph Coloring Problem:-
We have been given a graph and we are asked to color all vertices with the ‘M’ number
of given colors, in such a way that no two adjacent vertices should have the same
color.
It it is possible to color all the vertices with the given colors then we have to
output the colored result, otherwise output ‘no solution possible’.
N-queens Problem Solution
STEP-1 STEP-2
Cryptarithmetic problem
Backtracking search for CSP’s
The term backtracking search is used for a depth-first search that chooses values for one
variable at a time and backtracks when a variable has no legal values left to assign. The
algorithm is shown in Figure 5.3.
Propagating information through constraints
Graph Coloring Problem
We have been given a graph and we are asked to color all vertices with the ‘M’ number of given colors, in
such a way that no two adjacent vertices should have the same color.
It it is possible to color all the vertices with the given colors then we have to output the colored result,
otherwise output ‘no solution possible’.
The least possible value of ‘m’ required to color the graph successfully is known as the chromatic
number of the given graph.
Graph Coloring Using Backtracking Algorithm
That was the complete workflow of the minimax two player game.
Properties of Mini-Max algorithm:
Complete- Min-Max algorithm is Complete. It will definitely find a solution (if exist), in
the finite search tree.
Optimal- Min-Max algorithm is optimal if both opponents are playing optimally.
Time complexity- As it performs DFS for the game-tree, so the time complexity of Min-
Max algorithm is O(bm), where b is branching factor of the game-tree, and m is the
maximum depth of the tree.
Space Complexity- Space complexity of Mini-max algorithm is also similar to DFS which
is O(bm).
Limitation of the minimax Algorithm:
The main drawback of the minimax algorithm is that it gets really slow for complex
games such as Chess, go, etc.
This type of games has a huge branching factor, and the player has lots of choices to
decide. This limitation of the minimax algorithm can be improved from alpha-beta
pruning .
TIC-TAC-TOE GAME Solution using Minmax
Optimal decisions in multiplayer games
Many popular games allow more than two players. Let us examine how to extend the minimax idea to
multiplayer games.
First, we need to replace the single value for each nocle with a vector of values. For example, in a three-
player game with players A, B, and C, a vector (vA, vB, vc) is associated with each node.
The next step is to modify ALPHA-BETA-SEARCH so that it will call the heuristic EVAL function
when it is appropriate to cut off the search.
The TERMINAL-TIEST with the following line:
if CUT0FF-TEST(state, depth) then return EVAL(state)
We also must arrange for some bookkeeping so that the current depth is incremented on
each recursive call.
The most straightforward approach to controlling the amount of search is to set a fixed
depth limit, so that CUT0FF-TEST(state, depth) returns true for all depth greater than some
fixed depth d.
(It must also return true for all terminal states, just as TERMINAL-TEST did.)
The depth d is chosen so that the amount of time used will not exceed what the rules of
the
game allow.
The horizon effect is more difficult to eliminate. It arises when the program is facing a move
by the opponent that causes serious damage and is ultimately unavoidable.
THANK
YOU