#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.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.EvolutionTracking { [Item("Symbol graph", "A graph used to store the relationship between symbols in a population of individuals")] [StorableClass] public class FPGraph : DirectedGraph { [Storable] public Dictionary> Levels { get { return levels; } } private Dictionary> levels = new Dictionary>(); public void AddNode(SymbolNode node, int level) { if (levels.ContainsKey(level)) { SymbolNode match = levels[level].Find(n => n.Label.Equals(node.Label)); if (match == null) { levels[level].Add(node); } } else { levels[level] = new List { node }; } base.AddVertex(node); } public bool ContainsKey(string key, int level) { return levels.ContainsKey(level) && levels[level].Select(n => n.Label).Contains(key); } public SymbolNode GetNode(string key, int level) { SymbolNode node = null; if (levels.ContainsKey(level)) node = levels[level].Find(n => n.Label.Equals(key)); return node; } void AddArc(SymbolNode source, SymbolNode target, double weight, object data = null) { source.AddForwardArc(target, weight, data); } } }