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

Search Algorithms Part 2

Uploaded by

esraaaboelkhair8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Search Algorithms Part 2

Uploaded by

esraaaboelkhair8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

1.

Search Part II
Created @October 14, 2024 8:42 PM

Tags

Informed and Uninformed Search


Search Process
Definition: The process of searching for a sequence of actions that leads to a
goal.

Functionality: A search algorithm takes a problem as input and returns a


solution as an action sequence.

Execution Phase: Once a solution is found, the recommended actions can be


executed.

Uninformed Search Algorithms (Blind Algorithms)


Characteristics:

Algorithms are provided no information beyond the problem's definition.

Examples include Depth-First Search (DFS) and Breadth-First Search


(BFS).

Random-Trace Pathfinding
Description:

The agent moves towards the goal until it encounters an obstacle.

Upon hitting an obstacle, the agent randomly chooses to trace around it in


a clockwise or counterclockwise manner.

Limitations:

The Random-Trace algorithm is limited in the variety of paths it can


explore.

1. Search Part II 1
It may only pick from a few paths, despite the existence of many possible
routes from the start to the goal.

This makes it an incomplete algorithm, as it may not find a path in a finite


time for certain maps.

Informed Search Algorithms


Characteristics:

Utilize problem-specific knowledge beyond the definition of the problem.

Generally more efficient than uninformed strategies in finding solutions.

Greedy Best-First Search Algorithm


Definition:

A type of best-first search where nodes are selected for expansion based
on an evaluation function f(n).

Evaluation Function:

f(n) is viewed as a cost estimate; the node with the lowest evaluation is
expanded first.

Heuristic Function:

Most best-first algorithms incorporate a heuristic function h(n):

h(n) = estimated cost of the cheapest path from the state at node n to
the goal state.

Functionality:

The algorithm attempts to expand the node that appears closest to the
goal, under the assumption that this will lead to a solution more quickly.

Evaluates nodes solely based on the heuristic: f(n) = h(n)

Path Finding Considerations


Algorithm Performance:

1. Search Part II 2
Some algorithms may be misled and fail to find a path.

Algorithms that guarantee a path are termed complete algorithms.

Those that always find the most optimal path are referred to as optimal
algorithms.

Resource Usage:

The computational resources (CPU cycles and memory) required to find a


path are critical metrics for evaluating an algorithm.

A* Search Algorithm
Characteristics
Optimality Conditions:

Admissible Heuristic: h(n) never overestimates the true cost to reach the
goal.

Consistent Heuristic: For every node n and successor n' with step cost
c:

h(n) = h(n′ ) + c

Overview
A* combines features of Best-First Search and Dijkstra’s Algorithm. Both of
these are derivatives of the Breadth-First Algorithm.

A* considers various paths simultaneously and keeps track of multiple paths


to find the optimal route to the goal.

Pathfinding Process
Open List: Keeps track of paths that still need processing.

Closed List: Contains nodes that have already been processed.

Steps:

1. Search Part II 3
1. Start with the open list containing the initial state.

2. Remove a node from the open list.

3. If the node is the goal, return the solution.

4. Expand the node, generating new states and adding them to the open list.

5. Move processed nodes to the closed list.

Advantages
A* is complete and guarantees to find a solution if one exists, regardless of the
map's complexity.

The algorithm balances the costs of reaching nodes and the estimated cost to
the goal, providing a more directed search compared to others.

Comparison with Other Algorithms


1. Breadth-First Search (BFS)
Approach: Expands the shallowest nodes first, processing nodes level by
level.

Data Structure: Uses a queue (FIFO).

Drawbacks:

High memory consumption as it expands all nodes at the current depth


before moving deeper.

Does not prioritize direction toward the goal, making it inefficient in terms
of CPU cycles.

2. Best-First Search
Approach: Uses heuristics to expand nodes that appear closest to the goal.

Data Structure: Uses a priority queue based on heuristic costs.

Limitations:

1. Search Part II 4
While faster than BFS, it may not always find the optimal path, as it
focuses solely on getting close to the goal.

3. Dijkstra’s Algorithm
Approach: Similar to BFS, but it expands the cheapest node first.

Data Structure: Also uses a priority queue but based on path costs.

Benefits:

