Skip to content

Commit eedfef7

Browse files
author
Ezequiel Torres
committed
Added individuals lines to the Genealogy Chart
* There are performance issues to be resolved yet #11
1 parent 33410b5 commit eedfef7

File tree

5 files changed

+77
-21
lines changed

5 files changed

+77
-21
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.2.0, 2017-01-20T09:40:09. -->
3+
<!-- Written by QtCreator 4.1.0, 2017-01-20T14:24:56. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>
7-
<value type="QByteArray">{350f9065-16e4-4481-9d13-d542c79185b9}</value>
7+
<value type="QByteArray">{89aaf96f-e2f6-40f4-bca5-8aa7dd8dc388}</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 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>
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>
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">/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/build-untitled-Desktop_Qt_5_7_1_GCC_64bit-Debug</value>
69+
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/media/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/build-untitled-Desktop-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">/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/build-untitled-Desktop_Qt_5_7_1_GCC_64bit-Release</value>
129+
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/media/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/build-untitled-Desktop-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">/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/build-untitled-Desktop_Qt_5_7_1_GCC_64bit-Profile</value>
189+
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/media/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/build-untitled-Desktop-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:/home/etorres/Facultad/TP_Profesional/MLC_GUI/MLC/GUI/Autogenerated/untitled/untitled.pro</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>
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/GUI/Experiment/ExperimentDialog.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from PyQt5.QtWidgets import QAbstractItemView
2727
from PyQt5.QtWidgets import QMainWindow
2828
from PyQt5.QtWidgets import QMessageBox
29+
from PyQt5.QtWidgets import QInputDialog
2930
Config
3031

3132
logger = get_gui_logger()
@@ -252,8 +253,22 @@ def on_convergence_button_clicked(self):
252253

253254
def on_genealogy_button_clicked(self):
254255
logger.debug('[EXPERIMENT {0}] [GENEALOGY_BUTTON] - Executing on_genealogy_button_clicked function')
255-
dialog = GenealogyDialog(self, self._mlc_local, self._current_gen, 10)
256-
dialog.show()
256+
257+
# Ask the user which Individual he would like to have displayed
258+
indivs_per_gen = Config.get_instance().getint("POPULATION", "size")
259+
individuals_list = [str(x) for x in xrange(1, indivs_per_gen + 1)]
260+
261+
indiv = QInputDialog.getItem(self, "Individual Genealogy",
262+
"Select the individual you would like to display",
263+
individuals_list, 0, False)
264+
265+
if indiv[1] == True:
266+
dialog = GenealogyDialog(parent=self,
267+
mlc_local=self._mlc_local,
268+
generation=self._current_gen,
269+
individual=int(indiv[0]),
270+
experiment_name=self._experiment_name)
271+
dialog.show()
257272

258273
def _config_table_edited(self, left, right):
259274
config_table = self._autogenerated_object.config_table

MLC/GUI/Experiment/GenealogyDialog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
class GenealogyDialog(QMainWindow):
66

7-
def __init__(self, parent, mlc_local, generation, individual):
7+
def __init__(self, parent, experiment_name, mlc_local, generation, individual):
88
QMainWindow.__init__(self, parent)
99
self._autogenerated_object = Ui_GenealogyWindow()
1010
self._autogenerated_object.setupUi(self)
1111

12-
self._genealogy_chart = GenealogyChart(mlc_local, generation, individual)
12+
self._genealogy_chart = GenealogyChart(mlc_local, experiment_name,
13+
generation, individual)
1314
self._create_new_chart()
1415

1516
def _create_new_chart(self):
Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1+
import time
2+
13
from MLC.GUI.Experiment.QtCharts.QtChartWrapper import QtChartWrapper
24
from MLC.mlc_parameters.mlc_parameters import Config
35
from PyQt5.QtCore import Qt
46

57

68
class GenealogyChart(QtChartWrapper):
7-
CHART_COLORS = [Qt.black, Qt.red, Qt.green, Qt.blue,
8-
Qt.cyan, Qt.magenta, Qt.yellow, Qt.gray]
9+
SWIM_LINE_COLORS = [Qt.cyan, Qt.magenta, Qt.gray, Qt.yellow]
10+
INDIV_COLORS = [Qt.black, Qt.red, Qt.green, Qt.blue]
911

