Struct sim::simulator::Simulation

source ·
pub struct Simulation { /* private fields */ }
Expand description

The Simulation struct is the core of sim, and includes everything needed to run a simulation - models, connectors, and a random number generator. State information, specifically global time and active messages are additionally retained in the struct.

Implementations§

source§

impl Simulation

source

pub fn post(models: Vec<Model>, connectors: Vec<Connector>) -> Self

This constructor method creates a simulation from a supplied configuration (models and connectors).

source

pub fn post_with_rng( models: Vec<Model>, connectors: Vec<Connector>, global_rng: impl SimulationRng + 'static ) -> Self

This constructor method creates a simulation from a supplied configuration (models and connectors).

source

pub fn set_rng(&mut self, rng: impl SimulationRng + 'static)

source

pub fn put(&mut self, models: Vec<Model>, connectors: Vec<Connector>)

This method sets the models and connectors of an existing simulation.

source

pub fn get_messages(&self) -> &Vec<Message>

Simulation steps generate messages, which are then consumed on subsequent simulation steps. These messages between models in a simulation drive much of the discovery, analysis, and design. This accessor method provides the list of active messages, at the current point of time in the simulation. Message history is not retained, so simulation products and projects should collect messages as needed throughout the simulation execution.

source

pub fn get_global_time(&self) -> f64

An accessor method for the simulation global time.

source

pub fn get_status(&self, model_id: &str) -> Result<String, SimulationError>

This method provides a mechanism for getting the status of any model in a simulation. The method takes the model ID as an argument, and returns the current status string for that model.

source

pub fn get_records( &self, model_id: &str ) -> Result<&Vec<ModelRecord>, SimulationError>

This method provides a mechanism for getting the records of any model in a simulation. The method takes the model ID as an argument, and returns the records for that model.

source

pub fn reset(&mut self)

To enable simulation replications, the reset method resets the state of the simulation, except for the random number generator. Recreating a simulation from scratch for additional replications does not work, due to the random number generator seeding.

source

pub fn reset_messages(&mut self)

Clear the active messages in a simulation.

source

pub fn reset_global_time(&mut self)

Reset the simulation global time to 0.0.

source

pub fn models(&mut self) -> Vec<&mut Model>

This method provides a convenient foundation for operating on the full set of models in the simulation.

source

pub fn inject_input(&mut self, message: Message)

Input injection creates a message during simulation execution, without needing to create that message through the standard simulation constructs. This enables live simulation interaction, disruption, and manipulation - all through the standard simulation message system.

source

pub fn step(&mut self) -> Result<Vec<Message>, SimulationError>

The simulation step is foundational for a discrete event simulation. This method executes a single discrete event simulation step, including internal state transitions, external state transitions, message orchestration, global time accounting, and step messages output.

source

pub fn step_until( &mut self, until: f64 ) -> Result<Vec<Message>, SimulationError>

This method executes simulation step calls, until a global time has been exceeded. At which point, the messages from all the simulation steps are returned.

source

pub fn step_n(&mut self, n: usize) -> Result<Vec<Message>, SimulationError>

This method executes the specified number of simulation steps, n. Upon execution of the n steps, the messages from all the steps are returned.

Trait Implementations§

source§

impl Clone for Simulation

source§

fn clone(&self) -> Simulation

Returns a copy 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 Default for Simulation

source§

fn default() -> Simulation

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Simulation

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for Simulation

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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

§

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, U> TryFrom<U> for T
where 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 T
where 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 T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,