Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
27ae92ec
Commit
27ae92ec
authored
Apr 02, 2014
by
Ioannis Papagiannopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Repairman now inherits from operator
parent
9e5644ee
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
129 additions
and
101 deletions
+129
-101
dream/simulation/ObjectResource.py
dream/simulation/ObjectResource.py
+4
-0
dream/simulation/Operator.py
dream/simulation/Operator.py
+121
-6
dream/simulation/OperatorPool.py
dream/simulation/OperatorPool.py
+1
-9
dream/simulation/Repairman.py
dream/simulation/Repairman.py
+3
-86
No files found.
dream/simulation/ObjectResource.py
View file @
27ae92ec
...
...
@@ -41,6 +41,10 @@ class ObjectResource(object):
self
.
Res
=
Resource
(
self
.
capacity
)
# variable that checks whether the resource is already initialized
self
.
initialized
=
True
# list with the coreObjects IDs that the resource services
self
.
coreObjectIds
=
[]
# list with the coreObjects that the resource services
self
.
coreObjects
=
[]
# =======================================================================
# checks if the worker is available
...
...
dream/simulation/Operator.py
View file @
27ae92ec
...
...
@@ -27,17 +27,28 @@ models an operator that operates a machine
'''
from
SimPy.Simulation
import
Resource
,
now
from
Repairman
import
Repairman
import
xlwt
import
scipy.stats
as
stat
from
ObjectResource
import
ObjectResource
# ===========================================================================
# the resource that operates the machines
# ===========================================================================
class
Operator
(
Repairman
):
# XXX isn't it the other way around ?
class
Operator
(
ObjectResource
):
class_name
=
'Dream.Operator'
def
__init__
(
self
,
id
,
name
,
capacity
=
1
,
schedulingRule
=
"FIFO"
):
Repairman
.
__init__
(
self
,
id
=
id
,
name
=
name
,
capacity
=
capacity
)
def
__init__
(
self
,
id
,
name
,
capacity
=
1
,
schedulingRule
=
'FIFO'
):
ObjectResource
.
__init__
(
self
)
self
.
id
=
id
self
.
objName
=
name
self
.
capacity
=
capacity
# repairman is an instance of resource
self
.
type
=
"Operator"
# lists to hold statistics of multiple runs
self
.
Waiting
=
[]
# holds the percentage of waiting time
self
.
Working
=
[]
# holds the percentage of working time
# the following attributes are not used by the Repairman
self
.
activeCallersList
=
[]
# the list of object that request the operator
self
.
schedulingRule
=
schedulingRule
#the scheduling rule that the Queue follows
self
.
multipleCriterionList
=
[]
#list with the criteria used to sort the Entities in the Queue
...
...
@@ -175,5 +186,109 @@ class Operator(Repairman): # XXX isn't it the other way around ?
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
identifyEntityToGet
().
nextQueueLength
)
else
:
assert
False
,
"Unknown scheduling criterion %r"
%
(
criterion
,
)
# =======================================================================
# actions to be taken after the simulation ends
# =======================================================================
def
postProcessing
(
self
,
MaxSimtime
=
None
):
if
MaxSimtime
==
None
:
from
Globals
import
G
MaxSimtime
=
G
.
maxSimTime
# if the repairman is currently working we have to count the time of this work
# if len(self.getResourceQueue())>0:
if
not
self
.
checkIfResourceIsAvailable
():
self
.
totalWorkingTime
+=
now
()
-
self
.
timeLastOperationStarted
# Repairman was idle when he was not in any other state
self
.
totalWaitingTime
=
MaxSimtime
-
self
.
totalWorkingTime
# update the waiting/working time percentages lists
self
.
Waiting
.
append
(
100
*
self
.
totalWaitingTime
/
MaxSimtime
)
self
.
Working
.
append
(
100
*
self
.
totalWorkingTime
/
MaxSimtime
)
# =======================================================================
# outputs data to "output.xls"
# =======================================================================
def
outputResultsXL
(
self
,
MaxSimtime
=
None
):
from
Globals
import
G
if
MaxSimtime
==
None
:
MaxSimtime
=
G
.
maxSimTime
# if we had just one replication output the results to excel
if
(
G
.
numberOfReplications
==
1
):
G
.
outputSheet
.
write
(
G
.
outputIndex
,
0
,
"The percentage of working of "
+
self
.
objName
+
" is:"
)
G
.
outputSheet
.
write
(
G
.
outputIndex
,
1
,
100
*
self
.
totalWorkingTime
/
MaxSimtime
)
G
.
outputIndex
+=
1
G
.
outputSheet
.
write
(
G
.
outputIndex
,
0
,
"The percentage of waiting of "
+
self
.
objName
+
" is:"
)
G
.
outputSheet
.
write
(
G
.
outputIndex
,
1
,
100
*
self
.
totalWaitingTime
/
MaxSimtime
)
G
.
outputIndex
+=
1
#if we had multiple replications we output confidence intervals to excel
# for some outputs the results may be the same for each run (eg model is stochastic but failures fixed
# so failurePortion will be exactly the same in each run). That will give 0 variability and errors.
# so for each output value we check if there was difference in the runs' results
# if yes we output the Confidence Intervals. if not we output just the fix value
else
:
G
.
outputSheet
.
write
(
G
.
outputIndex
,
0
,
"CI "
+
str
(
G
.
confidenceLevel
*
100
)
+
"% for the mean percentage of Working of "
+
self
.
objName
+
" is:"
)
if
self
.
checkIfArrayHasDifValues
(
self
.
Working
):
G
.
outputSheet
.
write
(
G
.
outputIndex
,
1
,
stat
.
bayes_mvs
(
self
.
Working
,
G
.
confidenceLevel
)[
0
][
1
][
0
])
G
.
outputSheet
.
write
(
G
.
outputIndex
,
2
,
stat
.
bayes_mvs
(
self
.
Working
,
G
.
confidenceLevel
)[
0
][
0
])
G
.
outputSheet
.
write
(
G
.
outputIndex
,
3
,
stat
.
bayes_mvs
(
self
.
Working
,
G
.
confidenceLevel
)[
0
][
1
][
1
])
else
:
G
.
outputSheet
.
write
(
G
.
outputIndex
,
1
,
self
.
Working
[
0
])
G
.
outputSheet
.
write
(
G
.
outputIndex
,
2
,
self
.
Working
[
0
])
G
.
outputSheet
.
write
(
G
.
outputIndex
,
3
,
self
.
Working
[
0
])
G
.
outputIndex
+=
1
G
.
outputSheet
.
write
(
G
.
outputIndex
,
0
,
"CI "
+
str
(
G
.
confidenceLevel
*
100
)
+
"% for the mean percentage of Waiting of "
+
self
.
objName
+
" is:"
)
if
self
.
checkIfArrayHasDifValues
(
self
.
Waiting
):
G
.
outputSheet
.
write
(
G
.
outputIndex
,
1
,
stat
.
bayes_mvs
(
self
.
Waiting
,
G
.
confidenceLevel
)[
0
][
1
][
0
])
G
.
outputSheet
.
write
(
G
.
outputIndex
,
2
,
stat
.
bayes_mvs
(
self
.
Waiting
,
G
.
confidenceLevel
)[
0
][
0
])
G
.
outputSheet
.
write
(
G
.
outputIndex
,
3
,
stat
.
bayes_mvs
(
self
.
Waiting
,
G
.
confidenceLevel
)[
0
][
1
][
1
])
else
:
G
.
outputSheet
.
write
(
G
.
outputIndex
,
1
,
self
.
Waiting
[
0
])
G
.
outputSheet
.
write
(
G
.
outputIndex
,
2
,
self
.
Waiting
[
0
])
G
.
outputSheet
.
write
(
G
.
outputIndex
,
3
,
self
.
Waiting
[
0
])
G
.
outputIndex
+=
1
G
.
outputIndex
+=
1
# =======================================================================
# outputs results to JSON File
# =======================================================================
def
outputResultsJSON
(
self
):
from
Globals
import
G
# if we had just one replication output the results to JSON
if
(
G
.
numberOfReplications
==
1
):
json
=
{}
json
[
'_class'
]
=
'Dream.'
+
self
.
type
;
json
[
'id'
]
=
str
(
self
.
id
)
json
[
'results'
]
=
{}
json
[
'results'
][
'working_ratio'
]
=
100
*
self
.
totalWorkingTime
/
G
.
maxSimTime
json
[
'results'
][
'waiting_ratio'
]
=
100
*
self
.
totalWaitingTime
/
G
.
maxSimTime
#if we had multiple replications we output confidence intervals to excel
# for some outputs the results may be the same for each run (eg model is stochastic but failures fixed
# so failurePortion will be exactly the same in each run). That will give 0 variability and errors.
# so for each output value we check if there was difference in the runs' results
# if yes we output the Confidence Intervals. if not we output just the fix value
else
:
json
=
{}
json
[
'_class'
]
=
'Dream.Repairman'
;
json
[
'id'
]
=
str
(
self
.
id
)
json
[
'results'
]
=
{}
json
[
'results'
][
'working_ratio'
]
=
{}
if
self
.
checkIfArrayHasDifValues
(
self
.
Working
):
json
[
'results'
][
'working_ratio'
][
'min'
]
=
stat
.
bayes_mvs
(
self
.
Working
,
G
.
confidenceLevel
)[
0
][
1
][
0
]
json
[
'results'
][
'working_ratio'
][
'avg'
]
=
stat
.
bayes_mvs
(
self
.
Working
,
G
.
confidenceLevel
)[
0
][
0
]
json
[
'results'
][
'working_ratio'
][
'max'
]
=
stat
.
bayes_mvs
(
self
.
Working
,
G
.
confidenceLevel
)[
0
][
1
][
1
]
else
:
json
[
'results'
][
'working_ratio'
][
'min'
]
=
self
.
Working
[
0
]
json
[
'results'
][
'working_ratio'
][
'avg'
]
=
self
.
Working
[
0
]
json
[
'results'
][
'working_ratio'
][
'max'
]
=
self
.
Working
[
0
]
json
[
'results'
][
'waiting_ratio'
]
=
{}
if
self
.
checkIfArrayHasDifValues
(
self
.
Waiting
):
json
[
'results'
][
'waiting_ratio'
][
'min'
]
=
stat
.
bayes_mvs
(
self
.
Waiting
,
G
.
confidenceLevel
)[
0
][
1
][
0
]
json
[
'results'
][
'waiting_ratio'
][
'avg'
]
=
stat
.
bayes_mvs
(
self
.
Waiting
,
G
.
confidenceLevel
)[
0
][
0
]
json
[
'results'
][
'waiting_ratio'
][
'max'
]
=
stat
.
bayes_mvs
(
self
.
Waiting
,
G
.
confidenceLevel
)[
0
][
1
][
1
]
else
:
json
[
'results'
][
'waiting_ratio'
][
'min'
]
=
self
.
Waiting
[
0
]
json
[
'results'
][
'waiting_ratio'
][
'avg'
]
=
self
.
Waiting
[
0
]
json
[
'results'
][
'waiting_ratio'
][
'max'
]
=
self
.
Waiting
[
0
]
G
.
outputJSON
[
'elementList'
].
append
(
json
)
\ No newline at end of file
dream/simulation/OperatorPool.py
View file @
27ae92ec
...
...
@@ -44,10 +44,6 @@ class OperatorPool(ObjectResource):
self
.
objName
=
name
self
.
type
=
"OperatorPool"
# self.Res=Resource(self.capacity)
# lists to hold statistics of multiple runs
# self.Waiting=[] # holds the percentage of waiting time
# self.Working=[] # holds the percentage of working time
# list with the coreObjects IDs that the Operators operate
self
.
coreObjectIds
=
[]
# list with the coreObjects that the Operators operate
...
...
@@ -89,13 +85,9 @@ class OperatorPool(ObjectResource):
# initialize the object
# =======================================================================
def
initialize
(
self
):
# self.totalWorkingTime=0 #holds the total working time
# self.totalWaitingTime=0 #holds the total waiting time
# self.timeLastOperationStarted=0 #holds the time that the last operation was started
# initialize the operators
# an operator that may have been initialized by an other operator pool, is initiated again
# reconsider
#
TODO:
reconsider
for
operator
in
self
.
operators
:
if
not
operator
.
isInitialized
():
operator
.
initialize
()
...
...
dream/simulation/Repairman.py
View file @
27ae92ec
...
...
@@ -27,97 +27,14 @@ models a repairman that can fix a machine when it gets failures
'''
from
SimPy.Simulation
import
Resource
,
now
import
xlwt
from
ObjectResource
import
ObjectResource
from
Operator
import
Operator
# ===========================================================================
# the resource that repairs the machines
# ===========================================================================
class
Repairman
(
O
bjectResource
):
class
Repairman
(
O
perator
):
class_name
=
'Dream.Repairman'
def
__init__
(
self
,
id
,
name
,
capacity
=
1
):
ObjectResource
.
__init__
(
self
)
self
.
id
=
id
self
.
objName
=
name
self
.
capacity
=
capacity
# repairman is an instance of resource
Operator
.
__init__
(
self
,
id
=
id
,
name
=
name
,
capacity
=
capacity
)
self
.
type
=
"Repairman"
# self.Res=Resource(self.capacity)
# lists to hold statistics of multiple runs
self
.
Waiting
=
[]
# holds the percentage of waiting time
self
.
Working
=
[]
# holds the percentage of working time
# list with the coreObjects IDs that the repairman repairs
self
.
coreObjectIds
=
[]
# list with the coreObjects that the repairman repairs
self
.
coreObjects
=
[]
# =======================================================================
# actions to be taken after the simulation ends
# =======================================================================
def
postProcessing
(
self
,
MaxSimtime
=
None
):
if
MaxSimtime
==
None
:
from
Globals
import
G
MaxSimtime
=
G
.
maxSimTime
# if the repairman is currently working we have to count the time of this work
# if len(self.getResourceQueue())>0:
if
not
self
.
checkIfResourceIsAvailable
():
self
.
totalWorkingTime
+=
now
()
-
self
.
timeLastOperationStarted
# Repairman was idle when he was not in any other state
self
.
totalWaitingTime
=
MaxSimtime
-
self
.
totalWorkingTime
# update the waiting/working time percentages lists
self
.
Waiting
.
append
(
100
*
self
.
totalWaitingTime
/
MaxSimtime
)
self
.
Working
.
append
(
100
*
self
.
totalWorkingTime
/
MaxSimtime
)
# =======================================================================
# outputs data to "output.xls"
# =======================================================================
def
outputResultsXL
(
self
,
MaxSimtime
=
None
):
from
Globals
import
G
from
Globals
import
getConfidenceIntervals
if
MaxSimtime
==
None
:
MaxSimtime
=
G
.
maxSimTime
# if we had just one replication output the results to excel
if
(
G
.
numberOfReplications
==
1
):
G
.
outputSheet
.
write
(
G
.
outputIndex
,
0
,
"The percentage of working of "
+
self
.
objName
+
" is:"
)
G
.
outputSheet
.
write
(
G
.
outputIndex
,
1
,
100
*
self
.
totalWorkingTime
/
MaxSimtime
)
G
.
outputIndex
+=
1
G
.
outputSheet
.
write
(
G
.
outputIndex
,
0
,
"The percentage of waiting of "
+
self
.
objName
+
" is:"
)
G
.
outputSheet
.
write
(
G
.
outputIndex
,
1
,
100
*
self
.
totalWaitingTime
/
MaxSimtime
)
G
.
outputIndex
+=
1
#if we had multiple replications we output confidence intervals to excel
# for some outputs the results may be the same for each run (eg model is stochastic but failures fixed
# so failurePortion will be exactly the same in each run). That will give 0 variability and errors.
# so for each output value we check if there was difference in the runs' results
# if yes we output the Confidence Intervals. if not we output just the fix value
else
:
G
.
outputSheet
.
write
(
G
.
outputIndex
,
0
,
"CI "
+
str
(
G
.
confidenceLevel
*
100
)
+
"% for the mean percentage of Working of "
+
self
.
objName
+
" is:"
)
working_ci
=
getConfidenceIntervals
(
self
.
Working
)
G
.
outputSheet
.
write
(
G
.
outputIndex
,
1
,
working_ci
[
'min'
])
G
.
outputSheet
.
write
(
G
.
outputIndex
,
2
,
working_ci
[
'avg'
])
G
.
outputSheet
.
write
(
G
.
outputIndex
,
3
,
working_ci
[
'max'
])
G
.
outputIndex
+=
1
G
.
outputSheet
.
write
(
G
.
outputIndex
,
0
,
"CI "
+
str
(
G
.
confidenceLevel
*
100
)
+
"% for the mean percentage of Waiting of "
+
self
.
objName
+
" is:"
)
waiting_ci
=
getConfidenceIntervals
(
self
.
Waiting
)
G
.
outputSheet
.
write
(
G
.
outputIndex
,
1
,
waiting_ci
[
'min'
])
G
.
outputSheet
.
write
(
G
.
outputIndex
,
2
,
waiting_ci
[
'avg'
])
G
.
outputSheet
.
write
(
G
.
outputIndex
,
3
,
waiting_ci
[
'max'
])
G
.
outputIndex
+=
1
G
.
outputIndex
+=
1
# =======================================================================
# outputs results to JSON File
# =======================================================================
def
outputResultsJSON
(
self
):
from
Globals
import
G
from
Globals
import
getConfidenceIntervals
json
=
{
'_class'
:
self
.
class_name
,
'id'
:
self
.
id
,
'results'
:
{}}
if
(
G
.
numberOfReplications
==
1
):
json
[
'results'
][
'working_ratio'
]
=
100
*
self
.
totalWorkingTime
/
G
.
maxSimTime
json
[
'results'
][
'waiting_ratio'
]
=
100
*
self
.
totalWaitingTime
/
G
.
maxSimTime
else
:
json
[
'results'
][
'working_ratio'
]
=
getConfidenceIntervals
(
self
.
Working
)
json
[
'results'
][
'waiting_ratio'
]
=
getConfidenceIntervals
(
self
.
Waiting
)
G
.
outputJSON
[
'elementList'
].
append
(
json
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment