need your opinion: cancer center scenario

245 views
Skip to first unread message

mokoka...@gmail.com

unread,
Jun 7, 2016, 6:43:12 PM6/7/16
to simmer-devel

Dear Experts, need your opinion..


A center for treatment of leukemia has only 30 beds


Treatment involves the following process:

Induction 1--> Induction 2 --> Consolidation 1 --> Consolidation 2


Step #1 --> Induction 1

-accepting new cases to receive Chemotherapy Known as Induction 1 Regimen

-rate of arrival 2.3 patients / week

-average length of stay (ALOS) = 31 days


Step #2 -->  Induction 2

-84.2 % of patients from step #1 arrive successfully to this step

-ALOS = 28 days

-highest priority for admission


Step #3  --> Consolidation 1

-74.6% of patients from step#1 arrive successfully to this step

-ALOS = 25 days

- priority for admission less than step#2 but higher than step#1


Step #4 --> Consolidation 2

-73.5% of patients from step#1 arrive successfully to this step

-ALOS = 31.5 days

- priority for admission less than step#2 but higher than step#1


 

Using the R-script below, running the simulation for 2 years (730 days) and 30 beds gave the following

server status: 30(30) | queue status: 42

> mean(x$queue)
[1] 22.3562

 

Using the R-script below, running the simulation for 2 years (730 days) and 31 beds gave the following

server status: 31(31) | queue status: 13
> mean(x$queue)
[1] 6.314767
 
 

Using the R-script below, running the simulation for 2 years (730 days) and 32 beds gave the following

server status: 30(32) | queue status: 0
> mean(x$queue)
[1] 0.57
 
Does this mean that: "if I increase the center capacity from 30 to 32 beds, I will have no waiting list?"

========================= R Script ==============================

 

library(simmer)

# rate of new patient arrival = 2.3 per week
# inter-arrival time (IAT)= 7/2.3 days
 
#rn = interarrival time of new cases who will receive Induction 1
rn <- 7/2.3 # IAT = 7/2.3, Priority = 1
 
#rind2 = interarrival time of patients who will receive Induction 2
rind2 <- (1/0.842) * rn # priority = 9
 
#consol1 = interarrival time of patients who will receive consolidation 1
rconsol1 <- (1/0.746) * rn # priority = 8
 
#consol1 = interarrival time of patients who will receive consolidation 2
rconsol2 <- (1/0.735) * rn # priority = 8
 
env <- simmer("AML-env")
 
## add a new patient trajectory
newpatient <- create_trajectory("newAMLpatientpath") %>%
  
  seize("bed", amount = 1, priority = 1) %>%
  ## 31 day
  timeout(function() rnorm(1, 31, 2)) %>% 
  release("bed", 1) 
 
## add a Induction2 patient trajectory
rind2patient <- create_trajectory("rind2AMLpatientpath") %>%
  seize("bed", amount = 1, priority = 9) %>%
  ## 28 days
  timeout(function() rnorm(1, 28, 2)) %>%
  release("bed", 1)
 
## add a Consolidation1 patient trajectory
consol1patient <- create_trajectory("consol1AMLpatientpath") %>%
    seize("bed", amount = 1, priority = 8) %>%
  ## 25 days
  timeout(function() rnorm(1, 25, 2)) %>%
  release("bed", 1)
 
## add a Consolidation2 patient trajectory
consol2patient <- create_trajectory("consol2AMLpatientpath") %>%
    seize("bed", amount = 1, priority = 8) %>%
  ## 31.5 days
  timeout(function() rnorm(1, 31.5, 2)) %>%
  release("bed", 1)
 
env %>%
  add_resource("bed", 30) %>%
  add_generator("newpatient", newpatient, function() rn) %>%
  add_generator("rind2patient", rind2patient, function() rind2) %>%
  add_generator("consol1patient", consol1patient, function() rconsol1) %>%
  add_generator("consol2patient", consol2patient, function() rconsol2) 
 
env %>% run(until=730) ## run for two years (365 * 2 = 730)
x<-env %>% get_mon_resources()
y<-env %>% get_mon_arrivals()
mean(x$queue)

Iñaki Úcar

unread,
Jun 8, 2016, 7:26:46 AM6/8/16
to simmer-devel
Does this mean that: "if I increase the center capacity from 30 to 32 beds, I will have no waiting list?"
It would, if the model were good, but it doesn't seem reasonable to me.
  • You have no arrival process. You've merely assigned constant IATs.
  • Patients from the first stage don't go through subsequent stages. Instead, you are generating new different arrivals for each stage (!).

