Skip to content

Move priority, preemptible and restart to add_generator #69

Closed

Description

@Enchufa2

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 ?

Activity

  1. Enchufa2 commented on Jul 3, 2016

    @Enchufa2
    MemberAuthor

    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`
  2. changed the title [-]Priority, preemptible and restart as attributes[/-] [+]Move priority, preemptible and restart to add_generator[/+] on Jul 3, 2016
  3. added a commit that references this issue on Jul 5, 2016
    97d91ae
  4. added this to the v3.4.0 milestone on Jul 5, 2016
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