From c87120d28e159b939cac8f0ffe4123c15f662b77 Mon Sep 17 00:00:00 2001 From: Dorian Weber <weber@informatik.hu-berlin.de> Date: Tue, 28 Jul 2020 15:12:55 +0200 Subject: [PATCH] Renamed the example coroutines and deleted the old simcore. --- ...ecompressor_tokenizer.rs => coroutines.rs} | 0 src/bin/simcore.rs | 65 ------------------- 2 files changed, 65 deletions(-) rename src/bin/{decompressor_tokenizer.rs => coroutines.rs} (100%) delete mode 100644 src/bin/simcore.rs diff --git a/src/bin/decompressor_tokenizer.rs b/src/bin/coroutines.rs similarity index 100% rename from src/bin/decompressor_tokenizer.rs rename to src/bin/coroutines.rs diff --git a/src/bin/simcore.rs b/src/bin/simcore.rs deleted file mode 100644 index c3dff02..0000000 --- a/src/bin/simcore.rs +++ /dev/null @@ -1,65 +0,0 @@ -use simcore_rs::{Time, SimContext, Facility, RandomVar, simulation}; -use rand::{distributions::Uniform, rngs::SmallRng, SeedableRng, Rng}; - -// helper constants -const STOP_TIME: Time = 480000.0; -const SEED_A : u64 = 100000; -const SEED_S : u64 = 200000; - -fn main() { - // pseudo random number generators referenced from within the main process - let mut rng_a = SmallRng::seed_from_u64(SEED_A); - let mut rng_s = SmallRng::seed_from_u64(SEED_S); - - // the lifetimes are automatically extended - let joe = &Facility::new(); - let rv = &RandomVar::new(); - - // the main process - simulation(|sim| async move { - // activate a process to generate the customers - sim.activate(async move { - let dist = Uniform::new(12.0, 24.0); - - // wait some time before activating the first customer - sim.advance(rng_a.sample(dist)).await; - - // generate new customers until the store closes officially - while sim.now() < STOP_TIME { - // activate the next customer - sim.activate(Customer { - joe, rv, rng: SmallRng::from_seed(rng_s.gen()) - }.actions(sim)); - - // wait some time before activating the next customer - sim.advance(rng_a.sample(dist)).await; - } - }); - - // wait until the store closes - sim.advance(STOP_TIME).await; - - // finish processing the queue (no more customers arrive) - joe.seize().await; - joe.release(); - }); - - println!("Stats: {:.3}", rv); -} - -/// Customer process with access to the barber and a random number generator. -struct Customer<'j> { joe: &'j Facility, rv: &'j RandomVar, rng: SmallRng } - -impl Customer<'_> { - pub async fn actions(mut self, sim: SimContext<'_>) { - // access the barber and record the time for the report - let time = sim.now(); - self.joe.seize().await; - self.rv.tabulate(sim.now() - time); - - // spend time - sim.advance(self.rng.gen_range(12.0, 18.0)).await; - // release the barber - self.joe.release(); - } -} -- GitLab