0% found this document useful (0 votes)
38 views15 pages

Unit 2 - Aia

AIA NOTES

Uploaded by

Padmanabhan .s
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)
38 views15 pages

Unit 2 - Aia

AIA NOTES

Uploaded by

Padmanabhan .s
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/ 15

1

Chapter-2
Solving Problems by Searching

problem solving agent


•A problem-solving agent is a goal-based agent and use atomic representations.
•In atomic representations, states of the world are considered as wholes, with no internal
structure visible to
the problem solving algorithms.
•Intelligent agents are supposed to maximize their performance measure. Achieving this is
sometimes simplified if the agent can adopt a goal and aim at satisfying it.
•A problem-solving agent has three phases:
problem formulation, searching solution and executing actions in the solution.
•Problem formulation is the process of deciding what actions and states to consider.
•The process of looking for a sequence of actions that reaches the goal is called search.
•A search algorithm takes a problem as input and returns a solution in the form of an action
sequence.
•Once a solution is found, the carrying actions it recommends is called the execution phase.

A problem can be defined by five components:


•initial state, actions, transition model, goal test, path cost.
INITIAL STATE: The initial state that the agent starts in.
ACTIONS: A description of the possible actions available to the agent.
•Given a particular state s,
ACTIONS(s) returns the set of actions that can be executed in s.
•Each of these actions are applicable in s.
TRANSITION MODEL: A description of what each action does is known as the transition
model
•A function RESULT(s,a) that returns the state that results from doing action a in state s.
•The term successor to refer to any state reachable from a given state by a single
•The state space of the problem is the set of all states reachable from the initial state by any
sequence
of actions.
•The state space forms a graph in which the nodes are states and the links between nodes are
actions.
•A path in the state space is a sequence of states connected by a sequence of actions.
GOAL TEST: The goal test determines whether a given state is a goal state.
PATH COST: A path cost function that assigns a numeric cost to each path.
•The problem-solving agent chooses a cost function that reflects its own performance
measure.
•The cost of a path can be described as the sum of the costs of the individual actions along the
path.
•The step cost of taking action a in state s to reach state s′ is denoted by c(s, a, s′).

Dept. od CS, KFGSC


2

A SOLUTION to a problem is an action sequence that leads from the initial state to a goal
state.
•Solution quality is measured by the path cost function, and an OPTIMAL SOLUTION has
the lowest path cost among all solutions.
Example problem:
There are 2 kinds of problem
1. Toy problem
2. Real-world problem
Toy problem: it is a concise and exact description of the problem which is used by the
researchers to compare the performance of algorithms.
Ex: 8-puzzle problem
•The 8-puzzle consists of a 3×3 board with eight numbered tiles and a blank space.
•A tile adjacent to the blank space can slide into the space.
•The object is to reach a specified goal state.

States: A state specifies the location of each of the eight tiles and the blank in one of the nine
squares.
Initial state: Any state can be designated as the initial state.
•Note that goal can be reached from exactly half of the possible initial states.
Actions: Movements of the blank space Left, Right, Up, or Down.
•Different subsets of these are possible depending on where the blank is. Transition model:
Given a state and action, this returns the resulting state; Goal test: This checks whether the
state matches the goal configuration
Path Cost: Each step costs 1, so the path cost is the number of steps in the path.
•The 8-puzzle belongs to the family of sliding-block puzzles, This family is known to be NP-
complete.
•Optimal solution of n-Puzzle family is NP-hard. ie NO polynomial solution for the problem.
•The 8-puzzle has 9!/2=181, 440 reachable states.
•The 15-puzzle (on a 4×4 board) has around 1.3 trillion states,
•The 24-puzzle (on a 5 × 5 board) has around 1025 states

Dept. od CS, KFGSC


3

Real-world problem: it is a real world based problem which require solutions. It does not
depend on descriptions, but we can have a general formulation of the problem.
Example:
•Route-finding problem is defined in terms of specified locations and transitions along links
between
them.
•Route-finding algorithms are used in a variety of applications such as Web sites and in-car
systems
that provide driving directions.
•VLSI layout problem requires positioning millions of components and connections on a
chip to minimize area, minimize circuit delays, minimize stray capacitances, and maximize
manufacturing yield.

Searching for solutions:


