0% found this document useful (0 votes)
5 views83 pages

AI Module

The document discusses local search algorithms in artificial intelligence, emphasizing their role in optimizing solutions within vast search spaces through incremental changes. It outlines the workings of various algorithms, including hill climbing and simulated annealing, highlighting their advantages and disadvantages. Additionally, it explains the concept of objective functions and optimization problems, underscoring the significance of these algorithms in AI and machine learning applications.

Uploaded by

vadlashaikhoney
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)
5 views83 pages

AI Module

The document discusses local search algorithms in artificial intelligence, emphasizing their role in optimizing solutions within vast search spaces through incremental changes. It outlines the workings of various algorithms, including hill climbing and simulated annealing, highlighting their advantages and disadvantages. Additionally, it explains the concept of objective functions and optimization problems, underscoring the significance of these algorithms in AI and machine learning applications.

Uploaded by

vadlashaikhoney
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
You are on page 1/ 83

SEARCH IN COMPLEX

ENVIRONMENTS
MODULE 3
❖ Artificial Intelligence (AI) is revolutionizing how we solve complex problems and make decisions.
❖ One crucial aspect of AI is local search algorithms, which play a significant role in finding optimal
solutions in various domains.
WHAT IS LOCAL SEARCH IN AI?

❖ Local search in AI refers to a family of optimization algorithms that are used to find the best
possible solution within a given search space.

❖ Unlike global search methods that explore the entire solution space, local search algorithms focus on
making incremental changes to improve a current solution until they reach a locally optimal or
satisfactory solution.

❖ This approach is useful in situations where the solution space is vast, making an exhaustive search
impractical.

❖ The local search algorithm in artificial intelligence is a family of optimization algorithms used to find
the best possible solution to a problem by iteratively making small changes to an initial solution.

❖ These algorithms are used to solve optimization problems in which an exact solution is either
impossible to find or computationally expensive.
❖ Local search algorithms operate using a single current node and generally move only to neighbors
of that node.
❖ Local search algorithms ease up on completeness and optimality in the interest of improving time
and space complexity?
❖ Although local search algorithms are not systematic, they have two key advantages:
1. They use very little memory (usually a constant amount), and
2. They can often find reasonable solutions in large or infinite (continuous) state spaces. •
❖ In addition to finding goals, local search algorithms are useful for solving pure optimization
problems, in which the aim is to find the best state according to an objective function.
1. In optimization problems, the path to goal is irrelevant and the goal state itself is the
solution.
2. In some optimization problems, the goal is not known and the aim is to find the best state.
Local search algorithms are useful for solving pure optimization problems. In pure
optimization problems main aim is to find the best state according to required objective
function.
Local search algorithm make use of concept called as state space landscape. This landscape
has two structures -
1) Location (defined by the state)
2) Elevation (defined by the value of the heuristic cost function or objective function).
• If elevation corresponds to the cost, then the aim is to find the lowest valley - (a global
minimum).
• If elevation corresponds to the objective function, then aim is to find the highest peak - (a
global maximum).
• Local search algorithms explore the landscape.
What is Objective Function?
It focuses on decision-making based on constraints. It is a real-valued function that is either to be
maximized or minimized depending upon the constraints. Some terminologies include:
•Constraints: They are basically the conditional equations that govern the Linear function

•Decision Variables: The variables whose values are to be found out. The equations are solved so as to
get the optimal value of these variables.

•Feasible Region: It is the region in the graph where the constraints are satisfied and the decision
variables are found at the corners of the region.

•Optimum Solution: The best possible solution that satisfies all constraints and achieves the highest or
lowest objective.

•Infeasible Solution: A solution that violates one or more constraints and cannot be implemented or
executed.
Working of a Local Search Algorithm

The basic working principle of a local search algorithm involves the following steps:

❖ Initialization:

Start with an initial solution, which can be generated randomly or through some heuristic method.

❖ Evaluation:

Evaluate the quality of the initial solution using an objective function or a fitness measure. This
function quantifies how close the solution is to the desired outcome.

❖ Neighbor Generation:

Generate a set of neighboring solutions by making minor changes to the current solution. These
changes are typically referred to as "moves."
❖ Selection:

