aima.core.learning.reinforcement.agent.ReinforcementAgent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aima-core Show documentation
Show all versions of aima-core Show documentation
AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.
The newest version!
package aima.core.learning.reinforcement.agent;
import java.util.Map;
import aima.core.agent.Action;
import aima.core.agent.Percept;
import aima.core.agent.impl.AbstractAgent;
import aima.core.agent.impl.NoOpAction;
import aima.core.learning.reinforcement.PerceptStateReward;
/**
* An abstract base class for creating reinforcement based agents.
*
* @param
* the state type.
* @param
* the action type.
*
* @author Ciaran O'Reilly
* @author Ravi Mohan
*/
public abstract class ReinforcementAgent extends
AbstractAgent {
/**
* Default Constructor.
*/
public ReinforcementAgent() {
}
/**
* Map the given percept to an Agent action.
*
* @param percept
* a percept indicating the current state s' and reward signal r'
* @return the action to take.
*/
public abstract A execute(PerceptStateReward percept);
/**
* Get a vector of the currently calculated utilities for states of type S
* in the world.
*
* @return a Map of the currently learned utility values for the states in
* the environment (Note: this map may not contain all of the states
* in the environment, i.e. the agent has not seen them yet).
*/
public abstract Map getUtility();
/**
* Reset the agent back to its initial state before it has learned anything
* about its environment.
*/
public abstract void reset();
@SuppressWarnings("unchecked")
@Override
public Action execute(Percept p) {
if (p instanceof PerceptStateReward) {
Action a = execute((PerceptStateReward) p);
if (null == a) {
a = NoOpAction.NO_OP;
setAlive(false);
}
return a;
}
throw new IllegalArgumentException(
"Percept passed in must be a PerceptStateReward");
}
}