0% found this document useful (0 votes)
4 views123 pages

Unit3 Search

Chapter 3 of the document discusses problem-solving through search in artificial intelligence, covering key concepts such as state-space representation, search algorithms, and the differences between uninformed and informed search methods. It details various search strategies including breadth-first search (BFS), depth-first search (DFS), and uniform-cost search, along with their characteristics, advantages, and disadvantages. Additionally, it highlights the importance of defining search problems and the challenges posed by large state spaces.

Uploaded by

eeshasingh2501
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)
4 views123 pages

Unit3 Search

Chapter 3 of the document discusses problem-solving through search in artificial intelligence, covering key concepts such as state-space representation, search algorithms, and the differences between uninformed and informed search methods. It details various search strategies including breadth-first search (BFS), depth-first search (DFS), and uniform-cost search, along with their characteristics, advantages, and disadvantages. Additionally, it highlights the importance of defining search problems and the challenges posed by large state spaces.

Uploaded by

eeshasingh2501
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/ 123

Problem-Solving Through Search

Chapter 3
Artificial Intelligence (UCS411)

Thapar Institute of Engineering and Technology, Patiala


mukesh.singh@thapar.edu

Prof. Mukesh Singh (EIED) Artificial Intelligence 1 / 123


Chapter 3: Problem-solving through Search

Chapter Content
• Forward and backward
• State-space
• blind and Heuristic
• Problem-reduction
• A, A*, AO*, Minimax, Constraint propagation
• Neural, stochastic, and evolutionary search algorithms
• Sample applications

Prof. Mukesh Singh (EIED) Artificial Intelligence 2 / 123


Introduction: Searching

Searching means finding


• In general, searching means finding a solution
• For a website: Finding the answer of a question
• In a city: Finding the correct path
• In a chess: Finding the next best step to move

Search in terms of AI
Search is the process of considering various possible sequences
of operators applied to the initial state and finding out a
sequence which culminates in a goal state.

Prof. Mukesh Singh (EIED) Artificial Intelligence 3 / 123


State space

• A state is a representation of problem elements at a given moment.


• A State space is the set of all states reachable from the initial state.
• A state space forms a graph in which the nodes are states and the arcs between
nodes are actions.
• In the state space, a path is a sequence of states connected by a sequence of
actions.
• The solution of a problem is part of the graph formed by the state space.
• The state space representation forms the basis of most of the AI methods.
• Its structure corresponds to the structure of problem solving in two important ways:
• It allows for a formal definition of a problem.
• It permits the problem to be solved with the help of known techniques move
through the problem space until goal state is found.
• A search tree is a tree-like depiction of the search issue.
• The initial state corresponds to the root node of the search tree, which serves as the
tree’s starting point.
Path Cost is a function that assigns a cost value to each path.
It is an activity sequence that connects the beginning node to the end node.
• The optimal option is the one with the lowest cost among all alternatives.

Prof. Mukesh Singh (EIED) Artificial Intelligence 4 / 123


Search Problem in state space
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 Test: 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.

The state space can be HUGE! (Combinatorial explosion)


Theorem Proving: Infinite!
Chess: 10120 (in an average length game)
Checkers:1040
Eight puzzle:181,440

Prof. Mukesh Singh (EIED) Artificial Intelligence 5 / 123


State Space (Tic-Tac-Toe)....

Prof. Mukesh Singh (EIED) Artificial Intelligence 6 / 123


State Space (8 tiles)......

Prof. Mukesh Singh (EIED) Artificial Intelligence 7 / 123


Problem statement in State space search

Problem can be defined using five components:


• Initial state
• Total Possible Actions: A description of possible actions
available to the agent.
• State Space: Set of all states reachable from the initial state by
any sequence of actions
• Path Cost: Cost of each path
• Goal state

state space function


S={S, A, Action(S), Result(S,A), cost(S,A) }

Prof. Mukesh Singh (EIED) Artificial Intelligence 8 / 123


Example
Q problem
Place exactly one Q in each column so that no two Qs are in the
same row or diagonal

Input:
• Set of states
• Operators [and costs]
• Start state
• Goal state (test)
Output
Prof. Mukesh Singh (EIED) Artificial Intelligence 9 / 123
State Space Search
The search problem: How to control the search?
Given
• an initial state
• a set of operators (actions the agent can take)
• a set of goal states
• (optional) a path cost function
Find:
• a sequence of operators that leads from the initial state to a
goal state

Measuring effectiveness:
• Does the method find a solution at all?
• Is it a good solution (low path cost)
• What is the search cost?
The total cost is the sum of the search cost and the path cost
Prof. Mukesh Singh (EIED) Artificial Intelligence 10 / 123
State Space

Advantages:
1. It is very useful in AI because of it provides a set of all possible
states, operations and goals.
2. If the entire state space is for a problem then it is possible to
trace the path from the initial to the goal state and identify the
sequence of operation required for doing it.

