Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/26/14 22:07:40 (10 years ago)
Author:
bburlacu
Message:

#1772: Small refactoring in the GenealogyGraph.

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs

    r11475 r11502  
    4545    protected GenealogyGraph(GenealogyGraph original, Cloner cloner)
    4646      : base(original, cloner) {
    47       Ranks = new Dictionary<double, List<IGenealogyGraphNode>>(original.Ranks);
    48       contentMap = new Dictionary<object, IGenealogyGraphNode>(original.contentMap);
    49       idMap = new Dictionary<string, IGenealogyGraphNode>(original.idMap);
     47      RebuildDictionaries();
    5048    }
    5149
     
    6159    [StorableHook(HookType.AfterDeserialization)]
    6260    private void AfterDeserialization() {
    63       contentMap = new Dictionary<object, IGenealogyGraphNode>();
    64       idMap = new Dictionary<string, IGenealogyGraphNode>();
    65       ranks = new Dictionary<double, List<IGenealogyGraphNode>>();
    66 
    67       foreach (var v in Vertices) {
    68         contentMap[v.Data] = v;
    69         idMap[v.Id] = v;
    70         if (ranks.ContainsKey(v.Rank)) {
    71           ranks[v.Rank].Add(v);
    72         } else {
    73           ranks[v.Rank] = new List<IGenealogyGraphNode> { v };
    74         }
    75       }
     61      RebuildDictionaries();
    7662    }
    7763
     
    151137    }
    152138
     139    private void RebuildDictionaries() {
     140      contentMap = new Dictionary<object, IGenealogyGraphNode>();
     141      idMap = new Dictionary<string, IGenealogyGraphNode>();
     142      ranks = new Dictionary<double, List<IGenealogyGraphNode>>();
     143
     144      foreach (var v in Vertices) {
     145        contentMap[v.Data] = v;
     146        idMap[v.Id] = v;
     147        if (ranks.ContainsKey(v.Rank)) {
     148          ranks[v.Rank].Add(v);
     149        } else {
     150          ranks[v.Rank] = new List<IGenealogyGraphNode> { v };
     151        }
     152      }
     153    }
     154
    153155    public void ExportDot(string path) {
    154156      var sb = new StringBuilder();
     
    157159        sb.AppendLine("\"" + v.Id + "\"[shape=circle, style = filled, width = " + v.Degree / 2.0 + ", label = " + v.Rank + ", fillcolor = \"" + ColorTranslator.ToHtml(GetColor(v)) + "\"]");
    158160      }
    159       foreach (var a in Arcs.Select(x => (IGenealogyGraphArc)x)) {
     161      foreach (var a in Arcs) {
    160162        sb.AppendLine("\"" + a.Source.Id + "\" -- \"" + a.Target.Id + "\"");
    161163      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphArc.cs

    r11233 r11502  
    5555    [StorableConstructor]
    5656    protected GenealogyGraphArc(bool deserializing) : base(deserializing) { }
    57     protected GenealogyGraphArc(GenealogyGraphArc<T> original, Cloner cloner)
     57    protected GenealogyGraphArc(GenealogyGraphArc original, Cloner cloner)
    5858      : base(original, cloner) {
    59       Data = original.Data;
    6059    }
    6160
Note: See TracChangeset for help on using the changeset viewer.