pub struct Elevator {
    pub floor_on: usize,
    pub moving_up: bool,
    pub stopped: bool,
    pub people: Vec<Person>,
    pub capacity: usize,
    pub energy_up: f64,
    pub energy_down: f64,
    pub energy_coef: f64,
}
Expand description

§Elevator struct

An Elevator is aggregated by buildings, and transports people between floors. The Elevator struct generally should not be directly instantiated; instead it should be managed via the Building type and ElevatorController implementations.

Fields§

§floor_on: usize§moving_up: bool§stopped: bool§people: Vec<Person>§capacity: usize§energy_up: f64§energy_down: f64§energy_coef: f64

Implementations§

source§

impl Elevator

§Elevator type implementation

The following functions are used by Building and Controller types as well as Elevators implementations to update and control the behavior of an Elevator.

source

pub fn from( capacity: usize, energy_up: f64, energy_down: f64, energy_coef: f64 ) -> Elevator

Initialize a new elevator given the elevator’s energy spent moving up, energy spent moving down, and energy coefficient (additional energy spent per person transported). The elevator is initialized stopped on the first floor with no people.

§Example
let capacity: usize = 10_usize;
let energy_up: f64 = 5.0_f64;
let energy_down: f64 = 2.5_f64;
let energy_coef: f64 = 0.5_f64;
let my_elev: Elevator = Elevator::from(capacity, energy_up, energy_down, energy_coef);
source

pub fn get_energy_spent(&mut self) -> f64

Calculate the total energy spent (as an f64) while the elevator is moving. If the elevator is not moving then return 0.0_f64.

source

pub fn get_free_capacity(&self) -> usize

Calculate the free capacity for the elevator

source

pub fn update_direction(&mut self, floor_to: usize)

Update the stopped and moving_up properties of the elevator given a destination floor for the elevator. The properties will be set such that the elevator moves in the direction of the provided floor with respect to its current floor when updated.

source

pub fn update_floor(&mut self) -> usize

Use the stopped and moving_up properties of the elevator to update the elevator’s floor index. If stopped, then no change. If moving up then increment the floor_on by 1_usize. If moving down then decrement the floor_on by 1_usize.

source

pub fn get_nearest_dest_floor(&self) -> (usize, usize)

If there are people on the elevator, this returns the nearest destination floor among those people represented as a length-2 tuple of usizes. The first element is the destination floor, and the second is the distance to the floor. If there are no people on the floor, it returns (0_usize, 0_usize).

source

pub fn flush_people_leaving_elevator( &mut self, free_floor_capacity: usize ) -> Vec<Person>

If the elevator is stopped, this function returns a Vec<Person> containing the people on the elevator whose destination floor is the current floor. If the elevator is not stopped, this function returns an empty vector. The people removed from the elevator are limited to the free capacity of the floor they are entering, which is given as a usize function parameter.

Trait Implementations§

source§

impl Clone for Elevator

source§

fn clone(&self) -> Elevator

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 Extend<Person> for Elevator

source§

fn extend<T: IntoIterator<Item = Person>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl People for Elevator

source§

fn gen_num_tips(&self, rng: &mut impl Rng) -> usize

Generates the number of people among the collection of people who will tip.

source§

fn get_dest_floors(&self) -> Vec<usize>

Determines the destination floors for all people and returns it as a vector.

source§

fn get_num_people(&self) -> usize

Determines the total number of people and returns it as a usize.

source§

fn get_num_people_waiting(&self) -> usize

Determines the number of people waiting, that is, not at their desired floor.

source§

fn get_num_people_going_to_floor(&self, floor_to: usize) -> usize

Determines the number of people going to a particular floor

source§

fn get_aggregate_wait_time(&self) -> usize

Reads the wait times from people waiting/not at their desired floor and aggregates the total into a usize.

source§

fn are_people_waiting(&self) -> bool

Determines whether anyone in the collection of people are going to a given floor, and returns a bool which is true if so, and false if not.

source§

fn are_people_going_to_floor(&self, floor_index: usize) -> bool

Determines whether anyone in the collection of people is waiting/not at their desired floor, and returns a bool which is true if so, and false if not.

source§

fn increment_wait_times(&mut self)

Increments the wait times (by 1_usize) among all people waiting/not at their desired floor.

source§

fn reset_wait_times(&mut self)

Resets the wait times (to 0_usize) among all people who have a nonzero wait time and are on their desired floor.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 for T

§

type Output = T

Should always be Self
source§

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

source§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for T
where 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 T
where 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 T
where 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.
source§

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

source§

fn vzip(self) -> V