public class RLGlueAgent extends java.lang.Object implements Environment, org.rlcommunity.rlglue.codec.AgentInterface
Environment
, so that
any BURLAP RL agent can control the RLGlue agent.
To initialize this BURLAP environment, use the loadAgent()
or loadAgent(String, String)
methods so that
RLGlue knows to tell this class about the environment this class is wrapping. After the load method,
you can get the corresponding BURLAP domain that represents it by calling the getDomain()
method.
You can also get the RLGlue preferred discount factor using the getDiscountFactor()
method.
As with normal BURLAP Environment
implementations, you should call
the resetEnvironment()
method whenever a terminal state is reached. This will cause this class to
block until RLGlue has started a new episode with a new initial state, unless the RLGlue experiment has finished, in which case
the method will return immediately. If you want to check whether the RLGLue
experiment has finished manually, use the rlGlueExperimentFinished
method.
Modifier and Type | Class and Description |
---|---|
static class |
RLGlueAgent.MutableInt
A mutable int wrapper
|
static class |
RLGlueAgent.StateReference
A wrapper that maintains a reference to a
State or null. |
Modifier and Type | Field and Description |
---|---|
protected State |
curState
The current state of the environment
|
protected boolean |
curStateIsTerminal
Whether the current state is a terminal state
|
protected int |
debugCode
Debug code used for printing debug information.
|
protected double |
discount
The RLGlue specified discount factor
|
protected Domain |
domain
The BURLAP
Domain specifying the RLGlue problem representation and action space. |
protected RLGlueAgent.MutableInt |
domainSet
A variable for synchronized checking if the domain has been set.
|
protected double |
lastReward
The last reward received
|
protected RLGlueAgent.MutableInt |
nextAction
Maintains the current RLGlue action to be performed.
|
protected RLGlueAgent.StateReference |
nextStateReference
Maintains the field to wait for the next state received from RLGlue
|
protected boolean |
printDebug
Whether to print debug statements.
|
protected boolean |
rlGlueExperimentFinished |
Constructor and Description |
---|
RLGlueAgent() |
Modifier and Type | Method and Description |
---|---|
void |
agent_cleanup() |
void |
agent_end(double v) |
void |
agent_init(java.lang.String arg0) |
java.lang.String |
agent_message(java.lang.String s) |
org.rlcommunity.rlglue.codec.types.Action |
agent_start(org.rlcommunity.rlglue.codec.types.Observation observation) |
org.rlcommunity.rlglue.codec.types.Action |
agent_step(double v,
org.rlcommunity.rlglue.codec.types.Observation observation) |
void |
blockUntilStateReceived()
Blocks the calling thread until a state is provided by the RLGlue server or the RLGlue experiment has ended.
|
State |
currentObservation()
Returns the current observation of the environment as a
State . |
EnvironmentOutcome |
executeAction(Action ga)
Executes the specified action in this environment
|
int |
getDebugCode() |
double |
getDiscountFactor()
Returns the discount factor for this environment.
|
Domain |
getDomain()
Returns the domain for this environment.
|
static org.rlcommunity.rlglue.codec.types.Action |
getRLGlueAction(int id)
Returns the corresponding RLGlue action for the given action id.
|
boolean |
isInTerminalState()
Returns whether the environment is in a terminal state that prevents further action by the agent.
|
double |
lastReward()
Returns the last reward returned by the environment
|
void |
loadAgent()
Loads this RLGlue
AgentInterface into RLGlue and runs its event loop in a
separate thread. |
void |
loadAgent(java.lang.String hostAddress,
java.lang.String portString)
Loads this RLGlue
AgentInterface into RLGlue using the specified host address and port
nd runs its event loop in a separate thread. |
void |
resetEnvironment()
Resets this environment to some initial state, if the functionality exists.
|
boolean |
rlGlueExperimentFinished()
Returns true if the RLGlue experiment is finished; false otherwise.
|
void |
toggleDebug(boolean printDebug)
Toggles whether debug information should be printed
|
protected int debugCode
protected boolean printDebug
protected final RLGlueAgent.MutableInt nextAction
protected RLGlueAgent.StateReference nextStateReference
protected State curState
protected boolean curStateIsTerminal
protected double lastReward
protected Domain domain
Domain
specifying the RLGlue problem representation and action space.protected double discount
protected RLGlueAgent.MutableInt domainSet
protected boolean rlGlueExperimentFinished
public void loadAgent()
AgentInterface
into RLGlue and runs its event loop in a
separate thread.public void loadAgent(java.lang.String hostAddress, java.lang.String portString)
AgentInterface
into RLGlue using the specified host address and port
nd runs its event loop in a separate thread.hostAddress
- the RLGlue host address.portString
- the port on which to connect to RLGlue.public void toggleDebug(boolean printDebug)
printDebug
- whether to print debug logs or notpublic int getDebugCode()
public Domain getDomain()
agent_init(String)
method, which means you ought to have called
loadAgent()
or loadAgent(String, String)
before calling this method, otherwise
RLGlue will not know to set the environment.Domain
specification for this RLGlue environment.public double getDiscountFactor()
agent_init(String)
method, which means you ought to have called
loadAgent()
or loadAgent(String, String)
before calling this method, otherwise
RLGlue will not know to set the environment.public boolean rlGlueExperimentFinished()
public void blockUntilStateReceived()
public void agent_init(java.lang.String arg0)
agent_init
in interface org.rlcommunity.rlglue.codec.AgentInterface
public org.rlcommunity.rlglue.codec.types.Action agent_start(org.rlcommunity.rlglue.codec.types.Observation observation)
agent_start
in interface org.rlcommunity.rlglue.codec.AgentInterface
public org.rlcommunity.rlglue.codec.types.Action agent_step(double v, org.rlcommunity.rlglue.codec.types.Observation observation)
agent_step
in interface org.rlcommunity.rlglue.codec.AgentInterface
public void agent_end(double v)
agent_end
in interface org.rlcommunity.rlglue.codec.AgentInterface
public void agent_cleanup()
agent_cleanup
in interface org.rlcommunity.rlglue.codec.AgentInterface
public java.lang.String agent_message(java.lang.String s)
agent_message
in interface org.rlcommunity.rlglue.codec.AgentInterface
public State currentObservation()
Environment
State
.currentObservation
in interface Environment
State
.public EnvironmentOutcome executeAction(Action ga)
Environment
executeAction
in interface Environment
ga
- the Action that is to be performed in this environment.public double lastReward()
Environment
lastReward
in interface Environment
public boolean isInTerminalState()
Environment
isInTerminalState
in interface Environment
public void resetEnvironment()
Environment
resetEnvironment
in interface Environment
public static org.rlcommunity.rlglue.codec.types.Action getRLGlueAction(int id)
id
- the action id