Mohamed Kamal

unread,
Jun 8, 2016, 7:44:11 AM6/8/16
to simmer-devel
Thanks a lot for your response. I did not know it is possible to make patients go through subsequent stages in r-simmer. How is this possible ? In the examples provided with documentation I could not find an example of entities in sequence. I might need your help, if possible.

Regarding IATs I can use a distribution (prefer exponential ?)

Iñaki Úcar

unread,
Jun 8, 2016, 8:30:33 AM6/8/16
to simmer-devel
Thanks a lot for your response. I did not know it is possible to make patients go through subsequent stages in r-simmer. How is this possible ? In the examples provided with documentation I could not find an example of entities in sequence. I might need your help, if possible.

Building a trajectory with all the steps needed. The introductory vignette has an example in which patients visit a nurse, then a doctor and then the administration.
 
Regarding IATs I can use a distribution (prefer exponential ?)

You need to fit a distribution based on real data. Maybe the exponential is a good candidate, maybe not.
 
--

Mohamed Kamal

unread,
Jun 8, 2016, 8:46:43 AM6/8/16
to simmer-devel
The problem is that I have only one Resource = "Bed" I have 30 beds to accommodate all patients in all stages 

Mohamed Kamal

unread,
Jun 8, 2016, 8:51:31 AM6/8/16
to simmer-devel
To clarify more, in real-life I have a long waiting list of patients waiting for a "free" bed. Patients from new cases, Induction2, consolidation1 and consolidation2 are all competing for the same and only resource (30 Bed). So, if I design a trajectory, I will not be able to "distribute" beds over different stages. 

Bart Smeets

unread,
Jun 8, 2016, 9:04:28 AM6/8/16
to simmer-devel
You could built one trajectory to describe your simulation problem. Have look at the branching tactics described in https://cran.r-project.org/web/packages/simmer/vignettes/C-trajectories.html#branch. From a branch statement you can then model when and how you move towards a subtrajectory (e.g. the "74.6% of patients from step#1 arrive successfully to this step" statements).

Between each step you can use a timeout where you wait an appropriate amount of time between e.g. step 1 and step 2. Once the timeout is over, you can let the patient re-seize a bed (and it will compete here with other patients that might be in a different step). You can of course also work with priorities in the seize, to give different patients at different stages different priorities at seizing a bed (which is probably realistic)

Op woensdag 8 juni 2016 14:51:31 UTC+2 schreef Mohamed Kamal:

Mohamed Kamal

unread,
Jun 8, 2016, 9:35:20 AM6/8/16
to simmer...@googlegroups.com
thanks Bart and Iñaki
I will rewrite it and post it back on the group
--
You received this message because you are subscribed to a topic in the Google Groups "simmer-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/simmer-devel/sXcFXvUDD1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to simmer-devel...@googlegroups.com.
To post to this group, send email to simmer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/93bebb04-1325-4f1d-9a91-292b352cc38a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Mohamed Kamal, R.Ph., CHRP

Mohamed Kamal

unread,
Jun 8, 2016, 7:13:09 PM6/8/16
to simmer-devel
please check the following modified script with branches, your feedback is highly appreciated...

library(simmer)

# rate of new patient arrival = 2.3 per week

# interarrival time (IAT)= 7/2.3 days

env <- simmer("AML-env")

