public class World
extends java.lang.Object
StateMapping
object so that agents are provided an
abstract and simpler representation of the world. A game can be run until a terminal state is hit, or for a specific
number of stages, the latter of which is useful for repeated games.Modifier and Type | Field and Description |
---|---|
protected StateMapping |
abstractionForAgents |
protected HashedAggregator<java.lang.String> |
agentCumulativeReward |
protected java.util.List<SGAgent> |
agents |
protected GameEpisode |
currentGameEpisodeRecord |
protected State |
currentState |
protected int |
debugId |
protected SGDomain |
domain |
protected StateGenerator |
initialStateGenerator |
protected boolean |
isRecordingGame |
protected JointRewardFunction |
jointRewardFunction |
protected JointAction |
lastJointAction |
protected double[] |
lastRewards |
protected TerminalFunction |
tf |
protected JointModel |
worldModel |
protected java.util.List<WorldObserver> |
worldObservers |
Constructor and Description |
---|
World(SGDomain domain,
JointRewardFunction jr,
TerminalFunction tf,
State initialState)
Initializes the world.
|
World(SGDomain domain,
JointRewardFunction jr,
TerminalFunction tf,
StateGenerator sg)
Initializes the world.
|
World(SGDomain domain,
JointRewardFunction jr,
TerminalFunction tf,
StateGenerator sg,
StateMapping abstractionForAgents)
Initializes the world
|
Modifier and Type | Method and Description |
---|---|
void |
addWorldObserver(WorldObserver ob)
Adds a world observer to this world
|
SGAgent |
agentWithName(java.lang.String name)
Returns the agent with the given name, or null if there is no agent with that name.
|
void |
clearAllWorldObserver()
Clears all world observers from this world.
|
void |
executeJointAction(JointAction ja)
Manually attempts to execute a joint action in the current world state, if a game is currently not running.
|
boolean |
gameIsRunning()
Returns whether a game in this world is currently running.
|
void |
generateNewCurrentState()
Causes the world to set the current state to a state generated by the provided
StateGenerator object
if a game is not currently running. |
JointModel |
getActionModel()
Returns the
JointModel used in this world. |
java.util.List<SGAgentType> |
getAgentDefinitions()
Returns the agent definitions for the agents registered in this world.
|
double |
getCumulativeRewardForAgent(java.lang.String aname)
Returns the cumulative reward that the agent with name aname has received across all interactions in this world.
|
State |
getCurrentWorldState()
Returns the current world state
|
int |
getDebugId()
This class will report execution information as games are played using the
DPrint class. |
SGDomain |
getDomain() |
JointAction |
getLastJointAction()
Returns the last joint action taken in this world; null if none have been taken yet.
|
double[] |
getLastRewards()
Returns the last rewards received.
|
int |
getPlayerNumberForAgent(java.lang.String aname)
Returns the player index for the agent with the given name.
|
java.util.List<SGAgent> |
getRegisteredAgents()
Returns the list of agents participating in this world.
|
JointRewardFunction |
getRewardFunction()
Returns the
JointRewardFunction function used in this world. |
TerminalFunction |
getTF()
Returns the
TerminalFunction used in this world. |
protected void |
init(SGDomain domain,
JointModel jam,
JointRewardFunction jr,
TerminalFunction tf,
StateGenerator sg,
StateMapping abstractionForAgents) |
void |
join(SGAgent a)
Causes the provided agent to join the world
|
void |
removeWorldObserver(WorldObserver ob)
Removes the specified world observer from this world
|
GameEpisode |
rolloutJointPolicy(JointPolicy jp,
int maxStages)
Rollsout a joint policy until a terminate state is reached for a maximum number of stages.
|
GameEpisode |
rolloutJointPolicyFromState(JointPolicy jp,
State s,
int maxStages)
Rollsout a joint policy from a given state until a terminate state is reached for a maximum number of stages.
|
protected void |
rolloutOneStageOfJointPolicy(JointPolicy jp)
Runs a single stage following a joint policy for the current world state
|
GameEpisode |
runGame()
Runs a game until a terminal state is hit.
|
GameEpisode |
runGame(int maxStages)
Runs a game until a terminal state is hit for maxStages have occurred
|
GameEpisode |
runGame(int maxStages,
State s)
Runs a game starting in the input state until a terminal state is hit.
|
void |
runStage()
Runs a single stage of this game.
|
void |
setCurrentState(State s)
Sets the world state to the provided state if the a game is not currently running.
|
void |
setDebugId(int id)
Sets the debug code that is use for printing with
DPrint . |
void |
setDomain(SGDomain domain) |
boolean |
worldStateIsTerminal()
Returns whether the current state in the world is a terminal state or not.
|
protected SGDomain domain
protected State currentState
protected java.util.List<SGAgent> agents
protected HashedAggregator<java.lang.String> agentCumulativeReward
protected JointModel worldModel
protected JointRewardFunction jointRewardFunction
protected TerminalFunction tf
protected StateGenerator initialStateGenerator
protected StateMapping abstractionForAgents
protected JointAction lastJointAction
protected java.util.List<WorldObserver> worldObservers
protected GameEpisode currentGameEpisodeRecord
protected boolean isRecordingGame
protected int debugId
protected double[] lastRewards
public World(SGDomain domain, JointRewardFunction jr, TerminalFunction tf, State initialState)
domain
- the SGDomain the world will usejr
- the joint reward functiontf
- the terminal functioninitialState
- the initial state of the world every time a new game startspublic World(SGDomain domain, JointRewardFunction jr, TerminalFunction tf, StateGenerator sg)
domain
- the SGDomain the world will usejr
- the joint reward functiontf
- the terminal functionsg
- a state generator for generating initial states of a gamepublic World(SGDomain domain, JointRewardFunction jr, TerminalFunction tf, StateGenerator sg, StateMapping abstractionForAgents)
domain
- the SGDomain the world will usejr
- the joint reward functiontf
- the terminal functionsg
- a state generator for generating initial states of a gameabstractionForAgents
- the abstract state representation that agents will be providedprotected void init(SGDomain domain, JointModel jam, JointRewardFunction jr, TerminalFunction tf, StateGenerator sg, StateMapping abstractionForAgents)
public SGDomain getDomain()
public void setDomain(SGDomain domain)
public int getDebugId()
DPrint
class. If the user
wishes to suppress these messages, they can retrieve this code and suppress DPrint from printing messages that correspond to this code.DPrint
.public void setDebugId(int id)
DPrint
.id
- the debug code to use when printing messagespublic double getCumulativeRewardForAgent(java.lang.String aname)
aname
- the name of the agentpublic void join(SGAgent a)
a
- the agent to joinpublic SGAgent agentWithName(java.lang.String name)
name
- the name of the agentSGAgent
with the name in this world, or null if there is none.public State getCurrentWorldState()
public void generateNewCurrentState()
StateGenerator
object
if a game is not currently running. If a game is currently running, then the state will not be changed.public boolean worldStateIsTerminal()
public void setCurrentState(State s)
s
- the state to which the world will be set.public JointAction getLastJointAction()
public double[] getLastRewards()
public void addWorldObserver(WorldObserver ob)
ob
- the observer to addpublic void removeWorldObserver(WorldObserver ob)
ob
- the world observer to removepublic void clearAllWorldObserver()
public void executeJointAction(JointAction ja)
ja
- the JointAction
to execute.public GameEpisode runGame()
GameEpisode
of the game.public GameEpisode runGame(int maxStages)
maxStages
- the maximum number of stages to play in the game before its forced to end. If set to -1, then run until a terminal state is hit.GameEpisode
of the game.public GameEpisode runGame(int maxStages, State s)
maxStages
- the maximum number of stages to play in the game before its forced to end. If set to -1, then run until a terminal state is hit.s
- the input State
from which the game will startGameEpisode
of the game.public GameEpisode rolloutJointPolicy(JointPolicy jp, int maxStages)
jp
- the joint policy to rolloutmaxStages
- the maximum number of stagesGameEpisode
that has recorded the result.public GameEpisode rolloutJointPolicyFromState(JointPolicy jp, State s, int maxStages)
jp
- the joint policy to rollouts
- the state from which the joint policy should be rolled outmaxStages
- the maximum number of stagesGameEpisode
that has recorded the result.public void runStage()
protected void rolloutOneStageOfJointPolicy(JointPolicy jp)
jp
- the joint policy to followpublic JointModel getActionModel()
JointModel
used in this world.JointModel
used in this world.public JointRewardFunction getRewardFunction()
JointRewardFunction
function used in this world.JointRewardFunction
function used in this world.public TerminalFunction getTF()
TerminalFunction
used in this world.TerminalFunction
used in this world.public java.util.List<SGAgent> getRegisteredAgents()
public java.util.List<SGAgentType> getAgentDefinitions()
public int getPlayerNumberForAgent(java.lang.String aname)
aname
- the name of the agentpublic boolean gameIsRunning()