pub struct Building {
    pub elevators: Vec<Elevator>,
    pub floors: Vec<Floor>,
    pub avg_energy: f64,
    pub avg_wait_time: 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

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

Trait Implementations§

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)

Removes anyone who is leaving the first floor.

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.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

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

§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
§

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

§

fn vzip(self) -> V