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
a2ecb7e4
Commit
a2ecb7e4
authored
May 19, 2014
by
Ioannis Papagiannopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Router findCandidateReceivers clean-up
parent
0357c825
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
75 deletions
+56
-75
dream/simulation/Operator.py
dream/simulation/Operator.py
+6
-6
dream/simulation/OperatorRouter.py
dream/simulation/OperatorRouter.py
+50
-69
No files found.
dream/simulation/Operator.py
View file @
a2ecb7e4
...
...
@@ -112,15 +112,15 @@ class Operator(ObjectResource):
#===========================================================================
# method that finds a candidate entity for an operator
#===========================================================================
def
findCandidateStation
(
self
,
conflictingStations
=
[]):
conflicting
=
conflictingStations
def
findCandidateStation
(
self
):
from
Globals
import
G
candidateStation
=
next
(
x
for
x
in
self
.
candidateStations
if
not
x
in
conflicting
)
if
not
G
.
Router
.
sorting
:
router
=
G
.
Router
candidateStation
=
next
(
x
for
x
in
self
.
candidateStations
if
not
x
in
router
.
conflictingStations
)
if
not
router
.
sorting
:
if
not
candidateStation
:
candidateStation
=
next
(
x
for
x
in
self
.
candidateStations
)
conflicting
.
append
(
candidateStation
)
return
candidateStation
,
conflictingStations
router
.
conflictingStations
.
append
(
candidateStation
)
return
candidateStation
#===========================================================================
# recursive method that searches for entities with available receivers
...
...
dream/simulation/OperatorRouter.py
View file @
a2ecb7e4
...
...
@@ -64,6 +64,7 @@ class Router(ObjectInterruption):
self
.
conflictingOperators
=
[]
# list with the operators that have candidateEntity with conflicting candidateReceivers
self
.
conflictingEntities
=
[]
# entities with conflictingReceivers
self
.
conflictingStations
=
[]
# stations with conflicting operators
self
.
occupiedReceivers
=
[]
# occupied candidateReceivers of a candidateEntity
self
.
entitiesWithOccupiedReceivers
=
[]
# list of entities that have no available receivers
...
...
@@ -90,6 +91,7 @@ class Router(ObjectInterruption):
self
.
toBeSignalled
=
[]
self
.
conflictingOperators
=
[]
self
.
conflictingEntities
=
[]
self
.
conflictingStations
=
[]
self
.
occupiedReceivers
=
[]
self
.
entitiesWithOccupiedReceivers
=
[]
...
...
@@ -97,10 +99,8 @@ class Router(ObjectInterruption):
# the run method
# =======================================================================
'''
all the pendingEntities that are hot should be examined if they can proceed to the next
step of their route as they may not be first in the activeQueue of their currentStations (QueueManagedJob).
If they can be disposed to the next object then the router should wait again till the machine to receive them
returns canAcceptAndIsRequested (inPositionToGet is True)
after the events are over, assign the operators to machines for loading or simple processing
read the pendingEntities currentStations, these are the stations (queues) that may be signalled
'''
def
run
(
self
):
from
Globals
import
G
...
...
@@ -124,9 +124,7 @@ class Router(ObjectInterruption):
self
.
printTrace
(
''
,
'there are NO more events for now'
)
break
self
.
printTrace
(
''
,
'=-'
*
15
)
# after the events are over, assign the operators to machines for loading or simple processing
# read the pendingEntities currentStations, these are the stations (queues) that may be signalled
# the activeCallers list is updated each time the canAcceptAndIsRequested returns true even if the machine is not signalled
# find the pending objects
self
.
findPendingObjects
()
...
...
@@ -227,7 +225,7 @@ class Router(ObjectInterruption):
del
self
.
toBeSignalled
[:]
del
self
.
multipleCriterionList
[:]
del
self
.
conflictingOperators
[:]
del
self
.
conflicting
Operator
s
[:]
del
self
.
conflicting
Station
s
[:]
del
self
.
conflictingEntities
[:]
del
self
.
occupiedReceivers
[:]
del
self
.
entitiesWithOccupiedReceivers
[:]
...
...
@@ -478,33 +476,26 @@ class Router(ObjectInterruption):
# TODO: have to sort again after choosing candidateEntity
#=======================================================================
def
findCandidateReceivers
(
self
):
if
not
self
.
managed
:
# initialise local variables occupiedReceivers and entitiesWithOccupiedReceivers
conflictingStations
=
[]
# list with the operators that have candidateEntity with conflicting candidateReceivers
conflictingOperators
=
[]
# 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
#
# 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
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
candidateStations
]:
# find the first available entity that has no occupied receivers
operator
.
candidateStation
,
conflictingStations
=
operator
.
findCandidateStation
(
conflictingStations
)
operator
.
candidateStation
=
operator
.
findCandidateStation
(
)
# find the resources that are 'competing' for the same station
if
not
self
.
sorting
:
# if there are entities that have conflicting receivers
if
len
(
conflictingStations
):
for
operator
in
self
.
candidateOperators
:
if
operator
.
candidateStation
in
conflictingStations
:
conflictingOperators
.
append
(
operator
)
self
.
conflictingOperators
=
conflictingOperators
if
len
(
self
.
conflictingStations
):
self
.
conflictingOperators
=
[
operator
for
operator
in
self
.
candidateOperators
\
if
operator
.
candidateStation
in
self
.
conflictingStations
]
# 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
not
self
.
sorting
and
self
.
conflictingOperators
:
if
self
.
conflictingOperators
:
# for each of the candidateReceivers
for
station
in
conflictingStations
:
for
station
in
self
.
conflictingStations
:
# find the group of operators that compete for this station
conflictingGroup
=
[
operator
for
operator
in
self
.
conflictingOperators
if
operator
.
candidateStation
==
station
]
# the operator that can proceed is the manager of the entity as sorted by the queue that holds them
...
...
@@ -513,18 +504,10 @@ class Router(ObjectInterruption):
for
operator
in
conflitingGroup
:
if
conflictingGroup
.
index
(
operator
)
!=
0
:
self
.
candidateOperators
.
remove
(
operator
)
self
.
calledOperators
.
remove
(
operator
)
# if the moving entities are managed
#------------------------------------------------------------------------------
else
:
# initialise local variable conflictingOperators
conflictingOperators
=
[]
# list with the operators that have candidateEntity with conflicting candidateReceivers
# # 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
# # TODO: sorting after choosing candidateEntity
# 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
...
...
@@ -534,19 +517,18 @@ class Router(ObjectInterruption):
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
):
for
operator
in
self
.
candidateOperators
:
if
operator
.
candidateEntity
in
self
.
conflictingEntities
:
conflictingOperators
.
append
(
operator
)
elif
operator
.
candidateEntity
.
candidateReceiver
in
[
x
.
candidateReceiver
for
x
in
self
.
conflictingEntities
]:
conflictingOperators
.
append
(
operator
)
self
.
conflictingOperators
=
conflictingOperators
# 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
not
self
.
sorting
and
self
.
conflictingOperators
:
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
...
...
@@ -563,7 +545,6 @@ class Router(ObjectInterruption):
for
operator
in
conflictingGroup
:
if
conflictingGroup
.
index
(
operator
)
!=
0
:
self
.
candidateOperators
.
remove
(
operator
)
self
.
calledOperators
.
remove
(
operator
)
if
self
.
managed
:
self
.
printTrace
(
'candidateReceivers for each entity '
,[(
str
(
entity
.
id
),
\
...
...
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