pub struct CartPoleEnv {
Show 15 fields pub action_space: Discrete, pub observation_space: BoxR<CartPoleObservation>, pub render_mode: RenderMode, pub state: CartPoleObservation, pub metadata: Metadata<Self>, pub gravity: O64, pub masscart: O64, pub masspole: O64, pub length: O64, pub force_mag: O64, pub tau: O64, pub kinematics_integrator: KinematicsIntegrator, pub theta_threshold_radians: O64, pub x_threshold: O64, pub steps_beyond_terminated: Option<usize>, /* private fields */
}
Expand description

An environment which implements the cart pole problem described in Neuronlike adaptive elements that can solve difficult learning control problems.

The problem involves applying the correct forces onto a cart with a pole hinged onto it, in order to ensure the pole remains within the preconfigured regions. The agent starts by being assigned random values between (-0.05, 0.05) for all fields available in the state structure. The agent is rewarded ‘+1’ for every step taken until the episode ends.

The episode ends when any of the following conditions occur:

  1. Termination: [CartPoleObservation.theta] is greater than +/-12.0 (pole has fallen).
  2. Termination: [CartPoleObservation.x] is greater than +/-2.4 (cart is outside bounds).
  3. Truncation: Episode length is greater than 500.

Fields§

§action_space: Discrete

The available actions that can be taken.

§observation_space: BoxR<CartPoleObservation>

The range of values that can be observed.

§render_mode: RenderMode

The type of renders produced.

§state: CartPoleObservation

The current state of the environment.

§metadata: Metadata<Self>

Additional pieces of information provided by the environment.

§gravity: O64

The gravity constant applied to the environment..

§masscart: O64

The mass of the cart.

§masspole: O64

The mass of the pole.

§length: O64

Half the length of the pole.

§force_mag: O64

The default force applied to the pole.

§tau: O64

The number of seconds between state updates.

§kinematics_integrator: KinematicsIntegrator

The type of integration done on the differential equations found in the paper.

§theta_threshold_radians: O64

The angle that the pole can lean to before an episode is considered terminated.

§x_threshold: O64

The x value that the cart can be at before an episode is considered terminated.

§steps_beyond_terminated: Option<usize>

The number of steps taken after the episode was terminated.

Implementations§

source§

impl CartPoleEnv

source

pub fn new(render_mode: RenderMode) -> Self

Creates a cart pole environment using defaults from the paper.

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

    let mut rewards = vec![];

    for _ in 0..15 {
        let mut current_reward = OrderedFloat(0.);

        for _ in 0..475 {
            let action = (&mut thread_rng()).gen_range(0..=1);
            let state_reward = env.step(action);
            current_reward += state_reward.reward;

            if state_reward.done {
                break;
            }
        }

        env.reset(None, false, None);
        rewards.push(current_reward);
    }

    println!("{:?}", rewards);
}

Trait Implementations§

source§

impl Clone for CartPoleEnv

source§

fn clone(&self) -> CartPoleEnv

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 CartPoleEnv

source§

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

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

impl Env for CartPoleEnv

§

type Action = usize

The type of action supported.
§

type Observation = CartPoleObservation

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::Observation, Self::Info>

Acts on an environment using the given action, producing a reward.
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 render(&mut self, mode: RenderMode) -> Renders

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

fn close(&mut self)

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

impl EnvProperties for CartPoleEnv

§

type ActionSpace = Discrete

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

type ObservationSpace = BoxR<CartPoleObservation>

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 CartPoleEnv

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