Guarantees the optimal solution by keeping track of the path cost to each
node.

Drawbacks:

Exhaustive search, consuming considerable memory and CPU cycles.

Minimax Algorithm
Definition
A strategy used in two-player games where one player (Max) aims to
maximize their score while the opponent (Min) aims to minimize it.

Game Representation in Tic-Tac-Toe


S₀: Initial state (an empty 3x3 board).

Players(s): Function that determines whose turn it is (X or O).

Actions(s): Returns all legal moves for the current state.

Result(s, a): Returns a new state after applying action ( a ) to state ( s ).

Terminal(s): Checks if the game has ended (win or tie).

Utility(s): Returns the utility value of a terminal state: -1 (loss), 0 (draw), or +1


(win).

How the Algorithm Works


1. Recursion: Simulates all possible games starting from the current state until
reaching a terminal state.

1. Search Part II 5
2. Value Assignment: Each terminal state is assigned a value (-1, 0, or +1).

3. Alternating Turns: The maximizing player asks what the minimizing player
would do to minimize the score and vice versa, leading to a recursive
evaluation of possible states.

4. State Values: After evaluating, the maximizing player chooses the action
leading to the highest value.

Pseudocode

Function Max-Value(state):
if Terminal(state):
return Utility(state)
v = -∞
for action in Actions(state):
v = Max(v, Min-Value(Result(state, action)))
return v

Function Min-Value(state):
if Terminal(state):
return Utility(state)
v = ∞
for action in Actions(state):
v = Min(v, Max-Value(Result(state, action)))
return v

Alpha-Beta Pruning
Definition
An optimization technique for the Minimax algorithm that reduces the number
of nodes evaluated.

Mechanism
Alpha Value: The best score that the maximizing player can guarantee.

1. Search Part II 6
Beta Value: The best score that the minimizing player can guarantee.

When the maximizing player finds a move that is worse than the previously
examined options, further exploration of that branch is unnecessary.

Example
If a maximizing player has an action valued at 4 and discovers another action
that leads to a minimum value of 3, they can prune other branches since they
have already established a better option (4).

Depth-Limited Minimax
Overview
In games like Tic-Tac-Toe (255,168 possible games) and Chess (10²⁹⁰⁰⁰
possible games), generating all hypothetical games to terminal conditions can
be computationally expensive or infeasible.

Approach
Limits the depth of the search to a predefined number of moves before
stopping.

Uses an evaluation function to estimate the utility of the game from a given
state instead of reaching terminal states.

Utility Function
Evaluates the board configuration based on the pieces and their positions.

Returns a positive or negative value indicating the favorability of the state for
either player.

Classification of Games
Adversarial Search
Game Definition: The complete set of rules that describes a game.

1. Search Part II 7
Play: An instance of the game.

Position (State): A situation where a player must make a decision (move or


action).

Strategy: A plan that dictates which move to choose in every possible


position.

Rational Behavior: Players are assumed to optimize their payoffs, being aware
that other players are doing the same.

Classification of Games
Criteria for Classification
1. Number of Players:

Games can involve one or multiple players.

2. Simultaneous vs. Sequential Play:

Simultaneous Game: Players make decisions at the same time (e.g., Rock-
Paper-Scissors).

Sequential Game: Players take turns, where no two players move


simultaneously.

3. Random Moves:

Games may contain random events that influence their outcomes.

4. Perfect vs. Complete Information:

Perfect Information: Every player knows all previous moves (e.g., Chess).

Complete Information: All players understand the structure of the game,


including possible moves and outcomes.

5. Zero-Sum Games:

The total payoff to all players equals zero; one player's gain is another's
loss (e.g., Poker, Chess).

1. Search Part II 8
Simultaneous Games
Characteristics
In simultaneous games, each player has only one move, and all moves are
made simultaneously.

Players may have different roles and options for moves, and each player has
finitely many options.

Strategic Form of a Game


Two-Person Zero-Sum Games
In a two-person zero-sum game, the total payoff to both players sums up to
zero for any outcome.

If Player I has a gain, Player II experiences an equivalent loss.

Payoff Matrix Representation:

The game can be represented by a matrix \( A \), where \( A_{ij} \)


