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

Ch-3 Problem Solving

problem solving
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Ch-3 Problem Solving

problem solving
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

HiLCoE

School of Computer Science and Technology


Course Title: Introduction to Artificial Intelligence (CS488)
Credit Hour: 4
Instructor: Fantahun B. (PhD) [email protected]
Office: 3##

Ch-3: Problem Solving


Problem Solving

Agenda:
• Problem-solving agents
• Problem formulation: state space construction
• Problem types : Toy vs Real world problems

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 2
Problem Solving
Objectives:
After successfully completing this topic, students will be able
to:
• Describe problem solving agents
• Be able to formulate search problems, construct state
space for the various example problems
• Differentiate toy problems and real world problems; try to
formulate these and other similar problems.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 3
Problem Solving
• This chapter describes one kind of goal-based agent called a
problem-solving agent.
• Problem-solving agents use atomic representations, as
described in ch-2,
 states of the world are considered as wholes,
 with no internal structure visible to the problem solving algorithms.
• What is a problem?

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 4
Problem Solving: Problem Solving Agents
• Intelligent agents are supposed to maximize their performance
measure.
• As we stated in Ch-2, achieving this is sometimes simplified if the
agent can adopt a goal and aim at satisfying it.
• We will consider a goal to be:
 a set of world states — exactly those states in which the goal is
satisfied.
• The agent’s task is:
 to find out how to act, now and in the future, so that it reaches a
goal state.
• Goal formulation, based on the current situation and the agent’s
performance measure, is the first step in problem solving.
Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 5
Problem Solving: Problem Solving Agents
• Example:
 assume the agent has the goal of driving to Bucharest and is
considering where to go from Arad (Fig. 3.2).
 Three roads lead out of Arad,  Sibiu,
 Timisoara, and
 Zerind.
 None of these achieves the goal, so unless the agent is familiar with
the geography of Romania, it will not know which road to follow.
 If the agent has no additional information (unknown
environment), it has no choice but to try one of the actions at
random.
• Problem formulation is the process of deciding what actions and
states to consider, given a goal.
Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 6
Problem Solving: Problem Solving Agents
• Let’s assume that the environment is
 observable (the agent always knows the current state);
 discrete(at any given state there are only finitely many actions to
choose from);
 known (agent knows which states are reached by each action) and
 deterministic (each action has exactly one outcome)
• Under these assumptions, the solution to any problem is a fixed
sequence of actions.
• The process of looking for a sequence of actions that reaches
the goal is called search.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 7
Problem Solving: Problem Solving Agents
• A search algorithm takes a problem as input and returns a
solution in the form of an action sequence.
• Once a 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.
 It then uses the solution to guide its actions, doing whatever the
solution recommends as the next thing to do.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 8
Problem Solving: Problem Solving Agents

Figure 3.1 A simple problem-solving agent. It first formulates a goal and a problem,
searches for a sequence of actions that would solve the problem, and then executes the
actions one at a time. When this is complete, it formulates another goal and starts over.
Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 9
Problem Solving: Problem Solving Agents
Problem Formulation

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 10
Problem Solving: Problem Solving Agents
Problem Formulation
• A problem can be defined formally by five components:
1. Initial state: that the agent starts in.
 For example, the initial state for our agent in Romania might be
described as
In(Arad) [refer Fig. 3.2].
2. Actions: a description of the possible actions available to the
agent.
 Given a particular state s, ACTIONS(s) returns the set of actions that
can be executed in s. We say that each of these actions is applicable
in s. For example, from the state In(Arad), the applicable actions are
{Go(Sibiu), Go(Timisoara), Go(Zerind)}.
Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 11
Problem Solving: Problem Solving Agents
Problem Formulation
3. Transition model: A description of what each action does; the
transition model, specified by a function RESULT(s, a) that returns
the state that results from doing action a in state s.
For example, we have

RESULT(In(Arad), Go(Zerind)) = In(Zerind).


• Together, the initial state, actions, and transition model
implicitly define the state space of the problem — the set of
all states reachable from the initial state by any sequence of
actions.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 12
Problem Solving: Problem Solving Agents
Problem Formulation
• The state space forms a directed network or graph in which
the nodes are states and the links between nodes are actions.
• (The map of Romania shown in Figure 3.2 above can be
interpreted as a state-space graph if we view each road as
standing PATH for two driving actions, one in each direction.)
• A path in the state space is a sequence of states connected
by a sequence of actions.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 13
Problem Solving: Problem Solving Agents
Problem Formulation
4. The goal test: determines whether a given state is a goal state.
 Sometimes there is an explicit set of possible goal states,
and the test simply checks whether the given state is one of
them. The agent’s goal in Romania is the singleton set
{In(Bucharest )}.
 Sometimes the goal is specified by an abstract property
rather than an explicitly enumerated set of states.
o For example, in chess, the goal is to reach a state called
“checkmate,” where the opponent’s king is under attack and
can’t escape.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 14
Problem Solving: Problem Solving Agents
Problem Formulation
5. A path cost function: that assigns a numeric cost to each
path. The problem-solving agent chooses a cost function that
reflects its own performance measure.
 For the agent trying to get to Bucharest, time is of the essence, so the
cost of a path might be its length in kilometers.
 We assume that the cost of a path can be described as the sum of
the costs of the individual actions along the path.
 The step cost of taking action a in state s to reach state s’ is denoted
