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

branch doesn't pass attrs to function #42

Closed
nacnudus opened this Issue Mar 7, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@nacnudus
Contributor

nacnudus commented Mar 7, 2016

This might be a feature request rather than a bug. It would be handy to branch depending on attributes.

library(simmer)

t1 <- create_trajectory("trajectory with a branch") %>%
  # Decide whether to branch or not, store in attribute
  set_attribute("branch", function() sample(1:2, 1)) %>%
  seize("server", 1) %>%
  # Branch or not depending on the attribute
  branch(function(attrs) attrs[["branch"]], merge=c(T, F), 
    create_trajectory("branch1") %>%
      timeout(function() 1),
    create_trajectory("branch2") %>%
      timeout(function() rexp(1, 3)) %>%
      release("server", 1)
  ) %>%
  release("server", 1)

env<-
  simmer() %>%
  add_resource("server", 1) %>%
  add_generator("patient", t1, at(0), mon = 2) %>%
  run()

# Error in eval(expr, envir, enclos) : 
#   argument "attrs" is missing, with no default

@Enchufa2 Enchufa2 added the enhancement label Mar 7, 2016

@Enchufa2 Enchufa2 added this to the v3.2.0 milestone Mar 7, 2016

@Enchufa2

This comment has been minimized.

Member

Enchufa2 commented Mar 7, 2016

Indeed. We didn't realise that the branch is the only activity without this functionality right now. Thanks for the report. I'll program this feature for the next release.

@Enchufa2

This comment has been minimized.

Member

Enchufa2 commented Mar 14, 2016

Feature implemented in the dev-main branch. You can try it out with the following code:

library(simmer)

t1 <- create_trajectory("trajectory with a branch") %>%
  # Decide whether to branch or not, store in attribute
  set_attribute("branch", function() sample(1:2, 1)) %>%
  # Branch or not depending on the attribute
  branch(function(attrs) attrs[["branch"]], merge=c(T, T), 
    create_trajectory("branch1") %>%
     timeout(function() { print("hi, I'm the first branch"); 0 }),
    create_trajectory("branch2") %>%
     timeout(function() { print("hi, I'm the second branch"); 0 })
  ) %>%
  rollback(2, 10)

env <- simmer() %>%
  add_generator("patient", t1, at(0)) %>%
  run()
@nacnudus

This comment has been minimized.

Contributor

nacnudus commented Mar 15, 2016

Brilliant, thank you. It works for me.

@Enchufa2 Enchufa2 closed this in 841d029 Apr 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment