Module 2
Module 2
Module 2
• Simple agents discussed were the reflex agents, which base their actions on a
direct mapping from states to actions.
• Such agents cannot operate well in environments for which this mapping would be
too large to store and would take too long to learn.
• Goal-based agents, on the other hand, consider future actions and the desirability
of their outcomes.
• Such a goal-based agent called a problem-solving agent
PROBLEM-SOLVING AGENTS
• While the agent is executing the solution sequence ,it ignores its
percepts when choosing an action because it knows in advance what
they will be.
• An agent that carries out its plans with its eyes closed, so to speak,
must be quite certain of what is going on.
• This an open-loop system, because ignoring the percepts breaks the
loop between agent and environment.
• A problem can be defined formally by following components:
1. The initial state that the agent starts in.
2. A description of the possible actions available to the agent.
◦ Eg:- from the state In(Ernakulam), the applicable actions are
{Go(Thrissur), Go(Palakkad), Go(Kozhikod)}.
3. Transition model: description of what each action does, specified by a
function RESULT(s, a) that returns the state that results from doing action
a in state s
4. Successor: any state reachable from a given state by a single action
RESULT(In(Ernakulam),Go(Thrissur)) = In(Thrissur)
5. State space: The set of all states reachable from the initial state by any
sequence of actions. forms a directed network or graph in which the nodes
are states and the links between nodes are actions.
6. A path in the state space is a sequence of states connected by a sequence of
actions.
7. The goal test, which determines whether a given state is a goal state
{In(Chennai)}
8. A path cost function that assigns a numeric cost to each path.
Cost of a path can be described as the sum of the costs of the individual actions
along the path.
9. The step cost of taking action a in state s to reach state s is denoted by c(s,a,s).
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 having the lowest path cost among all solutions.
Formulating problems
• The formulation of the problem can be done in terms of the initial state,
actions, transition model, goal test, and path cost.
• Some of the considerations are left out from state descriptions because they
are irrelevant to the problem formulation.
eg:- In the travel from Ernakulam to Thrissur , can include : the traveling
companions, the current radio program, the scenery out of the window,
the proximity of law enforcement officers, the distance to the next rest
stop, the condition of the road, the weather, and so on
• The process of removing irrelevant details from a representation is called
abstraction and leaving most essential parts of the description.
• Conclusion: Only the most important parts that are contributing to search are
used.
• Example: Romania
Example Problems
• The problem-solving approach has been applied to a vast array of task
environments.
• The best known are, distinguishing between toy and real-world problems.
• A toy problem is intended to illustrate or exercise various problem-solving
methods.
• Its concise, exact description makes it usable to compare the performance
of algorithms.
e.g., puzzle, chess, etc
• A real-world problem is one whose solutions people actually care about.
e.g., Design, planning, etc.
Toy problems
a)Vacuum World
• 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.
• 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.
b) 8-puzzle
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 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.
• Actions: The simplest formulation defines the actions as movements of the
blank space Left, Right, Up, or Down.
• Transition model: Given a state and action, this returns the resulting state; for
example, if we apply Right to the start state, the resulting state has
the 5 and the blank switched.
• Goal test: This checks whether the state matches the goal configuration (Other goal
configurations are possible.)
• Path cost: Each step costs 1, so the path cost is the number of steps in the path.
• 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
c) 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 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.
• Incremental formulation
➢ involves operators that augment the state description, starting with an
empty state.
➢Each action adds a queen to the state
• Complete-state formulation
➢starts with all 8 queens on board and moves them around.
• Incremental Formulation
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
Complete state formulation
• 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
• Route-finding problems
• Touring problems
• Traveling Salesman problem
• VLSI layout problem
• Robot navigation
• Automatic assembly sequencing
• Internet searching
a) Route-Finding problem
• used in a variety of applications.
• such as Web sites and in-car systems that provide driving directions.
eg:- Airline travel problems
• States: Each state obviously includes a location (e.g., an airport) and the current
time.
• Initial state: This is specified by the user’s query.
• Actions: Take any flight from the current location 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
b) Touring problems
• “Visit every city in at least once, starting and ending in Bucharest.”
• Actions correspond to trips between adjacent cities
• Each state must include not just the current location but also the set of
cities the agent has visited.
• So the initial state would be In(Bucharest), Visited({Bucharest}), a typical
intermediate state would be In(Vaslui), Visited({Bucharest, Urziceni,
Vaslui}).
• Goal test would check whether the agent is in Bucharest and all 20 cities
have been visited.
c) Traveling salesperson problem
• 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.
d)VLSI layout problem
• 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.
• The layout problem comes after the logical design phase and is usually split into
two parts: ◦ cell layout and channel routing.
• Cell layout –
➢ The primitive components of the circuit are grouped into cells, each of which
performs some recognized function.
➢ Each cell has a fixed footprint and requires a certain number of connections to
each of the other cells.
➢The aim is to place the cells on the chip so that they do not overlap and so that
there is room for the connecting wires to be placed between the cells.
• Channel routing –
➢ finds a specific route for each wire through the gaps between the cells.
e) Robot navigation
• 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
Problem solving performance-UCS
• Complete: guaranteed provided the cost of every step exceeds some small
positive constant ε
• Optimal: optimal path to that node has been found, because step costs are
nonnegative, paths never get shorter as nodes are added. Uniform-cost search
expands nodes in order of their optimal path cost.
• Time Complexity: of nodes with g ≤ cost of optimal solution, O(bceiling(C*/ ε) )
where C* is the cost of the optimal solution
• Space Complexity: of nodes with g ≤ cost of optimal solution, O(bceiling(C*/ε) )
• Uniform-cost search is guided by path costs rather than depths, so its complexity
is not easily characterized in terms of b and d.
• Let C∗ be the cost of the optimal solution and that every action costs at least ε,
then the algorithm’s worst-case time and space complexity is can be much greater
than bd
• When all step costs are equal then complexity is just bd+1
• Also uniform-cost search is similar to breadth-first search, except that bfs stops as
soon as it generates a goal, whereas uniform-cost search examines all the nodes at
the goal’s depth to see if one has a lower cost thus uniform-cost search does
strictly more work by expanding nodes at depth d.
Depth-limited search
• The embarrassing failure of depth-first search in infinite state spaces can be
alleviated by supplying depth-first search with a predetermined depth limit ‘l’.
• That is, nodes at depth are treated as if they have no successors.
• This approach is called depth-limited search.
• The depth limit solves the infinite-path problem.
• But it also introduces an additional source of incompleteness, if we choose l <d,
that is, the shallowest goal is beyond the depth limit. (This is likely when d is
unknown.).
• Depth-limited search will also be nonoptimal if we choose l >d
• Its time complexity is O(b l) and its space complexity is O(b l). Depth-first search
can be viewed as a special case of depth-limited search with l =∞.
• Depth-limited search can be implemented as a simple modification to the general tree or
graph-search algorithm.
• Alternatively, it can be implemented as a simple recursive algorithm .
• The depth-limited search can terminate with two kinds of failure: the standard failure value
indicates no solution; the cutoff value indicates no solution within the depth limit.
Iterative deepening depth-first search
• This method tries to expand the node that is closest to the goal, on the
grounds that this is likely to lead to a solution quickly.
• It evaluates nodes by using just the heuristic function; that is, f(n) = h(n).
Greedy best-first search- Route finding problems in Romania
• Here 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 table.
• hsld is correlated with actual
road distances and is,
therefore, a useful heuristic
A* search: Minimizing the total estimated solution cost
Admissibility
• 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.
• Admissible heuristics are by nature optimistic because they think the cost of solving
the problem is less than it actually is.
• Eg:- of 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.
Consistency