muse2::time_slice

Struct TimeSliceInfo

Source
pub struct TimeSliceInfo {
    pub seasons: HashSet<Rc<str>>,
    pub times_of_day: HashSet<Rc<str>>,
    pub fractions: HashMap<TimeSliceID, f64>,
}
Expand description

Information about the time slices in the simulation, including names and fractions

Fields§

§seasons: HashSet<Rc<str>>

Names of seasons

§times_of_day: HashSet<Rc<str>>

Names of times of day (e.g. “evening”)

§fractions: HashMap<TimeSliceID, f64>

The fraction of the year that this combination of season and time of day occupies

Implementations§

Source§

impl TimeSliceInfo

Source

pub fn get_time_slice_id_from_str( &self, time_slice: &str, ) -> Result<TimeSliceID>

Get the TimeSliceID corresponding to the time_slice.

time_slice must be in the form “season.time_of_day”.

Source

pub fn get_selection(&self, time_slice: &str) -> Result<TimeSliceSelection>

Get a TimeSliceSelection from the specified string.

If the string is empty, the default value is TimeSliceSelection::Annual.

Source

pub fn iter_ids(&self) -> impl Iterator<Item = &TimeSliceID>

Iterate over all TimeSliceIDs.

The order will be consistent each time this is called, but not every time the program is run.

Source

pub fn iter(&self) -> impl Iterator<Item = (&TimeSliceID, f64)>

Iterate over all time slices.

The order will be consistent each time this is called, but not every time the program is run.

Source

pub fn iter_selection<'a>( &'a self, selection: &'a TimeSliceSelection, ) -> Box<dyn Iterator<Item = (&'a TimeSliceID, f64)> + 'a>

Iterate over the subset of time slices indicated by selection.

The order will be consistent each time this is called, but not every time the program is run.

Source

pub fn iterate_selection_share<'a>( &'a self, selection: &'a TimeSliceSelection, ) -> impl Iterator<Item = (&'a TimeSliceID, f64)>

Iterate over a subset of time slices calculating the relative duration of each.

The relative duration is specified as a fraction of the total time (proportion of year) covered by selection.

§Arguments
  • selection - A subset of time slices
§Returns

An iterator of time slices along with the fraction of the total selection.

Source

pub fn calculate_share<'a>( &'a self, selection: &'a TimeSliceSelection, value: f64, ) -> impl Iterator<Item = (&'a TimeSliceID, f64)>

Share a value between a subset of time slices in proportion to their lengths.

For instance, you could use this function to compute how demand is distributed between the different time slices of winter.

§Arguments
  • selection - A subset of time slices
  • value - The value to be shared between the time slices
§Returns

An iterator of time slices along with a fraction of value.

Trait Implementations§

Source§

impl Debug for TimeSliceInfo

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for TimeSliceInfo

Source§

fn default() -> Self

The default TimeSliceInfo is a single time slice covering the whole year

Source§

impl PartialEq for TimeSliceInfo

Source§

fn eq(&self, other: &TimeSliceInfo) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for TimeSliceInfo

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.