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