0% found this document useful (0 votes)
740 views

AI Chapter 4

The document discusses various search algorithms used in artificial intelligence, including: 1. Uninformed search methods like breadth-first search (BFS) and depth-first search (DFS) that do not use problem-specific knowledge. BFS explores shallow nodes first while DFS explores deep nodes first. 2. Informed search methods like greedy best-first search and A* search that use heuristic functions to guide the search towards promising solutions. Greedy search selects the node with the lowest estimated cost at each step. 3. The use of heuristics to estimate the cost of reaching the goal from the current node. Good heuristics can help informed search methods find solutions more efficiently than uninformed searches.

Uploaded by

Antonio Peji Jr
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
740 views

AI Chapter 4

The document discusses various search algorithms used in artificial intelligence, including: 1. Uninformed search methods like breadth-first search (BFS) and depth-first search (DFS) that do not use problem-specific knowledge. BFS explores shallow nodes first while DFS explores deep nodes first. 2. Informed search methods like greedy best-first search and A* search that use heuristic functions to guide the search towards promising solutions. Greedy search selects the node with the lowest estimated cost at each step. 3. The use of heuristics to estimate the cost of reaching the goal from the current node. Good heuristics can help informed search methods find solutions more efficiently than uninformed searches.

Uploaded by

Antonio Peji Jr
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

