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
Show 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):
# run method of the queue
#===========================================================================
def
run
(
self
):
activeObjectQueue
=
self
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
Res
.
activeQ
# check if there is WIP and signal receiver
self
.
initialSignalReceiver
()
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
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
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
self
.
isRequested
.
signalparam
=
None
self
.
getEntity
()
...
...
@@ -115,11 +115,11 @@ class Queue(CoreObject):
self
.
loadOperatorAvailable
.
signalparam
=
None
# if the queue received an canDispose with signalparam time, this means that the signals was sent from a MouldAssemblyBuffer
if
self
.
canDispose
.
signalparam
:
self
.
printTrace
(
self
.
id
,
canDispose
=
''
)
#
self.printTrace(self.id, canDispose='')
self
.
canDispose
.
signalparam
=
None
# if the event that activated the thread is canDispose then signalReceiver
if
self
.
haveToDispose
():
self
.
printTrace
(
self
.
id
,
attemptSignalReceiver
=
'(generator)'
)
#
self.printTrace(self.id, attemptSignalReceiver='(generator)')
if
self
.
receiver
:
if
not
self
.
receiver
.
entryIsAssignedTo
():
self
.
signalReceiver
()
...
...
@@ -132,16 +132,14 @@ class Queue(CoreObject):
# only to the predecessor that will give the entity.
# =======================================================================
def
canAccept
(
self
,
callerObject
=
None
):
# get active and giver objects
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
Res
.
activeQ
#if we have only one predecessor just check if there is a place available
# this is done to achieve better (cpu) processing time
# then we can also use it as a filter for a yield method
if
(
callerObject
==
None
):
return
len
(
activeObjectQueue
)
<
activeObject
.
capacity
return
len
(
activeObjectQueue
)
<
self
.
capacity
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
...
...
@@ -150,29 +148,24 @@ class Queue(CoreObject):
# this is kind of slow I think got to check
# =======================================================================
def
haveToDispose
(
self
,
callerObject
=
None
):
# get active object and its queue
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
Res
.
activeQ
#if we have only one possible receiver just check if the Queue holds one or more entities
if
(
callerObject
==
None
):
return
len
(
activeObjectQueue
)
>
0
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
# =======================================================================
def
removeEntity
(
self
,
entity
=
None
):
activeObject
=
self
.
getActiveObject
()
activeEntity
=
CoreObject
.
removeEntity
(
self
,
entity
)
#run the default method
if
self
.
canAccept
():
self
.
signalGiver
()
# TODO: disable that for the mouldAssemblyBuffer
if
not
self
.
__class__
.
__name__
==
'MouldAssemblyBuffer'
:
if
self
.
haveToDispose
():
self
.
printTrace
(
self
.
id
,
attemptSignalReceiver
=
'(removeEntity)'
)
#
self.printTrace(self.id, attemptSignalReceiver='(removeEntity)')
self
.
signalReceiver
()
return
activeEntity
...
...
@@ -182,14 +175,10 @@ class Queue(CoreObject):
# also updates the predecessorIndex to the one that is to be taken
# =======================================================================
def
canAcceptAndIsRequested
(
self
,
callerObject
=
None
):
# get the active and the giver objects
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
# giverObject=self.getGiverObject()
activeObjectQueue
=
self
.
Res
.
activeQ
giverObject
=
callerObject
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
...
...
@@ -203,13 +192,12 @@ class Queue(CoreObject):
# checks whether the entity can proceed to a successor object
#===========================================================================
def
canDeliver
(
self
,
entity
=
None
):
activeObject
=
self
.
getActiveObject
()
assert
activeObject
.
isInActiveQueue
(
entity
),
entity
.
id
+
' not in the internalQueue of'
+
activeObject
.
id
assert
self
.
isInActiveQueue
(
entity
),
entity
.
id
+
' not in the internalQueue of'
+
self
.
id
activeEntity
=
entity
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
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
.
candidateReceivers
.
append
(
nextObject
)
mayProceed
=
True
...
...
@@ -296,7 +284,7 @@ class Queue(CoreObject):
for
obj
in
G
.
ObjList
:
if
obj
.
id
in
nextObjIds
:
nextObject
=
obj
entity
.
nextQueueLength
=
len
(
nextObject
.
getActiveObjectQueue
()
)
entity
.
nextQueueLength
=
len
(
nextObject
.
Res
.
activeQ
)
activeObjectQ
.
sort
(
key
=
lambda
x
:
x
.
nextQueueLength
)
else
:
assert
False
,
"Unknown scheduling criterion %r"
%
(
criterion
,
)
...
...
dream/simulation/QueueJobShop.py
View file @
e5dca2a1
...
...
@@ -49,32 +49,30 @@ class QueueJobShop(Queue):
# and returns true only if the active object is the next station
# =======================================================================
def
canAccept
(
self
,
callerObject
=
None
):
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
activeObject
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
Res
.
activeQ
thecaller
=
callerObject
#return according to the state of the Queue
#check it the caller object holds an Entity that requests for current object
return
len
(
self
.
getActiveObjectQueue
())
<
activeObject
.
capacity
\
and
activeObject
.
isInRoute
(
callerObject
)
return
len
(
self
.
Res
.
activeQ
)
<
self
.
capacity
\
and
self
.
isInRoute
(
callerObject
)
#===========================================================================
# method used to check whether the station is in the entity-to-be-received route
# TODO: consider giving the activeEntity as attribute
#===========================================================================
def
isInRoute
(
self
,
callerObject
=
None
):
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
activeObject
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
Res
.
activeQ
thecaller
=
callerObject
# 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
if
not
thecaller
:
return
True
#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
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
activeObject
.
id
in
activeEntity
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[]):
if
self
.
id
in
activeEntity
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[]):
return
True
return
False
...
...
@@ -83,9 +81,7 @@ class QueueJobShop(Queue):
# Returns True only to the potential receiver
# =======================================================================
def
haveToDispose
(
self
,
callerObject
=
None
):
# get active object and its queue
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
Res
.
activeQ
thecaller
=
callerObject
#if we have only one possible receiver just check if the Queue holds one or more entities
if
(
callerObject
==
None
):
...
...
@@ -93,26 +89,23 @@ class QueueJobShop(Queue):
#return True if the Queue has Entities and the caller is in the self.next list
return
len
(
activeObjectQueue
)
>
0
\
and
(
thecaller
in
activeObject
.
next
)
\
and
thecaller
.
isInRoute
(
activeObject
)
and
(
thecaller
in
self
.
next
)
\
and
thecaller
.
isInRoute
(
self
)
#===========================================================================
# extend the default behaviour to check if whether the station
# is in the route of the entity to be received
#===========================================================================
def
canAcceptAndIsRequested
(
self
,
callerObject
=
None
):
activeObject
=
self
.
getActiveObject
()
# giverObject=activeObject.getGiverObject()
giverObject
=
callerObject
assert
giverObject
,
'there must be a caller for canAcceptAndIsRequested'
if
activeObject
.
isInRoute
(
giverObject
):
if
self
.
isInRoute
(
giverObject
):
return
Queue
.
canAcceptAndIsRequested
(
self
,
giverObject
)
# =======================================================================
# gets an entity from the predecessor that the predecessor index points to
# =======================================================================
def
getEntity
(
self
):
activeObject
=
self
.
getActiveObject
()
activeEntity
=
Queue
.
getEntity
(
self
)
activeEntity
.
remainingRoute
.
pop
(
0
)
#remove data from the remaining route of the entity
return
activeEntity
...
...
@@ -121,7 +114,6 @@ class QueueJobShop(Queue):
# update the next list of the object after reading the remaining list of the activeEntity
#===========================================================================
def
updateNext
(
self
,
entity
=
None
):
activeObject
=
self
.
getActiveObject
()
activeEntity
=
entity
# read the possible receivers - update the next list
import
Globals
...
...
@@ -133,27 +125,26 @@ class QueueJobShop(Queue):
# update the next list of the object
for
nextObject
in
nextObjects
:
# append only if not already in the list
if
nextObject
not
in
activeObject
.
next
:
activeObject
.
next
.
append
(
nextObject
)
if
nextObject
not
in
self
.
next
:
self
.
next
.
append
(
nextObject
)
# =======================================================================
# removes an entity from the Queue
# extension to remove possible receivers accordingly
# =======================================================================
def
removeEntity
(
self
,
entity
=
None
):
activeObject
=
self
.
getActiveObject
()
receiverObject
=
activeObject
.
getReceiverObject
()
receiverObject
=
self
.
getReceiverObject
()
#run the default method
activeEntity
=
Queue
.
removeEntity
(
self
,
entity
)
removeReceiver
=
True
# 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'
,[])
if
receiverObject
.
id
in
nextObjectIds
:
removeReceiver
=
False
# if not entity had the same receiver then the receiver will be removed
if
removeReceiver
:
activeObject
.
next
.
remove
(
receiverObject
)
self
.
next
.
remove
(
receiverObject
)
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