Disadvantages:
1. It is not possible to visualize all states for a problem.
2. The resources of the computer system are very limited to handle
huge combinational state space.

Prof. Mukesh Singh (EIED) Artificial Intelligence 11 / 123


8 tiles puzzle

Prof. Mukesh Singh (EIED) Artificial Intelligence 12 / 123


8 tiles puzzle....

Prof. Mukesh Singh (EIED) Artificial Intelligence 13 / 123


8 tiles puzzle.....

Prof. Mukesh Singh (EIED) Artificial Intelligence 14 / 123


8 tiles puzzle.....

Prof. Mukesh Singh (EIED) Artificial Intelligence 15 / 123


8 tiles puzzle.....

Prof. Mukesh Singh (EIED) Artificial Intelligence 16 / 123


8 tiles puzzle.....

Prof. Mukesh Singh (EIED) Artificial Intelligence 17 / 123


8 tiles puzzle.....

Prof. Mukesh Singh (EIED) Artificial Intelligence 18 / 123


Water Jug Problem

Assignment
We are provided with two jugs: one having the capacity to hold 3
gallons of water and the other has the capacity to hold 4 gallons of
water. There is no other measuring equipment available and the
jugs also do not have any kind of marking on them. So, the agents
task here is to fill the 4-gallon jug with 2 gallons of water by using
only these two jugs and no other material. Initially, both our jugs
are empty.

Prof. Mukesh Singh (EIED) Artificial Intelligence 19 / 123


Types of Searching

Prof. Mukesh Singh (EIED) Artificial Intelligence 20 / 123


Diferrence between Uninformed and Informed
Search

Uninformed Informed
Search without Information Search with Information
No Knowledge Use knowledge to find steps to sol.
Time Consuming Quick Solution
More complexity(time, space) Less complexity (time, space)
Ex: DFS and BFS A*, Heuristic DFS, Best fast search

Prof. Mukesh Singh (EIED) Artificial Intelligence 21 / 123


Uninformed Search
• Searching without information
• No Knowledge
• Time Consuming
• More complexity (time, space)

• Brute Force/blind search


• Optimal solution is guaranteed
• Search space grows exponentially.
• Depth-first search, Breadth-first search, Bi-directional
search, Uniform cost search and etc

Question
You may wonder why we should use a blind search, when we could
use a search with some built in intelligence. The simple answer is
that there may not be any information we can use.
Prof. Mukesh Singh (EIED) Artificial Intelligence 22 / 123
BFS
Working of BFS
• Breadth-first search (BFS) is an algorithm that is used to graph data or searching tree
or traversing structures.
• The algorithm efficiently visits and marks all the key nodes in a graph in an accurate
breadthwise fashion.
• This algorithm selects a single node (initial or source point) in a graph and then visits
all the nodes adjacent to the selected node. Remember, BFS

Prof. Mukesh Singh (EIED) Artificial Intelligence 23 / 123


BFS....

Prof. Mukesh Singh (EIED) Artificial Intelligence 24 / 123


Implementing BFS using FIFO

Prof. Mukesh Singh (EIED) Artificial Intelligence 25 / 123


Charateristics of BFS

• It is an Uninformed search techniques (Blind Search)


• FIFO (Queue)
• Shallowest Node
• Complete
• Optimal
• Time complexity (O(bd ))
Where b=branch and d=level or depth
• Space complexity (O(bd+1 ))
Where b=branch and d=level or depth

Prof. Mukesh Singh (EIED) Artificial Intelligence 26 / 123


BFS Pseudocode
Explanation
Pseudocode
• (G, s) is input, here G is the
• Input: s as the source node
graph and s is the root node
• BFS (G, s) • A queue Q is created and
• let Q be queue initialized with the source
• Q.enqueue( s ) node s
• mark s as visited • All child nodes of s are
• while ( Q is not empty) marked
• v = Q.dequeue( ) • Extract s from queue and
visit the child nodes
• for all neighbors w of v in
• Process all the child nodes of
Graph G
v
• if w is not visited
• Stores w (child nodes) in Q to
• Q.enqueue( w )
further visit its child nodes
• mark w as visited
• Continue till Q is empty
Prof. Mukesh Singh (EIED) Artificial Intelligence 27 / 123
Benefits of BFS

• BFS is useful for analyzing the nodes in a graph and


constructing the shortest path of traversing through these.
• BFS can traverse through a graph in the smallest number of
iterations.
• The architecture of the BFS algorithm is simple and robust.
• The result of the BFS algorithm holds a high level of accuracy
in comparison to other algorithms.
• BFS iterations are seamless, and there is no possibility of this
algorithm getting caught up in an infinite loop problem.

Prof. Mukesh Singh (EIED) Artificial Intelligence 28 / 123


DFS
Depth-first search is performed by moving downward in the tree in
depth-first fashion.

Prof. Mukesh Singh (EIED) Artificial Intelligence 29 / 123


Charateristics of DFS
• It is an Uninformed search techniques (Blind Search)
• LIFO (Stack)
• Incomplete
• Not Optimal
• Time complexity (O(bd ))
Where b=branch and d=level or depth
• Space complexity (O(bxd))
Where b=branch and d=level or depth

Prof. Mukesh Singh (EIED) Artificial Intelligence 30 / 123


DFS Implementation

• A standard DFS implementation puts each vertex of the graph


into one of two categories:
• Visited
• Not Visited
• Step 1: Start by putting any one of the graph’s vertices on top
of a stack.
• Step 2: Take the top item of the stack and add it to the visited
list.
• Step 3: Create a list of that vertex’s adjacent nodes. Add the
ones which aren’t in the visited list to the top of the stack.
• Keep repeating steps 2 and 3 until the stack is empty.

Prof. Mukesh Singh (EIED) Artificial Intelligence 31 / 123


Example 1: DFS

Prof. Mukesh Singh (EIED) Artificial Intelligence 32 / 123


Example 1: DFS....

Prof. Mukesh Singh (EIED) Artificial Intelligence 33 / 123


Example 2

Prof. Mukesh Singh (EIED) Artificial Intelligence 34 / 123


Example 2...

As C does not have any unvisited adjacent node so we keep


popping the stack until we find a node that has an unvisited
adjacent node.
In this case, there’s none and we keep popping until the stack
is empty.

Prof. Mukesh Singh (EIED) Artificial Intelligence 35 / 123


Pseducode for DFS

DFS(G,v) ( v is the vertex where the search starts )


Stack S := ; ( start with an empty stack )
for each vertex u, set visited[u] := false;
push S, v;
while (S is not empty) do
u := pop S;
if (not visited[u]) then
visited[u] := true;
for each unvisited neighbour w of u
push S, w;
end if
end while
END DFS()

Prof. Mukesh Singh (EIED) Artificial Intelligence 36 / 123


Example

Prof. Mukesh Singh (EIED) Artificial Intelligence 37 / 123


DFS

Prof. Mukesh Singh (EIED) Artificial Intelligence 38 / 123


BFS

Prof. Mukesh Singh (EIED) Artificial Intelligence 39 / 123


Difference bewtween DFS and BFS

Prof. Mukesh Singh (EIED) Artificial Intelligence 40 / 123


Bidirectional Search

Bidirectional search is a graph search algorithm which find


smallest path from source to goal vertex. It runs two simultaneous
search
• Forward search from source/initial vertex toward goal vertex
• Backward search from goal/target vertex toward source
vertex

Bidirectional search replaces single search graph (which is likely to


grow exponentially) with two smaller sub graphs one starting from
initial vertex and other starting from goal vertex. The search
terminates when two graphs intersect.

Prof. Mukesh Singh (EIED) Artificial Intelligence 41 / 123


Bidirectional Search

Prof. Mukesh Singh (EIED) Artificial Intelligence 42 / 123


Bidirectional Search....

Why bidirectional approach?


• Because in many cases it is faster, it dramatically reduce the
amount of required exploration.
• Suppose if branching factor of tree is b and distance of goal
vertex from source is d, then the normal BFS/DFS searching
complexity would be O(bd ).
• On the other hand, if we execute two search operation then
the complexity would be O(bd/2 ) for each search and total
complexity would be O(bd/2 +bd/2 ) which is far less than O(bd ).

Prof. Mukesh Singh (EIED) Artificial Intelligence 43 / 123


Uniform Cost Search
• Uniform-cost search is a searching algorithm used for
traversing a weighted tree or graph.
• This algorithm comes into play when a different cost is
available for each edge.
• The primary goal of the uniform-cost search is to find a
path to the goal node which has the lowest cumulative cost.
• Uniform-cost search expands nodes according to their path
costs form the root node.
• It can be used to solve any graph/tree where the optimal cost
is in demand.
• A uniform-cost search algorithm is implemented by the
priority queue. It gives maximum priority to the lowest
cumulative cost.
• Uniform cost search is equivalent to BFS algorithm if the path
cost of all edges is the same.
Prof. Mukesh Singh (EIED) Artificial Intelligence 44 / 123
Uniform Cost Search....

Prof. Mukesh Singh (EIED) Artificial Intelligence 45 / 123


Uniform Cost Search....

Prof. Mukesh Singh (EIED) Artificial Intelligence 46 / 123


Performance of UCS

• Completeness: UCS is complete as it traverse level by level in


the search tree as like BFS.
• Optimality: UCS is optimal as it chooses the minimum cost
path at each step.
• Time Complexity: The time complexity of UCS is of the order
of O(bc /m) where c is the cost of the optimal path and m is the
minimum edge length.
• Space Complexity: The space complexity of UCS is same as
that of BFS i.e. O(bd+1 )

Prof. Mukesh Singh (EIED) Artificial Intelligence 47 / 123