•A solution is an action sequence and search algorithms considers various possible action
sequences.
•The possible action sequences starting at the initial state form a search tree with the initial
state at the root;
•The branches are actions and the nodes correspond to states in the state space of the
problem.
•Expanding the current state is application of each legal action to the current state and
generation of a new set of states.
•The current state is the parent node, newly generated states are child nodes
•Leaf node is a node with no children in the tree.
•The set of all leaf nodes available for expansion at any given point is called the frontier.
•Search algorithms all share this basic structure; they vary primarily according to how they
choose which state to expand next: search strategy.
Infrastructure for Search Algorithms
•Search algorithms require a data structure to keep track of the search tree that is being
constructed.
Each node n of the tree contains four components:
n.STATE: the state in the state space to which the node corresponds;
n.PARENT: the node in the search tree that generated this node;
n.ACTION: the action that was applied to the parent to generate the node;
n.PATH-COST: the cost of the path from the initial state to the node.

Dept. od CS, KFGSC


4

Searching for solutions:


Informal description of graph search problems:
function GRAPH-SEARCH(problem) returns a solution, or failure
step1: initialize frontier using initial state of problem
step 2: initialize explored set to be empty
step 3: loop do
if frontier is empty then return failure
else
choose a leaf node from frontier and remove it from there
step 4: if node contains a goal state then return corresponding solution and add node to
explored set
step 5: expand node, adding resulting nodes to frontier only if not in frontier or explored set.

•To avoid exploring redundant paths is to remember them.


•Explored set (also known as closed list) remembers every expanded node.
•The frontier needs to be stored in such a way that search algorithm can easily choose next
node to expand according to its preferred strategy.
•The appropriate data structure for this is a queue.
•Queues are characterized by the order in which they store the inserted nodes.
•First-in, first-out or FIFO queue, which pops the oldest element of the queue; (QUEUE)
•Last-in, first-out or LIFO queue (also known as STACK), which pops the newest element
PRIORITY QUEUE, which pops the element of the queue with the highest priorit according
to some ordering function.
•The explored set can be implemented with a hash table to allow efficient checking for
repeated states.

Dept. od CS, KFGSC


5

Measuring problem-solving performance:


We can evaluate a search algorithm’s performance in four ways:
Completeness: Is the algorithm guaranteed to find a solution when there is one?
Optimality: Does the strategy find the optimal solution?
Time complexity: How long does it take to find a solution?
Space complexity: How much memory is needed to perform the search?
•The typical measure for time and space complexity is the size of the state space graph, |V | +
|E|,
where V is the set of vertices (nodes) of the graph and E is the set of edges (links). This is
appropriate when the graph is an explicit data structure. In AI, graph is often represented
implicitly by the initial state, actions, and transition model and is frequently infinite.
For these reasons, complexity is expressed in terms of three quantities:
b - maximum branching factor of the search tree
d - depth of the least-cost solution
m - maximum depth of the state space (may be ∞)
Time is often measured in terms of the number of nodes generated during the search, and
space in terms of the maximum number of nodes stored in memory.

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.

Types of search algorithms:


There are far too many powerful search algorithms out there to fit in a single article.
Instead, this article will discuss six of the fundamental search algorithms, divided
into two categories, as shown below.

Note that there is much more to search algorithms than the chart I have provided above.

Dept. od CS, KFGSC


6

Uninformed Search Algorithms:


The search algorithms in this section have no additional information on the goal node other
than the one provided in the problem definition. The plans to reach the goal state from the
start state differ only by the order and/or length of actions. Uninformed search is also
called Blind search. These algorithms can only generate the successors and differentiate
between the goal state and non goal state.

The following uninformed search algorithms are discussed in this section.


1. Depth First Search
2. Breadth First Search
3. Uniform Cost Search
Each of these algorithms will have:
 A problem graph, containing the start node S and the goal node G.
 A strategy, describing the manner in which the graph will be traversed to get to
G.
 A fringe, which is a data structure used to store all the possible states (nodes)
that you can go from the current states.
 A tree, that results while traversing to the goal node.
 A solution plan, which the sequence of nodes from S to G.

Depth First Search:


Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data
structures. The algorithm starts at the root node (selecting some arbitrary node as the root
node in the case of a graph) and explores as far as possible along each branch before
backtracking. It uses last in- first-out strategy and hence it is implemented using a stack.
Example:
Which solution would DFS find to move from node S to node G if run on the graph below?

Solution. The equivalent search tree for the above graph is as follows. As DFS traverses
the tree “deepest node first”, it would always pick the deeper branch until it reaches the
solution (or it runs out of nodes, and goes to the next branch). The traversal is shown in
blue arrows.

Dept. od CS, KFGSC


7

Path: S -> A -> B -> C -> G


d= the depth of the search tree = the number of levels of the search tree.
ni= number of nodes in level i.

Time complexity: Equivalent to the number of nodes traversed in