10-
def __init__(self, mlc_local, generation, individual):
12+
def __init__(self, mlc_local, experiment_name, generation, individual):
1113
QtChartWrapper.__init__(self, False)
1214
self._mlc_local = mlc_local
1315
self._indivs_per_gen = Config.get_instance().getint("POPULATION", "size")
1416
self._amount_generations = generation
1517
self._indiv_index = individual
18+
self._experiment_name = experiment_name
19+
self._next_curve = self._amount_generations
1620

1721
self._add_axis()
1822
self._add_swimming_lines()
23+
self._add_individuals()
1924

2025
def _add_axis(self):
2126
# Set the object name to be able to retrieve it later
@@ -25,18 +30,53 @@ def _add_axis(self):
2530
label_format='%g', tick_count=10)
2631

2732
chart_view = self.get_widget()
28-
chart_view.chart().axisX().setRange(1, self._amount_generations)
33+
chart_view.chart().axisX().setRange(0.5, self._amount_generations + 0.5)
2934
chart_view.chart().axisY().setRange(1, self._indivs_per_gen)
3035

3136
def _add_swimming_lines(self):
32-
amount_colors = len(GenealogyChart.CHART_COLORS)
37+
amount_colors = len(GenealogyChart.SWIM_LINE_COLORS)
3338
# TODO: Increase the marker size
3439
# when the individuals amount per generations decrease
3540
marker_size = 3
3641

3742
for index in xrange(self._amount_generations + 1):
3843
self.add_scatter(marker_size=marker_size,
39-
color=GenealogyChart.CHART_COLORS[index % amount_colors])
44+
color=GenealogyChart.SWIM_LINE_COLORS[index % amount_colors])
4045

4146
for indiv_id in xrange(self._indivs_per_gen):
4247
self.append_point(index, index, indiv_id)
48+
49+
def _add_individuals(self):
50+
start_time = time.time()
51+
generations = [self._mlc_local.get_generation(self._experiment_name, i)
52+
for i in xrange(1, self._amount_generations + 1)]
53+
54+
gen_method_points = [[], [], [], []]
55+
indivs_to_process = []
56+
new_indivs_to_process = [self._indiv_index]
57+
58+
for gen in xrange(self._amount_generations - 1, -1, -1):
59+
indivs_to_process = new_indivs_to_process
60+
new_indivs_to_process = []
61+
62+
for indiv_id in indivs_to_process:
63+
gen_method = generations[gen].get_gen_methods()[indiv_id - 1]
64+
65+
if gen != 0:
66+
parents = generations[gen].get_parents()[indiv_id - 1]
67+
if type(parents) == list:
68+
for parent_index in range(len(parents)):
69+
new_indivs_to_process.append(parents[parent_index])
70+
self.add_line_curve(line_width=.3, color=GenealogyChart.INDIV_COLORS[gen_method - 1])
71+
self.append_point(self._next_curve, gen + 1, indiv_id)
72+
self.append_point(self._next_curve, gen, parents[parent_index])
73+
self._next_curve += 1
74+
else:
75+
new_indivs_to_process.append(parents)
76+
self.add_line_curve(line_width=.3, color=GenealogyChart.INDIV_COLORS[gen_method - 1])
77+
self.append_point(self._next_curve, gen + 1, indiv_id)
78+
self.append_point(self._next_curve, gen, parents[parent_index])
79+
self._next_curve += 1
80+
81+
elapsed_time = time.time() - start_time
82+
print elapsed_time

MLC/GUI/Experiment/QtCharts/QtChartWrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def add_data(self, xdata, ydata, line_width=.1, color=None):
8383
curve.attachAxis(self._yaxis)
8484
return self._ncurves - 1
8585

86-
def add_curve(self, line_width=.1, color=None):
87-
curve = QSplineSeries()
86+
def add_line_curve(self, line_width=.1, color=None):
87+
curve = QLineSeries()
8888
pen = curve.pen()
8989

9090
if color is not None:

0 commit comments

Comments
 (0)