1+ import time
2+
13from MLC .GUI .Experiment .QtCharts .QtChartWrapper import QtChartWrapper
24from MLC .mlc_parameters .mlc_parameters import Config
35from PyQt5 .QtCore import Qt
46
57
68class 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
0 commit comments