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

Move priority, preemptible and restart to add_generator #69

Closed
Enchufa2 opened this Issue Jul 1, 2016 · 1 comment

Comments

Projects
None yet
1 participant
@Enchufa2
Member

Enchufa2 commented Jul 1, 2016

This would have several advantages:

  • More natural interpretation as attributes of an arrival, rather than attributes of a seize.
  • Alleviate seize's complex syntax.
  • Same flexibility and performance with set_attribute and static values, and even more flexibility with the possibility of passing functions to set_attribute.

By default, all arrivals would be generated with the same default values, so

t <- create_trajectory() %>%
  timeout(function(attr) cat(attr["priority"], attr["preemptible"], attr["restart"]))

should print 0 0 0. Maybe this would be a bit opaque, so priority=0, preemptible=priority, restart=FALSE could be added to add_generator to define these initial values for all the arrivals.

Thus, a trajectory like

t <- create_trajectory() %>%
  seize("dummy", 1, priority=3, preemptible=10, restart=TRUE) %>%
  timeout(1) %>%
  release("dummy", 1)

would become

t <- create_trajectory() %>%
  set_attribute("priority", 3) %>%
  set_attribute("preemptible", 10) %>%
  set_attribute("restart", TRUE) %>%
  seize("dummy", 1) %>%
  timeout(1) %>%
  release("dummy", 1)

Note this new possibility:

t <- create_trajectory() %>%
  seize("dummy", 1) %>%
  timeout(0.5) %>%
  set_attribute("priority", 3) %>%
  timeout(0.5) %>%
  release("dummy", 1)

Priorities could change while holding the resource: even more flexibility! What do you think, @Bart6114 ?

@Enchufa2 Enchufa2 added the enhancement label Jul 1, 2016

@Enchufa2

This comment has been minimized.

Member

Enchufa2 commented Jul 3, 2016

There were some issues with the initial plan. priority must be equal or greater than 0, and preemptible must be equal or greater than priority, but always checking the key of the attribute being set in order to enforce these limits is too expensive, so I've taken another approach.

There is an implementation of this in the dev-main branch. These, let's say, special attributes, priority, preemptible and restart, are stored apart from the attributes and they have a special verb to modify them: set_prioritization(). You can define the same static prioritization for all the arrivals belonging to certain generator:

t <- create_trajectory() %>%
  seize("dummy", 1) %>%
  timeout(1) %>%
  release("dummy", 1)

simmer() %>%
  add_resource("dummy", 1, preemptive=TRUE) %>%
  add_generator("noprior", t, at(0)) %>%
  add_generator("prior", t, at(0.5), priority=3, preemptible=10, restart=TRUE) %>%
  run() %>%
  get_mon_arrivals()
#>       name start_time end_time activity_time finished replication
#> 1 noprior0        0.0      2.0             1     TRUE           1
#> 2   prior0        0.5      1.5             1     TRUE           1

or you can define this prioritization dynamically inside the trajectory:

t_noprior <- create_trajectory() %>%
  seize("dummy", 1) %>%
  timeout(1) %>%
  release("dummy", 1)
t_prior <- create_trajectory() %>%
  set_prioritization(c(3, 10, TRUE)) %>%
  # set_prioritization(function() c(3, 10, TRUE)) %>%
  seize("dummy", 1) %>%
  timeout(1) %>%
  release("dummy", 1)

simmer() %>%
  add_resource("dummy", 1, preemptive=TRUE) %>%
  add_generator("noprior", t_noprior, at(0)) %>%
  add_generator("prior", t_prior, at(0.5)) %>%
  run() %>%
  get_mon_arrivals()
#>       name start_time end_time activity_time finished replication
#> 1 noprior0        0.0      2.0             1     TRUE           1
#> 2   prior0        0.5      1.5             1     TRUE           1

Of course, if you try to set the prioritization in the seize, a warning is shown:

t <- create_trajectory() %>%
  seize("dummy", 1, priority=3, preemptible=10, restart=TRUE) %>%
  timeout(1) %>%
  release("dummy", 1)
#> Warning messages:
#> 1: In seize(., "dummy", 1, priority = 3, preemptible = 10, restart = TRUE) :
#>   unused argument `priority` has been moved to `add_generator`
#> 2: In seize(., "dummy", 1, priority = 3, preemptible = 10, restart = TRUE) :
#>   unused argument `preemptible` has been moved to `add_generator`
#> 3: In seize(., "dummy", 1, priority = 3, preemptible = 10, restart = TRUE) :
#>   unused argument `restart` has been moved to `add_generator`

@Enchufa2 Enchufa2 changed the title from Priority, preemptible and restart as attributes to Move priority, preemptible and restart to add_generator Jul 3, 2016

@Enchufa2 Enchufa2 closed this in 97d91ae 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