-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add attributes to arrivals #16
Comments
I'm a big proponent of this. Ideally the
ps. the |
To kick this off, a very preliminary implementation can be found in e3581ba (dev-bart branch). Check the bottom of the __working_file.R for a test run. Haven't check the impact performance wise (which I fear for a bit) |
I set aside some time tonight for closing #22, because it required little effort, but I probably won't have time to spend in this issue until not this weekend but the next. |
Worked on it a bit more (42d8e37), this is now possible: t0 <- create_trajectory() %>%
set_attribute("health", function() sample(40:80,1)) %>%
set_attribute("nurses_to_seize",
function(attrs){
if(attrs[["health"]]<50) 2
else 1
}, provide_attrs = TRUE) %>%
seize("nurse",
function(attrs){
attrs[["nurses_to_seize"]]
}, provide_attrs = T) %>%
timeout(function(attrs){(100 - attrs[["health"]])},
provide_attrs = T) %>%
set_attribute("health",
function(attrs){
min(attrs[["health"]] + sample(attrs[["health"]]:100, 1), 100)},
provide_attrs=TRUE) %>%
release("nurse",
function(attrs){
attrs[["nurses_to_seize"]]
}, provide_attrs = T) %>%
## some other functionality
## simply print the attrs using a 0 timeout
timeout(function(attrs){print(attrs); 0}, provide_attrs=T) %>%
timeout(function() 0) %>% # if provide_attrs=F no attrs are passed and minimal overhead is incurred
timeout(0) # doesn't have to be a function (will be converted to one)
env<-simmer() %>%
add_generator("test", t0, at(seq(0,1000,200))) %>%
add_resource("nurse", 2) %>%
run() Passing the attributes incurs minimal overhead (because its optional). However, I've altered the Have a look at it when you have some time (no rush :)) |
Looks great! One question after a quick glance: why is the member |
And it would be great to benchmark the overhead of providing the attributes to decide whether the |
No specific reason why it is a pointer; I quickly started out that way and didn't look back. So, what I can do is test if a supplied function has a parameter and only if it has one set the Will work some more on it later |
|
So the above example is now simply:
|
I've just discovered the inline comments inside commits. 😄 I've dropped some comments there. And, apart from that, have you thought about how to monitor the attributes (where and how to retrieve the time series of values)? |
Thanks for the comments, I've pushed another commit in response to them. With regards to monitoring the attributes, do they have to be monitored? Or would it be enough to simply be able to extract the values as they are at the moment the simulation stops. (At the moment) this would be enough for my use-cases, and can be implemented quite easily. I.e. if you want to store something along the way, you can simply store it in an (extra) attribute that you don't change after that. What do you think? |
I asked because I haven't thought about it. Since the programmer can monitor these attributes, we may put this feature in standby for now. But if we come up with use cases that make a heavy use of attribute statistics, we should implement it inside the C++ core in order to do it efficiently. |
I've made some changes (check b23471b, please) in order to allow numeric input values into |
Nice one!! Too bad for the "gc" initialization, but I don't see an easy way around this (without making the code less readable) |
Yeap, it's a dirty trick. It doesn't compile if you don't initialise those functions. We need to figure out if there is an alternative, a NULL function or something. |
Comprehensive attribute statistics gathering added (check ba07e23, please). Let's suppose a simple trajectory: t0 <- create_trajectory() %>% set_attribute("dummy", 1) These statistics are optional, so if you do the following: env <- simmer() %>%
add_generator("test", t0, at(seq(0,1000,200))) %>%
run()
attributes <- env %>% get_mon_attributes()
head(attributes)
#> [1] time name key value
#> <0 rows> (or 0-length row.names) then env <- simmer() %>%
add_generator("test", t0, at(seq(0,1000,200)), mon=2) %>%
run()
attributes <- env %>% get_mon_attributes()
head(attributes)
#> time name key value
#> 1 0 test0 dummy 1
#> 2 200 test1 dummy 1
#> 3 400 test2 dummy 1
#> 4 600 test3 dummy 1
#> 5 800 test4 dummy 1 More unit tests are needed to cover the new functionalities and probably a |
nice addition 👍 |
Merge latest developments (originating from #16) into master
Note: the dirty "gc" initialization is gone with ba2b5fa. 👍 |
Probably, it is more efficient (and more easy to use) to integrate this attributes in the C++ core. Use case provided by @bart6114:
Possibilities:
The text was updated successfully, but these errors were encountered: