0% found this document useful (0 votes)
20 views69 pages

Solving Problems by Searching Final

The document discusses problem solving including defining problems, solving problems, and building goal-based agents. It provides examples of different types of problems and walks through solving the missionaries and cannibals problem as an illustration of problem solving.

Uploaded by

asnake ketema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views69 pages

Solving Problems by Searching Final

The document discusses problem solving including defining problems, solving problems, and building goal-based agents. It provides examples of different types of problems and walks through solving the missionaries and cannibals problem as an illustration of problem solving.

Uploaded by

asnake ketema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 69

sgirmaw@gmail.

com

1
Learning objectives: at the end of the class, you
should be able to:
• What is a Problem?

– Problem types with


examples
• Solving a problem

• Solution and optimal


solution
• Components of problem

• Steps in problem solving

• Searching
– Searching algorithm Evaluation
2
 Types of problem
– Searching based on the
Strategies
What is a
• It is a gap betweenProblem?
what actually is and what is desired.
–A problem exists when an individual becomes aware of the
existence of an obstacle
which makes it difficult to achieve a desired goal or objective.
• A number of problems are addressed towards designing
intelligent agent:
– Toy problems:
@ are problems that are useful to test and demonstrate
methodologies and can be used by researchers to compare the
performance of different algorithms.
• may require little or no ingenuity, good for games design
• e.g. 8-puzzle, n-queens, vacuum cleaner world, towers of
Hanoi, river crossing…
– Real-life problems:
• E.g. Route finding, Traveling sales 3
• 8- Example
Puzzle
problems
– Given an initial configuration of 8 numbered
tiles on a 3 x 3 board, move the tiles so as to
produce a desired goal configuration of the
tiles.
• Missionaries and Cannibals
– There are 3 missionaries, 3 cannibals, & 1
boat that can carry up to two people on one
side of a river. Move all the missionaries &
4
cannibals across the river.
- Missionaries can never be outnumbered
by cannibals on either side of river, or
else the missionaries are killed.
• The Eight Queens Game
Some more real-world
problems
• Route finding Problem
• Traveling Salesman
Problem(TSP)
• VLSI layout
• Assembly sequencing
• Robot navigation
• Route Finding Problem- shortest Cont
– Defined
path …along
in terms of locations and transitions
problem
links between them.
– Applications: automated travel advisory systems,
airline travel planning systems, military
operations planning, routing in computer
networks,
General route finding
algorithm
1. identify initial state as origin
2. expand to all possible locations
3. choose location with smallest cost/fastest route
4. test goal function, is it the destiny?
5. if yes, return location
Cont
• Route-finding problem: ’d
– Consider the agent in the city of Gondar, toward the end of
touring holiday. Flight leaves tomorrow from city Addis Ababa
airport. The agent has a ticket to fly out the following day. The
ticket is non-refundable, the agent’s visa is about to expire after
tomorrow and there are no seats available for six weeks.

8
Road map of Romania
Cont
• Traveling Salesperson Problems(TSP)

– Visit each city on the map exactly once and returns
to the origin
city.
– Needs information about the visited cities
– The aim is used to find the shortest possible route
that visits
every city exactly once and return to the starting
point.
– Applications: vehicle routing
• VLSI Cont
layout

– Place cells on a chip so they don’t overlap and there is
room for
connecting wires to be placed between the cells
– 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.
• Automatic Assembly Sequencing Cont
– Automatic assembly of complex objects
– The problem is to find an order in …
which to
assemble the parts of some object

 Robot Navigation
– Generalization of the route finding
problem.
– Rather than discrete set of routes, a
robot can move in a continuous
space with an infinite set of possible
actions and states
– When the robot has arms and legs or
Solving a
Problem solving is a process of generating solutions from
observed problem
or
given data.
- Use direct or indirect(Model based) methods
A problem is characterized by – a stet of goals
- a set of objects and
- a set of operations.
To build a system, to solve a particular problem, we
need to
• Define the problem precisely
- Find input situations as well as final situations for acceptable
solution to the problem
• Analyze the problem
• Choose- find
thefewbest problem
important featuressolving technique(s)
that may have impact on the12
the particular
and apply to
appropriateness of
Solving a
problem…
Solution and Optimal Solution
• Solution is set of actions that leads from initial
state to goal
state,
• There may be many solution for a problem
solving agent. The quality of this solution is
measured by the path cost and the solution with
minimum path cost is called Optimal Solution.

13
Solving a
Components of a Problem
o Initial State
problem…
- defines where the agent starts or begins its task
o Actions
- defines description of possible actions given a
particular state
o Transition Model
- describes each action a with respect to state.
o Goal Test
- determines the given state is goal or not
o Path Cost
problem- A function
solving thatisassigns
agents their cost to each path. The cost
14
Solving a
• Problem Formulation is the process of deciding what
problem…
actions and states to consider, given a goal.
• Define states
– States describe distinguishable stages
during the problem-solving process
– Example- What are the various states in route finding
problem?
• The various places including the location of the agent
• Define operators/rules
– Identify the available operators for getting from
one state to the next
– Operators causean action that brings transitions
from one state to
another by applying on a current state
State Space of the
Problem
• The state space defines the set of all relevant states
reachable by (any)
sequence of actions from the initial state until the goal state
is reached.
• Statespace(alsocalled search space/problem
space) of the problem
includes the various states
– Initial state
• defines where the agent starts or begins its task
– Transition states
• other states in between initial and goal states
– Goal state
• defines the situation the agent attempts to achieve 16
• Our aim is building Goal-based
Problem Solving
• A Problem solving agent isAgent
a goal-based agent . It decide
what to do by finding sequence of actions that lead to
desirable states. The agent can adopt a goal and aim at
satisfying it.
• Goal formulation is the first step in problem solving.

17
Building Goal-Based
• An agent which
Agents
has a goal to reach by applying a
sequence of
actions starting the initial state.
– Driving from point A to point B
– Put 8 queens on a chess board such that no one attacks
another
• To build a goal-based agent we need to answer the
following questions:
– What is the goal to be achieved?
18
– What are the actions?
– What relevant information is necessary to encode about the
Initial Goal
world to describe the
state Actions state
state of the world, describe the available transitions, and solve
the problem?
Missionaries and
Cannibals
Initial State

20
Missionaries and
Cannibals
Goal State

21
Missionaries and
Cannibals
(3,3,1): Initial State

22
Missionaries and
Cannibals
A missionary and cannibal
cross

23
Missionaries and
Cannibals
(2,2,0)

24
Missionaries and
Cannibals
One missionary returns

25
Missionaries and
Cannibals (3,2,1)
Missionaries and
Cannibals
Two cannibals
cross

27
Missionaries and
Cannibals
(3,0,0)

28
Missionaries and
Cannibals
A cannibal
returns

29
Missionaries and
Cannibals
(3,1,1)

30
Missionaries and
Cannibals
Two missionaries
cross

31
Missionaries and
Cannibals (1,1,0)

32
Missionaries and
Cannibals
A missionary and cannibal
return

33
Missionaries and
Cannibals (2,2,1)

34
Missionaries and
Cannibals
Two Missionaries
cross

35
Missionaries and
Cannibals (0,2,0)

36
Missionaries and
Cannibals
A cannibal
returns

37
Missionaries and
Cannibals (0,3,1)

38
Missionaries and
Cannibals
Two cannibals
cross

39
Missionaries and
Cannibals (0,1,0)

40
Missionaries and
Cannibals
A cannibal
returns

41
Missionaries and
Cannibals (0,2,1)

42
Missionaries and
Cannibals
The last two cannibals cross

43
Missionaries and
Cannibals
(0,0,0) : Goal State

44
Missionaries and
Cannibals
Solution = the sequence of actions within
the path : [ (3,3,1)→ (2,2,0)→(3,2,1) →(3,0,0) →(3,1,1)
→(1,1,0) →(2,2,1) →(0,2,0) →(0,3,1) →(0,1,0) → (0,2,1)
→(0,0,0)]; Cost = 11 crossings

45
Exercise : River
Crossing
Goat, Wolf and CabbagePuzzles
problem
• A farmer returns from the market, where he bought a
goat, a cabbage and a wolf. On the way home he must
cross a river. His boat is small and unable to transport
more than one of his purchases. He cannot leave the
goat alone with the cabbage (because the goat would eat
it), nor he can leave the goat alone with the wolf
(because the goat would be eaten). How can the farmer
get everything safely on the other side?
Example: The 8 puzzle
problem
1 2 3 1 2 3
4 8 4 5 6
7 6 5 7 8

Initial state
Goal state
Operators: slide blank up, slide blank down, slide
blank
1 2 left,
3 slide
1 2 blank
3 1 2right
3 1 2 3 1 2 3 1 2 3
4 8 4 8 5 4 8 5 4 5 4 5 4 5 6
7 6 5 7 6 7 6 7 8 6 7 8 6 7 8

Solution: sb-down, sb-left, sb-up,sb-


right, sb-down 47

Path cost: 5 steps to reach the goal


