Skip to content

Commit 6a70544

Browse files
committed
Added best indiv description in experiment info
* #36
1 parent 52911cd commit 6a70544

File tree

11 files changed

+66
-34
lines changed

11 files changed

+66
-34
lines changed

MLC/GUI/Autogenerated/untitled/untitled.pro.user

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 4.1.0, 2017-01-16T12:04:30. -->
3+
<!-- Written by QtCreator 4.2.0, 2017-01-17T23:56:31. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>
7-
<value type="QByteArray">{89aaf96f-e2f6-40f4-bca5-8aa7dd8dc388}</value>
7+
<value type="QByteArray">{350f9065-16e4-4481-9d13-d542c79185b9}</value>
88
</data>
99
<data>
1010
<variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -59,14 +59,14 @@
5959
<data>
6060
<variable>ProjectExplorer.Project.Target.0</variable>
6161
<valuemap type="QVariantMap">
62-
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
63-
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
64-
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{f92ecf44-e715-45cb-84a0-3754f1e7bcc1}</value>
62+
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.7.1 GCC 64bit</value>
63+
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.7.1 GCC 64bit</value>
64+
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.57.gcc_64_kit</value>
6565
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
6666
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
6767
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
6868
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
69-
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/media/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/build-untitled-Desktop-Debug</value>
69+
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/build-untitled-Desktop_Qt_5_7_1_GCC_64bit-Debug</value>
7070
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
7171
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
7272
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@@ -126,7 +126,7 @@
126126
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
127127
</valuemap>
128128
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
129-
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/media/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/build-untitled-Desktop-Release</value>
129+
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/build-untitled-Desktop_Qt_5_7_1_GCC_64bit-Release</value>
130130
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
131131
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
132132
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@@ -186,7 +186,7 @@
186186
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
187187
</valuemap>
188188
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
189-
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/media/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/build-untitled-Desktop-Profile</value>
189+
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/build-untitled-Desktop_Qt_5_7_1_GCC_64bit-Profile</value>
190190
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
191191
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
192192
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@@ -304,7 +304,7 @@
304304
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
305305
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">untitled</value>
306306
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
307-
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/media/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/untitled/untitled.pro</value>
307+
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/untitled/untitled.pro</value>
308308
<value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value>
309309
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
310310
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">untitled.pro</value>

MLC/api/MLCLocal.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import tarfile
99
import time
1010

11+
from collections import OrderedDict
1112
from MLC.api.Experiment import Experiment
1213
from MLC.api.mlc import MLC
1314
from MLC.api.mlc import ClosedExperimentException
@@ -183,14 +184,18 @@ def get_experiment_info(self, experiment_name):
183184

184185
simulation = self._open_experiments[experiment_name].get_simulation()
185186

186-
experiment_info = {
187-
"name": experiment_name,
188-
"generations": simulation.number_of_generations(),
189-
"individuals": MLCRepository.get_instance().count_individual(),
190-
"individuals_per_generation": Config.get_instance().getint("POPULATION", "size"),
191-
"filename": experiment_name + ".mlc"
192-
}
193-
187+
experiment_info = OrderedDict()
188+
experiment_info["name"] = experiment_name
189+
experiment_info["generations"] = simulation.number_of_generations()
190+
experiment_info["individuals"] = MLCRepository.get_instance().count_individual()
191+
experiment_info["individuals_per_generation"] = Config.get_instance().getint("POPULATION", "size")
192+
193+
if MLCRepository.get_instance().count_individual() != 0:
194+
# Get the best indiv description
195+
min_indiv_id = MLCRepository.get_instance().get_individual_with_min_cost()
196+
min_indiv_data = MLCRepository.get_instance().get_individual_data(min_indiv_id)
197+
experiment_info["best_indiv_id"] = min_indiv_id
198+
experiment_info["best_indiv_value"] = min_indiv_data.get_value()
194199
return experiment_info
195200

196201
def go(self, experiment_name, to_generation, from_generation=0, callbacks={}):

MLC/db/mlc_repository.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def update_individual(self, individual_id, individual):
8787
def remove_individual(self, individual_id):
8888
raise NotImplementedError("This method must be implemented")
8989

90+
def get_individual_with_min_cost(self):
91+
raise NotImplementedError("This method must be implemented")
92+
9093
def get_individual(self, individual_id):
9194
raise NotImplementedError("This method must be implemented")
9295

MLC/db/sqlite/sql_statements.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ def stmt_delete_generation(generation):
2121
return """DELETE FROM population
2222
WHERE gen = %s""" % (generation,)
2323

24+
2425
def stmt_delete_from_generations(from_generation):
2526
return """DELETE FROM population
2627
WHERE gen >= %s""" % (from_generation,)
2728

29+
2830
def stmt_delete_unused_individuals():
2931
return '''DELETE FROM individual
3032
WHERE indiv_id NOT IN (SELECT DISTINCT indiv_id FROM population)'''
@@ -39,6 +41,7 @@ def stmt_delete_unused_individuals():
3941
return '''DELETE FROM individual
4042
WHERE indiv_id NOT IN (SELECT DISTINCT indiv_id FROM population)'''
4143

