0% found this document useful (0 votes)
99 views87 pages

MODULE 1 Part B PDF

The document summarizes key concepts related to problem solving agents. It discusses three types of agent representations - atomic, factored, and structured. It also describes the problem solving process agents use, including goal formulation, problem formulation through abstraction, and searching for a solution. Finally, it provides examples of toy and real-world problems agents may solve.

Uploaded by

Vinay B R
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)
99 views87 pages

MODULE 1 Part B PDF

The document summarizes key concepts related to problem solving agents. It discusses three types of agent representations - atomic, factored, and structured. It also describes the problem solving process agents use, including goal formulation, problem formulation through abstraction, and searching for a solution. Finally, it provides examples of toy and real-world problems agents may solve.

Uploaded by

Vinay B R
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/ 87

MODULE 1

SOLVING PROBLEMS FOR


SEARCHING
Prepared By,
Silpa Ajith Kumar
PROBLEM SOLVING AGENTS

Introduction
• Problem solving agent is a goal based agent
• Problem solving agents use atomic representations
• An agent is a thing that can be viewed as:
– perceiving its environment through sensors and
– acting upon that environment through actuators.

• Agent’s organization

a) Atomic Representation: In this representation, each state of the world is


a black box that has no internal structure. E.g., finding each state is a city.
AI algorithms: search, games, Markov decision processes, hidden Markov
models, etc.
b) Factored Representation: In this representation, each
state has some attribute value properties. E.g., GPS
location, amount of gas in the tank.
AI algorithms: constraint satisfaction, and Bayesian
networks.

c) Structured Representation: Relationships between the


objects of a state can be explicitly expressed.
AI algorithms: first-order logic, knowledge-based
learning, natural language understanding.
• Goal based agents that use more advanced factored or
structured representations are called planning
agents
PROBLEM SOLVING AGENTS
• 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
• Let us first look at why and how an agent might do this
• Imagine our agent in the city of Arad, Romania, toward the end
of a touring holiday. The agent has a ticket to fly out of Bucharest
the following day. The ticket is nonrefundable, the agent's visa is
about to expire, and after tomorrow, there are no seats available
for six weeks. Now the agent's performance measure contains
many other factors besides the cost of the ticket and the.
undesirability of being arrested and deported. For example, it
wants to improve its suntan, improve its Romanian, take in the
sights, and so on. All these factors might suggest any of a vast
array of possible actions
• Given the seriousness of the situation, however, it should adopt
the goal of driving to Bucharest
• Actions that result in a failure to reach Bucharest on time can be
rejected without further consideration
• Goals such as this help organize behavior by limiting the
objectives that the agent is trying to achieve.
• Goal formulation, based on the current situation, is the first step
in problem solving.
• As well as formulating a goal, the agent may wish to decide on
some other factors that affect the desirability of different ways of
achieving the goal.
• We will consider a goal to be a set of world states—just those
states in which the goal is satisfied. Actions can be viewed as
causing transitions between world states, so obviously the agent
has to find out which actions will get it to a goal state.
• Before it can do this, it needs to decide what sorts of actions and
states to consider. If it were to try to consider actions at the level
of "move the left foot forward 18 inches" or "turn the steering
wheel six degrees left," it would never find its way out of the
parking lot, let alone to Bucharest, because constructing a
solution at that level of detail would be an intractable problem.
• Problem formulation is the process of deciding what actions and
states to consider, and follows goal formulation.
• We will discuss this process in more detail. For now, let us
assume that the agent will consider actions at the level of driving
from one major town to another. The states it will consider
therefore correspond to being in a particular town.'
• Our agent has now adopted the goal of driving to
Bucharest, and is considering which town to drive to
from Arad.
• There are three roads out of Arad, one toward Sibiu,
one to Timisoara, and one to Zerind.
• None of these achieves the goal, so unless the agent is
very familiar with the geography of Romania, it will
not know which road to follow.
• In other words, the agent will not know which of its
possible actions is best, because it does not know
enough about the state that j results from taking each
action. If the agent has no additional knowledge, then it
is stuck.
• 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 the solution is found, the actions it recommends
can be carried out. This is called the execution phase.
• Thus, we have a simple ―formulate, search ,execute ‖
design for the agent as shown in figure 3.1
• After formulating a goal and a problem to solve ,the
agent calls a search procedure to solve it
WELL-DEFINED PROBLEMS AND SOLUTIONS
• A problem is really a collection of information that the agent
will use to decide what to do. We will begin by specifying the
information needed to define a single-state problem.
• We have seen that the basic elements of a problem definition
are the states and actions. To capture these formally, we need
the following:
• The initial state that the agent knows itself to be in.
• The set of possible actions available to the agent. The term
operator is used to denote the description of an action in terms
of which state will be reached by carrying out the action in a
particular state. (An alternate formulation uses a successor
function S.
• Given a particular state x, S(x) returns the set of states
reachable from x by any single action.)
• Together, these define the state space of the problem: the set of
all states reachable from the initial state by any sequence of
actions.
• A path in the state space is simply any sequence of actions
leading from one state to another.
• The next element of a problem is the following:
• The goal test, which the agent can apply to a single state
description to determine if it is a goal state. Sometimes there is an
explicit set of possible goal states, and the test simply checks to
see if we have reached one of them.
• Sometimes the goal is specified by an abstract property rather
than an explicitly enumerated set of states. For example, in
chess, the goal is to reach a state called "checkmate," where
the opponent's king can be captured on the next move no
matter what the opponent does.
• Finally, it may be the case that one solution is preferable to
another, even though they both reach the goal.
• For example, we might prefer paths with fewer or less costly
actions.
• A path cost function is a function that assigns a cost to a path.
• In all cases we will consider, the cost of a path is the sum of
the costs of the individual actions along the path.
• The path cost function is often denoted by g.
FORMULATING PROBLEMS
• In the previous section we proposed a formulation of the problem of getting
to Bucharest in terms , of the initial state , actions, transition model goal
test and path cost .This formulation seems reasonable ,but it is still a model
– an abstract mathematical description – and not the real thing
• Compare the simple state description chosen ,In(Arad),to an actual cross
country trip ,where the state of the world includes so many things :the
travelling companions, the current radio program ,the scenery out of the
window , the distance to the next stop , the condition of the road ,the
weather ,and so on.
• All these considerations are left out of our state description because they
are irrelevant to the problem of finding a route to Bucharest.
• The process of removing detail from a representation is called abstraction
• In addition to abstracting the state description ,we must abstract the actions
themselves
• A driving action has many effects . Besides changing the location of the
vehicle and its occupants , it takes up time , consuming fuel , generates
pollution and changes the agent
• Our formulation in the example takes into account only
the change in the location . And ,there are many actions
that we omit together :turning on the radio, looking out of
the window etc.

• The abstraction is valid if we expand any abstract


