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
94ec1168
Commit
94ec1168
authored
Sep 10, 2014
by
Ioannis Papagiannopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new process added to Machine to handle the release of the operator resource.
parent
20e93ba0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
260 additions
and
92 deletions
+260
-92
dream/simulation/Machine.py
dream/simulation/Machine.py
+260
-92
No files found.
dream/simulation/Machine.py
View file @
94ec1168
...
@@ -362,7 +362,95 @@ class Machine(CoreObject):
...
@@ -362,7 +362,95 @@ class Machine(CoreObject):
assert
transmitter
==
self
.
broker
,
'brokerIsSet is not sent by the stations broker'
assert
transmitter
==
self
.
broker
,
'brokerIsSet is not sent by the stations broker'
assert
eventTime
==
self
.
env
.
now
,
'brokerIsSet is not received on time'
assert
eventTime
==
self
.
env
.
now
,
'brokerIsSet is not received on time'
self
.
brokerIsSet
=
self
.
env
.
event
()
self
.
brokerIsSet
=
self
.
env
.
event
()
#===========================================================================
# method controlling if there is a need to yield
#===========================================================================
def
shouldYield
(
self
,
operationTypes
=
{},
methods
=
{}):
'''
"methods":{'isInterrupted':'0'},
"operationTypes"={"Processing":1, % must
"Setup":0 % must NOT
}
'''
operationsRequired
=
[]
operationsNotRequired
=
[]
opRequest
=
True
if
operationTypes
:
for
operationType
,
func
in
operationTypes
.
iteritems
():
tup
=
(
operationType
,
func
)
if
bool
(
func
):
operationsRequired
.
append
(
tup
)
else
:
operationsNotRequired
.
append
(
tup
)
required
=
False
if
operationsRequired
:
for
opTup
in
operationsRequired
:
operation
,
func
=
opTup
required
=
required
or
(
any
(
type
==
str
(
operation
)
for
type
in
self
.
multOperationTypeList
))
else
:
required
=
True
notRequired
=
False
if
operationsNotRequired
:
for
opTup
in
operationsNotRequired
:
operation
,
func
=
opTup
notRequired
=
notRequired
or
(
any
(
type
==
str
(
operation
)
for
type
in
self
.
multOperationTypeList
))
opRequest
=
required
and
not
notRequired
methodsRequired
=
[]
methodsNotRequired
=
[]
methodsRequest
=
True
if
methods
:
for
methodType
,
func
in
methods
.
iteritems
():
tup
=
(
methodType
,
func
)
if
bool
(
func
):
methodsRequired
.
append
(
tup
)
else
:
methodsNotRequired
.
append
(
tup
)
required
=
False
from
Globals
import
getMethodFromName
# print ' '*20, 'Requested methods'
if
methodsRequired
:
for
methodTup
in
methodsRequired
:
method
,
func
=
methodTup
# print ' '*20,method,
objMethod
=
getMethodFromName
(
'Dream.Machine.'
+
method
)
# print objMethod(self)
required
=
required
or
(
objMethod
(
self
))
else
:
required
=
True
notRequired
=
False
# print ' '*20, 'not Requested methods'
if
methodsNotRequired
:
for
methodTup
in
methodsNotRequired
:
method
,
func
=
methodTup
# print ' '*20,method,
objMethod
=
getMethodFromName
(
'Dream.Machine.'
+
method
)
# print objMethod(self)
notRequired
=
notRequired
or
(
objMethod
(
self
))
methodsRequest
=
required
and
not
notRequired
if
(
self
.
operatorPool
!=
"None"
)
\
and
opRequest
\
and
methodsRequest
:
return
True
return
False
#===========================================================================
# yielding for the broker process
#===========================================================================
def
release
(
self
):
# after getting the entity release the operator
# machine has to release the operator
self
.
releaseOperator
()
# wait until the Broker has finished processing
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
yield
self
.
brokerIsSet
self
.
expectedSignals
[
'brokerIsSet'
]
=
0
transmitter
,
eventTime
=
self
.
brokerIsSet
.
value
assert
transmitter
==
self
.
broker
,
'brokerIsSet is not sent by the stations broker'
assert
eventTime
==
self
.
env
.
now
,
'brokerIsSet is not received on time'
self
.
brokerIsSet
=
self
.
env
.
event
()
# =======================================================================
# =======================================================================
# the main process of the machine
# the main process of the machine
...
@@ -435,9 +523,9 @@ class Machine(CoreObject):
...
@@ -435,9 +523,9 @@ class Machine(CoreObject):
self
.
requestOperator
()
self
.
requestOperator
()
self
.
timeWaitForLoadOperatorStarted
=
self
.
env
.
now
self
.
timeWaitForLoadOperatorStarted
=
self
.
env
.
now
# wait until the Broker has waited times equal to loadTime (if any)
# wait until the Broker has waited times equal to loadTime (if any)
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
yield
self
.
brokerIsSet
yield
self
.
brokerIsSet
transmitter
,
eventTime
=
self
.
brokerIsSet
.
value
transmitter
,
eventTime
=
self
.
brokerIsSet
.
value
...
@@ -447,7 +535,7 @@ class Machine(CoreObject):
...
@@ -447,7 +535,7 @@ class Machine(CoreObject):
self
.
timeWaitForLoadOperatorEnded
=
self
.
env
.
now
self
.
timeWaitForLoadOperatorEnded
=
self
.
env
.
now
self
.
loadOperatorWaitTimeCurrentEntity
+=
self
.
timeWaitForLoadOperatorEnded
-
self
.
timeWaitForLoadOperatorStarted
self
.
loadOperatorWaitTimeCurrentEntity
+=
self
.
timeWaitForLoadOperatorEnded
-
self
.
timeWaitForLoadOperatorStarted
self
.
totalTimeWaitingForLoadOperator
+=
self
.
loadOperatorWaitTimeCurrentEntity
self
.
totalTimeWaitingForLoadOperator
+=
self
.
loadOperatorWaitTimeCurrentEntity
# ======= Load the machine if the Load is defined as one of the Operators' operation types
# ======= Load the machine if the Load is defined as one of the Operators' operation types
if
any
(
type
==
"Load"
for
type
in
self
.
multOperationTypeList
)
and
self
.
isOperated
():
if
any
(
type
==
"Load"
for
type
in
self
.
multOperationTypeList
)
and
self
.
isOperated
():
self
.
timeLoadStarted
=
self
.
env
.
now
self
.
timeLoadStarted
=
self
.
env
.
now
...
@@ -456,28 +544,39 @@ class Machine(CoreObject):
...
@@ -456,28 +544,39 @@ class Machine(CoreObject):
self
.
timeLoadEnded
=
self
.
env
.
now
self
.
timeLoadEnded
=
self
.
env
.
now
self
.
loadTimeCurrentEntity
=
self
.
timeLoadEnded
-
self
.
timeLoadStarted
self
.
loadTimeCurrentEntity
=
self
.
timeLoadEnded
-
self
.
timeLoadStarted
self
.
totalLoadTime
+=
self
.
loadTimeCurrentEntity
self
.
totalLoadTime
+=
self
.
loadTimeCurrentEntity
if
self
.
shouldYield
(
operationTypes
=
{
"Load"
:
1
,
"Processing"
:
0
,
"Setup"
:
0
},
methods
=
{
'isOperated'
:
1
}):
yield
self
.
env
.
process
(
self
.
release
())
# ======= release a resource if the only operation type is Load
# ======= release a resource if the only operation type is Load
if
(
self
.
operatorPool
!=
"None"
)
\
# if (self.operatorPool!="None")\
and
any
(
type
==
"Load"
for
type
in
self
.
multOperationTypeList
)
\
# and any(type=="Load" for type in self.multOperationTypeList)\
and
not
(
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
)
\
# and not (any(type=="Processing" for type in self.multOperationTypeList)\
or
any
(
type
==
"Setup"
for
type
in
self
.
multOperationTypeList
))
\
# or any(type=="Setup" for type in self.multOperationTypeList))\
and
self
.
isOperated
():
# and self.isOperated():
# after getting the entity release the operator
# # after getting the entity release the operator
# machine has to release the operator
# # machine has to release the operator
self
.
releaseOperator
()
# self.releaseOperator()
# wait until the Broker has finished processing
# # wait until the Broker has finished processing
#
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
# self.expectedSignals['brokerIsSet']=1
#
yield
self
.
brokerIsSet
# yield self.brokerIsSet
#
transmitter
,
eventTime
=
self
.
brokerIsSet
.
value
# self.expectedSignals['brokerIsSet']=0
assert
transmitter
==
self
.
broker
,
'brokerIsSet is not sent by the stations broker'
#
assert
eventTime
==
self
.
env
.
now
,
'brokerIsSet is not received on time'
# transmitter, eventTime=self.brokerIsSet.value
self
.
brokerIsSet
=
self
.
env
.
event
()
# assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
# assert eventTime==self.env.now, 'brokerIsSet is not received on time'
# self.brokerIsSet=self.env.event()
# yield self.env.process(self.loading())
#===================================================================
#===================================================================
#===================================================================
# # # getting entity
#===================================================================
#===================================================================
#===================================================================
# get the entity
# get the entity
# TODO: if there was loading time then we must solve the problem of getting an entity
# TODO: if there was loading time then we must solve the problem of getting an entity
...
@@ -486,7 +585,28 @@ class Machine(CoreObject):
...
@@ -486,7 +585,28 @@ class Machine(CoreObject):
if
not
self
.
isProcessingInitialWIP
:
# if we are in the state of having initial wip no need to take an Entity
if
not
self
.
isProcessingInitialWIP
:
# if we are in the state of having initial wip no need to take an Entity
self
.
currentEntity
=
self
.
getEntity
()
self
.
currentEntity
=
self
.
getEntity
()
# TODO: the Machine receive the entity after the operator is available
# TODO: the Machine receive the entity after the operator is available
# the canAcceptAndIsRequested method checks only in case of Load type of operation
# the canAcceptAndIsRequested method checks only in case of Load type of operation
# variables dedicated to hold the processing times, the time when the Entity entered,
# and the processing time left
self
.
totalProcessingTimeInCurrentEntity
=
self
.
calculateProcessingTime
()
# get the processing time, tinMStarts holds the processing time of the machine
self
.
tinM
=
self
.
totalProcessingTimeInCurrentEntity
# timer to hold the processing time left
#===================================================================
#===================================================================
#===================================================================
# # # setup
#===================================================================
#===================================================================
#===================================================================
# ======= request a resource if it is not already assigned an Operator
# ======= request a resource if it is not already assigned an Operator
if
(
self
.
operatorPool
!=
"None"
)
\
if
(
self
.
operatorPool
!=
"None"
)
\
...
@@ -510,10 +630,7 @@ class Machine(CoreObject):
...
@@ -510,10 +630,7 @@ class Machine(CoreObject):
self
.
timeWaitForOperatorEnded
=
self
.
env
.
now
self
.
timeWaitForOperatorEnded
=
self
.
env
.
now
self
.
operatorWaitTimeCurrentEntity
+=
self
.
timeWaitForOperatorEnded
-
self
.
timeWaitForOperatorStarted
self
.
operatorWaitTimeCurrentEntity
+=
self
.
timeWaitForOperatorEnded
-
self
.
timeWaitForOperatorStarted
# variables dedicated to hold the processing times, the time when the Entity entered,
# and the processing time left
self
.
totalProcessingTimeInCurrentEntity
=
self
.
calculateProcessingTime
()
# get the processing time, tinMStarts holds the processing time of the machine
self
.
tinM
=
self
.
totalProcessingTimeInCurrentEntity
# timer to hold the processing time left
# ======= setup the machine if the Setup is defined as one of the Operators' operation types
# ======= setup the machine if the Setup is defined as one of the Operators' operation types
# in plantSim the setup is performed when the machine has to process a new type of Entity and only once
# in plantSim the setup is performed when the machine has to process a new type of Entity and only once
...
@@ -538,27 +655,44 @@ class Machine(CoreObject):
...
@@ -538,27 +655,44 @@ class Machine(CoreObject):
# self.totalSetupTime += self.setupTimeCurrentEntity
# self.totalSetupTime += self.setupTimeCurrentEntity
# except:
# except:
# pass
# pass
if
self
.
shouldYield
(
operationTypes
=
{
"Setup"
:
1
,
"Load"
:
1
,
"Processing"
:
0
},
methods
=
{
'isOperated'
:
1
}):
yield
self
.
env
.
process
(
self
.
release
())
# ======= release a resource if the only operation type is Setup
# ======= release a resource if the only operation type is Setup
if
(
self
.
operatorPool
!=
"None"
)
\
# if (self.operatorPool!="None")\
and
self
.
isOperated
()
\
# and self.isOperated()\
and
(
any
(
type
==
"Setup"
for
type
in
self
.
multOperationTypeList
)
\
# and (any(type=="Setup" for type in self.multOperationTypeList)\
or
any
(
type
==
"Load"
for
type
in
self
.
multOperationTypeList
))
\
# or any(type=="Load" for type in self.multOperationTypeList))\
and
not
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
):
# and not any(type=="Processing" for type in self.multOperationTypeList):
# after getting the entity release the operator
# # after getting the entity release the operator
# machine has to release the operator
# # machine has to release the operator
self
.
releaseOperator
()
# self.releaseOperator()
# wait until the Broker has finished processing
# # wait until the Broker has finished processing
#
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
# self.expectedSignals['brokerIsSet']=1
#
yield
self
.
brokerIsSet
# yield self.brokerIsSet
#
transmitter
,
eventTime
=
self
.
brokerIsSet
.
value
# self.expectedSignals['brokerIsSet']=0
assert
transmitter
==
self
.
broker
,
'brokerIsSet is not sent by the stations broker'
#
assert
eventTime
==
self
.
env
.
now
,
'brokerIsSet is not received on time'
# transmitter, eventTime=self.brokerIsSet.value
self
.
brokerIsSet
=
self
.
env
.
event
()
# assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
# assert eventTime==self.env.now, 'brokerIsSet is not received on time'
# self.brokerIsSet=self.env.event()
#===================================================================
#===================================================================
#===================================================================
# # # processing
#===================================================================
#===================================================================
#===================================================================
# variables used to flag any interruptions and the end of the processing
# variables used to flag any interruptions and the end of the processing
self
.
interruption
=
False
self
.
interruption
=
False
processingNotFinished
=
True
processingNotFinished
=
True
...
@@ -599,19 +733,26 @@ class Machine(CoreObject):
...
@@ -599,19 +733,26 @@ class Machine(CoreObject):
self
.
interruptionStart
=
self
.
env
.
event
()
self
.
interruptionStart
=
self
.
env
.
event
()
self
.
interruptionActions
()
# execute interruption actions
self
.
interruptionActions
()
# execute interruption actions
if
self
.
shouldYield
(
operationTypes
=
{
"Processing"
:
1
},
methods
=
{
'isOperated'
:
1
}):
yield
self
.
env
.
process
(
self
.
release
())
# =============== release the operator if there is interruption
# =============== release the operator if there is interruption
if
(
self
.
operatorPool
!=
"None"
)
\
# if (self.operatorPool!="None")\
and
self
.
isOperated
()
\
# and self.isOperated()\
and
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
):
# and any(type=="Processing" for type in self.multOperationTypeList):
self
.
releaseOperator
()
# self.releaseOperator()
#
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
# self.expectedSignals['brokerIsSet']=1
yield
self
.
brokerIsSet
#
# yield self.brokerIsSet
transmitter
,
eventTime
=
self
.
brokerIsSet
.
value
#
assert
transmitter
==
self
.
broker
,
'brokerIsSet is not sent by the stations broker'
# self.expectedSignals['brokerIsSet']=0
assert
eventTime
==
self
.
env
.
now
,
'brokerIsSet is not received on time'
#
self
.
brokerIsSet
=
self
.
env
.
event
()
# transmitter, eventTime=self.brokerIsSet.value
# assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
# assert eventTime==self.env.now, 'brokerIsSet is not received on time'
# self.brokerIsSet=self.env.event()
# loop until we reach at a state that there is no interruption
# loop until we reach at a state that there is no interruption
while
1
:
while
1
:
...
@@ -630,7 +771,7 @@ class Machine(CoreObject):
...
@@ -630,7 +771,7 @@ class Machine(CoreObject):
# =============== request a resource after the repair
# =============== request a resource after the repair
if
(
self
.
operatorPool
!=
"None"
)
\
if
(
self
.
operatorPool
!=
"None"
)
\
and
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
)
\
and
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
)
\
and
not
self
.
i
nterruption
:
and
not
self
.
i
sInterrupted
()
:
self
.
timeWaitForOperatorStarted
=
self
.
env
.
now
self
.
timeWaitForOperatorStarted
=
self
.
env
.
now
self
.
requestOperator
()
self
.
requestOperator
()
...
@@ -675,21 +816,26 @@ class Machine(CoreObject):
...
@@ -675,21 +816,26 @@ class Machine(CoreObject):
assert
eventTime
==
self
.
env
.
now
,
'the preemption must be performed on the time of request'
assert
eventTime
==
self
.
env
.
now
,
'the preemption must be performed on the time of request'
self
.
preemptQueue
=
self
.
env
.
event
()
self
.
preemptQueue
=
self
.
env
.
event
()
self
.
interruptionActions
()
# execute interruption actions
self
.
interruptionActions
()
# execute interruption actions
if
self
.
shouldYield
(
operationTypes
=
{
"Processing"
:
1
},
methods
=
{
'isOperated'
:
1
}):
yield
self
.
env
.
process
(
self
.
release
())
# =============== release the operator if there is interruption
# =============== release the operator if there is interruption
if
(
self
.
operatorPool
!=
"None"
)
\
# if (self.operatorPool!="None")\
and
self
.
isOperated
()
\
# and self.isOperated()\
and
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
):
# and any(type=="Processing" for type in self.multOperationTypeList):
self
.
releaseOperator
()
# self.releaseOperator()
#
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
# self.expectedSignals['brokerIsSet']=1
#
yield
self
.
brokerIsSet
# yield self.brokerIsSet
#
transmitter
,
eventTime
=
self
.
brokerIsSet
.
value
# self.expectedSignals['brokerIsSet']=0
assert
transmitter
==
self
.
broker
,
'brokerIsSet is not sent by the stations broker'
#
assert
eventTime
==
self
.
env
.
now
,
'brokerIsSet is not received on time'
# transmitter, eventTime=self.brokerIsSet.value
self
.
brokerIsSet
=
self
.
env
.
event
()
# assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
# assert eventTime==self.env.now, 'brokerIsSet is not received on time'
# self.brokerIsSet=self.env.event()
self
.
postInterruptionActions
()
self
.
postInterruptionActions
()
break
break
...
@@ -700,21 +846,39 @@ class Machine(CoreObject):
...
@@ -700,21 +846,39 @@ class Machine(CoreObject):
# carry on actions that have to take place when an Entity ends its processing
# carry on actions that have to take place when an Entity ends its processing
self
.
endProcessingActions
()
self
.
endProcessingActions
()
if
self
.
shouldYield
(
operationTypes
=
{
"Processing"
:
1
},
methods
=
{
'isInterrupted'
:
0
,
'isOperated'
:
1
}):
yield
self
.
env
.
process
(
self
.
release
())
# =============== release resource after the end of processing
# =============== release resource after the end of processing
if
(
self
.
operatorPool
!=
'None'
)
\
# if (self.operatorPool!='None')\
and
self
.
isOperated
()
\
# and self.isOperated()\
and
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
)
\
# and any(type=="Processing" for type in self.multOperationTypeList)\
and
not
self
.
interruption
:
# and not self.isInterrupted():
self
.
releaseOperator
()
# self.releaseOperator()
#
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
# self.expectedSignals['brokerIsSet']=1
#
yield
self
.
brokerIsSet
# yield self.brokerIsSet
#
transmitter
,
eventTime
=
self
.
brokerIsSet
.
value
# self.expectedSignals['brokerIsSet']=0
assert
transmitter
==
self
.
broker
,
'brokerIsSet is not sent by the stations broker'
#
assert
eventTime
==
self
.
env
.
now
,
'brokerIsSet is not received on time'
# transmitter, eventTime=self.brokerIsSet.value
self
.
brokerIsSet
=
self
.
env
.
event
()
# assert transmitter==self.broker, 'brokerIsSet is not sent by the stations broker'
# assert eventTime==self.env.now, 'brokerIsSet is not received on time'
# self.brokerIsSet=self.env.event()
#===================================================================
#===================================================================
#===================================================================
# # # end of processing
#===================================================================
#===================================================================
#===================================================================
# signal the receiver that the activeObject has something to dispose of
# signal the receiver that the activeObject has something to dispose of
if
not
self
.
signalReceiver
():
if
not
self
.
signalReceiver
():
# if there was no available receiver, get into blocking control
# if there was no available receiver, get into blocking control
...
@@ -726,8 +890,6 @@ class Machine(CoreObject):
...
@@ -726,8 +890,6 @@ class Machine(CoreObject):
# wait the event canDispose, this means that the station can deliver the item to successor
# wait the event canDispose, this means that the station can deliver the item to successor
self
.
printTrace
(
self
.
id
,
waitEvent
=
'(canDispose or interruption start)'
)
self
.
printTrace
(
self
.
id
,
waitEvent
=
'(canDispose or interruption start)'
)
receivedEvent
=
yield
self
.
env
.
any_of
([
self
.
canDispose
,
self
.
interruptionStart
])
receivedEvent
=
yield
self
.
env
.
any_of
([
self
.
canDispose
,
self
.
interruptionStart
])
# if there was interruption
# if there was interruption
# TODO not good implementation
# TODO not good implementation
...
@@ -900,6 +1062,12 @@ class Machine(CoreObject):
...
@@ -900,6 +1062,12 @@ class Machine(CoreObject):
# set isBlocked to False
# set isBlocked to False
self
.
isBlocked
=
False
self
.
isBlocked
=
False
#===========================================================================
# returns true if the station is interrupted
#===========================================================================
def
isInterrupted
(
self
):
return
self
.
interruption
# =======================================================================
# =======================================================================
# actions to be carried out when the processing of an Entity ends
# actions to be carried out when the processing of an Entity ends
# =======================================================================
# =======================================================================
...
...
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