DFS.
Space complexity: Equivalent to how large can the fringe get.
Completeness: DFS is complete if the search tree is finite, meaning for a given finite search
tree, DFS will come up with a solution if it exists.
Optimality: DFS is not optimal, meaning the number of steps in reaching the solution, or
the cost spent in reaching it is high.
Breadth First Search:
Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data
structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to
as a ‘search key’), and explores all of the neighbor nodes at the present depth prior to
moving on to the nodes at the next depth level. It is implemented using a queue.

Example:
Which solution would BFS find to move from node S to node G if run on the graph below?

Solution. The equivalent search tree for the above graph is as follows. As BFS traverses the
tree “shallowest node first”, it would always pick the shallower branch until it reaches the

Dept. od CS, KFGSC


8

solution (or it runs out of nodes, and goes to the next branch). The traversal is shown in
blue arrows.

Path: S -> D -> G


S= the depth of the shallowest solution.
ni = number of nodes in level i.
Time complexity: Equivalent to the number of nodes traversed in BFS until the shallowest
solution. T(n)=1+n2+n3+….ns i.e O(ns)
Space complexity: Equivalent to how large can the fringe set. S(n)=O(ns)
Completeness: BFS is complete, meaning for a given search tree, BFS will come up with a
solution if it exists.
Optimality: BFS is optimal as long as the costs of all edges are equal.

Uniform Cost Search:


UCS is different from BFS and DFS because here the costs come into play. In other words,
traversing via different edges might not have the same cost. The goal is to find a path where
the cumulative sum of costs is the least.

Cost of a node is defined as:

cost(node) = cumulative cost of all nodes from root


cost(root) = 0
Example:
Which solution would UCS find to move from node S to node G if run on the graph below?

Dept. od CS, KFGSC


9

Solution: The equivalent search tree for the above graph is as follows. The cost of each
node is the cumulative cost of reaching that node from the root. Based on the UCS strategy,
the path with the least cumulative cost is chosen. Note that due to the many options in the
fringe, the algorithm explores most of them so long as their cost is low, and discards them
when a lower-cost path is found; these discarded traversals are not shown below. The actual
traversal is shown in blue.

Advantages:
 UCS is complete only if states are finite and there should be no loop with zero
weight.
 UCS is optimal only if there is no negative cost.
Disadvantages:
 Explores options in every “direction”.
 No information on goal location.

Informed Search Algorithms:


Here, the algorithms have information on the goal state, which helps in more efficient
searching. This information is obtained by something called a heuristic.
In this section, we will discuss the following search algorithms.
1. Greedy Search
2. A* Tree Search
3. A* Graph Search
4. Bidirectional search

Dept. od CS, KFGSC


10

Search Heuristics: In an informed search, a heuristic is a function that estimates how close
a state is to the goal state. For example – Manhattan distance, Euclidean distance, etc.
(Lesser the distance, closer the goal.) Different heuristics are used in different informed
algorithms discussed below.

Greedy Best First Search:


In greedy search, we expand the node closest to the goal node. The “closeness” is estimated
by a heuristic h(x).

Heuristic: A heuristic h is defined as-


h(x) = Estimate of distance of node x from the goal node.
Lower the value of h(x), closer is the node from the goal.

Strategy: Expand the node closest to the goal state, i.e. expand the node with a lower h
value.
Example:
Find the path from S to G using greedy search. The heuristic values h of each node below
the name of the node.

Solution: Starting from S, we can traverse to A(h=9) or D(h=5). We choose D, as it has the
lower heuristic cost. Now from D, we can move to B(h=4) or E(h=3). We choose E with a
lower heuristic cost. Finally, from E, we go to G(h=0). This entire traversal is shown in the
search tree below, in blue.

Path: S -> D -> E -> G


Advantage: Works well with informed search problems, with fewer steps to reach a goal.
Disadvantage: Can turn into unguided DFS in the worst case.

Dept. od CS, KFGSC


11

A* Tree Search:
A* Tree Search, or simply known as A* Search, combines the strengths of uniform-cost
search and greedy search. In this search, the heuristic is the summation of the cost in UCS,
denoted by g(x), and the cost in the greedy search, denoted by h(x). The summed cost is
denoted by f(x).

Heuristic: The following points should be noted wrt heuristics in A*


search.
 Here, h(x) is called the forward cost and is an estimate of the distance of the
current node from the goal node.
 And, g(x) is called the backward cost and is the cumulative cost of a node from
the root node.
 A* search is optimal only when for all nodes, the forward cost for a node h(x)
underestimates the actual cost h*(x) to reach the goal. This property
of A* heuristic is called admissibility.

Admissibility:
Strategy: Choose the node with the lowest f(x) value.

Example: Find the path to reach from S to G using A* search.