solution into a solution in the more detailed world ; a
sufficient condition is that for every detailed state that is ―
in Arad‖, there is a detailed path to some state that is ―in
Sibiu‖ and so on .
• Abstraction is useful if carrying out each of the actions in
the solution is easier than the original problem
• The choice of a good abstraction involves removing as
much detail as possible while retaining validity and
ensuring that the abstract actions are easy to carry out
Example Problems
• The problem - solving approach has been applied to a vast
array of task environments
• Toy – Problem
• Real –world problem
• Toy – Problem : Intended to illustrate or exercise various
problem solving methods . It can be given a concise ,exact
description and hence is usable by different researchers to
compare the performance of algorithms
• Real –world problem : One whose solutions people actually
care about . Such problems tend not to have a single agreed –
upon description but we can give the general flavor of their
formulations
Toy Problems
• The first example we examine is the vacuum world first . (See
Figure 2.2.) This can be formulated as a problem as follows:
• This can be formulated as a problem as follows:
• States: The state is determined by both the agent
location and the dirt locations.
• The agent is in one of two locations, each of which
might or might not contain dirt. Thus, there are 2 × 22
= 8 possible world states.
• A larger environment with n locations has n ·2n states
• Initial state: Any state can be designated as the initial
state.
• Actions: In this simple environment, each state has
just three actions: Left, Right, and Suck. Larger
environments might also include Up and Down
• Transition model: The actions have their expected
effects, except that moving Left in the leftmost
square, moving Right in the rightmost square, and
Sucking in a clean square have no effect. The
complete state space is shown in Figure 3.3.
• Goal test: This checks whether all the squares are
clean.
• Path cost: Each step costs 1, so the path cost is the
number of steps in the path.
• Compared with the real world, this toy problem has
discrete locations, discrete dirt, reliable cleaning, and
it never gets any dirtier
The 8-puzzleProblem
• The 8-puzzle, an instance of which is shown in Figure
3.4, 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, such as
the one shown on the right of the figure. The standard
formulation is as follows:
• States: A state description specifies the location of
each of the eight tiles and the blank in one of the nine
squares.
• States: A state description 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 any given goal can be reached from
exactly half of the possible initial states (Exercise
3.5).
• Actions: The simplest formulation defines the actions
as 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; for example, if we apply
Left to the start state in Figure 3.4, the resulting state
has the 5 and the blank switched.

• Goal test: This checks whether the state matches the


goal configuration shown in Figure 3.4. (Other goal
configurations are possible.)

• Path cost: Each step costs 1, so the path cost is the


number of steps in the path.
What abstractions have been included in 8 puzzle
problem?
• The actions are abstracted to their beginning
and final states, ignoring the intermediate
locations where the block is sliding.
• We have abstracted away actions such as
shaking the board when pieces get stuck and
ruled out extracting the pieces with a knife and
putting them back again.
• We are left with a description of the rules of
the puzzle, avoiding all the details of physical
manipulations
• The 8-puzzle belongs to the family of sliding-block
puzzles, which are often used as test problems for
new search algorithms in AI. This family is known to
be NP-complete, so one does not expect to find
methods significantly better in the worst case than the
search algorithms described in this chapter and the
next.
• The 8-puzzle has 9!/2=181, 440 reachable states
and is easily solved. The 15-puzzle (on a 4×4 board)
has around 1.3 trillion states, and random instances
can be solved optimally in a few milliseconds by the
best search algorithms.
• The 24-puzzle (on a 5 × 5 board) has around 1025
states, and random instances take several hours to
solve optimally
P versus NP problem

• The P versus NP problem is a major unsolved


