Skip to content

branch doesn't pass attrs to function #42

Closed

Description

@nacnudus

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

Activity

  1. added this to the v3.2.0 milestone on Mar 7, 2016
  2. Enchufa2 commented on Mar 7, 2016

    @Enchufa2
    Member

    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.

  3. Enchufa2 commented on Mar 14, 2016

    @Enchufa2
    Member

    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()
  4. added a commit that references this issue on Mar 14, 2016
    841d029
  5. nacnudus commented on Mar 15, 2016

    @nacnudus
    ContributorAuthor

    Brilliant, thank you. It works for me.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions