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
69065e15
Commit
69065e15
authored
Sep 23, 2014
by
Ioannis Papagiannopoulos
Committed by
Jérome Perrin
Feb 04, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OperatorRouterManaged clean-up
parent
c148a1f1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
95 additions
and
359 deletions
+95
-359
dream/simulation/Job.py
dream/simulation/Job.py
+1
-8
dream/simulation/OperatorManagedJob.py
dream/simulation/OperatorManagedJob.py
+4
-5
dream/simulation/OperatorRouter.py
dream/simulation/OperatorRouter.py
+1
-3
dream/simulation/OperatorRouterManaged.py
dream/simulation/OperatorRouterManaged.py
+83
-318
dream/simulation/SkilledOperatorRouter.py
dream/simulation/SkilledOperatorRouter.py
+6
-25
No files found.
dream/simulation/Job.py
View file @
69065e15
...
@@ -120,13 +120,6 @@ class Job(Entity): # inherits from the Entity c
...
@@ -120,13 +120,6 @@ class Job(Entity): # inherits from the Entity c
except
SetWipTypeError
as
setWipError
:
except
SetWipTypeError
as
setWipError
:
print
'WIP definition error: {0}'
.
format
(
setWipError
)
print
'WIP definition error: {0}'
.
format
(
setWipError
)
#===========================================================================
# check if the entity can proceed to an operated machine, for use by Router
#===========================================================================
def
canProceed
(
self
):
activeObject
=
self
.
currentStation
return
activeObject
.
canDeliver
(
self
)
#===========================================================================
#===========================================================================
# check if the requireParts of the entity next step sequence (route) have
# check if the requireParts of the entity next step sequence (route) have
# have concluded the steps with sequence numbers smaller than the sequence
# have concluded the steps with sequence numbers smaller than the sequence
...
@@ -236,7 +229,7 @@ class Job(Entity): # inherits from the Entity c
...
@@ -236,7 +229,7 @@ class Job(Entity): # inherits from the Entity c
router
.
entitiesWithOccupiedReceivers
.
append
(
self
)
router
.
entitiesWithOccupiedReceivers
.
append
(
self
)
availableReceiver
=
None
availableReceiver
=
None
# if the sorting flag is not set then the sorting of each queue must prevail in case of operators conflict
# if the sorting flag is not set then the sorting of each queue must prevail in case of operators conflict
if
not
router
.
sorting
and
not
availableReceiver
and
bool
(
availableReceivers
):
if
not
availableReceiver
and
bool
(
availableReceivers
):
availableReceiver
=
self
.
currentStation
.
selectReceiver
(
self
.
candidateReceivers
)
availableReceiver
=
self
.
currentStation
.
selectReceiver
(
self
.
candidateReceivers
)
if
not
self
in
router
.
conflictingEntities
:
if
not
self
in
router
.
conflictingEntities
:
router
.
conflictingEntities
.
append
(
self
)
router
.
conflictingEntities
.
append
(
self
)
...
...
dream/simulation/OperatorManagedJob.py
View file @
69065e15
...
@@ -84,7 +84,7 @@ class OperatorManagedJob(Operator):
...
@@ -84,7 +84,7 @@ class OperatorManagedJob(Operator):
#=======================================================================
#=======================================================================
def
findCandidateEntities
(
self
,
pendingEntities
=
[]):
def
findCandidateEntities
(
self
,
pendingEntities
=
[]):
if
pendingEntities
:
if
pendingEntities
:
for
entity
in
[
x
for
x
in
pendingEntities
if
x
.
c
anProceed
and
x
.
manager
==
self
]:
for
entity
in
[
x
for
x
in
pendingEntities
if
x
.
c
urrentStation
.
canDeliver
(
x
)
and
x
.
manager
==
self
]:
self
.
candidateEntities
.
append
(
entity
)
self
.
candidateEntities
.
append
(
entity
)
#===========================================================================
#===========================================================================
...
@@ -117,10 +117,9 @@ class OperatorManagedJob(Operator):
...
@@ -117,10 +117,9 @@ class OperatorManagedJob(Operator):
router
=
G
.
Router
router
=
G
.
Router
# pick a candidateEntity
# pick a candidateEntity
candidateEntity
=
self
.
findAvailableEntity
()
candidateEntity
=
self
.
findAvailableEntity
()
if
not
router
.
sorting
:
if
not
candidateEntity
:
if
not
candidateEntity
:
candidateEntity
=
next
(
x
for
x
in
self
.
candidateEntities
)
candidateEntity
=
next
(
x
for
x
in
self
.
candidateEntities
)
router
.
conflictingEntities
.
append
(
candidateEntity
)
router
.
conflictingEntities
.
append
(
candidateEntity
)
return
candidateEntity
return
candidateEntity
# =======================================================================
# =======================================================================
...
...
dream/simulation/OperatorRouter.py
View file @
69065e15
...
@@ -39,14 +39,12 @@ class Router(ObjectInterruption):
...
@@ -39,14 +39,12 @@ class Router(ObjectInterruption):
# The Broker is initiated within the Machine and considered as
# The Broker is initiated within the Machine and considered as
# black box for the ManPy end Developer
# black box for the ManPy end Developer
# =======================================================================
# =======================================================================
def
__init__
(
self
,
sorting
=
False
):
def
__init__
(
self
):
ObjectInterruption
.
__init__
(
self
)
ObjectInterruption
.
__init__
(
self
)
self
.
type
=
"Router"
self
.
type
=
"Router"
self
.
isInitialized
=
False
self
.
isInitialized
=
False
self
.
isActivated
=
False
self
.
isActivated
=
False
self
.
candidateOperators
=
[]
self
.
candidateOperators
=
[]
# boolean flag to check whether the Router should perform sorting on operators and on pendingEntities
self
.
sorting
=
sorting
# list of objects to be signalled by the Router
# list of objects to be signalled by the Router
self
.
toBeSignalled
=
[]
self
.
toBeSignalled
=
[]
# flag to notify whether the router is already invoked
# flag to notify whether the router is already invoked
...
...
dream/simulation/OperatorRouterManaged.py
View file @
69065e15
...
@@ -46,12 +46,9 @@ class RouterManaged(Router):
...
@@ -46,12 +46,9 @@ class RouterManaged(Router):
# TODO: we should maybe define a global schedulingRule criterion that will be
# TODO: we should maybe define a global schedulingRule criterion that will be
# chosen in case of multiple criteria for different Operators
# chosen in case of multiple criteria for different Operators
# =======================================================================
# =======================================================================
def
__init__
(
self
,
sorting
=
False
):
def
__init__
(
self
):
Router
.
__init__
(
self
)
Router
.
__init__
(
self
)
self
.
multipleCriterionList
=
[]
self
.
schedulingRule
=
'WT'
# boolean flag to check whether the Router should perform sorting on operators and on pendingEntities
# boolean flag to check whether the Router should perform sorting on operators and on pendingEntities
self
.
sorting
=
sorting
self
.
entitiesWithOccupiedReceivers
=
[]
# list of entities that have no available receivers
self
.
entitiesWithOccupiedReceivers
=
[]
# list of entities that have no available receivers
#===========================================================================
#===========================================================================
...
@@ -61,13 +58,6 @@ class RouterManaged(Router):
...
@@ -61,13 +58,6 @@ class RouterManaged(Router):
Router
.
initialize
(
self
)
Router
.
initialize
(
self
)
# list that holds all the objects that can receive
# list that holds all the objects that can receive
self
.
pendingObjects
=
[]
self
.
pendingObjects
=
[]
self
.
calledOperator
=
[]
# list of the operators that may handle a machine at the current simulation time
self
.
candidateOperators
=
[]
# list of criteria
self
.
multipleCriterionList
=
[]
# TODO: find out which must be the default for the scheduling Rule
self
.
schedulingRule
=
'WT'
self
.
entitiesWithOccupiedReceivers
=
[]
self
.
entitiesWithOccupiedReceivers
=
[]
# =======================================================================
# =======================================================================
...
@@ -99,60 +89,47 @@ class RouterManaged(Router):
...
@@ -99,60 +89,47 @@ class RouterManaged(Router):
break
break
self
.
printTrace
(
''
,
'=-'
*
15
)
self
.
printTrace
(
''
,
'=-'
*
15
)
# entry actions
# find the pending objects
self
.
entry
()
self
.
findPendingObjects
()
# run the routine that allocates operators to machines
# find the pending entities
self
.
allocateOperators
()
self
.
findPendingEntities
()
# find the operators that can start working now
self
.
findCandidateOperators
()
# sort the pendingEntities list
if
self
.
sorting
:
self
.
sortPendingEntities
()
# find the operators candidateEntities
self
.
sortCandidateEntities
()
# find the entity that will occupy the resource, and the station that will receive it (if any available)
# entities that are already in stations have already a receiver
self
.
findCandidateReceivers
()
# assign operators to stations
# assign operators to stations
self
.
assignOperators
()
self
.
assignOperators
()
# unAssign exits
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
isAssignedTo
()]:
self
.
unAssignExits
()
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
for
object
in
self
.
pendingQueues
:
if
not
object
in
self
.
toBeSignalled
:
object
.
unAssignExit
()
# signal the stations that ought to be signalled
# signal the stations that ought to be signalled
self
.
signalOperatedStations
()
self
.
signalOperatedStations
()
self
.
printTrace
(
''
,
'router exiting'
)
self
.
printTrace
(
''
,
'router exiting'
)
self
.
printTrace
(
''
,
'=-'
*
20
)
self
.
printTrace
(
''
,
'=-'
*
20
)
# exit actions
self
.
exit
()
self
.
exit
()
#===========================================================================
def
entry
(
self
):
# assigning operators to machines
pass
#===========================================================================
def
assignOperators
(
self
):
def
allocateOperators
(
self
):
#------------------------------------------------------------------------------
# find the pending objects
# for all the operators that are requested
self
.
findPendingObjects
()
for
operator
in
self
.
candidateOperators
:
# find the pending entities
# check if the candidateOperators are available, if the are requested and reside in the pendingObjects list
self
.
findPendingEntities
()
#------------------------------------------------------------------------------
# find the operators that can start working now
if
operator
.
checkIfResourceIsAvailable
():
self
.
findCandidateOperators
()
if
operator
.
candidateEntity
:
# find the operators candidateEntities
# and if the priorityObject is indeed pending
self
.
sortCandidateEntities
()
if
(
operator
.
candidateEntity
.
currentStation
in
self
.
pendingObjects
)
\
# find the entity that will occupy the resource, and the station that will receive it (if any available)
and
(
not
operator
in
self
.
conflictingOperators
)
\
# entities that are already in stations have already a receiver
and
operator
.
candidateEntity
.
candidateReceiver
:
self
.
findCandidateReceivers
()
# assign an operator to the priorityObject
self
.
printTrace
(
'router'
,
'will assign '
+
operator
.
id
+
' to --> '
+
operator
.
candidateEntity
.
candidateReceiver
.
id
)
def
unAssignExits
(
self
):
operator
.
assignTo
(
operator
.
candidateEntity
.
candidateReceiver
)
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
isAssignedTo
()]:
if
not
operator
.
candidateEntity
.
currentStation
in
self
.
toBeSignalled
:
if
not
operator
.
isAssignedTo
()
in
self
.
pendingObjects
:
self
.
toBeSignalled
.
append
(
operator
.
candidateEntity
.
currentStation
)
if
operator
.
candidateEntity
.
currentStation
.
exitIsAssignedTo
():
self
.
printTrace
(
'objects to be signalled:'
+
' '
*
11
,
[
str
(
object
.
id
)
for
object
in
self
.
toBeSignalled
])
if
operator
.
isAssignedTo
()
!=
operator
.
candidateEntity
.
currentStation
.
exitIsAssignedTo
():
operator
.
candidateEntity
.
currentStation
.
unAssignExit
()
# if an object cannot proceed with getEntity, unAssign the exit of its giver
for
object
in
self
.
pendingQueues
:
if
not
object
in
self
.
toBeSignalled
:
object
.
unAssignExit
()
# =======================================================================
# =======================================================================
# return control to the Machine.run
# return control to the Machine.run
...
@@ -176,16 +153,34 @@ class RouterManaged(Router):
...
@@ -176,16 +153,34 @@ class RouterManaged(Router):
del
self
.
pendingMachines
[:]
del
self
.
pendingMachines
[:]
del
self
.
pendingQueues
[:]
del
self
.
pendingQueues
[:]
del
self
.
toBeSignalled
[:]
del
self
.
toBeSignalled
[:]
del
self
.
multipleCriterionList
[:]
del
self
.
conflictingOperators
[:]
del
self
.
conflictingOperators
[:]
del
self
.
conflictingStations
[:]
del
self
.
conflictingStations
[:]
del
self
.
conflictingEntities
[:]
del
self
.
conflictingEntities
[:]
del
self
.
occupiedReceivers
[:]
del
self
.
occupiedReceivers
[:]
del
self
.
entitiesWithOccupiedReceivers
[:]
del
self
.
entitiesWithOccupiedReceivers
[:]
self
.
schedulingRule
=
'WT'
self
.
invoked
=
False
self
.
invoked
=
False
#===========================================================================
# assigning operators to machines
#===========================================================================
def
assignOperators
(
self
):
# for all the operators that are requested
for
operator
in
self
.
candidateOperators
:
# check if the candidateOperators are available, if the are requested and reside in the pendingObjects list
if
operator
.
checkIfResourceIsAvailable
():
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
)
self
.
printTrace
(
'objects to be signalled:'
+
' '
*
11
,
[
str
(
object
.
id
)
for
object
in
self
.
toBeSignalled
])
#===========================================================================
#===========================================================================
# signal stations that wait for load operators
# signal stations that wait for load operators
#===========================================================================
#===========================================================================
...
@@ -195,7 +190,6 @@ class RouterManaged(Router):
...
@@ -195,7 +190,6 @@ class RouterManaged(Router):
station
=
operator
.
isAssignedTo
()
station
=
operator
.
isAssignedTo
()
if
station
:
if
station
:
# if the router deals with simple entities
# if the router deals with simple entities
if
station
in
self
.
pendingMachines
and
station
in
self
.
toBeSignalled
:
if
station
in
self
.
pendingMachines
and
station
in
self
.
toBeSignalled
:
# signal this station's broker that the resource is available
# signal this station's broker that the resource is available
self
.
printTrace
(
'router'
,
'signalling broker of'
+
' '
*
50
+
operator
.
isAssignedTo
().
id
)
self
.
printTrace
(
'router'
,
'signalling broker of'
+
' '
*
50
+
operator
.
isAssignedTo
().
id
)
...
@@ -213,21 +207,11 @@ class RouterManaged(Router):
...
@@ -213,21 +207,11 @@ class RouterManaged(Router):
if
operator
.
candidateEntity
.
currentStation
.
expectedSignals
[
'loadOperatorAvailable'
]:
if
operator
.
candidateEntity
.
currentStation
.
expectedSignals
[
'loadOperatorAvailable'
]:
self
.
sendSignal
(
receiver
=
operator
.
candidateEntity
.
currentStation
,
signal
=
operator
.
candidateEntity
.
currentStation
.
loadOperatorAvailable
)
self
.
sendSignal
(
receiver
=
operator
.
candidateEntity
.
currentStation
,
signal
=
operator
.
candidateEntity
.
currentStation
.
loadOperatorAvailable
)
#===========================================================================
# clear the pending lists of the router
#===========================================================================
def
clearPendingObjects
(
self
):
self
.
pendingQueues
=
[]
self
.
pendingMachines
=
[]
self
.
pendingObjects
=
[]
#===========================================================================
#===========================================================================
# find the stations that can be signalled by the router
# find the stations that can be signalled by the router
#===========================================================================
#===========================================================================
def
findPendingObjects
(
self
):
def
findPendingObjects
(
self
):
from
Globals
import
G
from
Globals
import
G
self
.
clearPendingObjects
()
for
entity
in
G
.
pendingEntities
:
for
entity
in
G
.
pendingEntities
:
if
entity
.
currentStation
in
G
.
MachineList
:
if
entity
.
currentStation
in
G
.
MachineList
:
if
entity
.
currentStation
.
broker
.
waitForOperator
:
if
entity
.
currentStation
.
broker
.
waitForOperator
:
...
@@ -238,7 +222,6 @@ class RouterManaged(Router):
...
@@ -238,7 +222,6 @@ class RouterManaged(Router):
self
.
pendingQueues
.
append
(
entity
.
currentStation
)
self
.
pendingQueues
.
append
(
entity
.
currentStation
)
self
.
pendingObjects
.
append
(
entity
.
currentStation
)
self
.
pendingObjects
.
append
(
entity
.
currentStation
)
break
break
# self.pendingMachines=[machine for machine in G.MachineList if machine.broker.waitForOperator]
self
.
pendingObjects
=
self
.
pendingQueues
+
self
.
pendingMachines
self
.
pendingObjects
=
self
.
pendingQueues
+
self
.
pendingMachines
self
.
printTrace
(
'router found pending objects'
+
'-'
*
6
+
'>'
,
[
str
(
object
.
id
)
for
object
in
self
.
pendingObjects
])
self
.
printTrace
(
'router found pending objects'
+
'-'
*
6
+
'>'
,
[
str
(
object
.
id
)
for
object
in
self
.
pendingObjects
])
self
.
printTrace
(
'pendingMachines'
+
'-'
*
19
+
'>'
,
[
str
(
object
.
id
)
for
object
in
self
.
pendingMachines
])
self
.
printTrace
(
'pendingMachines'
+
'-'
*
19
+
'>'
,
[
str
(
object
.
id
)
for
object
in
self
.
pendingMachines
])
...
@@ -282,15 +265,12 @@ class RouterManaged(Router):
...
@@ -282,15 +265,12 @@ class RouterManaged(Router):
# if the entity is ready to move to a machine and its manager is available
# if the entity is ready to move to a machine and its manager is available
if
entity
.
manager
.
checkIfResourceIsAvailable
():
if
entity
.
manager
.
checkIfResourceIsAvailable
():
# check whether the entity canProceed and update the its candidateReceivers
# check whether the entity canProceed and update the its candidateReceivers
if
entity
.
c
anProceed
(
)
\
if
entity
.
c
urrentStation
.
canDeliver
(
entity
)
\
and
not
entity
.
manager
in
self
.
candidateOperators
:
and
not
entity
.
manager
in
self
.
candidateOperators
:
self
.
candidateOperators
.
append
(
entity
.
manager
)
self
.
candidateOperators
.
append
(
entity
.
manager
)
# TODO: check if preemption can be implemented for the managed case
# TODO: check if preemption can be implemented for the managed case
# find the candidateEntities for each operator
# find the candidateEntities for each operator
self
.
findCandidateEntities
()
self
.
findCandidateEntities
()
# update the schedulingRule/multipleCriterionList of the Router
if
self
.
sorting
:
self
.
updateSchedulingRule
()
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
])
...
@@ -301,25 +281,6 @@ class RouterManaged(Router):
...
@@ -301,25 +281,6 @@ class RouterManaged(Router):
for
operator
in
self
.
candidateOperators
:
for
operator
in
self
.
candidateOperators
:
# find which pendingEntities that can move to machines is the operator managing
# find which pendingEntities that can move to machines is the operator managing
operator
.
findCandidateEntities
(
self
.
pending
)
operator
.
findCandidateEntities
(
self
.
pending
)
#=======================================================================
# find the schedulingRules of the candidateOperators
#=======================================================================
def
updateSchedulingRule
(
self
):
if
self
.
candidateOperators
:
for
operator
in
self
.
candidateOperators
:
if
operator
.
multipleCriterionList
:
for
criterion
in
operator
.
multipleCriterionList
:
if
not
criterion
in
self
.
multipleCriterionList
:
self
.
multipleCriterionList
.
append
(
criterion
)
else
:
# if operator has only simple scheduling Rule
if
not
operator
.
schedulingRule
in
self
.
multipleCriterionList
:
self
.
multipleCriterionList
.
append
(
operator
.
schedulingRule
)
# TODO: For the moment all operators should have only one scheduling rule and the same among them
# added for testing
assert
len
(
self
.
multipleCriterionList
)
==
1
,
'The operators must have the same (one) scheduling rule'
if
len
(
self
.
multipleCriterionList
)
==
1
:
self
.
schedulingRule
=
self
.
multipleCriterionList
[
0
]
#=======================================================================
#=======================================================================
# Find the candidateEntities for each candidateOperator
# Find the candidateEntities for each candidateOperator
...
@@ -329,63 +290,16 @@ class RouterManaged(Router):
...
@@ -329,63 +290,16 @@ class RouterManaged(Router):
#=======================================================================
#=======================================================================
def
sortCandidateEntities
(
self
):
def
sortCandidateEntities
(
self
):
from
Globals
import
G
from
Globals
import
G
# TODO: sort according to the number of pending Jobs
# TODO Have to sort again according to the priority used by the operators
# initialise the operatorsWithOneOption and operatorsWithOneCandidateEntity lists
operatorsWithOneOption
=
[]
# for all the candidateOperators
for
operator
in
self
.
candidateOperators
:
# sort the candidate operators so that those who have only one option be served first
# if the candidate entity has only one receiver then append the operator to operatorsWithOneOption list
if
operator
.
hasOneOption
():
operatorsWithOneOption
.
append
(
operator
)
# TODO: the operator here actually chooses entity. This may pose a problem as two entities may be equivalent
# TODO: the operator here actually chooses entity. This may pose a problem as two entities may be equivalent
# and as the operators chooses the sorting of the queue (if they do reside in the same queue is not taken into account)
# and as the operators chooses the sorting of the queue (if they do reside in the same queue is not taken into account)
# sort the candidateEntities list of each operator according to its schedulingRule
# sort the candidateEntities list of each operator according to its schedulingRule
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
candidateEntities
]:
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
candidateEntities
]:
operator
.
sortCandidateEntities
()
operator
.
sortCandidateEntities
()
# if there operators that have only one option then sort the candidateOperators according to the first one of these
# TODO: find out what happens if there are many operators with one option
# TODO: incorporate that to
# self.sortOperators()
if
self
.
sorting
:
# sort the operators according to their waiting time
self
.
candidateOperators
.
sort
(
key
=
lambda
x
:
x
.
totalWorkingTime
)
# sort according to the number of options
if
operatorsWithOneOption
:
self
.
candidateOperators
.
sort
(
key
=
lambda
x
:
x
in
operatorsWithOneOption
,
reverse
=
True
)
self
.
printTrace
(
'candidateEntities for each operator'
,
\
self
.
printTrace
(
'candidateEntities for each operator'
,
\
[(
str
(
operator
.
id
),[
str
(
x
.
id
)
for
x
in
operator
.
candidateEntities
])
[(
str
(
operator
.
id
),[
str
(
x
.
id
)
for
x
in
operator
.
candidateEntities
])
for
operator
in
self
.
candidateOperators
])
for
operator
in
self
.
candidateOperators
])
#=======================================================================
# Sort pendingEntities
# TODO: sorting them according to the operators schedulingRule
#=======================================================================
def
sortPendingEntities
(
self
):
if
self
.
candidateOperators
:
from
Globals
import
G
candidateList
=
self
.
pending
self
.
activeQSorter
(
criterion
=
self
.
schedulingRule
,
candList
=
candidateList
)
self
.
printTrace
(
'router'
,
' sorted pending entities'
)
#=======================================================================
# Sort candidateOperators
# TODO: consider if there must be an argument set for the schedulingRules of the Router
# TODO: consider if the scheduling rule for the operators must be global for all of them
#=======================================================================
def
sortOperators
(
self
):
# TODO: there must be criteria for sorting the cadidateOperators
#if we have sorting according to multiple criteria we have to call the sorter many times
# TODO: find out what happens in case of multiple criteria
if
self
.
candidateOperators
:
candidateList
=
self
.
candidateOperators
self
.
activeQSorter
(
criterion
=
self
.
schedulingRule
,
candList
=
candidateList
)
#=======================================================================
#=======================================================================
# Find candidate entities and their receivers
# Find candidate entities and their receivers
...
@@ -408,182 +322,33 @@ class RouterManaged(Router):
...
@@ -408,182 +322,33 @@ class RouterManaged(Router):
operator
.
candidateEntity
.
candidateReceiver
=
operator
.
candidateEntity
.
findCandidateReceiver
()
operator
.
candidateEntity
.
candidateReceiver
=
operator
.
candidateEntity
.
findCandidateReceiver
()
# find the resources that are 'competing' for the same station
# find the resources that are 'competing' for the same station
if
not
self
.
sorting
:
# if there are entities that have conflicting receivers
# if there are entities that have conflicting receivers
if
len
(
self
.
conflictingEntities
):
if
len
(
self
.
conflictingEntities
):
# find the conflictingOperators
# find the conflictingOperators
self
.
conflictingOperators
=
[
operator
for
operator
in
self
.
candidateOperators
\
self
.
conflictingOperators
=
[
operator
for
operator
in
self
.
candidateOperators
\
if
operator
.
candidateEntity
in
self
.
conflictingEntities
or
\
if
operator
.
candidateEntity
in
self
.
conflictingEntities
or
\
operator
.
candidateEntity
.
candidateReceiver
in
[
x
.
candidateReceiver
for
x
in
self
.
conflictingEntities
]]
operator
.
candidateEntity
.
candidateReceiver
in
[
x
.
candidateReceiver
for
x
in
self
.
conflictingEntities
]]
# keep the sorting provided by the queues if there is conflict between operators
# keep the sorting provided by the queues if there is conflict between operators
conflictingGroup
=
[]
# list that holds the operators that have the same recipient
conflictingGroup
=
[]
# list that holds the operators that have the same recipient
if
len
(
self
.
conflictingOperators
):
if
len
(
self
.
conflictingOperators
):
# for each of the candidateReceivers
# for each of the candidateReceivers
for
receiver
in
[
x
.
candidateEntity
.
candidateReceiver
for
x
in
self
.
conflictingOperators
]:
for
receiver
in
[
x
.
candidateEntity
.
candidateReceiver
for
x
in
self
.
conflictingOperators
]:
# find the group of operators that compete for this station
# find the group of operators that compete for this station
conflictingGroup
=
[
operator
for
operator
in
self
.
conflictingOperators
if
operator
.
candidateEntity
.
candidateReceiver
==
receiver
]
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
]]),
\
assert
len
([
station
for
station
in
[
x
.
candidateEntity
.
currentStation
for
x
in
conflictingGroup
]]),
\
'the conflicting entities must reside in the same queue'
'the conflicting entities must reside in the same queue'
# for each of the competing for the same station operators
# for each of the competing for the same station operators
for
operator
in
conflictingGroup
:
for
operator
in
conflictingGroup
:
# find the index of entities to be operated by them in the queue that holds them
# 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
)
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
# 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
)
conflictingGroup
.
sort
(
key
=
lambda
x
:
x
.
ind
)
# the operators that are not first in the list cannot proceed
# the operators that are not first in the list cannot proceed
for
operator
in
conflictingGroup
:
for
operator
in
conflictingGroup
:
if
conflictingGroup
.
index
(
operator
)
!=
0
:
if
conflictingGroup
.
index
(
operator
)
!=
0
:
self
.
candidateOperators
.
remove
(
operator
)
self
.
candidateOperators
.
remove
(
operator
)
self
.
printTrace
(
'candidateReceivers for each entity '
,[(
str
(
entity
.
id
),
\
self
.
printTrace
(
'candidateReceivers for each entity '
,[(
str
(
entity
.
id
),
\
str
(
entity
.
candidateReceiver
.
id
))
str
(
entity
.
candidateReceiver
.
id
))
for
entity
in
self
.
pending
if
entity
.
candidateReceiver
])
for
entity
in
self
.
pending
if
entity
.
candidateReceiver
])
\ No newline at end of file
# =======================================================================
# sorts the Operators of the Queue according to the scheduling rule
# =======================================================================
def
activeQSorter
(
self
,
criterion
=
None
,
candList
=
[]):
activeObjectQ
=
candList
if
not
activeObjectQ
:
assert
False
,
"empty candidateOperators list"
if
criterion
==
None
:
criterion
=
self
.
multipleCriterionList
[
0
]
#if the schedulingRule is first in first out
if
criterion
==
"FIFO"
:
# FIFO sorting has no meaning when sorting candidateEntities
self
.
activeQSorter
(
criterion
=
'WT'
,
candList
=
activeObjectQ
)
#if the schedulingRule is based on a pre-defined priority
elif
criterion
==
"Priority"
:
# if the activeObjectQ is a list of entities then perform the default sorting
try
:
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
priority
)
# if the activeObjectQ is a list of operators then sort them according to their candidateEntities
except
:
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
candidateEntity
.
priority
)
#if the scheduling rule is time waiting (time waiting of machine
# TODO: consider that the timeLastEntityEnded is not a
# indicative identifier of how long the station was waiting
elif
criterion
==
'WT'
:
try
:
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
schedule
[
-
1
][
1
])
except
:
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
candidateEntity
.
schedule
[
-
1
][
1
])
#if the schedulingRule is earliest due date
elif
criterion
==
"EDD"
:
try
:
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
dueDate
)
except
:
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
candidateEntity
.
dueDate
)
#if the schedulingRule is earliest order date
elif
criterion
==
"EOD"
:
try
:
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
orderDate
)
except
:
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
candidateEntity
.
orderDate
)
#if the schedulingRule is to sort Entities according to the stations they have to visit
elif
criterion
==
"NumStages"
:
try
:
activeObjectQ
.
sort
(
key
=
lambda
x
:
len
(
x
.
remainingRoute
),
reverse
=
True
)
except
:
activeObjectQ
.
sort
(
key
=
lambda
x
:
len
(
x
.
candidateEntity
.
remainingRoute
),
reverse
=
True
)
#if the schedulingRule is to sort Entities according to the their remaining processing time in the system
elif
criterion
==
"RPC"
:
try
:
for
entity
in
activeObjectQ
:
RPT
=
0
for
step
in
entity
.
remainingRoute
:
processingTime
=
step
.
get
(
'processingTime'
,
None
)
if
processingTime
:
RPT
+=
float
(
processingTime
.
get
(
'mean'
,
0
))
entity
.
remainingProcessingTime
=
RPT
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
remainingProcessingTime
,
reverse
=
True
)
except
:
for
entity
in
[
operator
.
candidateEntity
for
operator
in
activeObjectQ
]:
RPT
=
0
for
step
in
entity
.
remainingRoute
:
processingTime
=
step
.
get
(
'processingTime'
,
None
)
if
processingTime
:
RPT
+=
float
(
processingTime
.
get
(
'mean'
,
0
))
entity
.
remainingProcessingTime
=
RPT
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
candidateEntity
.
remainingProcessingTime
,
reverse
=
True
)
#if the schedulingRule is to sort Entities according to longest processing time first in the next station
elif
criterion
==
"LPT"
:
try
:
for
entity
in
activeObjectQ
:
processingTime
=
entity
.
remainingRoute
[
0
].
get
(
'processingTime'
,
None
)
entity
.
processingTimeInNextStation
=
float
(
processingTime
.
get
(
'mean'
,
0
))
if
processingTime
:
entity
.
processingTimeInNextStation
=
float
(
processingTime
.
get
(
'mean'
,
0
))
else
:
entity
.
processingTimeInNextStation
=
0
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
processingTimeInNextStation
,
reverse
=
True
)
except
:
for
entity
in
[
operator
.
candidateEntity
for
operator
in
activeObjectQ
]:
processingTime
=
entity
.
remainingRoute
[
0
].
get
(
'processingTime'
,
None
)
entity
.
processingTimeInNextStation
=
float
(
processingTime
.
get
(
'mean'
,
0
))
if
processingTime
:
entity
.
processingTimeInNextStation
=
float
(
processingTime
.
get
(
'mean'
,
0
))
else
:
entity
.
processingTimeInNextStation
=
0
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
candidateEntity
.
processingTimeInNextStation
,
reverse
=
True
)
#if the schedulingRule is to sort Entities according to shortest processing time first in the next station
elif
criterion
==
"SPT"
:
try
:
for
entity
in
activeObjectQ
:
processingTime
=
entity
.
remainingRoute
[
0
].
get
(
'processingTime'
,
None
)
if
processingTime
:
entity
.
processingTimeInNextStation
=
float
(
processingTime
.
get
(
'mean'
,
0
))
else
:
entity
.
processingTimeInNextStation
=
0
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
processingTimeInNextStation
)
except
:
for
entity
in
[
operator
.
candidateEntity
for
operator
in
activeObjectQ
]:
processingTime
=
entity
.
remainingRoute
[
0
].
get
(
'processingTime'
,
None
)
if
processingTime
:
entity
.
processingTimeInNextStation
=
float
(
processingTime
.
get
(
'mean'
,
0
))
else
:
entity
.
processingTimeInNextStation
=
0
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
candidateEntity
.
processingTimeInNextStation
)
#if the schedulingRule is to sort Entities based on the minimum slackness
elif
criterion
==
"MS"
:
try
:
for
entity
in
activeObjectQ
:
RPT
=
0
for
step
in
entity
.
remainingRoute
:
processingTime
=
step
.
get
(
'processingTime'
,
None
)
if
processingTime
:
RPT
+=
float
(
processingTime
.
get
(
'mean'
,
0
))
entity
.
remainingProcessingTime
=
RPT
activeObjectQ
.
sort
(
key
=
lambda
x
:
(
x
.
dueDate
-
x
.
remainingProcessingTime
))
except
:
for
entity
in
[
operator
.
candidateEntity
for
operator
in
activeObjectQ
]:
RPT
=
0
for
step
in
entity
.
remainingRoute
:
processingTime
=
step
.
get
(
'processingTime'
,
None
)
if
processingTime
:
RPT
+=
float
(
processingTime
.
get
(
'mean'
,
0
))
entity
.
remainingProcessingTime
=
RPT
activeObjectQ
.
sort
(
key
=
lambda
x
:
(
x
.
candidateEntity
.
dueDate
-
x
.
candidateEntity
.
remainingProcessingTime
))
#if the schedulingRule is to sort Entities based on the length of the following Queue
elif
criterion
==
"WINQ"
:
try
:
from
Globals
import
G
for
entity
in
activeObjectQ
:
nextObjIds
=
entity
.
remainingRoute
[
1
].
get
(
'stationIdsList'
,[])
for
obj
in
G
.
ObjList
:
if
obj
.
id
in
nextObjIds
:
nextObject
=
obj
entity
.
nextQueueLength
=
len
(
nextObject
.
getActiveObjectQueue
())
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
nextQueueLength
)
except
:
from
Globals
import
G
for
entity
in
[
operator
.
candidateEntity
for
operator
in
activeObjectQ
]:
nextObjIds
=
entity
.
remainingRoute
[
1
].
get
(
'stationIdsList'
,[])
for
obj
in
G
.
ObjList
:
if
obj
.
id
in
nextObjIds
:
nextObject
=
obj
entity
.
nextQueueLength
=
len
(
nextObject
.
getActiveObjectQueue
())
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
candidateEntity
.
nextQueueLength
)
else
:
assert
False
,
"Unknown scheduling criterion %r"
%
(
criterion
,
)
\ No newline at end of file
dream/simulation/SkilledOperatorRouter.py
View file @
69065e15
...
@@ -58,7 +58,6 @@ class SkilledRouter(Router):
...
@@ -58,7 +58,6 @@ class SkilledRouter(Router):
self
.
waitEndProcess
=
False
self
.
waitEndProcess
=
False
self
.
pendingQueues
=
[]
self
.
pendingQueues
=
[]
self
.
pendingMachines
=
[]
self
.
pendingMachines
=
[]
self
.
pendingObjects
=
[]
self
.
previousSolution
=
{}
self
.
previousSolution
=
{}
# =======================================================================
# =======================================================================
...
@@ -268,32 +267,14 @@ class SkilledRouter(Router):
...
@@ -268,32 +267,14 @@ class SkilledRouter(Router):
# default behaviour
# default behaviour
#===================================================================
#===================================================================
else
:
else
:
# find the pending objects
# entry actions
self
.
findPendingObjects
()
self
.
entry
()
# find the pending entities
# run the routine that allocates operators to machines
self
.
findPendingEntities
()
self
.
allocateOperators
()
# find the operators that can start working now
self
.
findCandidateOperators
()
# sort the pendingEntities list
if
self
.
sorting
:
self
.
sortPendingEntities
()
# find the operators candidateEntities
self
.
sortCandidateEntities
()
# find the entity that will occupy the resource, and the station that will receive it (if any available)
# entities that are already in stations have already a receiver
self
.
findCandidateReceivers
()
# assign operators to stations
# assign operators to stations
self
.
assignOperators
()
self
.
assignOperators
()
# unAssign exits
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
isAssignedTo
()]:
self
.
unAssignExits
()
if
not
operator
.
isAssignedTo
()
in
self
.
pendingObjects
:
for
object
in
[
x
for
x
in
operator
.
isAssignedTo
().
previous
if
x
.
exitIsAssignedTo
()]:
if
object
.
exitIsAssignedTo
()
!=
operator
.
isAssignedTo
():
object
.
unAssignExit
()
# if an object cannot proceed with getEntity, unAssign the exit of its giver
for
object
in
self
.
pendingQueues
:
if
not
object
in
self
.
toBeSignalled
:
object
.
unAssignExit
()
# signal the stations that ought to be signalled
# signal the stations that ought to be signalled
self
.
signalOperatedStations
()
self
.
signalOperatedStations
()
...
...
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