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
1c64c053
Commit
1c64c053
authored
Apr 07, 2014
by
Ioannis Papagiannopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sorting of Operators and pendingEntities now optional
parent
3513d0af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
15 deletions
+18
-15
dream/simulation/OperatorRouter.py
dream/simulation/OperatorRouter.py
+18
-15
No files found.
dream/simulation/OperatorRouter.py
View file @
1c64c053
...
...
@@ -43,7 +43,7 @@ class Router(ObjectInterruption):
# TODO: we should maybe define a global schedulingRule criterion that will be
# chosen in case of multiple criteria for different Operators
# =======================================================================
def
__init__
(
self
):
def
__init__
(
self
,
sorting
=
False
):
ObjectInterruption
.
__init__
(
self
)
self
.
type
=
"Router"
# signal used to initiate the generator of the Router
...
...
@@ -52,7 +52,8 @@ class Router(ObjectInterruption):
self
.
candidateOperators
=
[]
self
.
multipleCriterionList
=
[]
self
.
schedulingRule
=
'WT'
self
.
sorting
=
False
# boolean flag to check whether the Router should perform sorting on operators and on pendingEntities
self
.
sorting
=
sorting
#===========================================================================
# the initialize method
...
...
@@ -70,8 +71,6 @@ class Router(ObjectInterruption):
self
.
schedulingRule
=
'WT'
# flag used to check if the Router is initialised
self
.
isInitialized
=
True
# boolean flag to check whether the Router should perform sorting on operators and on pendingEntities
self
.
sorting
=
False
# =======================================================================
# the run method
...
...
@@ -124,7 +123,8 @@ class Router(ObjectInterruption):
#===================================================================
# sort the pendingEntities list
self
.
sortPendingEntities
()
if
self
.
sorting
:
self
.
sortPendingEntities
()
#===================================================================
# # TESTING
...
...
@@ -346,7 +346,8 @@ class Router(ObjectInterruption):
if
entity
.
canProceed
and
not
entity
.
manager
in
self
.
candidateOperators
:
self
.
candidateOperators
.
append
(
entity
.
manager
)
# update the schedulingRule/multipleCriterionList of the Router
self
.
updateSchedulingRule
()
if
self
.
sorting
:
self
.
updateSchedulingRule
()
#=======================================================================
...
...
@@ -401,13 +402,14 @@ class Router(ObjectInterruption):
# 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()
#
self.sortOperators()
# 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
)
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
)
#=======================================================================
# Find candidate entities and their receivers
...
...
@@ -448,11 +450,12 @@ class Router(ObjectInterruption):
# operator.candidateEntity.candidateReceiver=None
return
availableReceiver
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
candidateEntities
]:
operator
.
candidateEntity
=
operator
.
candidateEntities
[
0
]
#
for operator in [x for x in self.candidateOperators if x.candidateEntities]:
#
operator.candidateEntity=operator.candidateEntities[0]
# TODO: sorting again after choosing candidateEntity
self
.
sortOperators
()
if
self
.
sorting
:
self
.
sortOperators
()
# for the candidateOperators that do have candidateEntities pick a candidateEntity
for
operator
in
[
x
for
x
in
self
.
candidateOperators
if
x
.
candidateEntities
]:
...
...
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