Created
August 3, 2017 08:59
-
-
Save BenLauwens/15edb27cc0ac5cbea6e1bd79f5038a6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SimJulia, Distributions | |
@resumable function people(sim::Simulation, λ::Float64, clerk::Resource) | |
i = 1 | |
while true | |
Δt = rand(Exponential(1/λ)) | |
@yield return Timeout(sim, Δt) | |
@coroutine customer(sim, i, clerk) | |
i += 1 | |
end | |
end | |
@resumable function customer(sim::Simulation, n::Int64, clerk::Resource) | |
if length(clerk) > 5 | |
println(@sprintf("%0.2f: Queue is full! Customer %d leaves", now(sim), n)) | |
return | |
else | |
arrivaltime = now(sim) | |
println(@sprintf("%0.2f: Customer %d enqueues", now(sim), n)) | |
@request clerk req begin | |
@yield return req | |
println(@sprintf("%0.2f: Customer %d being served", now(sim), n)) | |
Δt = rand(DiscreteUniform(1, 5)) + randn()*0.2 | |
@yield return Timeout(sim, Δt) | |
end | |
println(@sprintf("%0.2f: Customer %d leaves after %0.2f min", now(sim), n, now(sim)-arrivaltime)) | |
end | |
end | |
sim = Simulation() | |
clerk = Resource(sim, 1) | |
@coroutine people(sim, 3.333, clerk) | |
run(sim, 60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Ben,
it works as you said. I had to change my bug in
function people
tothen I get the same results as in my notebook.
You can close therefore the issue. But you should perhaps change accordingly the function
customer2
inbenchmarks\coroutines_MM1.jl
, which I used as an example.I cannot follow you yet with the queue management. For this example you are right. But for my development, I have to enqueue things like
jobs::Job
which is not (yet) possible if I read your code well enough. One other aspect is a logical one: in my view, the clerk and the queue before the clerk are different entities, which should be treated separately. Your example would work if the clerk would work on different customers at a time (multitasking). But even then I needed a queue with separate distinguishable jobs or customers, on which the clerk could multitask.
BTW: are you interested, to integrate or to have integrated my functions from
simlog.jl
, which you can see working in the above notebook, intoSimJulia
?All the best and thank you for your work,
Paul