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
bcb85cef
Commit
bcb85cef
authored
May 28, 2014
by
Ioannis Papagiannopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Conveyer class updated
parent
16899abd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
33 deletions
+38
-33
dream/simulation/Conveyer.py
dream/simulation/Conveyer.py
+38
-33
No files found.
dream/simulation/Conveyer.py
View file @
bcb85cef
...
@@ -26,8 +26,9 @@ Models a conveyer object
...
@@ -26,8 +26,9 @@ Models a conveyer object
it gathers entities and transfers them with a certain speed
it gathers entities and transfers them with a certain speed
'''
'''
from
SimPy.Simulation
import
Process
,
Resource
,
SimEvent
# from SimPy.Simulation import Process, Resource, SimEvent
from
SimPy.Simulation
import
waitevent
,
now
,
hold
,
infinity
,
activate
# from SimPy.Simulation import waitevent, now, hold, infinity, activate
import
simpy
import
xlwt
import
xlwt
from
CoreObject
import
CoreObject
from
CoreObject
import
CoreObject
...
@@ -54,15 +55,15 @@ class Conveyer(CoreObject):
...
@@ -54,15 +55,15 @@ class Conveyer(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
self
.
moveEnd
=
SimEvent
(
'moveEnd'
)
self
.
moveEnd
=
self
.
env
.
event
(
)
#===========================================================================
#===========================================================================
# the initialize method
# the initialize method
#===========================================================================
#===========================================================================
def
initialize
(
self
):
def
initialize
(
self
):
Process
.
__init__
(
self
)
#
Process.__init__(self)
CoreObject
.
initialize
(
self
)
CoreObject
.
initialize
(
self
)
self
.
Res
=
Resource
(
capacity
=
infinity
)
self
.
Res
=
simpy
.
Resource
(
self
.
env
,
capacity
=
'inf'
)
self
.
position
=
[]
#list that shows the position of the corresponding element in the conveyer
self
.
position
=
[]
#list that shows the position of the corresponding element in the conveyer
self
.
timeLastMoveHappened
=
0
#holds the last time that the move was performed (in reality it is
self
.
timeLastMoveHappened
=
0
#holds the last time that the move was performed (in reality it is
...
@@ -72,7 +73,7 @@ class Conveyer(CoreObject):
...
@@ -72,7 +73,7 @@ class Conveyer(CoreObject):
#a place is freed. It performs the move at this point,
#a place is freed. It performs the move at this point,
#so if there are actions to be carried they will
#so if there are actions to be carried they will
self
.
entityLastReachedEnd
=
None
#the entity that last reached the end of the conveyer
self
.
entityLastReachedEnd
=
None
#the entity that last reached the end of the conveyer
self
.
timeBlockageStarted
=
now
()
#the time that the conveyer reached the blocked state
self
.
timeBlockageStarted
=
self
.
env
.
now
#the time that the conveyer reached the blocked state
#plant considers the conveyer blocked even if it can accept just one entity
#plant considers the conveyer blocked even if it can accept just one entity
#I think this is false
#I think this is false
self
.
wasFull
=
False
#flag that shows if the conveyer was full. So when an entity is disposed
self
.
wasFull
=
False
#flag that shows if the conveyer was full. So when an entity is disposed
...
@@ -90,7 +91,8 @@ class Conveyer(CoreObject):
...
@@ -90,7 +91,8 @@ class Conveyer(CoreObject):
#===========================================================================
#===========================================================================
def
run
(
self
):
def
run
(
self
):
#these are just for the first Entity
#these are just for the first Entity
activate
(
self
.
conveyerMover
,
self
.
conveyerMover
.
run
())
# activate(self.conveyerMover,self.conveyerMover.run())
self
.
env
.
process
(
self
.
conveyerMover
.
run
())
# check if there is WIP and signal receiver
# check if there is WIP and signal receiver
self
.
initialSignalReceiver
()
self
.
initialSignalReceiver
()
while
1
:
while
1
:
...
@@ -98,31 +100,31 @@ class Conveyer(CoreObject):
...
@@ -98,31 +100,31 @@ class Conveyer(CoreObject):
#set it as the timeToWait of the conveyerMover and raise call=true so that it will be triggered
#set it as the timeToWait of the conveyerMover and raise call=true so that it will be triggered
if
self
.
updateMoveTime
():
if
self
.
updateMoveTime
():
# print self.id, 'time to move', self.conveyerMover.timeToWait
# print self.id, 'time to move', self.conveyerMover.timeToWait
self
.
conveyerMover
.
canMove
.
s
ignal
(
now
()
)
self
.
conveyerMover
.
canMove
.
s
ucceed
(
self
.
env
.
now
)
self
.
printTrace
(
self
.
id
,
waitEvent
=
''
)
self
.
printTrace
(
self
.
id
,
waitEvent
=
''
)
yield
waitevent
,
self
,
[
self
.
isRequested
,
self
.
canDispose
,
self
.
moveEnd
]
# , self.loadOperatorAvailable]
receivedEvent
=
yield
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
in
receivedEvent
:
self
.
printTrace
(
self
.
id
,
isRequested
=
''
)
self
.
printTrace
(
self
.
id
,
isRequested
=
''
)
# reset the isRequested signal parameter
# reset the isRequested signal parameter
self
.
isRequested
.
signalparam
=
None
self
.
isRequested
=
self
.
env
.
event
()
# get the entity
# get the entity
self
.
getEntity
()
self
.
getEntity
()
# this should be performed only the first time
# this should be performed only the first time
if
not
self
.
numberOfMoves
:
if
not
self
.
numberOfMoves
:
self
.
timeLastMoveHappened
=
now
()
self
.
timeLastMoveHappened
=
self
.
env
.
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.
value
:
# self.loadOperatorAvailable.
signalparam
=None
# self.loadOperatorAvailable.
value
=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
in
receivedEvent
:
self
.
printTrace
(
self
.
id
,
canDispose
=
''
)
self
.
printTrace
(
self
.
id
,
canDispose
=
''
)
self
.
canDispose
.
signalparam
=
None
self
.
canDispose
=
self
.
env
.
event
()
# 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
in
receivedEvent
:
self
.
printTrace
(
self
.
id
,
moveEnd
=
''
)
self
.
printTrace
(
self
.
id
,
moveEnd
=
''
)
self
.
moveEnd
.
signalparam
=
None
self
.
moveEnd
=
self
.
env
.
event
()
# 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
,
attemptSignalGiver
=
'(removeEntity)'
)
self
.
printTrace
(
self
.
id
,
attemptSignalGiver
=
'(removeEntity)'
)
...
@@ -204,7 +206,7 @@ class Conveyer(CoreObject):
...
@@ -204,7 +206,7 @@ class Conveyer(CoreObject):
# also counts the time the move required to assign it as working time
# also counts the time the move required to assign it as working time
#===========================================================================
#===========================================================================
def
moveEntities
(
self
):
def
moveEntities
(
self
):
interval
=
now
()
-
self
.
timeLastMoveHappened
interval
=
self
.
env
.
now
-
self
.
timeLastMoveHappened
interval
=
(
float
(
interval
))
*
60.0
#the simulation time that passed since the last move was taken care
interval
=
(
float
(
interval
))
*
60.0
#the simulation time that passed since the last move was taken care
moveTime1
=
0
moveTime1
=
0
moveTime2
=
0
moveTime2
=
0
...
@@ -221,8 +223,8 @@ class Conveyer(CoreObject):
...
@@ -221,8 +223,8 @@ class Conveyer(CoreObject):
moveTime1
=
(
self
.
length
-
self
.
position
[
0
])
/
self
.
speed
moveTime1
=
(
self
.
length
-
self
.
position
[
0
])
/
self
.
speed
self
.
position
[
0
]
=
self
.
length
self
.
position
[
0
]
=
self
.
length
self
.
entityLastReachedEnd
=
self
.
getActiveObjectQueue
()[
0
]
self
.
entityLastReachedEnd
=
self
.
getActiveObjectQueue
()[
0
]
self
.
timeLastEntityReachedEnd
=
now
()
self
.
timeLastEntityReachedEnd
=
self
.
env
.
now
self
.
timeLastEntityEnded
=
now
()
self
.
timeLastEntityEnded
=
self
.
env
.
now
#for the other entities
#for the other entities
for
i
in
range
(
1
,
len
(
self
.
getActiveObjectQueue
())):
for
i
in
range
(
1
,
len
(
self
.
getActiveObjectQueue
())):
#if it does not reach the preceding entity move it according to speed
#if it does not reach the preceding entity move it according to speed
...
@@ -237,7 +239,7 @@ class Conveyer(CoreObject):
...
@@ -237,7 +239,7 @@ class Conveyer(CoreObject):
self
.
position
[
i
]
=
self
.
position
[
i
-
1
]
-
self
.
getActiveObjectQueue
()[
i
-
1
].
length
self
.
position
[
i
]
=
self
.
position
[
i
-
1
]
-
self
.
getActiveObjectQueue
()[
i
-
1
].
length
# print [x for x in self.position]
# print [x for x in self.position]
#assign this time as the time of last move
#assign this time as the time of last move
self
.
timeLastMoveHappened
=
now
()
self
.
timeLastMoveHappened
=
self
.
env
.
now
#all the time of moving (the max since things move in parallel) is considered as working time
#all the time of moving (the max since things move in parallel) is considered as working time
self
.
totalWorkingTime
+=
max
(
moveTime1
/
60.0
,
moveTime2
/
60.0
)
self
.
totalWorkingTime
+=
max
(
moveTime1
/
60.0
,
moveTime2
/
60.0
)
# check again if there is any entity that has reached the exit of the conveyer
# check again if there is any entity that has reached the exit of the conveyer
...
@@ -332,7 +334,7 @@ class Conveyer(CoreObject):
...
@@ -332,7 +334,7 @@ class Conveyer(CoreObject):
self
.
numberOfMoves
+=
1
self
.
numberOfMoves
+=
1
#check if the conveyer became full to start counting blockage
#check if the conveyer became full to start counting blockage
if
self
.
isFull
():
if
self
.
isFull
():
self
.
timeBlockageStarted
=
now
()
self
.
timeBlockageStarted
=
self
.
env
.
now
self
.
wasFull
=
True
self
.
wasFull
=
True
self
.
printTrace
(
self
.
id
,
conveyerFull
=
str
(
len
(
self
.
getActiveObjectQueue
())))
self
.
printTrace
(
self
.
id
,
conveyerFull
=
str
(
len
(
self
.
getActiveObjectQueue
())))
return
activeEntity
return
activeEntity
...
@@ -349,12 +351,12 @@ class Conveyer(CoreObject):
...
@@ -349,12 +351,12 @@ class Conveyer(CoreObject):
#if the conveyer was full, it means that it also was blocked
#if the conveyer was full, it means that it also was blocked
#we count this blockage time
#we count this blockage time
if
self
.
wasFull
:
if
self
.
wasFull
:
# self.totalBlockageTime+=
now()
-self.timeBlockageStarted
# self.totalBlockageTime+=
self.env.now
-self.timeBlockageStarted
self
.
wasFull
=
False
self
.
wasFull
=
False
#calculate the time that the conveyer will become available again and trigger the conveyerMover
#calculate the time that the conveyer will become available again and trigger the conveyerMover
if
self
.
updateMoveTime
():
if
self
.
updateMoveTime
():
# print self.id, 'time to move', self.conveyerMover.timeToWait
# print self.id, 'time to move', self.conveyerMover.timeToWait
self
.
conveyerMover
.
canMove
.
s
ignal
(
now
()
)
self
.
conveyerMover
.
canMove
.
s
ucceed
(
self
.
env
.
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
,
attemptSingalReceiver
=
'(removeEntity)'
)
self
.
printTrace
(
self
.
id
,
attemptSingalReceiver
=
'(removeEntity)'
)
...
@@ -367,7 +369,7 @@ class Conveyer(CoreObject):
...
@@ -367,7 +369,7 @@ class Conveyer(CoreObject):
#===========================================================================
#===========================================================================
def
addBlockage
(
self
):
def
addBlockage
(
self
):
if
self
.
wasFull
:
if
self
.
wasFull
:
self
.
totalBlockageTime
+=
now
()
-
self
.
timeBlockageStarted
self
.
totalBlockageTime
+=
self
.
env
.
now
-
self
.
timeBlockageStarted
#===========================================================================
#===========================================================================
# checks if the Conveyer can dispose an entity to the following object
# checks if the Conveyer can dispose an entity to the following object
...
@@ -414,7 +416,7 @@ class Conveyer(CoreObject):
...
@@ -414,7 +416,7 @@ class Conveyer(CoreObject):
self
.
moveEntities
()
#move the entities to count the working time
self
.
moveEntities
()
#move the entities to count the working time
#if the conveyer is full count the blockage time
#if the conveyer is full count the blockage time
if
self
.
isFull
():
if
self
.
isFull
():
self
.
totalBlockageTime
+=
now
()
-
self
.
timeBlockageStarted
+
0.1
self
.
totalBlockageTime
+=
self
.
env
.
now
-
self
.
timeBlockageStarted
+
0.1
#when the conveyer was nor working or blocked it was waiting
#when the conveyer was nor working or blocked it was waiting
self
.
totalWaitingTime
=
MaxSimtime
-
self
.
totalWorkingTime
-
self
.
totalBlockageTime
self
.
totalWaitingTime
=
MaxSimtime
-
self
.
totalWorkingTime
-
self
.
totalBlockageTime
...
@@ -494,16 +496,18 @@ class Conveyer(CoreObject):
...
@@ -494,16 +496,18 @@ class Conveyer(CoreObject):
#===============================================================================
#===============================================================================
# Process that handles the moves of the conveyer
# Process that handles the moves of the conveyer
#===============================================================================
#===============================================================================
class
ConveyerMover
(
Process
):
class
ConveyerMover
(
object
):
#===========================================================================
#===========================================================================
# ConveyerMover init method
# ConveyerMover init method
#===========================================================================
#===========================================================================
def
__init__
(
self
,
conveyer
):
def
__init__
(
self
,
conveyer
):
Process
.
__init__
(
self
)
# Process.__init__(self)
from
Globals
import
G
self
.
env
=
G
.
env
self
.
conveyer
=
conveyer
#the conveyer that owns the mover
self
.
conveyer
=
conveyer
#the conveyer that owns the mover
self
.
timeToWait
=
0
#the time to wait every time. This is calculated by the conveyer and corresponds
self
.
timeToWait
=
0
#the time to wait every time. This is calculated by the conveyer and corresponds
#either to the time that one entity reaches the end or the time that one space is freed
#either to the time that one entity reaches the end or the time that one space is freed
self
.
canMove
=
SimEvent
(
'canMove'
)
self
.
canMove
=
self
.
env
.
event
(
)
#===========================================================================
#===========================================================================
# ConveyerMover generator
# ConveyerMover generator
...
@@ -511,13 +515,14 @@ class ConveyerMover(Process):
...
@@ -511,13 +515,14 @@ class ConveyerMover(Process):
def
run
(
self
):
def
run
(
self
):
while
1
:
while
1
:
self
.
conveyer
.
printTrace
(
self
.
conveyer
.
id
,
waitEvent
=
'(canMove)'
)
self
.
conveyer
.
printTrace
(
self
.
conveyer
.
id
,
waitEvent
=
'(canMove)'
)
yield
waitevent
,
self
,
self
.
canMove
#wait until the conveyer triggers the mover
yield
self
.
canMove
#wait until the conveyer triggers the mover
self
.
canMove
=
self
.
env
.
event
()
self
.
conveyer
.
printTrace
(
self
.
conveyer
.
id
,
received
=
'(canMove)'
)
self
.
conveyer
.
printTrace
(
self
.
conveyer
.
id
,
received
=
'(canMove)'
)
yield
hold
,
self
,
self
.
timeToWait
#wait for the time that the conveyer calculated
yield
self
.
env
.
timeout
(
self
.
timeToWait
)
#wait for the time that the conveyer calculated
# 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
.
moveEnd
.
s
ignal
(
now
()
)
self
.
conveyer
.
moveEnd
.
s
ucceed
(
self
.
env
.
now
)
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