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
8e44904f
Commit
8e44904f
authored
Nov 25, 2013
by
Ioannis Papagiannopoulos
Committed by
Jérome Perrin
Dec 02, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Operator and OperatedMachine added. Not tested yet
parent
007e5b7c
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
540 additions
and
0 deletions
+540
-0
dream/simulation/OperatedMachine.py
dream/simulation/OperatedMachine.py
+385
-0
dream/simulation/Operator.py
dream/simulation/Operator.py
+155
-0
No files found.
dream/simulation/OperatedMachine.py
0 → 100644
View file @
8e44904f
This diff is collapsed.
Click to expand it.
dream/simulation/Operator.py
0 → 100644
View file @
8e44904f
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
'''
Created on 22 Nov 2012
@author: Ioannis
'''
'''
models a repairman that can fix a machine when it gets failures
'''
from
SimPy.Simulation
import
Resource
,
now
import
xlwt
import
scipy.stats
as
stat
from
ObjectResource
import
ObjectResource
# ===========================================================================
# the resource that repairs the machines
# ===========================================================================
class
Operator
(
ObjectResource
):
def
__init__
(
self
,
id
,
name
,
capacity
=
1
):
self
.
id
=
id
self
.
objName
=
name
self
.
capacity
=
capacity
# operator is an instance of resource
self
.
type
=
"Operator"
# 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 that the Operator operates
self
.
coreObjectIds
=
[]
# =======================================================================
# 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
not
self
.
isResourceFree
():
# if len(self.getResourceQueue())>0:
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.Repairman'
;
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
)
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