Unit 2 - Aia
Unit 2 - Aia
Chapter-2
Solving Problems by Searching
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
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.
Note that there is much more to search algorithms than the chart I have provided above.
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.
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
solution (or it runs out of nodes, and goes to the next branch). The traversal is shown in
blue arrows.
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.
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.
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.
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).
Admissibility:
Strategy: Choose the node with the lowest f(x) value.
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
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.
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.
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.
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.
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.