problem in computer science.
• It asks whether every problem whose solution can be
quickly verified can also be solved quickly.
• The class of questions for which an answer can be
verified in polynomial time is called NP, which
stands for "nondeterministic polynomial time".
• P = the set of problems that are solvable in
polynomial time by a Deterministic Turing
Machine.
NP –COMPLETE PROBLEM
• Definition : NP-complete problems are in NP, the
set of all decision problems whose solutions can be
verified in polynomial time;
• NP may be equivalently defined as the set of
decision problems that can be solved in polynomial
time on a non-deterministic Turing machine.
• The complexity class of decision problems for which
answers can be checked for correctness, given a
certificate, by an algorithm whose run time is
polynomial in the size of the input (that is, it is NP)
8 Queens Problem
• The goal of the 8-queens problem is to place eight queens on
a chessboard such that no queen attacks any other. (A queen
attacks any piece in the same row, column or diagonal.)
• Figure 3.5 shows an attempted solution that fails: the queen in
the rightmost column is attacked by the queen at the top left.
• Although efficient special-purpose algorithms exist for this
problem and for the whole n-queens family, it remains a useful
test problem for search algorithms.
• There are two main kinds of formulation. An incremental
formulation involves operators that augment the state
description, starting with an empty state; for the 8-queens
problem, this means that each action adds a queen to the state.
• A complete-state formulation starts with all 8 queens on
the board and moves them around.
• In either case, the path cost is of no interest because only the
final state counts.
Incremental formulation
• The first incremental formulation one might try is the
following
• States: Any arrangement of 0 to 8 queens on the board
is a state.
• Initial state: No queens on the board.
• Actions: Add a queen to any empty square.
• Transition model: Returns the board with a queen
added to the specified square.
• Goal test: 8 queens are on the board, none attacked.
• In this formulation, we have 64 · 63 · · · 57 ≈ 1.8×1014
possible sequences to investigate.
• A better formulation would prohibit placing a queen in
any square that is already attacked:
• States: All possible arrangements of n queens
(0 ≤ n ≤ 8), one per column in the leftmost n
columns, with no queen attacking another.
• Actions: Add a queen to any square in the
leftmost empty column such that it is not
attacked by any other queen.
• This formulation reduces the 8-queens state
space from 1.8×1014 to just 2,057, and
solutions are easy to find.
REAL - WORLD PROBLEMS
• We have already seen how the 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.
Some, such as Web sites and in-car systems that provide
driving directions, are relatively straightforward extensions of
the Romania example.
• Others, such as routing video streams in computer networks,
military operations planning, and airline travel-planning
systems, involve much more complex specifications.
• Consider the airline travel problems that must be solved by
a travel-planning Web site:
• States: Each state obviously includes a location (e.g., an
airport) and the current time.
• Furthermore, because the cost of an action (a flight segment)
may depend on previous segments, their fare bases, and their
status as domestic or international, the state must record extra
information about these ―historical‖ aspects.
• Initial state: This is specified by the user’s query.
• Actions: Take any flight from the current location, in any seat
class, leaving after the current time, leaving enough time for
within-airport transfer if needed.
• Transition model: The state resulting from taking a flight will
have the flight’s destination as the current location and the
flight’s arrival time as the current time.
• Goal test: Are we at the final destination specified by the
user?
• Path cost: This depends on monetary cost, waiting time, flight
time, customs and immigration procedures, seat quality, time
of day, type of airplane, frequent-flyer mileage awards, and so
on.
• Commercial travel advice systems use a problem formulation
of this kind, with many additional complications to handle the
byzantine fare structures that airlines impose. Any seasoned
traveler knows, however, that not all air travel goes according
to plan.
• A really good system should include contingency plans—
such as backup reservations on alternate flights— to the extent
that these are justified by the cost and likelihood of failure of
the original plan.
• The traveling salesperson problem (TSP) is a touring
problem in which each city must be visited exactly once.
• The aim is to find the shortest tour.
• The problem is known to be NP-hard, but an enormous
amount of effort has been expended to improve the capabilities
of TSP algorithms.
• In addition to planning trips for traveling salespersons, these
algorithms have been used for tasks such as planning
movements of automatic circuit-board drills and of stocking
machines on shop floors.
Note :In computational complexity theory, NP-hardness (non-
deterministic polynomial-time hardness) is the defining
property of a class of problems that are informally "at least as
hard as the hardest problems in NP". A simple example of an
NP-hard problem is the subset sum problem.
SEARCHING FOR SOLUTIONS
• Having formulated some problems, we now need to solve
them.
• A solution is an action sequence, so search algorithms work
by considering 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.
• Figure 3.6 shows the first few steps in growing the search tree
for finding a route from Arad to Bucharest.
• The root node of the tree corresponds to the initial state,
In(Arad).
• The first step is to test whether this is a goal state.
• Then we need to consider taking various actions.
• We do this by expanding the current state; that is,
applying each legal action to the current state, thereby
generating a new set of states.
• In this case, we add three branches from the parent
node In(Arad) leading to three new child nodes:
In(Sibiu), In(Timisoara), and In(Zerind).
• Now we must choose which of these three
possibilities to consider further.
• This is the essence of search—following up one
option now and putting the others aside for later, in
case the first choice does not lead to a solution
• Suppose we choose Sibiu first.
• We check to see whether it is a goal state (it is not)
and then expand it to get In(Arad), In(Fagaras),
In(Oradea), and In(RimnicuVilcea).
• We can then choose any of these four or go back and
choose Timisoara or Zerind. Each of these six nodes
is a leaf node, that 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.
• In Figure 3.6, the frontier of each tree consists of
those nodes with bold outlines.
• The process of expanding nodes on the frontier
continues until either a solution is found or there are
no more states to expand. The general TREE-
SEARCH algorithm is shown informally in Figure
3.7.
• Search algorithms all share this basic structure; they
vary primarily according to how they choose which
state to expand next—the so-called search strategy.
• The search tree shown in Figure 3.6: it includes the
path from Arad to Sibiu and back to Arad again!
• We say that In(Arad) is a repeated state in the search
tree, generated in this case by a loopy path.
• Considering such loopy paths means that the complete
search tree for Romania is infinite because there is no
limit to how often one can traverse a loop.
• Loops can cause certain algorithms to fail, making
otherwise solvable problems unsolvable.

