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
d9aa3a7b
Commit
d9aa3a7b
authored
Jan 16, 2014
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simply use a set instead of checkIfAntTested
parent
80a58f15
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
21 deletions
+7
-21
dream/simulation/MouldingFactory.py
dream/simulation/MouldingFactory.py
+7
-21
No files found.
dream/simulation/MouldingFactory.py
View file @
d9aa3a7b
...
...
@@ -3,7 +3,6 @@ import json
import
time
import
random
import
operator
from
Globals
import
G
from
dream.simulation.Default
import
Simulation
as
DefaultSimulation
...
...
@@ -26,22 +25,6 @@ def calculateAntScore(ant):
totalDelay
+=
delay
return
totalDelay
# XXX jerome: isn't repr() enough ? or json.dumps ?
# XXX use a set
#creates a light coded form of the ant and tests it
def
checkIfAntTested
(
ant
):
#code the ant in a lighter string form
codedAnt
=
''
for
key
in
ant
:
codedAnt
+=
ant
[
key
]
#if it already exists return true so that it will not be tested
if
codedAnt
in
G
.
CodedAnstsList
:
return
True
#else add it to the list and return false
else
:
G
.
CodedAnstsList
.
append
(
codedAnt
)
return
False
class
Simulation
(
DefaultSimulation
):
...
...
@@ -88,7 +71,7 @@ class Simulation(DefaultSimulation):
def
run
(
self
,
data
):
data
=
self
.
_setWIP
(
data
)
G
.
CodedAnstsList
=
[]
# a list to keep all the solutions in a coded form
tested_ants
=
set
()
start
=
time
.
time
()
# start counting execution time
# the list of options collated into a dictionary for ease of referencing in ManPy
...
...
@@ -99,13 +82,16 @@ class Simulation(DefaultSimulation):
ants
=
[]
#list of ants for keeping track of their performance
for
i
in
range
(
10
):
#Number of times new ants are to be created, i.e. number of generations (a generation can have more than 1 ant)
for
i
in
range
(
10
):
#
Number of times new ants are to be created, i.e. number of generations (a generation can have more than 1 ant)
for
j
in
range
(
20
):
#number of ants created per generation
ant
=
{}
# an ant dictionary to contain rule to queue assignment information
for
k
in
collated
.
keys
():
#for each of the machines, rules are randomly picked from the options list
ant
[
str
(
k
)]
=
random
.
choice
(
collated
[
str
(
k
)])
#if the ant was not already tested, only then test it
if
not
checkIfAntTested
(
ant
):
ant_key
=
repr
(
ant
)
# if the ant was not already tested, only then test it
if
ant_key
not
in
tested_ants
:
tested_ants
.
add
(
ant_key
)
ants
.
append
(
ant
)
#the current ant to be simulated (evaluated) is added to the ants list
# set scheduling rule on queues based on ant data
...
...
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