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
f2eea936
Commit
f2eea936
authored
Jan 20, 2014
by
Kazuhiko Shiozaki
Committed by
Jérome Perrin
Jan 20, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make run() return dict and _runSimulation() convert it to JSON.
parent
b200f808
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
5 deletions
+6
-5
dream/platform/__init__.py
dream/platform/__init__.py
+1
-1
dream/simulation/Default.py
dream/simulation/Default.py
+1
-1
dream/simulation/MouldingFactory.py
dream/simulation/MouldingFactory.py
+4
-3
No files found.
dream/platform/__init__.py
View file @
f2eea936
...
@@ -114,7 +114,7 @@ def _runSimulation(parameter_dict, queue):
...
@@ -114,7 +114,7 @@ def _runSimulation(parameter_dict, queue):
parameter_dict
[
'general'
][
'simulationClass'
]
parameter_dict
[
'general'
][
'simulationClass'
]
klass
=
__import__
(
klass_name
,
globals
(),
{},
klass_name
)
klass
=
__import__
(
klass_name
,
globals
(),
{},
klass_name
)
result
=
klass
.
Simulation
(
logger
=
app
.
logger
).
run
(
parameter_dict
)
result
=
klass
.
Simulation
(
logger
=
app
.
logger
).
run
(
parameter_dict
)
queue
.
put
(
dict
(
success
=
json
.
loads
(
result
)
))
queue
.
put
(
dict
(
success
=
result
))
except
Exception
,
e
:
except
Exception
,
e
:
tb
=
traceback
.
format_exc
()
tb
=
traceback
.
format_exc
()
app
.
logger
.
error
(
tb
)
app
.
logger
.
error
(
tb
)
...
...
dream/simulation/Default.py
View file @
f2eea936
...
@@ -6,4 +6,4 @@ class Simulation:
...
@@ -6,4 +6,4 @@ class Simulation:
self
.
logger
=
logger
self
.
logger
=
logger
def
run
(
self
,
data
):
def
run
(
self
,
data
):
return
simulate_line_json
(
input_data
=
json
.
dumps
(
data
))
return
json
.
loads
(
simulate_line_json
(
input_data
=
json
.
dumps
(
data
)
))
dream/simulation/MouldingFactory.py
View file @
f2eea936
...
@@ -15,7 +15,7 @@ def calculateAntScore(ant):
...
@@ -15,7 +15,7 @@ def calculateAntScore(ant):
XXX Maybe this can be based on other criterions, such as completion time ?
XXX Maybe this can be based on other criterions, such as completion time ?
"""
"""
totalDelay
=
0
#set the total delay to 0
totalDelay
=
0
#set the total delay to 0
jsonData
=
json
.
loads
(
ant
[
'resultJSON'
])
#read the result as JSON
jsonData
=
ant
[
'result'
]
#read the result as JSON
elementList
=
jsonData
[
'elementList'
]
#find the route of JSON
elementList
=
jsonData
[
'elementList'
]
#find the route of JSON
#loop through the elements
#loop through the elements
for
element
in
elementList
:
for
element
in
elementList
:
...
@@ -113,7 +113,7 @@ class Simulation(DefaultSimulation):
...
@@ -113,7 +113,7 @@ class Simulation(DefaultSimulation):
ant_data
[
"nodes"
][
k
][
'schedulingRule'
]
=
v
ant_data
[
"nodes"
][
k
][
'schedulingRule'
]
=
v
# TODO: those two steps have to be parallelized
# TODO: those two steps have to be parallelized
ant
[
'result
JSON
'
]
=
DefaultSimulation
.
run
(
self
,
ant_data
)
ant
[
'result'
]
=
DefaultSimulation
.
run
(
self
,
ant_data
)
ant
[
'score'
]
=
calculateAntScore
(
ant
)
ant
[
'score'
]
=
calculateAntScore
(
ant
)
# The ants in this generation are ranked based on their scores and the
# The ants in this generation are ranked based on their scores and the
...
@@ -131,11 +131,12 @@ class Simulation(DefaultSimulation):
...
@@ -131,11 +131,12 @@ class Simulation(DefaultSimulation):
collated
[
m
].
append
(
l
[
m
])
collated
[
m
].
append
(
l
[
m
])
result_count
=
min
(
4
,
len
(
ants
))
result_count
=
min
(
4
,
len
(
ants
))
print
repr
(
ants
)
print
'%s best results :'
%
result_count
print
'%s best results :'
%
result_count
for
i
in
range
(
result_count
):
for
i
in
range
(
result_count
):
ant
=
ants
[
i
]
ant
=
ants
[
i
]
displayed_ant
=
copy
(
ant
)
displayed_ant
=
copy
(
ant
)
displayed_ant
.
pop
(
'result
JSON
'
)
displayed_ant
.
pop
(
'result'
)
print
'================='
print
'================='
print
displayed_ant
print
displayed_ant
...
...
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