Choose one of the neighboring solutions based on a criterion, such as the improvement in the
objective function value. This step determines the direction in which the search proceeds.

❖ Termination:

Continue the process iteratively, moving to the selected neighboring solution, and repeating
steps 2 to 4 until a termination condition is met. This condition could be a maximum number of
iterations, reaching a predefined threshold, or finding a satisfactory solution.

❖ Solution:

The final solution is the best solution found during the search process.
Optimization Problems
❖ Optimization problems are central to artificial intelligence (AI) and machine learning, focusing
on selecting the best element from some set of available alternatives based on specific
criteria.
❖ These problems are characterized by an objective function that needs to be maximized or
minimized, often subject to a set of constraints.
❖ In the context of machine learning, optimization algorithms are used to minimize a loss
function, which measures the difference between the algorithm's predictions and the actual
data.
❖ The solutions to these problems are vital for training models, feature selection, resource
allocation, scheduling tasks, and much more, making them integral to both the development of
AI technologies and their application in various domains.
HILL CLIMBING ALGORITHM IN ARTIFICIAL INTELLIGENCE

❖ Hill climbing algorithm is a local search algorithm which continuously moves in the direction

of increasing elevation/value to find the peak of the mountain or best solution to the

problem. It terminates when it reaches a peak value where no neighbor has a higher value.

❖ Hill climbing algorithm is a technique which is used for optimizing the mathematical

problems. One of the widely discussed examples of Hill climbing algorithm is Traveling-

salesman Problem in which we need to minimize the distance traveled by the salesman.

❖ It is also called greedy local search as it only looks to its good immediate neighbor state

and not beyond that.

❖ A node of hill climbing algorithm has two components which are state and value.

❖ Hill Climbing is mostly used when a good heuristic is available.


Solution: The solution for the plateau is to take big steps or
Solution: Backtracking technique can be a solution of the local
very little steps while searching, to solve the problem.
maximum in state space landscape. Create a list of the promising
Randomly select a state which is far away from the current
path so that the algorithm can backtrack the search space and
explore other paths as well. state so it is possible that the algorithm could find non-
plateau region.

Solution: With the use of bidirectional search, or by moving in different


directions, we can improve this problem.
How Does the Hill Climbing Algorithm Work?

❖ In the Hill Climbing algorithm, the process begins with an initial solution, which is then

iteratively improved by making small, incremental changes.

❖ These changes are evaluated by a heuristic function to determine the quality of the solution.

❖ The algorithm continues to make these adjustments until it reaches a local maximum—a point

where no further improvement can be made with the current set of moves.
Basic Concepts of Hill Climbing Algorithms

Hill climbing follows these steps:

1.Initial State: Start with an arbitrary or random solution (initial state).

2.Neighboring States: Identify neighboring states of the current solution by making small
adjustments (mutations or tweaks).

3.Move to Neighbor: If one of the neighboring states offers a better solution (according to some
evaluation function), move to this new state.

4.Termination: Repeat this process until no neighboring state is better than the current one. At this
point, you’ve reached a local maximum or minimum (depending on whether you’re maximizing or
minimizing).
Advantages of Hill climb algorithm:
1.Ideal for complex problems.
2.It uses much less RAM for the current problem state and the solutions located around it
3.When it comes to the acceleration of the hill up, most of the time it brings a closure in the
local maximum straight away. This is the route if having quickly getting a solution, outshining
acquiring a global maximum, is an incentive.

Disadvantages of Hill Climbing Algorithm:


1.Concerning hill climbing, it seems that some solutions do not find the optimum point and remain
stuck at a local peak,
2.It is also superficial because it just seeks for the surrounding solution and does not get
farther than that.
3.It is highly likely that end result will largely depend on¬ initial setup and state with a precedent
of it being the most sensitive factor.
State-space Diagram for Hill Climbing:

The state-space landscape is a graphical representation of the hill-climbing algorithm which is

showing a graph between various states of algorithm and Objective function/Cost.


In the state-space diagram:

•X-axis: Represents the state space, which includes all the possible states or configurations that
the algorithm can reach.

•Y-axis: Represents the values of the objective function corresponding to each state.

