Skip to content
Snippets Groups Projects
Commit 4d452ee5 authored by pjs's avatar pjs
Browse files

Tweaked SimpleKit documentation

parent 21e025a0
No related branches found
No related tags found
No related merge requests found
require 'rubygems' if RUBY_VERSION =~ /^1\.8/ require 'rubygems' if RUBY_VERSION =~ /^1\.8/
require 'skewheap' 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> # +:model_time+, +:schedule+, and +:halt+ as mixins. You <b>MUST NOT</b>
# provide your own implementations of methods with these names in your model. # provide your own implementations of methods with these names in your model.
# All but +:run+ are delegated to the +EventScheduler+ class. # All but +:run+ are delegated to the +EventScheduler+ class.
module SimpleKit module SimpleKit
# The set of module methods to be passed to the EventScheduler # The set of module methods to be passed to the EventScheduler
# if not found in the model class.
DELEGATED_METHODS = [:model_time, :schedule, :halt] DELEGATED_METHODS = [:model_time, :schedule, :halt]
# Run your model by creating a new +EventScheduler+ and invoking its # Run your model by creating a new +EventScheduler+ and invoking its
...@@ -16,7 +19,8 @@ module SimpleKit ...@@ -16,7 +19,8 @@ module SimpleKit
@my_sim.run @my_sim.run
end 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) def method_missing(name, *args)
if DELEGATED_METHODS.include?(name) if DELEGATED_METHODS.include?(name)
@my_sim.send(name, *args) @my_sim.send(name, *args)
...@@ -55,11 +59,10 @@ module SimpleKit ...@@ -55,11 +59,10 @@ module SimpleKit
@event_list.push EventNotice.new(event, @model_time + delay, args) @event_list.push EventNotice.new(event, @model_time + delay, args)
end end
# Start execution of a model. The simulation +model_time+ is # Start execution of a model. The simulation +model_time+ is initialized
# initialized to zero and the model is initialized via the # to zero and the model is initialized via the mandatory +init+ method.
# mandatory +init+ method. Then enter a loop in which # Then loop while events are pending on the +event_list+. The event with
# the pending event with smallest time is extracted from the # the smallest time is popped, +model_time+ is updated to the event time,
# event list, the model_time is updated to the event time,
# and the event method is invoked. # and the event method is invoked.
def run def run
@model_time = 0.0 @model_time = 0.0
...@@ -70,7 +73,7 @@ module SimpleKit ...@@ -70,7 +73,7 @@ module SimpleKit
end end
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+. # Never schedule any new events after invoking +halt+.
def halt def halt
@event_list.clear @event_list.clear
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment