public class OnlineDFSAgent extends AbstractAgent
function ONLINE-DFS-AGENT(s') returns an action
inputs: s', a percept that identifies the current state
persistent: result, a table, indexed by state and action, initially empty
untried, a table that lists, for each state, the actions not yet tried
unbacktracked, a table that lists, for each state, the backtracks not yet tried
s, a, the previous state and action, initially null
if GOAL-TEST(s') then return stop
if s' is a new state (not in untried) then untried[s'] <- ACTIONS(s')
if s is not null then
result[s, a] <- s'
add s to the front of the unbacktracked[s']
if untried[s'] is empty then
if unbacktracked[s'] is empty then return stop
else a <- an action b such that result[s', b] = POP(unbacktracked[s'])
else a <- POP(untried[s'])
s <- s'
return a
Figure 4.21 An online search agent that uses depth-first exploration. The
agent is applicable only in state spaces in which every action can be
"undone" by some other action.program| Constructor and Description |
|---|
OnlineDFSAgent(OnlineSearchProblem problem,
PerceptToStateFunction ptsFunction)
Constructs an online DFS agent with the specified search problem and
percept to state function.
|
| Modifier and Type | Method and Description |
|---|---|
Action |
execute(Percept psDelta)
Call the Agent's program, which maps any given percept sequences to an
action.
|
PerceptToStateFunction |
getPerceptToStateFunction()
Returns the percept to state function of this agent.
|
OnlineSearchProblem |
getProblem()
Returns the search problem for this agent.
|
void |
setPerceptToStateFunction(PerceptToStateFunction ptsFunction)
Sets the percept to state functino of this agent.
|
void |
setProblem(OnlineSearchProblem problem)
Sets the search problem for this agent to solve.
|
isAlive, setAlivepublic OnlineDFSAgent(OnlineSearchProblem problem, PerceptToStateFunction ptsFunction)
problem - an online search problem for this agent to solveptsFunction - a function which returns the problem state associated with a
given Percept.public OnlineSearchProblem getProblem()
public void setProblem(OnlineSearchProblem problem)
problem - the search problem for this agent to solve.public PerceptToStateFunction getPerceptToStateFunction()
public void setPerceptToStateFunction(PerceptToStateFunction ptsFunction)
ptsFunction - a function which returns the problem state associated with a
given Percept.public Action execute(Percept psDelta)
Agentexecute in interface Agentexecute in class AbstractAgentpsDelta - The current percept of a sequence perceived by the Agent.