If the function on Y-axis is cost then, the goal of search is to find the global minimum and local

minimum. If the function of Y-axis is Objective function, then the goal of the search is to find the

global maximum and local maximum.


Different regions in the state space landscape:
Local Maximum: Local maximum is a state which is
better than its neighbor states, but there is also
another state which is higher than it.
Global Maximum: Global maximum is the best
possible state of state space landscape. It has the
highest value of objective function.
Current state: It is a state in a landscape diagram
where an agent is currently present.
Flat local maximum: It is a flat space in the
landscape where all the neighbor states of current
states have the same value.
Shoulder: It is a plateau region which has an uphill
edge.
Types of Hill Climbing Algorithm:

❖ Simple hill Climbing:

❖ Steepest-Ascent hill-climbing:

❖ Stochastic hill Climbing:


1. Simple Hill Climbing:

❖ Simple hill climbing is the simplest way to implement a hill climbing algorithm.

❖ It only evaluates the neighbor node state at a time and selects the first one which

optimizes current cost and set it as a current state.

❖ It only checks it's one successor state, and if it finds better than the current state, then move

else be in the same state.

❖ This algorithm has the following features:

•Less time consuming

•Less optimal solution and the solution is not guaranteed


Algorithm for Simple Hill Climbing:

•Step 1: Evaluate the initial state, if it is goal state then return success and Stop.

•Step 2: Loop Until a solution is found or there is no new operator left to apply.

•Step 3: Select and apply an operator to the current state.

•Step 4: Check new state:

• If it is goal state, then return success and quit.

• Else if it is better than the current state then assign new state as a current state.

• Else if not better than the current state, then return to step2.

•Step 5: Exit.
2. Steepest-Ascent Hill Climbing

❖ Steepest-Ascent Hill Climbing is an enhanced version of simple hill climbing.

❖ Instead of moving to the first neighboring node that improves the state, it evaluates all

neighbors and moves to the one offering the highest improvement (steepest ascent).
Algorithm for Steepest-Ascent Hill Climbing

1.Evaluate the initial state. If it is a goal state, return success.

2.Make the initial state the current state.

3.Repeat until the solution is found or the current state remains unchanged:

• Select a new state that hasn’t been applied to the current state.

• Initialize a ‘best state’ variable and evaluate all neighboring states.

• If a better state is found, update the best state.

• If the best state is the goal, return success.

• If the best state improves upon the current state, make it the new current state and
repeat.

4.Exit the function if no better state is found.


3. Stochastic Hill Climbing

❖ Stochastic Hill Climbing introduces randomness into the search process.

❖ Instead of evaluating all neighbors or selecting the first improvement, it selects a

random neighboring node and decides whether to move based on its improvement over

the current state.


Algorithm for Stochastic Hill Climbing:

1.Evaluate the initial state. If it is a goal state, return success.

2.Make the initial state the current state.

3.Repeat until a solution is found or the current state does not change:

• Apply the successor function to the current state and generate all neighboring states.

• Choose a random neighboring state based on a probability function.

• If the chosen state is better than the current state, make it the new current state.

• If the selected neighbor is the goal state, return success.

4.Exit the function if no better state is found.


SIMULATED ANNEALING ALGORITHM

The SA algorithm is based on the annealing process used in metallurgy, where a metal is heated to

a high temperature quickly and then gradually cooled. At high temperatures, the atoms move fast.

Moreover, when the temperature is reduced, their kinetic energy decreases as well. At the end of

the annealing process, the atoms fall into a more ordered state. Additionally, the material becomes

more ductile and easier to work with.

Similarly, in SA, a search process starts with a high-energy state (an initial solution) and

gradually lowers the temperature (a control parameter) until it reaches a state of minimum

energy (the optimal solution).


At first, the simulated annealing process starts with an initial solution. Furthermore, SA

iteratively improves the current solution by randomly perturbing it and accepting the

perturbation with a certain probability.

The probability of accepting a worse solution is initially high. However, as the number of

iterations increases, the probability of accepting a worse solution gradually decreases.

Therefore, the accuracy of the solution depends on the number of iterations SA performs.

The SA algorithm is quite simple, and we implement it straightforwardly


