Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/SymbolGraph.cs @ 17578

Last change on this file since 17578 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.7 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.Encodings.SymbolicExpressionTreeEncoding;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.EvolutionTracking {
29  [Item("Symbol graph", "A graph used to store the relationship between symbols in a population of individuals")]
30  [StorableClass]
31  public class SymbolGraph : DirectedGraph {
32    [Storable]
33    private readonly Dictionary<string, SymbolNode> nodeMap = new Dictionary<string, SymbolNode>();
34
35    public void AddVertex(SymbolNode node) {
36      if (nodeMap.ContainsKey(node.Label)) return; // node already present? do nothing
37      nodeMap[node.Label] = node;
38      base.AddVertex(node);
39    }
40
41    public bool ContainsKey(string key) {
42      return nodeMap.ContainsKey(key);
43    }
44
45    public SymbolNode GetNode(string key) {
46      SymbolNode node;
47      nodeMap.TryGetValue(key, out node);
48      return node;
49    }
50
51    void AddArc(SymbolNode source, SymbolNode target, double weight, object data = null) {
52      source.AddForwardArc(target, weight, data);
53    }
54  }
55
56  [StorableClass]
57  public class SymbolNode : Vertex {
58    public ISymbol Symbol { get; set; }
59    public Dictionary<int, int> Positions { get; set; }
60    public double AverageArity { get; set; }
61
62    public new List<SymbolArc> InArcs {
63      get { return base.InArcs == null ? null : base.InArcs.Cast<SymbolArc>().ToList(); }
64    }
65
66    public new List<SymbolArc> OutArcs {
67      get { return base.OutArcs == null ? null : base.OutArcs.Cast<SymbolArc>().ToList(); }
68    }
69
70    public SymbolNode() {
71    }
72  }
73
74  public class SymbolArc : IArc {
75    public IVertex Source { get; set; }
76    public IVertex Target { get; set; }
77    public double Weight { get; set; }
78
79    public object Data { get; set; }
80  }
81}
Note: See TracBrowser for help on using the repository browser.