Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplekit-ruby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sanchez, Paul
simplekit-ruby
Commits
4d452ee5
Commit
4d452ee5
authored
9 years ago
by
pjs
Browse files
Options
Downloads
Patches
Plain Diff
Tweaked SimpleKit documentation
parent
21e025a0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/simplekit.rb
+11
-8
11 additions, 8 deletions
lib/simplekit.rb
with
11 additions
and
8 deletions
lib/simplekit.rb
+
11
−
8
View file @
4d452ee5
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
# Clear
s
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment