Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Simcore-rs
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dorian Weber
Simcore-rs
Commits
b984c6f8
Commit
b984c6f8
authored
4 years ago
by
Dorian Weber
Browse files
Options
Downloads
Patches
Plain Diff
Shortened the example for print in the paper.
parent
d441ffc8
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
benches/barbershop.rs
+7
-7
7 additions, 7 deletions
benches/barbershop.rs
src/bin/barbershop.rs
+37
-42
37 additions, 42 deletions
src/bin/barbershop.rs
with
44 additions
and
49 deletions
benches/barbershop.rs
+
7
−
7
View file @
b984c6f8
...
@@ -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
;
}
}
});
});
...
...
This diff is collapsed.
Click to expand it.
src/bin/barbershop.rs
+
37
−
42
View file @
b984c6f8
...
@@ -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
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment