Title: PAGE of designing an agent
1L2. Problem Solving Using Search
- PAGE of designing an agent
- Problem types
- Problem formulation
- Search Strategies
2PAGE Percepts, Actions, Goals, Environment
Sensorseyes, camera,
percepts
environment
agent
actions
Effectorshands, motors,
Fig1. A generic agent diagram
e.g.
Percepts
cameras, speedometer, GPS, sonar
Actions
steer, accelerate, brake
Goals
safely to destination
Environment
traffic light, other traffic, pedestrians, in
Japan
Fig 1. The taxi driver agent and its PAGE
description
3More e.g. Vacuum-clearning Agent
Percepts
touch sensor, photo sensor, infrared sensor
go forward, turn right by 90o,turn left by 90o,
such up dirt, and turn off
Actions
Goals
clean up the room
A grid of squares that may have obstacles (wall
or furniture), dirt, or may be open space (having
nothing)
Environment
Fig 2. The Vacuum-cleaning agent and its PAGE
description
Notes Touch sensor is to check if the machine
has bumped into something. Photo
sensor is to check if there is dirt there.
Infrared sensor is to check if the agent
is in its home location.
4Problem types
Deterministic, accessible gt single-state
problem The agent sensors give it enough
information to tell exactly which state it is
in. technique ? search Deterministic,
inaccessible gt multiple-state problem The
agent knows all the effects of its actions but
has limited access to the world state so
that it must reason about sets of states that it
might get to. technique ? search Nondetermini
stic, inaccessible gt Contingency problem
There is no fixed action sequence that guarantees
a solution to the problem. It must sensors
during execution. solution is a tree or
policy, not a single sequence of actions.
techniques interleave search execution Unknown
state space gt exploration problem The
agent must experiment, gradually discovering what
its actions do and what sorts of states
exist. techniques experiment discovery
more
knowledge
less
5Define a problem
A problem is defined by four items initial
state The world initial state. operators
A set of possible actions. goal-test To
check if it reaches goal state or
states. path-cost-fucntion It is the sum of
cost of the individual actions along the path,
which is from one state to another.
Notes State space is the set of all states
reachable from the initial state by
any sequence of actions. Solution is
a path (a sequence of operators) from the initial
state to a state that satisfies the
goal test.
?
How to find a solution?
search
6Some examples - e.g. 1
The 8-puzzle
5
4
1
2
3
1
8
6
4
8
2
3
7
5
6
7
Start state
Goal state
state the location of each of the eight tiles in
one of the nine squares. operators blank tile
moves left, right, up, or down. goal-test state
matches the goal state. path-cost-fucntion each
step costs 1so the total cost is the length of
the path.
?
Can you write a Java program that can find a
solution, i.e. path from the initial state to the
goal state?
7Some examples e.g. 2
The vacuum world 2 squares
vacuum
1
3
5
7
dirt
2
4
6
8
state one of the eight states above. operators
move left, move right, suck. goal-test no dirt
left in any square. path-cost-fucntion each
action costs 1.
Can you write a Java program that can find a
solution, i.e. path from any initial state to the
goal state?
?
8Breath-first search
The breadth-first search algorithm searches a
state space by constructing a hierarchical tree
structure consisting of a set of nodes and links.
The algorithm defines a way to move through the
tree structure, examining the value at nodes.
From the start, it looks at each node one edge
away. Then it moves out from those nodes to all
two edges away from the start. This continues
until either the goal node is found or the entire
tree is searched.
- The algorithm follows
- Create a queue and add the first node to it.
- Loop
- If the queue is empty, quit.
- Remove the first node from the queue.
- If the node contains the goal state, then exit
with the node as the solution. - For each child of the current node add the new
state to the back of the queue.
9An example of breadth-first search Rochester ?
Wausau
InternationalFalls
GrandForks
Bemidji
Duluth
Fargo
GreenBay
Minneapolis
St.Cloud
Wausau
LaCrosse
Madison
Milwaukee
Rochester
Sioux
Dubuque
Rockford
Chicago
Rochester-gtSioux Falls, Minneapolis, LaCrosse,
Dubuque-gtMinneapolis, LaCrosse, Dubuque, Frago,
Rochester-gt LaCrosse, Dubuque, Frago,
Rochester, St.Cloud, Duluth, Wausau, LaCrosse,
Rochester-gt(after 5 goal test and expansion)
-gt Wausau, LaCrosse, Rochester, Minneapolis,
GreenBay, Finally, we get to Wausau, the goal
test succeeds.
10A demo
Source code for your reference
public SearchNode breadthFirstSearch(SearchNode
initialNode, Object goalState) Vector
queue new Vector() queue.addElement(init
ialNode) initialNode.setTested(true)
// test each node once while
(queue.size()gt 0) SearchNode testNode
(SearchNode)queue.firstElement()
queue.removeElementAt(0)
testNode.trace() if (testNode.state.equa
ls(goalState)) return testNode // found it
if (!testNode.expanded)
testNode.expand(queue,SearchNode.BACK)
return null
11Depth-first search
The depth-first algorithm follows a single branch
of the tree down as many levels as possible until
we either reach a solution or a dead end. It
searches from the start or root node all the way
down to a leaf node. If it does not find the goal
node, it backtracks up the tree and searches down
the next untested path until it reaches the next
leaf.
- The algorithm follows
- Create a queue and add the first node to it.
- Loop
- If the queue is empty, quit.
- Remove the first node from the queue.
- If the node contains the goal state, then exit
with the node as the solution. - For each child of the current node add the new
state to the front of the queue.
12An example of depth-first search Rochester ?
Wausau
InternationalFalls
GrandForks
Bemidji
Duluth
Fargo
GreenBay
Minneapolis
St.Cloud
Wausau
LaCrosse
Madison
Milwaukee
Rochester
Sioux
Dubuque
Rockford
Chicago
Rochester-gtDubuque, LaCrosse, Minneapolis,
Sioux Falls-gtRockford, LaCrosse,
Rochester,LaCrosse, Minneapolis, Sioux Falls-gt
(after 3 goal test and expansion) -gt
GreenBay, Madison, Chicago, Rockford, Chicago,
Madison, Dubuque, LaCrosse, Rochester,LaCrosse,
Minneapolis, Sioux Falls We remove GreenBay and
add Milwaukee, LaCrosse, and Wausau to the queue
in that order. Finally, we get to Wausau, at the
front of the queue and the goal test succeeds.
13A demo
Source code for your reference
public SearchNode depthFirstSearch(SearchNode
initialNode, Object goalState)
Vector queue new Vector()
queue.addElement(initialNode)
initialNode.setTested(true) // test each node
once while (queue.size()gt 0)
SearchNode testNode (SearchNode)queue.firstEleme
nt() queue.removeElementAt(0)
testNode.trace() // display trace
information if (testNode.state.equals(go
alState)) return testNode // found it
if (!testNode.expanded)
testNode.expand(queue,SearchNode.FRONT)
return null