How Simulated Annealing Works
The algorithm starts with an initial solution and a high "temperature," which gradually decreases
over time. Here’s a step-by-step breakdown of how the algorithm works:

•Initialization: Begin with an initial solution Sο and an initial temperature Tο. he temperature
controls how likely the algorithm is to accept worse solutions as it explores the search space.

•Neighborhood Search: At each step, a new solution S′ is generated by making a small change (or
perturbation) to the current solution S.

•Objective Function Evaluation: The new solution S' is evaluated using the objective function. If S'
provides a better solution than S, it is accepted as the new solution.

•Acceptance Probability: If S' is worse than S, it may still be accepted with a probability based on
the temperature and the difference in objective function values. The acceptance probability is
given by:
•Cooling Schedule: After each iteration, the temperature is decreased according to a predefined

cooling schedule, which determines how quickly the algorithm converges. Common cooling schedules

include linear, exponential, or logarithmic cooling.

•Termination: The algorithm continues until the system reaches a low temperature (i.e., no more

significant improvements are found), or a predetermined number of iterations is reached.

Cooling Schedule and Its Importance

The cooling schedule plays a crucial role in the performance of Simulated Annealing. If the

temperature decreases too quickly, the algorithm might converge prematurely to a suboptimal solution

(local optimum). On the other hand, if the cooling is too slow, the algorithm may take an excessively

long time to find the optimal solution. Hence, finding the right balance between exploration (high

temperature) and exploitation (low temperature) is essential.


Advantages of Simulated Annealing

•Ability to Escape Local Minima: One of the most significant advantages of Simulated
Annealing is its ability to escape local minima. The probabilistic acceptance of worse solutions
allows the algorithm to explore a broader solution space.

•Simple Implementation: The algorithm is relatively easy to implement and can be adapted to a
wide range of optimization problems.

•Global Optimization: Simulated Annealing can approach a global optimum, especially when
paired with a well-designed cooling schedule.

•Flexibility: The algorithm is flexible and can be applied to both continuous and discrete
optimization problems.
Disadvantages of Simulated Annealing

•Parameter Sensitivity: The performance of Simulated Annealing is highly dependent on the

choice of parameters, particularly the initial temperature and cooling schedule.

•Computational Time: Since Simulated Annealing requires many iterations, it can be

computationally expensive, especially for large problems.

•Slow Convergence: The convergence rate is generally slower than more deterministic methods

like gradient-based optimization.


Thus, we can observe that SA accepts the worse solutions when the temperature is high.
Conversely, when the temperature is low (e.g., T < 1 ), the algorithm is more selective, and
better solutions are accepted with higher probability.
What is an evolutionary algorithm

• An evolutionary algorithm is an evolutionary based AI-based computer application that solves

problems by employing processes that mimic the behaviors of living things.

• As such, it uses mechanisms that are typically associated with biological evolution, such as

reproduction, mutation and recombination.

• Evolutionary algorithms function in a Darwinian-like natural selection process; the weakest

solutions are eliminated while stronger, more viable options are retained and re-evaluated in the

next evolution—with the goal being to arrive at optimal actions to achieve the desired outcomes.
• With this approach, candidate solutions to an optimization problem are randomly generated
and act as individuals interacting with a larger population.
• A fitness function determines the quality of the solutions the candidates find as they move
about in each iteration.
• The “best fit” individuals are then chosen for reproduction in the next iteration.
• This generational process is repeated until the algorithm has evolved to find the optimal
solution to the problem.
How do Fitness Functions Work in Evolutionary Algorithms?
The heart of these algorithms is the fitness function, which is an objective function used to
summarize, as a single figure of merit (attractiveness), how close the current agent (solution) is to
achieving the algorithm’s programmed aims. There are many variations of the exact function that can
include velocity/position like in swarm intelligence, or employ any other time or frequency variables.

Regardless of specific function, the evolution process works involves the same steps:

1.Randomly generate the initial population of individuals. (First generation)


