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
e5dca2a1
Commit
e5dca2a1
authored
May 27, 2014
by
Ioannis Papagiannopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Queue/JobShop, getActiveObject/Queue() used less
parent
c66ccd79
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
54 deletions
+33
-54
dream/simulation/Queue.py
dream/simulation/Queue.py
+17
-29
dream/simulation/QueueJobShop.py
dream/simulation/QueueJobShop.py
+16
-25
No files found.
dream/simulation/Queue.py
View file @
e5dca2a1
...
@@ -92,17 +92,17 @@ class Queue(CoreObject):
...
@@ -92,17 +92,17 @@ class Queue(CoreObject):
# run method of the queue
# run method of the queue
#===========================================================================
#===========================================================================
def
run
(
self
):
def
run
(
self
):
activeObjectQueue
=
self
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
Res
.
activeQ
# check if there is WIP and signal receiver
# check if there is WIP and signal receiver
self
.
initialSignalReceiver
()
self
.
initialSignalReceiver
()
while
1
:
while
1
:
self
.
printTrace
(
self
.
id
,
waitEvent
=
''
)
#
self.printTrace(self.id, waitEvent='')
# wait until the Queue can accept an entity and one predecessor requests it
# wait until the Queue can accept an entity and one predecessor requests it
yield
waitevent
,
self
,
[
self
.
isRequested
,
self
.
canDispose
,
self
.
loadOperatorAvailable
]
yield
waitevent
,
self
,
[
self
.
isRequested
,
self
.
canDispose
,
self
.
loadOperatorAvailable
]
self
.
printTrace
(
self
.
id
,
received
=
''
)
#
self.printTrace(self.id, received='')
# if the event that activated the thread is isRequested then getEntity
# if the event that activated the thread is isRequested then getEntity
if
self
.
isRequested
.
signalparam
:
if
self
.
isRequested
.
signalparam
:
self
.
printTrace
(
self
.
id
,
isRequested
=
self
.
isRequested
.
signalparam
.
id
)
#
self.printTrace(self.id, isRequested=self.isRequested.signalparam.id)
# reset the isRequested signal parameter
# reset the isRequested signal parameter
self
.
isRequested
.
signalparam
=
None
self
.
isRequested
.
signalparam
=
None
self
.
getEntity
()
self
.
getEntity
()
...
@@ -115,11 +115,11 @@ class Queue(CoreObject):
...
@@ -115,11 +115,11 @@ class Queue(CoreObject):
self
.
loadOperatorAvailable
.
signalparam
=
None
self
.
loadOperatorAvailable
.
signalparam
=
None
# if the queue received an canDispose with signalparam time, this means that the signals was sent from a MouldAssemblyBuffer
# if the queue received an canDispose with signalparam time, this means that the signals was sent from a MouldAssemblyBuffer
if
self
.
canDispose
.
signalparam
:
if
self
.
canDispose
.
signalparam
:
self
.
printTrace
(
self
.
id
,
canDispose
=
''
)
#
self.printTrace(self.id, canDispose='')
self
.
canDispose
.
signalparam
=
None
self
.
canDispose
.
signalparam
=
None
# if the event that activated the thread is canDispose then signalReceiver
# if the event that activated the thread is canDispose then signalReceiver
if
self
.
haveToDispose
():
if
self
.
haveToDispose
():
self
.
printTrace
(
self
.
id
,
attemptSignalReceiver
=
'(generator)'
)
#
self.printTrace(self.id, attemptSignalReceiver='(generator)')
if
self
.
receiver
:
if
self
.
receiver
:
if
not
self
.
receiver
.
entryIsAssignedTo
():
if
not
self
.
receiver
.
entryIsAssignedTo
():
self
.
signalReceiver
()
self
.
signalReceiver
()
...
@@ -132,16 +132,14 @@ class Queue(CoreObject):
...
@@ -132,16 +132,14 @@ class Queue(CoreObject):
# only to the predecessor that will give the entity.
# only to the predecessor that will give the entity.
# =======================================================================
# =======================================================================
def
canAccept
(
self
,
callerObject
=
None
):
def
canAccept
(
self
,
callerObject
=
None
):
# get active and giver objects
activeObjectQueue
=
self
.
Res
.
activeQ
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
#if we have only one predecessor just check if there is a place available
#if we have only one predecessor just check if there is a place available
# this is done to achieve better (cpu) processing time
# this is done to achieve better (cpu) processing time
# then we can also use it as a filter for a yield method
# then we can also use it as a filter for a yield method
if
(
callerObject
==
None
):
if
(
callerObject
==
None
):
return
len
(
activeObjectQueue
)
<
activeObject
.
capacity
return
len
(
activeObjectQueue
)
<
self
.
capacity
thecaller
=
callerObject
thecaller
=
callerObject
return
len
(
activeObjectQueue
)
<
activeObject
.
capacity
and
(
thecaller
in
activeObject
.
previous
)
return
len
(
activeObjectQueue
)
<
self
.
capacity
and
(
thecaller
in
self
.
previous
)
# =======================================================================
# =======================================================================
# checks if the Queue can dispose an entity to the following object
# checks if the Queue can dispose an entity to the following object
...
@@ -150,29 +148,24 @@ class Queue(CoreObject):
...
@@ -150,29 +148,24 @@ class Queue(CoreObject):
# this is kind of slow I think got to check
# this is kind of slow I think got to check
# =======================================================================
# =======================================================================
def
haveToDispose
(
self
,
callerObject
=
None
):
def
haveToDispose
(
self
,
callerObject
=
None
):
# get active object and its queue
activeObjectQueue
=
self
.
Res
.
activeQ
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
#if we have only one possible receiver just check if the Queue holds one or more entities
#if we have only one possible receiver just check if the Queue holds one or more entities
if
(
callerObject
==
None
):
if
(
callerObject
==
None
):
return
len
(
activeObjectQueue
)
>
0
return
len
(
activeObjectQueue
)
>
0
thecaller
=
callerObject
thecaller
=
callerObject
return
len
(
activeObjectQueue
)
>
0
and
(
thecaller
in
activeObject
.
next
)
return
len
(
activeObjectQueue
)
>
0
and
(
thecaller
in
self
.
next
)
# =======================================================================
# =======================================================================
# removes an entity from the Object
# removes an entity from the Object
# =======================================================================
# =======================================================================
def
removeEntity
(
self
,
entity
=
None
):
def
removeEntity
(
self
,
entity
=
None
):
activeObject
=
self
.
getActiveObject
()
activeEntity
=
CoreObject
.
removeEntity
(
self
,
entity
)
#run the default method
activeEntity
=
CoreObject
.
removeEntity
(
self
,
entity
)
#run the default method
if
self
.
canAccept
():
if
self
.
canAccept
():
self
.
signalGiver
()
self
.
signalGiver
()
# TODO: disable that for the mouldAssemblyBuffer
# TODO: disable that for the mouldAssemblyBuffer
if
not
self
.
__class__
.
__name__
==
'MouldAssemblyBuffer'
:
if
not
self
.
__class__
.
__name__
==
'MouldAssemblyBuffer'
:
if
self
.
haveToDispose
():
if
self
.
haveToDispose
():
self
.
printTrace
(
self
.
id
,
attemptSignalReceiver
=
'(removeEntity)'
)
#
self.printTrace(self.id, attemptSignalReceiver='(removeEntity)')
self
.
signalReceiver
()
self
.
signalReceiver
()
return
activeEntity
return
activeEntity
...
@@ -182,14 +175,10 @@ class Queue(CoreObject):
...
@@ -182,14 +175,10 @@ class Queue(CoreObject):
# also updates the predecessorIndex to the one that is to be taken
# also updates the predecessorIndex to the one that is to be taken
# =======================================================================
# =======================================================================
def
canAcceptAndIsRequested
(
self
,
callerObject
=
None
):
def
canAcceptAndIsRequested
(
self
,
callerObject
=
None
):
# get the active and the giver objects
activeObjectQueue
=
self
.
Res
.
activeQ
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
# giverObject=self.getGiverObject()
giverObject
=
callerObject
giverObject
=
callerObject
assert
giverObject
,
'there must be a caller for canAcceptAndIsRequested'
assert
giverObject
,
'there must be a caller for canAcceptAndIsRequested'
return
len
(
activeObjectQueue
)
<
activeObject
.
capacity
and
giverObject
.
haveToDispose
(
activeObject
)
return
len
(
activeObjectQueue
)
<
self
.
capacity
and
giverObject
.
haveToDispose
(
self
)
# =======================================================================
# =======================================================================
# gets an entity from the predecessor that
# gets an entity from the predecessor that
...
@@ -203,13 +192,12 @@ class Queue(CoreObject):
...
@@ -203,13 +192,12 @@ class Queue(CoreObject):
# checks whether the entity can proceed to a successor object
# checks whether the entity can proceed to a successor object
#===========================================================================
#===========================================================================
def
canDeliver
(
self
,
entity
=
None
):
def
canDeliver
(
self
,
entity
=
None
):
activeObject
=
self
.
getActiveObject
()
assert
self
.
isInActiveQueue
(
entity
),
entity
.
id
+
' not in the internalQueue of'
+
self
.
id
assert
activeObject
.
isInActiveQueue
(
entity
),
entity
.
id
+
' not in the internalQueue of'
+
activeObject
.
id
activeEntity
=
entity
activeEntity
=
entity
mayProceed
=
False
mayProceed
=
False
# for all the possible receivers of an entity check whether they can accept and then set accordingly the canProceed flag of the entity
# for all the possible receivers of an entity check whether they can accept and then set accordingly the canProceed flag of the entity
for
nextObject
in
[
object
for
object
in
activeObject
.
next
if
object
.
canAcceptEntity
(
activeEntity
)]:
for
nextObject
in
[
object
for
object
in
self
.
next
if
object
.
canAcceptEntity
(
activeEntity
)]:
activeEntity
.
proceed
=
True
activeEntity
.
proceed
=
True
activeEntity
.
candidateReceivers
.
append
(
nextObject
)
activeEntity
.
candidateReceivers
.
append
(
nextObject
)
mayProceed
=
True
mayProceed
=
True
...
@@ -296,7 +284,7 @@ class Queue(CoreObject):
...
@@ -296,7 +284,7 @@ class Queue(CoreObject):
for
obj
in
G
.
ObjList
:
for
obj
in
G
.
ObjList
:
if
obj
.
id
in
nextObjIds
:
if
obj
.
id
in
nextObjIds
:
nextObject
=
obj
nextObject
=
obj
entity
.
nextQueueLength
=
len
(
nextObject
.
getActiveObjectQueue
()
)
entity
.
nextQueueLength
=
len
(
nextObject
.
Res
.
activeQ
)
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
nextQueueLength
)
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
nextQueueLength
)
else
:
else
:
assert
False
,
"Unknown scheduling criterion %r"
%
(
criterion
,
)
assert
False
,
"Unknown scheduling criterion %r"
%
(
criterion
,
)
...
...
dream/simulation/QueueJobShop.py
View file @
e5dca2a1
...
@@ -49,32 +49,30 @@ class QueueJobShop(Queue):
...
@@ -49,32 +49,30 @@ class QueueJobShop(Queue):
# and returns true only if the active object is the next station
# and returns true only if the active object is the next station
# =======================================================================
# =======================================================================
def
canAccept
(
self
,
callerObject
=
None
):
def
canAccept
(
self
,
callerObject
=
None
):
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
Res
.
activeQ
activeObjectQueue
=
activeObject
.
getActiveObjectQueue
()
thecaller
=
callerObject
thecaller
=
callerObject
#return according to the state of the Queue
#return according to the state of the Queue
#check it the caller object holds an Entity that requests for current object
#check it the caller object holds an Entity that requests for current object
return
len
(
self
.
getActiveObjectQueue
())
<
activeObject
.
capacity
\
return
len
(
self
.
Res
.
activeQ
)
<
self
.
capacity
\
and
activeObject
.
isInRoute
(
callerObject
)
and
self
.
isInRoute
(
callerObject
)
#===========================================================================
#===========================================================================
# method used to check whether the station is in the entity-to-be-received route
# method used to check whether the station is in the entity-to-be-received route
# TODO: consider giving the activeEntity as attribute
# TODO: consider giving the activeEntity as attribute
#===========================================================================
#===========================================================================
def
isInRoute
(
self
,
callerObject
=
None
):
def
isInRoute
(
self
,
callerObject
=
None
):
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
Res
.
activeQ
activeObjectQueue
=
activeObject
.
getActiveObjectQueue
()
thecaller
=
callerObject
thecaller
=
callerObject
# if the caller is not defined then return True. We are only interested in checking whether
# if the caller is not defined then return True. We are only interested in checking whether
# the station can accept whatever entity from whichever giver
# the station can accept whatever entity from whichever giver
if
not
thecaller
:
if
not
thecaller
:
return
True
return
True
#check it the caller object holds an Entity that requests for current object
#check it the caller object holds an Entity that requests for current object
if
len
(
thecaller
.
getActiveObjectQueue
()
)
>
0
:
if
len
(
thecaller
.
Res
.
activeQ
)
>
0
:
# TODO: make sure that the first entity of the callerObject is to be disposed
# TODO: make sure that the first entity of the callerObject is to be disposed
activeEntity
=
thecaller
.
getActiveObjectQueue
()
[
0
]
activeEntity
=
thecaller
.
Res
.
activeQ
[
0
]
# if the machine's Id is in the list of the entity's next stations
# if the machine's Id is in the list of the entity's next stations
if
activeObject
.
id
in
activeEntity
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[]):
if
self
.
id
in
activeEntity
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[]):
return
True
return
True
return
False
return
False
...
@@ -83,9 +81,7 @@ class QueueJobShop(Queue):
...
@@ -83,9 +81,7 @@ class QueueJobShop(Queue):
# Returns True only to the potential receiver
# Returns True only to the potential receiver
# =======================================================================
# =======================================================================
def
haveToDispose
(
self
,
callerObject
=
None
):
def
haveToDispose
(
self
,
callerObject
=
None
):
# get active object and its queue
activeObjectQueue
=
self
.
Res
.
activeQ
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
thecaller
=
callerObject
thecaller
=
callerObject
#if we have only one possible receiver just check if the Queue holds one or more entities
#if we have only one possible receiver just check if the Queue holds one or more entities
if
(
callerObject
==
None
):
if
(
callerObject
==
None
):
...
@@ -93,26 +89,23 @@ class QueueJobShop(Queue):
...
@@ -93,26 +89,23 @@ class QueueJobShop(Queue):
#return True if the Queue has Entities and the caller is in the self.next list
#return True if the Queue has Entities and the caller is in the self.next list
return
len
(
activeObjectQueue
)
>
0
\
return
len
(
activeObjectQueue
)
>
0
\
and
(
thecaller
in
activeObject
.
next
)
\
and
(
thecaller
in
self
.
next
)
\
and
thecaller
.
isInRoute
(
activeObject
)
and
thecaller
.
isInRoute
(
self
)
#===========================================================================
#===========================================================================
# extend the default behaviour to check if whether the station
# extend the default behaviour to check if whether the station
# is in the route of the entity to be received
# is in the route of the entity to be received
#===========================================================================
#===========================================================================
def
canAcceptAndIsRequested
(
self
,
callerObject
=
None
):
def
canAcceptAndIsRequested
(
self
,
callerObject
=
None
):
activeObject
=
self
.
getActiveObject
()
# giverObject=activeObject.getGiverObject()
giverObject
=
callerObject
giverObject
=
callerObject
assert
giverObject
,
'there must be a caller for canAcceptAndIsRequested'
assert
giverObject
,
'there must be a caller for canAcceptAndIsRequested'
if
activeObject
.
isInRoute
(
giverObject
):
if
self
.
isInRoute
(
giverObject
):
return
Queue
.
canAcceptAndIsRequested
(
self
,
giverObject
)
return
Queue
.
canAcceptAndIsRequested
(
self
,
giverObject
)
# =======================================================================
# =======================================================================
# gets an entity from the predecessor that the predecessor index points to
# gets an entity from the predecessor that the predecessor index points to
# =======================================================================
# =======================================================================
def
getEntity
(
self
):
def
getEntity
(
self
):
activeObject
=
self
.
getActiveObject
()
activeEntity
=
Queue
.
getEntity
(
self
)
activeEntity
=
Queue
.
getEntity
(
self
)
activeEntity
.
remainingRoute
.
pop
(
0
)
#remove data from the remaining route of the entity
activeEntity
.
remainingRoute
.
pop
(
0
)
#remove data from the remaining route of the entity
return
activeEntity
return
activeEntity
...
@@ -121,7 +114,6 @@ class QueueJobShop(Queue):
...
@@ -121,7 +114,6 @@ class QueueJobShop(Queue):
# update the next list of the object after reading the remaining list of the activeEntity
# update the next list of the object after reading the remaining list of the activeEntity
#===========================================================================
#===========================================================================
def
updateNext
(
self
,
entity
=
None
):
def
updateNext
(
self
,
entity
=
None
):
activeObject
=
self
.
getActiveObject
()
activeEntity
=
entity
activeEntity
=
entity
# read the possible receivers - update the next list
# read the possible receivers - update the next list
import
Globals
import
Globals
...
@@ -133,27 +125,26 @@ class QueueJobShop(Queue):
...
@@ -133,27 +125,26 @@ class QueueJobShop(Queue):
# update the next list of the object
# update the next list of the object
for
nextObject
in
nextObjects
:
for
nextObject
in
nextObjects
:
# append only if not already in the list
# append only if not already in the list
if
nextObject
not
in
activeObject
.
next
:
if
nextObject
not
in
self
.
next
:
activeObject
.
next
.
append
(
nextObject
)
self
.
next
.
append
(
nextObject
)
# =======================================================================
# =======================================================================
# removes an entity from the Queue
# removes an entity from the Queue
# extension to remove possible receivers accordingly
# extension to remove possible receivers accordingly
# =======================================================================
# =======================================================================
def
removeEntity
(
self
,
entity
=
None
):
def
removeEntity
(
self
,
entity
=
None
):
activeObject
=
self
.
getActiveObject
()
receiverObject
=
self
.
getReceiverObject
()
receiverObject
=
activeObject
.
getReceiverObject
()
#run the default method
#run the default method
activeEntity
=
Queue
.
removeEntity
(
self
,
entity
)
activeEntity
=
Queue
.
removeEntity
(
self
,
entity
)
removeReceiver
=
True
removeReceiver
=
True
# search in the internalQ. If an entity has the same receiver do not remove
# search in the internalQ. If an entity has the same receiver do not remove
for
ent
in
self
.
getActiveObjectQueue
()
:
for
ent
in
self
.
Res
.
activeQ
:
nextObjectIds
=
ent
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[])
nextObjectIds
=
ent
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[])
if
receiverObject
.
id
in
nextObjectIds
:
if
receiverObject
.
id
in
nextObjectIds
:
removeReceiver
=
False
removeReceiver
=
False
# if not entity had the same receiver then the receiver will be removed
# if not entity had the same receiver then the receiver will be removed
if
removeReceiver
:
if
removeReceiver
:
activeObject
.
next
.
remove
(
receiverObject
)
self
.
next
.
remove
(
receiverObject
)
return
activeEntity
return
activeEntity
\ No newline at end of file
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