Class: QueueSystem::ServiceQueue
- Inherits:
-
Object
- Object
- QueueSystem::ServiceQueue
- Defined in:
- lib/queue_system/service_queue.rb
Instance Attribute Summary collapse
-
#customers ⇒ Object
readonly
Returns the value of attribute customers.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
-
#initialize ⇒ ServiceQueue
constructor
A new instance of ServiceQueue.
- #simulate(duration:, arrival_rate:) ⇒ Object
Constructor Details
#initialize ⇒ ServiceQueue
Returns a new instance of ServiceQueue.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/queue_system/service_queue.rb', line 5 def initialize @customers = [] @current_time = 0 @stats = { total_customers: 0, avg_wait_time: 0, avg_system_time: 0, server_utilization: 0 } end |
Instance Attribute Details
#customers ⇒ Object (readonly)
Returns the value of attribute customers.
3 4 5 |
# File 'lib/queue_system/service_queue.rb', line 3 def customers @customers end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
3 4 5 |
# File 'lib/queue_system/service_queue.rb', line 3 def stats @stats end |
Instance Method Details
#simulate(duration:, arrival_rate:) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/queue_system/service_queue.rb', line 16 def simulate(duration:, arrival_rate:) server_busy_until = 0 while @current_time < duration if rand < arrival_rate customer = Customer.new(@current_time) process_customer(customer, server_busy_until) server_busy_until = calculate_server_busy_time(customer, server_busy_until) @customers << customer end @current_time += 1 end calculate_statistics(duration) end |