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
c94bdc63
Commit
c94bdc63
authored
Jun 05, 2019
by
Georgios Dagkakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code for experiments
parent
50a4e123
Changes
12
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
666 additions
and
20 deletions
+666
-20
dream/platform/static/manifest.appcache
dream/platform/static/manifest.appcache
+1
-1
dream/plugins/ACO.py
dream/plugins/ACO.py
+7
-1
dream/plugins/Batches/BatchesACO.py
dream/plugins/Batches/BatchesACO.py
+2
-0
dream/plugins/Batches/BatchesStochasticACO.py
dream/plugins/Batches/BatchesStochasticACO.py
+27
-6
dream/simulation/CoreObject.py
dream/simulation/CoreObject.py
+5
-0
dream/simulation/Examples/MilkPlant2.xls
dream/simulation/Examples/MilkPlant2.xls
+0
-0
dream/simulation/Examples/SeminarModels.py
dream/simulation/Examples/SeminarModels.py
+71
-0
dream/simulation/Examples/TestConveyer.xls
dream/simulation/Examples/TestConveyer.xls
+0
-0
dream/simulation/Exit.py
dream/simulation/Exit.py
+4
-0
dream/simulation/OperatedPoolBroker.py
dream/simulation/OperatedPoolBroker.py
+13
-4
dream/simulation/SkilledOperatorRouter.py
dream/simulation/SkilledOperatorRouter.py
+21
-8
dream/simulation/WhereToRuleSkilledRouter.py
dream/simulation/WhereToRuleSkilledRouter.py
+515
-0
No files found.
dream/platform/static/manifest.appcache
View file @
c94bdc63
CACHE MANIFEST
# This manifest was generated by grunt-manifest HTML5 Cache Manifest Generator
# Time: Wed
Sep 16 2015 18:23:50 GMT+0200 (CES
T)
# Time: Wed
Nov 28 2018 10:09:45 GMT+0000 (GM
T)
CACHE:
daff/index.html
...
...
dream/plugins/ACO.py
View file @
c94bdc63
...
...
@@ -41,6 +41,7 @@ class ACO(plugin.ExecutionPlugin):
def
run
(
self
,
data
):
"""Preprocess the data.
"""
self
.
logger
.
info
(
"ACO"
)
distributor_url
=
data
[
'general'
].
get
(
'distributorURL'
)
distributor
=
None
if
distributor_url
:
...
...
@@ -108,7 +109,12 @@ class ACO(plugin.ExecutionPlugin):
else
:
# synchronous
for
ant
in
scenario_list
:
self
.
logger
.
info
(
"%s running"
%
ant
[
'key'
])
try
:
ant
[
'result'
]
=
self
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
except
:
self
.
logger
.
info
(
"%s failed"
%
ant
[
'key'
])
ant
[
'result'
]
=
{
'result_list'
:
[
'fail'
]}
else
:
# asynchronous
self
.
logger
.
info
(
"Registering a job for %s scenarios"
%
len
(
scenario_list
))
...
...
dream/plugins/Batches/BatchesACO.py
View file @
c94bdc63
...
...
@@ -18,6 +18,8 @@ class BatchesACO(ACO):
"""Calculate the score of this ant.
"""
result
,
=
ant
[
'result'
][
'result_list'
]
#read the result as JSON
if
result
==
'fail'
:
return
0
#loop through the elements
for
element
in
result
[
'elementList'
]:
element_family
=
element
.
get
(
'family'
,
None
)
...
...
dream/plugins/Batches/BatchesStochasticACO.py
View file @
c94bdc63
...
...
@@ -39,6 +39,8 @@ class BatchesStochasticACO(BatchesACO):
"""Calculate the score of this ant.
"""
result
,
=
ant
[
'result'
][
'result_list'
]
#read the result as JSON
if
result
==
'fail'
:
return
0
#loop through the elements
for
element
in
result
[
'elementList'
]:
element_family
=
element
.
get
(
'family'
,
None
)
...
...
@@ -68,6 +70,7 @@ class BatchesStochasticACO(BatchesACO):
def
run
(
self
,
data
):
"""Preprocess the data.
"""
self
.
logger
.
info
(
"Stoch ACO"
)
self
.
outputFile
=
xlwt
.
Workbook
()
self
.
outputSheet
=
self
.
outputFile
.
add_sheet
(
'ACO Results'
,
cell_overwrite_ok
=
True
)
self
.
rowIndex
=
0
...
...
@@ -141,6 +144,7 @@ class BatchesStochasticACO(BatchesACO):
for
i
in
range
(
int
(
data
[
"general"
][
"numberOfGenerations"
])):
self
.
outputSheet
.
write
(
self
.
rowIndex
,
0
,
'Generation '
+
str
(
i
+
1
))
self
.
rowIndex
+=
1
self
.
logger
.
info
(
"Generation %s"
%
self
.
rowIndex
)
antsInCurrentGeneration
=
[]
scenario_list
=
[]
# for the distributor
# number of ants created per generation
...
...
@@ -190,8 +194,13 @@ class BatchesStochasticACO(BatchesACO):
self
.
outputSheet
.
write
(
self
.
rowIndex
,
1
,
'running deterministic'
)
self
.
outputSheet
.
write
(
self
.
rowIndex
,
2
,
ant
[
'key'
])
self
.
rowIndex
+=
1
try
:
ant
[
'result'
]
=
self
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
ant
[
'score'
]
=
self
.
_calculateAntScore
(
ant
)
except
:
self
.
logger
.
info
(
"%s failed"
%
ant
[
'key'
])
ant
[
'result'
]
=
{
'result_list'
:
[
'fail'
]}
ant
[
'score'
]
=
0
ant
[
'evaluationType'
]
=
'deterministic'
self
.
outputSheet
.
write
(
self
.
rowIndex
,
2
,
'Units Throughput'
)
self
.
outputSheet
.
write
(
self
.
rowIndex
,
3
,
-
ant
[
'score'
])
...
...
@@ -220,9 +229,14 @@ class BatchesStochasticACO(BatchesACO):
self
.
outputSheet
.
write
(
self
.
rowIndex
,
1
,
'running stochastic for '
+
str
(
numberOfReplicationsInGeneration
)
+
' replications'
)
self
.
outputSheet
.
write
(
self
.
rowIndex
,
2
,
ant
[
'key'
])
self
.
rowIndex
+=
1
try
:
ant
[
'result'
]
=
self
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
ant
[
'evaluationType'
]
=
'stochastic'
ant
[
'score'
]
=
self
.
calculateStochasticAntScore
(
ant
)
except
:
self
.
logger
.
info
(
"%s failed"
%
ant
[
'key'
])
ant
[
'result'
]
=
{
'result_list'
:
[
'fail'
]}
ant
[
'score'
]
=
0
ant
[
'evaluationType'
]
=
'stochastic'
self
.
outputSheet
.
write
(
self
.
rowIndex
,
2
,
'Average Units Throughput'
)
self
.
outputSheet
.
write
(
self
.
rowIndex
,
3
,
-
ant
[
'score'
])
self
.
rowIndex
+=
1
...
...
@@ -281,8 +295,15 @@ class BatchesStochasticACO(BatchesACO):
self
.
outputSheet
.
write
(
self
.
rowIndex
,
1
,
'running stochastic for '
+
str
(
numberOfReplicationsInTheEnd
)
+
' replications'
)
self
.
outputSheet
.
write
(
self
.
rowIndex
,
2
,
ant
[
'key'
])
self
.
rowIndex
+=
1
try
:
ant
[
'result'
]
=
self
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
ant
[
'score'
]
=
self
.
calculateStochasticAntScore
(
ant
)
except
:
self
.
logger
.
info
(
"%s failed"
%
ant
[
'key'
])
ant
[
'result'
]
=
{
'result_list'
:
[
'fail'
]}
ant
[
'score'
]
=
0
# ant['result'] = self.runOneScenario(ant['input'])['result']
# ant['score'] = self.calculateStochasticAntScore(ant)
self
.
outputSheet
.
write
(
self
.
rowIndex
,
2
,
'Average Units Throughput'
)
self
.
outputSheet
.
write
(
self
.
rowIndex
,
3
,
-
ant
[
'score'
])
self
.
rowIndex
+=
1
...
...
dream/simulation/CoreObject.py
View file @
c94bdc63
...
...
@@ -347,6 +347,11 @@ class CoreObject(ManPyObject):
# gets an entity from the giver
# =======================================================================
def
getEntity
(
self
):
import
logging
self
.
logger
=
logging
.
getLogger
(
"dream.platform"
)
self
.
logger
.
info
(
self
.
env
.
now
,
self
.
id
,
'GETTING!'
)
# raise ValueError('FOO')
# get active object and its queue, as well as the active (to be) entity
#(after the sorting of the entities in the queue of the giver object)
# activeObject=self.getActiveObject()
...
...
dream/simulation/Examples/MilkPlant2.xls
0 → 100644
View file @
c94bdc63
File added
dream/simulation/Examples/SeminarModels.py
0 → 100644
View file @
c94bdc63
from
dream.simulation.Source
import
Source
from
dream.simulation.Queue
import
Queue
from
dream.simulation.Machine
import
Machine
from
dream.simulation.Exit
import
Exit
from
dream.simulation.Part
import
Part
from
dream.simulation.Globals
import
runSimulation
from
dream.simulation.Globals
import
G
import
random
#the custom machine
class
Inspection
(
Machine
):
def
selectReceiver
(
self
,
possibleReceivers
=
[]):
# 80% continue, 20% go back to Q1
# XXX Custom implementation hard-coding objects
if
random
.
uniform
(
0
,
1
)
<
0.8
:
return
Q2
else
:
return
Q1
#define the objects of the model
S
=
Source
(
'S'
,
'Source'
,
interArrivalTime
=
{
'Fixed'
:{
'mean'
:
0.5
}},
entity
=
'Dream.Part'
)
Q1
=
Queue
(
'Q'
,
'Queue'
,
capacity
=
float
(
"inf"
))
M1
=
Machine
(
'M1'
,
'Milling1'
,
processingTime
=
{
'Fixed'
:{
'mean'
:
1
}})
QI
=
Queue
(
'Q'
,
'Queue'
,
capacity
=
float
(
"inf"
))
I
=
Inspection
(
'I'
,
'Inspection'
,
processingTime
=
{
'Fixed'
:{
'mean'
:
0.2
}})
Q2
=
Queue
(
'Q'
,
'Queue'
,
capacity
=
float
(
"inf"
))
M2
=
Machine
(
'M2'
,
'Milling2'
,
processingTime
=
{
'Fixed'
:{
'mean'
:
1
}})
E
=
Exit
(
'E1'
,
'Exit'
)
#create the global counter variables
G
.
NumM1
=
0
G
.
NumM2
=
0
#define predecessors and successors for the objects
S
.
defineRouting
([
Q1
])
Q1
.
defineRouting
([
S
,
I
],[
M1
])
M1
.
defineRouting
([
Q1
],[
QI
])
QI
.
defineRouting
([
M1
],[
I
])
I
.
defineRouting
([
QI
],[
Q1
,
Q2
])
Q2
.
defineRouting
([
I
],[
M2
])
M2
.
defineRouting
([
Q2
],[
E
])
E
.
defineRouting
([
M2
])
def
main
(
test
=
0
):
# add all the objects in a list
objectList
=
[
S
,
Q1
,
M1
,
QI
,
I
,
Q2
,
M2
,
E
]
# set the length of the experiment
maxSimTime
=
1440.0
# call the runSimulation giving the objects and the length of the experiment
runSimulation
(
objectList
,
maxSimTime
)
# calculate metrics
working_ratio_M1
=
(
M1
.
totalWorkingTime
/
maxSimTime
)
*
100
working_ratio_M2
=
(
M2
.
totalWorkingTime
/
maxSimTime
)
*
100
# return results for the test
if
test
:
return
{
"parts"
:
E
.
numOfExits
,
"working_ratio_M1"
:
working_ratio_M1
,
"working_ratio_M2"
:
working_ratio_M2
,
"NumM1"
:
G
.
NumM1
,
"NumM2"
:
G
.
NumM2
}
#print the results
print
"the system produced"
,
E
.
numOfExits
,
"parts"
print
"the working ratio of"
,
M1
.
objName
,
"is"
,
working_ratio_M1
,
"%"
print
"the working ratio of"
,
M2
.
objName
,
"is"
,
working_ratio_M2
,
"%"
if
__name__
==
'__main__'
:
main
()
dream/simulation/Examples/TestConveyer.xls
0 → 100644
View file @
c94bdc63
File added
dream/simulation/Exit.py
View file @
c94bdc63
...
...
@@ -105,6 +105,10 @@ class Exit(CoreObject):
# gets an entity from the predecessor
# =======================================================================
def
getEntity
(
self
):
import
logging
self
.
logger
=
logging
.
getLogger
(
"dream.platform"
)
self
.
logger
.
info
(
"!--- %s ----!"
%
self
.
env
.
now
)
activeEntity
=
CoreObject
.
getEntity
(
self
)
#run the default method
# if the entity is in the G.pendingEntities list then remove it from there
from
Globals
import
G
...
...
dream/simulation/OperatedPoolBroker.py
View file @
c94bdc63
...
...
@@ -30,6 +30,7 @@ Models an Interruption that handles the operating of a Station by an ObjectResou
import
simpy
from
ObjectInterruption
import
ObjectInterruption
# from SimPy.Simulation import waituntil, now, hold, request, release, waitevent
import
logging
# ===========================================================================
# Class that handles the Operator Behavior
...
...
@@ -52,6 +53,7 @@ class Broker(ObjectInterruption):
# flag that shows if broker was called to request or release operator.
# Machine updates this before calling the broker
self
.
invokeType
=
'request'
self
.
logger
=
logging
.
getLogger
(
"dream.platform"
)
#===========================================================================
# the initialize method
...
...
@@ -77,8 +79,9 @@ class Broker(ObjectInterruption):
# TODO: add new broker event - brokerIsCalled
self
.
expectedSignals
[
'isCalled'
]
=
1
self
.
logger
.
info
(
"!--- %s %s Waiting isCalled1 ----!"
%
(
self
.
env
.
now
,
self
.
id
))
yield
self
.
isCalled
self
.
logger
.
info
(
"!--- %s %s Got isCalled1 ----!"
%
(
self
.
env
.
now
,
self
.
id
))
transmitter
,
eventTime
=
self
.
isCalled
.
value
assert
eventTime
==
self
.
env
.
now
,
'the broker should be granted control instantly'
self
.
isCalled
=
self
.
env
.
event
()
...
...
@@ -106,8 +109,9 @@ class Broker(ObjectInterruption):
self
.
victim
.
printTrace
(
self
.
victim
.
id
,
waitEvent
=
'(resourceIsAvailable broker)'
)
self
.
expectedSignals
[
'resourceAvailable'
]
=
1
self
.
logger
.
info
(
"!--- %s %s Waiting resourceAvailable ----!"
%
(
self
.
env
.
now
,
self
.
id
))
yield
self
.
resourceAvailable
self
.
logger
.
info
(
"!--- %s %s Got resourceAvailable ----!"
%
(
self
.
env
.
now
,
self
.
id
))
transmitter
,
eventTime
=
self
.
resourceAvailable
.
value
self
.
resourceAvailable
=
self
.
env
.
event
()
...
...
@@ -132,7 +136,10 @@ class Broker(ObjectInterruption):
with
self
.
victim
.
operatorPool
.
getResource
(
self
.
victim
.
currentOperator
).
request
()
as
request
:
self
.
logger
.
info
(
"!--- %s %s Waiting request ----!"
%
(
self
.
env
.
now
,
self
.
id
))
yield
request
self
.
logger
.
info
(
"!--- %s %s Got request ----!"
%
(
self
.
env
.
now
,
self
.
id
))
# update the operator workingStation
self
.
victim
.
currentOperator
.
workingStation
=
self
.
victim
self
.
victim
.
printTrace
(
self
.
victim
.
currentOperator
.
objName
,
startWork
=
self
.
victim
.
id
)
...
...
@@ -165,7 +172,9 @@ class Broker(ObjectInterruption):
# wait till the processing is over
self
.
expectedSignals
[
'isCalled'
]
=
1
self
.
logger
.
info
(
"!--- %s %s Waiting isCalled2 ----!"
%
(
self
.
env
.
now
,
self
.
id
))
yield
self
.
isCalled
self
.
logger
.
info
(
"!--- %s %s Got isCalled2 ----!"
%
(
self
.
env
.
now
,
self
.
id
))
transmitter
,
eventTime
=
self
.
isCalled
.
value
assert
eventTime
==
self
.
env
.
now
,
'the broker should be granted control instantly'
...
...
dream/simulation/SkilledOperatorRouter.py
View file @
c94bdc63
...
...
@@ -87,8 +87,9 @@ class SkilledRouter(Router):
# wait until the router is called
self
.
expectedSignals
[
'isCalled'
]
=
1
self
.
logger
.
info
(
"!--- %s %s WAITING isCalled ----!"
%
(
self
.
env
.
now
,
self
.
id
))
yield
self
.
isCalled
self
.
logger
.
info
(
"!--- %s %s GOT isCalled ----!"
%
(
self
.
env
.
now
,
self
.
id
))
transmitter
,
eventTime
=
self
.
isCalled
.
value
self
.
isCalled
=
self
.
env
.
event
()
...
...
@@ -223,8 +224,11 @@ class SkilledRouter(Router):
import
time
startLP
=
time
.
time
()
if
LPFlag
:
if
self
.
whereToMaxWIP
and
self
.
previousSolution
:
self
.
logger
.
info
(
'---> '
+
str
(
self
.
env
.
now
))
self
.
logger
.
info
(
self
.
previousSolution
)
self
.
logger
.
info
(
self
.
availableOperatorList
)
if
self
.
whereToMaxWIP
and
self
.
previousSolution
:
# self.logger.info('---> ' + str(self.env.now))
solution
=
{}
maxWIP
=-
1
minWIP
=
float
(
'inf'
)
...
...
@@ -239,7 +243,7 @@ class SkilledRouter(Router):
# first, find the machine with max wip
for
stationId
in
sorted_station_id_list
:
stationDict
=
self
.
availableStationsDict
.
get
(
stationId
,
None
)
self
.
logger
.
info
(
stationDict
)
#
self.logger.info(stationDict)
if
not
stationDict
:
continue
wip
=
stationDict
[
'WIP'
]
...
...
@@ -250,11 +254,12 @@ class SkilledRouter(Router):
]
assert
len
(
assignedOperatorList
)
in
(
0
,
1
),
assignedOperatorList
if
not
assignedOperatorList
:
self
.
logger
.
info
(
'%s has no operator'
%
stationId
)
pass
# self.logger.info('%s has no operator' % stationId)
if
wip
>
maxWIP
and
not
assignedOperatorList
:
machineWithMaxWIP
=
stationId
maxWIP
=
wip
self
.
logger
.
info
(
machineWithMaxWIP
)
#
self.logger.info(machineWithMaxWIP)
solution
=
{}
# First, search for an operator that was not
# previously assigned, and can handle the maxWIP station
...
...
@@ -398,7 +403,7 @@ class SkilledRouter(Router):
if
operatorID
in
self
.
previousSolution
:
# if the solution returned the operator that is already in the station
# then no signal is needed
if
not
self
.
previousSolution
[
operatorID
]
==
solution
[
operatorID
]
:
if
not
(
self
.
previousSolution
[
operatorID
]
==
solution
[
operatorID
]
and
operator
==
station
.
currentOperator
)
:
self
.
toBeSignalled
.
append
(
station
)
else
:
self
.
toBeSignalled
.
append
(
station
)
...
...
@@ -413,12 +418,15 @@ class SkilledRouter(Router):
# remove the operator id from availableOperatorList
self
.
availableOperatorList
.
remove
(
operatorID
)
#===================================================================
# # XXX signal the stations that the assignment is complete
#===================================================================
# if the operator is free the station can be signalled right away
stationsProcessingLast
=
[]
toBeSignalled
=
list
(
self
.
toBeSignalled
)
self
.
logger
.
info
(
"!--- %s toBeSignalled: %s ----!"
%
(
self
.
env
.
now
,
len
(
toBeSignalled
)))
for
station
in
toBeSignalled
:
# check if the operator that the station waits for is free
operator
=
station
.
operatorToGet
...
...
@@ -438,7 +446,10 @@ class SkilledRouter(Router):
self
.
expectedFinishSignalsDict
[
station
.
id
]
=
signal
self
.
expectedFinishSignals
.
append
(
signal
)
while
self
.
expectedFinishSignals
:
self
.
logger
.
info
(
"!--- %s %s WAITING expectedFinishSignals ----!"
%
(
self
.
env
.
now
,
self
.
id
))
receivedEvent
=
yield
self
.
env
.
any_of
(
self
.
expectedFinishSignals
)
self
.
logger
.
info
(
"!--- %s %s GOT expectedFinishSignals ----!"
%
(
self
.
env
.
now
,
self
.
id
))
for
signal
in
self
.
expectedFinishSignals
:
if
signal
in
receivedEvent
:
transmitter
,
eventTime
=
signal
.
value
...
...
@@ -488,6 +499,8 @@ class SkilledRouter(Router):
# =======================================================================
def
signalStation
(
self
,
station
,
operator
):
# signal this station's broker that the resource is available
self
.
logger
.
info
(
"!--- %s %s signalStation ----!"
%
(
self
.
env
.
now
,
self
.
id
))
if
station
.
broker
.
waitForOperator
:
if
station
.
broker
.
expectedSignals
[
'resourceAvailable'
]:
self
.
sendSignal
(
receiver
=
station
.
broker
,
signal
=
station
.
broker
.
resourceAvailable
)
...
...
dream/simulation/WhereToRuleSkilledRouter.py
0 → 100644
View file @
c94bdc63
This diff is collapsed.
Click to expand it.
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