public class GameAnalysis
extends java.lang.Object
GameAnalysis(State)
) or by constructing with the default constructor and then
using the initializeGameWithInitialState(State)
method before recording any further transitions. Transitions should then be recorded with the
recordTransitionTo(JointAction, State, Map)
method which takes as input the next state to which the agent transtions, the joint action taken
in the previously recorded state that causes the transition, and the joint reward received for the transition.
When querying about the state, joint action, or joint rewards, use the methods getState(int)
, getJointAction(int)
, and getJointReward(int)
respectively.
These methods take as input the time step of the element you want. Note that t = 0 refers to the initial state step so calling getState(0) and getJointAction(0)
will return the initial state and the joint action taken in the initial state, respectively. However, joint rewards are always received in the next time step
from the state and action that produced them. Therefore, getJointReward(0) is undefined. Instead, the first reward received will be at time step 1: getReward(1).
Additionally, the action and reward for a specific agent in a specific time step can be queried with getActionForAgent(int, String)
and
getRewardForAgent(int, String)
, respectively.Modifier and Type | Field and Description |
---|---|
protected java.util.Set<java.lang.String> |
agentsInvolvedInGame
The set of agents involved in this game
|
protected java.util.List<JointAction> |
jointActions
The sequence of joint actions
|
protected java.util.List<java.util.Map<java.lang.String,java.lang.Double>> |
jointRewards
The sequence of joint rewards
|
protected java.util.List<State> |
states
The sequence of states
|
Constructor and Description |
---|
GameAnalysis()
Initialzes the datastructures.
|
GameAnalysis(State initialState)
Initializes with an initial state of the game.
|
Modifier and Type | Method and Description |
---|---|
boolean |
agentIsInvolvedInGame(java.lang.String agentName)
Returns true if an agent with the given name took any actions in the course of this game.
|
GroundedSingleAction |
getActionForAgent(int t,
java.lang.String agentName)
Returns the action taken for the given agent at the given time step where t=0 refers to the joint action taken in the initial state.
|
java.util.Set<java.lang.String> |
getAgentsInvolvedInGame()
Returns the set of agents involved in this game
|
JointAction |
getJointAction(int t)
Returns the joint action taken in time step t where t=0 refers to the joint action taken in the initial state.
|
java.util.List<JointAction> |
getJointActions()
Returns the joint action sequence list object
|
java.util.Map<java.lang.String,java.lang.Double> |
getJointReward(int t)
Returns the joint reward received in time step t.
|
java.util.List<java.util.Map<java.lang.String,java.lang.Double>> |
getJointRewards()
Returns the joint reward sequence list object
|
double |
getRewardForAgent(int t,
java.lang.String agentName)
Returns the reward received for the agent with the given name at the given step.
|
State |
getState(int t)
Returns the state stored at time step t where t=0 refers to the initial state
|
java.util.List<State> |
getStates()
Returns the state sequence list object
|
protected void |
initializeDatastructures()
Instantiates the datastructures of this object.
|
void |
initializeGameWithInitialState(State initialState)
Clears out any already recorded states, joint actions, and rewards, and sets the initial state of the game.
|
int |
maxTimeStep()
Returns the max time step index in this game which equals
numTimeSteps() -1. |
int |
numTimeSteps()
Returns the number of time steps recorded which is equal to the number of states observed.
|
static GameAnalysis |
parseFileIntoGA(java.lang.String path,
SGDomain domain,
StateParser sp)
Reads a game that was written to a file and turns into a
GameAnalysis object. |
java.lang.String |
parseIntoString(StateParser sp)
Converts this game into a string representation.
|
static GameAnalysis |
parseStringIntoGameAnalysis(java.lang.String str,
SGDomain domain,
StateParser sp)
Parses a string representing a
GameAnalysis object into an actual GameAnalysis object. |
void |
recordTransitionTo(JointAction jointAction,
State nextState,
java.util.Map<java.lang.String,java.lang.Double> jointReward)
Records a transition from the last recorded state in this object using the specififed joint action to the specified next state and with the specified joint reward
being recieved as a result.
|
void |
writeToFile(java.lang.String path,
StateParser sp)
Writes this game to a file.
|
protected java.util.List<State> states
protected java.util.List<JointAction> jointActions
protected java.util.List<java.util.Map<java.lang.String,java.lang.Double>> jointRewards
protected java.util.Set<java.lang.String> agentsInvolvedInGame
public GameAnalysis()
initializeGameWithInitialState(State)
should be called
to set the initial state of the game before any transitions are recorded.public GameAnalysis(State initialState)
initialState
- the initial state of the game.public void initializeGameWithInitialState(State initialState)
initialState
- the initial state of the game.protected void initializeDatastructures()
public State getState(int t)
t
- the time steppublic JointAction getJointAction(int t)
t
- the time steppublic java.util.Map<java.lang.String,java.lang.Double> getJointReward(int t)
t
- the time steppublic GroundedSingleAction getActionForAgent(int t, java.lang.String agentName)
t
- the time stepagentName
- the name of the agentpublic double getRewardForAgent(int t, java.lang.String agentName)
t
- the time stepagentName
- the name of the agentpublic boolean agentIsInvolvedInGame(java.lang.String agentName)
agentName
- the name of the agentpublic int numTimeSteps()
public int maxTimeStep()
numTimeSteps()
-1.public void recordTransitionTo(JointAction jointAction, State nextState, java.util.Map<java.lang.String,java.lang.Double> jointReward)
jointAction
- the joint action taken in the last recorded state in this objectnextState
- the next state to which the agents transitionjointReward
- the joint reward received for the transitonpublic java.util.List<State> getStates()
public java.util.List<JointAction> getJointActions()
public java.util.List<java.util.Map<java.lang.String,java.lang.Double>> getJointRewards()
public java.util.Set<java.lang.String> getAgentsInvolvedInGame()
public java.lang.String parseIntoString(StateParser sp)
sp
- the state parser to use to convert state objects to string representations.public void writeToFile(java.lang.String path, StateParser sp)
path
- the path to the file in which to write this game.sp
- the state parser to use to convert state objects to string representations.public static GameAnalysis parseStringIntoGameAnalysis(java.lang.String str, SGDomain domain, StateParser sp)
GameAnalysis
object into an actual GameAnalysis
object.str
- the string representationdomain
- the stochastic games domain to which the actions belongsp
- the state parser used to represent statesGameAnalysis
object.public static GameAnalysis parseFileIntoGA(java.lang.String path, SGDomain domain, StateParser sp)
GameAnalysis
object.path
- the path to the game file.domain
- the stochastic games domain to which the states and actions belongsp
- a state parser that can parse the state string representation in the fileGameAnalysis
object.