CHAPTER 5 AI
CHAPTER 5 AI
P R O B L E M S O LV I N G A N D S E A R C H I N G
S T R AT E G I ES I N A RT I F I C I A L
I N T E L L I G EN C E
Outline
problem-solving.
It organizes the steps/sequence required to formulate
one goal out of multiple goals as well as actions to
achieve that goal.
Goal formulation is based on the current situation and
the agent’s performance measure
Initial State: It is the starting state or initial step of the agent towards its
goal.
Path cost: It assigns a numeric cost to each path that follows the goal.
Remember, an optimal solution has the lowest path cost among all
the solutions.
an algorithm:
Completeness: It measures if the algorithm guarantees to find a
solution (if any solution exist).
Optimality: It measures if the strategy searches for an optimal solution.
problems
Searching is step by step procedure to solve a search-
tree. The root of the search tree is the root node which is corresponding to
the initial state.
Actions: It gives the description of all the available actions to the agent.
Solution: It is an action sequence which leads from the start node to the
goal node.
Optimal Solution: If a solution has the lowest cost among all solutions.
Properties of Search Algorithms:
the best solution (lowest path cost) among all other solutions, then
such a solution for is said to be an optimal solution.
Time Complexity: Time complexity is a measure of time for an
algorithms into
Uninformed (Blind search) search and
Informed search (Heuristic search) algorithms
Uninformed Search (Blind Search)
structure.
Example:
Cont…
Advantages:
If there are more than one solutions for a given problem, then
BFS will provide the minimal solution which requires the least
number of steps.
Disadvantages:
node
2. Depth-first Search
node and follows each path to its greatest depth node before
moving to the next path.
DFS uses a stack data structure for its implementation.
algorithm.
Advantage:
the nodes on the path from root node to the current node.
It takes less time to reach to the goal node than BFS algorithm (if it
Advantages:
BFS algorithms.
This search algorithm finds out the best depth limit and does it by
limit", and it keeps increasing the depth limit after each iteration
until the goal node is found.
This Search algorithm combines the benefits of Breadth-first
Advantages:
1'st Iteration-----> A
2'nd Iteration----> A, B, C
3'rd Iteration------>A, B, D, E, C, F, G
4'th Iteration------>A, B, D, H, I, E, C, F, K, G
In the fourth iteration, the algorithm will find the goal
node.
6. Bidirectional Search Algorithm:
two small sub graphs in which one starts the search from an
initial vertex and other starts from goal vertex.
The search stops when these two graphs intersect each
other
Bidirectional search can use search techniques such as BFS,
Cont..
Advantages:
Disadvantages:
difficult.
In bidirectional search, one should know the goal state in
advance.
Example
is O(bd).
The informed search algorithm is more useful for large search space. Informed
search algorithm uses the idea of heuristic, so it is also called Heuristic search.
Heuristics function: Heuristic is a function which is used in Informed
Greedy best-first search algorithm always selects the path which appears best at
that moment.
With the help of best-first search, at each step, we can choose the most
promising node. In the best first search algorithm, we expand the node which is
closest to the goal node and the closest cost is estimated by heuristic function,
i.e.
f(n)= g(n).
Were, h(n)= estimated cost from node n to the goal.
Step 3: Remove the node n, from the OPEN list which has the lowest
Step 5: Check each successor of node n, and find whether any node is
a goal node or not. If any successor node is goal node, then return
success and terminate the search, else proceed to Step 6.
Step 6: For each successor node, algorithm checks for evaluation
function f(n), and then check if the node has been in either OPEN or
CLOSED list. If the node has not been in both list, then add it to the
OPEN list.
Cont…
Advantages:
It uses heuristic function h(n), and cost to reach the node n from
of g(n).
Cont…
the node.
Hence we can combine both costs as following, and this sum is called as
a fitness number.
At each point in the search space, only those node is expanded which have
the lowest value of f(n), and the algorithm terminates when the goal node
is found.
Algorithm of A* search:
algorithms.
A* search algorithm is optimal and complete.
Disadvantages:
algorithm.
The heuristic value of all states is given in the below table so
we will calculate the f(n) of each state using the formula f(n)=
g(n) + h(n), where g(n) is the cost to reach any node from
start state.
Here we will use OPEN and CLOSED list.
Solution:
Initialization: {(S, 5)}
Iteration1: {(S--> A, 4), (S-->G,
10)}
Iteration2: {(S--> A-->C, 4), (S--
> A-->B, 7), (S-->G, 10)}
Iteration3: {(S--> A-->C--->G, 6),
(S--> A-->C--->D, 11), (S--> A--
>B, 7), (S-->G, 10)}
Iteration 4 will give the final
result, as S--->A--->C--->G it
provides the optimal path with
cost 6.
Cont…
Complete: A* algorithm is complete as long as:
Branching factor is finite.
Cost at every action is fixed.
Optimal: A* search algorithm is optimal if it follows below two
conditions:
Admissible: the first condition requires for optimality is that h(n)
should be an admissible heuristic for A* tree search. An admissible
heuristic is optimistic in nature.
Consistency: Second required condition is consistency for only A*
graph-search.
If the heuristic function is admissible, then A* tree search will
always find the least cost path.
Time Complexity: The time complexity of A* search algorithm
depends on heuristic function, and the number of nodes expanded is
exponential to the depth of solution d. So the time complexity is
O(b^d), where b is the branching factor.
Space Complexity: The space complexity of A* search algorithm
is O(b^d)
Adversarial Search
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.
Types of Games in AI:
Cont….
Perfect information: A game with the perfect information is that in which agents can
look into the complete board. Agents have all the information about the game, and they
can see each other moves also. Examples are Chess, Checkers, Go, etc.
Imperfect information: If in a game agents do not have all information about the
game and not aware with what's going on, such type of games are called the game with
Deterministic games: Deterministic games are those games which follow a strict
pattern and set of rules for the games, and there is no randomness associated with
unpredictable events and has a factor of chance or luck. This factor of chance or luck is
introduced by either dice or cards. These are random, and each action response is not
competition.
In Zero-sum game each agent's gain or loss of utility is exactly
A game is a type of AI search that can be structured into the following elements:
Player (s): indicates which player(s) has moved in the state space.
Result(s, a): The transition model defines the outcome of moves in the state space.
Terminal-Test(s): If the game is over, the terminal test is true; otherwise, it is false.
Terminal states are the states in which the game comes to a finish.
Utility(s, p): The final numeric value for a game that finishes in terminal states s for
player p is returned by a utility function. It's also known as the payout function.
Chess has three possible outcomes: win, defeat, or draw, with payoff values of +1, 0,
and 12. In addition, tic-tac-toe, utility values are +1, -1, and 0.
Game tree:
game tree.
Example: Tic-Tac-Toe game tree:
The following are some of the game's most important
features of Tic-Tac-Toe game tree.
There are two players MAX and MIN.
Players have an alternate turn and start with MAX.
MAX maximizes the result of the game tree
MIN minimizes the result.
Cont…
Example Explanation of Game tree:
MAX has 9 possible moves from the start because he is the first
player. Both players alternately place x and o until we reach a leaf
node where one player has three in a row or all squares are filled.
Both players will compute the best possible utility versus an
optimum adversary for each node, called the minimax value.
Assume that both players are well-versed in tic-tac-toe and are
playing their best game. Each player is trying everything he can to
keep the other from winning. In the game, MIN is working against
Max.
So, in the game tree, we have a Max layer, a MIN layer, and each
layer is referred to as Ply. The game proceeds to the terminal
node, with Max placing x and MIN placing o to prevent Max from
winning.
Either MIN or MAX wins, or the game ends in a tie. This game-
tree represents the whole search space of possibilities in which
MIN and MAX alternately play tic-tac-toe.
Cont…
technique is:
It is designed to determine the best strategy for MAX to
The ideal leaf node in the game tree could appear at any