## add a new patient trajectory
newpatient <- create_trajectory("newAMLpatientpath") %>%
  branch(function() sample(c(1,2),size=1,replace=F,prob=c(0.999,0.001)), merge=c(T, T), 
         create_trajectory("Induction1") %>%
           seize("bed", amount = 1, priority = 1) %>%
           seize("Induction1_in", amount = 1, priority = 1) %>%
           ## 31 day
           timeout(function() rnorm(1, 31, 2)) %>% 
           release("bed", 1)%>%
           
           #================ Induction 2
           branch(function() sample(c(1,2),size=1,replace=F,prob=c(0.842,0.158)), merge=c(T, T), 
                  create_trajectory("Induction2") %>%
                    seize("bed", amount = 1, priority = 9) %>%
                    seize("Induction2_in", amount = 1, priority = 9) %>%
                    ## 28 day
                    timeout(function() rnorm(1, 28, 2)) %>% 
                    release("bed", 1)%>%
                    #=============== Consolidation 1
                    branch(function() sample(c(1,2),size=1,replace=F,prob=c(0.746,0.254)), merge=c(T, T), 
                           create_trajectory("Consolidation1") %>%
                             seize("bed", amount = 1, priority = 8) %>%
                             seize("Consolidation1_in", amount = 1, priority = 8) %>%
                             ## 25 day
                             timeout(function() rnorm(1, 25, 2)) %>% 
                             release("bed", 1) %>%
                             #===============Consolidation 2
                             branch(function() sample(c(1,2),size=1,replace=F,prob=c(0.99,0.01)), merge=c(T, T), 
                                    create_trajectory("Consolidation2") %>%
                                      seize("bed", amount = 1, priority = 8) %>%
                                      seize("Consolidation2_in", amount = 1, priority = 8) %>%
                                      ## 31.5 day
                                      timeout(function() rnorm(1, 31.5, 2)) %>% 
                                      release("bed", 1)
                                    ,
                                    create_trajectory("Consolidation2_out") %>%
                                      seize("Consolidation2_out", amount = 1, priority = 1) 
                                    
                             ) 
                           #=============End Consolidation2
                           ,
                           create_trajectory("Consolidation1_out") %>%
                             seize("Consolidation1_out", amount = 1, priority = 1) 
                           
                    ) 
                  #===============End Consolidation 1
                  ,
                  create_trajectory("Induction2_out") %>%
                    seize("Induction2_out", amount = 1, priority = 1) 
                  
           ) 
         #=================End Induction 2
         
         ,
         create_trajectory("Induction1_out") %>%
           seize("Induction1_out", amount = 1, priority = 1) 
         
  ) 

env %>%
  
  ## add true resource
  add_resource("bed", 20) %>%
  
  ## add resources for counting purpose
  add_resource("Induction1_in", Inf) %>%
  add_resource("Induction2_in", Inf) %>%
  add_resource("Consolidation1_in", Inf) %>%
  add_resource("Consolidation2_in", Inf) %>%
  
  add_resource("Induction1_out", Inf) %>%
  add_resource("Induction2_out", Inf) %>%
  add_resource("Consolidation1_out", Inf) %>%
  add_resource("Consolidation2_out", Inf) %>%
  
  
  add_generator("newpatient", newpatient, function() rnorm(1, mean=3.33, sd=0.5)) 

env %>% run(until=730) ## run for two years (365 * 2 = 730)
x<-env %>% get_mon_resources()
y<-env %>% get_mon_arrivals()
z<-env %>% get_mon_attributes()


plot_resource_utilization(env, c("bed"))

write.csv(y,"y.csv")
mean(x$queue)
arrivals <- get_mon_arrivals(env, per_resource = T)
write.csv(arrivals,"arrivals.csv")

Mohamed Kamal

unread,
Jun 9, 2016, 2:55:04 AM6/9/16
to simmer...@googlegroups.com
I also need to know if there is a way to breakdown the queue. 
thanks again in advance.
--
You received this message because you are subscribed to a topic in the Google Groups "simmer-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/simmer-devel/sXcFXvUDD1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to simmer-devel...@googlegroups.com.
To post to this group, send email to simmer...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Iñaki Úcar

unread,
Jun 9, 2016, 4:40:31 AM6/9/16
to simmer-devel

What do you mean by "breakdown the queue"?

You received this message because you are subscribed to the Google Groups "simmer-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simmer-devel...@googlegroups.com.

To post to this group, send email to simmer...@googlegroups.com.

Mohamed Kamal

unread,
Jun 9, 2016, 4:45:24 AM6/9/16
to simmer...@googlegroups.com
Dear Iñaki

thanks a lot for your efforts and support

regarding queue, I mean percentage of queue from each stage: how many patients are waiting for Induction1, how many for Induction2, how many for Consolidation1 and consolidation2. All what I get is total number in queue.

one more thing, is my model OK now or do you still see something that needs improvement?

For more options, visit https://groups.google.com/d/optout.

Iñaki Úcar

unread,
Jun 9, 2016, 5:50:51 AM6/9/16
to simmer-devel
Sorry, I can't take a look at your code until tomorrow.


For more options, visit https://groups.google.com/d/optout.



--

Mohamed Kamal

unread,
Jun 9, 2016, 5:56:00 AM6/9/16
to simmer-devel
@Bart Smeet
any feedback
To unsubscribe from this group and all its topics, send an email to simmer-devel+unsubscribe@googlegroups.com.

To post to this group, send email to simmer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/99e9da8e-bbb8-4333-8d92-ff240091dae4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Mohamed Kamal, R.Ph., CHRP

