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
Show 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
...
...
@@ -363,6 +363,94 @@ class Machine(CoreObject):
assert
eventTime
==
self
.
env
.
now
,
'brokerIsSet is not received on time'
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
...
...
@@ -457,27 +545,38 @@ class Machine(CoreObject):
self
.
loadTimeCurrentEntity
=
self
.
timeLoadEnded
-
self
.
timeLoadStarted
self
.
totalLoadTime
+=
self
.
loadTimeCurrentEntity
# ======= release a resource if the only operation type is Load
if
(
self
.
operatorPool
!=
"None"
)
\
and
any
(
type
==
"Load"
for
type
in
self
.
multOperationTypeList
)
\
and
not
(
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
)
\
or
any
(
type
==
"Setup"
for
type
in
self
.
multOperationTypeList
))
\
and
self
.
isOperated
():
# after getting the entity release the operator
# machine has to release the operator
self
.
releaseOperator
()
# wait until the Broker has finished processing
if
self
.
shouldYield
(
operationTypes
=
{
"Load"
:
1
,
"Processing"
:
0
,
"Setup"
:
0
},
methods
=
{
'isOperated'
:
1
}):
yield
self
.
env
.
process
(
self
.
release
())
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
yield
self
.
brokerIsSet
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
()
# yield self.env.process(self.loading())
# ======= release a resource if the only operation type is Load
# if (self.operatorPool!="None")\
# and any(type=="Load" for type in self.multOperationTypeList)\
# and not (any(type=="Processing" for type in self.multOperationTypeList)\
# or any(type=="Setup" for type in self.multOperationTypeList))\
# and self.isOperated():
# # 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()
#===================================================================
#===================================================================
#===================================================================
# # # getting entity
#===================================================================
#===================================================================
#===================================================================
# get the entity
# TODO: if there was loading time then we must solve the problem of getting an entity
...
...
@@ -488,6 +587,27 @@ class Machine(CoreObject):
# TODO: the Machine receive the entity after the operator is available
# 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
if
(
self
.
operatorPool
!=
"None"
)
\
and
(
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
)
\
...
...
@@ -510,10 +630,7 @@ class Machine(CoreObject):
self
.
timeWaitForOperatorEnded
=
self
.
env
.
now
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
# in plantSim the setup is performed when the machine has to process a new type of Entity and only once
...
...
@@ -539,25 +656,42 @@ class Machine(CoreObject):
# except:
# 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
if
(
self
.
operatorPool
!=
"None"
)
\
and
self
.
isOperated
()
\
and
(
any
(
type
==
"Setup"
for
type
in
self
.
multOperationTypeList
)
\
or
any
(
type
==
"Load"
for
type
in
self
.
multOperationTypeList
))
\
and
not
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
):
# after getting the entity release the operator
# machine has to release the operator
self
.
releaseOperator
()
# wait until the Broker has finished processing
# if (self.operatorPool!="None")\
# and self.isOperated()\
# and (any(type=="Setup" for type in self.multOperationTypeList)\
# or any(type=="Load" for type in self.multOperationTypeList))\
# and not any(type=="Processing" for type in self.multOperationTypeList):
# # 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()
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
yield
self
.
brokerIsSet
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
()
#===================================================================
#===================================================================
#===================================================================
# # # processing
#===================================================================
#===================================================================
#===================================================================
# variables used to flag any interruptions and the end of the processing
self
.
interruption
=
False
...
...
@@ -599,19 +733,26 @@ class Machine(CoreObject):
self
.
interruptionStart
=
self
.
env
.
event
()
self
.
interruptionActions
()
# execute interruption actions
# =============== release the operator if there is interruption
if
(
self
.
operatorPool
!=
"None"
)
\
and
self
.
isOperated
()
\
and
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
):
self
.
releaseOperator
()
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
yield
self
.
brokerIsSet
if
self
.
shouldYield
(
operationTypes
=
{
"Processing"
:
1
},
methods
=
{
'isOperated'
:
1
}):
yield
self
.
env
.
process
(
self
.
release
())
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
()
# =============== release the operator if there is interruption
# if (self.operatorPool!="None")\
# and self.isOperated()\
# and any(type=="Processing" for type in self.multOperationTypeList):
# self.releaseOperator()
#
# 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()
# loop until we reach at a state that there is no interruption
while
1
:
...
...
@@ -630,7 +771,7 @@ class Machine(CoreObject):
# =============== request a resource after the repair
if
(
self
.
operatorPool
!=
"None"
)
\
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
.
requestOperator
()
...
...
@@ -676,20 +817,25 @@ class Machine(CoreObject):
self
.
preemptQueue
=
self
.
env
.
event
()
self
.
interruptionActions
()
# execute interruption actions
# =============== release the operator if there is interruption
if
(
self
.
operatorPool
!=
"None"
)
\
and
self
.
isOperated
()
\
and
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
):
self
.
releaseOperator
()
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
if
self
.
shouldYield
(
operationTypes
=
{
"Processing"
:
1
},
methods
=
{
'isOperated'
:
1
}):
yield
self
.
env
.
process
(
self
.
release
())
yield
self
.
brokerIsSet
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
()
# =============== release the operator if there is interruption
# if (self.operatorPool!="None")\
# and self.isOperated()\
# and any(type=="Processing" for type in self.multOperationTypeList):
# self.releaseOperator()
#
# 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()
self
.
postInterruptionActions
()
break
...
...
@@ -700,21 +846,39 @@ class Machine(CoreObject):
# carry on actions that have to take place when an Entity ends its processing
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
if
(
self
.
operatorPool
!=
'None'
)
\
and
self
.
isOperated
()
\
and
any
(
type
==
"Processing"
for
type
in
self
.
multOperationTypeList
)
\
and
not
self
.
interruption
:
self
.
releaseOperator
()
# if (self.operatorPool!='None')\
# and self.isOperated()\
# and any(type=="Processing" for type in self.multOperationTypeList)\
# and not self.isInterrupted():
# self.releaseOperator()
#
# 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()
#===================================================================
#===================================================================
#===================================================================
# # # end of processing
#===================================================================
#===================================================================
#===================================================================
self
.
expectedSignals
[
'brokerIsSet'
]
=
1
yield
self
.
brokerIsSet
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
()
# signal the receiver that the activeObject has something to dispose of
if
not
self
.
signalReceiver
():
# if there was no available receiver, get into blocking control
...
...
@@ -726,8 +890,6 @@ class Machine(CoreObject):
# wait the event canDispose, this means that the station can deliver the item to successor
self
.
printTrace
(
self
.
id
,
waitEvent
=
'(canDispose or interruption start)'
)
receivedEvent
=
yield
self
.
env
.
any_of
([
self
.
canDispose
,
self
.
interruptionStart
])
# if there was interruption
# TODO not good implementation
...
...
@@ -900,6 +1062,12 @@ class Machine(CoreObject):
# set isBlocked to 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
# =======================================================================
...
...
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