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
8e5f31b4
Commit
8e5f31b4
authored
May 26, 2014
by
Ioannis Papagiannopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
printTrace method changed. Clean-up
parent
6ddc3dae
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
195 additions
and
210 deletions
+195
-210
dream/simulation/Assembly.py
dream/simulation/Assembly.py
+8
-16
dream/simulation/Conveyer.py
dream/simulation/Conveyer.py
+13
-29
dream/simulation/CoreObject.py
dream/simulation/CoreObject.py
+47
-88
dream/simulation/Dismantle.py
dream/simulation/Dismantle.py
+3
-6
dream/simulation/Globals.py
dream/simulation/Globals.py
+75
-0
dream/simulation/Machine.py
dream/simulation/Machine.py
+8
-34
dream/simulation/MachineJobShop.py
dream/simulation/MachineJobShop.py
+2
-4
dream/simulation/OperatedPoolBroker.py
dream/simulation/OperatedPoolBroker.py
+7
-13
dream/simulation/OperatorRouter.py
dream/simulation/OperatorRouter.py
+21
-2
dream/simulation/Queue.py
dream/simulation/Queue.py
+7
-14
dream/simulation/QueueManagedJob.py
dream/simulation/QueueManagedJob.py
+3
-3
dream/simulation/Source.py
dream/simulation/Source.py
+1
-1
No files found.
dream/simulation/Assembly.py
View file @
8e5f31b4
...
@@ -123,26 +123,22 @@ class Assembly(CoreObject):
...
@@ -123,26 +123,22 @@ class Assembly(CoreObject):
# 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, 'will wait for frame event')
self
.
printTrace
(
self
.
id
,
waitEvent
=
''
)
self
.
printTrace1
(
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.isRequested,self.canDispose, self.loadOperatorAvailable]
yield
waitevent
,
self
,
self
.
isRequested
#[self.isRequested,self.canDispose, self.loadOperatorAvailable]
if
self
.
isRequested
.
signalparam
:
if
self
.
isRequested
.
signalparam
:
# self.printTrace(self.id, 'received a isRequested event from '+self.isRequested.signalparam.id)
self
.
printTrace
(
self
.
id
,
isRequested
=
self
.
isRequested
.
signalparam
.
id
)
self
.
printTrace1
(
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
(
"Frame"
)
#get the Frame
self
.
getEntity
(
"Frame"
)
#get the Frame
for
i
in
range
(
self
.
getActiveObjectQueue
()[
0
].
capacity
):
#this loop will be carried until the Frame is full with the parts
for
i
in
range
(
self
.
getActiveObjectQueue
()[
0
].
capacity
):
#this loop will be carried until the Frame is full with the parts
self
.
printTrace1
(
self
.
id
,
waitEvent
=
'(to load parts)'
)
self
.
printTrace
(
self
.
id
,
waitEvent
=
'(to load parts)'
)
# self.printTrace(self.id, 'will wait for part event')
yield
waitevent
,
self
,
self
.
isRequested
yield
waitevent
,
self
,
self
.
isRequested
if
self
.
isRequested
.
signalparam
:
if
self
.
isRequested
.
signalparam
:
# self.printTrace(self.id, 'received a isRequested event from '+self.isRequested.signalparam.id)
self
.
printTrace
(
self
.
id
,
isRequested
=
self
.
isRequested
.
signalparam
.
id
)
self
.
printTrace1
(
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
# TODO: fix the getEntity 'Part' case
# TODO: fix the getEntity 'Part' case
...
@@ -166,8 +162,7 @@ class Assembly(CoreObject):
...
@@ -166,8 +162,7 @@ class Assembly(CoreObject):
self
.
completedJobs
+=
1
#Assembly completed a job
self
.
completedJobs
+=
1
#Assembly completed a job
self
.
waitToDispose
=
True
#since all the frame is full
self
.
waitToDispose
=
True
#since all the frame is full
# self.printTrace(self.id, 'will try to signal a receiver from generator')
self
.
printTrace
(
self
.
id
,
attemptSignalReceiver
=
'(generator'
)
self
.
printTrace1
(
self
.
id
,
attemptSignalReceiver
=
'(generator'
)
# signal the receiver that the activeObject has something to dispose of
# signal the receiver that the activeObject has something to dispose of
if
not
self
.
signalReceiver
():
if
not
self
.
signalReceiver
():
# if there was no available receiver, get into blocking control
# if there was no available receiver, get into blocking control
...
@@ -250,8 +245,7 @@ class Assembly(CoreObject):
...
@@ -250,8 +245,7 @@ class Assembly(CoreObject):
activeEntity
=
CoreObject
.
removeEntity
(
self
,
entity
)
#run the default method
activeEntity
=
CoreObject
.
removeEntity
(
self
,
entity
)
#run the default method
self
.
waitToDispose
=
False
self
.
waitToDispose
=
False
if
self
.
canAccept
():
if
self
.
canAccept
():
# self.printTrace(self.id, 'will try signalling a giver from removeEntity')
self
.
printTrace
(
self
.
id
,
attemptSignalGiver
=
'(removeEntity)'
)
self
.
printTrace1
(
self
.
id
,
attemptSignalGiver
=
'(removeEntity)'
)
self
.
signalGiver
()
self
.
signalGiver
()
return
activeEntity
return
activeEntity
...
@@ -276,8 +270,7 @@ class Assembly(CoreObject):
...
@@ -276,8 +270,7 @@ class Assembly(CoreObject):
assert
activeEntity
.
type
==
type
,
'the type of the entity to get must be of type '
+
type
+
' while it is '
+
activeEntity
.
type
assert
activeEntity
.
type
==
type
,
'the type of the entity to get must be of type '
+
type
+
' while it is '
+
activeEntity
.
type
#remove the entity from the previews object
#remove the entity from the previews object
giverObject
.
removeEntity
(
activeEntity
)
giverObject
.
removeEntity
(
activeEntity
)
# self.printTrace(activeEntity.name, "got into "+self.id)
self
.
printTrace
(
activeEntity
.
name
,
enter
=
self
.
id
)
self
.
printTrace1
(
activeEntity
.
name
,
enter
=
self
.
id
)
self
.
outputTrace
(
activeEntity
.
name
,
"got into "
+
self
.
objName
)
self
.
outputTrace
(
activeEntity
.
name
,
"got into "
+
self
.
objName
)
# if the type is Frame
# if the type is Frame
if
(
activeEntity
.
type
==
"Frame"
):
if
(
activeEntity
.
type
==
"Frame"
):
...
@@ -287,8 +280,7 @@ class Assembly(CoreObject):
...
@@ -287,8 +280,7 @@ class Assembly(CoreObject):
# if the frame is not fully loaded then signal a giver
# if the frame is not fully loaded then signal a giver
if
len
(
activeObjectQueue
[
0
].
getFrameQueue
())
<
activeObjectQueue
[
0
].
capacity
:
if
len
(
activeObjectQueue
[
0
].
getFrameQueue
())
<
activeObjectQueue
[
0
].
capacity
:
# self.printTrace(self.id, 'will try signalling a giver from getEntity')
self
.
printTrace
(
self
.
id
,
attemptSignalGiver
=
'(getEntity)'
)
self
.
printTrace1
(
self
.
id
,
attemptSignalGiver
=
'(getEntity)'
)
self
.
signalGiver
()
self
.
signalGiver
()
return
activeEntity
return
activeEntity
...
...
dream/simulation/Conveyer.py
View file @
8e5f31b4
...
@@ -100,13 +100,11 @@ class Conveyer(CoreObject):
...
@@ -100,13 +100,11 @@ class Conveyer(CoreObject):
# print self.id, 'time to move', self.conveyerMover.timeToWait
# print self.id, 'time to move', self.conveyerMover.timeToWait
self
.
conveyerMover
.
canMove
.
signal
(
now
())
self
.
conveyerMover
.
canMove
.
signal
(
now
())
# self.printTrace(self.id, 'will wait for event')
self
.
printTrace
(
self
.
id
,
waitEvent
=
''
)
self
.
printTrace1
(
self
.
id
,
waitEvent
=
''
)
yield
waitevent
,
self
,
[
self
.
isRequested
,
self
.
canDispose
,
self
.
moveEnd
]
# , self.loadOperatorAvailable]
yield
waitevent
,
self
,
[
self
.
isRequested
,
self
.
canDispose
,
self
.
moveEnd
]
# , self.loadOperatorAvailable]
# 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, 'received an is requested event')
self
.
printTrace
(
self
.
id
,
isRequested
=
''
)
self
.
printTrace1
(
self
.
id
,
isRequested
=
''
)
# reset the isRequested signal parameter
# reset the isRequested signal parameter
self
.
isRequested
.
signalparam
=
None
self
.
isRequested
.
signalparam
=
None
# get the entity
# get the entity
...
@@ -119,32 +117,26 @@ class Conveyer(CoreObject):
...
@@ -119,32 +117,26 @@ class Conveyer(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, 'received a canDispose event')
self
.
printTrace
(
self
.
id
,
canDispose
=
''
)
self
.
printTrace1
(
self
.
id
,
canDispose
=
''
)
self
.
canDispose
.
signalparam
=
None
self
.
canDispose
.
signalparam
=
None
# if the object received a moveEnd signal from the ConveyerMover
# if the object received a moveEnd signal from the ConveyerMover
if
self
.
moveEnd
.
signalparam
:
if
self
.
moveEnd
.
signalparam
:
# self.printTrace(self.id, 'received a moveEnd event')
self
.
printTrace
(
self
.
id
,
moveEnd
=
''
)
self
.
printTrace1
(
self
.
id
,
moveEnd
=
''
)
self
.
moveEnd
.
signalparam
=
None
self
.
moveEnd
.
signalparam
=
None
# check if there is a possibility to accept and signal a giver
# check if there is a possibility to accept and signal a giver
if
self
.
canAccept
():
if
self
.
canAccept
():
# self.printTrace(self.id, 'will try to signal Giver from removeEntity')
self
.
printTrace
(
self
.
id
,
attemptSignalGiver
=
'(removeEntity)'
)
self
.
printTrace1
(
self
.
id
,
attemptSignalGiver
=
'(removeEntity)'
)
self
.
signalGiver
()
self
.
signalGiver
()
# 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, 'will try to signal a receiver from generator')
self
.
printTrace
(
self
.
id
,
attemptSignalReceiver
=
'(generator)'
)
self
.
printTrace1
(
self
.
id
,
attemptSignalReceiver
=
'(generator)'
)
if
self
.
receiver
:
if
self
.
receiver
:
if
not
self
.
receiver
.
entryIsAssignedTo
():
if
not
self
.
receiver
.
entryIsAssignedTo
():
# self.printTrace(self.id, 'will try to signal receiver from generator1')
self
.
printTrace
(
self
.
id
,
attemptSignalReceiver
=
'(generator1)'
)
self
.
printTrace1
(
self
.
id
,
attemptSignalReceiver
=
'(generator1)'
)
self
.
signalReceiver
()
self
.
signalReceiver
()
continue
continue
# self.printTrace(self.id, 'will try to signal receiver from generator2')
self
.
printTrace
(
self
.
id
,
attemptSignalReceiver
=
'(generator2)'
)
self
.
printTrace1
(
self
.
id
,
attemptSignalReceiver
=
'(generator2)'
)
self
.
signalReceiver
()
self
.
signalReceiver
()
#===========================================================================
#===========================================================================
...
@@ -203,8 +195,7 @@ class Conveyer(CoreObject):
...
@@ -203,8 +195,7 @@ class Conveyer(CoreObject):
if
(
self
.
length
-
self
.
position
[
0
]
<
0.000001
)
and
(
not
self
.
entityLastReachedEnd
==
self
.
getActiveObjectQueue
()[
0
]):
if
(
self
.
length
-
self
.
position
[
0
]
<
0.000001
)
and
(
not
self
.
entityLastReachedEnd
==
self
.
getActiveObjectQueue
()[
0
]):
self
.
waitToDispose
=
True
self
.
waitToDispose
=
True
self
.
entityLastReachedEnd
=
self
.
getActiveObjectQueue
()[
0
]
self
.
entityLastReachedEnd
=
self
.
getActiveObjectQueue
()[
0
]
# self.printTrace(self.getActiveObjectQueue()[0].name, 'has reached the end'+' !! . !! .'*7)
self
.
printTrace
(
self
.
getActiveObjectQueue
()[
0
].
name
,
conveyerEnd
=
''
)
self
.
printTrace1
(
self
.
getActiveObjectQueue
()[
0
].
name
,
conveyerEnd
=
''
)
return
True
return
True
return
False
return
False
...
@@ -343,8 +334,7 @@ class Conveyer(CoreObject):
...
@@ -343,8 +334,7 @@ class Conveyer(CoreObject):
if
self
.
isFull
():
if
self
.
isFull
():
self
.
timeBlockageStarted
=
now
()
self
.
timeBlockageStarted
=
now
()
self
.
wasFull
=
True
self
.
wasFull
=
True
# self.printTrace(self.id, 'is now Full '+str(len(self.getActiveObjectQueue()))+' (*) '*20)
self
.
printTrace
(
self
.
id
,
conveyerFull
=
str
(
len
(
self
.
getActiveObjectQueue
())))
self
.
printTrace1
(
self
.
id
,
conveyerFull
=
str
(
len
(
self
.
getActiveObjectQueue
())))
return
activeEntity
return
activeEntity
#===========================================================================
#===========================================================================
...
@@ -367,8 +357,7 @@ class Conveyer(CoreObject):
...
@@ -367,8 +357,7 @@ class Conveyer(CoreObject):
self
.
conveyerMover
.
canMove
.
signal
(
now
())
self
.
conveyerMover
.
canMove
.
signal
(
now
())
# if there is anything to dispose of then signal a receiver
# if there is anything to dispose of then signal a receiver
if
self
.
haveToDispose
():
if
self
.
haveToDispose
():
# self.printTrace(self.id, 'will try to signal a receiver from removeEntity')
self
.
printTrace
(
self
.
id
,
attemptSingalReceiver
=
'(removeEntity)'
)
self
.
printTrace1
(
self
.
id
,
attemptSingalReceiver
=
'(removeEntity)'
)
self
.
signalReceiver
()
self
.
signalReceiver
()
return
activeEntity
return
activeEntity
...
@@ -521,18 +510,13 @@ class ConveyerMover(Process):
...
@@ -521,18 +510,13 @@ class ConveyerMover(Process):
#===========================================================================
#===========================================================================
def
run
(
self
):
def
run
(
self
):
while
1
:
while
1
:
# self.conveyer.printTrace(self.conveyer.id, 'mover will wait for canMove event')
self
.
conveyer
.
printTrace
(
self
.
conveyer
.
id
,
waitEvent
=
'(canMove)'
)
self
.
conveyer
.
printTrace1
(
self
.
conveyer
.
id
,
waitEvent
=
'(canMove)'
)
yield
waitevent
,
self
,
self
.
canMove
#wait until the conveyer triggers the mover
yield
waitevent
,
self
,
self
.
canMove
#wait until the conveyer triggers the mover
# self.conveyer.printTrace(self.conveyer.id, 'mover received canMove event')
self
.
conveyer
.
printTrace
(
self
.
conveyer
.
id
,
received
=
'(canMove)'
)
self
.
conveyer
.
printTrace1
(
self
.
conveyer
.
id
,
received
=
'(canMove)'
)
yield
hold
,
self
,
self
.
timeToWait
#wait for the time that the conveyer calculated
yield
hold
,
self
,
self
.
timeToWait
#wait for the time that the conveyer calculated
# print '. .'*40
# print 'conveyer moving entities'
# continue if interrupted
# continue if interrupted
self
.
conveyer
.
moveEntities
()
#move the entities of the conveyer
self
.
conveyer
.
moveEntities
()
#move the entities of the conveyer
# self.conveyer.call=False #reset call so it will be triggered only when it is needed again
self
.
conveyer
.
moveEnd
.
signal
(
now
())
self
.
conveyer
.
moveEnd
.
signal
(
now
())
...
...
dream/simulation/CoreObject.py
View file @
8e5f31b4
...
@@ -253,8 +253,7 @@ class CoreObject(Process):
...
@@ -253,8 +253,7 @@ class CoreObject(Process):
# update the next list of the object
# update the next list of the object
activeObject
.
updateNext
(
activeEntity
)
activeObject
.
updateNext
(
activeEntity
)
self
.
outputTrace
(
activeEntity
.
name
,
"got into "
+
self
.
objName
)
self
.
outputTrace
(
activeEntity
.
name
,
"got into "
+
self
.
objName
)
# self.printTrace(activeEntity.name, "got into "+self.id)
self
.
printTrace
(
activeEntity
.
name
,
enter
=
self
.
id
)
self
.
printTrace1
(
activeEntity
.
name
,
enter
=
self
.
id
)
return
activeEntity
return
activeEntity
#===========================================================================
#===========================================================================
...
@@ -268,7 +267,6 @@ class CoreObject(Process):
...
@@ -268,7 +267,6 @@ class CoreObject(Process):
# and if preemption is required
# and if preemption is required
#===========================================================================
#===========================================================================
def
preemptReceiver
(
self
):
def
preemptReceiver
(
self
):
# self.printTrace(self.id, 'trying to preempt a receiver')
activeObject
=
self
.
getActiveObject
()
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
...
@@ -305,8 +303,7 @@ class CoreObject(Process):
...
@@ -305,8 +303,7 @@ class CoreObject(Process):
#if the receiver does not hold an Entity that is also critical
#if the receiver does not hold an Entity that is also critical
if
not
receiver
.
getActiveObjectQueue
()[
0
].
isCritical
:
if
not
receiver
.
getActiveObjectQueue
()[
0
].
isCritical
:
receiver
.
shouldPreempt
=
True
receiver
.
shouldPreempt
=
True
# activeObject.printTrace(self.id, 'preempting receiver '+receiver.id+'.. '*6)
self
.
printTrace
(
self
.
id
,
preempt
=
receiver
.
id
)
self
.
printTrace1
(
self
.
id
,
preempt
=
receiver
.
id
)
receiver
.
preempt
()
receiver
.
preempt
()
receiver
.
timeLastEntityEnded
=
now
()
#required to count blockage correctly in the preemptied station
receiver
.
timeLastEntityEnded
=
now
()
#required to count blockage correctly in the preemptied station
# sort so that the critical entity is placed in front
# sort so that the critical entity is placed in front
...
@@ -319,23 +316,33 @@ class CoreObject(Process):
...
@@ -319,23 +316,33 @@ class CoreObject(Process):
if
self
.
gatherWipStat
:
if
self
.
gatherWipStat
:
self
.
wipStatList
.
append
([
now
(),
len
(
activeObjectQueue
)])
self
.
wipStatList
.
append
([
now
(),
len
(
activeObjectQueue
)])
#===========================================================================
#===========================================================================
# find possible receivers
# find possible receivers
#===========================================================================
#===========================================================================
def
findReceivers
(
self
):
@
staticmethod
activeObject
=
self
.
getActiveObject
()
def
findReceiversFor
(
activeObject
):
receivers
=
[]
receivers
=
[]
for
object
in
[
x
for
x
in
self
.
next
if
x
.
canAccept
(
activeObject
)]:
for
object
in
[
x
for
x
in
activeObject
.
next
if
x
.
canAccept
(
activeObject
)]:
receivers
.
append
(
object
)
receivers
.
append
(
object
)
return
receivers
return
receivers
# #===========================================================================
# # find possible receivers
# #===========================================================================
# def findReceivers(self):
# activeObject=self.getActiveObject()
# receivers=[]
# for object in [x for x in self.next if x.canAccept(activeObject)]:
# receivers.append(object)
# return receivers
# =======================================================================
# =======================================================================
# signal the successor that the object can dispose an entity
# signal the successor that the object can dispose an entity
# =======================================================================
# =======================================================================
def
signalReceiver
(
self
):
def
signalReceiver
(
self
):
# self.printTrace(self.id, 'trying to signal receiver')
activeObject
=
self
.
getActiveObject
()
activeObject
=
self
.
getActiveObject
()
possibleReceivers
=
activeObject
.
findReceivers
(
)
possibleReceivers
=
self
.
findReceiversFor
(
activeObject
)
if
possibleReceivers
:
if
possibleReceivers
:
receiver
=
activeObject
.
selectReceiver
(
possibleReceivers
)
receiver
=
activeObject
.
selectReceiver
(
possibleReceivers
)
receiversGiver
=
activeObject
receiversGiver
=
activeObject
...
@@ -358,8 +365,7 @@ class CoreObject(Process):
...
@@ -358,8 +365,7 @@ class CoreObject(Process):
activeObject
.
receiver
=
receiver
activeObject
.
receiver
=
receiver
activeObject
.
receiver
.
giver
=
activeObject
activeObject
.
receiver
.
giver
=
activeObject
# self.printTrace(self.id, ' '*50+'signalling receiver '+self.receiver.id)
self
.
printTrace
(
self
.
id
,
signalReceiver
=
self
.
receiver
.
id
)
self
.
printTrace1
(
self
.
id
,
signalReceiver
=
self
.
receiver
.
id
)
# assign the entry of the receiver
# assign the entry of the receiver
activeObject
.
receiver
.
assignEntryTo
()
activeObject
.
receiver
.
assignEntryTo
()
activeObject
.
receiver
.
isRequested
.
signal
(
activeObject
)
activeObject
.
receiver
.
isRequested
.
signal
(
activeObject
)
...
@@ -371,8 +377,8 @@ class CoreObject(Process):
...
@@ -371,8 +377,8 @@ class CoreObject(Process):
# =======================================================================
# =======================================================================
# select a receiver Object
# select a receiver Object
# =======================================================================
# =======================================================================
def
selectReceiver
(
self
,
possibleReceivers
=
[]):
@
staticmethod
activeObject
=
self
.
getActiveObject
()
def
selectReceiver
(
possibleReceivers
=
[]):
candidates
=
possibleReceivers
candidates
=
possibleReceivers
# dummy variables that help prioritize the objects requesting to give objects to the Machine (activeObject)
# dummy variables that help prioritize the objects requesting to give objects to the Machine (activeObject)
maxTimeWaiting
=
0
# dummy variable counting the time a successor is waiting
maxTimeWaiting
=
0
# dummy variable counting the time a successor is waiting
...
@@ -387,7 +393,8 @@ class CoreObject(Process):
...
@@ -387,7 +393,8 @@ class CoreObject(Process):
#===========================================================================
#===========================================================================
# signalRouter method
# signalRouter method
#===========================================================================
#===========================================================================
def
signalRouter
(
self
,
receiver
=
None
):
@
staticmethod
def
signalRouter
(
receiver
=
None
):
# if an operator is not assigned to the receiver then do not signal the receiver but the Router
# if an operator is not assigned to the receiver then do not signal the receiver but the Router
try
:
try
:
if
not
receiver
.
assignedOperator
or
\
if
not
receiver
.
assignedOperator
or
\
...
@@ -395,8 +402,7 @@ class CoreObject(Process):
...
@@ -395,8 +402,7 @@ class CoreObject(Process):
if
receiver
.
isLoadRequested
():
if
receiver
.
isLoadRequested
():
from
Globals
import
G
from
Globals
import
G
if
not
G
.
Router
.
invoked
:
if
not
G
.
Router
.
invoked
:
# self.printTrace(self.id, ' '*50+'signalling router')
# self.printTrace(self.id, signal='router')
self
.
printTrace1
(
self
.
id
,
signal
=
'router'
)
G
.
Router
.
invoked
=
True
G
.
Router
.
invoked
=
True
G
.
Router
.
isCalled
.
signal
(
now
())
G
.
Router
.
isCalled
.
signal
(
now
())
return
True
return
True
...
@@ -414,21 +420,32 @@ class CoreObject(Process):
...
@@ -414,21 +420,32 @@ class CoreObject(Process):
#===========================================================================
#===========================================================================
# find possible givers
# find possible givers
#===========================================================================
#===========================================================================
def
findGivers
(
self
):
@
staticmethod
activeObject
=
self
.
getActiveObject
()
def
findGiversFor
(
activeObject
):
givers
=
[]
givers
=
[]
for
object
in
[
x
for
x
in
activeObject
.
previous
if
(
not
x
is
activeObject
)]:
for
object
in
[
x
for
x
in
activeObject
.
previous
if
(
not
x
is
activeObject
)]:
if
object
.
haveToDispose
(
activeObject
):
if
object
.
haveToDispose
(
activeObject
):
givers
.
append
(
object
)
givers
.
append
(
object
)
return
givers
return
givers
# #===========================================================================
# # find possible givers
# #===========================================================================
# def findGivers(self):
# activeObject=self.getActiveObject()
# givers=[]
# for object in [x for x in activeObject.previous if(not x is activeObject)]:
# if object.haveToDispose(activeObject):
# givers.append(object)
# return givers
# =======================================================================
# =======================================================================
# signal the giver that the entity is removed from its internalQueue
# signal the giver that the entity is removed from its internalQueue
# =======================================================================
# =======================================================================
def
signalGiver
(
self
):
def
signalGiver
(
self
):
# self.printTrace(self.id, 'trying to signal giver')
activeObject
=
self
.
getActiveObject
()
activeObject
=
self
.
getActiveObject
()
possibleGivers
=
activeObject
.
findGivers
(
)
possibleGivers
=
self
.
findGiversFor
(
activeObject
)
if
possibleGivers
:
if
possibleGivers
:
giver
=
activeObject
.
selectGiver
(
possibleGivers
)
giver
=
activeObject
.
selectGiver
(
possibleGivers
)
giversReceiver
=
activeObject
giversReceiver
=
activeObject
...
@@ -441,8 +458,7 @@ class CoreObject(Process):
...
@@ -441,8 +458,7 @@ class CoreObject(Process):
giversReceiver
=
activeObject
giversReceiver
=
activeObject
activeObject
.
giver
=
giver
activeObject
.
giver
=
giver
activeObject
.
giver
.
receiver
=
activeObject
activeObject
.
giver
.
receiver
=
activeObject
# self.printTrace(self.id, ' '*50+'signalling giver '+self.giver.id)
self
.
printTrace
(
self
.
id
,
signalGiver
=
self
.
giver
.
id
)
self
.
printTrace1
(
self
.
id
,
signalGiver
=
self
.
giver
.
id
)
activeObject
.
giver
.
canDispose
.
signal
(
activeObject
)
activeObject
.
giver
.
canDispose
.
signal
(
activeObject
)
return
True
return
True
return
False
return
False
...
@@ -450,8 +466,8 @@ class CoreObject(Process):
...
@@ -450,8 +466,8 @@ class CoreObject(Process):
# =======================================================================
# =======================================================================
# select a giver Object
# select a giver Object
# =======================================================================
# =======================================================================
def
selectGiver
(
self
,
possibleGivers
=
[]):
@
staticmethod
activeObject
=
self
.
getActiveObject
()
def
selectGiver
(
possibleGivers
=
[]):
candidates
=
possibleGivers
candidates
=
possibleGivers
# dummy variables that help prioritize the objects requesting to give objects to the Machine (activeObject)
# dummy variables that help prioritize the objects requesting to give objects to the Machine (activeObject)
maxTimeWaiting
=
0
# dummy variable counting the time a predecessor is blocked
maxTimeWaiting
=
0
# dummy variable counting the time a predecessor is blocked
...
@@ -498,27 +514,21 @@ class CoreObject(Process):
...
@@ -498,27 +514,21 @@ class CoreObject(Process):
G
.
sheetIndex
+=
1
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
def
printTrace1
(
self
,
entity
=
''
,
**
kw
):
@
staticmethod
def
printTrace
(
entity
=
''
,
**
kw
):
assert
len
(
kw
)
==
1
,
'only one phrase per printTrace supported for the moment'
assert
len
(
kw
)
==
1
,
'only one phrase per printTrace supported for the moment'
from
Globals
import
G
from
Globals
import
G
import
Globals
time
=
now
()
time
=
now
()
charLimit
=
60
charLimit
=
60
remainingChar
=
charLimit
-
len
(
entity
)
-
len
(
str
(
time
))
remainingChar
=
charLimit
-
len
(
entity
)
-
len
(
str
(
time
))
if
(
G
.
console
==
'Yes'
):
if
(
G
.
console
==
'Yes'
):
print
time
,
entity
,
print
time
,
entity
,
for
key
in
kw
:
for
key
in
kw
:
if
key
not
in
self
.
getSupportedPrintKwrds
():
if
key
not
in
Globals
.
getSupportedPrintKwrds
():
raise
ValueError
(
"Unsupported phrase %s for %s"
%
(
key
,
self
.
id
))
raise
ValueError
(
"Unsupported phrase %s for %s"
%
(
key
,
entity
.
name
))
element
=
self
.
getPhrase
()[
key
]
element
=
Globals
.
getPhrase
()[
key
]
phrase
=
element
[
'phrase'
]
phrase
=
element
[
'phrase'
]
prefix
=
element
.
get
(
'prefix'
,
None
)
prefix
=
element
.
get
(
'prefix'
,
None
)
suffix
=
element
.
get
(
'suffix'
,
None
)
suffix
=
element
.
get
(
'suffix'
,
None
)
...
@@ -533,40 +543,6 @@ class CoreObject(Process):
...
@@ -533,40 +543,6 @@ class CoreObject(Process):
print
phrase
,
arg
,
suffix
print
phrase
,
arg
,
suffix
else
:
else
:
print
phrase
,
arg
print
phrase
,
arg
@
staticmethod
def
getSupportedPrintKwrds
():
return
(
"signal"
,
"signalReceiver"
,
"signalGiver"
,
"attemptSignal"
,
"attemptSignalGiver"
,
"attemptSignalReceiver"
,
"preempt"
,
"preempted"
,
"startWork"
,
"finishWork"
,
"processEnd"
,
"interrupted"
,
"enter"
,
"waitEvent"
,
"received"
,
"isRequested"
,
"canDispose"
,
"interruptionEnd"
,
"loadOperatorAvailable"
,
'resourceAvailable'
,
'conveyerEnd'
,
'conveyerFull'
,
'moveEnd'
)
@
staticmethod
def
getPhrase
():
printKwrds
=
{
'signal'
:{
'phrase'
:
'signalling'
},
'signalGiver'
:{
'phrase'
:
'signalling giver'
,
'prefix'
:
'_'
},
'signalReceiver'
:{
'phrase'
:
'signalling receiver'
,
'prefix'
:
'_'
},
'attemptSignal'
:{
'phrase'
:
'will try to signal'
},
'attemptSignalGiver'
:{
'phrase'
:
'will try to signal a giver'
},
'attemptSignalReceiver'
:{
'phrase'
:
'will try to signal a receiver'
},
'preempt'
:
{
'phrase'
:
'preempts'
,
'suffix'
:
' .'
},
'preempted'
:
{
'phrase'
:
'is being preempted'
,
'suffix'
:
'. '
},
'startWork'
:{
'phrase'
:
'started working in'
},
'finishWork'
:{
'phrase'
:
'finished working in'
},
'processEnd'
:{
'phrase'
:
'ended processing in'
},
'interrupted'
:{
'phrase'
:
'interrupted at'
,
'suffix'
:
' .'
},
'enter'
:{
'phrase'
:
'got into'
,
'suffix'
:
'='
},
'waitEvent'
:{
'phrase'
:
'will wait for event'
},
'received'
:{
'phrase'
:
'received event'
},
'isRequested'
:{
'phrase'
:
'received an isRequested event from'
},
'canDispose'
:{
'phrase'
:
'received an canDispose event'
},
'interruptionEnd'
:{
'phrase'
:
'received an interruptionEnd event at'
},
"loadOperatorAvailable"
:{
'phrase'
:
'received a loadOperatorAvailable event at'
},
"resourceAvailable"
:{
'phrase'
:
'received a resourceAvailable event'
},
'moveEnd'
:{
'phrase'
:
'received a moveEnd event'
},
"conveyerEnd"
:{
'phrase'
:
'has reached conveyer End'
,
'suffix'
:
'.!'
},
'conveyerFull'
:{
'phrase'
:
'is now Full, No of units:'
,
'suffix'
:
'(*)'
}}
return
printKwrds
# =======================================================================
# =======================================================================
# outputs data to "output.xls"
# outputs data to "output.xls"
...
@@ -587,15 +563,6 @@ class CoreObject(Process):
...
@@ -587,15 +563,6 @@ class CoreObject(Process):
activeObjectQueue
=
self
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
return
len
(
activeObjectQueue
)
>
0
return
len
(
activeObjectQueue
)
>
0
#========================================================================
# checks if the object can dispose an entity
# and returns the entity that it will dispose
# To be used as self.canAcceptEntity(giver.haveToDisposeEntity(self))
#========================================================================
def
haveToDisposeEntity
(
self
,
callerObject
=
None
):
activeObjectQueue
=
self
.
getActiveObjectQueue
()
if
self
.
haveToDispose
(
callerObject
):
return
activeObjectQueue
[
0
]
# =======================================================================
# =======================================================================
# checks if the Object can accept an entity and there is an entity
# checks if the Object can accept an entity and there is an entity
# in some possible giver waiting for it
# in some possible giver waiting for it
...
@@ -609,12 +576,6 @@ class CoreObject(Process):
...
@@ -609,12 +576,6 @@ class CoreObject(Process):
def
canAccept
(
self
,
callerObject
=
None
):
def
canAccept
(
self
,
callerObject
=
None
):
pass
pass
# =======================================================================
# checks if the object can accept an specific Entity
# =======================================================================
def
canAcceptEntity
(
self
,
callerEntity
=
None
):
return
True
# =======================================================================
# =======================================================================
# sorts the Entities in the activeQ of the objects
# sorts the Entities in the activeQ of the objects
# =======================================================================
# =======================================================================
...
@@ -673,14 +634,12 @@ class CoreObject(Process):
...
@@ -673,14 +634,12 @@ class CoreObject(Process):
# assign Exit of the object
# assign Exit of the object
# =======================================================================
# =======================================================================
def
assignExitTo
(
self
,
callerObject
=
None
):
def
assignExitTo
(
self
,
callerObject
=
None
):
# self.printTrace(self.id, 'assignExit')
self
.
exitAssignedToReceiver
=
callerObject
self
.
exitAssignedToReceiver
=
callerObject
# =======================================================================
# =======================================================================
# unblock the object
# unblock the object
# =======================================================================
# =======================================================================
def
unAssignExit
(
self
):
def
unAssignExit
(
self
):
# self.printTrace(self.id, 'unassignExit')
self
.
exitAssignedToReceiver
=
None
self
.
exitAssignedToReceiver
=
None
# =======================================================================
# =======================================================================
...
...
dream/simulation/Dismantle.py
View file @
8e5f31b4
...
@@ -117,14 +117,12 @@ class Dismantle(CoreObject):
...
@@ -117,14 +117,12 @@ class Dismantle(CoreObject):
# 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, 'will wait for frame event')
self
.
printTrace
(
self
.
id
,
waitEvent
=
'(frame)'
)
self
.
printTrace1
(
self
.
id
,
waitEvent
=
'(frame)'
)
# 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.isRequested,self.canDispose, self.loadOperatorAvailable]
yield
waitevent
,
self
,
self
.
isRequested
#[self.isRequested,self.canDispose, self.loadOperatorAvailable]
if
self
.
isRequested
.
signalparam
:
if
self
.
isRequested
.
signalparam
:
# self.printTrace(self.id, 'received a isRequested event from '+self.isRequested.signalparam.id)
self
.
printTrace
(
self
.
id
,
isRequested
=
self
.
isRequested
.
signalparam
.
id
)
self
.
printTrace1
(
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
...
@@ -277,8 +275,7 @@ class Dismantle(CoreObject):
...
@@ -277,8 +275,7 @@ class Dismantle(CoreObject):
activeObject
.
waitToDisposePart
=
False
activeObject
.
waitToDisposePart
=
False
# if the internal queue is empty then try to signal the giver that the object can now receive
# if the internal queue is empty then try to signal the giver that the object can now receive
if
activeObject
.
canAccept
():
if
activeObject
.
canAccept
():
# activeObject.printTrace(self.id, 'will try signalling a giver from removeEntity')
activeObject
.
printTrace
(
self
.
id
,
attemptSingalGiver
=
'(removeEntity)'
)
activeObject
.
printTrace1
(
self
.
id
,
attemptSingalGiver
=
'(removeEntity)'
)
activeObject
.
signalGiver
()
activeObject
.
signalGiver
()
return
activeEntity
return
activeEntity
...
...
dream/simulation/Globals.py
View file @
8e5f31b4
...
@@ -279,3 +279,78 @@ def getConfidenceIntervals(value_list):
...
@@ -279,3 +279,78 @@ def getConfidenceIntervals(value_list):
'ub'
:
ub
,
'ub'
:
ub
,
'avg'
:
numpy
.
mean
(
value_list
)
}
'avg'
:
numpy
.
mean
(
value_list
)
}
# #===========================================================================
# # printTrace
# #===========================================================================
# def printTrace(entity='',station='', **kw):
# assert len(kw)==1, 'only one phrase per printTrace supported for the moment'
# from Globals import G
# time=now()
# charLimit=60
# remainingChar=charLimit-len(entity)-len(str(time))
# if(G.console=='Yes'):
# print time,entity,
# for key in kw:
# if key not in getSupportedPrintKwrds():
# raise ValueError("Unsupported phrase %s for %s" % (key, station.id))
# element=getPhrase()[key]
# phrase=element['phrase']
# prefix=element.get('prefix',None)
# suffix=element.get('suffix',None)
# arg=kw[key]
# if prefix:
# print prefix*remainingChar,phrase,arg
# elif suffix:
# remainingChar-=len(phrase)+len(arg)
# suffix*=remainingChar
# if key=='enter':
# suffix=suffix+'>'
# print phrase,arg,suffix
# else:
# print phrase,arg
#===========================================================================
# get the supported print Keywords
#===========================================================================
def
getSupportedPrintKwrds
():
return
(
"create"
,
"signal"
,
"signalReceiver"
,
"signalGiver"
,
"attemptSignal"
,
"attemptSignalGiver"
,
"attemptSignalReceiver"
,
"preempt"
,
"preempted"
,
"startWork"
,
"finishWork"
,
"processEnd"
,
"interrupted"
,
"enter"
,
"waitEvent"
,
"received"
,
"isRequested"
,
"canDispose"
,
"interruptionEnd"
,
"loadOperatorAvailable"
,
'resourceAvailable'
,
'conveyerEnd'
,
'conveyerFull'
,
'moveEnd'
)
#===========================================================================
# get the phrase to print from the keyword
#===========================================================================
def
getPhrase
():
printKwrds
=
{
'create'
:{
'phrase'
:
'created an entity'
},
'signal'
:{
'phrase'
:
'signalling'
},
'signalGiver'
:{
'phrase'
:
'signalling giver'
,
'prefix'
:
'_'
},
'signalReceiver'
:{
'phrase'
:
'signalling receiver'
,
'prefix'
:
'_'
},
'attemptSignal'
:{
'phrase'
:
'will try to signal'
},
'attemptSignalGiver'
:{
'phrase'
:
'will try to signal a giver'
},
'attemptSignalReceiver'
:{
'phrase'
:
'will try to signal a receiver'
},
'preempt'
:
{
'phrase'
:
'preempts'
,
'suffix'
:
' .'
},
'preempted'
:
{
'phrase'
:
'is being preempted'
,
'suffix'
:
'. '
},
'startWork'
:{
'phrase'
:
'started working in'
},
'finishWork'
:{
'phrase'
:
'finished working in'
},
'processEnd'
:{
'phrase'
:
'ended processing in'
},
'interrupted'
:{
'phrase'
:
'interrupted at'
,
'suffix'
:
' .'
},
'enter'
:{
'phrase'
:
'got into'
,
'suffix'
:
'='
},
'waitEvent'
:{
'phrase'
:
'will wait for event'
},
'received'
:{
'phrase'
:
'received event'
},
'isRequested'
:{
'phrase'
:
'received an isRequested event from'
},
'canDispose'
:{
'phrase'
:
'received an canDispose event'
},
'interruptionEnd'
:{
'phrase'
:
'received an interruptionEnd event at'
},
"loadOperatorAvailable"
:{
'phrase'
:
'received a loadOperatorAvailable event at'
},
"resourceAvailable"
:{
'phrase'
:
'received a resourceAvailable event'
},
'moveEnd'
:{
'phrase'
:
'received a moveEnd event'
},
"conveyerEnd"
:{
'phrase'
:
'has reached conveyer End'
,
'suffix'
:
'.!'
},
'conveyerFull'
:{
'phrase'
:
'is now Full, No of units:'
,
'suffix'
:
'(*)'
}}
return
printKwrds
dream/simulation/Machine.py
View file @
8e5f31b4
...
@@ -228,15 +228,12 @@ class Machine(CoreObject):
...
@@ -228,15 +228,12 @@ class Machine(CoreObject):
while
1
:
while
1
:
# waitEvent isRequested /interruptionEnd/loadOperatorAvailable
# waitEvent isRequested /interruptionEnd/loadOperatorAvailable
while
1
:
while
1
:
# self.printTrace(self.id, 'will wait for event')
self
.
printTrace
(
self
.
id
,
waitEvent
=
''
)
self
.
printTrace1
(
self
.
id
,
waitEvent
=
''
)
yield
waitevent
,
self
,
[
self
.
isRequested
,
self
.
interruptionEnd
,
self
.
loadOperatorAvailable
]
yield
waitevent
,
self
,
[
self
.
isRequested
,
self
.
interruptionEnd
,
self
.
loadOperatorAvailable
]
# self.printTrace(self.id, 'received an event')
self
.
printTrace
(
self
.
id
,
received
=
''
)
self
.
printTrace1
(
self
.
id
,
received
=
''
)
# if the machine can accept an entity and one predecessor requests it continue with receiving the entity
# if the machine can accept an entity and one predecessor requests it continue with receiving the entity
if
self
.
isRequested
.
signalparam
:
if
self
.
isRequested
.
signalparam
:
# self.printTrace(self.id, 'received an isRequested event from'+self.isRequested.signalparam.id)
self
.
printTrace
(
self
.
id
,
isRequested
=
self
.
isRequested
.
signalparam
.
id
)
self
.
printTrace1
(
self
.
id
,
isRequested
=
self
.
isRequested
.
signalparam
.
id
)
assert
self
.
isRequested
.
signalparam
==
self
.
giver
,
'the giver is not the requestingObject'
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'
assert
self
.
giver
.
receiver
==
self
,
'the receiver of the signalling object in not the station'
# reset the signalparam of the isRequested event
# reset the signalparam of the isRequested event
...
@@ -246,11 +243,9 @@ class Machine(CoreObject):
...
@@ -246,11 +243,9 @@ class Machine(CoreObject):
# if an operator was rendered available while it was needed by the machine to proceed with getEntity
# 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
()
or
self
.
loadOperatorAvailable
.
signalparam
==
now
():
if
self
.
interruptionEnd
.
signalparam
==
now
():
if
self
.
interruptionEnd
.
signalparam
==
now
():
# self.printTrace(self.id, 'received an interruptionEnd event sent at '+str(self.interruptionEnd.signalparam))
self
.
printTrace
(
self
.
id
,
interruptionEnd
=
str
(
self
.
interruptionEnd
.
signalparam
))
self
.
printTrace1
(
self
.
id
,
interruptionEnd
=
str
(
self
.
interruptionEnd
.
signalparam
))
elif
self
.
loadOperatorAvailable
.
signalparam
==
now
():
elif
self
.
loadOperatorAvailable
.
signalparam
==
now
():
# self.printTrace(self.id, 'received an loadOperatorAvailable event sent at '+str(self.loadOperatorAvailable.signalparam))
self
.
printTrace
(
self
.
id
,
loadOperatorAvailable
=
str
(
self
.
loadOperatorAvailable
.
signalparam
))
self
.
printTrace1
(
self
.
id
,
loadOperatorAvailable
=
str
(
self
.
loadOperatorAvailable
.
signalparam
))
# try to signal the Giver, otherwise wait until it is requested
# try to signal the Giver, otherwise wait until it is requested
if
self
.
signalGiver
():
if
self
.
signalGiver
():
break
break
...
@@ -475,8 +470,7 @@ class Machine(CoreObject):
...
@@ -475,8 +470,7 @@ class Machine(CoreObject):
activeObject
=
self
.
getActiveObject
()
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
activeObject
.
getActiveObjectQueue
()
activeObjectQueue
=
activeObject
.
getActiveObjectQueue
()
activeEntity
=
activeObjectQueue
[
0
]
activeEntity
=
activeObjectQueue
[
0
]
# self.printTrace(activeObject.getActiveObjectQueue()[0].name,"ended processing in "+activeObject.objName)
self
.
printTrace
(
activeObject
.
getActiveObjectQueue
()[
0
].
name
,
processEnd
=
activeObject
.
objName
)
self
.
printTrace1
(
activeObject
.
getActiveObjectQueue
()[
0
].
name
,
processEnd
=
activeObject
.
objName
)
# reset the variables used to handle the interruptions timing
# reset the variables used to handle the interruptions timing
self
.
timeRestartingProcessing
=
0
self
.
timeRestartingProcessing
=
0
self
.
breakTime
=
0
self
.
breakTime
=
0
...
@@ -526,8 +520,7 @@ class Machine(CoreObject):
...
@@ -526,8 +520,7 @@ class Machine(CoreObject):
activeObject
=
self
.
getActiveObject
()
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
activeObject
.
getActiveObjectQueue
()
activeObjectQueue
=
activeObject
.
getActiveObjectQueue
()
activeEntity
=
activeObjectQueue
[
0
]
activeEntity
=
activeObjectQueue
[
0
]
# self.printTrace(self.getActiveObjectQueue()[0].name, "Interrupted at "+self.objName+'. '*5)
self
.
printTrace
(
self
.
getActiveObjectQueue
()[
0
].
name
,
interrupted
=
self
.
objName
)
self
.
printTrace1
(
self
.
getActiveObjectQueue
()[
0
].
name
,
interrupted
=
self
.
objName
)
# if the interrupt occured while processing an entity
# if the interrupt occured while processing an entity
if
not
activeObject
.
waitToDispose
:
if
not
activeObject
.
waitToDispose
:
# output to trace that the Machine (self.objName) got interrupted
# output to trace that the Machine (self.objName) got interrupted
...
@@ -712,8 +705,7 @@ class Machine(CoreObject):
...
@@ -712,8 +705,7 @@ class Machine(CoreObject):
activeObject
.
waitToDispose
=
False
# update the waitToDispose flag
activeObject
.
waitToDispose
=
False
# update the waitToDispose flag
# if the Machine canAccept then signal a giver
# if the Machine canAccept then signal a giver
if
activeObject
.
canAccept
():
if
activeObject
.
canAccept
():
# self.printTrace(self.id, 'will try signalling a giver from removeEntity')
self
.
printTrace
(
self
.
id
,
attemptSignalGiver
=
'(removeEntity)'
)
self
.
printTrace1
(
self
.
id
,
attemptSignalGiver
=
'(removeEntity)'
)
activeObject
.
signalGiver
()
activeObject
.
signalGiver
()
return
activeEntity
return
activeEntity
...
@@ -744,12 +736,6 @@ class Machine(CoreObject):
...
@@ -744,12 +736,6 @@ class Machine(CoreObject):
def
calculateLoadTime
(
self
):
def
calculateLoadTime
(
self
):
return
self
.
loadRng
.
generateNumber
()
return
self
.
loadRng
.
generateNumber
()
# =======================================================================
# prepare the machine to be operated
# =======================================================================
def
requestRouter
(
self
):
if
not
self
.
router
.
isCalled
():
self
.
router
.
invoke
()
#===========================================================================
#===========================================================================
# find candidate operators within the free operators
# find candidate operators within the free operators
...
@@ -803,18 +789,6 @@ class Machine(CoreObject):
...
@@ -803,18 +789,6 @@ class Machine(CoreObject):
def
isOperated
(
self
):
def
isOperated
(
self
):
return
self
.
toBeOperated
return
self
.
toBeOperated
# =======================================================================
# check if the machine is already set-up
# =======================================================================
def
isSetUp
(
self
):
return
self
.
setUp
# =======================================================================
# request that the machine is set-up by an operator
# =======================================================================
def
requestSetup
(
self
):
self
.
setUp
=
False
# =======================================================================
# =======================================================================
# actions to be taken after the simulation ends
# actions to be taken after the simulation ends
# =======================================================================
# =======================================================================
...
...
dream/simulation/MachineJobShop.py
View file @
8e5f31b4
...
@@ -49,8 +49,7 @@ class MachineJobShop(Machine):
...
@@ -49,8 +49,7 @@ class MachineJobShop(Machine):
activeObject
=
self
.
getActiveObject
()
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
activeObject
.
getActiveObjectQueue
()
activeObjectQueue
=
activeObject
.
getActiveObjectQueue
()
activeEntity
=
activeObjectQueue
[
0
]
activeEntity
=
activeObjectQueue
[
0
]
# self.printTrace(activeObject.getActiveObjectQueue()[0].name,"ended processing in "+activeObject.objName)
self
.
printTrace
(
activeObject
.
getActiveObjectQueue
()[
0
].
name
,
processEnd
=
activeObject
.
objName
)
self
.
printTrace1
(
activeObject
.
getActiveObjectQueue
()[
0
].
name
,
processEnd
=
activeObject
.
objName
)
# reset the variables used to handle the interruptions timing
# reset the variables used to handle the interruptions timing
self
.
timeRestartingProcessing
=
0
self
.
timeRestartingProcessing
=
0
self
.
breakTime
=
0
self
.
breakTime
=
0
...
@@ -231,8 +230,7 @@ class MachineJobShop(Machine):
...
@@ -231,8 +230,7 @@ class MachineJobShop(Machine):
# method to execute preemption
# method to execute preemption
# =======================================================================
# =======================================================================
def
preempt
(
self
):
def
preempt
(
self
):
# self.printTrace(self.id,'preempting'+' .'*7)
self
.
printTrace
(
self
.
id
,
preempted
=
''
)
self
.
printTrace1
(
self
.
id
,
preempted
=
''
)
activeObject
=
self
.
getActiveObject
()
activeObject
=
self
.
getActiveObject
()
activeEntity
=
self
.
getActiveObjectQueue
()[
0
]
#get the active Entity
activeEntity
=
self
.
getActiveObjectQueue
()[
0
]
#get the active Entity
#calculate the remaining processing time
#calculate the remaining processing time
...
...
dream/simulation/OperatedPoolBroker.py
View file @
8e5f31b4
...
@@ -71,7 +71,7 @@ class Broker(ObjectInterruption):
...
@@ -71,7 +71,7 @@ class Broker(ObjectInterruption):
# TODO: add new broker event - brokerIsCalled
# TODO: add new broker event - brokerIsCalled
yield
waitevent
,
self
,
self
.
isCalled
yield
waitevent
,
self
,
self
.
isCalled
assert
self
.
isCalled
.
signalparam
==
now
(),
'the broker should be granted control instantly'
assert
self
.
isCalled
.
signalparam
==
now
(),
'the broker should be granted control instantly'
self
.
victim
.
printTrace
1
(
self
.
victim
.
id
,
received
=
'(broker)'
)
self
.
victim
.
printTrace
(
self
.
victim
.
id
,
received
=
'(broker)'
)
# ======= request a resource
# ======= request a resource
if
self
.
victim
.
isOperated
()
\
if
self
.
victim
.
isOperated
()
\
and
any
(
type
==
'Load'
or
type
==
'Setup'
or
type
==
'Processing'
\
and
any
(
type
==
'Load'
or
type
==
'Setup'
or
type
==
'Processing'
\
...
@@ -87,28 +87,24 @@ class Broker(ObjectInterruption):
...
@@ -87,28 +87,24 @@ class Broker(ObjectInterruption):
if
not
self
.
victim
.
currentEntity
in
G
.
pendingEntities
:
if
not
self
.
victim
.
currentEntity
in
G
.
pendingEntities
:
G
.
pendingEntities
.
append
(
self
.
victim
.
currentEntity
)
G
.
pendingEntities
.
append
(
self
.
victim
.
currentEntity
)
if
not
G
.
Router
.
invoked
:
if
not
G
.
Router
.
invoked
:
# self.printTrace(self.victim.id, 'broker'+' '*50+'signalling router')
self
.
victim
.
printTrace
(
self
.
victim
.
id
,
signal
=
'router (broker)'
)
self
.
victim
.
printTrace1
(
self
.
victim
.
id
,
signal
=
'router (broker)'
)
G
.
Router
.
invoked
=
True
G
.
Router
.
invoked
=
True
G
.
Router
.
isCalled
.
signal
(
now
())
G
.
Router
.
isCalled
.
signal
(
now
())
self
.
waitForOperator
=
True
self
.
waitForOperator
=
True
# self.printTrace(self.victim.id, 'broker waits till resource is available1')
self
.
victim
.
printTrace
(
self
.
victim
.
id
,
waitEvent
=
'(resourceIsAvailable broker)'
)
self
.
victim
.
printTrace1
(
self
.
victim
.
id
,
waitEvent
=
'(resourceIsAvailable broker)'
)
yield
waitevent
,
self
,
self
.
resourceAvailable
yield
waitevent
,
self
,
self
.
resourceAvailable
# remove the currentEntity from the pendingEntities
# remove the currentEntity from the pendingEntities
if
self
.
victim
.
currentEntity
in
G
.
pendingEntities
:
if
self
.
victim
.
currentEntity
in
G
.
pendingEntities
:
G
.
pendingEntities
.
remove
(
self
.
victim
.
currentEntity
)
G
.
pendingEntities
.
remove
(
self
.
victim
.
currentEntity
)
self
.
waitForOperator
=
False
self
.
waitForOperator
=
False
# self.printTrace(self.victim.id, 'received resourceAvailable event')
self
.
victim
.
printTrace
(
self
.
victim
.
id
,
resourceAvailable
=
'(broker)'
)
self
.
victim
.
printTrace1
(
self
.
victim
.
id
,
resourceAvailable
=
'(broker)'
)
#===============================================================
#===============================================================
assert
self
.
victim
.
operatorPool
.
checkIfResourceIsAvailable
(),
'there is no available operator to request'
assert
self
.
victim
.
operatorPool
.
checkIfResourceIsAvailable
(),
'there is no available operator to request'
# set the available resource as the currentOperator
# set the available resource as the currentOperator
self
.
victim
.
currentOperator
=
self
.
victim
.
operatorPool
.
findAvailableOperator
()
self
.
victim
.
currentOperator
=
self
.
victim
.
operatorPool
.
findAvailableOperator
()
yield
request
,
self
,
self
.
victim
.
operatorPool
.
getResource
(
self
.
victim
.
currentOperator
)
yield
request
,
self
,
self
.
victim
.
operatorPool
.
getResource
(
self
.
victim
.
currentOperator
)
# self.printTrace(self.victim.currentOperator.objName, 'started work in '+self.victim.id)
self
.
victim
.
printTrace
(
self
.
victim
.
currentOperator
.
objName
,
startWork
=
self
.
victim
.
id
)
self
.
victim
.
printTrace1
(
self
.
victim
.
currentOperator
.
objName
,
startWork
=
self
.
victim
.
id
)
# clear the timeWaitForOperatorStarted variable
# clear the timeWaitForOperatorStarted variable
self
.
timeWaitForOperatorStarted
=
0
self
.
timeWaitForOperatorStarted
=
0
# update the time that the operation started
# update the time that the operation started
...
@@ -125,16 +121,14 @@ class Broker(ObjectInterruption):
...
@@ -125,16 +121,14 @@ class Broker(ObjectInterruption):
# TODO: signalling the router must be done more elegantly, router must be set as global variable
# 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 the router is already invoked then do not signal it again
if
not
self
.
victim
.
router
.
invoked
:
if
not
self
.
victim
.
router
.
invoked
:
# self.printTrace(self.victim.id, 'broker'+' '*50+'signalling ROUTER')
self
.
victim
.
printTrace
(
self
.
victim
.
id
,
signal
=
'router (broker)'
)
self
.
victim
.
printTrace1
(
self
.
victim
.
id
,
signal
=
'router (broker)'
)
self
.
victim
.
router
.
invoked
=
True
self
.
victim
.
router
.
invoked
=
True
self
.
victim
.
router
.
isCalled
.
signal
(
now
())
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.
# TODO: signalling the router will give the chance to it to take the control, but when will it eventually receive it.
# after signalling the broker will signal it's victim that it has finished it's processes
# after signalling the broker will signal it's victim that it has finished it's processes
# TODO: this wont work for the moment. The actions that follow must be performed by all operated brokers.
# TODO: this wont work for the moment. The actions that follow must be performed by all operated brokers.
self
.
printTrace
(
self
.
victim
.
currentOperator
.
objName
,
'released '
+
self
.
victim
.
id
)
self
.
victim
.
printTrace
(
self
.
victim
.
currentOperator
.
objName
,
finishWork
=
self
.
victim
.
id
)
self
.
victim
.
printTrace1
(
self
.
victim
.
currentOperator
.
objName
,
finishWork
=
self
.
victim
.
id
)
# the victim current operator must be cleared after the operator is released
# the victim current operator must be cleared after the operator is released
self
.
timeLastOperationEnded
=
now
()
self
.
timeLastOperationEnded
=
now
()
self
.
victim
.
currentOperator
=
None
self
.
victim
.
currentOperator
=
None
...
...
dream/simulation/OperatorRouter.py
View file @
8e5f31b4
...
@@ -386,13 +386,13 @@ class Router(ObjectInterruption):
...
@@ -386,13 +386,13 @@ class Router(ObjectInterruption):
# for each pendingQueue
# for each pendingQueue
for
object
in
self
.
pendingQueues
:
for
object
in
self
.
pendingQueues
:
# find available operator for then machines that follow
# find available operator for then machines that follow
for
nextobject
in
object
.
findReceivers
(
):
for
nextobject
in
object
.
findReceivers
For
(
object
):
candidateOperator
=
nextobject
.
findCandidateOperator
()
candidateOperator
=
nextobject
.
findCandidateOperator
()
if
not
candidateOperator
in
self
.
candidateOperators
:
if
not
candidateOperator
in
self
.
candidateOperators
:
self
.
candidateOperators
.
append
(
candidateOperator
)
self
.
candidateOperators
.
append
(
candidateOperator
)
# check the option of preemption if there are critical entities and no available operators
# check the option of preemption if there are critical entities and no available operators
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
if
not
object
.
findReceivers
(
)
and
\
if
not
object
.
findReceivers
For
(
object
)
and
\
any
(
entity
for
entity
in
object
.
getActiveObjectQueue
()
if
entity
.
isCritical
):
any
(
entity
for
entity
in
object
.
getActiveObjectQueue
()
if
entity
.
isCritical
):
# for each of the following objects
# for each of the following objects
for
nextObject
in
object
.
next
:
for
nextObject
in
object
.
next
:
...
@@ -533,6 +533,25 @@ class Router(ObjectInterruption):
...
@@ -533,6 +533,25 @@ class Router(ObjectInterruption):
candidateList
=
self
.
candidateOperators
candidateList
=
self
.
candidateOperators
self
.
activeQSorter
(
criterion
=
self
.
schedulingRule
,
candList
=
candidateList
)
self
.
activeQSorter
(
criterion
=
self
.
schedulingRule
,
candList
=
candidateList
)
def
findCandidateReceiverFor
(
self
,
entity
):
# initiate the local list variable available receivers
availableReceivers
=
[
x
for
x
in
entity
.
candidateReceivers
\
if
not
x
in
self
.
occupiedReceivers
]
# and pick the object that is waiting for the most time
if
availableReceivers
:
# find the receiver that waits the most
availableReceiver
=
entity
.
currentStation
.
selectReceiver
(
availableReceivers
)
self
.
occupiedReceivers
.
append
(
availableReceiver
)
# if there is no available receiver add the entity to the entitiesWithOccupiedReceivers list
else
:
self
.
entitiesWithOccupiedReceivers
.
append
(
entity
)
availableReceiver
=
None
# if the sorting flag is not set then the sorting of each queue must prevail in case of operators conflict
if
not
self
.
sorting
and
not
availableReceiver
and
bool
(
availableReceivers
):
availableReceiver
=
entity
.
currentStation
.
selectReceiver
(
self
.
candidateReceivers
)
if
not
entity
in
self
.
conflictingEntities
:
self
.
conflictingEntities
.
append
(
entity
)
return
availableReceiver
#=======================================================================
#=======================================================================
# Find candidate entities and their receivers
# Find candidate entities and their receivers
...
...
dream/simulation/Queue.py
View file @
8e5f31b4
...
@@ -96,16 +96,13 @@ class Queue(CoreObject):
...
@@ -96,16 +96,13 @@ class Queue(CoreObject):
# 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, 'will wait for event')
self
.
printTrace
(
self
.
id
,
waitEvent
=
''
)
self
.
printTrace1
(
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, 'just received an event')
self
.
printTrace
(
self
.
id
,
received
=
''
)
self
.
printTrace1
(
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, 'received a isRequested event from'+self.isRequested.signalparam.id)
self
.
printTrace
(
self
.
id
,
isRequested
=
self
.
isRequested
.
signalparam
.
id
)
self
.
printTrace1
(
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
()
...
@@ -114,18 +111,15 @@ class Queue(CoreObject):
...
@@ -114,18 +111,15 @@ class Queue(CoreObject):
activeObjectQueue
[
0
].
startTime
=
now
()
activeObjectQueue
[
0
].
startTime
=
now
()
# if the queue received an loadOperatorIsAvailable (from Router) with signalparam time
# if the queue received an loadOperatorIsAvailable (from Router) with signalparam time
if
self
.
loadOperatorAvailable
.
signalparam
:
if
self
.
loadOperatorAvailable
.
signalparam
:
# self.printTrace(self.id, 'received a loadOperatorAvailable event')
# self.printTrace(self.id, loadOperatorAvailable=str(self.loadOperatorAvailable.signalparam))
# self.printTrace1(self.id, loadOperatorAvailable=str(self.loadOperatorAvailable.signalparam))
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, 'received a canDispose event')
self
.
printTrace
(
self
.
id
,
canDispose
=
''
)
self
.
printTrace1
(
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, 'will try to signal a receiver from generator')
self
.
printTrace
(
self
.
id
,
attemptSignalReceiver
=
'(generator)'
)
self
.
printTrace1
(
self
.
id
,
attemptSignalReceiver
=
'(generator)'
)
if
self
.
receiver
:
if
self
.
receiver
:
if
not
self
.
receiver
.
entryIsAssignedTo
():
if
not
self
.
receiver
.
entryIsAssignedTo
():
self
.
signalReceiver
()
self
.
signalReceiver
()
...
@@ -178,8 +172,7 @@ class Queue(CoreObject):
...
@@ -178,8 +172,7 @@ class Queue(CoreObject):
# 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
,
'will try to signal a receiver from removeEntity'
)
self
.
printTrace
(
self
.
id
,
attemptSignalReceiver
=
'(removeEntity)'
)
self
.
printTrace1
(
self
.
id
,
attemptSignalReceiver
=
'(removeEntity)'
)
self
.
signalReceiver
()
self
.
signalReceiver
()
return
activeEntity
return
activeEntity
...
...
dream/simulation/QueueManagedJob.py
View file @
8e5f31b4
...
@@ -104,7 +104,8 @@ class QueueManagedJob(QueueJobShop):
...
@@ -104,7 +104,8 @@ class QueueManagedJob(QueueJobShop):
#===========================================================================
#===========================================================================
# signalRouter method
# signalRouter method
#===========================================================================
#===========================================================================
def
signalRouter
(
self
,
receiver
=
None
):
@
staticmethod
def
signalRouter
(
receiver
=
None
):
# if an operator is not assigned to the receiver then do not signal the receiver but the Router
# if an operator is not assigned to the receiver then do not signal the receiver but the Router
# TODO: identifyEntityToGet needs giver defined but here is not yet defined for Machines and machineJobShops
# TODO: identifyEntityToGet needs giver defined but here is not yet defined for Machines and machineJobShops
try
:
try
:
...
@@ -113,8 +114,7 @@ class QueueManagedJob(QueueJobShop):
...
@@ -113,8 +114,7 @@ class QueueManagedJob(QueueJobShop):
if
receiver
.
identifyEntityToGet
().
manager
.
isAssignedTo
()
!=
receiver
:
if
receiver
.
identifyEntityToGet
().
manager
.
isAssignedTo
()
!=
receiver
:
from
Globals
import
G
from
Globals
import
G
if
not
G
.
Router
.
invoked
:
if
not
G
.
Router
.
invoked
:
# self.printTrace(self.id,' '*50+'signalling router')
# self.printTrace(self.id, signal='router')
self
.
printTrace1
(
self
.
id
,
signal
=
'router'
)
G
.
Router
.
invoked
=
True
G
.
Router
.
invoked
=
True
G
.
Router
.
isCalled
.
signal
(
now
())
G
.
Router
.
isCalled
.
signal
(
now
())
return
True
return
True
...
...
dream/simulation/Source.py
View file @
8e5f31b4
...
@@ -171,7 +171,7 @@ class Source(CoreObject):
...
@@ -171,7 +171,7 @@ class Source(CoreObject):
# creates an Entity
# creates an Entity
#============================================================================
#============================================================================
def
createEntity
(
self
):
def
createEntity
(
self
):
self
.
printTrace
(
self
.
id
,
'created an entity
'
)
# self.printTrace(self.id, create='
')
return
self
.
item
(
id
=
self
.
item
.
type
+
str
(
G
.
numberOfEntities
),
name
=
self
.
item
.
type
+
str
(
self
.
numberOfArrivals
))
#return the newly created Entity
return
self
.
item
(
id
=
self
.
item
.
type
+
str
(
G
.
numberOfEntities
),
name
=
self
.
item
.
type
+
str
(
self
.
numberOfArrivals
))
#return the newly created Entity
#============================================================================
#============================================================================
# calculates the processing time
# calculates the processing time
...
...
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