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
2f17b9a9
Commit
2f17b9a9
authored
Aug 20, 2014
by
Georgios Dagkakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Examples rearranged
parent
fcdb080a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
37 deletions
+16
-37
dream/simulation/Examples/ParallelServers3.py
dream/simulation/Examples/ParallelServers3.py
+15
-35
dream/simulation/Examples/ParallelServers4.py
dream/simulation/Examples/ParallelServers4.py
+1
-2
No files found.
dream/simulation/Examples/ParallelServers3.py
View file @
2f17b9a9
...
...
@@ -3,44 +3,27 @@ from dream.simulation.Globals import runSimulation
#the custom queue
class
SelectiveQueue
(
Queue
):
#
override so that it first chooses M1 and then M2
#
override so that it chooses receiver according to priority
def
selectReceiver
(
self
,
possibleReceivers
=
[]):
if
M1
.
canAccept
():
return
M1
elif
M2
.
canAccept
():
return
M2
# sort the receivers according to their priority
possibleReceivers
.
sort
(
key
=
lambda
x
:
x
.
priority
,
reverse
=
True
)
if
possibleReceivers
[
0
].
canAccept
():
return
possibleReceivers
[
0
]
elif
possibleReceivers
[
1
].
canAccept
():
return
possibleReceivers
[
1
]
return
None
#the custom machine
class
Milling
(
Machine
):
def
getEntity
(
self
):
activeEntity
=
Machine
.
getEntity
(
self
)
#call the parent method to get the entity
part
=
self
.
getActiveObjectQueue
()[
0
]
#retrieve the obtained part
part
.
machineId
=
self
.
id
#create an attribute to the obtained part and give it the value of the object's id
return
activeEntity
#return the entity obtained
#the custom exit
class
CountingExit
(
Exit
):
def
getEntity
(
self
):
activeEntity
=
Exit
.
getEntity
(
self
)
#call the parent method to get the entity
#check the attribute and update the counters accordingly
if
activeEntity
.
machineId
==
'M1'
:
G
.
NumM1
+=
1
elif
activeEntity
.
machineId
==
'M2'
:
G
.
NumM2
+=
1
return
activeEntity
#return the entity obtained
#define the objects of the model
S
=
Source
(
'S'
,
'Source'
,
interarrivalTime
=
{
'distributionType'
:
'Fixed'
,
'mean'
:
0.5
},
entity
=
'Dream.Part'
)
Q
=
SelectiveQueue
(
'Q'
,
'Queue'
,
capacity
=
float
(
"inf"
))
M1
=
M
illing
(
'M1'
,
'Milling1'
,
processingTime
=
{
'distributionType'
:
'Fixed'
,
'mean'
:
0.25
})
M2
=
M
illing
(
'M2'
,
'Milling2'
,
processingTime
=
{
'distributionType'
:
'Fixed'
,
'mean'
:
0.25
})
E
=
Counting
Exit
(
'E1'
,
'Exit'
)
M1
=
M
achine
(
'M1'
,
'Milling1'
,
processingTime
=
{
'distributionType'
:
'Fixed'
,
'mean'
:
0.25
})
M2
=
M
achine
(
'M2'
,
'Milling2'
,
processingTime
=
{
'distributionType'
:
'Fixed'
,
'mean'
:
0.25
})
E
=
Exit
(
'E1'
,
'Exit'
)
F
=
Failure
(
victim
=
M1
,
distribution
=
{
'distributionType'
:
'Fixed'
,
'MTTF'
:
60
,
'MTTR'
:
5
})
#create
the global counter variabl
es
G
.
NumM1
=
0
G
.
NumM2
=
0
#create
priority attribute in the Machin
es
M1
.
priority
=
1
0
M2
.
priority
=
0
#define predecessors and successors for the objects
S
.
defineRouting
([
Q
])
...
...
@@ -64,13 +47,10 @@ def main():
working_ratio_M2
=
(
M2
.
totalWorkingTime
/
maxSimTime
)
*
100
print
"the working ratio of"
,
M1
.
objName
,
"is"
,
working_ratio_M1
,
"%"
print
"the working ratio of"
,
M2
.
objName
,
"is"
,
working_ratio_M2
,
"%"
print
M1
.
objName
,
"produced"
,
G
.
NumM1
,
"parts"
print
M2
.
objName
,
"produced"
,
G
.
NumM2
,
"parts"
return
{
"parts"
:
E
.
numOfExits
,
"working_ratio_M1"
:
working_ratio_M1
,
"working_ratio_M2"
:
working_ratio_M2
,
"NumM1"
:
G
.
NumM1
,
"NumM2"
:
G
.
NumM2
}
}
if
__name__
==
'__main__'
:
main
()
dream/simulation/Examples/ParallelServers4.py
View file @
2f17b9a9
...
...
@@ -3,7 +3,7 @@ from dream.simulation.Globals import runSimulation
#the custom queue
class
SelectiveQueue
(
Queue
):
#override so that it
first chooses M1 and then M2
#override so that it
chooses receiver according to priority
def
selectReceiver
(
self
,
possibleReceivers
=
[]):
# sort the receivers according to their priority
possibleReceivers
.
sort
(
key
=
lambda
x
:
x
.
priority
,
reverse
=
True
)
...
...
@@ -48,7 +48,6 @@ G.NumM2=0
M1
.
priority
=
10
M2
.
priority
=
0
#define predecessors and successors for the objects
S
.
defineRouting
([
Q
])
Q
.
defineRouting
([
S
],[
M1
,
M2
])
...
...
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