Changeset 11459 for branches/HeuristicLab.EvolutionTracking
- Timestamp:
- 10/13/14 13:14:25 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs
r11390 r11459 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 25 using System.IO; 24 26 using System.Linq; 27 using System.Text; 25 28 using HeuristicLab.Common; 26 29 using HeuristicLab.Core; … … 31 34 [Item("GenealogyGraph", "A class representing a genealogy graph")] 32 35 public class GenealogyGraph : DirectedGraph, IGenealogyGraph { 33 [Storable] 34 private readonly Dictionary<object, IGenealogyGraphNode> contentMap; 35 36 [Storable] 37 private readonly Dictionary<string, IGenealogyGraphNode> idMap; 38 39 [Storable] 36 private Dictionary<object, IGenealogyGraphNode> contentMap; 37 private Dictionary<string, IGenealogyGraphNode> idMap; 40 38 protected Dictionary<double, List<IGenealogyGraphNode>> ranks; 41 39 … … 59 57 protected GenealogyGraph(bool deserializing) 60 58 : base(deserializing) { 59 } 60 61 [StorableHook(HookType.AfterDeserialization)] 62 private void AfterDeserialization() { 63 contentMap = new Dictionary<object, IGenealogyGraphNode>(); 64 idMap = new Dictionary<string, IGenealogyGraphNode>(); 65 ranks = new Dictionary<double, List<IGenealogyGraphNode>>(); 66 67 foreach (var v in Vertices) { 68 contentMap[v.Data] = v; 69 idMap[v.Id] = v; 70 if (ranks.ContainsKey(v.Rank)) { 71 ranks[v.Rank].Add(v); 72 } else { 73 ranks[v.Rank] = new List<IGenealogyGraphNode> { v }; 74 } 75 } 61 76 } 62 77 … … 130 145 ranks.Clear(); 131 146 } 147 148 public void ExportDot(string path) { 149 var sb = new StringBuilder(); 150 sb.AppendLine("graph fragmentgraph {"); 151 foreach (var v in Vertices) { 152 sb.AppendLine("\"" + v.Id + "\"[shape=circle, style = filled, width = " + v.Degree / 2.0 + ", label = " + v.Rank + ", fillcolor = \"" + ColorTranslator.ToHtml(GetColor(v)) + "\"]"); 153 } 154 foreach (var a in Arcs.Select(x => (IGenealogyGraphArc)x)) { 155 sb.AppendLine("\"" + a.Source.Id + "\" -- \"" + a.Target.Id + "\""); 156 } 157 158 sb.AppendLine("}"); 159 File.WriteAllText(path, sb.ToString()); 160 } 161 162 private Color GetColor(IGenealogyGraphNode node) { 163 var colorIndex = (int)Math.Round(node.Quality * ColorGradient.Colors.Count); 164 if (colorIndex >= ColorGradient.Colors.Count) return ColorGradient.Colors.Last(); 165 return ColorGradient.Colors[colorIndex]; 166 } 132 167 } 133 168 134 [Item("GenealogyGraph", "A specialization of the genealogy graph with T as content for vertices")]169 [Item("GenealogyGraph", "A genealogy graph in which the vertex data is of type T")] 135 170 [StorableClass] 136 171 public class GenealogyGraph<T> : GenealogyGraph, IGenealogyGraph<T> where T : class, IItem { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphNode.cs
r11262 r11459 52 52 53 53 public new IEnumerable<IGenealogyGraphArc> InArcs { 54 get { return base.InArcs. Cast<IGenealogyGraphArc>(); }54 get { return base.InArcs.Select(x => (IGenealogyGraphArc)x); } 55 55 } 56 56 57 57 public new IEnumerable<IGenealogyGraphArc> OutArcs { 58 get { return base.OutArcs. Cast<IGenealogyGraphArc>(); }58 get { return base.OutArcs.Select(x => (IGenealogyGraphArc)x); } 59 59 } 60 60 … … 148 148 } 149 149 public new IEnumerable<IGenealogyGraphNode<T>> Parents { 150 get { return base.Parents. Cast<IGenealogyGraphNode<T>>(); }150 get { return base.Parents.Select(x => (IGenealogyGraphNode<T>)x); } 151 151 } 152 152 public new IEnumerable<IGenealogyGraphNode<T>> Children { 153 get { return base.Children. Cast<IGenealogyGraphNode<T>>(); }153 get { return base.Children.Select(x => (IGenealogyGraphNode<T>)x); } 154 154 } 155 155 public new IEnumerable<IGenealogyGraphNode<T>> Ancestors { 156 get { return base.Ancestors. Cast<IGenealogyGraphNode<T>>(); }156 get { return base.Ancestors.Select(x => (IGenealogyGraphNode<T>)x); } 157 157 } 158 158 public new IEnumerable<IGenealogyGraphNode<T>> Descendants { 159 get { return base.Descendants. Cast<IGenealogyGraphNode<T>>(); }159 get { return base.Descendants.Select(x => (IGenealogyGraphNode<T>)x); } 160 160 } 161 161 }
Note: See TracChangeset
for help on using the changeset viewer.