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
23c117cb
Commit
23c117cb
authored
May 16, 2014
by
Ioannis Papagiannopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new method prinTrace for printing on console
parent
b84a9fd4
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
88 additions
and
143 deletions
+88
-143
dream/simulation/CoreObject.py
dream/simulation/CoreObject.py
+19
-26
dream/simulation/Globals.py
dream/simulation/Globals.py
+4
-0
dream/simulation/LineGenerationJSON.py
dream/simulation/LineGenerationJSON.py
+1
-0
dream/simulation/Machine.py
dream/simulation/Machine.py
+8
-14
dream/simulation/ObjectInterruption.py
dream/simulation/ObjectInterruption.py
+9
-1
dream/simulation/OperatedPoolBroker.py
dream/simulation/OperatedPoolBroker.py
+8
-20
dream/simulation/OperatorRouter.py
dream/simulation/OperatorRouter.py
+32
-75
dream/simulation/Queue.py
dream/simulation/Queue.py
+7
-7
No files found.
dream/simulation/CoreObject.py
View file @
23c117cb
...
...
@@ -266,10 +266,7 @@ class CoreObject(Process):
#if the receiver does not hold an Entity that is also critical
if
not
self
.
receiver
.
getActiveObjectQueue
()[
0
].
isCritical
:
self
.
receiver
.
shouldPreempt
=
True
#=======================================================
# testing
# print now(), self.id, 'preempting receiver', self.receiver.id,'.. '*6
#=======================================================
self
.
printTrace
(
self
.
id
,
'preempting receiver'
+
self
.
receiver
.
id
+
'.. '
*
6
)
self
.
receiver
.
preempt
()
self
.
receiver
.
timeLastEntityEnded
=
now
()
#required to count blockage correctly in the preemptied station
...
...
@@ -310,10 +307,7 @@ class CoreObject(Process):
# the hot flag should not be raised
if
successorsAreMachines
:
activeEntity
.
hot
=
True
#=======================================================================
# # TESTING
# print now(), activeEntity.name, "got into "+self.id
#=======================================================================
self
.
printTrace
(
activeEntity
.
name
,
"got into "
+
self
.
id
)
# update wipStatList
if
self
.
gatherWipStat
:
self
.
wipStatList
.
append
([
now
(),
len
(
activeObjectQueue
)])
...
...
@@ -333,7 +327,7 @@ class CoreObject(Process):
# signal the successor that the object can dispose an entity
# =======================================================================
def
signalReceiver
(
self
):
#
print now(), self.id, 'trying to signal receiver'
#
self.printTrace(self.id, 'trying to signal receiver')
activeObject
=
self
.
getActiveObject
()
possibleReceivers
=
activeObject
.
findReceivers
()
if
possibleReceivers
:
...
...
@@ -356,10 +350,7 @@ class CoreObject(Process):
activeObject
.
receiver
=
receiver
activeObject
.
receiver
.
giver
=
activeObject
#===================================================================
# # TESTING
# print now(), self.id,' '*50, 'signalling receiver', self.receiver.id
#===================================================================
self
.
printTrace
(
self
.
id
,
' '
*
50
+
'signalling receiver '
+
self
.
receiver
.
id
)
# assign the entry of the receiver
activeObject
.
receiver
.
assignEntryTo
()
activeObject
.
receiver
.
isRequested
.
signal
(
activeObject
)
...
...
@@ -392,10 +383,7 @@ class CoreObject(Process):
if
receiver
.
isLoadRequested
():
from
Globals
import
G
if
not
G
.
Router
.
invoked
:
#===================================================================
# # TESTING
# print now(), self.id,' '*50, 'signalling router'
#===================================================================
self
.
printTrace
(
self
.
id
,
' '
*
50
+
'signalling router'
)
G
.
Router
.
invoked
=
True
G
.
Router
.
isCalled
.
signal
(
now
())
return
True
...
...
@@ -425,7 +413,7 @@ class CoreObject(Process):
# signal the giver that the entity is removed from its internalQueue
# =======================================================================
def
signalGiver
(
self
):
#
print now(), self.id, 'trying to signal giver'
#
self.printTrace(self.id, 'trying to signal giver')
activeObject
=
self
.
getActiveObject
()
possibleGivers
=
activeObject
.
findGivers
()
if
possibleGivers
:
...
...
@@ -440,10 +428,7 @@ class CoreObject(Process):
giversReceiver
=
activeObject
activeObject
.
giver
=
giver
activeObject
.
giver
.
receiver
=
activeObject
#===================================================================
# # TESTING
# print now(), self.id,' '*50, 'signalling giver', self.giver.id
#===================================================================
self
.
printTrace
(
self
.
id
,
' '
*
50
+
'signalling giver '
+
self
.
giver
.
id
)
activeObject
.
giver
.
canDispose
.
signal
(
activeObject
)
return
True
return
False
...
...
@@ -497,8 +482,17 @@ class CoreObject(Process):
if
(
G
.
traceIndex
==
65536
):
G
.
traceIndex
=
0
G
.
sheetIndex
+=
1
G
.
traceSheet
=
G
.
traceFile
.
add_sheet
(
'sheet '
+
str
(
G
.
sheetIndex
),
cell_overwrite_ok
=
True
)
G
.
traceSheet
=
G
.
traceFile
.
add_sheet
(
'sheet '
+
str
(
G
.
sheetIndex
),
cell_overwrite_ok
=
True
)
#===========================================================================
# prints message to the console
#===========================================================================
#print message in the console. Format is (Simulation Time | Entity or Frame Name | message)
def
printTrace
(
self
,
entityName
,
message
):
from
Globals
import
G
if
(
G
.
console
==
"Yes"
):
#output only if the user has selected to
print
now
(),
entityName
,
message
# =======================================================================
# outputs data to "output.xls"
# =======================================================================
...
...
@@ -604,15 +598,14 @@ class CoreObject(Process):
# assign Exit of the object
# =======================================================================
def
assignExitTo
(
self
,
callerObject
=
None
):
# print self.id, 'assignExit'
# self.exitAssignedToReceiver = self.receiver
# self.printTrace(self.id, 'assignExit')
self
.
exitAssignedToReceiver
=
callerObject
# =======================================================================
# unblock the object
# =======================================================================
def
unAssignExit
(
self
):
#
print now(),self.id, 'unassignExit'
#
self.printTrace(self.id, 'unassignExit')
self
.
exitAssignedToReceiver
=
None
# =======================================================================
...
...
dream/simulation/Globals.py
View file @
23c117cb
...
...
@@ -50,6 +50,10 @@ class G:
Base
=
1
#the Base time unit. Default =1 minute
maxSimTime
=
0
#the total simulation time
# flag for printing in console
# -----------------------------------------------------------------------
console
=
""
# data for the trace output in excel
# -----------------------------------------------------------------------
trace
=
""
#this is written from input. If it is "Yes" then you write to trace, else we do not
...
...
dream/simulation/LineGenerationJSON.py
View file @
23c117cb
...
...
@@ -103,6 +103,7 @@ def readGeneralInput():
G
.
numberOfReplications
=
int
(
general
.
get
(
'numberOfReplications'
,
'1'
))
# read the number of replications / default 1
G
.
maxSimTime
=
float
(
general
.
get
(
'maxSimTime'
,
'100'
))
# get the maxSimTime / default 100
G
.
trace
=
general
.
get
(
'trace'
,
'No'
)
# get trace in order to check if trace is requested
G
.
console
=
general
.
get
(
'console'
,
'No'
)
# get console flag in order to check if console print is requested
G
.
confidenceLevel
=
float
(
general
.
get
(
'confidenceLevel'
,
'0.95'
))
# get the confidence level
G
.
seed
=
general
.
get
(
'seed'
)
...
...
dream/simulation/Machine.py
View file @
23c117cb
...
...
@@ -226,12 +226,12 @@ class Machine(CoreObject):
while
1
:
# waitEvent isRequested /interruptionEnd/loadOperatorAvailable
while
1
:
#
print now(), self.id, 'will wait for event'
#
self.printTrace(self.id, 'will wait for event')
yield
waitevent
,
self
,
[
self
.
isRequested
,
self
.
interruptionEnd
,
self
.
loadOperatorAvailable
]
#
print now(), self.id, 'received an event'
#
self.printTrace(self.id, 'received an event')
# if the machine can accept an entity and one predecessor requests it continue with receiving the entity
if
self
.
isRequested
.
signalparam
:
#
print now(), self.id, 'received an isRequested event from', self.isRequested.signalparam.id
#
self.printTrace(self.id, 'received an isRequested event from'+self.isRequested.signalparam.id)
assert
self
.
isRequested
.
signalparam
==
self
.
giver
,
'the giver is not the requestingObject'
assert
self
.
giver
.
receiver
==
self
,
'the receiver of the signalling object in not the station'
# reset the signalparam of the isRequested event
...
...
@@ -241,9 +241,9 @@ class Machine(CoreObject):
# if an operator was rendered available while it was needed by the machine to proceed with getEntity
if
self
.
interruptionEnd
.
signalparam
==
now
()
or
self
.
loadOperatorAvailable
.
signalparam
==
now
():
# if self.interruptionEnd.signalparam==now():
#
print self.id, 'received an interruptionEnd event sent at ', self.interruptionEnd.signalparam
#
self.printTrace(self.id, 'received an interruptionEnd event sent at '+self.interruptionEnd.signalparam)
# elif self.loadOperatorAvailable.signalparam==now():
#
print now(), self.id, 'received an loadOperatorAvailable event sent at ', self.loadOperatorAvailable.signalparam
#
self.printTrace(self.id, 'received an loadOperatorAvailable event sent at '+self.loadOperatorAvailable.signalparam)
# try to signal the Giver, otherwise wait until it is requested
if
self
.
signalGiver
():
break
...
...
@@ -481,10 +481,7 @@ class Machine(CoreObject):
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
activeObject
.
getActiveObjectQueue
()
activeEntity
=
activeObjectQueue
[
0
]
#=======================================================================
# # TESTING
# print activeObject.getActiveObjectQueue()[0].name,"ended processing in "+activeObject.objName
#=======================================================================
self
.
printTrace
(
activeObject
.
getActiveObjectQueue
()[
0
].
name
,
"ended processing in "
+
activeObject
.
objName
)
# reset the variables used to handle the interruptions timing
self
.
timeRestartingProcessing
=
0
self
.
breakTime
=
0
...
...
@@ -539,10 +536,7 @@ class Machine(CoreObject):
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
activeObject
.
getActiveObjectQueue
()
activeEntity
=
activeObjectQueue
[
0
]
#=======================================================================
# testing
# print self.getActiveObjectQueue()[0].name, "Interrupted at ",self.objName, '. '*5
#=======================================================================
self
.
printTrace
(
self
.
getActiveObjectQueue
()[
0
].
name
,
"Interrupted at "
+
self
.
objName
+
'. '
*
5
)
# if the interrupt occured while processing an entity
if
not
activeObject
.
waitToDispose
:
# output to trace that the Machine (self.objName) got interrupted
...
...
@@ -747,7 +741,7 @@ class Machine(CoreObject):
activeObject
.
waitToDispose
=
False
# update the waitToDispose flag
# if the Machine canAccept then signal a giver
if
activeObject
.
canAccept
():
#
print self.id, now(), 'will try signalling a giver from removeEntity'
#
self.printTrace(self.id, 'will try signalling a giver from removeEntity')
activeObject
.
signalGiver
()
return
activeEntity
...
...
dream/simulation/ObjectInterruption.py
View file @
23c117cb
...
...
@@ -137,4 +137,12 @@ class ObjectInterruption(Process):
G
.
traceIndex
=
0
G
.
sheetIndex
+=
1
G
.
traceSheet
=
G
.
traceFile
.
add_sheet
(
'sheet '
+
str
(
G
.
sheetIndex
),
cell_overwrite_ok
=
True
)
\ No newline at end of file
#===========================================================================
# prints message to the console
#===========================================================================
#print message in the console. Format is (Simulation Time | Entity or Frame Name | message)
def
printTrace
(
self
,
entityName
,
message
):
from
Globals
import
G
if
(
G
.
console
==
"Yes"
):
#output only if the user has selected to
print
now
(),
entityName
,
message
\ No newline at end of file
dream/simulation/OperatedPoolBroker.py
View file @
23c117cb
...
...
@@ -49,7 +49,6 @@ class Broker(ObjectInterruption):
self
.
timeWaitForOperatorStarted
=
0
# Broker events
self
.
isCalled
=
SimEvent
(
'brokerIsCalled'
)
# self.victimQueueIsEmpty=SimEvent('victimQueueIsEmpty')
self
.
resourceAvailable
=
SimEvent
(
'resourceAvailable'
)
self
.
waitForOperator
=
False
...
...
@@ -76,7 +75,7 @@ class Broker(ObjectInterruption):
if
self
.
victim
.
isOperated
()
\
and
any
(
type
==
'Load'
or
type
==
'Setup'
or
type
==
'Processing'
\
for
type
in
self
.
victim
.
multOperationTypeList
):
#
print now(), self.victim.id, 'broker is invoked'
#
self.printTrace(self.victim.id, 'broker is invoked')
# update the time that the station is waiting for the operator
self
.
timeWaitForOperatorStarted
=
now
()
#===============================================================
...
...
@@ -88,30 +87,24 @@ class Broker(ObjectInterruption):
if
not
self
.
victim
.
currentEntity
in
G
.
pendingEntities
:
G
.
pendingEntities
.
append
(
self
.
victim
.
currentEntity
)
if
not
G
.
Router
.
invoked
:
#===========================================================
# testing
# print now(), self.victim.id, 'broker', ' '*50, 'signalling router'
#===========================================================
self
.
printTrace
(
self
.
victim
.
id
,
'broker'
+
' '
*
50
+
'signalling router'
)
G
.
Router
.
invoked
=
True
G
.
Router
.
isCalled
.
signal
(
now
())
self
.
waitForOperator
=
True
#
print now(), self.victim.id, 'broker waits till resource is available1'
#
self.printTrace(self.victim.id, 'broker waits till resource is available1')
yield
waitevent
,
self
,
self
.
resourceAvailable
# remove the currentEntity from the pendingEntities
if
self
.
victim
.
currentEntity
in
G
.
pendingEntities
:
G
.
pendingEntities
.
remove
(
self
.
victim
.
currentEntity
)
self
.
waitForOperator
=
False
#
print self.victim.id, 'received resourceAvailable event'
#
self.printTrace(self.victim.id, 'received resourceAvailable event')
#===============================================================
assert
self
.
victim
.
operatorPool
.
checkIfResourceIsAvailable
(),
'there is no available operator to request'
# set the available resource as the currentOperator
self
.
victim
.
currentOperator
=
self
.
victim
.
operatorPool
.
findAvailableOperator
()
yield
request
,
self
,
self
.
victim
.
operatorPool
.
getResource
(
self
.
victim
.
currentOperator
)
#===============================================================
# # TESTING
# print now(), self.victim.currentOperator.objName, 'started work in ', self.victim.id
#===============================================================
self
.
printTrace
(
self
.
victim
.
currentOperator
.
objName
,
'started work in '
+
self
.
victim
.
id
)
# clear the timeWaitForOperatorStarted variable
self
.
timeWaitForOperatorStarted
=
0
# update the time that the operation started
...
...
@@ -125,13 +118,11 @@ class Broker(ObjectInterruption):
yield
release
,
self
,
self
.
victim
.
operatorPool
.
getResource
(
self
.
victim
.
currentOperator
)
# signal the other brokers waiting for the same operators that they are now free
# also signal the stations that were not requested to receive because the operator was occupied
#===============================================================
# TESTING
# print now(), self.victim.id, 'broker signalling ROUTER'
#===============================================================
# TODO: signalling the router must be done more elegantly, router must be set as global variable
# if the router is already invoked then do not signal it again
if
not
self
.
victim
.
router
.
invoked
:
self
.
printTrace
(
self
.
victim
.
id
,
'broker'
+
' '
*
50
+
'signalling ROUTER'
)
self
.
victim
.
router
.
invoked
=
True
self
.
victim
.
router
.
isCalled
.
signal
(
now
())
# TODO: signalling the router will give the chance to it to take the control, but when will it eventually receive it.
...
...
@@ -139,10 +130,7 @@ class Broker(ObjectInterruption):
# TODO: this wont work for the moment. The actions that follow must be performed by all operated brokers.
# self.signalLoadStations()
#===============================================================
# # TESTING
# print now(), self.victim.currentOperator.objName, 'released', self.victim.id
#===============================================================
self
.
printTrace
(
self
.
victim
.
currentOperator
.
objName
,
'released '
+
self
.
victim
.
id
)
# the victim current operator must be cleared after the operator is released
self
.
timeLastOperationEnded
=
now
()
self
.
victim
.
currentOperator
=
None
...
...
dream/simulation/OperatorRouter.py
View file @
23c117cb
...
...
@@ -104,18 +104,17 @@ class Router(ObjectInterruption):
while
1
:
# wait until the router is called
yield
waitevent
,
self
,
self
.
isCalled
# print '=-'*15
# print now(), 'router received event'
self
.
printTrace
(
''
,
'=-'
*
15
)
self
.
printTrace
(
''
,
'router received event'
)
# wait till there are no more events, the machines must be blocked
while
1
:
# print Simulation.allEventNotices(sim)
if
now
()
in
Simulation
.
allEventTimes
(
sim
):
# print 'there are MORE events for now'
self
.
printTrace
(
''
,
'there are MORE events for now'
)
yield
hold
,
self
,
0
else
:
# print 'there are NO more events for now'
self
.
printTrace
(
''
,
'there are NO more events for now'
)
break
# print '=-'*15
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
...
...
@@ -160,11 +159,8 @@ class Router(ObjectInterruption):
object
.
unAssignExit
()
# signal the stations that ought to be signalled
self
.
signalOperatedStations
()
#===================================================================
# # testing
# print 'router exiting'
# print '=-'*20
#===================================================================
self
.
printTrace
(
''
,
'router exiting'
)
self
.
printTrace
(
''
,
'=-'
*
20
)
self
.
exit
()
#===========================================================================
...
...
@@ -182,10 +178,7 @@ class Router(ObjectInterruption):
# if the operator is not conflicting
if
not
operator
in
self
.
conflictingOperators
:
# assign an operator to the priorityObject
#=======================================================
# # testing
# print 'router will assign', operator.id, 'to', operator.candidateStation.id
#=======================================================
self
.
printTrace
(
'router'
,
' will assign'
+
operator
.
id
+
'to'
+
operator
.
candidateStation
.
id
)
operator
.
assignTo
(
operator
.
candidateStation
)
if
not
operator
.
candidateStation
in
self
.
toBeSignalled
:
self
.
toBeSignalled
.
append
(
operator
.
candidateStation
)
...
...
@@ -197,18 +190,11 @@ class Router(ObjectInterruption):
and
(
not
operator
in
self
.
conflictingOperators
)
\
and
operator
.
candidateEntity
.
candidateReceiver
:
# assign an operator to the priorityObject
#=======================================================
# # testing
# print 'router will assign', operator.id, 'to', operator.candidateEntity.candidateReceiver.id
#=======================================================
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
)
#===================================================================
# # testing
# print 'router found objects to be signalled'
# print [str(object.id) for object in self.toBeSignalled]
#===================================================================
self
.
printTrace
(
'objects to be signalled:'
+
' '
*
11
,
[
str
(
object
.
id
)
for
object
in
self
.
toBeSignalled
])
# =======================================================================
# return control to the Machine.run
...
...
@@ -251,29 +237,20 @@ class Router(ObjectInterruption):
assert
station
in
self
.
toBeSignalled
,
'the station must be in toBeSignalled list'
if
station
.
broker
.
waitForOperator
:
# signal this station's broker that the resource is available
#===========================================================
# # testing
# print now(), 'router signalling broker of ', operator.isAssignedTo().id
#===========================================================
self
.
printTrace
(
'router'
,
'signalling broker of'
+
' '
*
50
+
operator
.
isAssignedTo
().
id
)
station
.
broker
.
resourceAvailable
.
signal
(
now
())
else
:
# signal the queue proceeding the station
if
station
.
canAccept
()
\
and
any
(
type
==
'Load'
for
type
in
station
.
multOperationTypeList
):
#=======================================================
# # testing
# print now(), 'router signalling ', operator.isAssignedTo().id
#=======================================================
self
.
printTrace
(
'router'
,
'signalling'
+
' '
*
50
+
operator
.
isAssignedTo
().
id
)
station
.
loadOperatorAvailable
.
signal
(
now
())
# in case the router deals with managed entities
#------------------------------------------------------------------------------
else
:
if
station
in
self
.
pendingMachines
and
station
in
self
.
toBeSignalled
:
# signal this station's broker that the resource is available
#===========================================================
# # testing
# print now(), 'router signalling broker of', operator.isAssignedTo().id
#===========================================================
self
.
printTrace
(
'router'
,
'signalling broker of'
+
' '
*
50
+
operator
.
isAssignedTo
().
id
)
operator
.
isAssignedTo
().
broker
.
resourceAvailable
.
signal
(
now
())
elif
(
not
station
in
self
.
pendingMachines
)
or
(
not
station
in
self
.
toBeSignalled
):
# signal the queue proceeding the station
...
...
@@ -281,10 +258,7 @@ class Router(ObjectInterruption):
assert
operator
.
candidateEntity
.
currentStation
in
G
.
QueueList
,
'the candidateEntity currentStation to receive signal from Router is not a queue'
if
operator
.
candidateEntity
.
candidateReceiver
.
canAccept
()
\
and
any
(
type
==
'Load'
for
type
in
operator
.
candidateEntity
.
candidateReceiver
.
multOperationTypeList
):
#=======================================================
# # testing
# print now(), 'router signalling queue', operator.candidateEntity.currentStation.id
#=======================================================
self
.
printTrace
(
'router'
,
'signalling queue'
+
' '
*
50
+
operator
.
candidateEntity
.
currentStation
.
id
)
operator
.
candidateEntity
.
currentStation
.
loadOperatorAvailable
.
signal
(
now
())
#===========================================================================
...
...
@@ -314,12 +288,9 @@ class Router(ObjectInterruption):
break
# self.pendingMachines=[machine for machine in G.MachineList if machine.broker.waitForOperator]
self
.
pendingObjects
=
self
.
pendingQueues
+
self
.
pendingMachines
#=======================================================================
# # testing
# print 'router found pending objects', '-'*6,'>', [str(object.id) for object in self.pendingObjects]
# print 'pendingMachines', '-'*19,'>', [str(object.id) for object in self.pendingMachines]
# print 'pendingQueues', '-'*21,'>', [str(object.id) for object in self.pendingQueues]
#=======================================================================
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
(
'pendingQueues'
+
'-'
*
21
+
'>'
,
[
str
(
object
.
id
)
for
object
in
self
.
pendingQueues
])
#===========================================================================
# finding the entities that require manager now
...
...
@@ -339,10 +310,7 @@ class Router(ObjectInterruption):
if
self
.
pending
:
if
self
.
pending
[
0
].
manager
:
self
.
managed
=
True
#=======================================================================
# # testing
# print 'found pending entities', '-'*12,'>', [str(entity.id) for entity in self.pending if not entity.type=='Part']
#=======================================================================
self
.
printTrace
(
'found pending entities'
+
'-'
*
12
+
'>'
,
[
str
(
entity
.
id
)
for
entity
in
self
.
pending
if
not
entity
.
type
==
'Part'
])
#========================================================================
# Find candidate Operators
...
...
@@ -422,14 +390,11 @@ class Router(ObjectInterruption):
self
.
updateSchedulingRule
()
# find the candidateEntities for each operator
self
.
findCandidateEntities
()
#=======================================================================
# # testing
# print 'router found candidate operators'
# if self.managed:
# print [operator.id for operator in self.candidateOperators]
# else:
# print [(operator.id, [station.id for station in operator.candidateStations]) for operator in self.candidateOperators]
#=======================================================================
if
self
.
managed
:
self
.
printTrace
(
'router found candidate operators'
+
' '
*
3
,[
operator
.
id
for
operator
in
self
.
candidateOperators
])
else
:
self
.
printTrace
(
'router found candidate operators'
+
' '
*
3
,
[(
operator
.
id
,
[
station
.
id
for
station
in
operator
.
candidateStations
])
for
operator
in
self
.
candidateOperators
])
#===========================================================================
# find the candidate entities for each candidateOperator
...
...
@@ -496,14 +461,10 @@ class Router(ObjectInterruption):
if
operatorsWithOneOption
:
self
.
candidateOperators
.
sort
(
key
=
lambda
x
:
x
in
operatorsWithOneOption
,
reverse
=
True
)
#=======================================================================
# # testing
# if self.managed:
# print 'router found the candidate entities for each operator'
# print [(str(operator.id),\
# [str(x.id) for x in operator.candidateEntities])
# for operator in self.candidateOperators]
#=======================================================================
if
self
.
managed
:
self
.
printTrace
(
'candidateEntities for each operator'
,
[(
str
(
operator
.
id
),
\
[
str
(
x
.
id
)
for
x
in
operator
.
candidateEntities
])
for
operator
in
self
.
candidateOperators
])
#=======================================================================
# Sort pendingEntities
...
...
@@ -522,7 +483,7 @@ class Router(ObjectInterruption):
self
.
activeQSorter
(
criterion
=
self
.
schedulingRule
,
candList
=
candidateList
)
#=======================================================================
# # testing
#
print 'router sorted pending entities'
#
self.printTrace('router', ' sorted pending entities')
#=======================================================================
#=======================================================================
...
...
@@ -698,14 +659,10 @@ class Router(ObjectInterruption):
self
.
candidateOperators
.
remove
(
operator
)
self
.
calledOperators
.
remove
(
operator
)
#=======================================================================
# # testing
# if self.managed:
# print 'router found candidate receivers for each entity'
# print [(str(entity.id),\
# str(entity.candidateReceiver.id))
# for entity in self.pending if entity.candidateReceiver]
#=======================================================================
if
self
.
managed
:
self
.
printTrace
(
'candidateReceivers for each entity '
,[(
str
(
entity
.
id
),
\
str
(
entity
.
candidateReceiver
.
id
))
for
entity
in
self
.
pending
if
entity
.
candidateReceiver
])
# =======================================================================
# sorts the Operators of the Queue according to the scheduling rule
...
...
dream/simulation/Queue.py
View file @
23c117cb
...
...
@@ -95,13 +95,13 @@ class Queue(CoreObject):
# check if there is WIP and signal receiver
self
.
initialSignalReceiver
()
while
1
:
#
print self.id, 'will wait for event', now(
)
#
self.printTrace(self.id, 'will wait for event'
)
# wait until the Queue can accept an entity and one predecessor requests it
yield
waitevent
,
self
,
[
self
.
isRequested
,
self
.
canDispose
,
self
.
loadOperatorAvailable
]
#
print now(), self.id, 'just received an event'
#
self.printTrace(self.id, 'just received an event')
# if the event that activated the thread is isRequested then getEntity
if
self
.
isRequested
.
signalparam
:
#
print now(), self.id, 'received a isRequested event from', self.isRequested.signalparam.id
#
self.printTrace(self.id, 'received a isRequested event from'+self.isRequested.signalparam.id)
# reset the isRequested signal parameter
self
.
isRequested
.
signalparam
=
None
self
.
getEntity
()
...
...
@@ -110,15 +110,15 @@ class Queue(CoreObject):
activeObjectQueue
[
0
].
startTime
=
now
()
# if the queue received an loadOperatorIsAvailable (from Router) with signalparam time
if
self
.
loadOperatorAvailable
.
signalparam
:
#
print now(), self.id, 'received a loadOperatorAvailable event'
#
self.printTrace(self.id, 'received a loadOperatorAvailable event')
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
:
#
print now(), self.id, 'received a canDispose event'
#
self.printTrace(self.id, 'received a canDispose event')
self
.
canDispose
.
signalparam
=
None
# if the event that activated the thread is canDispose then signalReceiver
if
self
.
haveToDispose
():
#
print now(), self.id, 'will try to signal a receiver from generator'
#
self.printTrace(self.id, 'will try to signal a receiver from generator')
if
self
.
receiver
:
if
not
self
.
receiver
.
entryIsAssignedTo
():
self
.
signalReceiver
()
...
...
@@ -171,7 +171,7 @@ class Queue(CoreObject):
# TODO: disable that for the mouldAssemblyBuffer
if
not
self
.
__class__
.
__name__
==
'MouldAssemblyBuffer'
:
if
self
.
haveToDispose
():
#
print now(), self.id, 'will try to signal a receiver from removeEntity'
#
self.printTrace(self.id, 'will try to signal a receiver from removeEntity')
self
.
signalReceiver
()
return
activeEntity
...
...
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