pub trait Environment<const R: usize, const SR: usize, const AR: usize> {
type StateType: State<SR>;
type ObservationType: Observation<R>;
type ActionType: Action<AR>;
type RewardType: Reward;
type SnapshotType: Snapshot<R, ObservationType = Self::ObservationType, RewardType = Self::RewardType>;
// Required methods
fn reset(&mut self) -> Result<Self::SnapshotType, EnvironmentError>;
fn step(
&mut self,
action: Self::ActionType,
) -> Result<Self::SnapshotType, EnvironmentError>;
}Expand description
Interaction protocol between an agent and a problem domain.
An environment encapsulates the dynamics of a problem, processing actions and returning observations (snapshots) along with rewards. Environments are responsible for managing state, computing rewards, and determining episode termination.
§Type Parameters
R- Rank of the observation tensor (matchesObservation<R>andSnapshot<R>).SR- Rank of the state tensor (matchesState<SR>).AR- Rank of the action tensor (matchesAction<AR>).
§Associated Types
StateType- The concrete state type for this environment.ObservationType- The observation type exposed to the agent.ActionType- The action type this environment accepts.RewardType- The reward scalar type returned each step.SnapshotType- The snapshot type returned byresetandstep.
Required Associated Types§
Sourcetype ObservationType: Observation<R>
type ObservationType: Observation<R>
The observation type exposed to the agent.
Sourcetype ActionType: Action<AR>
type ActionType: Action<AR>
The concrete action type this environment accepts.
Sourcetype RewardType: Reward
type RewardType: Reward
The reward scalar type returned by this environment.
Sourcetype SnapshotType: Snapshot<R, ObservationType = Self::ObservationType, RewardType = Self::RewardType>
type SnapshotType: Snapshot<R, ObservationType = Self::ObservationType, RewardType = Self::RewardType>
The snapshot type returned by reset and step operations.
Required Methods§
Sourcefn reset(&mut self) -> Result<Self::SnapshotType, EnvironmentError>
fn reset(&mut self) -> Result<Self::SnapshotType, EnvironmentError>
Reset the environment to its initial state and return the first snapshot.
The returned snapshot carries the initial observation, a reward of zero, and
EpisodeStatus::Running. Call this at the start of every episode before
calling step.
§Errors
Returns EnvironmentError if the environment cannot be initialised (e.g.
an I/O failure when loading level data).
Sourcefn step(
&mut self,
action: Self::ActionType,
) -> Result<Self::SnapshotType, EnvironmentError>
fn step( &mut self, action: Self::ActionType, ) -> Result<Self::SnapshotType, EnvironmentError>
Execute one transition of the environment with the given action.
Applies action to the current state, updates internal state, and
returns a snapshot containing the next observation, the immediate reward,
and the new EpisodeStatus. When Snapshot::is_done returns true
the episode is over; call reset to begin a new one.
§Errors
Returns EnvironmentError::InvalidAction if the action is not legal in
the current state, or another EnvironmentError variant if the step
cannot complete (e.g. physics simulation failure).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".