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 '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
......
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