public class GraphDefinedDomain extends java.lang.Object implements DomainGenerator
setTransition(int, int, int, double)
method and
transitions can be cleared/removed with the methods clearStateTransitionsFrom(int)
,
clearStateActionTransitions(int, int)
, and removeEdge(int, int, int)
.
A constructed graph's transition dynamics can be validated as proper (all edges from a state-action pair sum to 1)
using the method isValidMDPGraph()
and if they are false, a string reporting which state-actions do not
sum to 1 (and their various edges) can be returned with the invalidMDPReport()
method.
Modifying the transition dynamics of a graph will not affect the transition dynamics of previously generated
Domain
, allowing you to reuse the same generator without affected previous domains.
Modifier and Type | Class and Description |
---|---|
static class |
GraphDefinedDomain.GraphActionType
An action class for defining actions that can be taken from state nodes.
|
static class |
GraphDefinedDomain.GraphStateModel |
class |
GraphDefinedDomain.NodeTransitionProbability
A class for specifying transition probabilities to result node states.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BASE_ACTION_NAME
Constant for the base name of each action
|
protected int |
maxActions
The maximum number of actions available from any given state node.
|
protected int |
numNodes
The number of state nodes in the graph
|
protected RewardFunction |
rf |
protected TerminalFunction |
tf |
protected java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.util.Set<GraphDefinedDomain.NodeTransitionProbability>>> |
transitionDynamics
The state-action stochastic transition dynamics from each state node.
|
static java.lang.String |
VAR
the variable key for the single graph node values of a state
|
Constructor and Description |
---|
GraphDefinedDomain()
Initializes the generator.
|
GraphDefinedDomain(int numNodes)
Initializes the generator to create a domain with the given number of state nodes in it.
|
Modifier and Type | Method and Description |
---|---|
void |
clearStateActionTransitions(int srcNode,
int action)
Clears all (stochastic) edges for a given state-action pair.
|
void |
clearStateTransitionsFrom(int srcNode)
Clears all transitions from a given state node
|
protected java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.util.Set<GraphDefinedDomain.NodeTransitionProbability>>> |
copyTransitionDynamics()
Returns a deep copy of the transition dynamics
|
SADomain |
generateDomain()
Returns a newly instanced Domain object
|
protected GraphDefinedDomain.NodeTransitionProbability |
getNodeTransitionTo(java.util.Set<GraphDefinedDomain.NodeTransitionProbability> nts,
int tNode)
Returns the
GraphDefinedDomain.NodeTransitionProbability object
in the provided set that corresponds to a transition to state tNode or null if it doesn't exist. |
int |
getNumNodes()
Returns the number of state nodes specified in this domain
|
RewardFunction |
getRf() |
TerminalFunction |
getTf() |
java.lang.String |
invalidMDPReport()
Returns a string that lists the state-action paris that have improper transition dynamics (transitions that don't sum to 1).
|
static java.lang.String |
invalidMDPReport(java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.util.Set<GraphDefinedDomain.NodeTransitionProbability>>> transitionDynamics)
Returns a string that lists the state-action paris that have improper transition dynamics (transitions that don't sum to 1).
|
boolean |
isValidMDPGraph()
Checks whether the the probability of all state-action outcomes sum to 1 in this graph.
|
static boolean |
isValidMDPGraph(java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.util.Set<GraphDefinedDomain.NodeTransitionProbability>>> transitionDynamics)
Checks whether the the probability of all state-action outcomes sum to 1 in he provided transition dynamics.
|
static void |
main(java.lang.String[] args) |
void |
removeEdge(int srcNode,
int action,
int tNode)
Removes a given edge from the transition dynamics.
|
void |
setRf(RewardFunction rf) |
void |
setTf(TerminalFunction tf) |
void |
setTransition(int srcNode,
int action,
int tNode,
double p)
Sets the probability
p for transitioning to state node tNode after taking action number action in state node srcNode . |
public static final java.lang.String VAR
public static final java.lang.String BASE_ACTION_NAME
protected int numNodes
protected int maxActions
protected java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.util.Set<GraphDefinedDomain.NodeTransitionProbability>>> transitionDynamics
protected RewardFunction rf
protected TerminalFunction tf
public GraphDefinedDomain()
setTransition(int, int, int, double)
method.public GraphDefinedDomain(int numNodes)
numNodes
- the number of state nodes in the domain.public int getNumNodes()
public RewardFunction getRf()
public void setRf(RewardFunction rf)
public TerminalFunction getTf()
public void setTf(TerminalFunction tf)
public void setTransition(int srcNode, int action, int tNode, double p)
p
for transitioning to state node tNode
after taking action number action
in state node srcNode
.
Note that this method also defines from which nodes an action can be executed. If this method is never called for source node i and action j, then
it will be assumed that action j cannot be executed in state node i. The the specified source node or target node
is greater than this domain generator's previously specified number of nodes, then space will be added for them
in the transition dynamics.srcNode
- the source node number from which an action will be takenaction
- the action to be takentNode
- the resulting state from taking the action in the given source nodep
- the probability of this transition occurring for the given action and source node.public boolean isValidMDPGraph()
public static boolean isValidMDPGraph(java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.util.Set<GraphDefinedDomain.NodeTransitionProbability>>> transitionDynamics)
transitionDynamics
- the graph transition dynamics to checkpublic java.lang.String invalidMDPReport()
(s, a): sumProbability
(s, a)->s_1' p_1
(s, a)->s_2' p_2
...
public static java.lang.String invalidMDPReport(java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.util.Set<GraphDefinedDomain.NodeTransitionProbability>>> transitionDynamics)
(s, a): sumProbability
(s, a)->s_1' p_1
(s, a)->s_2' p_2
...
transitionDynamics
- the transition dynamics of the MDP/Graphpublic void clearStateTransitionsFrom(int srcNode)
srcNode
- the state node from which transitions will be clearedpublic void clearStateActionTransitions(int srcNode, int action)
srcNode
- The state node of the pair to clearaction
- the action of the pair to clearpublic void removeEdge(int srcNode, int action, int tNode)
srcNode
- the source state node of the edgeaction
- the action in the state node of the edgetNode
- the target state node of the dgeprotected GraphDefinedDomain.NodeTransitionProbability getNodeTransitionTo(java.util.Set<GraphDefinedDomain.NodeTransitionProbability> nts, int tNode)
GraphDefinedDomain.NodeTransitionProbability
object
in the provided set that corresponds to a transition to state tNode or null if it doesn't exist.nts
- the set of possible node transitionstNode
- the query transition node idGraphDefinedDomain.NodeTransitionProbability
or null if the transition to the state does not already exist.protected java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.util.Set<GraphDefinedDomain.NodeTransitionProbability>>> copyTransitionDynamics()
public SADomain generateDomain()
DomainGenerator
generateDomain
in interface DomainGenerator
public static void main(java.lang.String[] args)