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.GraphAction
An action class for defining actions that can be taken from state nodes.
|
class |
GraphDefinedDomain.NodeTransitionProbibility
A class for specifying transition probabilities to result node states.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ATTNODE
Constant for the name of the graph node attribute
|
static java.lang.String |
BASEACTIONNAME
Constant for the base name of each action
|
static java.lang.String |
CLASSAGENT
Constant for the name of the agent class
|
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 java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.util.Set<GraphDefinedDomain.NodeTransitionProbibility>>> |
transitionDynamics
The state-action stochastic transition dynamics from each state node.
|
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.NodeTransitionProbibility>>> |
copyTransitionDynamics()
Returns a deep copy of the transition dynamics
|
Domain |
generateDomain()
Returns a newly instanced Domain object
|
static int |
getNodeId(State s)
Returns the state node number where the agent of the provided state is
|
protected GraphDefinedDomain.NodeTransitionProbibility |
getNodeTransitionTo(java.util.Set<GraphDefinedDomain.NodeTransitionProbibility> nts,
int tNode)
Returns the
GraphDefinedDomain.NodeTransitionProbibility 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
|
static State |
getState(Domain d,
int sNode)
Returns a new state in which the agent is in the specified source node number.
|
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.NodeTransitionProbibility>>> 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.NodeTransitionProbibility>>> 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 |
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 ATTNODE
public static final java.lang.String CLASSAGENT
public static final java.lang.String BASEACTIONNAME
protected int numNodes
protected int maxActions
protected java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.util.Set<GraphDefinedDomain.NodeTransitionProbibility>>> transitionDynamics
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 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.NodeTransitionProbibility>>> transitionDynamics)
transitionDynamics
- the graph transition dynamics to checkpublic java.lang.String invalidMDPReport()
public static java.lang.String invalidMDPReport(java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.util.Set<GraphDefinedDomain.NodeTransitionProbibility>>> transitionDynamics)
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.NodeTransitionProbibility getNodeTransitionTo(java.util.Set<GraphDefinedDomain.NodeTransitionProbibility> nts, int tNode)
GraphDefinedDomain.NodeTransitionProbibility
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.NodeTransitionProbibility
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.NodeTransitionProbibility>>> copyTransitionDynamics()
public Domain generateDomain()
DomainGenerator
generateDomain
in interface DomainGenerator
public static State getState(Domain d, int sNode)
d
- the domain object for the graph domainsNode
- the state node number in which the agent will be.public static int getNodeId(State s)
s
- the state object to querypublic static void main(java.lang.String[] args)