metaRangePriorityQueue | R Documentation |
Creates a priority queue in form of an R6 class, that manages the correct process execution order.
<metaRangePriorityQueue>
A metaRangePriorityQueue object.
new()
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
execute_next_process()
Executes the next process in the queue. No reason to call this as user. The next process is executed automatically.
metaRangePriorityQueue$execute_next_process(verbose)
verbose
<logical>
Print timing and information or not.
<logical>
TRUE
if the next process has been executed,
FALSE
if not and 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)
enqueue()
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()
dequeue()
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_future_queue()
Sort the (future) queue based on the execution priority. This method is called automatically when a process is added to the queue.
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()
Update and reset the queue. This method is called automatically at the end of each time step.
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()
is_empty()
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())
get_queue()
Get 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()
get_future_queue()
Get 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_current_index()
Get the number / index of the next to be executed process.
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()
print()
Prints information about the queue to the console.
metaRangePriorityQueue$print()
<invisible self>
.
pr_queue <- metaRangePriorityQueue$new() pr_queue$print()
## ------------------------------------------------
## 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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.