pub struct MountainCarEnv {
    pub min_position: O64,
    pub max_position: O64,
    pub max_speed: O64,
    pub goal_position: O64,
    pub goal_velocity: O64,
    pub force: O64,
    pub gravity: O64,
    pub render_mode: RenderMode,
    pub action_space: Discrete,
    pub observation_space: BoxR<MountainCarObservation>,
    pub state: MountainCarObservation,
    pub metadata: Metadata<Self>,
    /* private fields */
}
Expand description

An implementation of the classical reinforcment learning environment, mountain car.

The problem involves moving a stochastically placed car on the bottom of a sinusoidal valley to the top of the hill by applying left and right forces to the car. The car is given a reward of -1 for each step taken by the agent, until a terminal step is reached.

An episode ends when one of the following conditions occur: 1. Termination: The car reaches the goal position. 2. Truncation: The episode exceeds 200 steps.

Fields§

§min_position: O64

The minimum position the car can be spawned at.

§max_position: O64

The maximum position the cart can be spawned at.

§max_speed: O64

The max speed the car can reach.

§goal_position: O64

The position on the map, where when passed, an episode can be considered terminated.

§goal_velocity: O64

The velocity at which an episode can be considered terminated.

§force: O64

The force of the cart.

§gravity: O64

The gravity constant applied to the environment.

§render_mode: RenderMode

The type of renders produced.

§action_space: Discrete

The set of actions which can be taken.

§observation_space: BoxR<MountainCarObservation>

The range of values that can be observed.

§state: MountainCarObservation

The state of the environment.

§metadata: Metadata<Self>

Additional information provided by the environment.

Implementations§

source§

impl MountainCarEnv

source

pub fn new(render_mode: RenderMode) -> Self

Generates an instance of the mountain car environment using the defaults provided in the paper.

Examples found in repository?
examples/mountain_car.rs (line 9)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
fn main() {
    let mut mc = MountainCarEnv::new(RenderMode::Human);
    let _state = mc.reset(None, false, None);

    let mut end: bool = false;
    let mut episode_length = 0;
    while !end {
        if episode_length > 200 {
            break;
        }
        let action = (&mut thread_rng()).gen_range(0..3);
        let ActionReward { done, .. } = mc.step(action);
        episode_length += 1;
        end = done;
        println!("episode_length: {}", episode_length);
    }

    mc.close();

    for _ in 0..200 {
        let action = (&mut thread_rng()).gen_range(0..3);
        mc.step(action);
        episode_length += 1;
        println!("episode_length: {}", episode_length);
    }
}

Trait Implementations§

source§

impl Clone for MountainCarEnv

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for MountainCarEnv

source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Env for MountainCarEnv

§

type Action = usize

The type of action supported.
§

type Observation = MountainCarObservation

The type of the observation produced after an action has been applied.
§

type Info = ()

The type of the metadata object produced by acting on the environment.
§

type ResetInfo = ()

The type of the object produced when an environment is reset.
source§

fn step( &mut self, action: Self::Action ) -> ActionReward<<Self as Env>::Observation, Self::Info>

Acts on an environment using the given action, producing a reward.
source§

fn render(&mut self, mode: RenderMode) -> Renders

Produces the renders, if any, associated with the given mode.
source§

fn reset( &mut self, seed: Option<u64>, return_info: bool, options: Option<BoxR<Self::Observation>> ) -> (Self::Observation, Option<Self::ResetInfo>)

Resets the environment to a initial random state.
source§

fn close(&mut self)

Closes any open resources associated with the internal rendering service.
source§

impl EnvProperties for MountainCarEnvwhere Self: Sized,

§

type ActionSpace = Discrete

The type of values that can be observed in the action space.
§

type ObservationSpace = BoxR<<MountainCarEnv as Env>::Observation>

The type of observations produced
source§

fn metadata(&self) -> &Metadata<Self>

Provides an object describing additional details about this environment.
source§

fn rand_random(&self) -> &Pcg64

Provides the random number generator responsible for seeding states.
source§

fn action_space(&self) -> &Self::ActionSpace

Provides the object describing the actions that can be observed.
source§

fn observation_space(&self) -> &Self::ObservationSpace

Provides the object describing the states that can be observed in this environment.
source§

fn render_mode(&self) -> &RenderMode

Provides the current render mode.
source§

fn reward_range(&self) -> &RewardRange

Provides the range of reward values that can be outputted by this environment.
source§

impl Serialize for MountainCarEnv

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V