Struct gym_rs::envs::classical_control::cartpole::CartPoleEnv
source · 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:
- Termination: [
CartPoleObservation.theta
] is greater than +/-12.0 (pole has fallen). - Termination: [
CartPoleObservation.x
] is greater than +/-2.4 (cart is outside bounds). - 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
impl CartPoleEnv
sourcepub fn new(render_mode: RenderMode) -> Self
pub fn new(render_mode: RenderMode) -> Self
Creates a cart pole environment using defaults from the paper.
Examples found in repository?
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
impl Clone for CartPoleEnv
source§fn clone(&self) -> CartPoleEnv
fn clone(&self) -> CartPoleEnv
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for CartPoleEnv
impl Debug for CartPoleEnv
source§impl Env for CartPoleEnv
impl Env for CartPoleEnv
§type Observation = CartPoleObservation
type Observation = CartPoleObservation
source§fn step(
&mut self,
action: Self::Action
) -> ActionReward<Self::Observation, Self::Info>
fn step( &mut self, action: Self::Action ) -> ActionReward<Self::Observation, Self::Info>
source§fn reset(
&mut self,
seed: Option<u64>,
return_info: bool,
options: Option<BoxR<Self::Observation>>
) -> (Self::Observation, Option<Self::ResetInfo>)
fn reset( &mut self, seed: Option<u64>, return_info: bool, options: Option<BoxR<Self::Observation>> ) -> (Self::Observation, Option<Self::ResetInfo>)
source§fn render(&mut self, mode: RenderMode) -> Renders
fn render(&mut self, mode: RenderMode) -> Renders
source§impl EnvProperties for CartPoleEnv
impl EnvProperties for CartPoleEnv
§type ActionSpace = Discrete
type ActionSpace = Discrete
§type ObservationSpace = BoxR<CartPoleObservation>
type ObservationSpace = BoxR<CartPoleObservation>
source§fn metadata(&self) -> &Metadata<Self>
fn metadata(&self) -> &Metadata<Self>
source§fn rand_random(&self) -> &Pcg64
fn rand_random(&self) -> &Pcg64
source§fn action_space(&self) -> &Self::ActionSpace
fn action_space(&self) -> &Self::ActionSpace
source§fn observation_space(&self) -> &Self::ObservationSpace
fn observation_space(&self) -> &Self::ObservationSpace
source§fn render_mode(&self) -> &RenderMode
fn render_mode(&self) -> &RenderMode
source§fn reward_range(&self) -> &RewardRange
fn reward_range(&self) -> &RewardRange
Auto Trait Implementations§
impl RefUnwindSafe for CartPoleEnv
impl !Send for CartPoleEnv
impl !Sync for CartPoleEnv
impl Unpin for CartPoleEnv
impl UnwindSafe for CartPoleEnv
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.