Tower of Hanoi
Questions
Tower of Hanoi is a mathematical puzzle where we have three rods (A, B, and C) and N
disks. Initially, all the disks are stacked in decreasing value of diameter i.e., the smallest disk
is placed on the top and they are on rod A. The objective of the puzzle is to move the entire
stack to another rod (here considered C), obeying the following simple rules:
• Only one disk can be moved at a time.
• Each move consists of taking the upper disk from one of the stacks and placing it on
top of another stack i.e. a disk can only be moved if it is the uppermost disk on a
stack.
• No disk may be placed on top of a smaller disk.

Prof. Mukesh Singh (EIED) Artificial Intelligence 48 / 123


Tower of Hanoi

Prof. Mukesh Singh (EIED) Artificial Intelligence 49 / 123


Tower of Hanoi using State Space

. Prof. Mukesh Singh (EIED) Artificial Intelligence 50 / 123


Algorithm...

Recusrsive method
• Shift N-1 disks from A to B, using C.
• Shift last disk from A to C.
• Shift N-1 disks from B to C, using A.

Follow the steps below to solve the problem:


• Create a function towerOfHanoi where pass the N (current number of disk),
from-rod, to-rod, aux-rod.
• Make a function call for (N − 1) th disk.
• Then print the current disk along with from-rod and to-rod
• Again make a function call for (N − 1) th disk.

Prof. Mukesh Singh (EIED) Artificial Intelligence 51 / 123


Tic-Tac-Toe Problem

• It is a two-player game where one player (say Player 1) marks a letter X and the
opponent (Player 2) marks a letter 0.
• There is a 3x3 grid where the players put their letters.
• The player who is able to first mark his three letters in a complete row or column or
diagonal wins the game.
• Each state is represented by the positions occupied by the letters of the two players in
3x3 matrix along with other empty places.
• Initial State: Empty 3x3 matrix.
• Intermediate State: Any arrangement of a 3x3 matrix obtained after applying valid
rules / operators on the current state.
• Final State: Same letters in a complete row or column or diagonal.
Rules / Operators:
• The players will get turns one after the other
• The player can mark their own letter on the empty cell.

Prof. Mukesh Singh (EIED) Artificial Intelligence 52 / 123


Travelling Sales Problem

TSP?
Traveling Salesman Problem describe the salesman who is
travelling between N cities. Salesman knows the route and the cost
of cities so he has to find the possible shortest route that visits
every city exactly one and returns to the starting city.

Prof. Mukesh Singh (EIED) Artificial Intelligence 53 / 123


Travelling Sales Problem

Prof. Mukesh Singh (EIED) Artificial Intelligence 54 / 123


Travelling Sales Problem

Prof. Mukesh Singh (EIED) Artificial Intelligence 55 / 123


Travelling Sales Problem

Prof. Mukesh Singh (EIED) Artificial Intelligence 56 / 123


Informed Search

Informed Search (Heuristic Search)

Prof. Mukesh Singh (EIED) Artificial Intelligence 57 / 123


Heuristic Technique

Concept of Heuristic
• A heuristic is a technique that is used to solve a problem faster than the classic
methods.
• These techniques are used to find the approximate solution of a problem when
classical methods do not.
• It is said to be the problem-solving techniques that result in practical and quick
solutions.
• Heuristics use practical methods and shortcuts used to produce the solutions that
may or may not be optimal, but those solutions are sufficient in a given limited
timeframe.

The heuristic method might not always provide us the finest solution, but it is assured
that it helps us find a good solution in a reasonable time.

Prof. Mukesh Singh (EIED) Artificial Intelligence 58 / 123


Examples of Heuristics

• Common sense: It is a heuristic that is used to


solve a problem based on the observation of an
individual.
• Rule of thumb: In heuristics, we also use a term
rule of thumb. This heuristic allows an individual
to make an approximation without doing an
exhaustive search.
• Educated guess: It allows a person to reach a
conclusion without doing an exhaustive search.
• Working backward: It lets an individual solve a
problem by assuming that the problem is already
being solved by them and working backward in
their minds to see how much a solution has been
reached.

Prof. Mukesh Singh (EIED) Artificial Intelligence 59 / 123


Some concepts related to Heuristic search

Euclidean distance
Euclidean distance is the length of the line segment joining a given pair of points in a
grid/graph. This is unique & is the shortest path between the given pair of points.

Manhattan distance
Manhattan distance is the sum of all horizontal and vertical segments joining a given pair
points in a grid/graph.
It is the distance between points if you cant travel diagonally, as you might have to
walk in a city where the streets are in a grid pattern

Prof. Mukesh Singh (EIED) Artificial Intelligence 60 / 123


Other distance techniques

Prof. Mukesh Singh (EIED) Artificial Intelligence 61 / 123


