pub struct Simulation { /* private fields */ }Expand description
A Simulation struct is responsible to hold all the state for a simulation and coordinates the actions and interactions of the agents.
A Simulation has its own concept of time, which is implemented as discrete
ticks of the u64 field time. Every tick is modeled as an instantaneous
point in time at which interactions can occur. The Simulation engine uses a
concept of Messages to communicate between agents. Agents can receive
messages and send messages to other Agents.
Implementations§
Source§impl Simulation
impl Simulation
pub fn new(parameters: SimulationParameters) -> Self
Sourcepub fn consumed_for_agent(&self, name: &str) -> Option<&[Message]>
pub fn consumed_for_agent(&self, name: &str) -> Option<&[Message]>
Returns the consumed messages for a given Agent during the Simulation.
Sourcepub fn find_by_name(&self, name: &str) -> Option<&SimulationAgent>
pub fn find_by_name(&self, name: &str) -> Option<&SimulationAgent>
Returns a SimulationAgent by name.
Sourcepub fn find_by_name_mut(&mut self, name: &str) -> Option<&mut SimulationAgent>
pub fn find_by_name_mut(&mut self, name: &str) -> Option<&mut SimulationAgent>
Returns a SimulationAgent by name.
Sourcepub fn produced_for_agent(&self, name: &str) -> Option<&[Message]>
pub fn produced_for_agent(&self, name: &str) -> Option<&[Message]>
Returns the produced messages for a given Agent during the Simulation.
Sourcepub fn queue_depth_metrics(&self, name: &str) -> Option<&[usize]>
pub fn queue_depth_metrics(&self, name: &str) -> Option<&[usize]>
Returns the queue depth timeseries for a given Agent during the Simulation.
Sourcepub fn asleep_cycle_count(&self, name: &str) -> Option<DiscreteTime>
pub fn asleep_cycle_count(&self, name: &str) -> Option<DiscreteTime>
Returns the asleep cycle count for a given Agent during the Simulation.
Sourcepub fn run(&mut self)
pub fn run(&mut self)
Runs the simulation. This should only be called after adding all the beginning state.
Sourcepub fn calc_avg_wait_statistics(&self) -> HashMap<String, f64>
pub fn calc_avg_wait_statistics(&self) -> HashMap<String, f64>
A helper to calculate the average waiting time to process items. Note: This function will likely go away; it is an artifact of prototyping.
Sourcepub fn calc_queue_len_statistics(&self) -> HashMap<String, usize>
pub fn calc_queue_len_statistics(&self) -> HashMap<String, usize>
Calculates the statistics of queue lengths. Mostly useful for checking which agents still have queues of work after halting.
Sourcepub fn calc_consumed_len_statistics(&self) -> HashMap<String, usize>
pub fn calc_consumed_len_statistics(&self) -> HashMap<String, usize>
Calculates the length of the consumed messages for each Agent.
Sourcepub fn calc_produced_len_statistics(&self) -> HashMap<String, usize>
pub fn calc_produced_len_statistics(&self) -> HashMap<String, usize>
Calculates the length of the produced messages for each Agent.
Sourcepub fn find_agent<P>(&self, predicate: P) -> Option<&SimulationAgent>
pub fn find_agent<P>(&self, predicate: P) -> Option<&SimulationAgent>
Searches for an agent in the Simulation matching the given predicate.
Sourcepub fn all_agents<P>(&self, predicate: P) -> bool
pub fn all_agents<P>(&self, predicate: P) -> bool
Checks whether all agents match the given predicate.
Sourcepub fn agents(&self) -> &[SimulationAgent]
pub fn agents(&self) -> &[SimulationAgent]
Returns a slice of the Agents in the Simulation.
Sourcepub const fn time(&self) -> DiscreteTime
pub const fn time(&self) -> DiscreteTime
Returns the current DiscreteTime tick for the Simulation.
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