• Fortunately, there is no need to consider loopy paths.


We can rely on more than intuition for this: because
path costs are additive and step costs are nonnegative, a
loopy path to any given state is never better than the
same path with the loop removed
• Loopy paths are a special case of the more general
concept of redundant paths, which exist whenever
there is more than one way to get from one state to
another.
• Consider the paths Arad–Sibiu (140 km long) and
Arad–Zerind–Oradea–Sibiu (297 km long).
• Obviously, the second path is redundant—it’s just a
worse way to get to the same state.
• If you are concerned about reaching the goal,
there’s never any reason to keep more than one path
to any given state, because any goal state that is
reachable by extending one path is also reachable
by extending the other.
Infrastructure for search algorithms
• Search algorithms require a data structure to keep
track of the search tree that is being constructed.
• For each node n of the tree, we have a structure that
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, traditionally
denoted by g(n), of the path from the initial
state to the node, as indicated by the parent
pointers
• Given the components for a parent node, it is
easy to see how to compute the necessary
components for a child node.
• The function CHILD-NODE takes a parent
node and an action and returns the resulting
child node:
• The node data structure is depicted in Figure 3.10.
• Notice how the PARENT pointers string the nodes
together into a tree structure. These pointers also allow
the solution path to be extracted when a goal node is
found; we use the SOLUTION function to return the
sequence of actions obtained by following parent
pointers back to the root.
• A node is a bookkeeping data structure used to
represent the search tree.
• A state corresponds to a configuration of the world.
Thus, nodes are on particular paths, as defined by
PARENT pointers, whereas states are not.
• Furthermore, two different nodes can contain the same
world state if that state is generated via two different
search paths.
• Now that we have nodes, we need somewhere to put
them.
• The frontier needs to be stored in such a way that the
search algorithm can easily choose the next node to
expand according to its preferred strategy. The
appropriate data structure for this is a queue.
• The operations on a queue are as follows:

• EMPTY?(queue) returns true only if there are no more


elements in the queue.
• POP(queue) removes the first element of the queue and
returns it.
• INSERT(element , queue) inserts an element and
returns the resulting queue.
• Queues are characterized by the order in which
they store the inserted nodes.
• Three common variants are
• the first-in, first-out or FIFO queue, which pops
the oldest element of the queue;
• the last-in, first-out or LIFO queue (also known as
a stack), which pops the newest element of the
queue;
• and the priority queue, which pops the element of
the queue with the highest priority according to
some ordering function.
Measuring problem solving performance
• The algorithm performance can be evaluated in four ways:
• Before we get into the design of specific search algorithms, we
need to consider the criteria that might be used to choose
among them. We can evaluate an 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?
• Time and space complexity are always considered with respect
to some measure of the problem difficulty

• In theoretical computer science, the typical measure 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


that is input to the search program. (The map of Romania is an
example of this.)

• In AI, the 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, the branching factor or maximum number of successors of


any node;
 d, the depth of the shallowest goal node (i.e., the number of
steps along the path from the root);
 and m, the maximum length of any path in the state space.

• 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

• For the most part, we describe time and space complexity for
search on a tree; for a graph, the answer depends on how
―redundant‖ the paths in the state space are
• Time is measured in terms of the number of nodes generated during the
search ,and space complexity for search on a tree; for a graph , the answer
depends on how ―redundant‖ the paths in the state space are.

• To assess the effectiveness of a search algorithm ,we can consider the


search cost – which typically depends on the time complexity or we can
use the total cost ,which combines the search cost and the path cost of the
solution found

• For the problem of finding a route from Arad to Bucharest, the search cost
is the amount of time taken by the search and the solution cost is the total
length of the path in kilometers. Thus, to compute the total cost, we have to
add milliseconds and kilometers.
UNIFORMED SEARCH STRATEGIES
• Uniformed Search Strategies is also known as blind search

• The term means that the strategies have no additional


information about states beyond that provided in the
problem definition
• All they can do is that they generate successors and distinguish
a goal state from a non –goal state
• All search strategies are distinguished by the order in which
nodes are expanded
• Strategies that know whether one non –goal state is ―more
promising ― than another are called informed search or
heuristic search strategies‖:
BREADTH –FIRST SEARCH
• Breadth-first search is a simple strategy in which the root node
is expanded first, then all the successors of the root node are
expanded next, then their successors, and so on
• All the nodes are expanded at a given depth in the search tree
before any nodes at the next level are expanded
• Breadth-first search is an instance of the general graph-search
algorithm in which the shallowest unexpanded node is chosen
for expansion.
• This is achieved very simply by using a FIFO queue for the
frontier.
• Thus, new nodes (which are always deeper than their parents)
go to the back of the queue, and old nodes, which are
shallower than the new nodes, get expanded first.
BREADTH –FIRST SEARCH
• There is one slight tweak on the general graph-
search algorithm, which is that the goal test is
applied to each node when it is generated rather
than when it is selected for expansion.
• Note :The algorithm, following the general
template for graph search, discards any new path
to a state already in the frontier or explored set; it
is easy to see that any such path must be at least
as deep as the one already found. Thus, breadth-
first search always has the shallowest path to
every node on the frontier
• Pseudo code is given in Figure 3.11. Figure 3.12
shows the progress of the search on a simple
binary tree
How does breadth-first search rate according to
the four criteria ?
• We can easily see that it is complete—if the shallowest goal
node is at some finite depth d, breadth-first search will
eventually find it after generating all shallower nodes
(provided the branching factor b is finite)
• Note that as soon as a goal node is generated, we know it is the
shallowest goal node because all shallower nodes must have
been generated already and failed the goal test.
• Now, the shallowest goal node is not necessarily the optimal
one; technically, breadth-first search is optimal if the path cost
is a non decreasing function of the depth of the node
• The most common such scenario is that all actions have the
same cost.
• So far, the news about breadth-first search has been
good.
• The time and space is not so good.
• Imagine searching a uniform tree where every state
has b successors.
• The root of the search tree generates b nodes at the
first level, each of which generates b more nodes, for
a total of b 2 at the second level.
• Each of these generates b more nodes, yielding b3
nodes at the third level, and so on.
• Now suppose that the solution is at depth d.
• In the worst case, it is the last node generated at that
level. Then the total number of nodes generated is
Uniform-cost search
• When all step costs are equal, breadth-first search is
optimal because it always expands the shallowest
unexpanded node.
• By a simple extension, we can find an algorithm that
is optimal with any step-cost function.
• Instead of expanding the shallowest node, uniform-
cost search expands the node n with the lowest path
cost g(n). This is done by storing the frontier as a
priority queue ordered by g.
• The algorithm is shown in Figure 3.14.
ALGORITHM
• In addition to the ordering of the queue by path cost,
there are two other significant differences from
breadth-first search.
• The first is that the goal test is applied to a node when
it is selected for expansion rather than when it is first
generated.
• The reason is that the first goal node that is generated
may be on a suboptimal path
• The second difference is that a test is added in case a
better path is found to a node currently on the frontier
• Both of these modifications come into play in the
example shown in Figure 3.15, where the problem is
to get from Sibiu to Bucharest.
• The successors of Sibiu are Rimnicu Vilcea and
Fagaras, with costs 80 and 99, respectively.
• The least-cost node, Rimnicu Vilcea, is expanded
next, adding Pitesti with cost 80 + 97=177.
• The least-cost node is now Fagaras, so it is expanded,
adding Bucharest with cost 99+211=310
• Now a goal node has been generated, but
uniform-cost search keeps going, choosing
Pitesti for expansion and adding a second path
to Bucharest with cost 80+97+101= 278.
• Now the algorithm checks to see if this new
path is better than the old one; it is, so the old
one is discarded. Bucharest, now with g-cost
278, is selected for expansion and the solution
is returned.
Informed (Heuristic) Search Strategies
• This section shows how an informed search strategy—
one that uses problem- specific knowledge beyond the
definition of the problem itself—can find solutions more
efficiently than can an uninformed strategy
• A search strategy which searches the most promising
branches of the state-space first can:
– find a solution more quickly,
– find solutions even when there is limited time
available,
– often find a better solution, since more profitable
parts of the state-space can be examined, while ignoring the
unprofitable parts
Best-first search
• A search strategy which is better than another at identifying
the most promising branches of a search-space is said to be
more informed
• To implement an informed search strategy, we need to slightly
modify the skeleton for agenda-based search that we've
already seen.
• Again, the crucial part of the skeleton is where we update the
agenda.
• The general approach we consider is called best-first search
• Best-first search is an instance of the general TREE-SEARCH
or GRAPH-SEARCH algorithm in which 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 of best-first graph search is identical to
that for uniform-cost search (Figure 3.14), except for the use
of f instead of g to order the priority queue
• The choice of f determines the search strategy. (For example,
as Exercise 3.22 shows, best-first tree search includes depth-
first search as a special case.)
• Most best-first algorithms include as a component of f a
heuristic function, denoted h(n):
• h(n) = estimated cost of the cheapest path from the state at
node n to a goal state.
• (Notice that h(n) takes a node as input, but, unlike g(n), it
depends only on the state at that node.)
• For example, in Romania, one might estimate the cost of the
cheapest path from Arad to Bucharest via the straight-line
distance from Arad to Bucharest.
• Heuristic functions are the most common form in which
additional knowledge of the problem is imparted to the search
algorithm
Heuristic evaluation functions
• A heuristic evaluation function, h(n), is the estimated cost of
the cheapest path from the state at node n, to a goal state.
• Heuristic evaluation functions are very much dependent on
the domain used.
• h(n) might be the estimated number of moves needed to
complete a puzzle, or the estimated straight-line distance to
some town in a route finder.
• Choosing an appropriate function greatly affects the
effectiveness of the state-space search, since it tells us which
parts of the state-space to search next.
• A heuristic evaluation function which accurately represents the
actual cost of getting to a goal state, tells us very clearly which
nodes in the state-space to expand next, and leads us quickly to
the goal state.
Greedy best-first search
• Greedy best-first search 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; that is, f(n) = h(n)
• Let us see how this works for route-finding problems in
Romania; we use the straight line distance heuristic, which we
will call hSLD.
• If the goal is Bucharest, we need to know the straight-line
distances to Bucharest, which are shown in Figure 3.22
• 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.
• Figure 3.23 shows the progress of a greedy best-first search
using hSLD to find a path from Arad to Bucharest.
• The first node to be expanded from Arad will be Sibiu because
it is closer to Bucharest than either Zerind or Timisoara.
• The next node to be expanded will be Fagaras because it is
closest. Fagaras in turn generates Bucharest, which is the goal.
• For this particular problem, greedy best-first search using hSLD
finds a solution without ever expanding a node that is not on
the solution path; hence, its search cost is minimal.
• It is not optimal, however: the path via Sibiu and Fagaras to
Bucharest is 32 kilometers longer than the path through
Rimnicu Vilcea and Pitesti.
• This shows why the algorithm is called ―greedy‖—at each step
it tries to get as close to the goal as it can
Greedy Search
• Alternatively, we might sort the agenda by the cost of getting
to the goal from that state. This is known as greedy search