ARTIFICIAL INTELLIGENCE (A. I.

LECTURE 4: Uninformed Search, Informed Search and Exploration


Uninformed Search
Blind search or uninformed search does not use any extra information about the problem domain. The two
common methods of blind search are:
1. BFS or Breadth First Search FIFO
2. DFS or Depth First Search LIFO

1. Breadth First Search


Breadth first search the newly generated nodes are put at the back of fringe or the OPEN list. What this implies
is that the nodes will be expanded in a First In First Out (FIFO) order. The node that enters OPEN earlier will be
expanded earlier. This amounts to expanding the shallowest nodes first.

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.

ARTIFICIAL INTELLIGENCE (A. I.)

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.

ARTIFICIAL INTELLIGENCE (A. I.)

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.

Properties of Breadth-First Search


Breadth first search is:
Complete.
The algorithm is optimal (i.e., admissible) if all operators have the same
cost. Otherwise, breadth first search finds a solution with the shortest
path length.
The algorithm has exponential time and space complexity. Suppose the
search tree can be modeled as a b-ary tree as shown in Step 1 (graph).
Then the time and space complexity of the algorithm is O(bd) where d is
the depth of the solution and b is the branching factor (i.e., number of
children) at each node.
A complete search tree of depth d where each non-leaf node has b children, has a total of
2

1 + b + b + ... + b = (b

(d+1)

- 1)/(b-1) nodes

Advantages of Breadth First Search:


Finds the path of minimal length to the goal.
Disadvantages of Breadth First Search:
Requires the generation and storage of a tree whose size is exponential the depth of the shallowest goal
node.

2. Depth First Search


Depth first search algorithm puts newly generated nodes in the front of OPEN. This results in expanding the
deepest node first. Thus the nodes in OPEN follow a Last In First Out (LIFO) order. OPEN is thus implemented
using a stack data structure.

ARTIFICIAL INTELLIGENCE (A. I.)

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.

ARTIFICIAL INTELLIGENCE (A. I.)

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

Properties of Depth First Search


The algorithm takes exponential time. If N is the maximum depth of a node in the search space, in the worst case
d

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 Limited Search


A variation of Depth First Search circumvents the above problem by keeping a depth bound. Nodes are only
expanded if they have depth less than the bound. This algorithm is known as depth-limited search.
Advantages:
Linear memory requirements of depth-first search
Guarantee for goal node of minimal depth
Procedure:
Successive depth-first searches are conducted each with depth bounds increasing by 1

Depth First Iterative Deepening

ARTIFICIAL INTELLIGENCE (A. I.)

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 Strategies

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.

ARTIFICIAL INTELLIGENCE (A. I.)

Simplify the original problem by removing constraints


The cost of an optimal solution to a relaxed problem is an admissible heuristic.

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.

Step 1: S is expanded. Its children are A and D.

Step 2: D has smaller cost and is expanded next.

ARTIFICIAL INTELLIGENCE (A. I.)

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.

Values of hSLD-straight-line distances to Bucharest .

Stages in a greedy best-first search for Bucharest using the straight-line distance
heuristic hsto. Nodes are labeled with their h-values.

ARTIFICIAL INTELLIGENCE (A. I.)

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.

Best First Search

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.

ARTIFICIAL INTELLIGENCE (A. I.)

10

Best-first search is an instance of the general TREE-SEARCH or GRAPH-SEARCH algorithm in which a


node is EVALUATION FUNCTION selected for expansion based on an evaluation function, f (n).
The name "best-first search" is a venerable but inaccurate one. Nevertheless, we will stick with the name
"best-first search," because "seemingly-best-first search" is a little awkward.

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.

Uniform Cost Search


In Uniform Cost Search (UCS), we enqueue nodes by path cost. Let g(n) = cost of the path from the start node to
the current node n. The algorithm sorts nodes by increasing value of g, and expands the lowest cost node of the
fringe.
Properties of Uniform Cost Search:
Complete
Optimal/Admissible
Exponential time and space complexity, O(bd)
The UCS algorithm uses the value of g(n) to select the order of node expansion. We will now introduce informed
search or heuristic search that uses problem specific heuristic information. The heuristic will be used to select the
order of node expansion.
Example: Hill Climbing
Uniform Cost

Hill Climbing

Measures the cost to each node.


Is optimal and complete!
Can be very slow.

Estimates how far away the goal is.


Is neither optimal nor complete.
Can be very fast.

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

ARTIFICIAL INTELLIGENCE (A. I.)

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.

The path returned is A-B-C-F-H.


The path cost is 39. This is an optimal path.

Informal proof outline of A* completeness:


Assume that every operator has some minimum positive cost, epsilon.
Assume that a goal state exists, therefore some finite set of operators lead to it.
Expanding nodes produces paths whose actual costs increase by at least epsilon each time. Since the
algorithm will not terminate until it finds a goal state, it must expand a goal state in finite time.
Informal proof outline of A* optimality:
When A* terminates, it has found a goal state
All remaining nodes have an estimate cost to goal (f(n)) greater than or equal to that of goal we have
found.
Since the heuristic function was optimistic, the actual cost to goal for these other paths can be no better
than the cost of the one we have already found.

Local Search Algorithms

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:

ARTIFICIAL INTELLIGENCE (A. I.)

12

Moves in the direction of increasing value.


Terminates when it reaches a peak.
Does not look beyond immediate neighbors.

Can get stuck for some reasons:


a. Local maxima - a local maximum is a peak that is higher than
each of its neighboring states, but lowers than the global
maximum. H[ill-climbing algorithms that reach the vicinity of a local
maximum will be drawn upwards towards the peak, but will then be
stuck with nowhere else to go.
Example: 8-queens a local maximum (i.e., a local minimum for the
cost h); every move of a single queen makes the situation worse.
b. Ridges - result in a sequence of local maxima that is very difficult
for greedy algorithms to navigate.
c.

Plateaux - is an area of the state space landscape where the


evaluation function is flat. It can be a flat local maximum, from
which no uphill exit exists, or a shoulder, from which it is possible
to make progress. A hill-climbing search might be unable to find
its way off the plateau.

Illustration of why ridges cause difficulties


for hill-climbing. The grid of states (dark
circles) is superimposed on a ridge rising
from left to right, creating a sequence of
local maxima that are not directly
connected to each other. From each
local maximum, all the available actions
point downhill.

Online Search Problems

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

Online Search Agents

The agent maintains a map of the environment.


Updated based on percept input.
This map is used to decide next action.

* An online version can only expand the node it is physically in (local order).

Online Local Search

ARTIFICIAL INTELLIGENCE (A. I.)

Hill-climbing is already online


One state is stored.

Bad performance due to local maxima


Random restarts impossible.

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.

You might also like