44+
4245
def stmt_get_generations():
4346
return '''SELECT distinct gen FROM population'''
4447

@@ -61,6 +64,7 @@ def stmt_get_individuals_from_population(generation):
6164

6265

6366
class SQLSaveFormal:
67+
6468
@staticmethod
6569
def to_sql(indiv_formal):
6670
if isinstance(indiv_formal, str):
@@ -72,12 +76,14 @@ def to_sql(indiv_formal):
7276
def from_sql(indiv_formal_column):
7377
return indiv_formal_column.split('@')
7478

79+
7580
def stmt_insert_individual(individual_id, individual):
7681
return '''INSERT INTO individual VALUES (%s, "%s", "%s", %s)''' % (individual_id,
7782
individual.get_value(),
7883
SQLSaveFormal.to_sql(individual.get_formal()),
7984
individual.get_complexity())
8085

86+
8187
def stmt_get_all_individuals():
8288
return '''SELECT indiv_id, value, formal, complexity
8389
from individual
@@ -89,11 +95,13 @@ def stmt_get_individual_data(indiv_id):
8995
FROM population
9096
WHERE indiv_id = %s''' % (indiv_id)
9197

98+
9299
def stmt_get_individuals_data():
93100
return '''SELECT indiv_id, gen, cost, evaluation_time
94101
FROM population
95102
ORDER BY indiv_id'''
96103

104+
97105
def stmt_update_all_costs(individual_id, cost, evaluation_time):
98106
return '''UPDATE population
99107
SET cost = %s, evaluation_time = %s
@@ -107,5 +115,13 @@ def stmt_update_cost(individual_id, cost, evaluation_time, generation):
107115
evaluation_time,
108116
individual_id,
109117
generation)
118+
119+
120+
def stmt_get_individual_with_min_cost():
121+
return '''SELECT indiv_id
122+
FROM population
123+
ORDER BY cost ASC
124+
LIMIT 1'''
125+
110126
def stmt_enable_foreign_key():
111-
return '''PRAGMA foreign_keys = ON'''
127+
return '''PRAGMA foreign_keys = ON'''

MLC/db/sqlite/sqlite_repository.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ def update_individual(self, individual_id, individual):
159159
def remove_individual(self, individual_id):
160160
raise NotImplementedError("This method must be implemented")
161161

162+
def get_individual_with_min_cost(self):
163+
conn = self.__get_db_connection()
164+
cursor = conn.execute(stmt_get_individual_with_min_cost())
165+
166+
# We are expecting just one result
167+
min_indiv_id = cursor.fetchone()[0]
168+
cursor.close()
169+
return min_indiv_id
170+
162171
def get_individual(self, individual_id):
163172
try:
164173
return self.__individuals[individual_id]

templates/toy_problem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def show_best(index, generation, indiv, cost, block=True):
7575
fig.canvas.manager.window.setWindowModality(Qt.ApplicationModal)
7676

7777
plt.suptitle("Generation N#{0} - Individual N#{1}\n"
78-
"Cost: {1}\n Formal: {3}".format(generation,
78+
"Cost: {2}\n Formal: {3}".format(generation,
7979
index,
8080
cost,
8181
indiv.get_formal()))

tests/integration_tests/test_basic/default_evaluation_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def show_best(index, generation, indiv, cost, block=True):
7474
fig.canvas.manager.window.setWindowModality(Qt.ApplicationModal)
7575

7676
plt.suptitle("Generation N#{0} - Individual N#{1}\n"
77-
"Cost: {1}\n Formal: {3}".format(generation,
77+
"Cost: {2}\n Formal: {3}".format(generation,
7878
index,
7979
cost,
8080
indiv.get_formal()))

tests/integration_tests/test_multiple_controls/default_evaluation_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def show_best(index, generation, indiv, cost, block=True):
7474
fig.canvas.manager.window.setWindowModality(Qt.ApplicationModal)
7575

7676
plt.suptitle("Generation N#{0} - Individual N#{1}\n"
77-
"Cost: {1}\n Formal: {3}".format(generation,
77+
"Cost: {2}\n Formal: {3}".format(generation,
7878
index,
7979
cost,
8080
indiv.get_formal()))

tests/integration_tests/test_persist_reusing_simulations/default_evaluation_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def show_best(index, generation, indiv, cost, block=True):
7474
fig.canvas.manager.window.setWindowModality(Qt.ApplicationModal)
7575

7676
plt.suptitle("Generation N#{0} - Individual N#{1}\n"
77-
"Cost: {1}\n Formal: {3}".format(generation,
77+
"Cost: {2}\n Formal: {3}".format(generation,
7878
index,
7979
cost,
8080
indiv.get_formal()))

tests/integration_tests/test_persist_simulation/default_evaluation_script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def show_best(index, generation, indiv, cost, block=True):
7474
fig.canvas.manager.window.setWindowModality(Qt.ApplicationModal)
7575

7676
plt.suptitle("Generation N#{0} - Individual N#{1}\n"
77-
"Cost: {1}\n Formal: {3}".format(generation,
77+
"Cost: {2}\n Formal: {3}".format(generation,
7878
index,
7979
cost,
8080
indiv.get_formal()))

0 commit comments

Comments
 (0)