--
You received this message because you are subscribed to the Google Groups "simmer-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simmer-devel+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "simmer-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/simmer-devel/sXcFXvUDD1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to simmer-devel+unsubscribe@googlegroups.com.

To post to this group, send email to simmer...@googlegroups.com.


--
Mohamed Kamal, R.Ph., CHRP

--
You received this message because you are subscribed to the Google Groups "simmer-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simmer-devel...@googlegroups.com.
To post to this group, send email to simmer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/CAGJu%2B0Q%2BOSPwk4tchrxGcMoN_Ypu8V-iHDWccgdOZRLyt1Epfw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Mohamed Kamal

unread,
Jun 9, 2016, 9:39:36 AM6/9/16
to simmer-devel
Experts

need your advice, is it possible to label Beds as Bed01, Bed02 ,....., Bed30
and when the patient try to seize "loop" through the beds and choose the first free bed

Bart Smeets

unread,
Jun 9, 2016, 10:19:42 AM6/9/16
to simmer-devel
Haven't looked at it yet, will take a look if I find some free time. Is there anything in the output that makes you think its "incorrect"?

Op donderdag 9 juni 2016 11:56:00 UTC+2 schreef Mohamed Kamal:

Bart Smeets

unread,
Jun 9, 2016, 10:21:08 AM6/9/16
to simmer-devel
I think this related to https://github.com/r-simmer/simmer/issues/52

Op donderdag 9 juni 2016 15:39:36 UTC+2 schreef Mohamed Kamal:

Mohamed Kamal

unread,
Jun 9, 2016, 10:21:37 AM6/9/16
to simmer...@googlegroups.com
the output is OK, after running the simulation it is almost same as real data
Waiting for your feedback


but I need (optionally) to label beds with numbers, is it possible ?
>>>>>>> simmer-devel...@googlegroups.com.
>>>>>>> To post to this group, send email to simmer...@googlegroups.com.
>>>>>>> To view this discussion on the web visit
>>>>>>> https://groups.google.com/d/msgid/simmer-devel/99e9da8e-bbb8-4333-8d92-ff240091dae4%40googlegroups.com.
>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Mohamed Kamal, R.Ph., CHRP
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "simmer-devel" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>>> an email to simmer-devel...@googlegroups.com.
>>>>>> To post to this group, send email to simmer...@googlegroups.com.
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/simmer-devel/CAGJu%2B0SdiONjj03iFckO0yAuqmV02SoWsgxtv3dLxyd%2Bq0KcYQ%40mail.gmail.com.
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to a topic in the
>>>>> Google Groups "simmer-devel" group.
>>>>> To unsubscribe from this topic, visit
>>>>> https://groups.google.com/d/topic/simmer-devel/sXcFXvUDD1w/unsubscribe.
>>>>> To unsubscribe from this group and all its topics, send an email to
>>>>> simmer-devel...@googlegroups.com.
>>>>> To post to this group, send email to simmer...@googlegroups.com.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/simmer-devel/CALEXWq3Z2HZ__Z%2Bgg3CKzVkdymXaSYMmzxP8yzcQHH4Wyu%3DYUQ%40mail.gmail.com.
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>>
>>>>
>>>> --
>>>> Mohamed Kamal, R.Ph., CHRP
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "simmer-devel" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to simmer-devel...@googlegroups.com.
>>>> To post to this group, send email to simmer...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/simmer-devel/CAGJu%2B0Q%2BOSPwk4tchrxGcMoN_Ypu8V-iHDWccgdOZRLyt1Epfw%40mail.gmail.com.
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>>
>>>
>>> --
>>> Iñaki Úcar
>>> http://www.enchufa2.es
>>> @Enchufa2
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "simmer-devel" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/simmer-devel/sXcFXvUDD1w/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> simmer-devel...@googlegroups.com.
> To post to this group, send email to simmer...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/simmer-devel/7db4c8b0-3bdb-4896-bed8-0f0024474cd0%40googlegroups.com.

Mohamed Kamal

unread,
Jun 9, 2016, 12:38:23 PM6/9/16
to simmer...@googlegroups.com
by the way, please ignore the very first percentages i sent in the very first post. the latest numbers are more accurate

Mohamed Kamal

unread,
Jun 10, 2016, 7:22:43 AM6/10/16
to simmer...@googlegroups.com
any feedback ?

Bart Smeets

unread,
Jun 10, 2016, 8:02:43 AM6/10/16
to simmer-devel
Can you explain why you want to label the beds in this case? If the first free bed will always be seized, won't the final results be the comparable to the output you have now?


