Creates a discrete resource management system for discrete event simulations. This system manages a fixed number of identical resource units that can be blocked (used) by patients and maintains a priority queue for waiting patients.
Details
The returned environment has the following methods:
size()
: Returns the total capacityqueue_size()
: Returns the number of patients in queuen_free()
: Returns the number of free resource unitspatients_using()
: Vector of patient IDs currently using the resourcepatients_using_times()
: Vector of start times for patients using the resourcequeue_start_times()
: Vector of queue start times parallel to queue orderqueue_priorities()
: Vector of priorities parallel to queue orderqueue_info(n)
: Data.frame with patient_id, priority, start_time for queueis_patient_in_queue(patient_id)
: Check if patient is in queueis_patient_using(patient_id)
: Check if patient is using resourceattempt_block(patient_id, priority, start_time)
: Attempt to block a resource unitattempt_free(patient_id, remove_all)
: Free a resource unitattempt_free_if_using(patient_id, remove_all)
: Free only if patient is usingnext_patient_in_line(n)
: Get next n patients in queuemodify_priority(patient_id, new_priority)
: Modify patient priority in queueadd_resource(n)
: Add n resource units to total capacityremove_resource(n, current_time)
: Remove n resource units from total capacity
Examples
# Create a resource with 3 units
beds <- resource_discrete(3)
# Check initial state
beds$size() # 3
#> [1] 3
beds$n_free() # 3
#> [1] 3
beds$queue_size() # 0
#> [1] 0
# Block resources
i <- 101; curtime <- 0.0
beds$attempt_block() # Uses i and curtime from environment
#> [1] TRUE
# Or explicitly
beds$attempt_block(patient_id = 102, priority = 1, start_time = 1.0)
#> [1] TRUE
# Check patient status
beds$is_patient_using(101) # TRUE
#> [1] TRUE
beds$is_patient_in_queue(102) # FALSE
#> [1] FALSE