On Wed, 28 Nov 2018 at 15:37, Tom Lawton <
t...@t-lawton.org> wrote:
> On Friday, November 23, 2018 at 12:18:12 PM UTC, Tom Lawton wrote:
>>
>> When a hospital bed (resource) closes, the patient will have to be transferred elsewhere, but I'm not sure how best to detect that using r-simmer. By default it appears, if a resource is occupied when set_capacity reduces the resource availability, the actor is not "kicked off" and continues to occupy the resource as normal.
>>
>> Can anyone suggest a good way to model this within r-simmer? I've enclosed an example below based on one of the bank vignettes. Ideally I need some way of detecting that Customer0 and Customer1 need to find themselves some other resource until time 126.
For some reason I didn't receive your previous email.
> It strikes me that an alternative way to do this would be to avoid using set_capacity, and instead leave capacity at whatever its maximum value will be, and seize resources (with pre-emption) to represent beds being closed etc. This should kick patients out as expected. I gather there's a queue_size_strict option to prevent those patients joining a queue (we have to put them somewhere!) - will they then just go down the "reject" trajectory as if they'd been denied the bed in the first place?
There should be no difference between using set_capacity to close a
resource and seizing the whole resource with a higher priority. I.e.,
if preemption is enabled and queue_size_strict is set to true,
everything is rejected.
The problem (for your use case) is that the "reject" trajectory is not
honored in such cases, as it would be if the resource is denied in the
first place. But now that you put it in that way, maybe this is
confusing, and maybe the "reject" trajectory should be followed by
rejections due to preemption too. I have to think about it.
Meanwhile, you can use signals and you don't need preemption:
library(simmer)
kicked <- trajectory() %>%
log_("I've been kicked!")
patient <- trajectory() %>%
seize("bed") %>%
trap("bed closed", handler=kicked, interruptible=FALSE) %>%
timeout(10) %>%
release("bed")
blocker <- trajectory() %>%
set_capacity("bed", 0) %>%
send("bed closed")
env <- simmer() %>%
add_resource("bed") %>%
add_generator("patient", patient, at(0)) %>%
add_generator("blocker", blocker, at(5)) %>%
run()
#> 5: patient0: I've been kicked!
Iñaki