#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Collections.Generic; using System.Linq; using HeuristicLab.Core; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.EvolutionTracking; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.DataAnalysis.Symbolic { [Item("Symbol graph", "A graph used to store the relationship between symbols in a population of individuals")] [StorableClass] public class SymbolGraph : DirectedGraph { [Storable] private readonly Dictionary nodeMap = new Dictionary(); public void AddVertex(SymbolNode node) { if (nodeMap.ContainsKey(node.Label)) return; // node already present? do nothing nodeMap[node.Label] = node; base.AddVertex(node); } public bool ContainsKey(string key) { return nodeMap.ContainsKey(key); } public SymbolNode GetNode(string key) { SymbolNode node; nodeMap.TryGetValue(key, out node); return node; } } [StorableClass] public class SymbolNode : Vertex { public ISymbol Symbol { get; set; } public Dictionary Positions { get; set; } public double AverageArity { get; set; } public new List InArcs { get { return base.InArcs == null ? null : base.InArcs.Cast().ToList(); } } public new List OutArcs { get { return base.OutArcs == null ? null : base.OutArcs.Cast().ToList(); } } public SymbolNode() { } } public class SymbolArc : IArc { public IVertex Source { get; set; } public IVertex Target { get; set; } public double Weight { get; set; } public object Data { get; set; } } }