Op donderdag 9 juni 2016 15:39:36 UTC+2 schreef Mohamed Kamal:
Experts

Mohamed Kamal

unread,
Jun 10, 2016, 8:08:15 AM6/10/16
to simmer...@googlegroups.com
I think I dont "need" to label beds, just asking if it is possible to do it.
So, do you think this model is OK ? I mean, if the percentages are matching reality, shall i depend on it to predict scenarios?
To unsubscribe from this group and all its topics, send an email to simmer-devel...@googlegroups.com.

To post to this group, send email to simmer...@googlegroups.com.


--
Mohamed Kamal, R.Ph., CHRP

--
You received this message because you are subscribed to the Google Groups "simmer-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simmer-devel...@googlegroups.com.
To post to this group, send email to simmer...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "simmer-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/simmer-devel/sXcFXvUDD1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to simmer-devel...@googlegroups.com.

To post to this group, send email to simmer...@googlegroups.com.


--
Mohamed Kamal, R.Ph., CHRP

--
You received this message because you are subscribed to the Google Groups "simmer-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simmer-devel...@googlegroups.com.
To post to this group, send email to simmer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/CAGJu%2B0Q%2BOSPwk4tchrxGcMoN_Ypu8V-iHDWccgdOZRLyt1Epfw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "simmer-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/simmer-devel/sXcFXvUDD1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to simmer-devel...@googlegroups.com.

To post to this group, send email to simmer...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Shawn Garbett

unread,
Jun 10, 2016, 10:38:13 AM6/10/16
to simmer...@googlegroups.com
On Fri, Jun 10, 2016 at 7:08 AM, Mohamed Kamal <mohamedk...@gmail.com> wrote:
So, do you think this model is OK ? I mean, if the percentages are matching reality, shall i depend on it to predict scenarios?

What do you mean matching reality? Model validation is important. Did you do a statistical prop test or ANOVA? If so, what were the results, etc? How much data do you have from reality?

Then if the model is validated for known parameters, to change those to areas outside observed usually results in extrapolation. It's important to be aware of the dangers of extrapolation. The changes made, may change external behaviors, or there may be factors that come into play that weren't part of the original model. With this cautionary note, it's still a powerful technique. Make sure that the final statistical method used is for computing predicted intervals and not confidence intervals.

---

Shawn Garbett
Vanderbilt Biostatistics

Iñaki Úcar

unread,
Jun 12, 2016, 7:56:46 AM6/12/16
to simmer-devel

To avoid a branch inside a branch inside a branch… I would simulate something like this:

patient <- create_trajectory() %>%
  seize("waiting_induction1", 1) %>%
  seize("bed", 1, priority=induction1) %>%
  release("waiting_induction1", 1) %>%
  timeout(induction1_timeout) %>%
  branch(induction1_prob_continue, c(T, F),
         create_trajectory() %>% release("bed"),
         create_trajectory() %>% release("bed")) %>%
  seize("waiting_induction2", 1) %>%
  seize("bed", 1, priority=induction2) %>%
  release("waiting_induction2", 1) %>%
  timeout(induction2_timeout) %>%
  ...

and so on, where “waiting_induction1”, “waiting_induction2”… are resources with infinite capacity allocated to count how many patients are waiting for each stage.


--
You received this message because you are subscribed to the Google Groups "simmer-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simmer-devel...@googlegroups.com.
To post to this group, send email to simmer...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

moko kamello

unread,
Jun 12, 2016, 8:01:19 AM6/12/16
to simmer...@googlegroups.com

Thanks a lot. Would you kindly advise me how to get waiting time data as vector. I can only get it as curve using function plot_evolution_arrival_times(env, "waiting_time")

You received this message because you are subscribed to a topic in the Google Groups "simmer-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/simmer-devel/sXcFXvUDD1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to simmer-devel...@googlegroups.com.

To post to this group, send email to simmer...@googlegroups.com.

moko kamello

unread,
Jun 12, 2016, 8:10:31 AM6/12/16
to simmer...@googlegroups.com
Is it possible to use the following to get the waiting time:
arrivals_no_resource<-get_mon_arrivals(env)
arrivals_no_resource$waiting<-arrivals_no_resource$end_time-arrivals_no_resource$start_time-arrivals_no_resource$activity_time

moko kamello

unread,
Jun 12, 2016, 8:17:01 AM6/12/16
to simmer...@googlegroups.com
Dear Experts, please allow me to ask one more question
what if the patient is discharged from the hospital for 5 days before re-admission. I don't want to count those 5 days as waiting time (because it is not). How is it possible to do it in simmer?

Iñaki Úcar

unread,
Jun 13, 2016, 5:49:10 PM6/13/16
to simmer-devel
Yes, that's the waiting time in general: end_time - start_time - activity_time.

But specifically in my example, the infinite resources waiting_induction1, waiting_induction2, etc., measure just your waiting time in queue. So the activity_time column from these resources is your waiting time.


For more options, visit https://groups.google.com/d/optout.

Iñaki Úcar

unread,
Jun 13, 2016, 5:52:59 PM6/13/16
to simmer-devel
what if the patient is discharged from the hospital for 5 days before re-admission. I don't want to count those 5 days as waiting time (because it is not). How is it possible to do it in simmer?

I don't know if I follow you. You mean between two stages? Then you can simply set a timeout for 5 days between stages, between the release from one stage and the seize from the next stage.


mokoka...@gmail.com

unread,
Jun 13, 2016, 7:08:54 PM6/13/16
to simmer-devel
Thanks a lot. 

mokoka...@gmail.com

unread,
Jun 15, 2016, 9:12:50 AM6/15/16
to simmer-devel
if i need to generate 10 patients at once, should i put the add_generator function in a loop

for (i in 1:10){
add_generator("newpatient", newpatient, function() rexp(1, 1/myIAT))
}

OR there is another solution?

Iñaki Úcar

unread,
Jun 15, 2016, 10:03:16 AM6/15/16
to simmer-devel

No, you shouldn’t. You need, instead of function() rexp(1, 1/myIAT), a new function returning one time rexp(1, 1/myIAT) and 9 times 0, one time rexp(1, 1/myIAT), 9 times 0, and so on.


--
You received this message because you are subscribed to the Google Groups "simmer-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simmer-devel...@googlegroups.com.
To post to this group, send email to simmer...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Mohamed Kamal

unread,
Jun 15, 2016, 10:09:50 AM6/15/16
to simmer...@googlegroups.com
hmmm, is it possible (when you have time) to show me an example.
You received this message because you are subscribed to a topic in the Google Groups "simmer-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/simmer-devel/sXcFXvUDD1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to simmer-devel...@googlegroups.com.

To post to this group, send email to simmer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/CALEXWq1Gnb6y1jnni0YT8nqaUnx96Ot7JA9QeUwAQ1E8EC9Wvg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--
Mohamed Kamal, R.Ph., CHRP

Shawn Garbett