by c(s, a, s’).
 The step costs for Romania are shown in Figure 3.2 (slide-10)as route
distances. We assume that step costs are nonnegative.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 15
Problem Solving: Problem Solving Agents
Problem Formulation
• The preceding elements define a problem and can be
gathered into a single data structure that is given as input to a
problem-solving algorithm.
• 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.
 optimal solution has the lowest path cost among all solutions.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 16
Problem Solving: Problem Solving Agents
Problem Formulation: Example
• On holiday in Romania; currently in Arad. Flight leaves
tomorrow from Bucharest.
• Formulate goal:
 be in Bucharest
• Formulate problem:
 states: various cities
 Initial state: Arad
 actions: drive between cities
• Find solution:
 sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 17
Problem Solving: Problem Solving Agents
Example Problems: Toy vs real world problems
• Toy problems
 A toy problem is 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 problems
 A real-world problem is one whose solutions people actually care
about.
 Such problems tend not to have a single agreedupon description, but
we can give the general flavor of their formulations.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 18
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  Vacuum world
• This can be formulated as a problem as follows:
 States:
o The state is determined by both the agent location and the dirt
locations. There are two locations, each may be clean or dirty.
Thus, there are 2 × 22 = 8 world states. A larger environment with n
locations has n· 2n states.
 Initial state:
o Any state can be designated as the initial state.
 Actions:
o In this simple environment, each state has just three actions: Left,
Right, and Suck. Larger environments might also include Up and
Down.
Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 19
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  Vacuum world
• This can be formulated as a problem as follows:
 Transition model:
o 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. Fig. 3.3 shows the
complete state space.
 Goal test:
o This checks whether all the squares are clean.
 Path cost:
o Each step costs 1, so the path cost is the number of steps in the
path.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 20
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  Vacuum world

• Class work:
• Generate the 8 possible world states (state space) for the vacuum
world.
• Hint: Think of the 2-locations; 3-actions; 2-room states and the transition model.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 21
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  Vacuum world
• Class work: generate the 8 possible world states (state space) for
the vacuum world.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 22
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  The 8-puzzle
• 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.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 23
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  The 8-puzzle
• 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.
• Actions:
 The simplest formulation defines the actions as movements of the
blank space Left, Right, Up, or Down.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 24
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  The 8-puzzle
• 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.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 25
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  The 8-puzzle
• 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.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 26
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  The 8-puzzle

• Reading Assignment:
• The 8-puzzle has 9!/2=181, 440 reachable states and is easily solved.
• In the above equation, why do we divide 9! by 2 ?

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 27
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  The 8-queen 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 (a) shows an attempted solution that fails: the queen in the
rightmost column is attacked by the queen at the top left.

Solved?

Fig 3.5 Almost a solution


Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 28
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  The 8-queen problem
• 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.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 29
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  The 8-queen problem
• In either case, the path cost is of no interest because only the
final state counts.
• 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.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 30
Problem Solving: Problem Solving Agents
Example Problems: Toy problems  The 8-queen problem
• In this formulation, we have ≈ 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.
 On the other hand, for 100 queens the reduction is from roughly 10400
states to about 1052 states — a big improvement
Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 31
Problem Solving: Problem Solving Agents
Example Problems: Real world problems  Airline travel problems
• 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.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 32
Problem Solving: Problem Solving Agents
Example Problems: Real world problems  Airline travel problems
 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.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 33
Problem Solving: Problem Solving Agents
Example Problems: Real world problems  Touring problems
• Touring problems are closely related to route-finding problems, but
with an important difference.
• Consider, for example, the problem “Visit every city in Figure 3.2 at
least once, starting and ending in Bucharest.”
• As with route finding, the actions correspond to trips between
adjacent cities. The state space, however, is quite different. 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}), and
• the goal test would check whether the agent is in Bucharest and all
20 cities have been visited.
Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 34
Problem Solving: Problem Solving Agents
Example Problems: Real world problems  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. 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.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 35
Problem Solving: Problem Solving Agents
Example Problems: Real world problems  VLSI layout problem
• A 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.
• In 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 (size and shape) 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. These search problems are extremely complex, but
definitely
Oct-23
worth solving. 36
3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others
Problem Solving: Problem Solving Agents
Example Problems: Real world problems  Automatic assembly
sequencing
• Automatic assembly sequencing of complex objects by a robot
was first demonstrated by FREDDY (Michie, 1972). Progress since
then has been slow but sure, to the point where the assembly of
intricate objects such as electric motors is economically feasible.
• In assembly problems, the aim is to find an order in which to
assemble the parts of some object.
• If the wrong order is chosen, there will be no way to add some part
later in the sequence without undoing some of the work already
done.
• Checking a step in the sequence for feasibility is a difficult
geometrical search problem closely related to robot navigation.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 37
Problem Solving: Problem Solving Agents
Example Problems: Real world problems  Automatic assembly
sequencing
• Thus, the generation of legal actions is the expensive part of
assembly sequencing.
• Any practical algorithm must avoid exploring all but a tiny
fraction of the state space.
• Another important assembly problem is protein design, in which
the goal is to find a sequence of amino acids that will fold into a
three-dimensional protein with the right properties to cure some
disease.

Oct-23 3 - Problem Solving Fantahun B.(PhD) Based on AI a Modern Approach 3e & others 38

You might also like