Heuristic search function
• Heuristic functions are the most common form in which
additional knowledge of the problem is imparted to the search
algorithm.
• A node is selected for expansion based on an evaluation function
f(n)
• The evaluation function is construed as a cost estimate
• So the node with the lowest evaluation is expanded first
• The implementation is identical to that for the uniform cost
search
• except for the use of f instead of g to order the priority
queue.
• The choise of f determines the search strategy
• Most best first algorithms inlcudes as a component of f a
heuristic functions, h(n)
• h(n)=estimated cost of the cheapest path form the state at
node n to a goal state
• We can consider h(n) to be arbitrary, non negative,
problem-specific functions with one contstraint: if n is a goal
node, then h(n)=0

Prof. Mukesh Singh (EIED) Artificial Intelligence 62 / 123


Greedy best-first search

• Greedy best first search tries to expand the node that is closes to the goal
• on the grounds that this is likely to lead to a solution quickly
• The evaluation function is f(n)=h(n)
• Where h(n)= estimated cost from node n to the goal
• Greedy search ignores the cost of the path that has already been tranversed to reach n
• Therefore, the solution given is not necessararily optimal.

Drawback
• Greedy best first search can start down an infinite path and never return to try other
possibilities, it is uncomplete
• Because of its greediness the search makes choices that can lead to a dead end; then
one backs up in the search tree to the deepest unexpanded node
• It resembles DFS but it will backup when it hits a dead end
• The quality of the heuristics functons determins the practical usability of the greedy
search.

Prof. Mukesh Singh (EIED) Artificial Intelligence 63 / 123


Greedy best-first search

Prof. Mukesh Singh (EIED) Artificial Intelligence 64 / 123


Pseudocode for Best First Search

Best-First-Search(Graph g, Node start)


1) Create an empty PriorityQueue
PriorityQueue pq;
2) Insert ”start” in pq.
pq.insert(start)
3) Until PriorityQueue is empty
u = PriorityQueue.DeleteMin
If u is the goal
Exit
Else
Foreach neighbor v of u
If v ”Unvisited”
Mark v ”Visited”
pq.insert(v)
Mark u ”Examined”
End procedure

Prof. Mukesh Singh (EIED) Artificial Intelligence 65 / 123


Greedy best-first search-Find the error

Let ’OPEN’ be a priority queue containing initial state


Loop
if OPEN is empty return failure
Node ¡- Remove-First (OPEN)
if Node is a Goal then return the path from initial to Node
else generate all successors of Node and
Put the newly generated Node into OPEN according to f values or (H(n))
END Loop

Prof. Mukesh Singh (EIED) Artificial Intelligence 66 / 123


Assignment on Greedy Best Search
Assignment
Given here is the map of Romania with cities and distance between them. We need to find
the shortest route from Arad to Bucharest.The heurestics that we are using here is the
straight-line distance from the city to the goal(Here, Bucharest). Note that, this straight
line distance is obtained only by knowing the map coordinates of the 2 cities.

Prof. Mukesh Singh (EIED) Artificial Intelligence 67 / 123


A* Search Algorithm

A* Search
• The most widely known form of best- first search
• It evaluates nodes by combining
• g(n), the cost to reach the node and
• h(n), the cost to get from the node to the goal
• f(n)=g(n)+h(n)
• Since g(n) gives the path cost from the start to node n, and h(n) gives the estimated
cost of the cheapest path from n to the goal
• f(n)=estimated cost of the cheapest solutions through n
The algorithm is identical to Uniform Cost Search except that A* uses g +h (instead of
only g)

Prof. Mukesh Singh (EIED) Artificial Intelligence 68 / 123


A* Search Algorithm- Example 1

Prof. Mukesh Singh (EIED) Artificial Intelligence 69 / 123


A* Search Algorithm- Example 2
Assignement
Suppose we want to use the A* algorithm on the graph below to find the shortest path from
node S to node G. Each node is labeled by a capital letter and the value of a heuristic
function. Each edge is labeled by the cost to traverse that edge. A, h=4 C, h=4 E, h=1 3 3 2, 2
S, h=6 1 1 G, h=0 3 2 B, h=4 D, h=3.5 F, h=1.
• Perform the A* algorithm on this graph.
• Indicate the f, g, and h values of each node on the queue as shown in the first two
rows of the table.
• You need not write the contents of the (priority) queue in order in the table.
• Assume that if you find a path to a node already on the queue that you update its cost
(using the lower f value) instead of adding another copy of that node to the queue.
• Show the path found by the A* algorithm on the graph above.

Prof. Mukesh Singh (EIED) Artificial Intelligence 70 / 123


A* Search Algorithm- Example 3

Prof. Mukesh Singh (EIED) Artificial Intelligence 71 / 123


A* Best Search Algorithm- Step 1

Prof. Mukesh Singh (EIED) Artificial Intelligence 72 / 123


A* Best Search Algorithm- Step 2

Prof. Mukesh Singh (EIED) Artificial Intelligence 73 / 123


A* Best Search Algorithm- Step 3

Prof. Mukesh Singh (EIED) Artificial Intelligence 74 / 123


A* Best Search Algorithm- Step 4

Prof. Mukesh Singh (EIED) Artificial Intelligence 75 / 123


A* Best Search Algorithm- Step 5