2.Evaluate the fitness of each individual in that population with the preferred fitness function.
3.Repeat the following generational steps until an optimal solution is found:
1. Select the parents (best-fit individuals) for reproduction.
2. Breed new individuals through crossover and random mutation, giving “birth” to the next
generation.
3. Use the fitness function to gauge the individual fitness of the new individuals.
4. Replace least-fit population with new individuals.
Benefits of Evolutionary Algorithms

1. Efficiency

One of the main benefits of evolutionary algorithms is their efficiency. Unlike traditional optimization
algorithms, which can get stuck in local optima, evolutionary algorithms explore a wide range of
solutions and can find the global optimum. This is because they use a population of solutions instead of
a single solution and apply operators such as mutation and crossover to generate new solutions. As a
result, evolutionary algorithms are often faster and more accurate than traditional optimization
algorithms.

For example, evolutionary algorithms have been used to optimize the design of aircraft wings, where
the goal is to minimize weight while maintaining structural integrity. By using evolutionary algorithms,
researchers were able to find a design that was 20% lighter than the previous design, while still
meeting all the structural requirements.
2. Robustness

Another benefit of evolutionary algorithms is their robustness. Evolutionary algorithms are able to
adapt to changing environments and complex problems, making them ideal for real world applications.
This is because they use a stochastic search process that can explore a wide range of solutions and
adapt to new situations.

For example, evolutionary algorithms have been used to optimize the routing of emergency vehicles
in urban areas. In this scenario, the goal is to minimize response time while taking into account
traffic congestion and road closures. By using evolutionary algorithms, researchers were able to find
a routing strategy that was robust to changes in traffic patterns and road closures, resulting in
faster response time and better emergency services.
Flexibility

Evolutionary Algorithms are highly flexible and can be customized to suit different
applications. This is because they can be adapted to handle different types of data and
search spaces, making them ideal for a wide range of applications.

For example, evolutionary algorithms have been used to optimize the placement of wind
turbines in offshore wind farms. In this scenario, the goal is to maximize energy
production while minimizing the impact on marine life and the environment. By using
evolutionary algorithms, researchers were able to find an optimal placement strategy that
took into account a wide range of factors, resulting in a more efficient and sustainable energy
farm.
OPTIMAL DECISIONS IN GAMES

Humans’ intellectual capacities have been engaged by games for as long as civilization has existed,
sometimes to an alarming degree. Games are an intriguing subject for AI researchers because of their
abstract character. A game’s state is simple to depict, and actors are usually limited to a small number
of actions with predetermined results. Physical games, such as croquet and ice hockey, contain
significantly more intricate descriptions, a much wider variety of possible actions, and rather
ambiguous regulations defining the legality of activities. With the exception of robot soccer, these
physical games have not piqued the AI community’s interest.

Games are usually intriguing because they are difficult to solve. Chess, for example, has an average
branching factor of around 35, and games frequently stretch to 50 moves per player, therefore the
search tree has roughly 35100 or 10154 nodes (despite the search graph having “only” about 1040
unique nodes). As a result, games, like the real world, necessitate the ability to make some sort of
decision even when calculating the best option is impossible.
Optimal Decision Making in Games

Let us start with games with two players, whom we’ll refer to as MAX and MIN for obvious reasons.
MAX is the first to move, and then they take turns until the game is finished. At the conclusion of the
game, the victorious player receives points, while the loser receives penalties. A game can be formalized
as a type of search problem that has the following elements:

• S0: The initial state of the game, which describes how it is set up at the start.

• Player (s): Defines which player in a state has the move.

• Actions (s): Returns a state’s set of legal moves.

• Result (s, a): A transition model that defines a move’s outcome.

• Terminal-Test (s): A terminal test that returns true if the game is over but false otherwise.
Terminal states are those in which the game has come to a conclusion.
• Utility (s, p): A utility function (also known as a payout function or objective function )

determines the final numeric value for a game that concludes in the terminal state s for

player p. The result in chess is a win, a loss, or a draw, with values of +1, 0, or 1/2.

Backgammon’s payoffs range from 0 to +192, but certain games have a greater range of

possible outcomes. A zero-sum game is defined (confusingly) as one in which the total reward

to all players is the same for each game instance. Chess is a zero-sum game because each game

has a payoff of 0 + 1, 1 + 0, or 1/2 + 1/2. “Constant-sum” would have been a preferable name,