unread,
Jun 15, 2016, 10:34:36 AM6/15/16
to simmer...@googlegroups.com
Brute force using a global (there's certainly a better way):


tenatatime_cnt <- 0
tenatatime <- function()
{
  if(tenatatime_cnt == 0)
  {
    tenatatime_cnt <<- 9
    rexp(1)
  }
  else
  {
    tenatatime_cnt <<- tenatatime_cnt - 1
    0
  }
}

env %>% add_generator("patient", traj, tenatatime)

Note this goes on forever now. 


For more options, visit https://groups.google.com/d/optout.



--
Shawn Garbett
615.397.8737

Iñaki Úcar

unread,
Jun 15, 2016, 12:15:10 PM6/15/16
to simmer-devel

Thanks Shawn. That does the trick.

However, this is easier with the current version (check out the master branch on GitHub), because the generation function can return more than one value at once (see #65), so now we can do the following:

add_generator("newpatient", newpatient, function() c(rexp(1, 1/myIAT), rep(0, 9)))


For more options, visit https://groups.google.com/d/optout.

moko kamello

unread,
Jun 15, 2016, 7:35:46 PM6/15/16
to simmer...@googlegroups.com
I don't know if it is my bad, but i get the following

add_generator("newpatient", newpatient, function() c(rexp(1, 1/myIAT),
rep(0, 9)))
Error: expecting a single value

Thanks Shawn and Iñaki
> https://groups.google.com/d/msgid/simmer-devel/CALEXWq0696it7s79KGtPzQqu-y8pYCwnQ6Xxzx8EGyrFkhR8mQ%40mail.gmail.com.

Iñaki Úcar

unread,
Jun 16, 2016, 2:20:34 AM6/16/16
to simmer-devel
I said "with the current version on GitHub". You have to install it.


For more options, visit https://groups.google.com/d/optout.

Mohamed Kamal

unread,
Jun 17, 2016, 8:55:42 AM6/17/16
to simmer...@googlegroups.com
what about if I need to simulate spread of infection ? Is there a way that a patient "infect" another patient (or more ). 

one idea is to ceate a resource "infected" with unlimited capacity for counting purpose, but his will not simulate the interaction of patient to patient.

any other ideas?

For more options, visit https://groups.google.com/d/optout.

moko kamello

unread,
Jun 17, 2016, 7:05:59 PM6/17/16
to simmer...@googlegroups.com

Iñaki Úcar

unread,
Jun 20, 2016, 4:34:18 AM6/20/16
to simmer-devel
2016-06-18 1:05 GMT+02:00 moko kamello <mokoka...@gmail.com>:
Is it possible that "waiting time" be negative values ?

No, it's not.

Iñaki

moko kamello

unread,
Jun 26, 2016, 12:53:16 AM6/26/16
to simmer...@googlegroups.com
I don't know if this is my bad: the waiting time is positive only if in case of get_mon_arrival(env, per_resources=F)
However, It gives me mixed positive and negative values in case of per_resource=T and I have absolutely no clue why this happens
Any Help ?

--
You received this message because you are subscribed to a topic in the Google Groups "simmer-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/simmer-devel/sXcFXvUDD1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to simmer-devel...@googlegroups.com.
To post to this group, send email to simmer...@googlegroups.com.
waiting_time_test.R
negative_waiting_1.png
positive_waiting_time.png

Iñaki Úcar

unread,
Jun 26, 2016, 3:12:23 AM6/26/16
to simmer-devel
It seems there's a bug in the development version. The version on CRAN gives correct results though. It would be great if you could reproduce this problem with a much simpler example. It would help me debug the issue.

--
You received this message because you are subscribed to the Google Groups "simmer-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simmer-devel...@googlegroups.com.

To post to this group, send email to simmer...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Iñaki Úcar

unread,
Jun 26, 2016, 3:28:54 AM6/26/16
to simmer-devel
Actually the current CRAN version (3.2.1) does NOT give correct results either, sorry. It's the release 3.1.2 which gives the correct results.

moko kamello

unread,
Jun 26, 2016, 3:33:20 AM6/26/16
to simmer...@googlegroups.com

Could you please send me a zip file to install it as I have no experience to install it from github

Iñaki Úcar

unread,
Jun 26, 2016, 3:39:28 AM6/26/16
to simmer-devel
You can download every release from the Releases page: https://github.com/r-simmer/simmer/releases


For more options, visit https://groups.google.com/d/optout.

moko kamello

unread,
Jun 26, 2016, 3:42:16 AM6/26/16
to simmer...@googlegroups.com

Iñaki Úcar

unread,
Jun 26, 2016, 4:00:56 AM6/26/16
to simmer-devel
I've opened an issue on GitHub. If anyone finds a smaller piece of code featuring this bug, please, post it there.


For more options, visit https://groups.google.com/d/optout.

moko kamello

unread,
Jun 26, 2016, 4:54:13 PM6/26/16
to simmer...@googlegroups.com
Is there any quick work around until this issue is resolved ?

Iñaki Úcar

unread,
Jun 26, 2016, 4:58:54 PM6/26/16
to simmer-devel

moko kamello

unread,
Jun 26, 2016, 9:45:51 PM6/26/16
to simmer...@googlegroups.com
Now, using the latest CRAN version, I think the error results from the cumulative sum of time within each branch, this will result in activity time to become greater and lead to -ve values. Just an opinion.

moko kamello

unread,
Jun 26, 2016, 10:10:29 PM6/26/16
to simmer...@googlegroups.com
Attached simpler example with cummulative time calculated for a branch
example_branch_cumm_time.R
Capture.PNG

moko kamello

unread,
Jun 27, 2016, 12:55:47 PM6/27/16
to simmer...@googlegroups.com

For a reason or another the only version working is the one on CRAN. Is there any snippet of script to prevent cumulative sum of timeout inside a branch

Iñaki Úcar

unread,
Jun 27, 2016, 1:53:29 PM6/27/16
to simmer-devel
The bug is already fixed. Check out the master branch on GitHub. The CRAN version has the bug and does NOT work properly.


For more options, visit https://groups.google.com/d/optout.

Iñaki Úcar

unread,
Jun 28, 2016, 5:19:40 AM6/28/16
to simmer-devel

BTW, in order to avoid so many nested branches in your model, you’ll be probably interested in the new activity called leave, which does exactly what you need: leave a trajectory with some probability.

moko kamello

unread,
Jun 28, 2016, 5:24:27 AM6/28/16
to simmer...@googlegroups.com

Iñaki Úcar

unread,
Jun 28, 2016, 5:26:11 AM6/28/16
to simmer-devel

moko kamello

unread,
Jun 28, 2016, 3:34:02 PM6/28/16
to simmer...@googlegroups.com
OK, I see. But I think that leave() cannot be used if I want the two branches to seize the resources at different priorities and timeouts for example ..

 branch(function() sample(c(1,2),size=1,replace=T,prob=c(0.2,0.8)), merge=c(T, T),
                                            create_trajectory("relapse") %>%
                                            seize("bed", amount = 1, priority = 1) %>%
                                            seize("relapse", amount = 1, priority = 1) %>%
                                            timeout(function() rnorm(1, 40, 2)) %>%
                                            release("bed", 1)
                                               ,

                                             create_trajectory("relapse_out") %>%
                                             seize("bed", amount = 1, priority = 9) %>%
                                             seize("relapse_out", amount = 1, priority = 1)  %>%
                                             timeout(function() rnorm(1, 10, 2)) %>%
                                             release("bed", 1)
                                             
                                      )

So, in such case there is no other option but to use branch inside a branch, right?

Iñaki Úcar

unread,
Jun 29, 2016, 8:01:57 AM6/29/16
to simmer-devel
I was talking about the points in your trajectory, at the end of each stage, where a patient may leave with some probability. The case you mention is different, of course.


For more options, visit https://groups.google.com/d/optout.

moko kamello

unread,
Jun 29, 2016, 8:08:34 AM6/29/16
to simmer...@googlegroups.com

Congratulations for version 3.3 btw

moko kamello

unread,
Jun 29, 2016, 11:32:26 PM6/29/16
to simmer...@googlegroups.com
in get_mon_resources(env, per_resource=T) i see only finished=TRUE. Is
there a way to get the finished=FALSE?

Iñaki Úcar

unread,
Jun 30, 2016, 5:41:28 AM6/30/16
to simmer-devel
  • get_mon_resources does NOT have a per_resource argument nor a finished column in the resulting data frame.
  • get_mon_arrivals does have a per_resource argument, but
    • per_resource=F (default) shows a finished column, and you’ll see TRUEs and FALSEs.
    • per_resource=T does NOT show a finished column.


For more options, visit https://groups.google.com/d/optout.

moko kamello

unread,
Jun 30, 2016, 10:47:24 AM6/30/16
to simmer...@googlegroups.com

Thanks, but I always have "TRUE" only. If for example 200 patients generated I only have 160-170 records with finished= "true" but zero records with finished= false

Iñaki Úcar

unread,
Jun 30, 2016, 11:03:43 AM6/30/16
to simmer-devel
That's because no one got rejected.


For more options, visit https://groups.google.com/d/optout.

moko kamello

unread,
Jun 30, 2016, 12:08:35 PM6/30/16
to simmer...@googlegroups.com

Sorry for bothering, how can a patient get rejected

Iñaki Úcar

unread,
Jun 30, 2016, 12:24:32 PM6/30/16
to simmer-devel
By trying to seize a resource with no space in queue or by using `leave` instead of `branch`. A `branch` is an alternative but perfectly valid trajectory.


For more options, visit https://groups.google.com/d/optout.

moko kamello

unread,
Jul 5, 2016, 5:27:37 PM7/5/16
to simmer...@googlegroups.com
"waiting time evolution" plot is plotted from the waiting time
calculated from the get_mon_arrivals(per_resource=FALSE), right?
> https://groups.google.com/d/msgid/simmer-devel/CALEXWq0k_ce12uJ0tPtyuss%3DTyFpHGk0SefSvj%3D%3DEufHNX343w%40mail.gmail.com.

Iñaki Úcar

unread,
Jul 6, 2016, 5:11:48 AM7/6/16
to simmer-devel
"waiting time evolution" plot is plotted from the waiting time
calculated from the get_mon_arrivals(per_resource=FALSE), right?

Yes, it is. You can check it by yourself: https://github.com/r-simmer/simmer/blob/master/R/plot.R#L117

Mohamed Kamal

unread,
Jul 6, 2016, 6:09:10 AM7/6/16
to simmer...@googlegroups.com
thanks a lot
--
You received this message because you are subscribed to a topic in the Google Groups "simmer-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/simmer-devel/sXcFXvUDD1w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to simmer-devel...@googlegroups.com.
To post to this group, send email to simmer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/CALEXWq2ikTVO6cXVH-12Yiy43HcQFrs8g0q9EMC35fL_y_D4uw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--
Mohamed Kamal, R.Ph., CHRP

Reply all
Reply to author
Forward
0 new messages