Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/30/14 01:41:54 (10 years ago)
Author:
bburlacu
Message:

#1772: Worked towards integrating the new graph api with the tracking operators.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs

    r11227 r11233  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Linq;
    2324using HeuristicLab.Analysis;
     
    268269        #region add elite in the graph and connect it with the previous elite
    269270        if (elite != null) {
    270           var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.GetVertex(elite);
     271          var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.GetByContent(elite);
    271272          prevVertex.IsElite = true; // mark elites in the graph retroactively
    272273
    273274          var clone = (T)elite.Clone();
    274275
    275           var vertex = new GenealogyGraphNode<T>(prevVertex.Content) {
     276          var v = new GenealogyGraphNode<T>(prevVertex.Content) {
    276277            Rank = generation,
    277278            Quality = prevVertex.Quality,
     
    279280          };
    280281
    281           prevVertex.Content = clone;
     282          var w = new GenealogyGraphNode<T>(clone) {
     283            Rank = generation - 1,
     284            Quality = prevVertex.Quality,
     285            IsElite = true
     286          };
     287
     288          // replace previous elite with vertex w
     289          List<IGenealogyGraphNode<T>> parents = null;
     290          object data = null;
     291          if (prevVertex.InArcs.Any()) {
     292            data = prevVertex.InArcs.Last().Data;
     293            parents = prevVertex.InArcs.Select(x => (IGenealogyGraphNode<T>)x.Source).ToList();
     294            //            v.InArcs.Last().Data = prevVertex.InArcs.Last().Data; // save the fragment in case there is one
     295            //            var p = prevVertex.InArcs.First().Source;
     296            //            GenealogyGraph.AddArc(p, w);
     297          }
     298          GenealogyGraph.RemoveVertex(prevVertex);
     299          GenealogyGraph.AddVertex(w);
     300          GenealogyGraph.AddVertex(v);
     301          GenealogyGraph.AddArc(w, v); // connect current elite with previous elite
     302
     303          v.InArcs.Last().Data = data;
     304          if (parents != null) {
     305            foreach (var p in parents)
     306              GenealogyGraph.AddArc(p, w);
     307          }
     308
    282309          // inject the graph node unique id to the scope
    283           ExecutionContext.Scope.SubScopes[index].Variables["Id"].Value = new StringValue(vertex.Id);
    284           GenealogyGraph.AddVertex(vertex);
    285           GenealogyGraph.AddArc(prevVertex, vertex); // connect current elite with previous elite
    286 
    287           if (prevVertex.InArcs.Any()) {
    288             vertex.InArcs.Last().Data = prevVertex.InArcs.Last().Data; // save the fragment in case there is one
    289           }
     310          ExecutionContext.Scope.SubScopes[index].Variables["Id"].Value = new StringValue(v.Id);
    290311        }
    291312        #endregion
     
    295316      // update qualities
    296317      for (int i = 0; i < population.Length; ++i) {
    297         var vertex = (IGenealogyGraphNode)GenealogyGraph.GetVertex(population[i]);
     318        var vertex = (IGenealogyGraphNode)GenealogyGraph.GetByContent(population[i]);
    298319        vertex.Quality = qualities[i].Value;
    299320      }
     
    301322      // remove extra graph nodes (added by the instrumented operators in the case of offspring selection)
    302323      var discardedOffspring = GenealogyGraph.Ranks[generation].Select(x => (T)x.Content).Except(population).ToList();
    303       foreach (var vertex in discardedOffspring.Select(individual => GenealogyGraph.GetVertex(individual))) {
     324      foreach (var vertex in discardedOffspring.Select(individual => GenealogyGraph.GetByContent(individual))) {
    304325        GenealogyGraph.RemoveVertex(vertex);
    305326      }
     
    313334      // compute the weight of each genealogy graph node as the ratio (produced offspring) / (surviving offspring)
    314335      foreach (var ind in population) {
    315         var v = (IGenealogyGraphNode)GenealogyGraph.GetVertex(ind);
     336        var v = (IGenealogyGraphNode)GenealogyGraph.GetByContent(ind);
    316337        foreach (var p in v.Parents)
    317338          p.Weight++;
Note: See TracChangeset for help on using the changeset viewer.