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
bacdd24e
Commit
bacdd24e
authored
12 years ago
by
pjs
Browse files
Options
Downloads
Patches
Plain Diff
Added AoModel to demos
Signed-off-by:
pjs
<
pjs@alum.mit.edu
>
parent
53440fe9
No related branches found
Branches containing commit
Tags
v0.3.2
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
demos/AoModel.rb
+140
-0
140 additions, 0 deletions
demos/AoModel.rb
with
140 additions
and
0 deletions
demos/AoModel.rb
0 → 100644
+
140
−
0
View file @
bacdd24e
#!/usr/bin/env ruby
require
'rubygems'
require
'simplekit'
# Demonstration model of Operational Availability (Ao).
class
AoModel
include
SimpleKit
# model state
attr_reader
:numAvailableJeeps
,
:numAvailableMechanics
,
:maintenanceQLength
,
:breakdownQLength
# model parameters
attr_reader
:maxJeeps
,
:maxMaintainers
,
:breakdownRate
,
:maintenanceCycleInDays
,
:repairRate
,
:haltTime
# Exponential random variate generator with specified rate.
def
exponential
(
rate
)
-
Math
.
log
(
rand
)
/
rate
end
# the actual model implementation...
# Constructor initializes the model parameters.
def
initialize
(
maxJeeps
,
maxMaintainers
,
breakdownRate
,
maintenanceCycleInDays
,
meanRepairTime
,
haltTime
)
@maxJeeps
=
maxJeeps
@maxMaintainers
=
maxMaintainers
@breakdownRate
=
breakdownRate
@maintenanceCycleInDays
=
maintenanceCycleInDays
@repairRate
=
1.0
/
meanRepairTime
@haltTime
=
haltTime
end
# init method kickstarts a simplekit model. State variables are
# set to initial values, and some preliminary events get scheduled
def
init
@numAvailableJeeps
=
@maxJeeps
@numAvailableMechanics
=
@maxMaintainers
@maintenanceQLength
=
0
@breakdownQLength
=
0
@numAvailableJeeps
.
times
do
|
i
|
breakdownTime
=
exponential
(
@breakdownRate
)
if
(
breakdownTime
<=
@maintenanceCycleInDays
)
schedule
(
:breakdown
,
breakdownTime
)
else
schedule
(
:maintenance
,
@maintenanceCycleInDays
)
end
end
schedule
(
:halt
,
@haltTime
)
STDOUT
.
puts
"DailyAoReport"
schedule
(
:dailyReport
,
0.0
)
end
# Event methods follow...
def
dailyReport
STDOUT
.
printf
"%d
\n
"
,
@numAvailableJeeps
schedule
(
:dailyReport
,
8.0
)
end
def
breakdown
@breakdownQLength
+=
1
@numAvailableJeeps
-=
1
schedule
(
:beginBreakdownService
,
0.0
)
if
(
@numAvailableMechanics
>
0
)
end
def
maintenance
@maintenanceQLength
+=
1
@numAvailableJeeps
-=
1
schedule
(
:beginMaintenanceService
,
0.0
)
if
(
@numAvailableMechanics
>
0
)
end
def
beginMaintenanceService
@maintenanceQLength
-=
1
@numAvailableMechanics
-=
1
if
(
rand
<=
0.95
)
schedule
(
:endService
,
(
6.5
-
rand
)
/
8.0
)
else
schedule
(
:endService
,
exponential
(
@repairRate
/
4.0
))
end
end
def
beginBreakdownService
@breakdownQLength
-=
1
@numAvailableMechanics
-=
1
if
(
rand
<=
0.8
)
schedule
(
:endService
,
exponential
(
@repairRate
))
else
schedule
(
:endService
,
exponential
(
@repairRate
/
4.0
))
end
end
def
endService
@numAvailableMechanics
+=
1
@numAvailableJeeps
+=
1
if
(
@maintenanceQLength
>
0
)
schedule
(
:beginMaintenanceService
,
0.0
)
else
schedule
(
:beginBreakdownService
,
0.0
)
if
(
@breakdownQLength
>
0
)
end
breakdownTime
=
exponential
(
@breakdownRate
)
if
(
breakdownTime
<=
@maintenanceCycleInDays
)
schedule
(
:breakdown
,
breakdownTime
)
else
schedule
(
:maintenance
,
@maintenanceCycleInDays
)
end
end
end
# Run model based on command-line arguments...
if
(
ARGV
.
length
!=
6
)
STDERR
.
puts
"
\n
Must supply six command-line arguments:
\n
"
STDERR
.
puts
"
\t
Initial Stock level (int)"
STDERR
.
puts
"
\t
#Maintenance personnel (int)"
STDERR
.
puts
"
\t
Normal breakdown rate (double)"
STDERR
.
puts
"
\t
Maintenance cycle length (int)"
STDERR
.
puts
"
\t
Mean repair time (double)"
STDERR
.
puts
"
\t
Number of days to run (int)"
STDERR
.
puts
"
\n
Example: ruby AoModel.rb 50 2 0.01 90 3.0 50
\n
"
else
maxJeeps
=
ARGV
[
0
].
to_i
maxMaintainers
=
ARGV
[
1
].
to_i
breakdownRate
=
ARGV
[
2
].
to_f
maintenanceCycleInDays
=
ARGV
[
3
].
to_i
meanRepairTime
=
ARGV
[
4
].
to_f
haltTimeInDays
=
ARGV
[
5
].
to_i
# Simulation.run(new AoModel(50, 2, 0.01, 90, 3.0, 8.0 * haltTimeInDays))
AoModel
.
new
(
maxJeeps
,
maxMaintainers
,
breakdownRate
,
maintenanceCycleInDays
,
meanRepairTime
,
8.0
*
haltTimeInDays
).
run
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