22 but zero-sum is the usual term and makes sense if each participant is charged 1.
Adversarial Search
• Adversarial search is a search, where we examine the problem which arises when we try to
plan ahead of the world and other agents are planning against us.
• There might be some situations where more than one agent is searching for the solution in the
same search space, and this situation usually occurs in game playing.
• The environment with more than one agent is termed as multi-agent environment, in which each
agent is an opponent of other agent and playing against each other. Each agent needs to consider
the action of other agent and effect of that action on their performance.
• So, Searches in which two or more players with conflicting goals are trying to explore the
same search space for the solution, are called adversarial searches, often known as Games.
• Games are modeled as a Search problem and heuristic evaluation function, and these are the two
main factors which help to model and solve games in AI.
MINI-MAX ALGORITHM IN ARTIFICIAL INTELLIGENCE

• Mini-max algorithm is a recursive or backtracking algorithm which is used in decision-making and

game theory. It provides an optimal move for the player assuming that opponent is also playing

optimally.

• Mini-Max algorithm uses recursion to search through the game-tree.

• Min-Max algorithm is mostly used for game playing in AI. Such as Chess, Checkers, tic-tac-toe, go,

and various tow-players game. This Algorithm computes the minimax decision for the current state.

• In this algorithm two players play the game, one is called MAX and other is called MIN.

• Both the players fight it as the opponent player gets the minimum benefit while they get the

maximum benefit.
• Both Players of the game are opponent of each other, where MAX will select the maximized

value and MIN will select the minimized value.

• The minimax algorithm performs a depth-first search algorithm for the exploration of the

complete game tree.

• The minimax algorithm proceeds all the way down to the terminal node of the tree, then

backtrack the tree as the recursion.


Working of Min-Max Process in AI
• The Min-Max algorithm is a decision-making process used in artificial intelligence for two-player
games. It involves two players: the maximizer and the minimizer, each aiming to optimize their
own outcomes.

Players Involved

Maximizing Player (Max):

• Aims to maximize their score or utility value.

• Chooses the move that leads to the highest possible utility value, assuming the opponent will play
optimally.

Minimizing Player (Min):

• Aims to minimize the maximizer's score or utility value.


• Selects the move that results in the lowest possible utility value for the maximizer, assuming the
opponent will play optimally.

• The interplay between these two players is central to the Min-Max algorithm, as each player
attempts to outthink and counter the other's strategies.

• The working of the minimax algorithm can be easily described using an example. Below we have
taken an example of game-tree which is representing the two-player game.
• In this example, there are two players one is called Maximizer and other is called Minimizer.
• Maximizer will try to get the Maximum possible score, and Minimizer will try to get the minimum
possible score.
• This algorithm applies DFS, so in this game-tree, we have to go all the way through the leaves to
reach the terminal nodes.
• At the terminal node, the terminal values are given so we will compare those value and backtrack
the tree until the initial state occurs. Following are the main steps involved in solving the two-player
game tree:
Step-1: In the first step, the algorithm generates the entire game-tree and apply the utility
function to get the utility values for the terminal states. In the below tree diagram, let's take A is
the initial state of the tree. 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.
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

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
What do you mean by Optimal Decision Player game?
• Making the greatest decision feasible in a circumstance while considering a variety of
variables, including the game mechanics, the resources at your disposal, potential risks and
rewards, and the activities of other players, is known as optimal decision making in a player
game.
• To make a decision that is well-informed and most likely to result in a favorable outcome, it
entails evaluating the information at hand and utilizing a variety of decision-making tactics
and procedures.
• Making the best decisions is crucial in player games since they can affect the result and
ultimately determine whether a player wins or loses.
ALPHA-BETA PRUNING
• Alpha-beta pruning is a modified version of the minimax algorithm.
• It is an optimization technique for the minimax algorithm.
• As we have seen in the minimax search algorithm that the number of game states it has to examine
are exponential in depth of the tree.
• Since we cannot eliminate the exponent, but we can cut it to half. Hence there is a technique by
which without checking each node of the game tree we can compute the correct minimax decision,
and this technique is called pruning.
• This involves two threshold parameter Alpha and beta for future expansion, so it is called alpha-
beta pruning.
• It is also called as Alpha-Beta Algorithm.
• Alpha-beta pruning can be applied at any depth of a tree, and sometimes it not only prune
the tree leaves but also entire sub-tree.
• The two-parameter can be defined as:
• 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.
Condition for Alpha-beta pruning:
• The main condition which required for alpha-beta pruning is:
α>=β

