Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11257 for branches


Ignore:
Timestamp:
08/02/14 20:25:20 (10 years ago)
Author:
bburlacu
Message:

#1772:

  • GenealogyAnalyzer: compute relative success ratios per individual and save them in a DataTableHistory chart and as a heat map
  • GenealogyGraph: remove rank if it contains no vertices
  • BeforeManipulatorOperator: avoid "collection was modified" exception
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  
    260260        T elite = null;
    261261
    262         int psum1 = GenealogyGraph.Ranks[generation].Sum(x => x.Parents.Count());
    263 
    264262        for (int i = 0; i < population.Length; ++i) {
    265263          if (GenealogyGraph.GetByContent(population[i]).Rank.Equals(generation - 1)) {
     
    305303        }
    306304        #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 one
    310           throw new InvalidOperationException("Parent sum should remain the same.");
    311305
    312306        ComputeSuccessRatios();
     
    319313
    320314      // 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);
    322324      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        }
    323331        GenealogyGraph.RemoveVertex(vertex);
    324332      }
    325 
    326       return base.Apply();
    327333    }
    328334
    329335    private void ComputeSuccessRatios() {
     336      const string successfulOffspringRatioTableHistoryName = "Successful offspring ratio";
     337      const string successfulOffspringRatioHeatMapName = "Successful offspring ratio heatmap";
     338
    330339      var population = PopulationParameter.ActualValue;
    331340      var generation = GenerationsParameter.ActualValue.Value;
     
    342351
    343352      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));
    349358      } 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      };
    353365      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      }
    354383    }
    355384  }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs

    r11253 r11257  
    9595      if (Ranks.ContainsKey(node.Rank)) {
    9696        Ranks[node.Rank].Remove(node);
     97        if (!Ranks[node.Rank].Any())
     98          Ranks.Remove(node.Rank);
    9799      }
    98100      base.RemoveVertex(vertex);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs

    r11253 r11257  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    5758      GenealogyGraph.AddVertex(c);
    5859
    59       var arcs = v.InArcs;
     60      var arcs = v.InArcs.ToList();
    6061      foreach (var arc in arcs) {
    6162        var p = arc.Source;
Note: See TracChangeset for help on using the changeset viewer.