represents the payoff to Player I when Player I chooses row \( i \) and
Player II chooses column \( j \).

For Player II, the payoff is the negative of Player I's payoff, i.e., \(-A_{ij}\).

Example: Odd or Even Game


Game Setup:

Players I and II simultaneously choose a number, either 1 or 2.

Player I wins if the sum is odd, while Player II wins if the sum is even.

The winner's payoff is equal to the sum of the chosen numbers.

Payoff Matrix for Player I:

1 (Player II) 2 (Player II)

1 (Player I) 2 -3

2 (Player I) -3 4

1. Search Part II 9
Here, each entry \( A_{ij} \) represents Player I's payoff. For instance:

If both players choose 1, the sum is 2 (even), so Player II wins, and the payoff
for Player I is -2.

If Player I chooses 1 and Player II chooses 2, the sum is 3 (odd), and Player I
wins 3

solution

Example: Odd-or-Even Game with Payoff as Product


Game Setup
Players:

Player I (Odd): Wins if the sum of the chosen numbers is odd.

Player II (Even): Wins if the sum is even.

Choices:

Both players simultaneously call out one of the numbers: 1 or 2.

Payoff:

The loser pays the winner an amount equal to the product of the
numbers chosen.

Step 1: Construct the Payoff Matrix


Let’s set up the payoff matrix \( A \) for Player I based on their choices and the
outcomes:

1 (Player II) 2 (Player II)

1 (Player I) -2 (Player II wins) +3 (Player I wins)

2 (Player I) +3 (Player I wins) -4 (Player II wins)

The payoff matrix for Player I can be represented as follows:

\[
A = \begin{bmatrix}
-2 & 3 \\

1. Search Part II 10
3 & -4 \\
\end{bmatrix}
\]

Step 2: Analyze the Game

Finding Optimal Strategies


We will determine the optimal strategies for both players.

Step 2.1: Player I's Strategy


Let \( p \) be the probability that Player I chooses "1" and \( 1 - p \) the
probability for "2". Player I wants to make their expected winnings equal
regardless of Player II's choice.

1. Expected Payoff for Player I if Player II chooses "1":


\[
E_1 = (-2)p + 3(1 - p) = -2p + 3 - 3p = 3 - 5p
\]

2. Expected Payoff for Player I if Player II chooses "2":


\[
E_2 = 3p + (-4)(1 - p) = 3p - 4 + 4p = 7p - 4
\]

Set these equal to find \( p \):


\[
3 - 5p = 7p - 4
\]
Solving for \( p \):
\[
3 + 4 = 7p + 5p
\]
\[
7 = 12p \implies p = \frac{7}{12}
\]

1. Search Part II 11
So, Player I should choose "1" with probability \( \frac{7}{12} \) and "2" with
probability \( \frac{5}{12} \).

Step 2.2: Player II's Strategy


Let \( q \) be the probability that Player II chooses "1" and \( 1 - q \) for "2".
Player II also wants to equalize expected losses based on Player I’s choices.

1. Expected Payoff for Player II if Player I chooses "1":


\[
E_1 = (-2)q + 3(1 - q) = -2q + 3 - 3q = 3 - 5q
\]

2. Expected Payoff for Player II if Player I chooses "2":


\[
E_2 = 3q + (-4)(1 - q) = 3q - 4 + 4q = 7q - 4
\]

Set these equal to find \( q \):


\[
3 - 5q = 7q - 4
\]
Solving for \( q \):

\[
3 + 4 = 7q + 5q
\]
\[
7 = 12q \implies q = \frac{7}{12}
\]
So, Player II should choose "1" with probability \( \frac{7}{12} \) and "2" with
probability \( \frac{5}{12} \).

Step 3: Determine the Value of the Game


To find the expected value of the game, substitute \( p = \frac{7}{12} \) and \(
q = \frac{7}{12} \) into the expected payoff equations.

1. Expected Payoff for Player I:

1. Search Part II 12
\[
E = (-2)(\frac{7}{12})(\frac{7}{12}) + 3(\frac{7}{12})(\frac{5}{12}) +
3(\frac{5}{12})(\frac{7}{12}) + (-4)(\frac{5}{12})(\frac{5}{12})
\]

