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

Implement post.seize and reject subtrajectories in seize #49

Closed
Enchufa2 opened this Issue Apr 14, 2016 · 4 comments

Comments

Projects
None yet
1 participant
@Enchufa2
Member

Enchufa2 commented Apr 14, 2016

Many models require an arrival to do something if it gets rejected when trying to seize a resource. So we need something in between a seize and a branch: an ifseize activity would work similarly to the R function ifelse. For instance,

ifseize(traj, resource, amount = 1, retry = FALSE, merge = c(TRUE, TRUE),
           yes = NULL, 
           no = NULL,
           priority = 0, preemptible = 0, restart = FALSE)

Use case: a WiFi station trying to seize the wireless channel to transmit a frame:

frame <- create_trajectory() %>%
  timeout(backoff) %>%
  ifseize("channel", 1, retry=7, merge=c(T, T),
          yes = create_trajectory() %>%
            timeout(send_frame) %>%
            release("channel", 1),
          no = create_trajectory() %>%
            timeout(backoff))

@Bart6114, review this proposal, please.

@Enchufa2

This comment has been minimized.

Member

Enchufa2 commented Jun 4, 2016

By virtue of #56, retries can be implemented using rollback, so this argument can be suppressed.

@Enchufa2

This comment has been minimized.

Member

Enchufa2 commented Jun 4, 2016

Linking with #52, there should be a ifseize_selected too.

@Enchufa2

This comment has been minimized.

Member

Enchufa2 commented Jun 11, 2016

Following #57, the merge parameter must be called continue instead.

Enchufa2 added a commit that referenced this issue Jul 5, 2016

@Enchufa2 Enchufa2 changed the title from Implement ifseize activity to Implement post.seize and reject subtrajectories in seize Jul 5, 2016

@Enchufa2

This comment has been minimized.

Member

Enchufa2 commented Jul 5, 2016

#69 alleviates seize's syntax and simplifies things for this enhancement. Instead of defining new verbs, I've opted to add this new feature to the existing seize and seize_selected. This is their new signature:

seize(traj, resource, amount = 1, 
      continue = NULL, post.seize = NULL, reject = NULL)

seize_selected(traj, amount = 1, id = 0, 
               continue = NULL, post.seize = NULL, reject = NULL)

so that their default behaviour is the same. But now, we can execute a post.seize trajectory, that is, only if the resource is seized:

t <- create_trajectory() %>% 
  seize("dummy", 1, continue=FALSE, 
        post.seize = create_trajectory() %>% 
          timeout(2) %>%
          release("dummy", 1)) %>%
  timeout(1) # this is not executed in any case, as continue=FALSE

simmer() %>%
  add_resource("dummy", 1, 0) %>%
  add_generator("arrival", t, at(0, 1)) %>%
  run() %>% get_mon_arrivals()
#>       name start_time end_time activity_time finished replication
#> 1 arrival1          1        1             0    FALSE           1
#> 2 arrival0          0        2             2     TRUE           1

or a reject trajectory, that is, only if the resource cannot be seized, which is useful if we want to perform retries, for instance:

t <- create_trajectory() %>% 
  seize("dummy", 1, continue=FALSE, 
        reject = create_trajectory() %>% 
          timeout(1) %>%        # wait 
          rollback(2, Inf)) %>% # and then retry, until the resource is seized
  timeout(2) %>%
  release("dummy", 1)

simmer() %>%
  add_resource("dummy", 1, 0) %>%
  add_generator("arrival", t, at(0, 1)) %>%
  run() %>% get_mon_arrivals()
#>       name start_time end_time activity_time finished replication
#> 1 arrival0          0        2             2     TRUE           1
#> 2 arrival1          1        4             3     TRUE           1

or we can do both and then continue:

t <- create_trajectory() %>% 
  seize("dummy", 1, continue=c(TRUE, TRUE), 
        post.seize = create_trajectory() %>% 
          timeout(2) %>%
          release("dummy"),
        reject = create_trajectory() %>% 
          timeout(3)) %>%
  timeout(3) # all arrivals, rejected or not, execute this, as continue=c(TRUE, TRUE)

simmer() %>%
  add_resource("dummy", 1, 0) %>%
  add_generator("arrival", t, at(0, 1)) %>%
  run() %>% get_mon_arrivals()
#>       name start_time end_time activity_time finished replication
#> 1 arrival0          0        5             5     TRUE           1
#> 2 arrival1          1        7             6     TRUE           1

@Enchufa2 Enchufa2 closed this in 37bd021 Jul 5, 2016

@Enchufa2 Enchufa2 added this to the v3.4.0 milestone Jul 5, 2016

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