Expand description
This crate implements a discrete time event simulation framework inspired by the SimPy library for Python. It uses the generator feature that is nightly. Once the feature is stabilized, also this crate will use stable. Generators will be the only nightly feature used in this crate.
The examples directory in this repository contains full usage examples of the desim crate as a simulation framework.
Simulation
A simulation is performed scheduling one or more processes that models the environment you are going to simulate. Your model may consider some kind of finite resource that must be shared among the processes, e.g. a bunch of servers in a simulation on queues.
After setting up the simulation, it can be run step-by-step, using
the step() method, or all at once, with run(), until and ending
condition is met.
The simulation will generate a log of all the events with a state that
returns true to should_log.
Process
A process is implemented using the rust generators syntax. This let us avoid the overhead of spawning a new thread for each process, while still keeping the use of this framework quite simple.
When a new process is created in the simulation, an identifier, of type
ProcessId is assigned to it. That id can be used to schedule an event that
resumes the process.
A process can be stopped and resumed later on. To stop the process, the
generator yields an Effect that specify what the simulator should do.
For example, a generator can set a timeout after which it is executed again.
The process may also return. In that case it can not be resumed anymore.
Resource
A resource is a finite amount of entities, eachone of which can be used by one process a time. When the process does not need the resource anymore, it must release it.
A resource can be created in the simulation using the create_resource
method, which requires the resource to add to the simulation and returns an identifier
for that resource that can be used to require and release it.
A resource can be required and reelased by a process yielding
the corresponding Effect. There is no check on the fact that a process
yielding Release was holding a resource with that ID.
For more information about the Resource trait and the SimpleResource implementation,
see the resources module.
Modules
Structs
Event Effect
or by the owner of a Simulation through the schedule methodEnums
Traits
Process. This allows attaching application-specific data
to Effects. This data is then carried arround by the Simulation, passed
into user callbacks for context or simply logged for later.Type Definitions
Process generator