Skip to content
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

Fix timeout priority #229

Merged
merged 3 commits into from
Apr 10, 2020
Merged

Fix timeout priority #229

merged 3 commits into from
Apr 10, 2020

Conversation

Enchufa2
Copy link
Member

The execution priority for timeout activities has been set to PRIORITY_MIN, which should have been always the case. #228 and this fix enable custom service priority implementations with the help of renege_if and set_prioritization, e.g.:

env <- simmer()

custom <- trajectory() %>%
  set_attribute("arrival time", function() now(env)) %>%
  renege_if(
    "recompute priority",
    out = trajectory() %>%
      # e.g., increase priority if wait_time < 3
      set_prioritization(function() {
        if (now(env) - get_attribute(env, "arrival time") < 3)
          c(1, NA, NA)     # only change the priority
        else c(NA, NA, NA) # don't change anything
      }, mod="+") %>%
      # go 2 steps back to renege_if
      rollback(2)) %>%
  seize("resource") %>%
  renege_abort() %>%
  log_("processing") %>%
  timeout(5) %>%
  # trigger this before releasing the resource
  send("recompute priority") %>%
  timeout(0) %>%
  release("resource")

env %>%
  add_resource("resource") %>%
  add_generator("dummy", custom, at(0:4)) %>%
  run() %>% invisible()
#> 0: dummy0: processing
#> 5: dummy3: processing
#> 10: dummy4: processing
#> 15: dummy1: processing
#> 20: dummy2: processing

This example has been included in the "Queueing systems" vignette, and applies to cases such as this and #226.

@codecov
Copy link

codecov bot commented Apr 10, 2020

Codecov Report

Merging #229 into master will not change coverage by %.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #229   +/-   ##
=======================================
  Coverage   99.74%   99.74%           
=======================================
  Files          46       46           
  Lines        2791     2791           
=======================================
  Hits         2784     2784           
  Misses          7        7           
Impacted Files Coverage Δ
inst/include/simmer/activity/timeout.h 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 97ecbf2...a06867c. Read the comment docs.

@Enchufa2 Enchufa2 merged commit ecebca7 into master Apr 10, 2020
@Enchufa2 Enchufa2 deleted the fix/timeout-priority branch April 10, 2020 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant