- Timestamp:
- 03/28/14 16:23:40 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r10675 r10677 230 230 previousVertex.AddForwardArc(vertex); 231 231 vertex.AddReverseArc(previousVertex); 232 vertex.InArcs.Last().Data = previousVertex.InArcs.Last().Data; // save the fragment in case there is one 233 vertex.Id = previousVertex.Id; 232 vertex.Id = previousVertex.Id; // another way would be to introduce the vertex.Id into the scope of the elite 233 if (previousVertex.InArcs.Any()) { 234 vertex.InArcs.Last().Data = previousVertex.InArcs.Last().Data; // save the fragment in case there is one 235 } 234 236 } 235 237 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/DirectedGraph.cs
r10300 r10677 77 77 public virtual void Clear() { 78 78 nodes.Clear(); 79 contentMap.Clear(); 79 80 } 80 81 public virtual void AddVertex(IVertex vertex) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IVertex.cs
r10650 r10677 26 26 public interface IVertex : IItem { 27 27 string Id { get; } 28 List<IArc> InArcs { get; }29 List<IArc> OutArcs { get; }28 IEnumerable<IArc> InArcs { get; set; } 29 IEnumerable<IArc> OutArcs { get; set; } 30 30 31 31 int InDegree { get; } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Vertex.cs
r10300 r10677 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 43 44 [Storable] 44 45 private List<IArc> inArcs; 45 public List<IArc> InArcs { get { return inArcs; } protected set { inArcs = value; } } 46 public IEnumerable<IArc> InArcs { 47 get { return inArcs ?? Enumerable.Empty<IArc>(); } 48 set { inArcs = value.ToList(); } 49 } 46 50 [Storable] 47 51 private List<IArc> outArcs; 48 public List<IArc> OutArcs { get { return outArcs; } protected set { outArcs = value; } } 52 public IEnumerable<IArc> OutArcs { 53 get { return outArcs ?? Enumerable.Empty<IArc>(); } 54 set { outArcs = value.ToList(); } 55 } 49 56 50 57 [StorableConstructor] … … 61 68 Id = Guid.NewGuid().ToString(); 62 69 Label = original.Label; 63 InArcs = new List<IArc>(original.InArcs);64 OutArcs = new List<IArc>(original.OutArcs);70 inArcs = new List<IArc>(original.InArcs); 71 outArcs = new List<IArc>(original.OutArcs); 65 72 } 66 73 … … 81 88 public void AddForwardArc(IVertex target, double w = 0.0, object data = null) { 82 89 var arc = new Arc { Source = this, Target = target, Data = data, Weight = w }; 83 if ( OutArcs == null) OutArcs = new List<IArc> { arc };84 else OutArcs.Add(arc);90 if (outArcs == null) outArcs = new List<IArc> { arc }; 91 else outArcs.Add(arc); 85 92 } 86 93 public void AddForwardArc(IArc arc) { 87 94 if (arc.Source == null) { arc.Source = this; } 88 95 if (arc.Source != this) { throw new Exception("AddForwardArc: Source should be equal to this."); } 89 if (OutArcs == null) { OutArcs = new List<IArc> { arc }; } else { OutArcs.Add(arc); } 96 if (outArcs == null) { outArcs = new List<IArc> { arc }; } else { outArcs.Add(arc); } 97 } 98 public void AddReverseArc(IVertex source, double w = 0.0, object data = null) { 99 var arc = new Arc { Source = source, Target = this, Data = data, Weight = w }; 100 if (inArcs == null) inArcs = new List<IArc> { arc }; 101 else inArcs.Add(arc); 90 102 } 91 103 public void AddReverseArc(IArc arc) { 92 104 if (arc.Target == null) { arc.Target = this; } 93 105 if (arc.Target != this) { throw new Exception("AddReverseArc: Target should be equal to this."); }; 94 if (InArcs == null) { InArcs = new List<IArc> { arc }; } else { InArcs.Add(arc); } 95 } 96 public void AddReverseArc(IVertex source, double w = 0.0, object data = null) { 97 var arc = new Arc { Source = source, Target = this, Data = data, Weight = w }; 98 if (InArcs == null) InArcs = new List<IArc> { arc }; 99 else InArcs.Add(arc); 106 if (inArcs == null) { inArcs = new List<IArc> { arc }; } else { inArcs.Add(arc); } 100 107 } 101 108 102 public int InDegree { get { return InArcs == null ? 0 : InArcs.Count; } }103 public int OutDegree { get { return OutArcs == null ? 0 : OutArcs.Count; } }109 public int InDegree { get { return InArcs.Count(); } } 110 public int OutDegree { get { return OutArcs.Count(); } } 104 111 public int Degree { get { return InDegree + OutDegree; } } 105 112 } 106 107 113 108 114 [StorableClass] -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs
r10650 r10677 37 37 set { ranks = value; } 38 38 } 39 public new IEnumerable<IGenealogyGraphNode> Nodes { 40 get { return from n in base.Nodes select (IGenealogyGraphNode)n; } 41 } 39 42 protected GenealogyGraph(GenealogyGraph original, Cloner cloner) 40 43 : base(original, cloner) { … … 74 77 } 75 78 } 79 80 public override void Clear() { 81 base.Clear(); 82 ranks.Clear(); 83 } 76 84 } 77 85 … … 79 87 [Item("GenealogyGraph", "")] 80 88 public class GenealogyGraph<T> : DirectedGraph, IGenealogyGraph<T> where T : class, IItem { 89 // members and properties 81 90 [Storable] 82 91 private Dictionary<double, LinkedList<IGenealogyGraphNode>> ranks; … … 85 94 set { ranks = value; } 86 95 } 96 public new IEnumerable<IGenealogyGraphNode<T>> Nodes { 97 get { return from n in base.Nodes select (IGenealogyGraphNode<T>)n; } 98 } 99 // contructors 87 100 protected GenealogyGraph(GenealogyGraph<T> original, Cloner cloner) 88 101 : base(original, cloner) { … … 96 109 Ranks = new Dictionary<double, LinkedList<IGenealogyGraphNode>>(); 97 110 } 111 // methods 98 112 public override void AddVertex(IVertex vertex) { 99 113 var node = (IGenealogyGraphNode<T>)vertex; … … 110 124 base.RemoveVertex(vertex); 111 125 } 126 127 IEnumerable<IGenealogyGraphNode> IGenealogyGraph.Nodes { 128 get { return Nodes; } 129 } 130 112 131 public event EventHandler GraphUpdated; 113 132 private void OnGraphUpdated(object sender, EventArgs args) { … … 115 134 if (updated != null) updated(sender, args); 116 135 } 117 118 136 public new List<IGenealogyGraphNode<T>> this[object content] { 119 137 get { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphNode.cs
r10300 r10677 41 41 public GenealogyGraphNode() { } 42 42 43 public new List<IGenealogyGraphArc> InArcs {43 public new IEnumerable<IGenealogyGraphArc> InArcs { 44 44 get { 45 return base.InArcs == null ? null : base.InArcs.Cast<IGenealogyGraphArc>().ToList();45 return base.InArcs.Cast<IGenealogyGraphArc>().ToList(); 46 46 } 47 set { base.InArcs = value; } 47 48 } 48 public new List<IGenealogyGraphArc> OutArcs {49 public new IEnumerable<IGenealogyGraphArc> OutArcs { 49 50 get { 50 return base.OutArcs == null ? null : base.OutArcs.Cast<IGenealogyGraphArc>().ToList();51 return base.OutArcs.Cast<IGenealogyGraphArc>().ToList(); 51 52 } 53 set { base.InArcs = value; } 52 54 } 53 public IEnumerable<IGenealogyGraphNode> Ancestors (){54 // for performance, we use a hashset for lookup and a list for iteration55 var nodes = new HashSet<IGenealogyGraphNode> { this };56 var list = new List<IGenealogyGraphNode> { this };57 int i = 0;58 while (i != list.Count) {59 if (list[i].InArcs != null) {55 public IEnumerable<IGenealogyGraphNode> Ancestors { 56 get { 57 // for performance, we use a hashset for lookup and a list for iteration 58 var nodes = new HashSet<IGenealogyGraphNode> { this }; 59 var list = new List<IGenealogyGraphNode> { this }; 60 int i = 0; 61 while (i != list.Count) { 60 62 foreach (var e in list[i].InArcs) { 61 63 if (nodes.Contains(e.Source)) continue; … … 63 65 list.Add(e.Source); 64 66 } 67 ++i; 65 68 } 66 ++i;69 return list; 67 70 } 68 return list;69 71 } 70 72 /// <summary> … … 72 74 /// </summary> 73 75 /// <returns>All the descendants of the current node</returns> 74 public IEnumerable<IGenealogyGraphNode> Descendants (){75 var nodes = new HashSet<IGenealogyGraphNode> { this };76 var list = new List<IGenealogyGraphNode> { this };77 int i = 0;78 while (i != list.Count) {79 if (list[i].OutArcs != null) {76 public IEnumerable<IGenealogyGraphNode> Descendants { 77 get { 78 var nodes = new HashSet<IGenealogyGraphNode> { this }; 79 var list = new List<IGenealogyGraphNode> { this }; 80 int i = 0; 81 while (i != list.Count) { 80 82 foreach (var e in list[i].OutArcs) { 81 83 if (nodes.Contains(e.Target)) continue; … … 83 85 list.Add(e.Target); 84 86 } 87 ++i; 85 88 } 86 ++i;89 return list; 87 90 } 88 return list;89 91 } 90 92 [Storable] … … 118 120 base.AddReverseArc(arc); 119 121 } 122 123 public IEnumerable<IGenealogyGraphNode> Parents { 124 get { 125 return InArcs == null ? Enumerable.Empty<IGenealogyGraphNode>() : InArcs.Select(a => a.Source); 126 } 127 } 128 129 public IEnumerable<IGenealogyGraphNode> Children { 130 get { return OutArcs == null ? Enumerable.Empty<IGenealogyGraphNode>() : OutArcs.Select(a => a.Source); } 131 } 120 132 } 121 133 … … 135 147 return new GenealogyGraphNode<T>(this, cloner); 136 148 } 149 150 public new IEnumerable<IGenealogyGraphNode<T>> Parents { 151 get { 152 return base.Parents.Select(p => (IGenealogyGraphNode<T>)p); 153 } 154 } 155 156 public new IEnumerable<IGenealogyGraphNode<T>> Children { 157 get { 158 return base.Children.Select(c => (IGenealogyGraphNode<T>)c); 159 } 160 } 161 162 public new IEnumerable<IGenealogyGraphNode<T>> Ancestors { 163 get { return base.Ancestors.Select(x => (IGenealogyGraphNode<T>)x); } 164 } 165 166 public new IEnumerable<IGenealogyGraphNode<T>> Descendants { 167 get { return base.Descendants.Select(x => (IGenealogyGraphNode<T>)x); } 168 } 137 169 } 138 170 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraph.cs
r10650 r10677 26 26 public interface IGenealogyGraph : IDirectedGraph { 27 27 Dictionary<double, LinkedList<IGenealogyGraphNode>> Ranks { get; } 28 new IEnumerable<IGenealogyGraphNode> Nodes { get; } 28 29 } 29 30 30 public interface IGenealogyGraph<T> : IGenealogyGraph where T : class,IItem { } 31 public interface IGenealogyGraph<T> : IGenealogyGraph where T : class, IItem { 32 new IEnumerable<IGenealogyGraphNode<T>> Nodes { get; } 33 } 31 34 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraphNode.cs
r10650 r10677 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Core;25 24 26 25 namespace HeuristicLab.EvolutionTracking { 27 26 public interface IGenealogyGraphNode : IVertex, IComparable<IGenealogyGraphNode> { 28 IEnumerable<IGenealogyGraphNode> Ancestors();29 IEnumerable<IGenealogyGraphNode> Descendants();30 new List<IGenealogyGraphArc> InArcs { get; }31 new List<IGenealogyGraphArc> OutArcs { get; }32 33 27 double Rank { get; set; } 34 28 double Quality { get; set; } 35 29 bool IsElite { get; set; } 30 31 IEnumerable<IGenealogyGraphNode> Parents { get; } 32 IEnumerable<IGenealogyGraphNode> Children { get; } 33 IEnumerable<IGenealogyGraphNode> Ancestors { get; } 34 IEnumerable<IGenealogyGraphNode> Descendants { get; } 35 new IEnumerable<IGenealogyGraphArc> InArcs { get; set; } 36 new IEnumerable<IGenealogyGraphArc> OutArcs { get; set; } 36 37 } 37 38 38 public interface IGenealogyGraphNode<T> : IGenealogyGraphNode, IVertex<T> where T : class { } 39 public interface IGenealogyGraphNode<T> : IGenealogyGraphNode, IVertex<T> where T : class { 40 new IEnumerable<IGenealogyGraphNode<T>> Parents { get; } 41 new IEnumerable<IGenealogyGraphNode<T>> Children { get; } 42 43 new IEnumerable<IGenealogyGraphNode<T>> Ancestors { get; } 44 new IEnumerable<IGenealogyGraphNode<T>> Descendants { get; } 45 } 39 46 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs
r10650 r10677 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Linq; 23 24 using HeuristicLab.Common; … … 55 56 // adjust parent-child(clone) relationship in the graph 56 57 var parents = vChild.InArcs.Select(a => a.Source); 57 vChild.InArcs .Clear();58 vChild.InArcs = new List<IGenealogyGraphArc>(); 58 59 foreach (var p in parents) { 59 60 foreach (var a in p.OutArcs) {
Note: See TracChangeset
for help on using the changeset viewer.