diff --git a/lib/simplekit.rb b/lib/simplekit.rb index 5572fbcf0102c68c8f2178be4099d2473af49bf6..07cdc7f04c22cb5c123a41f454131e1feb25d134 100644 --- a/lib/simplekit.rb +++ b/lib/simplekit.rb @@ -1,12 +1,15 @@ require 'rubygems' if RUBY_VERSION =~ /^1\.8/ require 'skewheap' -# Including SimpleKit in your simulation model gives you methods +:run+, +# The +SimpleKit+ module provides basic event scheduling capabilities. +# +# Including +SimpleKit+ in your simulation model gives you methods +:run+, # +:model_time+, +:schedule+, and +:halt+ as mixins. You <b>MUST NOT</b> # provide your own implementations of methods with these names in your model. # All but +:run+ are delegated to the +EventScheduler+ class. module SimpleKit # The set of module methods to be passed to the EventScheduler + # if not found in the model class. DELEGATED_METHODS = [:model_time, :schedule, :halt] # Run your model by creating a new +EventScheduler+ and invoking its @@ -16,7 +19,8 @@ module SimpleKit @my_sim.run end - # If a method doesn't exist in the model class, try to delegate it. + # If a method doesn't exist in the model class, try to delegate it + # to +EventScheduler+. def method_missing(name, *args) if DELEGATED_METHODS.include?(name) @my_sim.send(name, *args) @@ -55,11 +59,10 @@ module SimpleKit @event_list.push EventNotice.new(event, @model_time + delay, args) end - # Start execution of a model. The simulation +model_time+ is - # initialized to zero and the model is initialized via the - # mandatory +init+ method. Then enter a loop in which - # the pending event with smallest time is extracted from the - # event list, the model_time is updated to the event time, + # Start execution of a model. The simulation +model_time+ is initialized + # to zero and the model is initialized via the mandatory +init+ method. + # Then loop while events are pending on the +event_list+. The event with + # the smallest time is popped, +model_time+ is updated to the event time, # and the event method is invoked. def run @model_time = 0.0 @@ -70,7 +73,7 @@ module SimpleKit end end - # Clears the event list, which causes termination of the simulation. + # Clear the event list, which causes termination of the simulation. # Never schedule any new events after invoking +halt+. def halt @event_list.clear