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
44abdf4d
Commit
44abdf4d
authored
6 years ago
by
pjs
Browse files
Options
Downloads
Patches
Plain Diff
Added sptf.rb demo
parent
6c5300b7
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
demos/sptf.rb
+12
-15
12 additions, 15 deletions
demos/sptf.rb
with
12 additions
and
15 deletions
demos/sptf.rb
+
12
−
15
View file @
44abdf4d
#!/usr/bin/env ruby
#!/usr/bin/env ruby
require_relative
'../lib/simplekit'
require_relative
'../lib/simplekit'
require_relative
'../lib/priority_queue'
# Customer class to store arrival times and processing times.
class
Customer
attr_reader
:arrival_time
,
:processing_time
def
initialize
(
arrival
,
processing
)
@arrival_time
=
arrival
@processing_time
=
processing
end
# Create a Customer Struct that will store arrival times and processing times.
Customer
=
Struct
.
new
(
:arrival_time
,
:processing_time
)
do
include
Comparable
include
Comparable
# rank customers by their processing times, smallest first.
def
<
=>
(
other
)
def
<
=>
(
other
)
processing_time
<=>
other
.
processing_time
processing_time
<=>
other
.
processing_time
end
end
...
@@ -41,6 +34,7 @@ class SPTF
...
@@ -41,6 +34,7 @@ class SPTF
@numAvailableServers
=
@maxServers
@numAvailableServers
=
@maxServers
@q
=
PriorityQueue
.
new
@q
=
PriorityQueue
.
new
schedule
(
:arrival
,
0.0
)
schedule
(
:arrival
,
0.0
)
schedule
(
:close_doors
,
@closeTime
)
end
end
...
@@ -69,21 +63,24 @@ class SPTF
...
@@ -69,21 +63,24 @@ class SPTF
# the desired closing time, halt the simulation.
# the desired closing time, halt the simulation.
def
endService
def
endService
@numAvailableServers
+=
1
@numAvailableServers
+=
1
if
(
@q
.
empty?
)
unless
@q
.
empty?
halt
if
model_time
>=
@closeTime
else
schedule
(
:beginService
,
0.0
)
schedule
(
:beginService
,
0.0
)
end
end
end
end
# Commence shutdown by denying the next :arrival
def
close_doors
cancel
:arrival
end
# Exponential random variate generator.
# Exponential random variate generator.
# param: rate - The rate (= 1 / mean) of the distribution.
# param: rate - The rate (= 1 / mean) of the distribution.
# returns: A realization of the specified distribution.
# returns: A realization of the specified distribution.
def
exponential
(
rate
)
def
exponential
(
rate
)
-
Math
.
log
(
rand
)
/
rate
-
Math
.
log
(
rand
)
/
rate
end
end
end
end
# Instantiate an SPTF object with a particular parameterization and run it.
# Instantiate an SPTF object with a particular parameterization and run it.
SPTF
.
new
(
4.5
,
1.0
,
5
,
100.0
).
run
srand
(
9876543
)
# set seed for repeatability
SPTF
.
new
(
6
,
1.0
,
5
,
20.0
).
run
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