public class SimulatedEnvironment extends java.lang.Object implements StateSettableEnvironment, EnvironmentServerInterface
Environment
that simulates interactions using a SampleModel
that is provided
in an input domain.
Initial states of the environment
are defined using a StateGenerator
. If no StateGenerator
is specified,
but an initial State
is provided in a constructor, then the StateGenerator
is
set to a ConstantStateGenerator
so that upon resetEnvironment()
method calls,
the initial state is the same as the original input state.
All returned environment observations are fully observable returning a copy of the true internal State
of
the environment. Copies of the state are returned to prevent tampering of the internal environment state.
By default, this Environment
will not allow states to change when the current
environment state is a terminal state (as specified by the input TerminalFunction
); instead, the
same current state will be returned with a reward of zero if someone attempts to interact with the environment through executeAction(Action)
.
In this case, the environment state will have to be manually changed with resetEnvironment()
or setCurStateTo(State)
to a non-terminal state before actions will affect the state again. Alternatively, you can allow actions to affect the state from
terminal states with the setAllowActionFromTerminalStates(boolean)
method.
Modifier and Type | Field and Description |
---|---|
protected boolean |
allowActionFromTerminalStates
A flag indicating whether the environment will respond to actions from a terminal state.
|
protected State |
curState
The current state of the environment
|
protected double |
lastReward
The last reward generated from this environment.
|
protected SampleModel |
model |
protected java.util.List<EnvironmentObserver> |
observers
The
EnvironmentObserver objects that will be notified of Environment
events. |
protected StateGenerator |
stateGenerator
The state generator used to generate new states when the environment is reset with
resetEnvironment() ; |
protected boolean |
terminated |
Constructor and Description |
---|
SimulatedEnvironment(SADomain domain) |
SimulatedEnvironment(SADomain domain,
State initialState) |
SimulatedEnvironment(SADomain domain,
StateGenerator stateGenerator) |
SimulatedEnvironment(SampleModel model) |
SimulatedEnvironment(SampleModel model,
State initialState) |
SimulatedEnvironment(SampleModel model,
StateGenerator stateGenerator) |
Modifier and Type | Method and Description |
---|---|
void |
addObservers(EnvironmentObserver... observers)
Adds one or more
EnvironmentObserver s |
void |
clearAllObservers()
Clears all
EnvironmentObserver s from this server. |
State |
currentObservation()
Returns the current observation of the environment as a
State . |
EnvironmentOutcome |
executeAction(Action a)
Executes the specified action in this environment
|
StateGenerator |
getStateGenerator() |
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
|
java.util.List<EnvironmentObserver> |
observers()
Returns all
EnvironmentObserver s registered with this server. |
void |
removeObservers(EnvironmentObserver... observers)
Removes one or more
EnvironmentObserver s from this server. |
void |
resetEnvironment()
Resets this environment to some initial state, if the functionality exists.
|
void |
setAllowActionFromTerminalStates(boolean allowActionFromTerminalStates)
Sets whether the environment will respond to actions from a terminal state.
|
void |
setCurStateTo(State s)
Sets the current state of the environment to the specified state.
|
void |
setStateGenerator(StateGenerator stateGenerator) |
protected SampleModel model
protected StateGenerator stateGenerator
resetEnvironment()
;protected State curState
protected double lastReward
protected boolean terminated
protected boolean allowActionFromTerminalStates
executeAction(Action)
method will result in no change in state and to enable action again, the Environment state will have to be
manually changed with the resetEnvironment()
method or the setCurStateTo(State)
method.
If this value is true, then actions will be carried out according to the domain's transition dynamics.protected java.util.List<EnvironmentObserver> observers
EnvironmentObserver
objects that will be notified of Environment
events.public SimulatedEnvironment(SADomain domain)
public SimulatedEnvironment(SADomain domain, StateGenerator stateGenerator)
public SimulatedEnvironment(SampleModel model)
public SimulatedEnvironment(SampleModel model, State initialState)
public SimulatedEnvironment(SampleModel model, StateGenerator stateGenerator)
public StateGenerator getStateGenerator()
public void setStateGenerator(StateGenerator stateGenerator)
public void addObservers(EnvironmentObserver... observers)
EnvironmentServerInterface
EnvironmentObserver
saddObservers
in interface EnvironmentServerInterface
observers
- and EnvironmentObserver
public void clearAllObservers()
EnvironmentServerInterface
EnvironmentObserver
s from this server.clearAllObservers
in interface EnvironmentServerInterface
public void removeObservers(EnvironmentObserver... observers)
EnvironmentServerInterface
EnvironmentObserver
s from this server.removeObservers
in interface EnvironmentServerInterface
observers
- the EnvironmentObserver
s to remove.public java.util.List<EnvironmentObserver> observers()
EnvironmentServerInterface
EnvironmentObserver
s registered with this server.observers
in interface EnvironmentServerInterface
EnvironmentObserver
s registered with this server.public void setAllowActionFromTerminalStates(boolean allowActionFromTerminalStates)
executeAction(Action)
method will result in no change in state and to enable action again, the Environment state will have to be
manually changed with the resetEnvironment()
method or the setCurStateTo(State)
method.
If this value is true, then actions will be carried out according to the domain's transition dynamics.allowActionFromTerminalStates
- if false, then actions are not allowed from terminal states; if true, then they are allowed.public void setCurStateTo(State s)
StateSettableEnvironment
setCurStateTo
in interface StateSettableEnvironment
s
- the state to which this Environment
will be set.public State currentObservation()
Environment
State
.currentObservation
in interface Environment
State
.public EnvironmentOutcome executeAction(Action a)
Environment
executeAction
in interface Environment
a
- 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