Prof. Mukesh Singh (EIED) Artificial Intelligence 76 / 123


A* Best Search Algorithm- Step 6

Prof. Mukesh Singh (EIED) Artificial Intelligence 77 / 123


A* Best Search Algorithm- Step 7

Prof. Mukesh Singh (EIED) Artificial Intelligence 78 / 123


AO* Search Algorithm

Prof. Mukesh Singh (EIED) Artificial Intelligence 79 / 123


AO* Search Algorithm....

• AO* algorithm is a best first search algorithm.


• It uses the concept of AND-OR graphs to decompose any
complex problem given into smaller set of problems which are
further solved.

• The AO* algorithm works as per eq. given below :


• f(n) = g(n) + h(n)
where,
g(n): The actual cost of traversal from initial state to the
current state.
h(n): The estimated cost of traversal from the current state to
the goal state.
f(n): The actual cost of traversal from the initial state to the
goal state.

Prof. Mukesh Singh (EIED) Artificial Intelligence 80 / 123


AO* Steps...

Prof. Mukesh Singh (EIED) Artificial Intelligence 81 / 123


AO* Steps...

Prof. Mukesh Singh (EIED) Artificial Intelligence 82 / 123


A* Vs AO*

• Both are part of informed search technique and use heuristic values to solve the
problem.
• The solution is guaranteed in both algorithm.
• A* always gives an optimal solution (shortest path with low cost)
• But It is not guaranteed to that AO* always provide an optimal solutions.
• Reason: Because AO* does not explore all the solution path once it got solution.

Key difference A* and AO*


• A* algorithm provides with the optimal solution, whereas AO* stops when it finds any
solution.
• AO* algorithm requires lesser memory compared to A* algorithm.
• AO* algorithm doesn’t go into infinite loop whereas the A* algorithm can go into an
infinite loop.

Prof. Mukesh Singh (EIED) Artificial Intelligence 83 / 123


Mini-Max Algorithm

• 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.
• It uses recursion to search through the game-tree.
• It is mostly used for game playing in AI. Such as Chess, Checkers, tic-tac-toe and
various tow-players game.
• 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.

Prof. Mukesh Singh (EIED) Artificial Intelligence 84 / 123


Mini-Max Algorithms

Prof. Mukesh Singh (EIED) Artificial Intelligence 85 / 123


Alpha beta pruning(α-β)

• Alpha-beta pruning is an optimized version of the minimax algorithm.


• In the minimax search algorithm, the number of states it has to examine are
exponential in depth of the tree (O(bd )).
• Since we cannot eliminate the exponent, However, 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.

Prof. Mukesh Singh (EIED) Artificial Intelligence 86 / 123


Alpha beta pruning

• Alpha-beta pruning can be applied at any depth of a tree, and sometimes it not only
prunes the tree leaves but also entire sub-tree. These parameters 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 +∞.

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. Condition for Alpha-beta
pruning: The main condition which required for alpha-beta pruning is: α≥β

Prof. Mukesh Singh (EIED) Artificial Intelligence 87 / 123


alpha-beta pruning- Fundamental (Minimax)

Prof. Mukesh Singh (EIED) Artificial Intelligence 88 / 123


alpha-beta pruning

Prof. Mukesh Singh (EIED) Artificial Intelligence 89 / 123


alpha-beta pruning

Prof. Mukesh Singh (EIED) Artificial Intelligence 90 / 123


Constraint Satisfaction Problem
• Constraint satisfaction is a technique where a problem is solved when its values
satisfy certain constraints or rules of the problem.
• A solution is therefore a set of values for the variables that satisfies all
constraints that is, a point in the feasible region.

Prof. Mukesh Singh (EIED) Artificial Intelligence 91 / 123


Constraint Satisfaction Problem

Prof. Mukesh Singh (EIED) Artificial Intelligence 92 / 123


Example 1: 4 Queen Problem

Prof. Mukesh Singh (EIED) Artificial Intelligence 93 / 123


Stochastic Search

Stochastic Search Techniques

Prof. Mukesh Singh (EIED) Artificial Intelligence 94 / 123


Stochastic Search Techniques
• Stochastic search techniques form the backbone of modern machine learning and
data analysis.
• Computer systems that are able to extract information from huge data sets (data
mining), to recognize patterns, to do classification, or to suggest diagnoses using
Stocahatic search techniques.
• The ability of organisms to learn and adapt to signals from their environment is one of
the core features of life.
• Technically, any adaptive system needs some kind of search operator in order to
explore a feature space which describes all possible configurations of the system.
• Stochastic Algorithms- Certain steps are based on random choices

Stochastic Search
Is an optimization algorithm which incorporate randomness in its exploration of the search
space

Evolutionary Search
Evolutionary Search is a type of Stochastic Search Techniquies

Evolutionary Search
Genetic Algorithm is a type of Evolutionary Search.

Prof. Mukesh Singh (EIED) Artificial Intelligence 95 / 123


