Skip to content

Commit ab2e6a3

Browse files
committed
Added cut generations feature
* No validations are being made at the moment #49
1 parent 529889e commit ab2e6a3

File tree

7 files changed

+1200
-1106
lines changed

7 files changed

+1200
-1106
lines changed

MLC/GUI/Autogenerated/autogenerated.py

Lines changed: 1084 additions & 1084 deletions
Large diffs are not rendered by default.

MLC/GUI/Autogenerated/mlc_qtcreator/experiment.ui

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<enum>QTabWidget::North</enum>
2525
</property>
2626
<property name="currentIndex">
27-
<number>0</number>
27+
<number>1</number>
2828
</property>
2929
<widget class="QWidget" name="experiment_tab">
3030
<property name="layoutDirection">
@@ -473,27 +473,26 @@
473473
<item>
474474
<widget class="QGroupBox" name="groupBox_3">
475475
<property name="title">
476-
<string>DB</string>
476+
<string>Generations</string>
477477
</property>
478478
<layout class="QVBoxLayout" name="verticalLayout_13">
479479
<item>
480-
<widget class="QPushButton" name="pushButton_3">
481-
<property name="text">
482-
<string>Create</string>
480+
<widget class="QPushButton" name="gen_cut_button">
481+
<property name="toolTip">
482+
<string>Remove generations ahead of the current generation</string>
483483
</property>
484-
</widget>
485-
</item>
486-
<item>
487-
<widget class="QPushButton" name="pushButton_4">
488484
<property name="text">
489485
<string>Cut</string>
490486
</property>
491487
</widget>
492488
</item>
493489
<item>
494-
<widget class="QPushButton" name="pushButton_8">
490+
<widget class="QPushButton" name="gen_start_over_button">
491+
<property name="toolTip">
492+
<string>Remove all the generations, maintaining only the last generation computed</string>
493+
</property>
495494
<property name="text">
496-
<string>Import</string>
495+
<string>Start Over</string>
497496
</property>
498497
</widget>
499498
</item>
@@ -1239,6 +1238,38 @@
12391238
</hint>
12401239
</hints>
12411240
</connection>
1241+
<connection>
1242+
<sender>gen_cut_button</sender>
1243+
<signal>clicked()</signal>
1244+
<receiver>ExperimentWindow</receiver>
1245+
<slot>on_gen_cut_button_clicked()</slot>
1246+
<hints>
1247+
<hint type="sourcelabel">
1248+
<x>835</x>
1249+
<y>309</y>
1250+
</hint>
1251+
<hint type="destinationlabel">
1252+
<x>480</x>
1253+
<y>283</y>
1254+
</hint>
1255+
</hints>
1256+
</connection>
1257+
<connection>
1258+
<sender>gen_start_over_button</sender>
1259+
<signal>clicked()</signal>
1260+
<receiver>ExperimentWindow</receiver>
1261+
<slot>on_gen_start_over_button_clicked()</slot>
1262+
<hints>
1263+
<hint type="sourcelabel">
1264+
<x>835</x>
1265+
<y>337</y>
1266+
</hint>
1267+
<hint type="destinationlabel">
1268+
<x>480</x>
1269+
<y>283</y>
1270+
</hint>
1271+
</hints>
1272+
</connection>
12421273
</connections>
12431274
<slots>
12441275
<slot>on_closed_dialog()</slot>
@@ -1266,5 +1297,7 @@
12661297
<slot>on_first_add_indiv_button_clicked()</slot>
12671298
<slot>on_first_remove_indiv_button_clicked()</slot>
12681299
<slot>on_first_add_indiv_from_textfile_button_clicked()</slot>
1300+
<slot>on_gen_cut_button_clicked()</slot>
1301+
<slot>on_gen_start_over_button_clicked()</slot>
12691302
</slots>
12701303
</ui>

MLC/GUI/Experiment/ExperimentWindow.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,45 @@ def on_first_remove_indiv_button_clicked(self):
419419
.format(self._experiment_name))
420420
self._first_indivs_manager.remove_individual()
421421

422+
def on_gen_cut_button_clicked(self):
423+
logger.debug('[EXPERIMENT {0}] [GEN_CUT_BUTTON] - '
424+
'Executing on_gen_cut_button_clicked function'
425+
.format(self._experiment_name))
426+
experiment_info = self._mlc_local.get_experiment_info(self._experiment_name)
427+
number_of_gens = experiment_info["generations"]
428+
429+
amount_of_gen_losts = number_of_gens - self._current_gen + 1
430+
response = QMessageBox.warning(self, "Cut Generations",
431+
"{0} generations will be lost with this operation. "
432+
"Do you really want to continue?"
433+
.format(amount_of_gen_losts),
434+
QMessageBox.Yes | QMessageBox.No,
435+
QMessageBox.No)
436+
437+
if response == QMessageBox.Yes:
438+
logger.info("[GEN_CUT_BUTTON] Proceed to remove {0} generations (From {1} onwards)"
439+
.format(amount_of_gen_losts, self._current_gen))
440+
self._mlc_local.remove_generations_from(self._experiment_name,
441+
self._current_gen)
442+
last_gen_removed = self._current_gen
443+
# Recalculate the amount of generations in the project
444+
experiment_info = self._mlc_local.get_experiment_info(self._experiment_name)
445+
number_of_gens = experiment_info["generations"]
446+
self._current_gen = number_of_gens
447+
self._update_individuals_per_generation_list()
448+
self._update_experiment_info()
449+
self._update_individuals_figure()
450+
self._update_scatter_chart()
451+
452+
QMessageBox.information(self, "Cut Generations",
453+
"{0} generations were succesfully removed (From {1} onwards)"
454+
.format(amount_of_gen_losts, last_gen_removed))
455+
456+
def on_gen_start_over_button_clicked(self):
457+
logger.debug('[EXPERIMENT {0}] [GEN_START_OVER_BUTTON] - '
458+
'Executing on_gen_start_over_button_clicked function'
459+
.format(self._experiment_name))
460+
422461
def _config_table_edited(self, left, right):
423462
config_table = self._autogenerated_object.config_table
424463
table_model = config_table.model()

MLC/api/MLCLocal.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ def get_generation(self, experiment_name, generation_number):
263263

264264
return simulation.get_generation(generation_number)
265265

266+
def remove_generations_from(self, experiment_name, gen_number):
267+
if experiment_name not in self._experiments:
268+
raise ExperimentNotExistException(experiment_name)
269+
270+
if experiment_name not in self._open_experiments:
271+
raise ClosedExperimentException("get_experiment_info", experiment_name)
272+
273+
MLCRepository.get_instance().remove_population_from(gen_number)
274+
MLCRepository.get_instance().remove_unused_individuals()
275+
266276
def get_individual(self, experiment_name, individual_id):
267277
if experiment_name not in self._experiments:
268278
raise ExperimentNotExistException(experiment_name)

MLC/api/mlc.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ def get_generation(self, experiment_name, generation_number):
188188
"""
189189
raise NotImplementedError("MLC::get_generation not implemented")
190190

191+
def remove_generations_from(self, experiment_name, gen_number):
192+
"""
193+
Remove all the generations above the given as a parameter
194+
:param experiment_name
195+
:param gen_number
196+
"""
197+
191198
def get_individuals(self, experiment_name):
192199
"""
193200
Obtained generated individuals during the simulation.
@@ -204,7 +211,8 @@ def get_individual(self, experiment_name, individual_id):
204211
"""
205212
raise NotImplementedError("MLC::get_individual not implemented")
206213

207-
def update_individual_cost(self, experiment_name, indiv_id, new_cost, new_ev_time, generation=-1):
214+
def update_individual_cost(self, experiment_name, indiv_id,
215+
new_cost, new_ev_time, generation=-1):
208216
"""
209217
Update individual cost. If generation == -1 Individual cost will
210218
be updated in all generations.
@@ -215,10 +223,10 @@ def update_individual_cost(self, experiment_name, indiv_id, new_cost, new_ev_tim
215223

216224
def show_best(self, experiment_name, generation_number):
217225
"""
218-
Plot the best individual of the populations evaluated. This method ought not
226+
Plot the best individual of the populations evaluated. This method ought not
219227
to be called before calling the function go at least once
220228
:param experiment_name:
221-
:param generation_number: The generation in which we are looking
229+
:param generation_number: The generation in which we are looking
222230
for the best individual
223231
"""
224232
raise NotImplementedError("MLC::get_individuals not implemented")

MLC/db/mlc_repository.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def count_population(self):
7171
def remove_population_from(self, from_generation):
7272
raise NotImplementedError("This method must be implemented")
7373

74+
def remove_population_to(self, to_generation):
75+
raise NotImplementedError("This method must be implemented")
76+
77+
def remove_unused_individuals(self):
78+
raise NotImplementedError("This method must be implemented")
79+
7480
# operations over individuals
7581
def add_individual(self, individual):
7682
raise NotImplementedError("This method must be implemented")
@@ -97,10 +103,8 @@ def count_individual(self):
97103
raise NotImplementedError("This method must be implemented")
98104

99105
# special methods
100-
def update_individual_cost(self, individual_id, cost, evaluation_time, generation=-1):
101-
raise NotImplementedError("This method must be implemented")
102-
103-
def remove_unused_individuals(self):
106+
def update_individual_cost(self, individual_id, cost,
107+
evaluation_time, generation=-1):
104108
raise NotImplementedError("This method must be implemented")
105109

106110
@staticmethod

MLC/db/sqlite/sqlite_repository.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def add_population(self, population):
7979
cursor = conn.cursor()
8080

8181
try:
82-
next_gen_id = self.__base_gen+self.__generations
82+
next_gen_id = self.__base_gen + self.__generations
8383
for i in range(len(population._individuals)):
8484
individual_id = population._individuals[i]
8585
individual_cost = population._costs[i]
@@ -110,10 +110,10 @@ def count_population(self):
110110

111111
# special methods
112112
def remove_population_from(self, from_generation):
113-
if from_generation>self.__generations:
113+
if from_generation > self.__generations:
114114
return
115115

116-
gen_id = self.__base_gen+from_generation-1
116+
gen_id = self.__base_gen + from_generation - 1
117117
self.__execute(stmt_delete_from_generations(gen_id))
118118
self.__generations = from_generation - 1
119119
if from_generation == 1:
@@ -125,7 +125,7 @@ def remove_population_to(self, to_generation):
125125

126126
gen_id = self.__base_gen + to_generation - 1
127127
self.__execute(stmt_delete_to_generations(gen_id))
128-
self.__generations = self.__generations-to_generation
128+
self.__generations = self.__generations - to_generation
129129
if self.__generations == 0:
130130
self.__base_gen = 1
131131
else:

0 commit comments

Comments
 (0)