Expand description
Chapter 5: How to proceed.
You now know the core loop of every simu model: spawn processes, await timeouts / events / resources, run, read out results. The rest of the toolbox, in the order you are likely to need it:
PriorityResource— likeResource, butrequest(priority)serves lower numbers first (FIFO within a level). Triage queues, VIP lanes.PreemptiveResource— a priority pool where an urgent request can evict a lower-priority holder mid-service; the victim observes it viaguard.preempted(). See the type docs for the full pattern.Container— continuous quantity instead of discrete units: tanks, silos, blood banks.put(amount)/get(amount)with strict FIFO waiters.all_of!— the dual ofany_of!: wait for every sub-future (barrier / fork-join).- Randomness —
h.rng()borrows the env’s seeded RNG; combine withrng::sampleorrand_distrfor stochastic arrival/service times. Sample before.await— the borrow cannot be held across a suspension point. - Monte Carlo —
monte_carlo::runexecutes one full, independent simulation per seed in parallel threads:
use simu::{SimEnv, monte_carlo};
let end_times = monte_carlo::run(0..8u64, |seed| {
let mut env = SimEnv::with_seed(seed);
let h = env.handle();
env.spawn(async move { h.timeout(1.0).await; });
env.run();
env.now()
});
assert_eq!(end_times.len(), 8); // results arrive in seed orderWhen you are ready for full models, three commented showcases combine
everything above, each with a walkthrough document in examples/:
cargo run --example hospital— ER with priority triage, bed eviction, and a blood bank (PriorityResource,PreemptiveResourceprecursor patterns,Container).cargo run --example brewery— a fermentation line with contamination events and cleanup priorities (EventTrigger,PriorityResource).cargo run --example warehouse— a forklift fleet shared between receiving and shipping (PreemptiveResourceend-to-end).
Coming from SimPy? The repository root has llms.txt with a complete
SimPy → simu translation table.