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,SGAgentType> |
agentDefinitions |
protected java.util.List<SGAgent> |
agents |
protected java.util.Map<SGAgentType,java.util.List<SGAgent>> |
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 java.util.Map<java.lang.String,java.lang.Double> |
lastRewards |
protected TerminalFunction |
tf |
protected JointActionModel |
worldModel |
protected java.util.List<WorldObserver> |
worldObservers |
Constructor and Description |
---|
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
|
World(SGDomain domain,
JointReward jr,
TerminalFunction tf,
State initialState)
Initializes the world.
|
Modifier and Type | Method and Description |
---|---|
void |
addWorldObserver(WorldObserver ob)
Adds a world observer to this world
|
protected boolean |
agentInstanceExists(SGAgent 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 |
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
SGStateGenerator object
if a game is not currently running. |
JointActionModel |
getActionModel()
Returns the
JointActionModel used in this world. |
java.util.Map<java.lang.String,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.
|
java.util.Map<java.lang.String,java.lang.Double> |
getLastRewards()
Returns the last rewards received.
|
protected java.lang.String |
getNewWorldNameForAgentAndIndex(SGAgent a,
SGAgentType 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<SGAgent> |
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(SGAgent a,
SGAgentType 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
|
GameAnalysis |
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 java.util.Map<SGAgentType,java.util.List<SGAgent>> agentsByType
protected HashedAggregator<java.lang.String> agentCumulativeReward
protected java.util.Map<java.lang.String,SGAgentType> 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
protected java.util.Map<java.lang.String,java.lang.Double> lastRewards
public World(SGDomain domain, JointReward 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, 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 gamepublic 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 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 agentprotected java.lang.String registerAgent(SGAgent a, SGAgentType 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
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 java.util.Map<java.lang.String,java.lang.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 GameAnalysis runGame()
GameAnalysis
of the game.public GameAnalysis 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.GameAnalysis
of the game.public GameAnalysis 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 startGameAnalysis
of the game.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<SGAgent> getRegisteredAgents()
public java.util.Map<java.lang.String,SGAgentType> getAgentDefinitions()
public int getPlayerNumberForAgent(java.lang.String aname)
aname
- the name of the agentpublic boolean gameIsRunning()
protected java.lang.String getNewWorldNameForAgentAndIndex(SGAgent a, SGAgentType type)
a
- the agent for which a unique name is to be returnedtype
- the agent type of the agentprotected boolean agentInstanceExists(SGAgent a)
a
- the agent reference to check for