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
b8c6f37e
Commit
b8c6f37e
authored
May 20, 2014
by
Ioannis Papagiannopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Assembly updated to the new signalling approach
parent
38d2047a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
179 additions
and
84 deletions
+179
-84
dream/simulation/Assembly.py
dream/simulation/Assembly.py
+178
-83
dream/simulation/CoreObject.py
dream/simulation/CoreObject.py
+1
-1
No files found.
dream/simulation/Assembly.py
View file @
b8c6f37e
...
@@ -27,15 +27,19 @@ it gathers frames and parts which are loaded to the frames
...
@@ -27,15 +27,19 @@ it gathers frames and parts which are loaded to the frames
'''
'''
from
SimPy.Simulation
import
Process
,
Resource
from
SimPy.Simulation
import
Process
,
Resource
from
SimPy.Simulation
import
wait
until
,
now
,
hold
from
SimPy.Simulation
import
wait
event
,
now
,
hold
import
xlwt
import
xlwt
from
RandomNumberGenerator
import
RandomNumberGenerator
from
RandomNumberGenerator
import
RandomNumberGenerator
from
CoreObject
import
CoreObject
from
CoreObject
import
CoreObject
#the Assembly object
#===============================================================================
# the Assembly object
#===============================================================================
class
Assembly
(
CoreObject
):
class
Assembly
(
CoreObject
):
class_name
=
'Dream.Assembly'
class_name
=
'Dream.Assembly'
#initialize the object
#===========================================================================
# initialize the object
#===========================================================================
def
__init__
(
self
,
id
,
name
,
processingTime
=
None
):
def
__init__
(
self
,
id
,
name
,
processingTime
=
None
):
if
not
processingTime
:
if
not
processingTime
:
processingTime
=
{
'distributionType'
:
'Fixed'
,
processingTime
=
{
'distributionType'
:
'Fixed'
,
...
@@ -71,7 +75,10 @@ class Assembly(CoreObject):
...
@@ -71,7 +75,10 @@ class Assembly(CoreObject):
# when the entities have to be loaded to operatedMachines
# when the entities have to be loaded to operatedMachines
# then the giverObjects have to be blocked for the time
# then the giverObjects have to be blocked for the time
# that the machine is being loaded
# that the machine is being loaded
#===========================================================================
# initialize method
#===========================================================================
def
initialize
(
self
):
def
initialize
(
self
):
Process
.
__init__
(
self
)
Process
.
__init__
(
self
)
CoreObject
.
initialize
(
self
)
CoreObject
.
initialize
(
self
)
...
@@ -108,110 +115,194 @@ class Assembly(CoreObject):
...
@@ -108,110 +115,194 @@ class Assembly(CoreObject):
self
.
Res
.
activeQ
=
[]
self
.
Res
.
activeQ
=
[]
self
.
Res
.
waitQ
=
[]
self
.
Res
.
waitQ
=
[]
#===========================================================================
# class generator
#===========================================================================
def
run
(
self
):
def
run
(
self
):
activeObjectQueue
=
self
.
getActiveObjectQueue
()
# check if there is WIP and signal receiver
self
.
initialSignalReceiver
()
while
1
:
while
1
:
yield
waituntil
,
self
,
self
.
canAcceptAndIsRequested
#wait until the Assembly can accept a frame
self
.
printTrace
(
self
.
id
,
'will wait for frame event'
)
#and one "frame" giver requests it
# wait until the Queue can accept an entity and one predecessor requests it
self
.
getEntity
(
"Frame"
)
#get the Frame
yield
waitevent
,
self
,
self
.
isRequested
#[self.isRequested,self.canDispose, self.loadOperatorAvailable]
# yield waituntil, self, self.canAcceptAndIsRequested #wait until the Assembly can accept a frame
# #and one "frame" giver requests it
if
self
.
isRequested
.
signalparam
:
self
.
printTrace
(
self
.
id
,
'received a isRequested event from '
+
self
.
isRequested
.
signalparam
.
id
)
# reset the isRequested signal parameter
self
.
isRequested
.
signalparam
=
None
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
yield
waituntil
,
self
,
self
.
isRequestedFromPart
#wait until a part is requesting for the assembly
self
.
printTrace
(
self
.
id
,
'will wait for part event'
)
self
.
getEntity
(
"Part"
)
yield
waitevent
,
self
,
self
.
isRequested
if
self
.
isRequested
.
signalparam
:
self
.
printTrace
(
self
.
id
,
'received a isRequested event from '
+
self
.
isRequested
.
signalparam
.
id
)
# reset the isRequested signal parameter
self
.
isRequested
.
signalparam
=
None
# yield waituntil, self, self.isRequestedFromPart #wait until a part is requesting for the assembly
# TODO: fix the getEntity 'Part' case
self
.
getEntity
(
"Part"
)
self
.
outputTrace
(
self
.
getActiveObjectQueue
()[
0
].
name
,
"is now full in "
+
self
.
objName
)
self
.
outputTrace
(
self
.
getActiveObjectQueue
()[
0
].
name
,
"is now full in "
+
self
.
objName
)
self
.
timeLastFrameWasFull
=
now
()
self
.
timeLastFrameWasFull
=
now
()
self
.
nameLastFrameWasFull
=
self
.
getActiveObjectQueue
()[
0
].
name
self
.
nameLastFrameWasFull
=
self
.
getActiveObjectQueue
()[
0
].
name
startWorkingTime
=
now
()
startWorkingTime
=
now
()
self
.
totalProcessingTimeInCurrentEntity
=
self
.
calculateProcessingTime
()
self
.
totalProcessingTimeInCurrentEntity
=
self
.
calculateProcessingTime
()
yield
hold
,
self
,
self
.
totalProcessingTimeInCurrentEntity
#hold for the time the assembly operation is carried
yield
hold
,
self
,
self
.
totalProcessingTimeInCurrentEntity
#hold for the time the assembly operation is carried
self
.
totalWorkingTime
+=
now
()
-
startWorkingTime
self
.
totalWorkingTime
+=
now
()
-
startWorkingTime
self
.
outputTrace
(
self
.
getActiveObjectQueue
()[
0
].
name
,
"ended processing in "
+
self
.
objName
)
self
.
timeLastEntityEnded
=
now
()
self
.
nameLastEntityEnded
=
self
.
getActiveObjectQueue
()[
0
].
name
self
.
outputTrace
(
self
.
getActiveObjectQueue
()[
0
].
name
,
"ended processing in "
+
self
.
objName
)
startBlockageTime
=
now
(
)
self
.
timeLastEntityEnded
=
now
()
self
.
completedJobs
+=
1
#Assembly completed a job
self
.
nameLastEntityEnded
=
self
.
getActiveObjectQueue
()[
0
].
name
self
.
waitToDispose
=
True
#since all the frame is full
startBlockageTime
=
now
()
self
.
printTrace
(
self
.
id
,
'will try to signal a receiver from generator'
)
self
.
completedJobs
+=
1
#Assembly completed a job
# signal the receiver that the activeObject has something to dispose of
self
.
waitToDispose
=
True
#since all the frame is full
if
not
self
.
signalReceiver
():
while
1
:
# if there was no available receiver, get into blocking control
yield
waituntil
,
self
,
self
.
next
[
0
].
canAccept
#wait until the next object is free
while
1
:
if
self
.
next
[
0
].
getGiverObject
()
==
self
:
#if the free object can accept from this Assembly
# wait the event canDispose, this means that the station can deliver the item to successor
#break. Else continue
event
=
yield
waitevent
,
self
,
self
.
canDispose
#[self.canDispose, self.interruptionStart]
break
# try to signal a receiver, if successful then proceed to get an other entity
if
self
.
signalReceiver
():
break
# TODO: router most probably should signal givers and not receivers in order to avoid this hold,self,0
# As the receiver (e.g.) a machine that follows the machine receives an loadOperatorAvailable event,
# signals the preceding station (e.g. self.machine) and immediately after that gets the entity.
# the preceding machine gets the canDispose signal which is actually useless, is emptied by the following station
# and then cannot exit an infinite loop.
yield
hold
,
self
,
0
# if while waiting (for a canDispose event) became free as the machines that follows emptied it, then proceed
if
not
self
.
haveToDispose
():
break
#self.totalBlockageTime+=now()-startBlockageTime #add the blockage time
#self.totalBlockageTime+=now()-startBlockageTime #add the blockage time
#checks if the Assembly can accept an entity
#===========================================================================
# checks if the Assembly can accept an entity
#===========================================================================
def
canAccept
(
self
,
callerObject
=
None
):
def
canAccept
(
self
,
callerObject
=
None
):
return
len
(
self
.
getActiveObjectQueue
())
==
0
# get active and giver objects
activeObject
=
self
.
getActiveObject
()
#checks if the Assembly can accept an entity and there is a Frame waiting for it
def
canAcceptAndIsRequested
(
self
):
activeObjectQueue
=
self
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
#if there is no caller then perform the default
#loop through the possible givers
if
(
callerObject
==
None
):
for
object
in
self
.
previous
:
return
len
(
activeObjectQueue
)
==
0
#activate only if the possible giver is not empty
thecaller
=
callerObject
if
(
len
(
object
.
getActiveObjectQueue
())
>
0
):
# if the object holds nothing then return true
#activate only if the caller carries Frame
if
len
(
self
.
getActiveObjectQueue
())
==
0
:
if
(
object
.
getActiveObjectQueue
()[
0
].
type
==
'Frame'
):
return
not
activeObject
.
entryIsAssignedTo
()
#update the giver
# if it holds already a frame then return true only for parts and if the frame has still space
self
.
giver
=
object
if
len
(
activeObjectQueue
[
0
].
getFrameQueue
())
<
activeObjectQueue
[
0
].
capacity
:
return
len
(
activeObjectQueue
)
==
0
and
object
.
haveToDispose
(
self
)
if
callerObject
.
getActiveObjectQueue
()[
0
].
type
==
'Part'
:
return
False
return
not
activeObject
.
entryIsAssignedTo
()
return
False
#checks if the Assembly can accept an entity and there is a Frame waiting for it
def
isRequestedFromPart
(
self
):
#===========================================================================
# checks if the Assembly can accept a part or a Frame
#===========================================================================
def
canAcceptAndIsRequested
(
self
,
callerObject
=
None
):
# get the active and the giver objects
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
# giverObject=self.getGiverObject()
giverObject
=
callerObject
assert
giverObject
,
'there must be a caller for canAcceptAndIsRequested'
if
(
len
(
giverObject
.
getActiveObjectQueue
())
>
0
):
#activate only if the caller carries Frame
if
(
giverObject
.
getActiveObjectQueue
()[
0
].
type
==
'Frame'
):
return
len
(
activeObjectQueue
)
==
0
and
giverObject
.
haveToDispose
(
activeObject
)
#activate only if the caller carries Part
if
(
giverObject
.
getActiveObjectQueue
()[
0
].
type
==
'Part'
):
return
len
(
activeObjectQueue
)
==
1
and
giverObject
.
haveToDispose
(
activeObject
)
return
False
#loop through the possible givers
#===========================================================================
for
object
in
self
.
previous
:
# checks if the Assembly can dispose an entity to the following object
#activate only if the possible giver is not empty
#===========================================================================
if
(
len
(
object
.
getActiveObjectQueue
())
>
0
):
def
haveToDispose
(
self
,
callerObject
=
None
):
#activate only if the caller carries Part
# get active object and its queue
if
(
object
.
getActiveObjectQueue
()[
0
].
type
==
'Part'
):
activeObject
=
self
.
getActiveObject
()
#update giver
activeObjectQueue
=
self
.
getActiveObjectQueue
()
self
.
giver
=
object
return
len
(
activeObjectQueue
)
==
1
and
object
.
haveToDispose
(
self
)
#if we have only one possible receiver just check if the Queue holds one or more entities
return
False
if
(
callerObject
==
None
):
return
len
(
activeObjectQueue
)
>
0
#checks if the Assembly can dispose an entity to the following object
def
haveToDispose
(
self
,
callerObject
=
None
):
thecaller
=
callerObject
return
len
(
self
.
getActiveObjectQueue
())
>
0
and
self
.
waitToDispose
return
len
(
activeObjectQueue
)
>
0
and
(
thecaller
in
activeObject
.
next
)
and
activeObject
.
waitToDispose
#removes an entity from the Assembly
#===========================================================================
# removes an entity from the Assembly
#===========================================================================
def
removeEntity
(
self
,
entity
=
None
):
def
removeEntity
(
self
,
entity
=
None
):
activeEntity
=
CoreObject
.
removeEntity
(
self
,
entity
)
#run the default method
activeObject
=
self
.
getActiveObject
()
self
.
waitToDispose
=
False
activeEntity
=
CoreObject
.
removeEntity
(
self
,
entity
)
#run the default method
return
activeEntity
#the object does not wait to dispose now
self
.
waitToDispose
=
False
if
self
.
canAccept
():
self
.
printTrace
(
self
.
id
,
'will try signalling a giver from removeEntity'
)
self
.
signalGiver
()
return
activeEntity
#gets an entity from the giver
#===========================================================================
#it may handle both Parts and Frames
# gets an entity from the giver
# it may handle both Parts and Frames
#===========================================================================
def
getEntity
(
self
,
type
):
def
getEntity
(
self
,
type
):
activeObject
=
self
.
getActiveObject
()
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
giverObject
=
self
.
getGiverObject
()
giverObject
=
self
.
getGiverObject
()
giverObject
.
sortEntities
()
#sort the Entities of the giver according to the scheduling rule if applied
giverObject
.
sortEntities
()
#sort the Entities of the giver according to the scheduling rule if applied
giverObjectQueue
=
self
.
getGiverObjectQueue
()
giverObjectQueue
=
self
.
getGiverObjectQueue
()
activeEntity
=
giverObjectQueue
[
0
]
# if the giverObject is blocked then unBlock it
if
giverObject
.
exitIsAssignedTo
():
giverObject
.
unAssignExit
()
# if the activeObject entry is blocked then unBlock it
if
activeObject
.
entryIsAssignedTo
():
activeObject
.
unAssignEntry
()
if
(
type
==
"Part"
):
activeEntity
=
self
.
identifyEntityToGet
()
activeObjectQueue
[
0
].
getFrameQueue
().
append
(
activeEntity
)
#get the part from the giver and append it to the frame!
assert
activeEntity
.
type
==
type
,
'the type of the entity to get must be of type '
+
type
+
' while it is '
+
activeEntity
.
type
giverObject
.
removeEntity
(
activeEntity
)
#remove the part
from the previews object
#remove the entity
from the previews object
self
.
outputTrace
(
activeEntity
.
name
,
"got into "
+
self
.
objName
)
giverObject
.
removeEntity
(
activeEntity
)
elif
(
type
==
"Frame"
):
self
.
printTrace
(
activeEntity
.
name
,
"got into "
+
self
.
id
)
activeObjectQueue
.
append
(
giverObjectQueue
[
0
])
#get the frame from the giver
self
.
outputTrace
(
activeEntity
.
name
,
"got into "
+
self
.
objName
)
giverObject
.
removeEntity
(
activeEntity
)
#remove the frame from the previews object
# if the type is Frame
self
.
outputTrace
(
activeEntity
.
name
,
"got into "
+
self
.
objName
)
if
(
activeEntity
.
type
==
"Frame"
):
self
.
nameLastEntityEntered
=
activeEntity
.
name
self
.
nameLastEntityEntered
=
activeEntity
.
name
self
.
timeLastEntityEntered
=
now
()
self
.
timeLastEntityEntered
=
now
()
activeEntity
.
currentStation
=
self
activeEntity
.
currentStation
=
self
return
activeEntity
# if the frame is not fully loaded then signal a giver
#actions to be taken after the simulation ends
if
len
(
activeObjectQueue
[
0
].
getFrameQueue
())
<
activeObjectQueue
[
0
].
capacity
:
self
.
printTrace
(
self
.
id
,
'will try signalling a giver from getEntity'
)
self
.
signalGiver
()
return
activeEntity
#===========================================================================
# appends entity to the receiver object. to be called by the removeEntity of the giver
# this method is created to be overridden by the Assembly class in its getEntity where Frames are loaded
#===========================================================================
def
appendEntity
(
self
,
entity
=
None
):
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
assert
entity
,
'the entity to be appended cannot be None'
if
entity
.
type
==
'Part'
:
activeObjectQueue
[
0
].
getFrameQueue
().
append
(
entity
)
#get the part from the giver and append it to the frame!
elif
entity
.
type
==
'Frame'
:
activeObjectQueue
.
append
(
entity
)
#get the frame and append it to the internal queue
#===========================================================================
# actions to be taken after the simulation ends
#===========================================================================
def
postProcessing
(
self
,
MaxSimtime
=
None
):
def
postProcessing
(
self
,
MaxSimtime
=
None
):
if
MaxSimtime
==
None
:
if
MaxSimtime
==
None
:
...
@@ -241,7 +332,9 @@ class Assembly(CoreObject):
...
@@ -241,7 +332,9 @@ class Assembly(CoreObject):
self
.
Working
.
append
(
100
*
self
.
totalWorkingTime
/
MaxSimtime
)
self
.
Working
.
append
(
100
*
self
.
totalWorkingTime
/
MaxSimtime
)
self
.
Blockage
.
append
(
100
*
self
.
totalBlockageTime
/
MaxSimtime
)
self
.
Blockage
.
append
(
100
*
self
.
totalBlockageTime
/
MaxSimtime
)
#outputs data to "output.xls"
#===========================================================================
# outputs data to "output.xls"
#===========================================================================
def
outputResultsXL
(
self
,
MaxSimtime
=
None
):
def
outputResultsXL
(
self
,
MaxSimtime
=
None
):
from
Globals
import
G
from
Globals
import
G
from
Globals
import
getConfidenceIntervals
from
Globals
import
getConfidenceIntervals
...
@@ -280,7 +373,9 @@ class Assembly(CoreObject):
...
@@ -280,7 +373,9 @@ class Assembly(CoreObject):
G
.
outputIndex
+=
1
G
.
outputIndex
+=
1
G
.
outputIndex
+=
1
G
.
outputIndex
+=
1
#outputs results to JSON File
#===========================================================================
# outputs results to JSON File
#===========================================================================
def
outputResultsJSON
(
self
):
def
outputResultsJSON
(
self
):
from
Globals
import
G
from
Globals
import
G
from
Globals
import
getConfidenceIntervals
from
Globals
import
getConfidenceIntervals
...
...
dream/simulation/CoreObject.py
View file @
b8c6f37e
...
@@ -262,7 +262,7 @@ class CoreObject(Process):
...
@@ -262,7 +262,7 @@ 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'
)
#
self.printTrace(self.id, 'trying to preempt a receiver')
activeObject
=
self
.
getActiveObject
()
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
activeObjectQueue
=
self
.
getActiveObjectQueue
()
...
...
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