pub struct Building {
pub elevators: Vec<Elevator>,
pub floors: Vec<Floor>,
pub avg_energy: f64,
pub avg_wait_time: f64,
pub tot_tips: f64,
/* private fields */
}Expand description
§Building struct
A Building aggregates Elevators and Floors. It also tracks the everage
energy usage by the elevators, and the average wait time among the people on
the building’s floors and elevators. It randomly generates arrivals.
Fields§
§elevators: Vec<Elevator>§floors: Vec<Floor>§avg_energy: f64§avg_wait_time: f64§tot_tips: f64Implementations§
Source§impl Building
§Building type implementation
The following functions are used to control the behavior of the people and elevators
owned by the Building type.
impl Building
§Building type implementation
The following functions are used to control the behavior of the people and elevators
owned by the Building type.
Sourcepub fn from(
num_floors: usize,
num_elevators: usize,
p_in: f64,
energy_up: f64,
energy_down: f64,
energy_coef: f64,
) -> Building
pub fn from( num_floors: usize, num_elevators: usize, p_in: f64, energy_up: f64, energy_down: f64, energy_coef: f64, ) -> Building
Initialize a new building given the number of floors, the number of elevators the expected number of arrivals per time step, the base energy spent while moving an elevator up and down, and the additional energy spent per person moved.
§Example
let num_floors: usize = 4_usize;
let num_elevators: usize = 2_usize;
let p_in: f64 = 0.5_f64;
let energy_up: f64 = 5.0_f64;
let energy_down: f64 = 2.5_f64;
let energy_coef: f64 = 0.5_f64;
let my_building: Building = Building::from(
num_floors,
num_elevators,
p_in,
energy_up,
energy_down,
energy_coef
);Sourcepub fn update_dest_probabilities(&mut self)
pub fn update_dest_probabilities(&mut self)
Calculate the probability that each floor becomes a destination floor for an elevator
during the next time step. If the floor currently is a destination floor, then return
1_f64.
Sourcepub fn gen_people_arriving(&mut self, rng: &mut impl Rng)
pub fn gen_people_arriving(&mut self, rng: &mut impl Rng)
Generate the people arriving by sampling the Poisson distribution to receive a number of arrivals, and then instantiate that many people and append them to the first floor.
Sourcepub fn gen_tip_value(&self, num_tips: usize, rng: &mut impl Rng) -> f64
pub fn gen_tip_value(&self, num_tips: usize, rng: &mut impl Rng) -> f64
Given the number of people who decided to tip, generate the total value of their tips
Sourcepub fn exchange_people_on_elevator(&mut self)
pub fn exchange_people_on_elevator(&mut self)
For each of the building’s elevators, exchange people between the elevator and its current floor if anyone on the elevator is going to the current floor, or if anyone on the floor is waiting for the elevator.
Sourcepub fn flush_and_update_tips(&mut self, rng: &mut impl Rng)
pub fn flush_and_update_tips(&mut self, rng: &mut impl Rng)
Removes anyone who is leaving the first floor, and generates tips
Sourcepub fn collect_tips(&mut self) -> f64
pub fn collect_tips(&mut self) -> f64
Returns all tips collected by the building, and resets the total tips to 0
Sourcepub fn update_average_energy(&mut self, time_step: i32, energy_spent: f64)
pub fn update_average_energy(&mut self, time_step: i32, energy_spent: f64)
Update the average energy spent by the building’s elevators given the time step and the energy spent during the time step.
Sourcepub fn append_elevator(
&mut self,
energy_up: f64,
energy_down: f64,
energy_coef: f64,
)
pub fn append_elevator( &mut self, energy_up: f64, energy_down: f64, energy_coef: f64, )
Append a new elevator to the building
Trait Implementations§
Source§impl Floors for Building
impl Floors for Building
Source§fn are_people_waiting_on_floor(&self, floor_index: usize) -> bool
fn are_people_waiting_on_floor(&self, floor_index: usize) -> bool
Determines whether there are any people waiting on a given floor. Returns a bool which is true if so, and false if not.
Source§fn get_nearest_wait_floor(&self, floor_on: usize) -> (usize, usize)
fn get_nearest_wait_floor(&self, floor_on: usize) -> (usize, usize)
Determines the nearest floor at which people are waiting with respect to the given floor. Returns a tuple of usizes representing the floor index and the distance to the floor.
Source§fn get_dest_probabilities(&self) -> Vec<f64>
fn get_dest_probabilities(&self) -> Vec<f64>
Gets the probability that each floor becomes a destination floor in the next time step.
Source§fn gen_people_leaving(&mut self, rng: &mut impl Rng)
fn gen_people_leaving(&mut self, rng: &mut impl Rng)
Randomly generates the people leaving each floor using each Floor’s
gen_people_leaving function, which itself uses each Person’s gen_is_leaving
function.
Source§fn flush_first_floor(&mut self) -> Vec<Person>
fn flush_first_floor(&mut self) -> Vec<Person>
Removes anyone who is leaving the first floor, and generates tips
Source§fn increment_wait_times(&mut self)
fn increment_wait_times(&mut self)
Increments the waiting times among people who are waiting/not at their destination floor throughout the building’s floors and elevators.
Source§fn append_floor(&mut self)
fn append_floor(&mut self)
Appends a new floor to the building.
Auto Trait Implementations§
impl Freeze for Building
impl RefUnwindSafe for Building
impl Send for Building
impl Sync for Building
impl Unpin for Building
impl UnwindSafe for Building
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.