Principals of AI Unit II
Principals of AI Unit II
• A problem con
• sist of input state , set of actions goal test function and path cost function..
• Together ,the initial state and successor function implicitly define the state space of the problem
• It deals with search techniques that use an explicit search tree that is generated by the initial
state and the successor function that together define the state space
Eg : Expansion in the search tree for finding a route from Arad to Bucharest.
• The root of the search tree is a search node corresponding to the initial state , in(Arad).
• The first step is to test whether this is goal state. clearly it is not.
• A search problem consists of:
• A State Space. Set of all possible states where you can be.
• A Start State. The state from where the search begins.
• A Goal State. A function that looks at the current state returns whether or not it is the goal state.
• The Solution to a search problem is a sequence of actions, called the plan that transforms the start state to the goal
state.
• This plan is achieved through search algorithms.
Uninformed /Blind search
➢The Uninformed search does not contain any domain knowledge
such as closeness, the location of the goal.
➢It operates in a brute force way , as it only includes information
about how to traverse the tree and how to identify leaf and goal
nodes
➢Uninformed search applies a way in which search tree is searched
without any information about the search space like intial state
operators and test for the goal, so it is called blind search.
➢It examines each nodes until it achieves the goal node.
Informed Search
➢It uses domain knowledge ,the problem information is available which
can guide the search.
➢Informed search strategies can find a solution more efficient than an
uninformed. Informed search is also called as Heuristic search.
➢A Heuristic is a way which might not always be guaranteed for the best
solution but guaranteed to find a good solution in reasonable time.
➢It can solve much complex problem which could not be solved in another
way.
Breadth-First Search(BFS)
➢It is the most common search strategy for traversing a tree or graph.
➢This algorithm searches breadthwise in a tree or graph , so it is called
breadth-first search.
➢BFS algorithm starts searching from the root node of the tree and expands
all successor node at the current level before.
➢BFS algorithm is an example of general-graph search algorithm
➢BFS implemented using FIFO queue data structure.
Merits of BFS
▪ BFS will provide a solution if any solution exists.
▪ If there is more than one solution for a given problem, then BFS will provide
the minimal solution which requires the least number of steps.
Demerits of BFS
▪ Its requires lots of memory since each level of the tree must be saved
into memory to expand the next level
▪ BFS needs lots of time if the solution is far away from the root node.
DEPTH- FRIST SEARCH
➢It is a recursive algorithm for traversing a tree or graph data structure.
➢It is called DFS because it starts from the root 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
➢The process of the DFS algorithm is similar to the BFS algorithm.
Demerits of DFS
▪ There is a possibility that many states keep re-occurring , and there is no
guarantee of finding the solution.
▪ DFS algorithm goes for deep down searching and sometimes it may go to the
infinite loop
Merits of DFS
▪ DFS requires very less memory as it only needs to store a stack of the nodes
on the path from root node to the current node
▪ It takes less time to reach goal node than BFS algorithm (if it traverses in the
right path)
Breadth-First Search and Depth-First Search
Diagram
Heuristic Search
• One of the core methods AI systems use to navigate problem-solving is
through heuristic search techniques.
• These techniques are essential for tasks that involve finding the best path
from a starting point to a goal state, such as in navigation systems, game
playing, and optimization problems.
• This article delves into what heuristic search is, its significance, and the
various techniques employed in AI.
• The primary benefit of using heuristic search techniques in AI is their ability
to handle large search spaces.
• Heuristics help to prioritize which paths are most likely to lead to a solution,
significantly reducing the number of paths that must be explored.
• This not only speeds up the search process but also makes it feasible to
solve problems that are otherwise too complex to handle with exact
algorithms
Example of Heuristic search
7 5 4 - 1 2 The purpose of heuristic
5 - 6 3 4 5 function is to guide the
8 3 1 6 7 8 search process in the most
Start state Goal state profitable path among all
that are available.
1 2
5 4
• The core of the A* algorithm is based on cost functions and heuristics. It uses
two main parameters:
g(n): The actual cost from the starting node to any node n.
h(n): The heuristic estimated cost from node n to the goal.
This is where A* integrates knowledge beyond the graph to guide the
search.
• The sum, 𝑓(𝑛)=𝑔(𝑛)+ℎ(𝑛) represents the total estimated cost of the cheapest
solution through n. The A* algorithm functions by maintaining a priority
queue (or open set) of all possible paths along the graph, prioritizing them
based on their f values.
Applications of A*
The A* algorithm’s ability to find the most efficient path with a given
heuristic makes it suitable for various practical applications:
▪ Pathfinding in Games and Robotics: A* is extensively used in the gaming
industry to control characters in dynamic environments, as well as in
robotics for navigating between points.
▪ Network Routing: In telecommunications, A* helps in determining the
shortest routing path that data packets should take to reach the destination.
▪ AI and Machine Learning: A* can be used in planning and decision-making
algorithms, where multiple stages of decisions and movements need to be
evaluated.
Advantages of A*
• Optimality: When equipped with an admissible heuristic, A* is guaranteed
to find the shortest path to the goal.
• Completeness: A* will always find a solution if one exists.
• Flexibility: By adjusting heuristics, A* can be adapted to a wide range of
problem settings and constraints.
The steps of the A* algorithm are as follows:
1.Initialization: Start by adding the initial node to the open set with
its f(n).
2.Loop: While the open set is not empty, the node with the lowest
f(n) value is removed from the queue.
3.Goal Check: If this node is the goal, the algorithm terminates and
returns the discovered path.
4.Node Expansion: Otherwise, expand the node (find all its
neighbors), calculating g, h, and f values for each neighbor. Add
each neighbor to the open set if it’s not already present, or if a
better path to this neighbor is found.
5.Repeat: The loop repeats until the goal is reached or if there are
no more nodes in the open set, indicating no available path.
(AND-OR) AO* Search Algorithm
• The AO* method divides any given difficult problem into a smaller group of problems that
are then resolved using the AND-OR graph concept.
• The problem is divided into a set of sub-problems , where each sub-problem can be solved
seperately
• AND OR graphs are specialized graphs that are used in problems that can be divided into
smaller problems.
• The AND side of the graph represents a set of tasks that must be completed to achieve the
main goal, while the OR side of the graph represents different methods for accomplishing the
same main goal.
• In the above figure, the buying of a car may be broken down into
smaller problems or tasks that can be accomplished to achieve the
main goal in the above figure, which is an example of a simple AND-OR
graph. The other task is to either steal a car that will help us accomplish
the main goal or use your own money to purchase a car that will
accomplish the main goal. The AND symbol is used to indicate the AND
part of the graphs, which refers to the need that all subproblems
containing the AND to be resolved before the preceding node or issue
may be finished.
• Working of AO* algorithm:
• The evaluation function in AO* looks like this:
f(n) = g(n) + h(n)
f(n) = Actual cost + Estimated cost
here,
f(n) = The actual cost of traversal.
g(n) = the cost from the initial node to the current node.
h(n) = estimated cost from the current node to the goal state.
AO* Algorithm
Let’s briefly understand what the AO* algorithm is:
➢AO* is a variant of the A* algorithm. It is designed to be more flexible and
capable of adapting to changing environments.
➢AO* can repair its solution whenever it encounters a change in the
environment without having to start the search from scratch.
➢AO* is like a supercharged version of A*. It is designed to handle situations
where things might change like a dynamic environment.
➢For example, imagine a robot moving around a busy room. If furniture gets
rearranged AO* can quickly adjust its plan without starting from scratch.
➢One of the cool things about AO* is that it uses a combination of OR and AND
operations. This means it can consider multiple paths simultaneously making it
really good at adapting to new information.
➢It’s like being able to plan a route while also keeping an eye on alternative
options. This makes AO* a powerful tool for tasks that involve uncertainty and
change.
Problem Reduction
• In problem reduction, the main problem is divided into smaller sub-problems,
known as subgoals, that can be tackled individually.
• Each subgoal represents a part of the main problem that needs to be solved
in order to reach a solution.
• By solving these subgoals one by one, the overall problem can be solved by
combining the solutions of each subgoal.
• Problem reduction is a technique used in artificial intelligence to simplify
complex problems by breaking them down into smaller, more manageable
sub-problems. This approach is particularly useful when dealing with
problems that are difficult to solve directly or require a significant amount of
computational resources.
THE PROCESS OF PROBLEM REDUCTION
The problem reduction approach involves the following steps:
➢Identifying the main problem:
The first step in problem reduction is to identify the main problem that needs to be solved.
➢Breaking down the problem:
Once the main problem is identified, it is broken down into smaller sub-
problems. This is done by identifying the key components or factors that
contribute to the main problem.
➢Solving the sub-problems:
Each sub-problem is solved individually using appropriate techniques or
algorithms.
➢Combining the solutions:
Finally, the solutions to the sub-problems are combined to obtain the
solution to the main problem.
BENEFITS OF PROBLEM REDUCTION
The problem reduction approach offers several benefits
➢Complex problems become more manageable: By breaking down a complex
problem into smaller sub-problems
1.Advancement of AI: Game playing has been a driving force behind the development of artificial
intelligence and has led to the creation of new algorithms and techniques that can be applied to
other areas of AI.
2.Education and training: Game playing can be used to teach AI techniques and algorithms to
students and professionals, as well as to provide training for military and emergency response
personnel.
3.Research: Game playing is an active area of research in AI and provides an opportunity to study
and develop new techniques for decision-making and problem-solving.
4.Real-world applications: The techniques and algorithms developed for game playing can be
applied to real-world applications, such as robotics, autonomous systems, and decision support
systems.
Disadvantages of Game Playing in Artificial Intelligence:
1.Limited scope: The techniques and algorithms developed for game playing may not be well-suited
for other types of applications and may need to be adapted or modified for different domains.
2.Computational cost: Game playing can be computationally expensive, especially for complex
games such as chess or Go, and may require powerful computers to achieve real-time performance.
Adversarial search
➢The Adversarial search is a well-suited approach in a competitive environment, where two or
more agents have conflicting goals.
➢The adversarial search can be employed in two-player zero-sum games which means what is good
for one player will be the misfortune for the other.
➢ In such a case, there is no win-win outcome. In artificial intelligence, adversarial search plays a
vital role in decision-making, particularly in competitive environments associated with games and
strategic interactions.
➢By employing adversarial search, AI agents can make optimal decisions while anticipating the
actions of an opponent with their opposing objectives.
➢It aims to establish an effective decision for a player by considering the possible moves and the
counter-moves of the opponents.
➢The adversarial search in competitive environments can be utilized in the below scenarios where the
AI system can assist in determining the best course of action by both considering the possible
moves and counter-moves of the opponents.
➢Each agent seeks to boost their utility or minimize their loss.
➢One agent’s action impacts the outcomes and objectives of the other agents.
➢Additionally, strategic uncertainty arises when the agents may lack sufficient information about
each other’s strategies.
Role of Adversarial Search in AI
➢Game-playing: The Adversarial search finds a significant
application in game-playing scenarios, including renowned games
like chess, Go, and poker. The adversarial search offers the
simplified nature of these games that represents the state of a
game in a straightforward approach and the agents are limited to
a small number of actions whose effects are governed by precise
rules.
➢Decision-making: Decision-making plays a central role in
adversarial search algorithms, where the goal is to find the best
possible move or strategy for a player in a competitive
environment against one or more components. This requires
strategic thinking, evaluation of potential outcomes, and adaptive
decision-making throughout the game.
Types of algorithms in Adversarial search
➢In a normal search , we follow a sequence of actions to reach the goal or to
finish the game optimally.
➢But in an adversarial search, the result depends on the players which will
decide the result of the game.
➢It is also obvious that the solution for the goal state will be an optimal
solution because the player will try to win the game with the shortest path
and under limited time.
There are following types of adversarial search:
▪ Min-max algorithm.
▪ Alpha-beta pruning.
Min-Max algorithm
The Mini-Max algorithm is a decision-making algorithm used in artificial intelligence, particularly
in game theory and computer games.
It is designed to minimize the possible loss in a worst-case scenario (hence “min”) and maximize
the potential gain (therefore “max”).
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.
It is a specialized search that returns optimal sequence of moves for a player in zero sum game.
➢It is a recursive or backtracking algorithm which is use game theory and decision-making.
➢It is mostly used for game playing in AI such as Chess , Tic-tac-toe, Checkers etc.
➢There are two players Max & Min
➢Max for maximized value and Min for minimized value.
➢MinMax performs a DFS algorithm
Step 1:
A
-> Maximizer Maximizer = -∞
Minimizer = ∞
B C -> Minimizer
D E F G -> Maximizer
H I J K L M N O
-> Terminal node
-1 4 2 6 -3 -5 0 7
Terminal values
At node D {-1,4} Max(-1,-∞)=4 max(-1,4)
At node E{2,6} max(2,-∞)=6 max(2,6)
At node F{-3,-5} max(-3,-∞)= -3 max(-3,-5)
At node G{0,7} max(0,-∞)=7 max(0,7)
Step 2 ->max
A
B C
4 6 -3 7 -> min
D E
F G -> max Here Min Node B= min(4,6)=4
Node C=min(-3,7)=-3
H I J K L M N O
Step 3
A ->MAX
4 -3
B C
-> min
4 6 -3 7
D E F G
->max
H I J K L M N O
-1 4 2 6 -3 -5 0 7