AI Chapter 4
AI Chapter 4
Example:
We will now consider the search space, and show how breadth first search works on this graph.
Step 1: Initially fringe contains only one node corresponding to the source state A.
Fringe: A
Step 2: A is removed from fringe. The node is expanded, and its children B and C are generated. They are placed
at the back of fringe.
Fringe: B C
Step 3: Node B is removed from fringe and is expanded. Its children D, E are generated and put at the back of
fringe.
Fringe: C D E
Step 4: Node C is removed from fringe and is expanded. Its children D and G are added to the back of fringe.
Fringe: D E D G
Step 5: Node D is removed from fringe. Its children C and F are generated and added to the back of fringe.
Fringe: E D G C F
Step 6: Node E is removed from fringe. It has no children.
Fringe: D G C F
Step 7: D is expanded; B and F are put in OPEN.
Fringe: G C F B F
Step 8: G is selected for expansion. It is found to be a goal node. So the algorithm returns the path A C G by
following the parent pointers of the node corresponding to G. The algorithm terminates.
1 + b + b + ... + b = (b
(d+1)
- 1)/(b-1) nodes
Example:
Let us now run Depth First Search on the search space given above, and trace its progress.
Step 1: Initially fringe contains only the node for A.
Fringe: A
Step 2: A is removed from fringe. A is expanded and its children B and C are put in front of fringe.
Fringe: B C
Step 3: Node B is removed from fringe, and its children D and E are pushed in front of fringe.
Fringe: D E C
Step 4: Node D is removed from fringe. C and F are pushed in front of fringe.
Fringe: C F E C
Step 5: Node C is removed from fringe. Its child G is pushed in front of fringe.
Fringe: G F E C
Step 6: Node G is expanded and found to be a goal node. The solution path A-B-D-C-G is returned and the
algorithm terminates.
Fringe: G F E C
the algorithm will take time O(b ). However the space taken is linear in the depth of the search tree, O(bN).
Note that the time taken by the algorithm is related to the maximum depth of the search tree. If the search tree
has infinite depth, the algorithm may not terminate. This can happen if the search space is infinite. It can also
happen if the search space contains cycles. The latter case can be handled by checking for cycles in the
algorithm. Thus Depth First Search is not complete.
Depth First Iterative Deepening combines the advantage of BFS (i.e., completeness) with the advantages of
DFS (i.e., limited space and finds longer paths more quickly). This algorithm is generally preferred for large state
spaces where the solution depth is unknown.
Informed search strategy--one that uses problem-specific knowledge beyond the definition of the problem
itself-can find solutions more efficiently than an uninformed strategy.
Informed search strategies exploit problem-specific knowledge as much as possible to drive the search.
They are almost always more efficient than uninformed searches and often also optimal.
Heuristics
a replicable method or approach for directing one's attention in learning, discovery, or problem-solving. It
is originally derived from the Greek "heurisko", which means "I find". (A form of the same verb is found in
Archimedes' famous exclamation "eureka!" "I have found [it]!"). The term was introduced in the 4th
century AD by Pappus of Alexandria.
means rule of thumb. To quote Judea Pearl, Heuristics are criteria, methods or principles for deciding
which among several alternative courses of action promises to be the most effective in order to achieve
some goal.
used to identify the most promising search path.
stand for strategies using readily accessible, though loosely applicable, information to control problem
solving in human beings and machines.
used to come to a solution rapidly that is hoped to be close to the best possible answer, or 'optimal
solution'.
In other words, the heuristic tells us approximately how far the state is from the goal state*.
Heuristic algorithm consists of two parts:
Heuristic measure
Search algorithm
Search algorithm maintains a list of nodes called the fringe. The fringe keeps track of the nodes that have been
generated but are yet to be explored. The fringe represents the frontier of the search tree generated.
Here are a few other commonly used heuristics:
If you are having difficulty understanding a problem, try drawing a picture.
If you can't find a solution, try assuming that you have a solution and seeing what you can derive from
that ("working backward").
If the problem is abstract, try examining a concrete example.
Try solving a more general problem first (the "inventor's paradox": the more ambitious plan may have
more chances of success).
Informed search methods use problem specific knowledge, and may be more efficient. At the heart of such
algorithms there is the concept of a heuristic function.
Heuristic Function - heuristics are often obtained from relaxed problem.
A heuristic function at a node n is an estimate of the optimum cost from the current node to a goal. It is denoted
by h(n).
h(n) = estimated cost of the cheapest path from node n to a goal node
Example 1: We want a path from Arad to Bucharest
Solution: Straight-Line Distance
Greedy Search
Greedy algorithms often perform very well. They tend to find good solutions quickly, although not always optimal
ones.
The resulting algorithm is not optimal. The algorithm is also incomplete, and it may fail to find a solution even if
one exists. This can be seen by running greedy search on the following example. A good heuristic for the routefinding problem would be straight-line distance to the goal.
Greedy best-first search3 tries to expand the node that is closest to the goal, on the: grounds that this is likely to
lead to a solution quickly. Thus, it evaluates nodes by using just the heuristic function: f (n) = h(n)
h(n) estimates the distance remaining to a goal.
Figure 1 is an example of a route finding problem. S is the starting state, G is the goal state.
Figure 1
Figure 2
Let us run the greedy search algorithm for the graph given in Figure 1. The straight line distance heuristic
estimates for the nodes are shown in Figure 2.
Straight-Line Distance
Let us see how this works for route-finding problems in Romania, using the straight-line distance heuristic, which
we will call hsLD. If the goal is Bucharest, we will need to know the straight-line distances to Bucharest. For
example, hsLD(In(Arad)=) 366. Notice that the values of hsLD cannot be computed from the problem description
itself. Moreover, it takes a certain amount of experience to know that hsLD is correlated with actual road distances
and is, therefore, a useful heuristic.
Stages in a greedy best-first search for Bucharest using the straight-line distance
heuristic hsto. Nodes are labeled with their h-values.
Our first edition called this greedy search; other authors have called it best-first search. Our mare general
usage of the latter tern follows Pearl (1984).
Manhattan Distance Heuristic. Another heuristic for 8-puzzle is the Manhattan distance heuristic. This heuristic
sums the distance that the tiles are out of place. The distance of a tile is measured by the sum of the differences
in the x-positions and the y-positions. Manhattan distance is always >= exact heuristic, we can find path that
close to best path but the application runs fast.
Example: 8-puzzle: Misplaced Tiles Heuristics is the number of tiles out of place.
The first picture shows the current state n, and the second picture the goal state.
h1(n) = number of misplaced tiles
h2(n) = total Manhattan distance (i.e., number of squares from desired location of each tile)
h(n) = 5 because the tiles 2, 8, 1, 6 and 7 are out of place.
For the above example, using the Manhattan distance heuristic, h(n) = 1 + 1 + 0 + 0 + 0 + 1 + 1 + 2 = 6
Symmetry Reductions. The state explosion problem is the main limitation of model checking. Symmetries in the
system being verified can be exploited in order to avoid this problem by defining an equivalence (symmetry)
relation on the states of the system, which induces a semantically equivalent quotient system of smaller size. On
the other hand, heuristic search algorithms can be applied to improve the bug finding capabilities of model
checking.
Example: Tic-Tac-Toe
This is a game that involves two players who play alternately. Player one puts a X in an empty position. Player 2
places an O in an unoccupied position. The player who can first get three of his symbols in the same row, column
or diagonal wins. A portion of the state space of tic-tac-toe is depicted below.
Uniform Cost Search is a special case of the best first search algorithm. The algorithm maintains a
priority queue of nodes to be explored. A cost function f(n) is applied to each node. Nodes with smaller
f(n) values are expanded earlier.
10
There is a whole family of BEST-FIRST-SEARCH algorithms with different evaluation functions.' A key
component of these algorithms is a heuristic function, noted h(n):
h(n) = estimated cost of the cheapest path from node n to a goal node.
We will now consider different ways of defining the function f. This leads to different search algorithms.
Hill Climbing
A* Search
In computer science, A* (pronounced "A star") is a computer algorithm that is widely used in path-finding and
graph traversal, the process of plotting an efficiently traversable path between points, called nodes. Noted for its
performance and accuracy, it enjoys widespread use. Peter Hart, Nils Nilsson, and Bertram Raphael first
described the algorithm in 1968. It is an extension of Edsger Dijkstra's 1959 algorithm. A* achieves better
performance (with respect to time) by using heuristics.
A* algorithm
f(n) = g(n) + h(n)
where:
g(n) is the cost to get to a node.
sum of edge costs from start to n
cost of going from the starting state to state n
h(n) is the estimated distance to the goal
estimate of lowest cost path from n to goal
11
heuristic estimate of the cost of going from state n to the goal state
f(n) actual distance so far + estimated distance remaining
We can think of f(n) as the estimated cost of the cheapest solution that goes through node n. We can prove that if
h(n) is admissible, then the search will find an optimal solution.
If the path does not matter we can deal with local search.
They use a single current state
Move only to neighbors of that state
Advantages:
Use very little memory
Often find reasonable solutions
It helps to see a state space landscape
Find global maximum or minimum
Complete search: Always finds a goal
Optimal search: Finds global maximum or minimum.
Example: Hill Climbing, local beam search, genetic algorithms,
Hill Climbing:
12
Agent knowledge:
ACTION(s): list of allowed actions in state s
C(s,a,s): step-cost function (! After s is determined)
GOAL-TEST(s)
An agent can recognize previous states
Actions are deterministic
Access to admissible heuristic h(s), e.g. Manhattan distance
Objective: reach goal with minimal cost
Cost = total cost of traveled path
Competitive ratio = comparison of cost with cost of the solution
path if search space is known.
Can be infinite in case of the agent accidentally reaches dead
ends
* An online version can only expand the node it is physically in (local order).
13
Real Problems
Route finding
Touring problems: traveling salesman, delivery tour
Traveling Salesman Problem (TSP): Given a route of cities, visit each city exactly once while minimizing distance
traveled.
Vehicle Routine Problem (VRP): Similar. Given one or more vehicles, visit each city at most once starting
and returning to a depot(s).
Scheduling and planning
Theorem proving
Configuration Problems: Given a set of components and constraints on their (spatial) relationships,
arrange the components to variously minimize interconnections, maximize number of components, etc.
(example: VLSI layout).
VLSI layout
VLSI layout: positioning millions of components and connections on a chip (minimizing area, circuit delays, stray
capacitance, . . . )
Speech recognition
Model based vision
Robot Planning: Given a real robot and a goal of getting from point A to point B, find a plan which
minimizes distance/time traveled and succeeds.
Robot navigation: no discrete sets of routes, continuous space
Automatic assembly sequence: find an order in which to assemble parts of an object
Protein design: find a sequence of amino acids that will fold into three-dimensional protein with right
properties
Internet searching: looking for relevant information on the Web
Note: All above are Constraint Optimization Problems which are known to be NP-complete.