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
c0573a03
Commit
c0573a03
authored
Jul 14, 2014
by
Ioannis Papagiannopoulos
Committed by
Georgios Dagkakis
Sep 01, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cherry-pick from readWIPseperatelly. unused code removed from simple Router
parent
accfa6d6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
244 deletions
+97
-244
dream/simulation/OperatorRouter.py
dream/simulation/OperatorRouter.py
+97
-244
No files found.
dream/simulation/OperatorRouter.py
View file @
c0573a03
...
@@ -25,14 +25,9 @@ Created on 19 Feb 2013
...
@@ -25,14 +25,9 @@ Created on 19 Feb 2013
'''
'''
Models an Interruption that schedules the operation of the machines by different managers
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
import
simpy
import
simpy
from
ObjectInterruption
import
ObjectInterruption
from
ObjectInterruption
import
ObjectInterruption
#from SimPy.Simulation import waituntil, now, hold, request, release, waitevent
# ===========================================================================
# ===========================================================================
# Class that handles the Operator Behavior
# Class that handles the Operator Behavior
...
@@ -60,8 +55,6 @@ class Router(ObjectInterruption):
...
@@ -60,8 +55,6 @@ class Router(ObjectInterruption):
self
.
toBeSignalled
=
[]
self
.
toBeSignalled
=
[]
# flag to notify whether the router is already invoked
# flag to notify whether the router is already invoked
self
.
invoked
=
False
self
.
invoked
=
False
# flag to notify whether the router is dealing with managed or simple entities
self
.
managed
=
False
self
.
criticalPending
=
[]
# list of critical entities that are pending
self
.
criticalPending
=
[]
# list of critical entities that are pending
self
.
preemptiveOperators
=
[]
# list of preemptiveOperators that should preempt their machines
self
.
preemptiveOperators
=
[]
# list of preemptiveOperators that should preempt their machines
...
@@ -92,7 +85,6 @@ class Router(ObjectInterruption):
...
@@ -92,7 +85,6 @@ class Router(ObjectInterruption):
self
.
isInitialized
=
True
self
.
isInitialized
=
True
self
.
invoked
=
False
self
.
invoked
=
False
self
.
managed
=
False
self
.
criticalPending
=
[]
self
.
criticalPending
=
[]
self
.
preemptiveOperators
=
[]
self
.
preemptiveOperators
=
[]
...
@@ -112,13 +104,6 @@ class Router(ObjectInterruption):
...
@@ -112,13 +104,6 @@ class Router(ObjectInterruption):
read the pendingEntities currentStations, these are the stations (queues) that may be signalled
read the pendingEntities currentStations, these are the stations (queues) that may be signalled
'''
'''
def
run
(
self
):
def
run
(
self
):
from
Globals
import
G
# find out whether we are dealing with managed entities
if
G
.
EntityList
:
for
entity
in
G
.
EntityList
:
if
entity
.
manager
:
self
.
managed
=
True
break
while
1
:
while
1
:
# wait until the router is called
# wait until the router is called
yield
self
.
isCalled
yield
self
.
isCalled
...
@@ -153,23 +138,11 @@ class Router(ObjectInterruption):
...
@@ -153,23 +138,11 @@ class Router(ObjectInterruption):
# assign operators to stations
# assign operators to stations
self
.
assignOperators
()
self
.
assignOperators
()
# if an exit of an object is assigned to one station, while the operator to operate
# the moving entity is assigned to a different, unAssign the exit
#------------------------------------------------------------------------------
if
not
self
.
managed
:
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
isAssignedTo
()]:
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
isAssignedTo
()]:
if
not
operator
.
isAssignedTo
()
in
self
.
pendingObjects
:
if
not
operator
.
isAssignedTo
()
in
self
.
pendingObjects
:
for
object
in
[
x
for
x
in
operator
.
isAssignedTo
().
previous
if
x
.
exitIsAssignedTo
()]:
for
object
in
[
x
for
x
in
operator
.
isAssignedTo
().
previous
if
x
.
exitIsAssignedTo
()]:
if
object
.
exitIsAssignedTo
()
!=
operator
.
isAssignedTo
():
if
object
.
exitIsAssignedTo
()
!=
operator
.
isAssignedTo
():
object
.
unAssignExit
()
object
.
unAssignExit
()
#------------------------------------------------------------------------------
else
:
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
isAssignedTo
()]:
if
not
operator
.
isAssignedTo
()
in
self
.
pendingObjects
:
if
operator
.
candidateEntity
.
currentStation
.
exitIsAssignedTo
():
if
operator
.
isAssignedTo
()
!=
operator
.
candidateEntity
.
currentStation
.
exitIsAssignedTo
():
operator
.
candidateEntity
.
currentStation
.
unAssignExit
()
# if an object cannot proceed with getEntity, unAssign the exit of its giver
# if an object cannot proceed with getEntity, unAssign the exit of its giver
for
object
in
self
.
pendingQueues
:
for
object
in
self
.
pendingQueues
:
if
not
object
in
self
.
toBeSignalled
:
if
not
object
in
self
.
toBeSignalled
:
...
@@ -188,11 +161,7 @@ class Router(ObjectInterruption):
...
@@ -188,11 +161,7 @@ class Router(ObjectInterruption):
# for all the operators that are requested
# for all the operators that are requested
for
operator
in
self
.
candidateOperators
:
for
operator
in
self
.
candidateOperators
:
# check if the candidateOperators are available, if the are requested and reside in the pendingObjects list
# check if the candidateOperators are available, if the are requested and reside in the pendingObjects list
#------------------------------------------------------------------------------
if
operator
.
checkIfResourceIsAvailable
():
if
operator
.
checkIfResourceIsAvailable
():
# if the router deals with managed entities
#------------------------------------------------------------------------------
if
not
self
.
managed
:
# if the operator is not conflicting
# if the operator is not conflicting
if
not
operator
in
self
.
conflictingOperators
:
if
not
operator
in
self
.
conflictingOperators
:
# assign an operator to the priorityObject
# assign an operator to the priorityObject
...
@@ -200,23 +169,8 @@ class Router(ObjectInterruption):
...
@@ -200,23 +169,8 @@ class Router(ObjectInterruption):
operator
.
assignTo
(
operator
.
candidateStation
)
operator
.
assignTo
(
operator
.
candidateStation
)
if
not
operator
.
candidateStation
in
self
.
toBeSignalled
:
if
not
operator
.
candidateStation
in
self
.
toBeSignalled
:
self
.
toBeSignalled
.
append
(
operator
.
candidateStation
)
self
.
toBeSignalled
.
append
(
operator
.
candidateStation
)
# if the router deals not with managed entities
#------------------------------------------------------------------------------
else
:
if
operator
.
candidateEntity
:
# and if the priorityObject is indeed pending
if
(
operator
.
candidateEntity
.
currentStation
in
self
.
pendingObjects
)
\
and
(
not
operator
in
self
.
conflictingOperators
)
\
and
operator
.
candidateEntity
.
candidateReceiver
:
# assign an operator to the priorityObject
self
.
printTrace
(
'router'
,
'will assign '
+
operator
.
id
+
' to --> '
+
operator
.
candidateEntity
.
candidateReceiver
.
id
)
operator
.
assignTo
(
operator
.
candidateEntity
.
candidateReceiver
)
if
not
operator
.
candidateEntity
.
currentStation
in
self
.
toBeSignalled
:
self
.
toBeSignalled
.
append
(
operator
.
candidateEntity
.
currentStation
)
# if there must be preemption performed
# if there must be preemption performed
#------------------------------------------------------------------------------
elif
operator
in
self
.
preemptiveOperators
and
not
operator
in
self
.
conflictingOperators
:
elif
operator
in
self
.
preemptiveOperators
and
not
operator
in
self
.
conflictingOperators
:
if
not
self
.
managed
:
# if the operator is not currently working on the candidateStation then the entity he is
# if the operator is not currently working on the candidateStation then the entity he is
# currently working on must be preempted, and he must be unassigned and assigned to the new station
# currently working on must be preempted, and he must be unassigned and assigned to the new station
if
operator
.
workingStation
!=
operator
.
candidateStation
:
if
operator
.
workingStation
!=
operator
.
candidateStation
:
...
@@ -267,12 +221,8 @@ class Router(ObjectInterruption):
...
@@ -267,12 +221,8 @@ class Router(ObjectInterruption):
for
operator
in
self
.
candidateOperators
:
for
operator
in
self
.
candidateOperators
:
station
=
operator
.
isAssignedTo
()
station
=
operator
.
isAssignedTo
()
if
station
:
if
station
:
# if the router deals with simple entities
#------------------------------------------------------------------------------
if
not
self
.
managed
:
assert
station
in
self
.
toBeSignalled
,
'the station must be in toBeSignalled list'
assert
station
in
self
.
toBeSignalled
,
'the station must be in toBeSignalled list'
# if the operator is preemptive
# if the operator is preemptive
#------------------------------------------------------------------------------
if
operator
in
self
.
preemptiveOperators
:
if
operator
in
self
.
preemptiveOperators
:
# if not assigned to the station currently working on, then preempt both stations
# if not assigned to the station currently working on, then preempt both stations
if
station
!=
operator
.
workingStation
:
if
station
!=
operator
.
workingStation
:
...
@@ -295,23 +245,6 @@ class Router(ObjectInterruption):
...
@@ -295,23 +245,6 @@ class Router(ObjectInterruption):
and
any
(
type
==
'Load'
for
type
in
station
.
multOperationTypeList
):
and
any
(
type
==
'Load'
for
type
in
station
.
multOperationTypeList
):
self
.
printTrace
(
'router'
,
'signalling'
+
' '
*
50
+
operator
.
isAssignedTo
().
id
)
self
.
printTrace
(
'router'
,
'signalling'
+
' '
*
50
+
operator
.
isAssignedTo
().
id
)
station
.
loadOperatorAvailable
.
succeed
(
self
.
env
.
now
)
station
.
loadOperatorAvailable
.
succeed
(
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
.
succeed
(
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'
assert
operator
.
candidateEntity
.
currentStation
in
G
.
QueueList
,
'the candidateEntity currentStation to receive signal from Router is not a queue'
if
operator
.
candidateEntity
.
candidateReceiver
.
canAccept
()
\
and
any
(
type
==
'Load'
for
type
in
operator
.
candidateEntity
.
candidateReceiver
.
multOperationTypeList
):
# if the station is already is already signalled then do not send event
if
not
operator
.
candidateEntity
.
currentStation
.
loadOperatorAvailable
.
triggered
:
self
.
printTrace
(
'router'
,
'signalling queue'
+
' '
*
50
+
operator
.
candidateEntity
.
currentStation
.
id
)
operator
.
candidateEntity
.
currentStation
.
loadOperatorAvailable
.
succeed
(
self
.
env
.
now
)
#===========================================================================
#===========================================================================
# clear the pending lists of the router
# clear the pending lists of the router
...
@@ -321,7 +254,6 @@ class Router(ObjectInterruption):
...
@@ -321,7 +254,6 @@ class Router(ObjectInterruption):
self
.
pendingMachines
=
[]
self
.
pendingMachines
=
[]
self
.
pendingObjects
=
[]
self
.
pendingObjects
=
[]
#===========================================================================
#===========================================================================
# find the stations that can be signalled by the router
# find the stations that can be signalled by the router
#===========================================================================
#===========================================================================
...
@@ -361,10 +293,6 @@ class Router(ObjectInterruption):
...
@@ -361,10 +293,6 @@ class Router(ObjectInterruption):
if
entity
.
isCritical
and
not
entity
in
self
.
criticalPending
:
if
entity
.
isCritical
and
not
entity
in
self
.
criticalPending
:
self
.
criticalPending
.
append
(
entity
)
self
.
criticalPending
.
append
(
entity
)
break
break
# find out which type of entities are we dealing with, managed entities or not
if
self
.
pending
:
if
self
.
pending
[
0
].
manager
:
self
.
managed
=
True
self
.
printTrace
(
'found pending entities'
+
'-'
*
12
+
'>'
,
[
str
(
entity
.
id
)
for
entity
in
self
.
pending
if
not
entity
.
type
==
'Part'
])
self
.
printTrace
(
'found pending entities'
+
'-'
*
12
+
'>'
,
[
str
(
entity
.
id
)
for
entity
in
self
.
pending
if
not
entity
.
type
==
'Part'
])
if
self
.
criticalPending
:
if
self
.
criticalPending
:
self
.
printTrace
(
'found pending critical'
+
'-'
*
12
+
'>'
,
[
str
(
entity
.
id
)
for
entity
in
self
.
criticalPending
if
not
entity
.
type
==
'Part'
])
self
.
printTrace
(
'found pending critical'
+
'-'
*
12
+
'>'
,
[
str
(
entity
.
id
)
for
entity
in
self
.
criticalPending
if
not
entity
.
type
==
'Part'
])
...
@@ -378,9 +306,6 @@ class Router(ObjectInterruption):
...
@@ -378,9 +306,6 @@ class Router(ObjectInterruption):
# . the candidate receivers of the entities (the stations the operators will be working at)
# . the candidate receivers of the entities (the stations the operators will be working at)
#========================================================================
#========================================================================
def
findCandidateOperators
(
self
):
def
findCandidateOperators
(
self
):
# if we are not dealing with managed entities
#------------------------------------------------------------------------------
if
not
self
.
managed
:
# for each pendingMachine
# for each pendingMachine
for
object
in
self
.
pendingMachines
:
for
object
in
self
.
pendingMachines
:
# find candidateOperators for each object operator
# find candidateOperators for each object operator
...
@@ -396,7 +321,6 @@ class Router(ObjectInterruption):
...
@@ -396,7 +321,6 @@ class Router(ObjectInterruption):
if
not
candidateOperator
in
self
.
candidateOperators
:
if
not
candidateOperator
in
self
.
candidateOperators
:
self
.
candidateOperators
.
append
(
candidateOperator
)
self
.
candidateOperators
.
append
(
candidateOperator
)
# check the option of preemption if there are critical entities and no available operators
# check the option of preemption if there are critical entities and no available operators
#------------------------------------------------------------------------------
if
not
object
.
findReceiversFor
(
object
)
and
\
if
not
object
.
findReceiversFor
(
object
)
and
\
any
(
entity
for
entity
in
object
.
getActiveObjectQueue
()
if
entity
.
isCritical
):
any
(
entity
for
entity
in
object
.
getActiveObjectQueue
()
if
entity
.
isCritical
):
# for each of the following objects
# for each of the following objects
...
@@ -419,28 +343,9 @@ class Router(ObjectInterruption):
...
@@ -419,28 +343,9 @@ class Router(ObjectInterruption):
# self.candidateOperators.append(preemptiveOperator)
# self.candidateOperators.append(preemptiveOperator)
# self.preemptiveOperators.append(preemptiveOperator)
# self.preemptiveOperators.append(preemptiveOperator)
# in case the router deals with managed entities
#------------------------------------------------------------------------------
else
:
# if there are pendingEntities
if
len
(
self
.
pending
):
# for those pending entities that require a manager (MachineManagedJob case)
for
entity
in
[
x
for
x
in
self
.
pending
if
x
.
manager
]:
# if the entity is ready to move to a machine and its manager is available
if
entity
.
manager
.
checkIfResourceIsAvailable
():
# check whether the entity canProceed and update the its candidateReceivers
if
entity
.
canProceed
()
\
and
not
entity
.
manager
in
self
.
candidateOperators
:
self
.
candidateOperators
.
append
(
entity
.
manager
)
# TODO: check if preemption can be implemented for the managed case
# find the candidateEntities for each operator
self
.
findCandidateEntities
()
# update the schedulingRule/multipleCriterionList of the Router
# update the schedulingRule/multipleCriterionList of the Router
if
self
.
sorting
:
if
self
.
sorting
:
self
.
updateSchedulingRule
()
self
.
updateSchedulingRule
()
if
self
.
managed
:
self
.
printTrace
(
'router found candidate operators'
+
' '
*
3
,[
operator
.
id
for
operator
in
self
.
candidateOperators
])
else
:
self
.
printTrace
(
'router found candidate operators'
+
' '
*
3
,
self
.
printTrace
(
'router found candidate operators'
+
' '
*
3
,
[(
operator
.
id
,
[
station
.
id
for
station
in
operator
.
candidateStations
])
for
operator
in
self
.
candidateOperators
])
[(
operator
.
id
,
[
station
.
id
for
station
in
operator
.
candidateStations
])
for
operator
in
self
.
candidateOperators
])
...
@@ -509,11 +414,6 @@ class Router(ObjectInterruption):
...
@@ -509,11 +414,6 @@ class Router(ObjectInterruption):
if
operatorsWithOneOption
:
if
operatorsWithOneOption
:
self
.
candidateOperators
.
sort
(
key
=
lambda
x
:
x
in
operatorsWithOneOption
,
reverse
=
True
)
self
.
candidateOperators
.
sort
(
key
=
lambda
x
:
x
in
operatorsWithOneOption
,
reverse
=
True
)
if
self
.
managed
:
self
.
printTrace
(
'candidateEntities for each operator'
,
\
[(
str
(
operator
.
id
),[
str
(
x
.
id
)
for
x
in
operator
.
candidateEntities
])
for
operator
in
self
.
candidateOperators
])
#=======================================================================
#=======================================================================
# Sort pendingEntities
# Sort pendingEntities
# TODO: sorting them according to the operators schedulingRule
# TODO: sorting them according to the operators schedulingRule
...
@@ -547,7 +447,6 @@ class Router(ObjectInterruption):
...
@@ -547,7 +447,6 @@ class Router(ObjectInterruption):
# finally we have to sort before giving the entities to the operators
# finally we have to sort before giving the entities to the operators
# If there is an entity which must have priority then it should be assigned first
# If there is an entity which must have priority then it should be assigned first
# TODO: sorting after choosing candidateEntity
# TODO: sorting after choosing candidateEntity
if
not
self
.
managed
:
# for the candidateOperators that do have candidateEntities pick a candidateEntity
# for the candidateOperators that do have candidateEntities pick a candidateEntity
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
candidateStations
]:
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
candidateStations
]:
# find the first available entity that has no occupied receivers
# find the first available entity that has no occupied receivers
...
@@ -573,52 +472,6 @@ class Router(ObjectInterruption):
...
@@ -573,52 +472,6 @@ class Router(ObjectInterruption):
if
conflictingGroup
.
index
(
operator
)
!=
0
:
if
conflictingGroup
.
index
(
operator
)
!=
0
:
self
.
candidateOperators
.
remove
(
operator
)
self
.
candidateOperators
.
remove
(
operator
)
# if the moving entities are managed
#------------------------------------------------------------------------------
else
:
# for the candidateOperators that do have candidateEntities pick a candidateEntity
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
candidateEntities
]:
# find the first available entity that has no occupied receivers
operator
.
candidateEntity
=
operator
.
findCandidateEntity
()
if
operator
.
candidateEntity
:
if
operator
.
candidateEntity
.
currentStation
in
self
.
pendingMachines
:
operator
.
candidateEntity
.
candidateReceiver
=
operator
.
candidateEntity
.
currentStation
else
:
operator
.
candidateEntity
.
candidateReceiver
=
operator
.
candidateEntity
.
findCandidateReceiver
()
# find the resources that are 'competing' for the same station
if
not
self
.
sorting
:
# if there are entities that have conflicting receivers
if
len
(
self
.
conflictingEntities
):
# find the conflictingOperators
self
.
conflictingOperators
=
[
operator
for
operator
in
self
.
candidateOperators
\
if
operator
.
candidateEntity
in
self
.
conflictingEntities
or
\
operator
.
candidateEntity
.
candidateReceiver
in
[
x
.
candidateReceiver
for
x
in
self
.
conflictingEntities
]]
# keep the sorting provided by the queues if there is conflict between operators
conflictingGroup
=
[]
# list that holds the operators that have the same recipient
if
len
(
self
.
conflictingOperators
):
# for each of the candidateReceivers
for
receiver
in
[
x
.
candidateEntity
.
candidateReceiver
for
x
in
self
.
conflictingOperators
]:
# find the group of operators that compete for this station
conflictingGroup
=
[
operator
for
operator
in
self
.
conflictingOperators
if
operator
.
candidateEntity
.
candidateReceiver
==
receiver
]
assert
len
([
station
for
station
in
[
x
.
candidateEntity
.
currentStation
for
x
in
conflictingGroup
]]),
\
'the conflicting entities must reside in the same queue'
# for each of the competing for the same station operators
for
operator
in
conflictingGroup
:
# find the index of entities to be operated by them in the queue that holds them
operator
.
ind
=
operator
.
candidateEntity
.
currentStation
.
getActiveObjectQueue
().
index
(
operator
.
candidateEntity
)
# the operator that can proceed is the manager of the entity as sorted by the queue that holds them
conflictingGroup
.
sort
(
key
=
lambda
x
:
x
.
ind
)
# the operators that are not first in the list cannot proceed
for
operator
in
conflictingGroup
:
if
conflictingGroup
.
index
(
operator
)
!=
0
:
self
.
candidateOperators
.
remove
(
operator
)
if
self
.
managed
:
self
.
printTrace
(
'candidateReceivers for each entity '
,[(
str
(
entity
.
id
),
\
str
(
entity
.
candidateReceiver
.
id
))
for
entity
in
self
.
pending
if
entity
.
candidateReceiver
])
# =======================================================================
# =======================================================================
# sorts the Operators of the Queue according to the scheduling rule
# sorts the Operators of the Queue according to the scheduling rule
# =======================================================================
# =======================================================================
...
...
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