Class: DiscreteEvent::Simulation

Inherits:
EventQueue show all
Defined in:
lib/discrete_event/simulation.rb

Overview

A simulation, including an EventQueue, the current time, and various helpers.

See the README for an example.

Instance Attribute Summary

Attributes inherited from EventQueue

#events, #now

Instance Method Summary collapse

Methods inherited from EventQueue

#after, #at, #at_each, #cancel, #each, #every, #initialize, #next_event_time, #recur_after, #reset, #run_next, #run_to

Constructor Details

This class inherits a constructor from DiscreteEvent::EventQueue

Instance Method Details

#run { ... } ⇒ nil

Run (or continue, if there are existing events) the simulation until :stop is thrown, or there are no more events.

Yields:

  • after each event runs

Returns:

  • (nil)

26
27
28
29
30
31
32
33
34
35
# File 'lib/discrete_event/simulation.rb', line 26

def run
  start if @events.empty?
  catch :stop do
    if block_given?
      yield while run_next
    else
      nil while run_next
    end
  end
end

#startObject

This method is abstract.

Called by run when beginning a new simulation; you will probably want to override this.


17
# File 'lib/discrete_event/simulation.rb', line 17

def start; end