Key points about alpha-beta pruning:


• The Max player will only update the value of alpha.
• The Min player will only update the value of beta.
• While backtracking the tree, the node values will be passed to upper nodes instead of
values of alpha and beta.
• We will only pass the alpha, beta values to the child nodes.
Working of Alpha-Beta Pruning:
Let's take an example of two-player search tree to understand the working of Alpha-beta pruning
Step 1: At the first step the, Max player will start first move from node A where α= -∞ and β=
+∞, these value of alpha and beta passed down to node B where again α= -∞ and β= +∞, and Node B
passes the same value to its child D.
Step 2: At Node D, the value of α will be calculated as its turn for Max. The value of α is compared
with firstly 2 and then 3, and the max (2, 3) = 3 will be the value of α at node D and node value will also
3.
Step 3: Now algorithm backtrack to node B, where the value of β will change as this is a turn of Min,
Now β= +∞, will compare with the available subsequent nodes value, i.e. min (∞, 3) = 3, hence at node B
now α= -∞, and β= 3.
In the next step, algorithm traverse the next successor of Node B which is node E, and the values of
α= -∞, and β= 3 will also be passed.
Step 4: At node E, Max will take its turn, and the value of alpha will change. The current value of
alpha will be compared with 5, so max (-∞, 5) = 5, hence at node E α= 5 and β= 3, where α>=β, so the
right successor of E will be pruned, and algorithm will not traverse it, and the value at node E will be
5.
Step 5: At next step, algorithm again backtrack the tree, from node B to node A. At node A, the
value of alpha will be changed the maximum available value is 3 as max (-∞, 3)= 3, and β= +∞, these
two values now passes to right successor of A which is Node C.
At node C, α=3 and β= +∞, and the same values will be passed on to node F.
Step 6: At node F, again the value of α will be compared with left child which is 0, and max(3,0)= 3,
and then compared with right child which is 1, and max(3,1)= 3 still α remains 3, but the node value of
F will become 1.
Step 7: Node F returns the node value 1 to node C, at C α= 3 and β= +∞, here the value of beta will
be changed, it will compare with 1 so min (∞, 1) = 1. Now at C, α=3 and β= 1, and again it satisfies
the condition α>=β, so the next child of C which is G will be pruned, and the algorithm will not
compute the entire sub-tree G.
Step 8: C now returns the value of 1 to A here the best value for A is max (3, 1) = 3. Following is the
final game tree which is the showing the nodes which are computed and nodes which has never
computed. Hence the optimal value for the maximizer is 3 for this example.
Move Ordering in Alpha-Beta pruning:
The effectiveness of alpha-beta pruning is highly dependent on the order in which each node is
examined. Move order is an important aspect of alpha-beta pruning.
It can be of two types:
• Worst ordering: In some cases, alpha-beta pruning algorithm does not prune any of the leaves
of the tree, and works exactly as minimax algorithm. In this case, it also consumes more time
because of alpha-beta factors, such a move of pruning is called worst ordering. In this case,
the best move occurs on the right side of the tree. The time complexity for such an order is
O(bm).
• Ideal ordering: The ideal ordering for alpha-beta pruning occurs when lots of pruning happens
in the tree, and best moves occur at the left side of the tree. We apply DFS hence it first
search left of the tree and go deep twice as minimax algorithm in the same amount of time.
Complexity in ideal ordering is O(bm/2).
Rules to find good ordering:

Following are some rules to find good ordering in alpha-beta pruning:

• Occur the best move from the shallowest node.

• Order the nodes in the tree such that the best nodes are checked first.

• Use domain knowledge while finding the best move. Ex: for Chess, try order: captures first, then

threats, then forward moves, backward moves.

• We can bookkeep the states, as there is a possibility that states may repeat.

You might also like