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
5f1345ee
Commit
5f1345ee
authored
May 28, 2014
by
Georgios Dagkakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Machine/QueueJobshop ported to SimPy3
parent
a4a07c58
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
27 deletions
+23
-27
dream/simulation/MachineJobShop.py
dream/simulation/MachineJobShop.py
+15
-17
dream/simulation/QueueJobShop.py
dream/simulation/QueueJobShop.py
+8
-10
No files found.
dream/simulation/MachineJobShop.py
View file @
5f1345ee
...
@@ -25,9 +25,7 @@ Created on 1 oct 2012
...
@@ -25,9 +25,7 @@ Created on 1 oct 2012
extends the machine object so that it can act as a jobshop station. It reads the processing time and the successive station from the Entity
extends the machine object so that it can act as a jobshop station. It reads the processing time and the successive station from the Entity
'''
'''
from
SimPy.Simulation
import
Process
,
Resource
import
simpy
from
SimPy.Simulation
import
activate
,
passivate
,
waituntil
,
now
,
hold
,
reactivate
from
Machine
import
Machine
from
Machine
import
Machine
# ===========================================================================
# ===========================================================================
# the MachineJobShop object
# the MachineJobShop object
...
@@ -47,7 +45,7 @@ class MachineJobShop(Machine):
...
@@ -47,7 +45,7 @@ class MachineJobShop(Machine):
# =======================================================================
# =======================================================================
def
endProcessingActions
(
self
):
def
endProcessingActions
(
self
):
activeObject
=
self
.
getActiveObject
()
activeObject
=
self
.
getActiveObject
()
activeObjectQueue
=
activeObject
.
Res
.
activeQ
activeObjectQueue
=
activeObject
.
Res
.
users
activeEntity
=
activeObjectQueue
[
0
]
activeEntity
=
activeObjectQueue
[
0
]
# self.printTrace(activeEntity.name,processEnd=activeObject.objName)
# self.printTrace(activeEntity.name,processEnd=activeObject.objName)
# reset the variables used to handle the interruptions timing
# reset the variables used to handle the interruptions timing
...
@@ -85,14 +83,14 @@ class MachineJobShop(Machine):
...
@@ -85,14 +83,14 @@ class MachineJobShop(Machine):
activeObject
.
waitToDispose
=
True
activeObject
.
waitToDispose
=
True
#do this so that if it is overtime working it is not counted as off-shift time
#do this so that if it is overtime working it is not counted as off-shift time
if
not
activeObject
.
onShift
:
if
not
activeObject
.
onShift
:
activeObject
.
timeLastShiftEnded
=
now
()
activeObject
.
timeLastShiftEnded
=
self
.
env
.
now
# update the total working time # the total processing time for this entity is what the distribution initially gave
# update the total working time # the total processing time for this entity is what the distribution initially gave
if
not
self
.
shouldPreempt
:
if
not
self
.
shouldPreempt
:
activeObject
.
totalWorkingTime
+=
activeObject
.
totalProcessingTimeInCurrentEntity
activeObject
.
totalWorkingTime
+=
activeObject
.
totalProcessingTimeInCurrentEntity
else
:
else
:
activeObject
.
totalWorkingTime
+=
now
()
-
(
self
.
timeLastEntityEntered
)
activeObject
.
totalWorkingTime
+=
self
.
env
.
now
-
(
self
.
timeLastEntityEntered
)
# update the variables keeping track of Entity related attributes of the machine
# update the variables keeping track of Entity related attributes of the machine
activeObject
.
timeLastEntityEnded
=
now
()
# this holds the time that the last entity ended processing in Machine
activeObject
.
timeLastEntityEnded
=
self
.
env
.
now
# this holds the time that the last entity ended processing in Machine
activeObject
.
nameLastEntityEnded
=
activeObject
.
currentEntity
.
name
# this holds the name of the last entity that ended processing in Machine
activeObject
.
nameLastEntityEnded
=
activeObject
.
currentEntity
.
name
# this holds the name of the last entity that ended processing in Machine
activeObject
.
completedJobs
+=
1
# Machine completed one more Job
activeObject
.
completedJobs
+=
1
# Machine completed one more Job
# reseting the preemption flag
# reseting the preemption flag
...
@@ -162,7 +160,7 @@ class MachineJobShop(Machine):
...
@@ -162,7 +160,7 @@ class MachineJobShop(Machine):
# and returns true only if the active object is the next station
# and returns true only if the active object is the next station
# =======================================================================
# =======================================================================
def
canAccept
(
self
,
callerObject
=
None
):
def
canAccept
(
self
,
callerObject
=
None
):
activeObjectQueue
=
self
.
Res
.
activeQ
activeObjectQueue
=
self
.
Res
.
users
thecaller
=
callerObject
thecaller
=
callerObject
#return according to the state of the Queue
#return according to the state of the Queue
# also check if (if the machine is to be operated) there are available operators
# also check if (if the machine is to be operated) there are available operators
...
@@ -185,16 +183,16 @@ class MachineJobShop(Machine):
...
@@ -185,16 +183,16 @@ class MachineJobShop(Machine):
# postProcessing calls canAccept on next members with no arguments
# postProcessing calls canAccept on next members with no arguments
#===========================================================================
#===========================================================================
def
isInRoute
(
self
,
callerObject
=
None
):
def
isInRoute
(
self
,
callerObject
=
None
):
activeObjectQueue
=
self
.
Res
.
activeQ
activeObjectQueue
=
self
.
Res
.
users
thecaller
=
callerObject
thecaller
=
callerObject
# if the caller is not defined then return True. We are only interested in checking whether
# if the caller is not defined then return True. We are only interested in checking whether
# the station can accept whatever entity from whichever giver
# the station can accept whatever entity from whichever giver
if
not
thecaller
:
if
not
thecaller
:
return
True
return
True
#check it the caller object holds an Entity that requests for current object
#check it the caller object holds an Entity that requests for current object
if
len
(
thecaller
.
Res
.
activeQ
)
>
0
:
if
len
(
thecaller
.
Res
.
users
)
>
0
:
# TODO: make sure that the first entity of the callerObject is to be disposed
# TODO: make sure that the first entity of the callerObject is to be disposed
activeEntity
=
thecaller
.
Res
.
activeQ
[
0
]
activeEntity
=
thecaller
.
Res
.
users
[
0
]
# if the machine's Id is in the list of the entity's next stations
# if the machine's Id is in the list of the entity's next stations
if
self
.
id
in
activeEntity
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[]):
if
self
.
id
in
activeEntity
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[]):
return
True
return
True
...
@@ -205,7 +203,7 @@ class MachineJobShop(Machine):
...
@@ -205,7 +203,7 @@ class MachineJobShop(Machine):
# Returns True only to the potential receiver
# Returns True only to the potential receiver
# =======================================================================
# =======================================================================
def
haveToDispose
(
self
,
callerObject
=
None
):
def
haveToDispose
(
self
,
callerObject
=
None
):
activeObjectQueue
=
self
.
Res
.
activeQ
activeObjectQueue
=
self
.
Res
.
users
thecaller
=
callerObject
thecaller
=
callerObject
#if we have only one successor just check if machine waits to dispose and also is up
#if we have only one successor just check if machine waits to dispose and also is up
# this is done to achieve better (cpu) processing time
# this is done to achieve better (cpu) processing time
...
@@ -225,7 +223,7 @@ class MachineJobShop(Machine):
...
@@ -225,7 +223,7 @@ class MachineJobShop(Machine):
# =======================================================================
# =======================================================================
def
preempt
(
self
):
def
preempt
(
self
):
# self.printTrace(self.id,preempted='')
# self.printTrace(self.id,preempted='')
activeEntity
=
self
.
Res
.
activeQ
[
0
]
#get the active Entity
activeEntity
=
self
.
Res
.
users
[
0
]
#get the active Entity
#calculate the remaining processing time
#calculate the remaining processing time
#if it is reset then set it as the original processing time
#if it is reset then set it as the original processing time
if
self
.
resetOnPreemption
:
if
self
.
resetOnPreemption
:
...
@@ -233,7 +231,7 @@ class MachineJobShop(Machine):
...
@@ -233,7 +231,7 @@ class MachineJobShop(Machine):
#else subtract the time that passed since the entity entered
#else subtract the time that passed since the entity entered
#(may need also failure time if there was. TO BE MELIORATED)
#(may need also failure time if there was. TO BE MELIORATED)
else
:
else
:
remainingProcessingTime
=
self
.
procTime
-
(
now
()
-
self
.
timeLastEntityEntered
)
remainingProcessingTime
=
self
.
procTime
-
(
self
.
env
.
now
-
self
.
timeLastEntityEntered
)
#update the remaining route of activeEntity
#update the remaining route of activeEntity
activeEntity
.
remainingRoute
.
insert
(
0
,
{
'stationIdsList'
:[
str
(
self
.
id
)],
\
activeEntity
.
remainingRoute
.
insert
(
0
,
{
'stationIdsList'
:[
str
(
self
.
id
)],
\
'processingTime'
:
\
'processingTime'
:
\
...
@@ -247,7 +245,7 @@ class MachineJobShop(Machine):
...
@@ -247,7 +245,7 @@ class MachineJobShop(Machine):
self
.
receiver
=
self
.
lastGiver
self
.
receiver
=
self
.
lastGiver
self
.
next
=
[
self
.
receiver
]
self
.
next
=
[
self
.
receiver
]
self
.
waitToDispose
=
True
#set that I have to dispose
self
.
waitToDispose
=
True
#set that I have to dispose
self
.
receiver
.
timeLastEntityEnded
=
now
()
#required to count blockage correctly in the preemptied station
self
.
receiver
.
timeLastEntityEnded
=
self
.
env
.
now
#required to count blockage correctly in the preemptied station
# TODO: use a signal and wait for it, reactivation is not recognised as interruption
# TODO: use a signal and wait for it, reactivation is not recognised as interruption
reactivate
(
self
)
reactivate
(
self
)
# TODO: consider the case when a failure has the Station down. The event preempt will not be received now()
# TODO: consider the case when a failure has the Station down. The event preempt will not be received now()
...
@@ -274,7 +272,7 @@ class MachineJobShop(Machine):
...
@@ -274,7 +272,7 @@ class MachineJobShop(Machine):
assert
callerObject
!=
None
,
'the caller of readLoadTime cannot be None'
assert
callerObject
!=
None
,
'the caller of readLoadTime cannot be None'
thecaller
=
callerObject
thecaller
=
callerObject
thecaller
.
sortEntities
()
thecaller
.
sortEntities
()
activeEntity
=
thecaller
.
Res
.
activeQ
[
0
]
activeEntity
=
thecaller
.
Res
.
users
[
0
]
loadTime
=
activeEntity
.
remainingRoute
[
0
].
get
(
'loadTime'
,{})
loadTime
=
activeEntity
.
remainingRoute
[
0
].
get
(
'loadTime'
,{})
self
.
distType
=
loadTime
.
get
(
'distributionType'
,
'Fixed'
)
self
.
distType
=
loadTime
.
get
(
'distributionType'
,
'Fixed'
)
self
.
loadTime
=
float
(
loadTime
.
get
(
'mean'
,
0
))
self
.
loadTime
=
float
(
loadTime
.
get
(
'mean'
,
0
))
...
@@ -288,7 +286,7 @@ class MachineJobShop(Machine):
...
@@ -288,7 +286,7 @@ class MachineJobShop(Machine):
activeEntity
=
Machine
.
removeEntity
(
self
,
entity
)
#run the default method
activeEntity
=
Machine
.
removeEntity
(
self
,
entity
)
#run the default method
removeReceiver
=
True
removeReceiver
=
True
# search in the internalQ. If an entity has the same receiver do not remove
# search in the internalQ. If an entity has the same receiver do not remove
for
ent
in
self
.
Res
.
activeQ
:
for
ent
in
self
.
Res
.
users
:
nextObjectIds
=
ent
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[])
nextObjectIds
=
ent
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[])
if
receiverObject
.
id
in
nextObjectIds
:
if
receiverObject
.
id
in
nextObjectIds
:
removeReceiver
=
False
removeReceiver
=
False
...
...
dream/simulation/QueueJobShop.py
View file @
5f1345ee
...
@@ -25,9 +25,7 @@ Created on 1 oct 2012
...
@@ -25,9 +25,7 @@ Created on 1 oct 2012
extends the Queue object so that it can act as a jobshop station. Preceding station is read from the Entity
extends the Queue object so that it can act as a jobshop station. Preceding station is read from the Entity
'''
'''
from
SimPy.Simulation
import
Process
,
Resource
import
simpy
from
SimPy.Simulation
import
activate
,
passivate
,
waituntil
,
now
,
hold
from
Queue
import
Queue
from
Queue
import
Queue
# ===========================================================================
# ===========================================================================
...
@@ -49,11 +47,11 @@ class QueueJobShop(Queue):
...
@@ -49,11 +47,11 @@ class QueueJobShop(Queue):
# and returns true only if the active object is the next station
# and returns true only if the active object is the next station
# =======================================================================
# =======================================================================
def
canAccept
(
self
,
callerObject
=
None
):
def
canAccept
(
self
,
callerObject
=
None
):
activeObjectQueue
=
self
.
Res
.
activeQ
activeObjectQueue
=
self
.
Res
.
users
thecaller
=
callerObject
thecaller
=
callerObject
#return according to the state of the Queue
#return according to the state of the Queue
#check it the caller object holds an Entity that requests for current object
#check it the caller object holds an Entity that requests for current object
return
len
(
self
.
Res
.
activeQ
)
<
self
.
capacity
\
return
len
(
self
.
Res
.
users
)
<
self
.
capacity
\
and
self
.
isInRoute
(
callerObject
)
and
self
.
isInRoute
(
callerObject
)
#===========================================================================
#===========================================================================
...
@@ -61,16 +59,16 @@ class QueueJobShop(Queue):
...
@@ -61,16 +59,16 @@ class QueueJobShop(Queue):
# TODO: consider giving the activeEntity as attribute
# TODO: consider giving the activeEntity as attribute
#===========================================================================
#===========================================================================
def
isInRoute
(
self
,
callerObject
=
None
):
def
isInRoute
(
self
,
callerObject
=
None
):
activeObjectQueue
=
self
.
Res
.
activeQ
activeObjectQueue
=
self
.
Res
.
users
thecaller
=
callerObject
thecaller
=
callerObject
# if the caller is not defined then return True. We are only interested in checking whether
# if the caller is not defined then return True. We are only interested in checking whether
# the station can accept whatever entity from whichever giver
# the station can accept whatever entity from whichever giver
if
not
thecaller
:
if
not
thecaller
:
return
True
return
True
#check it the caller object holds an Entity that requests for current object
#check it the caller object holds an Entity that requests for current object
if
len
(
thecaller
.
Res
.
activeQ
)
>
0
:
if
len
(
thecaller
.
Res
.
users
)
>
0
:
# TODO: make sure that the first entity of the callerObject is to be disposed
# TODO: make sure that the first entity of the callerObject is to be disposed
activeEntity
=
thecaller
.
Res
.
activeQ
[
0
]
activeEntity
=
thecaller
.
Res
.
users
[
0
]
# if the machine's Id is in the list of the entity's next stations
# if the machine's Id is in the list of the entity's next stations
if
self
.
id
in
activeEntity
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[]):
if
self
.
id
in
activeEntity
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[]):
return
True
return
True
...
@@ -81,7 +79,7 @@ class QueueJobShop(Queue):
...
@@ -81,7 +79,7 @@ class QueueJobShop(Queue):
# Returns True only to the potential receiver
# Returns True only to the potential receiver
# =======================================================================
# =======================================================================
def
haveToDispose
(
self
,
callerObject
=
None
):
def
haveToDispose
(
self
,
callerObject
=
None
):
activeObjectQueue
=
self
.
Res
.
activeQ
activeObjectQueue
=
self
.
Res
.
users
thecaller
=
callerObject
thecaller
=
callerObject
#if we have only one possible receiver just check if the Queue holds one or more entities
#if we have only one possible receiver just check if the Queue holds one or more entities
if
(
callerObject
==
None
):
if
(
callerObject
==
None
):
...
@@ -138,7 +136,7 @@ class QueueJobShop(Queue):
...
@@ -138,7 +136,7 @@ class QueueJobShop(Queue):
activeEntity
=
Queue
.
removeEntity
(
self
,
entity
)
activeEntity
=
Queue
.
removeEntity
(
self
,
entity
)
removeReceiver
=
True
removeReceiver
=
True
# search in the internalQ. If an entity has the same receiver do not remove
# search in the internalQ. If an entity has the same receiver do not remove
for
ent
in
self
.
Res
.
activeQ
:
for
ent
in
self
.
Res
.
users
:
nextObjectIds
=
ent
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[])
nextObjectIds
=
ent
.
remainingRoute
[
0
].
get
(
'stationIdsList'
,[])
if
receiverObject
.
id
in
nextObjectIds
:
if
receiverObject
.
id
in
nextObjectIds
:
removeReceiver
=
False
removeReceiver
=
False
...
...
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