Genetic Algorithm(GA)

• It is a non traditional optimization techniques which is based on evolutionary


algorithm.
• We try to mimic the behavior of nature.
• It is based on the survival of the fittest concept (Darwinian Theory).
• Simulates (mimic) the process of evolution
• They are not calculus based.
• It is a search techniques and any search techniques have a logic.
• Search algorithm is based on the mechanics of natural selection and natural genetics.
• It is a robust.
• For a wide variety of problems its convergence is quite a reasonable one.

Evolution is an optimizing process

Prof. Mukesh Singh (EIED) Artificial Intelligence 96 / 123


GA

Defining GA
• GA is a search technique used in computing to find true or approximate solutions to
optimization and search problems.
• They are categorized as global search heuristics.
• It is a particular class of evolutionary algorithm that use techniques inspired by
evolutionary biology such as inheritance, mutation, selection, and crossover (also
called recombination).

Why it is Robust ?
• If an air conditioner is designed for Europe it can not run in Saudi. The reason behind
is in the design of compressor.
• Mosquito: As the time changes, Mosquito will not have any effect on ’ALLOUT’.
• Biological system changes continuously to adapt the environment.

Prof. Mukesh Singh (EIED) Artificial Intelligence 97 / 123


Global and Local Maxima and Minima

Prof. Mukesh Singh (EIED) Artificial Intelligence 98 / 123


Who developed GA

• Developed by Prof. John Holland at the university of Michigan,


1979.
• David Goldberg a student of Holland wrote a book named
Genetic Algorithm in search optimization and Machine learning
in 1989.
• K. Dev, a student of Goldberg. He was a professor at IIT
Kanpur. Now he is abroad.
• There is a lab named Kangal Lab.
• K. Dev is the most cited and top 100 research scientist of
the world.

Prof. Mukesh Singh (EIED) Artificial Intelligence 99 / 123


Difference between GA and traditional optimization
methods
• GAs work with the coding of the parameter set, not the
parameter themselves.
• GAs search for a population of points, not a single point.
• GAs uses the objective function information and not the
derivative or second derivative.
• GA uses stochastic transition rules, not deterministic rules.

Concept of GA
• Genetic algorithms are implemented as a computer simulation.
• Here a population of large size where a probable solutions
exist is created.
• Traditionally, solutions are represented in binary as strings of
0s and 1s, but other encodings are also possible.
Prof. Mukesh Singh (EIED) Artificial Intelligence 100 / 123
Representation of Solutions
1)How do we represent a set of variables as a string?
Example 1
X=(x1, x2, x3, x4)
Let x1=15, x2=4, x3=21, x4=7
As a binary string, X can be written as
X=(01111, 00100, 10101, 00111)
2) Can we handle decimals or a continuous variable?
Let us say we want to represent 4.87
Multiply this by 100 which gives 487
We need 9 bits to represents 487
Because 28 represents 256 and 29 is 1111 1111 1 corresponds to
511
487 is smaller then 511 and hence 9 bits are enough to
represent 487
As our accuracy required increases; the number of bits required
will increase dramatically.
Prof. Mukesh Singh (EIED) Artificial Intelligence 101 / 123
Steps of GA

• The evolution usually starts from a population of randomly generated


individuals and happens in generations.
• In each generation, the fitness of every individual in the population is
evaluated.
• Multiple individuals are selected from the current population (based on their
fitness).
• And finally modified (recombined and possibly mutated) to form a new
population.
• The new population is then used in the next iteration of the algorithm.
• Commonly, the algorithm terminates when either a maximum number of
generations has been produced, or a satisfactory fitness level has been
reached for the population.
• If the algorithm has terminated due to a maximum number of generations, a
satisfactory solution may or may not have been reached.

Fitness is decided based on the objective function

Prof. Mukesh Singh (EIED) Artificial Intelligence 102 / 123


Representation of GA Terms

Prof. Mukesh Singh (EIED) Artificial Intelligence 103 / 123


Representation of GA Terms....

Prof. Mukesh Singh (EIED) Artificial Intelligence 104 / 123


Flow chart of GA

Prof. Mukesh Singh (EIED) Artificial Intelligence 105 / 123


Fitness Function

Prof. Mukesh Singh (EIED) Artificial Intelligence 106 / 123


Step 1: Population Initialization

• Initially, many individual solutions are randomly generated


to form an initial population.
• The population size depends on the nature of the problem,
but typically contains several hundreds or thousands of
possible solutions.
• Traditionally, the population is generated randomly, covering
the entire range of possible solutions (the search space).
• Occasionally, the solutions may be ”seeded” in areas where
optimal solutions are likely to be found.

Prof. Mukesh Singh (EIED) Artificial Intelligence 107 / 123


Step 2: Selection

• During each successive generation, a proportion of the existing


population is selected to breed a new generation.
• Individual solutions are selected through a fitness-based
process, where fitter solutions (as measured by a fitness
function) are typically more likely to be selected.
• Certain selection methods rate the fitness of each solution
and preferentially select the best solutions.
• Other methods rate only a random sample of the population,
as this process may be very time-consuming.

