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
56cff46e
Commit
56cff46e
authored
Oct 10, 2013
by
Georgios Dagkakis
Committed by
Sebastien Robin
Nov 06, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
machine object updated so that it uses the new methods (getActiveEntityQueue, getGiverEntity etc)
parent
bd460546
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
60 deletions
+69
-60
dream/simulation/CoreObject.py
dream/simulation/CoreObject.py
+1
-1
dream/simulation/Machine.py
dream/simulation/Machine.py
+68
-59
No files found.
dream/simulation/CoreObject.py
View file @
56cff46e
...
@@ -147,7 +147,7 @@ class CoreObject(Process):
...
@@ -147,7 +147,7 @@ class CoreObject(Process):
#get the receiver object in a removeEntity transaction.
#get the receiver object in a removeEntity transaction.
def
getReceiverObject
(
self
):
def
getReceiverObject
(
self
):
return
self
.
next
[
self
.
prede
cessorIndex
]
return
self
.
next
[
self
.
suc
cessorIndex
]
#get the receiver object queue in a removeEntity transaction.
#get the receiver object queue in a removeEntity transaction.
def
getReceiverObjectQueue
(
self
):
def
getReceiverObjectQueue
(
self
):
...
...
dream/simulation/Machine.py
View file @
56cff46e
...
@@ -128,8 +128,7 @@ class Machine(CoreObject):
...
@@ -128,8 +128,7 @@ class Machine(CoreObject):
processingEndedFlag
=
True
processingEndedFlag
=
True
failureTime
=
0
failureTime
=
0
self
.
downTimeInCurrentEntity
=
0
self
.
downTimeInCurrentEntity
=
0
#this loop is repeated until the processing time is expired with no failure
#this loop is repeated until the processing time is expired with no failure
while
processingEndedFlag
:
while
processingEndedFlag
:
tBefore
=
now
()
tBefore
=
now
()
...
@@ -198,47 +197,50 @@ class Machine(CoreObject):
...
@@ -198,47 +197,50 @@ class Machine(CoreObject):
#checks if the Machine can accept an entity
#checks if the Machine can accept an entity
#it checks also who called it and returns TRUE only to the predecessor that will give the entity.
#it checks also who called it and returns TRUE only to the predecessor that will give the entity.
def
canAccept
(
self
,
callerObject
=
None
):
def
canAccept
(
self
,
callerObject
=
None
):
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
giverObject
=
self
.
getGiverObject
()
#if we have only one predecessor just check if there is a place and the machine is up
#if we have only one predecessor just check if there is a place and the machine is up
if
(
len
(
self
.
previous
)
==
1
or
callerObject
==
None
):
if
(
len
(
activeObject
.
previous
)
==
1
or
callerObject
==
None
):
return
self
.
Up
and
len
(
self
.
Res
.
activeQ
)
==
0
return
activeObject
.
Up
and
len
(
activeObjectQueue
)
==
0
#if the machine is busy return False immediately
#if the machine is busy return False immediately
if
len
(
self
.
Res
.
activeQ
)
==
self
.
capacity
:
if
len
(
activeObjectQueue
)
==
activeObject
.
capacity
:
return
False
return
False
thecaller
=
callerObject
thecaller
=
callerObject
#return true only to the predecessor from which the queue will take
return
len
(
activeObjectQueue
)
<
self
.
capacity
and
(
thecaller
is
giverObject
)
flag
=
False
if
thecaller
is
self
.
previous
[
self
.
predecessorIndex
]:
flag
=
True
return
len
(
self
.
Res
.
activeQ
)
<
self
.
capacity
and
flag
#checks if the Machine can accept an entity and there is an entity in some predecessor waiting for it
#checks if the Machine can accept an entity and there is an entity in some predecessor waiting for it
#also updates the predecessorIndex to the one that is to be taken
#also updates the predecessorIndex to the one that is to be taken
def
canAcceptAndIsRequested
(
self
):
def
canAcceptAndIsRequested
(
self
):
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
giverObject
=
self
.
getGiverObject
()
#if we have only one predecessor just check if there is a place, the machine is up and the predecessor has an entity to dispose
#if we have only one predecessor just check if there is a place, the machine is up and the predecessor has an entity to dispose
if
(
len
(
self
.
previous
)
==
1
):
if
(
len
(
activeObject
.
previous
)
==
1
):
return
self
.
Up
and
len
(
self
.
Res
.
activeQ
)
==
0
and
self
.
previous
[
0
].
haveToDispose
(
self
)
return
activeObject
.
Up
and
len
(
activeObjectQueue
)
==
0
and
giverObject
.
haveToDispose
(
activeObject
)
isRequested
=
False
isRequested
=
False
maxTimeWaiting
=
0
maxTimeWaiting
=
0
#loop through the predecessors to see which have to dispose and which is the one blocked for longer
#loop through the predecessors to see which have to dispose and which is the one blocked for longer
for
i
in
range
(
len
(
self
.
previous
)):
for
i
in
range
(
len
(
activeObject
.
previous
)):
if
(
self
.
previous
[
i
].
haveToDispose
(
self
)):
if
(
activeObject
.
previous
[
i
].
haveToDispose
(
self
)):
isRequested
=
True
isRequested
=
True
if
(
self
.
previous
[
i
].
downTimeInTryingToReleaseCurrentEntity
>
0
):
if
(
activeObject
.
previous
[
i
].
downTimeInTryingToReleaseCurrentEntity
>
0
):
timeWaiting
=
now
()
-
self
.
previous
[
i
].
timeLastFailureEnded
timeWaiting
=
now
()
-
activeObject
.
previous
[
i
].
timeLastFailureEnded
else
:
else
:
timeWaiting
=
now
()
-
self
.
previous
[
i
].
timeLastEntityEnded
timeWaiting
=
now
()
-
activeObject
.
previous
[
i
].
timeLastEntityEnded
#if more than one predecessor have to dispose take the part from the one that is blocked longer
#if more than one predecessor have to dispose take the part from the one that is blocked longer
if
(
timeWaiting
>=
maxTimeWaiting
):
if
(
timeWaiting
>=
maxTimeWaiting
):
self
.
predecessorIndex
=
i
self
.
predecessorIndex
=
i
maxTimeWaiting
=
timeWaiting
maxTimeWaiting
=
timeWaiting
return
len
(
self
.
Res
.
activeQ
)
<
self
.
capacity
and
isRequested
return
len
(
activeObjectQueue
)
<
activeObject
.
capacity
and
isRequested
#checks if the machine down or it can dispose the object
#checks if the machine down or it can dispose the object
def
ifCanDisposeOrHaveFailure
(
self
):
def
ifCanDisposeOrHaveFailure
(
self
):
...
@@ -247,44 +249,52 @@ class Machine(CoreObject):
...
@@ -247,44 +249,52 @@ class Machine(CoreObject):
#removes an entity from the Machine
#removes an entity from the Machine
def
removeEntity
(
self
):
def
removeEntity
(
self
):
self
.
timeLastEntityLeft
=
now
()
activeObject
=
self
.
getActiveObject
()
self
.
outputTrace
(
"releases "
+
self
.
objName
)
activeObjectQueue
=
self
.
getActiveObjectQueue
()
self
.
waitToDispose
=
False
self
.
Res
.
activeQ
.
pop
(
0
)
activeObject
.
timeLastEntityLeft
=
now
()
self
.
downTimeInTryingToReleaseCurrentEntity
=
0
activeObject
.
outputTrace
(
"releases "
+
activeObject
.
objName
)
activeObject
.
waitToDispose
=
False
activeObjectQueue
.
pop
(
0
)
#remove the Entity from the activeQ
activeObject
.
downTimeInTryingToReleaseCurrentEntity
=
0
#checks if the Machine can dispose an entity to the following object
#checks if the Machine can dispose an entity to the following object
def
haveToDispose
(
self
,
callerObject
=
None
):
def
haveToDispose
(
self
,
callerObject
=
None
):
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
#if we have only one successor just check if machine waits to dispose and also is up
#if we have only one successor just check if machine waits to dispose and also is up
if
(
len
(
self
.
next
)
==
1
or
callerObject
==
None
):
if
(
len
(
activeObject
.
next
)
==
1
or
callerObject
==
None
):
return
len
(
self
.
Res
.
activeQ
)
>
0
and
self
.
waitToDispose
and
self
.
Up
return
len
(
activeObjectQueue
)
>
0
and
activeObject
.
waitToDispose
and
activeObject
.
Up
#if the Machine is empty it returns false right away
#if the Machine is empty it returns false right away
if
(
len
(
self
.
Res
.
activeQ
)
==
0
):
if
(
len
(
activeObjectQueue
)
==
0
):
return
False
return
False
thecaller
=
callerObject
thecaller
=
callerObject
#give the entity to the successor that is waiting for the most time.
#give the entity to the successor that is waiting for the most time.
#
plant does not do this in every occasion!
#
(plant simulation does not do this in every occasion!)
maxTimeWaiting
=
0
maxTimeWaiting
=
0
for
i
in
range
(
len
(
self
.
next
)):
i
=
0
if
(
self
.
next
[
i
].
canAccept
(
self
)):
for
object
in
activeObject
.
next
:
timeWaiting
=
now
()
-
self
.
next
[
i
].
timeLastEntityLeft
if
(
object
.
canAccept
(
activeObject
)):
timeWaiting
=
now
()
-
object
.
timeLastEntityLeft
if
(
timeWaiting
>
maxTimeWaiting
or
maxTimeWaiting
==
0
):
if
(
timeWaiting
>
maxTimeWaiting
or
maxTimeWaiting
==
0
):
maxTimeWaiting
=
timeWaiting
maxTimeWaiting
=
timeWaiting
self
.
successorIndex
=
i
activeObject
.
successorIndex
=
i
i
+=
1
#return true only to the predecessor from which the queue will take
receiverObject
=
activeObject
.
getReceiverObject
()
flag
=
False
return
len
(
activeObjectQueue
)
>
0
and
activeObject
.
waitToDispose
and
activeObject
.
Up
and
(
thecaller
is
receiverObject
)
if
thecaller
is
self
.
next
[
self
.
successorIndex
]:
flag
=
True
return
len
(
self
.
Res
.
activeQ
)
>
0
and
self
.
waitToDispose
and
self
.
Up
and
flag
#actions to be taken after the simulation ends
#actions to be taken after the simulation ends
def
postProcessing
(
self
,
MaxSimtime
):
def
postProcessing
(
self
,
MaxSimtime
):
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
alreadyAdded
=
False
#a flag that shows if the blockage time has already been added
alreadyAdded
=
False
#a flag that shows if the blockage time has already been added
#checks all the successors. If no one can accept an Entity then the machine might be blocked
#checks all the successors. If no one can accept an Entity then the machine might be blocked
...
@@ -298,41 +308,41 @@ class Machine(CoreObject):
...
@@ -298,41 +308,41 @@ class Machine(CoreObject):
#till the end of simulation, we have to add this blockage to the percentage of blockage in Machine
#till the end of simulation, we have to add this blockage to the percentage of blockage in Machine
#we should exclude the failure time in current entity though!
#we should exclude the failure time in current entity though!
#if (len(self.Res.activeQ)>0) and (len(self.next[0].Res.activeQ)>0) and ((self.nameLastEntityEntered == self.nameLastEntityEnded)):
#if (len(self.Res.activeQ)>0) and (len(self.next[0].Res.activeQ)>0) and ((self.nameLastEntityEntered == self.nameLastEntityEnded)):
if
(
len
(
self
.
Res
.
activeQ
)
>
0
)
and
(
mightBeBlocked
)
and
((
self
.
nameLastEntityEntered
==
self
.
nameLastEntityEnded
)):
if
(
len
(
activeObjectQueue
)
>
0
)
and
(
mightBeBlocked
)
and
((
activeObject
.
nameLastEntityEntered
==
activeObject
.
nameLastEntityEnded
)):
self
.
totalBlockageTime
+=
now
()
-
(
self
.
timeLastEntityEnded
+
self
.
downTimeInTryingToReleaseCurrentEntity
)
activeObject
.
totalBlockageTime
+=
now
()
-
(
activeObject
.
timeLastEntityEnded
+
activeObject
.
downTimeInTryingToReleaseCurrentEntity
)
if
self
.
Up
==
False
:
if
activeObject
.
Up
==
False
:
self
.
totalBlockageTime
-=
now
()
-
self
.
timeLastFailure
activeObject
.
totalBlockageTime
-=
now
()
-
activeObject
.
timeLastFailure
alreadyAdded
=
True
alreadyAdded
=
True
#if Machine is currently processing an entity we should count this working time
#if Machine is currently processing an entity we should count this working time
if
(
len
(
self
.
Res
.
activeQ
)
>
0
)
and
(
not
(
self
.
nameLastEntityEnded
==
self
.
nameLastEntityEntered
)):
if
(
len
(
activeObject
.
Res
.
activeQ
)
>
0
)
and
(
not
(
activeObject
.
nameLastEntityEnded
==
activeObject
.
nameLastEntityEntered
)):
#if Machine is down we should add this last failure time to the time that it has been down in current entity
#if Machine is down we should add this last failure time to the time that it has been down in current entity
if
(
len
(
self
.
Res
.
activeQ
)
>
0
)
and
(
self
.
Up
==
False
):
if
(
len
(
activeObjectQueue
)
>
0
)
and
(
self
.
Up
==
False
):
self
.
downTimeProcessingCurrentEntity
+=
now
()
-
self
.
timeLastFailure
activeObject
.
downTimeProcessingCurrentEntity
+=
now
()
-
activeObject
.
timeLastFailure
self
.
totalWorkingTime
+=
now
()
-
self
.
timeLastEntityEntered
-
self
.
downTimeProcessingCurrentEntity
activeObject
.
totalWorkingTime
+=
now
()
-
activeObject
.
timeLastEntityEntered
-
activeObject
.
downTimeProcessingCurrentEntity
#if Machine is down we have to add this failure time to its total failure time
#if Machine is down we have to add this failure time to its total failure time
#we also need to add the last blocking time to total blockage time
#we also need to add the last blocking time to total blockage time
if
(
self
.
Up
==
False
):
if
(
activeObject
.
Up
==
False
):
self
.
totalFailureTime
+=
now
()
-
self
.
timeLastFailure
activeObject
.
totalFailureTime
+=
now
()
-
activeObject
.
timeLastFailure
#we add the value only if it hasn't already been added
#we add the value only if it hasn't already been added
#if((len(self.next[0].Res.activeQ)>0) and (self.nameLastEntityEnded==self.nameLastEntityEntered) and (not alreadyAdded)):
#if((len(self.next[0].Res.activeQ)>0) and (self.nameLastEntityEnded==self.nameLastEntityEntered) and (not alreadyAdded)):
if
((
mightBeBlocked
)
and
(
self
.
nameLastEntityEnded
==
self
.
nameLastEntityEntered
)
and
(
not
alreadyAdded
)):
if
((
mightBeBlocked
)
and
(
activeObject
.
nameLastEntityEnded
==
activeObject
.
nameLastEntityEntered
)
and
(
not
alreadyAdded
)):
self
.
totalBlockageTime
+=
(
now
()
-
self
.
timeLastEntityEnded
)
-
(
now
()
-
self
.
timeLastFailure
)
-
self
.
downTimeInTryingToReleaseCurrentEntity
activeObject
.
totalBlockageTime
+=
(
now
()
-
activeObject
.
timeLastEntityEnded
)
-
(
now
()
-
activeObject
.
timeLastFailure
)
-
activeObject
.
downTimeInTryingToReleaseCurrentEntity
#Machine was idle when it was not in any other state
#Machine was idle when it was not in any other state
self
.
totalWaitingTime
=
MaxSimtime
-
self
.
totalWorkingTime
-
self
.
totalBlockageTime
-
self
.
totalFailureTime
activeObject
.
totalWaitingTime
=
MaxSimtime
-
activeObject
.
totalWorkingTime
-
activeObject
.
totalBlockageTime
-
activeObject
.
totalFailureTime
if
self
.
totalBlockageTime
<
0
and
self
.
totalBlockageTime
>-
0.00001
:
#to avoid some effects of getting negative cause of rounding precision
if
activeObject
.
totalBlockageTime
<
0
and
activeObject
.
totalBlockageTime
>-
0.00001
:
#to avoid some effects of getting negative cause of rounding precision
self
.
totalBlockageTime
=
0
self
.
totalBlockageTime
=
0
if
self
.
totalWaitingTime
<
0
and
self
.
totalWaitingTime
>-
0.00001
:
#to avoid some effects of getting negative cause of rounding precision
if
activeObject
.
totalWaitingTime
<
0
and
activeObject
.
totalWaitingTime
>-
0.00001
:
#to avoid some effects of getting negative cause of rounding precision
self
.
totalWaitingTime
=
0
self
.
totalWaitingTime
=
0
self
.
Failure
.
append
(
100
*
self
.
totalFailureTime
/
MaxSimtime
)
activeObject
.
Failure
.
append
(
100
*
self
.
totalFailureTime
/
MaxSimtime
)
self
.
Blockage
.
append
(
100
*
self
.
totalBlockageTime
/
MaxSimtime
)
activeObject
.
Blockage
.
append
(
100
*
self
.
totalBlockageTime
/
MaxSimtime
)
self
.
Waiting
.
append
(
100
*
self
.
totalWaitingTime
/
MaxSimtime
)
activeObject
.
Waiting
.
append
(
100
*
self
.
totalWaitingTime
/
MaxSimtime
)
self
.
Working
.
append
(
100
*
self
.
totalWorkingTime
/
MaxSimtime
)
activeObject
.
Working
.
append
(
100
*
self
.
totalWorkingTime
/
MaxSimtime
)
#outputs message to the trace.xls. Format is (Simulation Time | Entity Name | message)
#outputs message to the trace.xls. Format is (Simulation Time | Entity Name | message)
def
outputTrace
(
self
,
message
):
def
outputTrace
(
self
,
message
):
...
@@ -353,8 +363,7 @@ class Machine(CoreObject):
...
@@ -353,8 +363,7 @@ class Machine(CoreObject):
#outputs the the "output.xls"
#outputs the the "output.xls"
def
outputResultsXL
(
self
,
MaxSimtime
):
def
outputResultsXL
(
self
,
MaxSimtime
):
from
Globals
import
G
from
Globals
import
G
if
(
G
.
numberOfReplications
==
1
):
#if we had just one replication output the results to excel
if
(
G
.
numberOfReplications
==
1
):
#if we had just one replication output the results to excel
G
.
outputSheet
.
write
(
G
.
outputIndex
,
0
,
"The percentage of Failure of "
+
self
.
objName
+
" is:"
)
G
.
outputSheet
.
write
(
G
.
outputIndex
,
0
,
"The percentage of Failure of "
+
self
.
objName
+
" is:"
)
G
.
outputSheet
.
write
(
G
.
outputIndex
,
1
,
100
*
self
.
totalFailureTime
/
MaxSimtime
)
G
.
outputSheet
.
write
(
G
.
outputIndex
,
1
,
100
*
self
.
totalFailureTime
/
MaxSimtime
)
G
.
outputIndex
+=
1
G
.
outputIndex
+=
1
...
...
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