Simplifying step-by-step:
\[
E = -\frac{98}{144} + \frac{105}{144} + \frac{105}{144} - \frac{100}{144}
\]
Combine the terms:
\[
E = \frac{-98 + 105 + 105 - 100}{144} = \frac{12}{144} = \frac{1}{12}
\]

Conclusion: Is the Game Fair?


The value of the game is \( \frac{1}{12} \), which means:

The game is not fair. Player I has an advantage since the expected value
indicates that Player I can expect to win \( \frac{1}{12} \) dollars per game.

Optimal Strategies:

Player I: Choose "1" with probability \( \frac{7}{12} \) and "2" with


probability \( \frac{5}{12} \).

Player II: Choose "1" with probability \( \frac{7}{12} \) and "2" with
probability \( \frac{5}{12} \).

Summary
Player I can guarantee an average win of \( \frac{1}{12} \) each time the
game is played, making it advantageous for Player I. Thus, even with
optimal strategies employed, Player II cannot avoid losses entirely.

This is the complete solution to the Odd-or-Even game problem with the
modifications specified! Let me know if you have any questions or need
further clarification.

1. Search Part II 13
Solving the Game: Saddle Points and Minimax Strategy
Saddle Points
A saddle point in a payoff matrix is an entry \( A_{ij} \) that satisfies:

1. It is the minimum value in its row (Player I's viewpoint).

2. It is the maximum value in its column (Player II's viewpoint).

how to get it?

min of each row

max of each column

get the intersection

When a saddle point exists:

The value of the game is equal to that saddle point, meaning both players
have an optimal strategy by choosing the corresponding row and column.

Example
Consider a payoff matrix:

Column 1 Column 2

Row 1 1 3

Row 2 2 2

Here, the central entry (2) is a saddle point because:

It is the minimum in Row 2.

It is the maximum in Column 2.

Therefore, the value of the game is 2. The optimal strategy for Player I is to
choose Row 2, and for Player II to choose Column 2.

No Saddle Point
When there is no saddle point in the matrix, the game does not have a
straightforward solution through pure strategies.

1. Search Part II 14
In such cases, mixed strategies or equalizing strategies can be used:

Players randomize their choices based on specific probabilities.

The mixed strategy guarantees an expected value (payoff) to each player.

Mixed Strategies
Pure vs. Mixed Strategies
Pure Strategy: A player consistently chooses the same move.

Mixed Strategy: A player assigns probabilities to different moves and


randomly selects based on those probabilities.

For example, if Player I's optimal mixed strategy is to choose "1" with
7
probability 12​ and "2" with /eq then Player I is using a mixed strategy.

Solving a 2x2 Game without a Saddle Point


1. Construct Payoff Matrix:

A=[ ]
a b
c d
​ ​

1. Determine Probabilities:

Calculate the probabilities \( p \) and \( 1-p \) for Player I and \( q \) and \(


1-q \) for Player II to make the expected value equal for all moves.

Matrix Game Domination


Dominated Strategies
Dominated Strategy: A row or column in the matrix that is always worse than
another row or column, respectively.

Strict Domination: If one row's values are always less than or equal to another
row's values, the dominated row can be removed.

1. Search Part II 15
Pruning the Matrix
To simplify the analysis, dominated rows or columns can be removed, ideally
reducing the matrix to a simpler form, such as a 2x2 matrix.

Removing dominated strategies does not change the value of the game,
although it may affect the set of optimal strategies.

Example: Simplification
1. Original Payoff Matrix:

3 2 5
A= 1 ​ ​ 4 ​ 3 ​ ​

0 3 6

1. Removing Dominated Rows:

If the first row is dominated by the second row, remove the first row.

2. Reduced Matrix:

1 4 3
A=[ ]
0 3 6
​ ​ ​

The Minimax Theorem


Fundamental Theorem
For all finite two-person zero-sum games, the Minimax Theorem holds, stating
that:

There exists a value \( V \) for the game.

Player I can guarantee at least \( V \), and Player II can limit their loss to at
most \( V \), using optimal strategies.

Interpretation

1. Search Part II 16
If \( V = 0 \): The game is fair.

If \( V > 0 \): The game favors Player I.

If \( V < 0 \): The game favors Player II.

1. Search Part II 17

You might also like