Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs @ 10300

Last change on this file since 10300 was 10300, checked in by bburlacu, 10 years ago

#1772: Cleaned up the design of the generic genealogy analyzer and related classes, created generic genealogy graph view. Added instrumentation code to TravelingSalesmapProblem.cs allowing genealogy tracking. Merged trunk changes (instrumentation for multi operators).

File size: 2.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.EvolutionTracking {
30  [StorableClass]
31  [Item("GenealogyGraph", "")]
32  public class GenealogyGraph : DirectedGraph, IGenealogyGraph {
33    [Storable]
34    private Dictionary<double, LinkedList<IGenealogyGraphNode>> ranks; // use a linked list for fast insertion/removal
35    public Dictionary<double, LinkedList<IGenealogyGraphNode>> Ranks {
36      get { return ranks; }
37      set { ranks = value; }
38    }
39    protected GenealogyGraph(GenealogyGraph original, Cloner cloner)
40      : base(original, cloner) {
41    }
42    public override IDeepCloneable Clone(Cloner cloner) {
43      return new GenealogyGraph(this, cloner);
44    }
45    [StorableConstructor]
46    protected GenealogyGraph(bool deserializing) : base(deserializing) { }
47    public GenealogyGraph() {
48      Ranks = new Dictionary<double, LinkedList<IGenealogyGraphNode>>();
49    }
50    public override void AddVertex(IVertex vertex) {
51      var ggn = (IGenealogyGraphNode)vertex;
52      if (!Ranks.ContainsKey(ggn.Rank))
53        Ranks[ggn.Rank] = new LinkedList<IGenealogyGraphNode>();
54      Ranks[ggn.Rank].AddLast(ggn);
55      base.AddVertex(vertex);
56    }
57    public override void RemoveVertex(IVertex vertex) {
58      var ggn = (IGenealogyGraphNode)vertex;
59      if (Ranks.ContainsKey(ggn.Rank)) {
60        Ranks[ggn.Rank].Remove(ggn);
61      }
62      base.RemoveVertex(vertex);
63    }
64    public event EventHandler GraphUpdated;
65    private void OnGraphUpdated(object sender, EventArgs args) {
66      var updated = GraphUpdated;
67      if (updated != null) updated(sender, args);
68    }
69
70    public new List<IGenealogyGraphNode> this[object content] {
71      get {
72        var result = base[content];
73        return result != null ? result.Cast<IGenealogyGraphNode>().ToList() : null;
74      }
75    }
76  }
77
78}
Note: See TracBrowser for help on using the repository browser.