Solution. Starting from S, the algorithm computes g(x) + h(x) for all nodes in the fringe at
each step, choosing the node with the lowest sum. The entire work is shown in the table
below.

Note that in the fourth set of iterations, we get two paths with equal summed cost f(x), so
we expand them both in the next set. The path with a lower cost on further expansion is the
chosen path.
Path h(x) g(x) f(x)
S 7 0 7

S -> A 9 3 12

S -> D 5 2 7

S -> D -> B 4 2+1=3 7


S -> D -> E 3 2+4=6 9

Dept. od CS, KFGSC


12

S -> D -> B -> C 2 3+2=5 7

S -> D -> B -> E 3 3+1=4 7

S -> D -> B -> C -> G 0 5+4=9 9

S -> D -> B -> E -> G 0 4+3=7 7


Path: S -> D -> B -> E -> G
Cost: 7

A* Graph Search:
 A* tree search works well, except that it takes time re-exploring the branches it
has already explored. In other words, if the same node has expanded twice in
different branches of the search tree, A* search might explore both of those
branches, thus wasting time
 A* Graph Search, or simply Graph Search, removes this limitation by adding
this rule: do not expand the same node more than once.
 Heuristic. Graph search is optimal only when the forward cost between two
successive nodes A and B, given by h(A) – h (B), is less than or equal to the
backward cost between those two nodes g(A -> B). This property of the graph
search heuristic is called consistency.
Consistency:

Example: Use graph searches to find paths from S to G in the following graph.

Solution: We solve this question pretty much the same way we solved last question, but in
this case, we keep a track of nodes explored so that we don’t re-explore them.

Dept. od CS, KFGSC


13

Path: S -> D -> B -> E -> G


Cost: 7

Bidirectional search: In normal graph search using BFS/DFS we begin our search in one
direction usually from source vertex toward the goal vertex, but what if we start search
from both direction simultaneously.
Bidirectional search is a graph search algorithm which find smallest path from source to
goal vertex. It runs two simultaneous search –
1. Forward search from source/initial vertex toward goal vertex
2. 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.

Example:

Suppose we want to find if there exists a path from vertex 0 to vertex 14. Here we can
execute two searches, one from vertex 0 and other from vertex 14. When both forward and
backward search meet at vertex 7, we know that we have found a path from node 0 to 14
and search can be terminated now. We can clearly see that we have successfully avoided
unnecessary exploration.

Dept. od CS, KFGSC


14

 Completeness : Bidirectional search is complete if BFS is used in both searches.


 Optimality : It is optimal if BFS is used for search and paths have uniform cost.
 Time and Space Complexity : Time and space complexity is O(bd/2).

AO* search

The AO* method divides any given difficult problem into a smaller group of problems
that are then resolved using the AND-OR graph concept. 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.

The start state and the target state are already known in the knowledge-based search
strategy known as the AO* algorithm, and the best path is identified by heuristics. The
informed search technique considerably reduces the algorithm’s time complexity. The
AO* algorithm is far more effective in searching AND-OR trees than the A* algorithm.

Dept. od CS, KFGSC


15

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.

Difference between the A* Algorithm and AO* algorithm


 A* algorithm and AO* algorithm both works on the best first search.
 They are both informed search and works on given heuristics values.
 A* always gives the optimal solution but AO* doesn’t guarantee to give the
optimal solution.
 Once AO* got a solution doesn’t explore all possible paths but A* explores all
paths.
 When compared to the A* algorithm, the AO* algorithm uses less memory.
 opposite to the A* algorithm, the AO* algorithm cannot go into an endless loop.

Heuristic functions
it is a informed search function that finds the most promising path. It input the current state
of the agent and produces output as the estimation of how close agent is from the goal. This
method may not always give the best solution, but it ensure to find a good solution in
reusable time. It estimates how close a state to the goal and also calculate the cost of an
optimal path between the pair of states. It is denoted by h(n), its value always be positive.

Admissibility of the heuristic function is given as:


h(n) <= h*(n) heuristic cost should be less than or equal to estimated cost.
where,
h(n) is heuristic cost
h*(n) is the estimated cost

Pure Heuristic Search


it is the simplest form of heuristic search algorithms. Based on the heuristic value h(n) the
nodes will be expanded.
It maintains 2 lists such as OPEN and CLOSED list
CLOSED LIST: it places those nodes which have already expanded.
OPEN LIST: : it places those nodes which have not yet been expanded.

On each iteration, each node n of the lowest heuristic value is expanded and generates all
its successors and node n is placed to the CLOSED list. The algorithm continues until the
goal state is found.

Dept. od CS, KFGSC

You might also like