public class RLGlueEnvironmentInterface extends java.lang.Object implements Environment, org.rlcommunity.rlglue.codec.AgentInterface
Environment that manages the interface to an RLGlue
Environment. To implement this interface, it requires that this class is both a BURLAP Environment
and an RLGlue AgentInterface, since BURLAP agents will communicate to the RL Glue
Environment through the an RLGlue AgentInterface. However, you can use this
class like a normal BURLAP Environment.
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.
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 |
RLGlueEnvironmentInterface.MutableInt
A mutable int wrapper
|
static class |
RLGlueEnvironmentInterface.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 RLGlueEnvironmentInterface.MutableInt |
domainSet
A variable for synchronized checking if the domain has been set.
|
protected double |
lastReward
The last reward received
|
protected RLGlueEnvironmentInterface.MutableInt |
nextAction
Maintains the current RLGlue action to be performed.
|
protected RLGlueEnvironmentInterface.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 |
|---|
RLGlueEnvironmentInterface() |
| 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.
|
EnvironmentOutcome |
executeAction(GroundedAction ga)
Executes the specified action in this environment
|
State |
getCurrentObservation()
Returns the current observation of the environment as a
State. |
int |
getDebugCode() |
double |
getDiscountFactor()
Returns the discount factor for this environment.
|
Domain |
getDomain()
Returns the domain for this environment.
|
double |
getLastReward()
Returns the last reward returned by the 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.
|
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 RLGlueEnvironmentInterface.MutableInt nextAction
protected RLGlueEnvironmentInterface.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 RLGlueEnvironmentInterface.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.AgentInterfacepublic org.rlcommunity.rlglue.codec.types.Action agent_start(org.rlcommunity.rlglue.codec.types.Observation observation)
agent_start in interface org.rlcommunity.rlglue.codec.AgentInterfacepublic 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.AgentInterfacepublic void agent_end(double v)
agent_end in interface org.rlcommunity.rlglue.codec.AgentInterfacepublic void agent_cleanup()
agent_cleanup in interface org.rlcommunity.rlglue.codec.AgentInterfacepublic java.lang.String agent_message(java.lang.String s)
agent_message in interface org.rlcommunity.rlglue.codec.AgentInterfacepublic State getCurrentObservation()
EnvironmentState.getCurrentObservation in interface EnvironmentState.public EnvironmentOutcome executeAction(GroundedAction ga)
EnvironmentexecuteAction in interface Environmentga - the GroundedAction that is to be performed in this environment.public double getLastReward()
EnvironmentgetLastReward in interface Environmentpublic boolean isInTerminalState()
EnvironmentisInTerminalState in interface Environmentpublic void resetEnvironment()
EnvironmentresetEnvironment in interface Environmentpublic static org.rlcommunity.rlglue.codec.types.Action getRLGlueAction(int id)
id - the action id