Building

Struct Building 

Source
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: f64

Implementations§

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.

Source

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
);
Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn flush_and_update_tips(&mut self, rng: &mut impl Rng)

Removes anyone who is leaving the first floor, and generates tips

Source

pub fn collect_tips(&mut self) -> f64

Returns all tips collected by the building, and resets the total tips to 0

Source

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.

Source

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 Clone for Building

Source§

fn clone(&self) -> Building

Returns a duplicate 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 Display for Building

Source§

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

Format a Building as a string.

§Example
println!("{}", my_building);
Source§

impl Floors for Building

Source§

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)

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>

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)

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>

Removes anyone who is leaving the first floor, and generates tips

Source§

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)

Appends a new floor to the building.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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

Source§

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,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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