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
impl Simulation
sourcepub fn post(models: Vec<Model>, connectors: Vec<Connector>) -> Self
pub fn post(models: Vec<Model>, connectors: Vec<Connector>) -> Self
This constructor method creates a simulation from a supplied configuration (models and connectors).
sourcepub fn post_with_rng(
models: Vec<Model>,
connectors: Vec<Connector>,
global_rng: impl SimulationRng + 'static
) -> Self
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).
pub fn set_rng(&mut self, rng: impl SimulationRng + 'static)
sourcepub fn put(&mut self, models: Vec<Model>, connectors: Vec<Connector>)
pub fn put(&mut self, models: Vec<Model>, connectors: Vec<Connector>)
This method sets the models and connectors of an existing simulation.
sourcepub fn get_messages(&self) -> &Vec<Message>
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.
sourcepub fn get_global_time(&self) -> f64
pub fn get_global_time(&self) -> f64
An accessor method for the simulation global time.
sourcepub fn get_status(&self, model_id: &str) -> Result<String, SimulationError>
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.
sourcepub fn get_records(
&self,
model_id: &str
) -> Result<&Vec<ModelRecord>, SimulationError>
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.
sourcepub fn reset(&mut self)
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.
sourcepub fn reset_messages(&mut self)
pub fn reset_messages(&mut self)
Clear the active messages in a simulation.
sourcepub fn reset_global_time(&mut self)
pub fn reset_global_time(&mut self)
Reset the simulation global time to 0.0.
sourcepub fn models(&mut self) -> Vec<&mut Model>
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.
sourcepub fn inject_input(&mut self, message: Message)
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.
sourcepub fn step(&mut self) -> Result<Vec<Message>, SimulationError>
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.
sourcepub fn step_until(
&mut self,
until: f64
) -> Result<Vec<Message>, SimulationError>
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.
Trait Implementations§
source§impl Clone for Simulation
impl Clone for Simulation
source§fn clone(&self) -> Simulation
fn clone(&self) -> Simulation
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more