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
1a2f1a30
Commit
1a2f1a30
authored
8 years ago
by
pjs
Browse files
Options
Downloads
Patches
Plain Diff
convert camelcase to snakecase
parent
52800707
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
demos/MMk.rb
+29
-31
29 additions, 31 deletions
demos/MMk.rb
with
29 additions
and
31 deletions
demos/MMk.rb
+
29
−
31
View file @
1a2f1a30
...
@@ -9,52 +9,51 @@ class MMk
...
@@ -9,52 +9,51 @@ class MMk
include
SimpleKit
include
SimpleKit
# Constructor - initializes the model parameters.
# Constructor - initializes the model parameters.
# param: arrival
R
ate - The rate at which customers arrive to the system.
# param: arrival
_r
ate - The rate at which customers arrive to the system.
# param: service
R
ate - The rate at which individual servers serve.
# param: service
_r
ate - The rate at which individual servers serve.
# param: max
S
ervers - The total number of servers in the system.
# param: max
_s
ervers - The total number of servers in the system.
def
initialize
(
arrival
R
ate
,
service
R
ate
,
max
S
ervers
)
def
initialize
(
arrival
_r
ate
,
service
_r
ate
,
max
_s
ervers
)
@arrival
R
ate
=
arrival
R
ate
@arrival
_r
ate
=
arrival
_r
ate
@service
R
ate
=
service
R
ate
@service
_r
ate
=
service
_r
ate
@max
S
ervers
=
max
S
ervers
@max
_s
ervers
=
max
_s
ervers
end
end
# Initialize the model state and schedule any necessary events.
# Initialize the model state and schedule any necessary events.
# Note that this particular model will terminate based on
# Note that this particular model will terminate based on
# time by scheduling a halt 100 time units in the future.
# time by scheduling a halt 100 time units in the future.
def
init
def
init
@num
A
vailable
S
ervers
=
@max
S
ervers
@num
_a
vailable
_s
ervers
=
@max
_s
ervers
@q
L
ength
=
0
@q
_l
ength
=
0
schedule
(
:arrival
,
0.0
)
schedule
(
:arrival
,
0.0
)
schedule
(
:halt
,
100.0
)
schedule
(
:halt
,
100.0
)
dump
S
tate
(
"
init
"
)
dump
_s
tate
(
'
init
'
)
end
end
# An arrival event increments the queue length, schedules the next
# An arrival event increments the queue length, schedules the next
# arrival, and schedules a begin
S
ervice event if a server is available.
# arrival, and schedules a begin
_s
ervice event if a server is available.
def
arrival
def
arrival
@q
L
ength
+=
1
@q
_l
ength
+=
1
schedule
(
:arrival
,
exponential
(
@arrival
R
ate
))
schedule
(
:arrival
,
exponential
(
@arrival
_r
ate
))
schedule
(
:begin
S
ervice
,
0.0
)
if
(
@num
A
vailable
S
ervers
>
0
)
schedule
(
:begin
_s
ervice
,
0.0
)
if
@num
_a
vailable
_s
ervers
>
0
dump
S
tate
(
"A
rrival
"
)
dump
_s
tate
(
'a
rrival
'
)
end
end
# Start service for the first customer in line, removing that
# Start service for the first customer in line, removing that
# customer from the queue and utilizing one of the available servers.
# customer from the queue and utilizing one of the available servers.
# An end
S
ervice will be scheduled.
# An end
_s
ervice will be scheduled.
def
begin
S
ervice
def
begin
_s
ervice
@q
L
ength
-=
1
@q
_l
ength
-=
1
@num
A
vailable
S
ervers
-=
1
@num
_a
vailable
_s
ervers
-=
1
schedule
(
:end
S
ervice
,
exponential
(
@service
R
ate
))
schedule
(
:end
_s
ervice
,
exponential
(
@service
_r
ate
))
dump
S
tate
(
"B
egin
S
vc
"
)
dump
_s
tate
(
'b
egin
s
vc
'
)
end
end
# Frees up an available server, and schedules a begin
S
ervice if
# Frees up an available server, and schedules a begin
_s
ervice if
# anybody is waiting in line.
# anybody is waiting in line.
def
end
S
ervice
def
end
_s
ervice
@num
A
vailable
S
ervers
+=
1
@num
_a
vailable
_s
ervers
+=
1
schedule
(
:begin
S
ervice
,
0.0
)
if
(
@q
L
ength
>
0
)
schedule
(
:begin
_s
ervice
,
0.0
)
if
@q
_l
ength
>
0
dump
S
tate
(
"E
nd
S
vc
"
)
dump
_s
tate
(
'e
nd
s
vc
'
)
end
end
# Exponential random variate generator.
# Exponential random variate generator.
...
@@ -67,13 +66,12 @@ class MMk
...
@@ -67,13 +66,12 @@ class MMk
# A report mechanism which dumps the time, current event, and values
# A report mechanism which dumps the time, current event, and values
# of the state variables to the console.
# of the state variables to the console.
# param: event - The name of the event which invoked this method.
# param: event - The name of the event which invoked this method.
def
dump
S
tate
(
event
)
def
dump
_s
tate
(
event
)
printf
"Time: %8.3f
\t
%10s - Q: %d
\t
Servers Available: %d
\n
"
,
printf
"Time: %8.3f
\t
%10s - Q: %d
\t
Servers Available: %d
\n
"
,
model_time
,
event
,
@q
L
ength
,
@num
A
vailable
S
ervers
model_time
,
event
,
@q
_l
ength
,
@num
_a
vailable
_s
ervers
end
end
end
end
# Instantiate an MMk object with a particular parameterization and run it.
# Instantiate an MMk object with a particular parameterization and run it.
srand
7654321
srand
7
_
654
_
321
MMk
.
new
(
4.5
,
1.0
,
5
).
run
MMk
.
new
(
4.5
,
1.0
,
5
).
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