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
62074e93
Commit
62074e93
authored
May 29, 2014
by
Ioannis Papagiannopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Router and Broker updated
parent
78428476
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
54 deletions
+74
-54
dream/simulation/OperatedPoolBroker.py
dream/simulation/OperatedPoolBroker.py
+58
-41
dream/simulation/OperatorRouter.py
dream/simulation/OperatorRouter.py
+16
-13
No files found.
dream/simulation/OperatedPoolBroker.py
View file @
62074e93
...
...
@@ -26,9 +26,10 @@ Created on 27 Nov 2013
Models an Interruption that handles the operating of a Station by an ObjectResource
'''
from
SimPy.Simulation
import
Process
,
Resource
,
SimEvent
# from SimPy.Simulation import Process, Resource, SimEvent
import
simpy
from
ObjectInterruption
import
ObjectInterruption
from
SimPy.Simulation
import
waituntil
,
now
,
hold
,
request
,
release
,
waitevent
#
from SimPy.Simulation import waituntil, now, hold, request, release, waitevent
# ===========================================================================
# Class that handles the Operator Behavior
...
...
@@ -48,8 +49,8 @@ class Broker(ObjectInterruption):
self
.
timeLastOperationEnded
=
0
self
.
timeWaitForOperatorStarted
=
0
# Broker events
self
.
isCalled
=
SimEvent
(
'brokerIsCalled'
)
self
.
resourceAvailable
=
SimEvent
(
'resourceAvailable'
)
self
.
isCalled
=
self
.
env
.
event
()
#
SimEvent('brokerIsCalled')
self
.
resourceAvailable
=
self
.
env
.
event
()
#
SimEvent('resourceAvailable')
self
.
waitForOperator
=
False
#===========================================================================
...
...
@@ -69,15 +70,16 @@ class Broker(ObjectInterruption):
def
run
(
self
):
while
1
:
# TODO: add new broker event - brokerIsCalled
yield
waitevent
,
self
,
self
.
isCalled
assert
self
.
isCalled
.
signalparam
==
now
(),
'the broker should be granted control instantly'
yield
self
.
isCalled
assert
self
.
isCalled
.
value
==
self
.
env
.
now
,
'the broker should be granted control instantly'
self
.
isCalled
=
self
.
env
.
event
()
self
.
victim
.
printTrace
(
self
.
victim
.
id
,
received
=
'(broker)'
)
# ======= request a resource
if
self
.
victim
.
isOperated
()
\
and
any
(
type
==
'Load'
or
type
==
'Setup'
or
type
==
'Processing'
\
for
type
in
self
.
victim
.
multOperationTypeList
):
# update the time that the station is waiting for the operator
self
.
timeWaitForOperatorStarted
=
now
()
self
.
timeWaitForOperatorStarted
=
self
.
env
.
now
#
()
#===============================================================
# if the victim already holds an entity that means that the machine's operation type
# is no Load or setup, in that case the router is already invoked and the machine is already assigned an operator
...
...
@@ -89,51 +91,66 @@ class Broker(ObjectInterruption):
if
not
G
.
Router
.
invoked
:
self
.
victim
.
printTrace
(
self
.
victim
.
id
,
signal
=
'router (broker)'
)
G
.
Router
.
invoked
=
True
G
.
Router
.
isCalled
.
s
ignal
(
now
()
)
G
.
Router
.
isCalled
.
s
ucceed
(
self
.
env
.
now
)
self
.
waitForOperator
=
True
self
.
victim
.
printTrace
(
self
.
victim
.
id
,
waitEvent
=
'(resourceIsAvailable broker)'
)
yield
waitevent
,
self
,
self
.
resourceAvailable
yield
self
.
resourceAvailable
self
.
resourceAvailable
=
self
.
env
.
event
()
# remove the currentEntity from the pendingEntities
if
self
.
victim
.
currentEntity
in
G
.
pendingEntities
:
G
.
pendingEntities
.
remove
(
self
.
victim
.
currentEntity
)
self
.
waitForOperator
=
False
self
.
victim
.
printTrace
(
self
.
victim
.
id
,
resourceAvailable
=
'(broker)'
)
#===============================================================
assert
self
.
victim
.
operatorPool
.
checkIfResourceIsAvailable
(),
'there is no available operator to request'
# set the available resource as the currentOperator
self
.
victim
.
currentOperator
=
self
.
victim
.
operatorPool
.
findAvailableOperator
()
yield
request
,
self
,
self
.
victim
.
operatorPool
.
getResource
(
self
.
victim
.
currentOperator
)
self
.
victim
.
printTrace
(
self
.
victim
.
currentOperator
.
objName
,
startWork
=
self
.
victim
.
id
)
# clear the timeWaitForOperatorStarted variable
self
.
timeWaitForOperatorStarted
=
0
# update the time that the operation started
self
.
timeOperationStarted
=
now
()
self
.
victim
.
outputTrace
(
self
.
victim
.
currentOperator
.
objName
,
"started work in "
+
self
.
victim
.
objName
)
self
.
victim
.
currentOperator
.
timeLastOperationStarted
=
now
()
# ======= release a resource
elif
not
self
.
victim
.
isOperated
():
self
.
victim
.
currentOperator
.
totalWorkingTime
+=
now
()
-
self
.
victim
.
currentOperator
.
timeLastOperationStarted
yield
release
,
self
,
self
.
victim
.
operatorPool
.
getResource
(
self
.
victim
.
currentOperator
)
# signal the other brokers waiting for the same operators that they are now free
# also signal the stations that were not requested to receive because the operator was occupied
# TODO: signalling the router must be done more elegantly, router must be set as global variable
# if the router is already invoked then do not signal it again
if
not
self
.
victim
.
router
.
invoked
:
self
.
victim
.
printTrace
(
self
.
victim
.
id
,
signal
=
'router (broker)'
)
self
.
victim
.
router
.
invoked
=
True
self
.
victim
.
router
.
isCalled
.
signal
(
now
())
# TODO: signalling the router will give the chance to it to take the control, but when will it eventually receive it.
# after signalling the broker will signal it's victim that it has finished it's processes
# TODO: this wont work for the moment. The actions that follow must be performed by all operated brokers.
self
.
victim
.
printTrace
(
self
.
victim
.
currentOperator
.
objName
,
finishWork
=
self
.
victim
.
id
)
# the victim current operator must be cleared after the operator is released
self
.
timeLastOperationEnded
=
now
()
self
.
victim
.
currentOperator
=
None
else
:
pass
# TODO: the victim must have a new event brokerIsSet
self
.
victim
.
brokerIsSet
.
signal
(
now
())
\ No newline at end of file
with
self
.
victim
.
operatorPool
.
getResource
(
self
.
victim
.
currentOperator
).
request
()
as
request
:
yield
request
self
.
victim
.
printTrace
(
self
.
victim
.
currentOperator
.
objName
,
startWork
=
self
.
victim
.
id
)
# clear the timeWaitForOperatorStarted variable
self
.
timeWaitForOperatorStarted
=
0
# update the time that the operation started
self
.
timeOperationStarted
=
self
.
env
.
now
#()
self
.
victim
.
outputTrace
(
self
.
victim
.
currentOperator
.
objName
,
"started work in "
+
self
.
victim
.
objName
)
self
.
victim
.
currentOperator
.
timeLastOperationStarted
=
self
.
env
.
now
#()
# signal the machine that an operator is reserved
self
.
victim
.
brokerIsSet
.
succeed
(
self
.
env
.
now
)
# wait till the processing is over
yield
self
.
isCalled
assert
self
.
isCalled
.
value
==
self
.
env
.
now
,
'the broker should be granted control instantly'
self
.
isCalled
=
self
.
env
.
event
()
# The operator is released
if
not
self
.
victim
.
isOperated
():
self
.
victim
.
currentOperator
.
totalWorkingTime
+=
self
.
env
.
now
-
self
.
victim
.
currentOperator
.
timeLastOperationStarted
# signal the other brokers waiting for the same operators that they are now free
# also signal the stations that were not requested to receive because the operator was occupied
# TODO: signalling the router must be done more elegantly, router must be set as global variable
# if the router is already invoked then do not signal it again
if
not
self
.
victim
.
router
.
invoked
:
self
.
victim
.
printTrace
(
self
.
victim
.
id
,
signal
=
'router (broker)'
)
self
.
victim
.
router
.
invoked
=
True
# self.victim.router.isCalled.signal(now())
self
.
victim
.
router
.
isCalled
.
succeed
(
self
.
env
.
now
)
# TODO: signalling the router will give the chance to it to take the control, but when will it eventually receive it.
# after signalling the broker will signal it's victim that it has finished it's processes
# TODO: this wont work for the moment. The actions that follow must be performed by all operated brokers.
self
.
victim
.
printTrace
(
self
.
victim
.
currentOperator
.
objName
,
finishWork
=
self
.
victim
.
id
)
# the victim current operator must be cleared after the operator is released
self
.
timeLastOperationEnded
=
self
.
env
.
now
self
.
victim
.
currentOperator
=
None
else
:
pass
# return the control to the victim
self
.
victim
.
brokerIsSet
.
succeed
(
self
.
env
.
now
)
dream/simulation/OperatorRouter.py
View file @
62074e93
...
...
@@ -25,9 +25,11 @@ Created on 19 Feb 2013
'''
Models an Interruption that schedules the operation of the machines by different managers
'''
from
SimPy.Globals
import
sim
from
SimPy.Simulation
import
Simulation
from
SimPy.Simulation
import
Process
,
Resource
,
SimEvent
# from SimPy.Globals import sim
# from SimPy.Simulation import Simulation
# from SimPy.Simulation import Process, Resource, SimEvent
import
simpy
from
ObjectInterruption
import
ObjectInterruption
from
SimPy.Simulation
import
waituntil
,
now
,
hold
,
request
,
release
,
waitevent
...
...
@@ -48,7 +50,7 @@ class Router(ObjectInterruption):
ObjectInterruption
.
__init__
(
self
)
self
.
type
=
"Router"
# signal used to initiate the generator of the Router
self
.
isCalled
=
SimEvent
(
'RouterIsCalled'
)
self
.
isCalled
=
self
.
env
.
event
(
)
self
.
isInitialized
=
False
self
.
candidateOperators
=
[]
self
.
multipleCriterionList
=
[]
...
...
@@ -118,14 +120,15 @@ class Router(ObjectInterruption):
break
while
1
:
# wait until the router is called
yield
waitevent
,
self
,
self
.
isCalled
yield
self
.
isCalled
self
.
isCalled
=
self
.
env
.
event
()
self
.
printTrace
(
''
,
'=-'
*
15
)
self
.
printTrace
(
''
,
'router received event'
)
# wait till there are no more events, the machines must be blocked
while
1
:
if
now
()
in
Simulation
.
allEventTimes
(
sim
):
if
self
.
env
.
now
==
self
.
env
.
peek
(
):
self
.
printTrace
(
''
,
'there are MORE events for now'
)
yield
hold
,
self
,
0
yield
self
.
env
.
timeout
(
0
)
else
:
self
.
printTrace
(
''
,
'there are NO more events for now'
)
break
...
...
@@ -277,28 +280,28 @@ class Router(ObjectInterruption):
operator
.
getResourceQueue
()[
0
].
victim
.
shouldPreempt
=
True
self
.
printTrace
(
'router'
,
'preempting '
+
operator
.
getResourceQueue
()[
0
].
victim
.
id
+
'.. '
*
6
)
operator
.
getResourceQueue
()[
0
].
victim
.
preempt
()
operator
.
getResourceQueue
()[
0
].
victim
.
timeLastEntityEnded
=
now
()
#required to count blockage correctly in the preemptied station
operator
.
getResourceQueue
()[
0
].
victim
.
timeLastEntityEnded
=
self
.
env
.
now
#required to count blockage correctly in the preemptied station
station
.
shouldPreempt
=
True
self
.
printTrace
(
'router'
,
'preempting receiver '
+
station
.
id
+
'.. '
*
6
)
station
.
preempt
()
station
.
timeLastEntityEnded
=
now
()
#required to count blockage correctly in the preemptied station
station
.
timeLastEntityEnded
=
self
.
env
.
now
#required to count blockage correctly in the preemptied station
elif
station
.
broker
.
waitForOperator
:
# signal this station's broker that the resource is available
self
.
printTrace
(
'router'
,
'signalling broker of'
+
' '
*
50
+
operator
.
isAssignedTo
().
id
)
station
.
broker
.
resourceAvailable
.
s
ignal
(
now
()
)
station
.
broker
.
resourceAvailable
.
s
ucceed
(
self
.
env
.
now
)
else
:
# signal the queue proceeding the station
if
station
.
canAccept
()
\
and
any
(
type
==
'Load'
for
type
in
station
.
multOperationTypeList
):
self
.
printTrace
(
'router'
,
'signalling'
+
' '
*
50
+
operator
.
isAssignedTo
().
id
)
station
.
loadOperatorAvailable
.
s
ignal
(
now
()
)
station
.
loadOperatorAvailable
.
s
ucceed
(
self
.
env
.
now
)
# in case the router deals with managed entities
#------------------------------------------------------------------------------
else
:
if
station
in
self
.
pendingMachines
and
station
in
self
.
toBeSignalled
:
# signal this station's broker that the resource is available
self
.
printTrace
(
'router'
,
'signalling broker of'
+
' '
*
50
+
operator
.
isAssignedTo
().
id
)
operator
.
isAssignedTo
().
broker
.
resourceAvailable
.
s
ignal
(
now
()
)
operator
.
isAssignedTo
().
broker
.
resourceAvailable
.
s
ucceed
(
self
.
env
.
now
)
elif
(
not
station
in
self
.
pendingMachines
)
or
(
not
station
in
self
.
toBeSignalled
):
# signal the queue proceeding the station
assert
operator
.
candidateEntity
.
currentStation
in
self
.
toBeSignalled
,
'the candidateEntity currentStation is not picked by the Router'
...
...
@@ -306,7 +309,7 @@ class Router(ObjectInterruption):
if
operator
.
candidateEntity
.
candidateReceiver
.
canAccept
()
\
and
any
(
type
==
'Load'
for
type
in
operator
.
candidateEntity
.
candidateReceiver
.
multOperationTypeList
):
self
.
printTrace
(
'router'
,
'signalling queue'
+
' '
*
50
+
operator
.
candidateEntity
.
currentStation
.
id
)
operator
.
candidateEntity
.
currentStation
.
loadOperatorAvailable
.
s
ignal
(
now
()
)
operator
.
candidateEntity
.
currentStation
.
loadOperatorAvailable
.
s
ucceed
(
self
.
env
.
now
)
#===========================================================================
# clear the pending lists of the router
...
...
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