Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/FPGraph.cs

Last change on this file was 10300, checked in by bburlacu, 11 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.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Core;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26
27namespace HeuristicLab.EvolutionTracking {
28  [Item("Symbol graph", "A graph used to store the relationship between symbols in a population of individuals")]
29  [StorableClass]
30  public class FPGraph : DirectedGraph {
31    [Storable]
32    public Dictionary<int, List<SymbolNode>> Levels { get { return levels; } }
33    private Dictionary<int, List<SymbolNode>> levels = new Dictionary<int, List<SymbolNode>>();
34
35    public void AddNode(SymbolNode node, int level) {
36      if (levels.ContainsKey(level)) {
37        SymbolNode match = levels[level].Find(n => n.Label.Equals(node.Label));
38        if (match == null) {
39          levels[level].Add(node);
40        }
41      } else {
42        levels[level] = new List<SymbolNode> { node };
43      }
44      base.AddVertex(node);
45    }
46
47    public bool ContainsKey(string key, int level) {
48      return levels.ContainsKey(level) && levels[level].Select(n => n.Label).Contains(key);
49    }
50
51    public SymbolNode GetNode(string key, int level) {
52      SymbolNode node = null;
53      if (levels.ContainsKey(level))
54        node = levels[level].Find(n => n.Label.Equals(key));
55      return node;
56    }
57
58    void AddArc(SymbolNode source, SymbolNode target, double weight, object data = null) {
59      source.AddForwardArc(target, weight, data);
60    }
61  }
62}
Note: See TracBrowser for help on using the repository browser.