Prof. Mukesh Singh (EIED) Artificial Intelligence 108 / 123


Finally What Does GA Mean

• Instead of doing directly the variables we do the


manipulation with the coded variable.
• It is easier to have binary number and we can have many
combinations.
• Traditional GA have binary representation but now a days they
are using a lot many ways.
• So whenever there is stochastic situation we can decide for GA.
• Actually we use deterministic methods but using the stochastic
method we are ensuring that there should not be any
premature convergence.

Prof. Mukesh Singh (EIED) Artificial Intelligence 109 / 123


A Single Variable Problem

Example 1
Maximize(Y) = 800 - 62.83(2D+0.91D−0.2 )
where; 0 < D < 6.3

Important points
• A population of 2 to 4 trial design vectors (rather than just one)
is used initially in a problem with n design parameters(GA
works with a set of solutions)
• Each design vector (solution) is represented by a string of
binary variables, corresponding to the chromosomes in
genetics.

Prof. Mukesh Singh (EIED) Artificial Intelligence 110 / 123


Example...

Maximize(Y) = 800 - 62.83(2D+0.91D−0.2 ) where 0 < D < 6.3

6.3 multiplied by 10 = 63
26 = 64 ; it means we can represent 0 < D < 6.3 in 6 bits

Prof. Mukesh Singh (EIED) Artificial Intelligence 111 / 123


Convention of Random Numbers and Its Population

• There is 50-50 (approximately) , 0s and 1s in the random


number table.
• Say in 16 bits, if there is say 8 (0s) and/or 16(1s), then there is a
chance of premature convergence.
• Therefore, we should use random number table to find the
population string.
• The idea of developing the GA is to reduce the premature
convergence and overcome the local minima or local maxima.
• Therefore, the original solutions should be widespread so that
there should not be any chance of missing local maxima or
global maxima.
After initialization, the next step is selection

Prof. Mukesh Singh (EIED) Artificial Intelligence 112 / 123


Use of Random Numbers in GA

Prof. Mukesh Singh (EIED) Artificial Intelligence 113 / 123


Roulette Wheel selection

Fittest individual has the largest portion of the wheel; while;


weakest has the smallest portion.

Prof. Mukesh Singh (EIED) Artificial Intelligence 114 / 123


Mating Pool and Crossover

Prof. Mukesh Singh (EIED) Artificial Intelligence 115 / 123


Different types Crossover

Prof. Mukesh Singh (EIED) Artificial Intelligence 116 / 123


Iteration 3

Prof. Mukesh Singh (EIED) Artificial Intelligence 117 / 123


Mutation
• After selection and crossover, we now have a new population full of individuals.
• Some are directly copied, and others are produced by crossover.
• In order to ensure that the individuals are not all exactly the same, you allow for a
small chance of mutation.
• You loop through all the alleles of all the individuals, and if that allele is selected for
mutation, you can either change it by a small amount or replace it with a new value.
• The probability of mutation is usually between 1 and 2 tenths of a percent.
• Mutation is fairly simple. You just change the selected alleles based on what you feel is
necessary and move on.
• Mutation is, however, vital to ensuring genetic diversity within the population.

Mutation...
Mutation is a genetic operator used to maintain genetic diversity from one generation of a
population of genetic algorithm chromosomes to the next. It is analogous to biological
mutation. Mutation alters one or more gene values in a chromosome from its initial state.

Prof. Mukesh Singh (EIED) Artificial Intelligence 118 / 123


Mutation

Changes 1 to 0 and vice versa to create a point in the neighborhood


Maximum mutation 5% of the total number of bits.
Mutation is to preserve good strings, just in case crossover destroys some good properties.

In the random number table mutation can be used as


If the random number is less then 0.001 then do the mutation

Prof. Mukesh Singh (EIED) Artificial Intelligence 119 / 123


Convergence of Solution

Prof. Mukesh Singh (EIED) Artificial Intelligence 120 / 123


Example 2

Nemerical
The cost of engines plus fuel for a cargo ship (in lakhs of rupees per
year for 100 tons of cargo carried) varies with speed and is given by
0.2x2 where x is the speed of the ship in m/s. The fixed costs of hull
and crew (again in the same units) are given by 450 x . Using GA,
perform two iterations to determine the operating speed of the
ship. The original interval of uncertainty is
0.5≤x≤25.5.
One decimal accuracy is required for representing x.

Prof. Mukesh Singh (EIED) Artificial Intelligence 121 / 123


Solution

Total no of bits required is 8.


25.5 multiplied by 10. This comes to be 255.
28 is required to represent 256 , imply 8 bit is required for
representing 25.5

Prof. Mukesh Singh (EIED) Artificial Intelligence 122 / 123


Solution

Prof. Mukesh Singh (EIED) Artificial Intelligence 123 / 123

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy