Skip to content

Process priority queue

Creates a priority queue in form of an R6 class, that manages the correct process execution order.

Creates a new metaRangePriorityQueue object. Note: No reason to call this as user. The priority queue is created automatically when a simulation is created.

metaRangePriorityQueue$new()

<metaRangePriorityQueue> A metaRangePriorityQueue object.

# Only for illustration purposes.
pr_queue <- metaRangePriorityQueue$new()
pr_queue

Executes the next process in the queue. No reason to call this as user. The next process is executed automatically, when the previous process is finished.

metaRangePriorityQueue$execute_next_process(verbose)
  • verbose: <logical> Should timing and process information be printed when the process is executed?

<logical>``TRUE if the next process has been executed, FALSE if not, in which case the queue is empty.

# Only for illustration purposes.
pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$update()
pr_queue$execute_next_process(verbose = TRUE)

Add a process to the (future) queue. Users should only use this method if they added a process to the simulation via the add_process method of the simulation object with the argument queue = FALSE. Otherwise the process is added to the queue automatically.

metaRangePriorityQueue$enqueue(process)
  • process: <metaRangeProcess> A metaRangeProcess that should be added to the queue.

<boolean>``TRUE on success FALSE on failure.

pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$get_future_queue()

Remove a process from the (future) queue. Useful to remove a process from the queue if it is no longer needed. E.g. if a species went extinct.

metaRangePriorityQueue$dequeue(PID = NULL)
  • PID: <string> the ID of the process, that should be dequeued.

<boolean>``TRUE on success FALSE on failure.

pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$dequeue(pr$get_PID())
pr_queue$get_future_queue()

Sort the (future) queue based on the execution priority. This method is called automatically when a process is added to the queue. Note: No reason to call this as user.

metaRangePriorityQueue$sort_future_queue()

<invisible self>.

pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$sort_future_queue()
# at least no error

Update and reset the queue. This method is called automatically at the end of each time step. Note: No reason to call this as user.

metaRangePriorityQueue$update()

<invisible self>.

pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$update()
pr_queue$get_queue()

Check if the queue is empty.

metaRangePriorityQueue$is_empty()

<boolean>``TRUE if queue is empty FALSE otherwise.

pr_queue <- metaRangePriorityQueue$new()
stopifnot(pr_queue$is_empty())

Return the current queue.

metaRangePriorityQueue$get_queue()

<named int vector> The current queue.

pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$update()
pr_queue$get_queue()

Return the future queue.

metaRangePriorityQueue$get_future_queue()

<named int vector> The future queue.

pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$get_future_queue()

Get the index of the process that will be executed next.

metaRangePriorityQueue$get_current_index()

<integer> The index.

pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$update()
pr_queue$get_current_index()

Prints information about the queue to the console.

metaRangePriorityQueue$print()

<invisible self>.

pr_queue <- metaRangePriorityQueue$new()
pr_queue$print()

<metaRangePriorityQueue> A metaRangePriorityQueue object.

## ------------------------------------------------
## Method `metaRangePriorityQueue$new`
## ------------------------------------------------
# Only for illustration purposes.
pr_queue <- metaRangePriorityQueue$new()
pr_queue
## ------------------------------------------------
## Method `metaRangePriorityQueue$execute_next_process`
## ------------------------------------------------
# Only for illustration purposes.
pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$update()
pr_queue$execute_next_process(verbose = TRUE)
## ------------------------------------------------
## Method `metaRangePriorityQueue$enqueue`
## ------------------------------------------------
pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$get_future_queue()
## ------------------------------------------------
## Method `metaRangePriorityQueue$dequeue`
## ------------------------------------------------
pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$dequeue(pr$get_PID())
pr_queue$get_future_queue()
## ------------------------------------------------
## Method `metaRangePriorityQueue$sort_future_queue`
## ------------------------------------------------
pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$sort_future_queue()
# at least no error
## ------------------------------------------------
## Method `metaRangePriorityQueue$update`
## ------------------------------------------------
pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$update()
pr_queue$get_queue()
## ------------------------------------------------
## Method `metaRangePriorityQueue$is_empty`
## ------------------------------------------------
pr_queue <- metaRangePriorityQueue$new()
stopifnot(pr_queue$is_empty())
## ------------------------------------------------
## Method `metaRangePriorityQueue$get_queue`
## ------------------------------------------------
pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$update()
pr_queue$get_queue()
## ------------------------------------------------
## Method `metaRangePriorityQueue$get_future_queue`
## ------------------------------------------------
pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$get_future_queue()
## ------------------------------------------------
## Method `metaRangePriorityQueue$get_current_index`
## ------------------------------------------------
pr_queue <- metaRangePriorityQueue$new()
pr <- metaRangeProcess$new("A", "1", \() {message("test")}, 1, new.env())
pr_queue$enqueue(pr)
pr_queue$update()
pr_queue$get_current_index()
## ------------------------------------------------
## Method `metaRangePriorityQueue$print`
## ------------------------------------------------
pr_queue <- metaRangePriorityQueue$new()
pr_queue$print()