Exercise: The 8 puzzle
• This is
problem
the problem of arranging the tiles so that all the
tiles are in the correct positions. You do this by moving
tiles or space up, down, left, or right, so long as the
following conditions are met:
– a) there's no other tile blocking you in the direction of the
movement; and
– b) you're not trying to move outside of the boundaries/ edges.
1 2 3 1 2 3
• Identify possible states & operators?
8 4 5 8 4
• Construct state space?
7 6 7 6 548
Steps in problem
solving
•Goal formulation
– is a step that specifies exactly what the agent is trying to
achieve
– This step narrows down the scope that the agent has to look at
•Problem formulation
– is a step that puts down the actions and states that the agent has to
consider given
a goal (avoiding any redundant states), like:
• the initial state
• the allowable actions etc…
•Search
– is the process of looking for the various sequence of actions that
lead to a goal state, evaluating them and choosing the optimal
sequence.
•Execute
– is the final step that the agent executes the chosen sequence of
• Formulate Example: Path Finding
– be in
goal:
Bucharest
(Romania)
problem Initial
State
• Formulate
– action: drive
problem:
between pair of
connected cities
Goal
(direct road) State
– state: be in a
city
(20 world
• Findstates)
– sequence of cities
solution:
leading from start
to goal state, e.g.,
Arad, Sibiu,
Fagaras, Bucharest
• Executi
– drive from Arad
on
to Bucharest
according to the
solution
Problem Solving Agent
Algorithm
function SIMPLE-PROBLEM-SOLVING-
AGENT(percept) returns an action
static: seq, an action sequence, initially empty
state, some description of the current world state
goal, a goal initially null
problem, a problem formulation
state  UPDATE-STATE(state, percept)
if seq is empty then do
goal  FORMULATE-GOAL(state)
problem FORMULATE-
PROBLEM(state,goal)
seq  SEARCH(problem)
If seq= failure then return a null action 53
returnaction  FIRST(seq)
Searchi
• ngof methods to systematically
search consists of a set
determine the
next best action in order to search for a solution of a
problem

• parts of a problem: initial state, operators, goal test


function, path cost function.

• Examine different possible sequences of actions &


states, and come up with specific optimal sequence of
actions that will take you from the initial state to the
goal state
Searchin
•Searching in State Space
g…
– select optimal (min-cost/max-profit) node/state in the
state space
– test whether the state selected is the goal state or
not
– if not, expand the node further to identify its
successor.
Search
• The searching process is like building the search tree that is
Tree
super imposed over the state space
– A search tree is a representation in which nodes denote paths and
branches connect
paths. The node with no parent is the root node. The nodes with no
children are called leaf nodes.
Example: Route finding Problem
• Partial search tree for route finding from Sidistgoal
SidistKilo Kilotestto
(a) The initial
Stadium.
state SidistKilo
(b) After expanding generating a new state
Sidist Kilo AratKilo Giorgis ShiroMeda
choosing one SidistKilo
option

AratKilo Giorgis ShiroMeda


(c) After expanding
Arat Kilo
MeskelSquare Piassa Megenagna
Search

algorithm
•Two functions needed for conducting search
Generator (or successors) function: Given a state and action,
produces its successor
states (in a state space)
– Tester (or IsGoal) function: Tells whether given state S is a goal
state IsGoal(S) 
True/False
IsGoal and Successors functions depend on problem domain.
• Two lists maintained during searching
– OPEN list: stores the nodes expanded but not explored
– CLOSED list: the nodes expanded and explored
Generally search proceeds by examining each node on the OPEN list;
performing some expansion operation that adds its children to the OPEN
list, & moving the node to the CLOSED list
• Merge function: Given successor nodes, it either append, prepend
to open list or rearrange based on evaluation cost
• Path cost: function assigning a numeric cost to each path; either
General Search
I. identifyAlgorithm
initial state
II. expand /generate new states
III. choose option(search strategy)
IV. test goal function
V. expand until goal not attained/no more
states to expand
Search
algorithm
• Input: a given problem (Initial State + Goal state + transit
states and operators)
• Output: returns optimal sequence of actions to reach the
goal.
function GeneralSearch (problem, strategy)
open = (initialState); //put initial state
in the List closed = {}; //maintain list of
nodes examined earlier while (not
(empty (open)))
f = remove_first(open);
if IsGoal (f) then
return (f); closed =
append (closed, f);
succ = Successors (f)
left = not-in-closed
(succ, closed );
• Completen Evaluation Searching
ess Algorithm
– Guarantees finding a solution whenever one exists.
– Think about the density of solutions in space and evaluate
whether the searching
technique guaranteed to find all solutions or not.
• Optimality
– is the algorithm finding an optimal solution; i.e. the one with
minimize cost or
maximize profit
– If a solution is found, is it guaranteed to be an optimal one?
That is, is it the one with minimum cost?
• how good is our solution?
 Time complexity
- how long does it take to find a solution
- Usually measured in terms of the number of nodes expanded
Searching
examined
Strategies
•Search strategy gives the order in which the search space is

•Uninformed (= blind) search


– they do not need domain knowledge that guide them towards the
goal
– Have no information about the number of steps or the
path cost from the
Uninformed
considstate to the goal
current
er search
– It is important for
problems for which Breadth
there is no additionalfirst
information to Depth
first
Searching
•Informed (= heuristic) search
Strategies…
– have problem-specific knowledge (knowledge that is true
from experience)
– Have knowledge about how far are the various state from
the goal
– Can find solutions more efficiently than uninformed
search

Informed search
Greedy search
A*-search
Iterative
improvement
Constraint
64
Types of Problems via
Knowledge
• Solving Level
a problem requires knowledge about:
– The states: are they fully accessible or inaccessible
– Effects of its action: deterministic or non-deterministic
• Thus, the 1st step in problem formulation for an agent is to see
– to what extent the state of the world is accessible or fully
observable to the
agent to update its knowledge
– the extent of knowledge it has to determine the effects of its
action on the environment
• This knowledge depends on how it is connected to the
and 65
environment via its percepts
Cont
’d
• Problems can be classified into four types based
on the level of knowledge that an agent can have
concerning its action and the state of the world

Increasing complexity
– Type 1: Single state problems
– Type 2: Multiple state problems
– Type 3: Exploration problems
– Type 4: Contingency Problems

66
Example: Vacuum world
To simplifyproblem
the problem (rather
than the
full version), let;
•The world has only two
locations
– Each location may or may
not contain dirt
– The agent may be in one
location or the
other
• Eight possible world states
• Three possible actions (Left,
Right,
Suck) 67
– Suck operator clean the dirt
Vacuum Cleaner state
Space

68
I. Single state
problem
• Fully observable: The world is accessible to the agent
– It can determine its exact state through its sensors
– The agent’s sensor knows which state it is in
• Deterministic: The agent knows exactly the effect of its actions
– It can then calculate exactly which state it will be in after any
sequence of actions
• Action sequence is completely planned
Example - Vacuum cleaner world
– Can the agent achieve its goal? Let say the agent is initially at
state 4?
– Agent •easily
Right  &{6}
calculates formulates sequences of actions ([Left,
Suck])•andSuck  get {8
knows that it will to a goal state
} 69
II. Multiple state
problems
• Partially observable: The agent has limited access to the world
state
– It might not have sensors to get full access to the environment states or
as an extreme, it can have no sensors at all (due to lack of percepts)
• Deterministic: The agent knows exactly what each of its actions do
– It can then calculate which state it will be in after any sequence of
actions
Example - Vacuum cleaner world
– Can the agent achieve its goal?
• If the agent has full knowledge of how its actions change the world, but
does not know of the state of the world, it can still solve the task
– Agent’s initial state is one of the 8 states: {1,2,3,4,5,6,7,8}
– Action sequence: {right, suck, left, suck}
Right what
– Because agent knows its actions do,Suck
 [2.4.6.8.] {4,8} and
it candiscover
reach to goal state.
Left {3,7} Suck  {7} 70

II Contingency
I. Problems
•Partially observable: The agent has limited access to the world
state
•Non-deterministic: The agent is ignorant of the effect of its
actions
– Sometimes ignorance prevents the agent from
finding a guaranteed solution sequence.
•Suppose the agent is in Murphy’s law world
– The agent has to sense during the execution phase, since things
might have changed while it was carrying out an action. This
implies that
• the agent has to compute a tree of actions, rather than a linear
sequence of
action 71
– Example - Vacuum cleaner world:
Cont
• ’d world
Example - Vacuum cleaner
– What will happen given initial state [1,2,3,4,5,6,7,8], and
action sequence: [Suck,
Right, Suck]?
{5, 4, 7, 2, 1, 8,3,6}  {2,4,6,8}  {4,2,8,6} (failure)
• Is there a way to solve this problem?
– Solving this problem requires local sensing, i.e. sensing the
execution phase,
– Start from one of the states {1,2,3,4,5,6,7,8}, and take
improved action sequence [Suck, Right, Suck (only if there is
dirt there)]
• Many problems in the real world are contingency
problems (exact prediction is impossible)
– For this reason many people keep their eyes open while 72

walking around or driving.


IV. Exploration
problem
• The agent has no knowledge of the environment
– World Partially observable : No knowledge of states
(environment)
• Unknown state space (no map, no sensor)
– Non-deterministic: No knowledge of the effects of its actions
– Problem faced by (intelligent) agents (like, newborn babies)
• This is a kind of problem in the real world rather than in a
model, which may involve significant danger for an ignorant
agent. If the agent survives, it learns about the environment
• The agentmustexperiment, learn andbuild the model
of the environment
through its results, gradually, discovering
– What sort of states exist and What its action do
– Then it can use these to solve subsequent (future) problems
• Example: in solving Vacuum cleaner world problem the agent
learns the state space and the effects of its action sequences
End!
!!

74

You might also like