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
11247272
Commit
11247272
authored
Oct 20, 2015
by
Georgios Dagkakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up and comments
parent
601abebe
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
10 deletions
+30
-10
dream/simulation/Examples/OperationalFailures.py
dream/simulation/Examples/OperationalFailures.py
+30
-10
No files found.
dream/simulation/Examples/OperationalFailures.py
View file @
11247272
...
...
@@ -4,38 +4,49 @@ import random
from
random
import
Random
Rnd
=
Random
(
3
)
# transition probabilities
p
=
0.01
g
=
0.01
r
=
0.1
f
=
0.2
# the capacity of B123
capacity
=
35
class
OpQueue
(
Queue
):
# allow to be locked between the time periods
def
canAccept
(
self
,
callerObject
=
None
):
if
self
.
locked
:
return
False
return
Queue
.
canAccept
(
self
,
callerObject
)
class
OpExit
(
Exit
):
# set numGoodParts=0 at every replication
def
initialize
(
self
):
self
.
numGoodParts
=
0
Exit
.
initialize
(
self
)
# allow to be locked between the time periods
def
canAccept
(
self
,
callerObject
=
None
):
if
self
.
locked
:
return
False
return
True
# if the status of the entity is 'Good' update numGoodParts
def
getEntity
(
self
):
activeEntity
=
Exit
.
getEntity
(
self
)
if
activeEntity
.
status
==
'Good'
:
self
.
numGoodParts
+=
1
return
activeEntity
# update the GoodExits list
def
postProcessing
(
self
):
Exit
.
postProcessing
(
self
,
MaxSimtime
=
1000.1
)
self
.
GoodExits
.
append
(
self
.
numGoodParts
)
class
OpMachine
(
Machine
):
# allow to be locked between the time periods
# also if there is failure (state=0) do not get new work
def
canAccept
(
self
,
callerObject
=
None
):
if
self
.
locked
:
return
False
...
...
@@ -43,17 +54,22 @@ class OpMachine(Machine):
return
False
return
Machine
.
canAccept
(
self
,
callerObject
)
# set state=1 at the start of each replication
def
initialize
(
self
):
Machine
.
initialize
(
self
)
self
.
state
=
1
# if the state is -1 set that the disposed Entity is 'Bad'
def
removeEntity
(
self
,
entity
):
activeEntity
=
Machine
.
removeEntity
(
self
,
entity
)
if
self
.
state
==-
1
:
activeEntity
.
status
=
'Bad'
return
activeEntity
# method invoked by the generator at every time period
def
controllerMethod
():
# for every machine calculate the state (based on transition probabilities)
for
M
in
[
M1
,
M2
,
M3
]:
rn1
=
createRandomNumber
()
rn2
=
createRandomNumber
()
...
...
@@ -69,20 +85,21 @@ def controllerMethod():
if
rn1
<
f
:
M
.
state
=
0
# unlock E and let part get from M3 to E
E
.
locked
=
False
if
len
(
M3
.
getActiveObjectQueue
())
and
(
not
M3
.
state
==
0
):
# print '----> M3->E'
Controller
.
sendSignal
(
sender
=
M3
,
receiver
=
E
,
signal
=
E
.
isRequested
)
yield
G
.
env
.
timeout
(
0
)
E
.
locked
=
True
# unlock M3 and let part get from B123 to M3
M3
.
locked
=
False
if
len
(
B123
.
getActiveObjectQueue
())
and
(
not
M3
.
state
==
0
):
# print '----> B123->M3'
Controller
.
sendSignal
(
sender
=
B123
,
receiver
=
M3
,
signal
=
M3
.
isRequested
)
yield
G
.
env
.
timeout
(
0
)
M3
.
locked
=
True
# unlock B123 and let parts get from M1 and M2 to B123
B123
.
locked
=
False
if
((
len
(
M1
.
getActiveObjectQueue
()))
and
(
not
M1
.
state
==
0
)
\
or
((
len
(
M2
.
getActiveObjectQueue
()))
and
not
M2
.
state
==
0
))
\
...
...
@@ -97,6 +114,7 @@ def controllerMethod():
break
B123
.
locked
=
True
# unlock M1 and M2 and let parts get from NS1 to M1 and from NS2 to M2
M1
.
locked
=
False
M2
.
locked
=
False
if
len
(
M1
.
getActiveObjectQueue
())
==
0
:
...
...
@@ -105,13 +123,13 @@ def controllerMethod():
Controller
.
sendSignal
(
sender
=
NS2
,
receiver
=
M2
,
signal
=
M2
.
isRequested
)
while
1
:
yield
G
.
env
.
timeout
(
0
)
# print G.env.now, len(M1.getActiveObjectQueue()), M1.state, len(M2.getActiveObjectQueue()), M2.state
if
(
len
(
M1
.
getActiveObjectQueue
())
or
M1
.
state
==
0
)
\
and
(
len
(
M2
.
getActiveObjectQueue
())
or
M2
.
state
==
0
):
M1
.
locked
=
True
M2
.
locked
=
True
break
# returns a number from the uniform distribution (0,1)
def
createRandomNumber
():
return
Rnd
.
uniform
(
0
,
1
)
...
...
@@ -122,7 +140,7 @@ NS2=NonStarvingEntry('NS2','Entry2',entityData={'_class':'Dream.Part','status':'
M1
=
OpMachine
(
'M1'
,
'Machine1'
,
processingTime
=
{
'Fixed'
:{
'mean'
:
0.1
}})
M2
=
OpMachine
(
'M2'
,
'Machine2'
,
processingTime
=
{
'Fixed'
:{
'mean'
:
0.1
}})
M3
=
OpMachine
(
'M3'
,
'Machine3'
,
processingTime
=
{
'Fixed'
:{
'mean'
:
0.1
}})
B123
=
OpQueue
(
'B123'
,
'Queue'
,
capacity
=
10
)
B123
=
OpQueue
(
'B123'
,
'Queue'
,
capacity
=
capacity
)
E
=
OpExit
(
'E1'
,
'Exit'
)
Controller
=
EventGenerator
(
'EV'
,
'Controller'
,
start
=
0
,
interval
=
1
,
method
=
controllerMethod
)
...
...
@@ -138,9 +156,11 @@ E.defineRouting(predecessorList=[M3])
# add all the objects to a list
objectList
=
[
NS1
,
NS2
,
M1
,
M2
,
M3
,
B123
,
E
,
Controller
]
# set all objects locked at beginning
for
obj
in
objectList
:
obj
.
locked
=
True
# GoodExits will keep the number of good parts produced in every replication
E
.
GoodExits
=
[]
# call the runSimulation giving the objects and the length of the experiment
...
...
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