Search in Complex Environments
Search in Complex Environments
Search in Complex Environments
com/c/EDULINEFORCSE
STUDENTS
MODULE 3
SEARCH IN COMPLEX
ENVIRONMENTS
ADVERSARIAL SEARCH
• In artificial intelligence, deep learning, machine learning,
adversarial search is basically a kind of search in which one can
trace the movement of an enemy or opponent.
• Adversarial search is a method applied to a situation where you are
planning while another actor prepares against you.
• Your plans, therefore, could be affected by your opponent’s
actions. The term “search” in the context of adversarial search
refers to games, at least in the realm of Artificial Intelligence.
• Adversarial search problems typically exist in two-player games
where the players’ actions alternate.
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 2
GAME TREE
• A game tree is a tree where nodes of the tree are the game states
and Edges of the tree are the moves by players. Game tree involves
initial state, actions function, and result Function.
TECHNIQUES REQUIRED TO GET THE BEST OPTIMAL SOLUTION
• There is always a need to choose those algorithms which provide
the best optimal solution in a limited time. So, we use the following
techniques which could fulfill our requirements:
Pruning: A technique which allows ignoring the unwanted portions
of a search tree which make no difference in its final result.
Heuristic Evaluation Function: It allows to approximate the cost
value at each level of the search tree, before reaching the goal
node.
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 7
• INITIAL STATE (S0): The top node in the game-tree represents the initial
state in the tree and shows all the possible choice to pick out one.
• PLAYER (s): There are two players, MAX and MIN. MAX begins the
game by picking one best move and place X in the empty square box.
• ACTIONS (s): Both the players can make moves in the empty boxes
chance by chance.
• RESULT (s, a): The moves made by MIN and MAX will decide the
outcome of the game.
• TERMINAL-TEST(s): When all the empty boxes will be filled, it will be
the terminating state of the game.
• UTILITY: At the end, we will get to know who wins: MAX or MIN, and
accordingly, the price will be given to them. (-1): If the PLAYER loses.
(+1): If the PLAYER wins. (0): If there is a draw between the PLAYERS.
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 9
• In this algorithm two players play the game, one is called MAX and
other is called MIN.
• MAX will select the maximized value
• MIN will select the minimized value.
• The min-max algorithm performs a depth-first search algorithm for
the exploration of the complete game tree.
• The min-max algorithm proceeds all the way down to the terminal
node of the tree, then backtrack the tree as the recursion
Search strategies
Consider the game tree
• The nodes are MAX nodes, in which it is MAX’s turn to move and the
nodes are MIN nodes. The terminal states show the utility values for
MAX.
• The possible moves for MAX at the root node are labeled a1, a2, a3. the
possible replies to a1 for MIN are b1, b2, b3 and so on. This game ends
after one move each by MAX and MIN.
• Given a game tree, the optimal strategy can be determined by
examining the min-max value of each node, which we write as minmax-
value (n).
• The minmax-value of a node is the utility for MAX of being in the
corresponding state.
• The minmax-value of a terminal state is just its utility.
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 14
• Suppose maximizer takes first turn which has worst-case initial value
= -infinity, and minimizer will take next turn which has worst-case
initial value = +infinity.
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 17
• Step 2: Now, first we find the utilities value for the Maximizer, its
initial value is -∞, so we will compare each value in terminal state
with initial value of Maximizer and determines the higher nodes
values. It will find the maximum among the all.
• For node D: max(-1, -∞) => max(-1,4)= 4
• For Node E : max(2, -∞) => max(2, 6)= 6
• For Node F :max(-3, -∞) => max(-3,-5)= -3
• For node G: max(0, -∞) = max(0, 7) = 7
• Step 3: In the next step, it's a turn for minimizer, so it will compare
all nodes value with +∞, and will find the 3rd layer node values.
• For node B= min(4,6) = 4
• For node C= min (-3, 7) = -3
• Step 4: Now it's a turn for Maximizer, and it will again choose the
maximum of all nodes value and find the maximum value for the
root node.
• In this game tree, there are only 4 layers, hence we reach
immediately to the root node, but in real games, there will be more
than 4 layers.
• For node A max(4, -3)= 4
The two-parameter
• Alpha: The best (highest-value) choice we have found so far at
any point along the path of Maximizer. The initial value of alpha is
-∞.
• Beta: The best (lowest-value) choice we have found so far at any
point along the path of Minimizer. The initial value of beta is +∞.
• The Alpha-beta pruning to a standard minimax algorithm returns
the same move as the standard algorithm does, but it removes all
the nodes which are not really affecting the final decision but
making algorithm slow. Hence by pruning these nodes, it makes
the algorithm fast.
dcc
bb
CONSTRAINT SATISFACTION
PROBLEMS(CSP)
• Consider a Sudoku game with some numbers filled initially in some
squares. You are expected to fill the empty squares with numbers
ranging from 1 to 9 in such a way that no row, column or a block has a
number repeating itself.
• This is a very basic constraint satisfaction problem.
• You are supposed to solve a problem keeping in mind some constraints.
The remaining squares that are to be filled are known as variables, and
the range of numbers (1-9) that can fill them is known as a domain.
• Variables take on values from the domain. The conditions governing
how a variable will choose its domain are known as constraints.
• A constraint is a restriction.
There are many real-life problems that require to give a decision in
the presence of constraints:
flight / train scheduling;
scheduling of events in an operating system;
staff rostering at a company;
course time tabling at a university …
• Such problems are called Constraint Satisfaction Problems (CSPs).
• A solution to a CSP is an assignment of values to the variables
which satisfies all the constraints simultaneously
CSP EXAMPLE
Variables
X = {X1, X2, X3}
Domains
D(X1) = {1,2}, D(X2) = {0,1,2,3}, D(X3) = {2,3}
Constraints
X1 > X2 and X1 + X2 = X3 and X1 ≠ X2 ≠ X3 ≠ X1
Solution
X1 = 2, X2 = 1, X3 = 3
• Suppose you have a very simple CSP with the variables A, B, and C,
each with domain {1,2,3,4}. Suppose the constraints
are A<B and B<C. A possible search tree is
MODEL OF A CSP
• A model of a CSP is an assignment of values to all of its variables
that satisfies all of its constraints.
V = {V1}
Dom(V1) = {1,2,3,4}
C = {C1,C2}
• C1: V1 ≠ 2
• C2: V1 > 1
All models for this CSP: {V1 = 3}
{V1 = 4}
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 46
Scope of a constraint
• The scope of a constraint is the set of variables that are involved in
the constraint
Examples:
• V2 ≠ 2 has scope {V2}
• V1 > V2 has scope {V1,V2}
• V1 + V2 + V4 < 5 has scope {V1,V2,V4}
CONSTRAINT PROPAGATION
• Constraint propagation (filtering algorithm) means the process of
applying filtering to the constraints in the CSP instance at hand.
• As filtering one constraint can reduce the domains of its variables,
it can trigger further reduction when filtering another constraint
that also involves the reduced-domain variables.
• Thus a constraint can be filtered multiple times during the
constraint propagation process.
• Usually the process is run to the end, meaning until no more
reduction happens in filtering any of the constraints. Or if this takes
too long, then until some resource usage limit is exceeded.
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 49
Example:
• When 𝐷 (x)={1,2,4} and 𝐷 (y)={1,2,5}, filtering the
constraint x=y optimally gives to domains 𝐷 (x)={1,2} and
𝐷 (y)={1,2}. This is because the solutions of the constraint are
x=1,y=1 and x=2,y=2.
• constraint propagation: Using the constraints to reduce the
number of legal values for a variable, which in turn can reduce the
legal values for another variable, and so on.
BB
Backtracking algorithms
• Explore search space via DFS but evaluate each constraint as soon
as all its variables are bound.
• Any partial assignment that doesn’t satisfy the constraint can be
pruned.
• A partial assignment is one that assigns values to only some of the
variables