Skip to content
Snippets Groups Projects
Commit b984c6f8 authored by Dorian Weber's avatar Dorian Weber
Browse files

Shortened the example for print in the paper.

parent d441ffc8
Branches
No related merge requests found
...@@ -62,18 +62,18 @@ impl BarberShop { ...@@ -62,18 +62,18 @@ impl BarberShop {
sim.activate(async move { sim.activate(async move {
let dist = Uniform::new(12.0, 24.0); let dist = Uniform::new(12.0, 24.0);
// wait some time before activating the first customer loop {
sim.advance(rng_a.sample(dist)).await; // wait some time before activating the next customer
sim.advance(rng_a.sample(dist)).await;
// generate new customers until the store closes officially
while sim.now() < stop_time { // generate new customers until the store closes officially
if sim.now() >= stop_time { return; }
// activate the next customer // activate the next customer
sim.activate(Customer { sim.activate(Customer {
joe: joe.clone(), joe: joe.clone(),
rng: SmallRng::from_seed(rng_s.gen()) rng: SmallRng::from_seed(rng_s.gen())
}.actions(sim)); }.actions(sim));
// wait some time before activating the next customer
sim.advance(rng_a.sample(dist)).await;
} }
}); });
......
...@@ -6,48 +6,6 @@ const STOP_TIME: Time = 480000.0; ...@@ -6,48 +6,6 @@ const STOP_TIME: Time = 480000.0;
const SEED_A : u64 = 100000; const SEED_A : u64 = 100000;
const SEED_S : u64 = 200000; 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 until the end of the scope
let joe = &Facility::new();
let rv = &RandomVar::new();
// the main process
simulation(|sim| Process::new(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: joe.clone(),
rv: rv.clone(),
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;
}));
println!("Stats: {:.3}", rv);
}
/// Customer process with access to the barber and a random number generator. /// Customer process with access to the barber and a random number generator.
struct Customer<'c> { joe: &'c Facility, rv: &'c RandomVar, rng: SmallRng } struct Customer<'c> { joe: &'c Facility, rv: &'c RandomVar, rng: SmallRng }
...@@ -64,3 +22,40 @@ impl<'c> Customer<'c> { ...@@ -64,3 +22,40 @@ impl<'c> Customer<'c> {
self.joe.release(); self.joe.release();
} }
} }
async fn sim_main<'m>(sim: SimContext<'m>, joe: &'m Facility, rv: &'m RandomVar) {
// 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);
// activate a process to generate the customers
sim.activate(async move {
let dist = Uniform::new(12.0, 24.0);
loop {
sim.advance(rng_a.sample(dist)).await;
if sim.now() >= STOP_TIME { return; }
sim.activate(Customer {
joe: joe.clone(),
rv: rv.clone(),
rng: SmallRng::from_seed(rng_s.gen())
}.actions(sim));
}
});
// wait until the store closes
sim.advance(STOP_TIME).await;
// finish processing the queue (no more customers arrive)
joe.seize().await;
}
fn main() {
// the lifetimes are automatically extended until the end of the scope
let joe = &Facility::new();
let rv = &RandomVar::new();
// the main process
simulation(|sim| Process::new(sim_main(sim, joe, rv)));
println!("Stats: {:.3}", rv);
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment