public class World
extends java.lang.Object
StateAbstraction
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 StateAbstraction |
abstractionForAgents |
protected HashedAggregator<java.lang.String> |
agentCumulativeReward |
protected java.util.Map<java.lang.String,AgentType> |
agentDefinitions |
protected java.util.List<Agent> |
agents |
protected java.util.Map<AgentType,java.util.List<Agent>> |
agentsByType |
protected GameAnalysis |
currentGameRecord |
protected State |
currentState |
protected int |
debugId |
protected SGDomain |
domain |
protected SGStateGenerator |
initialStateGenerator |
protected boolean |
isRecordingGame |
protected JointReward |
jointRewardModel |
protected JointAction |
lastJointAction |
protected TerminalFunction |
tf |
protected JointActionModel |
worldModel |
protected java.util.List<WorldObserver> |
worldObservers |
Constructor and Description |
---|
World(SGDomain domain,
JointActionModel jam,
JointReward jr,
TerminalFunction tf,
SGStateGenerator sg)
Deprecated.
|
World(SGDomain domain,
JointActionModel jam,
JointReward jr,
TerminalFunction tf,
SGStateGenerator sg,
StateAbstraction abstractionForAgents)
Deprecated.
|
World(SGDomain domain,
JointReward jr,
TerminalFunction tf,
SGStateGenerator sg)
Initializes the world.
|
World(SGDomain domain,
JointReward jr,
TerminalFunction tf,
SGStateGenerator sg,
StateAbstraction abstractionForAgents)
Initializes the world
|
Modifier and Type | Method and Description |
---|---|
void |
addWorldObserver(WorldObserver ob)
Adds a world observer to this world
|
protected boolean |
agentInstanceExists(Agent a)
Returns whether the reference for the given agent already exists in the registered agents
|
void |
clearAllWorldObserver()
Clears all world observers from this world.
|
void |
generateNewCurrentState()
Causes the world to set the current state to a state generated by the provided
SGStateGenerator object. |
JointActionModel |
getActionModel()
Returns the
JointActionModel used in this world. |
java.util.Map<java.lang.String,AgentType> |
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. |
JointAction |
getLastJointAction()
Returns the last joint action taken in this world; null if none have been taken yet.
|
protected java.lang.String |
getNewWorldNameForAgentAndIndex(Agent a,
AgentType type)
Returns a unique agent name for the given agent object and agent type for that agent.
|
int |
getPlayerNumberForAgent(java.lang.String aname)
Returns the player index for the agent with the given name.
|
java.util.List<Agent> |
getRegisteredAgents()
Returns the list of agents participating in this world.
|
JointReward |
getRewardModel()
Returns the
JointReward function used in this world. |
TerminalFunction |
getTF()
Returns the
TerminalFunction used in this world. |
protected void |
init(SGDomain domain,
JointActionModel jam,
JointReward jr,
TerminalFunction tf,
SGStateGenerator sg,
StateAbstraction abstractionForAgents) |
protected java.lang.String |
registerAgent(Agent a,
AgentType at)
Registers an agent to be a participant in this world.
|
void |
removeWorldObserver(WorldObserver ob)
Removes the specified world observer from this world
|
GameAnalysis |
rolloutJointPolicy(JointPolicy jp,
int maxStages)
Rollsout a joint policy until a terminate state is reached for a maximum number of stages.
|
GameAnalysis |
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
|
GameAnalysis |
runGame()
Runs a game until a terminal state is hit.
|
GameAnalysis |
runGame(int maxStages)
Runs a game until a terminal state is hit for maxStages have occurred
|
void |
runStage()
Runs a single stage of this game.
|
void |
setDebugId(int id)
Sets the debug code that is use for printing with
DPrint . |
protected SGDomain domain
protected State currentState
protected java.util.List<Agent> agents
protected HashedAggregator<java.lang.String> agentCumulativeReward
protected java.util.Map<java.lang.String,AgentType> agentDefinitions
protected JointActionModel worldModel
protected JointReward jointRewardModel
protected TerminalFunction tf
protected SGStateGenerator initialStateGenerator
protected StateAbstraction abstractionForAgents
protected JointAction lastJointAction
protected java.util.List<WorldObserver> worldObservers
protected GameAnalysis currentGameRecord
protected boolean isRecordingGame
protected int debugId
@Deprecated public World(SGDomain domain, JointActionModel jam, JointReward jr, TerminalFunction tf, SGStateGenerator sg)
SGDomain
objects are now expected
to have a JointActionModel
associated with them, making the constructor parameter for it
unnecessary. Instead use the constructor World(SGDomain, JointReward, burlap.oomdp.core.TerminalFunction, SGStateGenerator)
domain
- the SGDomain the world will usejam
- the joint action model that specifies the transition dynamicsjr
- the joint reward functiontf
- the terminal functionsg
- a state generator for generating initial states of a gamepublic World(SGDomain domain, JointReward jr, TerminalFunction tf, SGStateGenerator sg)
domain
- the SGDomain the world will usejr
- the joint reward functiontf
- the terminal functionsg
- a state generator for generating initial states of a game@Deprecated public World(SGDomain domain, JointActionModel jam, JointReward jr, TerminalFunction tf, SGStateGenerator sg, StateAbstraction abstractionForAgents)
SGDomain
objects are now expected
to have a JointActionModel
associated with them, making the constructor parameter for it
unnecessary. Instead use the constructor World(SGDomain, JointReward, burlap.oomdp.core.TerminalFunction, SGStateGenerator, burlap.oomdp.auxiliary.StateAbstraction)
domain
- the SGDomain the world will usejam
- the joint action model that specifies the transition dynamicsjr
- 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 providedpublic World(SGDomain domain, JointReward jr, TerminalFunction tf, SGStateGenerator sg, StateAbstraction 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, JointActionModel jam, JointReward jr, TerminalFunction tf, SGStateGenerator sg, StateAbstraction abstractionForAgents)
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 agentprotected java.lang.String registerAgent(Agent a, AgentType at)
a
- the agent to be registered in this worldat
- the agent type the agent will be playing aspublic State getCurrentWorldState()
public void generateNewCurrentState()
SGStateGenerator
object.public JointAction getLastJointAction()
public void addWorldObserver(WorldObserver ob)
ob
- the observer to addpublic void removeWorldObserver(WorldObserver ob)
ob
- the world observer to removepublic void clearAllWorldObserver()
public GameAnalysis runGame()
public GameAnalysis runGame(int maxStages)
maxStages
- the maximum number of stages to play in the game before its forced to end.public GameAnalysis rolloutJointPolicy(JointPolicy jp, int maxStages)
jp
- the joint policy to rolloutmaxStages
- the maximum number of stagesGameAnalysis
that has recorded the result.public GameAnalysis 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 stagesGameAnalysis
that has recorded the result.public void runStage()
protected void rolloutOneStageOfJointPolicy(JointPolicy jp)
jp
- the joint policy to followpublic JointActionModel getActionModel()
JointActionModel
used in this world.JointActionModel
used in this world.public JointReward getRewardModel()
JointReward
function used in this world.JointReward
function used in this world.public TerminalFunction getTF()
TerminalFunction
used in this world.TerminalFunction
used in this world.public java.util.List<Agent> getRegisteredAgents()
public java.util.Map<java.lang.String,AgentType> getAgentDefinitions()
public int getPlayerNumberForAgent(java.lang.String aname)
aname
- the name of the agentprotected java.lang.String getNewWorldNameForAgentAndIndex(Agent a, AgentType type)
a
- the agent for which a unique name is to be returnedtype
- the agent type of the agentprotected boolean agentInstanceExists(Agent a)
a
- the agent reference to check for