Keep in mind that the attributes facility is about storing values per arrival: each arrival has its own set of attributes. So a common name in set_attributes() corresponds not only to different attributes across trajectories, but also across arrivals in the same trajectory. Let me illustrate this with a simple example:
library(simmer)
set.seed(1234)
t <- create_trajectory() %>%
set_attribute("example", function() runif(1)) %>%
timeout(1) %>%
timeout(function(attr) { print(attr[["example"]]); 0 })
simmer() %>%
add_generator("arrival", t, at(0, 0)) %>%
run
#> [1] 0.1137034
#> [1] 0.6222994
I would like to remark this, because my feeling, from your description, is that you are trying to share an attribute for the whole simulation, with all the trajectories and all the arrivals. And this is not an attribute in the sense we define them in simmer. What you really need, if I understood well, is simply a global variable!
library(simmer)
set.seed(1234)
my_global <- NA
t0 <- create_trajectory() %>%
timeout(function() { print(my_global); 0 })
t1 <- create_trajectory() %>%
timeout(function() {
my_global <<- runif(1) # don't forget the double-assigment operator!
1 }) %>%
join(t0)
t2 <- create_trajectory() %>%
timeout(1) %>%
join(t0)
simmer() %>%
add_generator("t1_", t1, at(0)) %>%
add_generator("t2_", t2, at(0)) %>%
run
#> [1] 0.1137034
#> [1] 0.1137034
For globals, plain and simple R does the trick. The attributes facility was conceived to manage the hard work of keeping different values on a per-arrival basis. But you don’t need this at all in this case. And with this approach, you don’t need to call get_mon_attributes() either.
Regards,
Iñaki
--
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.
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/1810eb70-e5eb-4a69-bd42-d44b4ddd5b54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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/1810eb70-e5eb-4a69-bd42-d44b4ddd5b54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi InakiThanks a lot for your help. This is what I needed. I did not know you could use global variables inside simmer. However, the limitation of this is that,as far as am aware, if I use a global variables I will not be able to check its values throughout the period of simulations, at least not as easy as an attribute, which is something I need for some of those global variables.
custom_monitor<-function(){ results <- data.frame() function(time, value){ if(missing(value)){ return(results) } results<<-rbind(results, data.frame(time=time, value=value)) }}my_mon<-custom_monitor()
my_mon(5, "firstval")
my_mon(18, "secondval")
> my_mon()
time value
1 5 firstval
2 18 secondval--
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.
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/8c0b5bbc-42c4-4a09-abb3-d5fb96106ed3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Juan,Ok, I understand now. Then it could interesting to add an option to `set_attributes()` to define and monitor global attributes as well.In the meanwhile, you can implement a custom monitor as Bart suggested.Regards,Iñaki
2016-11-03 1:25 GMT+01:00 Juan Ossa-Moreno <js.os...@gmail.com>:
HI IñakiI meant that I will not be able to track the value of the variable throughout the simulation, as I would with an attribute. I meant that I would know the final value of the variable but I think I do not have the value of the variable at all times (e.g. t=1, t=2, t=3..........t=t) as I have with the attributes in the table get_mon_attributes. If am wrong please let me know so I can track those values.REgardsJuan
El jueves, 13 de octubre de 2016, 9:37:29 (UTC+10), Iñaki Úcar escribió:2016-10-12 23:55 GMT+02:00 Juan Ossa-Moreno <js.os...@gmail.com>:Hi InakiThanks a lot for your help. This is what I needed. I did not know you could use global variables inside simmer. However, the limitation of this is that,as far as am aware, if I use a global variables I will not be able to check its values throughout the period of simulations, at least not as easy as an attribute, which is something I need for some of those global variables.Why not? I'm using one in my last example, writing and reading it, as easy as an attribute.--
--
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/8c0b5bbc-42c4-4a09-abb3-d5fb96106ed3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Diego,
You should call your custom monitor each time you change the value, and always inside a function (otherwise, it’s not dynamically evaluated). For instance:
timeout(function() {
BlockBin <<- 1
BlockBin_rec(now(Project), BlockBin)
return(0)
}) %>%
Iñaki
To unsubscribe from this group and stop receiving emails from it, 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/f7ec47d5-1ff2-4a9b-ba96-96ee10dee7b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/f7ec47d5-1ff2-4a9b-ba96-96ee10dee7b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/ebeee06f-717d-40c7-8e5f-27d3c633f79b%40googlegroups.com.
If you call your monitor without any argument, BlockBin_rec(), it returns a data frame. :)
To unsubscribe from this group and stop receiving emails from it, 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/ebeee06f-717d-40c7-8e5f-27d3c633f79b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, 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/ebeee06f-717d-40c7-8e5f-27d3c633f79b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/CAHY4WHnO9V2s7hMk5V0Y%2BeZNqf2areDfd9MRP7dpghj2Xs7BEg%40mail.gmail.com.