Struct elevate_lib::elevator::Elevator
source · 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: f64Implementations§
source§impl Elevator
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.
sourcepub fn from(
capacity: usize,
energy_up: f64,
energy_down: f64,
energy_coef: f64
) -> Elevator
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);sourcepub fn get_energy_spent(&mut self) -> f64
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.
sourcepub fn get_free_capacity(&self) -> usize
pub fn get_free_capacity(&self) -> usize
Calculate the free capacity for the elevator
sourcepub fn update_direction(&mut self, floor_to: usize)
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.
sourcepub fn update_floor(&mut self) -> usize
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.
sourcepub fn get_nearest_dest_floor(&self) -> (usize, usize)
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).
sourcepub fn flush_people_leaving_elevator(
&mut self,
free_floor_capacity: usize
) -> Vec<Person>
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 Extend<Person> for Elevator
impl Extend<Person> for Elevator
source§fn extend<T: IntoIterator<Item = Person>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Person>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)source§impl People for Elevator
impl People for Elevator
source§fn gen_num_tips(&self, rng: &mut impl Rng) -> usize
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>
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
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
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
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
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
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
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)
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)
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§
impl Freeze for Elevator
impl RefUnwindSafe for Elevator
impl Send for Elevator
impl Sync for Elevator
impl Unpin for Elevator
impl UnwindSafe for Elevator
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
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moresource§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).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.