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
b3eff1c1
Commit
b3eff1c1
authored
10 years ago
by
pjs
Browse files
Options
Downloads
Patches
Plain Diff
lint-based cleanup
parent
502d7e09
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
-11
11 additions, 11 deletions
lib/simplekit.rb
with
11 additions
and
11 deletions
lib/simplekit.rb
+
11
−
11
View file @
b3eff1c1
require
'rubygems'
require
'rubygems'
if
RUBY_VERSION
=~
/^1\.8/
require
'skewheap'
require
'skewheap'
# Including SimpleKit in your simulation model gives you methods +:run+,
# Including SimpleKit in your simulation model gives you methods +:run+,
...
@@ -12,19 +12,19 @@ module SimpleKit
...
@@ -12,19 +12,19 @@ module SimpleKit
# Run your model by creating a new +EventScheduler+ and invoking its
# Run your model by creating a new +EventScheduler+ and invoking its
# +run+ method.
# +run+ method.
def
run
def
run
@my
S
im
=
EventScheduler
.
new
(
self
)
@my
_s
im
=
EventScheduler
.
new
(
self
)
@my
S
im
.
run
@my
_s
im
.
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.
def
method_missing
(
name
,
*
args
)
def
method_missing
(
name
,
*
args
)
if
DELEGATED_METHODS
.
include?
(
name
)
if
DELEGATED_METHODS
.
include?
(
name
)
@my
S
im
.
send
(
name
,
*
args
)
@my
_s
im
.
send
(
name
,
*
args
)
else
else
super
super
end
end
end
end
# Class +EventScheduler+ provides the computation engine for a discrete
# Class +EventScheduler+ provides the computation engine for a discrete
# event simulation model. It uses the +SkewHeap+ RubyGem as a priority
# event simulation model. It uses the +SkewHeap+ RubyGem as a priority
# queue implementation for the pending events list.
# queue implementation for the pending events list.
...
@@ -51,7 +51,7 @@ module SimpleKit
...
@@ -51,7 +51,7 @@ module SimpleKit
# - +args+ -> an optional list of arguments to pass to the event
# - +args+ -> an optional list of arguments to pass to the event
# at invocation time.
# at invocation time.
def
schedule
(
event
,
delay
,
*
args
)
def
schedule
(
event
,
delay
,
*
args
)
r
ai
se
"
Model scheduled event with negative delay.
"
if
(
delay
<
0
)
f
ai
l
'
Model scheduled event with negative delay.
'
if
delay
<
0
@event_list
.
push
EventNotice
.
new
(
event
,
@model_time
+
delay
,
*
args
)
@event_list
.
push
EventNotice
.
new
(
event
,
@model_time
+
delay
,
*
args
)
end
end
...
@@ -64,7 +64,7 @@ module SimpleKit
...
@@ -64,7 +64,7 @@ module SimpleKit
def
run
def
run
@model_time
=
0.0
@model_time
=
0.0
@user_model
.
init
@user_model
.
init
while
(
current_event
=
@event_list
.
pop
)
do
while
(
current_event
=
@event_list
.
pop
)
@model_time
=
current_event
.
time
@model_time
=
current_event
.
time
@user_model
.
send
(
current_event
.
event
,
*
current_event
.
args
)
@user_model
.
send
(
current_event
.
event
,
*
current_event
.
args
)
end
end
...
@@ -77,23 +77,23 @@ module SimpleKit
...
@@ -77,23 +77,23 @@ module SimpleKit
end
end
end
end
private
# This is a private helper class for the EventScheduler class.
# This is a private helper class for the EventScheduler class.
# Users should never try to access anything in this class directly.
# Users should never try to access anything in this class directly.
private
class
EventNotice
class
EventNotice
include
Comparable
include
Comparable
attr_reader
:event
,
:time
,
:args
attr_reader
:event
,
:time
,
:args
def
initialize
(
event
,
time
,
*
args
)
def
initialize
(
event
,
time
,
*
args
)
@event
=
event
@event
=
event
@time
=
time
@time
=
time
@args
=
args
@args
=
args
end
end
def
<
=>
(
other
)
def
<
=>
(
other
)
time
<=>
other
.
time
time
<=>
other
.
time
end
end
end
end
end
end
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