Struct desim::Simulation
[−]
[src]
pub struct Simulation { /* fields omitted */ }
This struct provides the methods to create and run the simulation in a single thread.
It provides methods to create processes and finite resources that must be shared among them.
See the crate-level documentation for more information about how the simulation framework works
Methods
impl Simulation
[src]
pub fn new() -> Simulation
[src]
pub fn time(&self) -> f64
[src]
Returns the current simulation time
pub fn processed_events(&self) -> &[Event]
[src]
Returns the log of processed events
pub fn create_process(
&mut self,
process: Box<Generator<Yield = Effect, Return = ()>>
) -> ProcessId
[src]
&mut self,
process: Box<Generator<Yield = Effect, Return = ()>>
) -> ProcessId
Create a process. That is a generator that can Yield Effect
s.
An effect may be a new Event
to schedule, a Timeout
after which the
same process should be executed, or a Request
to hold an instance
of a finite resource.
Returns the identifier of the process.
pub fn create_resource(&mut self, n: usize) -> ResourceId
[src]
Create a new finite resource, of which n instancies are available.
The resource can be requested by a process yielding a Request
.
If the requested resource is not available at that time, the process
is enqueued until one instance of the resource is freed.
When the process has done with the resource, it has to yield Release
,
so that other processes can use that.
The queue has a FIFO (first in first out) policy.
Returns the identifier of the resource
pub fn schedule_event(&mut self, event: Event)
[src]
Schedule a process to be executed. Another way to schedule events is
yielding Effect::Event
from a process during the simulation.
pub fn step(&mut self)
[src]
Proceed in the simulation by 1 step
pub fn run(self, until: EndCondition) -> Simulation
[src]
Run the simulation until and ending condition is met.