• An obvious problem with greedy search is that it doesn't take


account of the cost so far, so it isn't optimal, and can wander
into dead-ends, like depth-first search

• In most domains, we also don't know the cost of getting to the


goal from a state. So we have to guess, using a heuristic
evaluation function.
– If we knew how far we were from the goal state we
wouldn’t need to search for it!
A* search: Minimizing the total estimated
solution cost
• The choice of an appropriate heuristic evaluation function,
h(n), is still crucial to the behavior of this algorithm.
• In general, we want to choose a heuristic evaluation function
h(n) which is as close as possible to the actual cost of getting
to a goal state.
• If we can choose a function h(n) which never overestimates
the actual cost of getting to the goal state, then we have a very
useful property. Such a h(n) is said to be admissible.
• Best-first search, where the agenda is sorted according to the
function f(n) = g(n) + h(n) and where the function h(n) is
admissible, can be proven to always find an optimal solution.
This is known as Algorithm A*.
• f(n) = g(n) + h(n)
• Since g(n) gives the path cost from the start node to node n,
and
• h(n) is the estimated cost of the cheapest path from n to the
goal,
• f(n) = estimated cost of the cheapest solution through n .
• Thus, if we are trying to find the cheapest solution, a
reasonable thing to try first is the node with the lowest value of
g(n) + h(n)
• It turns out that this strategy is more than just reasonable:
provided that the heuristic function h(n) satisfies certain
conditions, A∗ search is both complete and optimal. The
algorithm is identical to UNIFORM-COST-SEARCH except
that A∗ uses g + h instead of g
Conditions for optimality: Admissibility and
consistency
• The first condition we require for optimality is that h(n) be an
admissible heuristic.
• An admissible heuristic is one that never overestimates the
cost to reach the goal.
• Because g(n) is the actual cost to reach n along the current
path, and f(n) = g(n) + h(n), we have as an immediate
consequence that f(n) never overestimates the true cost of a
solution along the current path through n.
• Admissible heuristics are by nature optimistic because they
think the cost of solving the problem is less than it actually is.
• An obvious example of an admissible heuristic is the straight-
line distance hSLD that we used in getting to Bucharest
• Straight-line distance is admissible because the shortest path
between any two points is a straight line, so the straight line
cannot be an overestimate.
• In Figure 3.24, we show the progress of an A∗ tree search for
Bucharest. The values of g are computed from the step costs in
Figure 3.2, and the values of hSLD are given in Figure 3.22.
• Notice in particular that Bucharest first appears on the frontier
at step (e), but it is not selected for expansion because its f-cost
(450) is higher than that of Pitesti (417)
• Another way to say this is that there might be a solution
through Pitesti whose cost is as low as 417, so the algorithm
will not settle for a solution that costs 450.
CONSISTENCY and MONOTONICITY
• A second, slightly stronger condition called consistency (or
sometimes monotonicity) is required only for applications of
A∗ to graph search.
• A heuristic h(n) is consistent if, for every node n and every
successor n′ of n generated by any action a, the estimated cost
of reaching the goal from n is no greater than the step cost of
getting to n′ plus the estimated cost of reaching the goal from
n′:
• h(n) ≤ c(n, a, n′) + h(n′)
• This is a form of the general triangle inequality, which
stipulates that each side of a triangle cannot be longer than the
sum of the other two sides.

You might also like