Changeset 11257
- Timestamp:
- 08/02/14 20:25:20 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r11253 r11257 260 260 T elite = null; 261 261 262 int psum1 = GenealogyGraph.Ranks[generation].Sum(x => x.Parents.Count());263 264 262 for (int i = 0; i < population.Length; ++i) { 265 263 if (GenealogyGraph.GetByContent(population[i]).Rank.Equals(generation - 1)) { … … 305 303 } 306 304 #endregion 307 int psum2 = GenealogyGraph.Ranks[generation].Sum(x => x.Parents.Count());308 309 if (psum1 != psum2 - 1) // -1 because we have added an additional arc from the previous elite to the current one310 throw new InvalidOperationException("Parent sum should remain the same.");311 305 312 306 ComputeSuccessRatios(); … … 319 313 320 314 // remove extra graph nodes (added by the instrumented operators in the case of offspring selection) 321 var discardedOffspring = GenealogyGraph.Ranks[generation].Select(x => (T)x.Data).Except(population).ToList(); 315 RemoveUnsuccessfulOffspring(); 316 317 return base.Apply(); 318 } 319 320 private void RemoveUnsuccessfulOffspring() { 321 int generation = GenerationsParameter.ActualValue.Value; 322 var population = PopulationParameter.ActualValue; 323 var discardedOffspring = GenealogyGraph.Ranks[generation].Select(x => (T)x.Data).Except(population); 322 324 foreach (var vertex in discardedOffspring.Select(individual => GenealogyGraph.GetByContent(individual))) { 325 if (vertex.InDegree == 1) { 326 var p = vertex.Parents.First(); 327 if (p.Rank.Equals(generation - 1)) 328 throw new InvalidOperationException("Parent must be an intermediate vertex"); 329 GenealogyGraph.RemoveVertex(p); 330 } 323 331 GenealogyGraph.RemoveVertex(vertex); 324 332 } 325 326 return base.Apply();327 333 } 328 334 329 335 private void ComputeSuccessRatios() { 336 const string successfulOffspringRatioTableHistoryName = "Successful offspring ratio"; 337 const string successfulOffspringRatioHeatMapName = "Successful offspring ratio heatmap"; 338 330 339 var population = PopulationParameter.ActualValue; 331 340 var generation = GenerationsParameter.ActualValue.Value; … … 342 351 343 352 var results = ResultsParameter.ActualValue; 344 DataTable table; 345 if (!results.ContainsKey("Successful offspring ratio")) {346 table = new DataTable("Successful offspring ratio");347 results.Add(new Result("Successful offspring ratio", table));348 table.Rows.Add(new DataRow("Successful offspring ratio") { VisualProperties = { ChartType = DataRowVisualProperties.DataRowChartType.Columns, StartIndexZero = true } });353 354 DataTableHistory history; 355 if (!results.ContainsKey(successfulOffspringRatioTableHistoryName)) { 356 history = new DataTableHistory(); 357 results.Add(new Result(successfulOffspringRatioTableHistoryName, history)); 349 358 } else { 350 table = (DataTable)results["Successful offspring ratio"].Value; 351 } 352 var row = table.Rows["Successful offspring ratio"]; 359 history = (DataTableHistory)results[successfulOffspringRatioTableHistoryName].Value; 360 } 361 var table = new DataTable(); 362 var row = new DataRow("Successful Offspring") { 363 VisualProperties = { ChartType = DataRowVisualProperties.DataRowChartType.Columns, StartIndexZero = true } 364 }; 353 365 row.Values.Replace(GenealogyGraph.Ranks[generation - 1].OrderByDescending(x => x.Quality).Select(x => x.Weight)); 366 table.Rows.Add(row); 367 history.Add(table); 368 double[,] elements = new double[population.Length, history.Count]; 369 var col = history.AsReadOnly().ToList(); 370 for (int i = 0; i < col.Count; ++i) { 371 var values = col[i].Rows.First().Values; 372 for (int j = 0; j < values.Count; ++j) { 373 elements[j, i] = values[j]; 374 } 375 } 376 377 var heatmap = new HeatMap(elements); 378 if (!results.ContainsKey(successfulOffspringRatioHeatMapName)) { 379 results.Add(new Result(successfulOffspringRatioHeatMapName, heatmap)); 380 } else { 381 results[successfulOffspringRatioHeatMapName].Value = heatmap; 382 } 354 383 } 355 384 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs
r11253 r11257 95 95 if (Ranks.ContainsKey(node.Rank)) { 96 96 Ranks[node.Rank].Remove(node); 97 if (!Ranks[node.Rank].Any()) 98 Ranks.Remove(node.Rank); 97 99 } 98 100 base.RemoveVertex(vertex); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs
r11253 r11257 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 57 58 GenealogyGraph.AddVertex(c); 58 59 59 var arcs = v.InArcs ;60 var arcs = v.InArcs.ToList(); 60 61 foreach (var arc in arcs) { 61 62 var p = arc.Source;
Note: See TracChangeset
for help on using the changeset viewer.