Changeset 11233
- Timestamp:
- 07/30/14 01:41:54 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 23 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r11227 r11233 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Linq; 23 24 using HeuristicLab.Analysis; … … 268 269 #region add elite in the graph and connect it with the previous elite 269 270 if (elite != null) { 270 var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.Get Vertex(elite);271 var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.GetByContent(elite); 271 272 prevVertex.IsElite = true; // mark elites in the graph retroactively 272 273 273 274 var clone = (T)elite.Clone(); 274 275 275 var v ertex= new GenealogyGraphNode<T>(prevVertex.Content) {276 var v = new GenealogyGraphNode<T>(prevVertex.Content) { 276 277 Rank = generation, 277 278 Quality = prevVertex.Quality, … … 279 280 }; 280 281 281 prevVertex.Content = clone; 282 var w = new GenealogyGraphNode<T>(clone) { 283 Rank = generation - 1, 284 Quality = prevVertex.Quality, 285 IsElite = true 286 }; 287 288 // replace previous elite with vertex w 289 List<IGenealogyGraphNode<T>> parents = null; 290 object data = null; 291 if (prevVertex.InArcs.Any()) { 292 data = prevVertex.InArcs.Last().Data; 293 parents = prevVertex.InArcs.Select(x => (IGenealogyGraphNode<T>)x.Source).ToList(); 294 // v.InArcs.Last().Data = prevVertex.InArcs.Last().Data; // save the fragment in case there is one 295 // var p = prevVertex.InArcs.First().Source; 296 // GenealogyGraph.AddArc(p, w); 297 } 298 GenealogyGraph.RemoveVertex(prevVertex); 299 GenealogyGraph.AddVertex(w); 300 GenealogyGraph.AddVertex(v); 301 GenealogyGraph.AddArc(w, v); // connect current elite with previous elite 302 303 v.InArcs.Last().Data = data; 304 if (parents != null) { 305 foreach (var p in parents) 306 GenealogyGraph.AddArc(p, w); 307 } 308 282 309 // inject the graph node unique id to the scope 283 ExecutionContext.Scope.SubScopes[index].Variables["Id"].Value = new StringValue(vertex.Id); 284 GenealogyGraph.AddVertex(vertex); 285 GenealogyGraph.AddArc(prevVertex, vertex); // connect current elite with previous elite 286 287 if (prevVertex.InArcs.Any()) { 288 vertex.InArcs.Last().Data = prevVertex.InArcs.Last().Data; // save the fragment in case there is one 289 } 310 ExecutionContext.Scope.SubScopes[index].Variables["Id"].Value = new StringValue(v.Id); 290 311 } 291 312 #endregion … … 295 316 // update qualities 296 317 for (int i = 0; i < population.Length; ++i) { 297 var vertex = (IGenealogyGraphNode)GenealogyGraph.Get Vertex(population[i]);318 var vertex = (IGenealogyGraphNode)GenealogyGraph.GetByContent(population[i]); 298 319 vertex.Quality = qualities[i].Value; 299 320 } … … 301 322 // remove extra graph nodes (added by the instrumented operators in the case of offspring selection) 302 323 var discardedOffspring = GenealogyGraph.Ranks[generation].Select(x => (T)x.Content).Except(population).ToList(); 303 foreach (var vertex in discardedOffspring.Select(individual => GenealogyGraph.Get Vertex(individual))) {324 foreach (var vertex in discardedOffspring.Select(individual => GenealogyGraph.GetByContent(individual))) { 304 325 GenealogyGraph.RemoveVertex(vertex); 305 326 } … … 313 334 // compute the weight of each genealogy graph node as the ratio (produced offspring) / (surviving offspring) 314 335 foreach (var ind in population) { 315 var v = (IGenealogyGraphNode)GenealogyGraph.Get Vertex(ind);336 var v = (IGenealogyGraphNode)GenealogyGraph.GetByContent(ind); 316 337 foreach (var p in v.Parents) 317 338 p.Weight++; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Arc.cs
r11229 r11233 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 27 namespace HeuristicLab. Problems.DataAnalysis.Symbolic{27 namespace HeuristicLab.EvolutionTracking { 28 28 /// <summary> 29 29 /// An arc that can have a weight, a label, and a data object for holding additional info -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/DirectedGraph.cs
r11229 r11233 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 29 30 namespace HeuristicLab. Problems.DataAnalysis.Symbolic{30 namespace HeuristicLab.EvolutionTracking { 31 31 [Item("DirectedGraph", "Generic class representing a directed graph with custom vertices and content")] 32 32 [StorableClass] … … 94 94 vertex.ArcAdded += OnArcAdded; 95 95 vertex.ArcRemoved += OnArcRemoved; 96 OnVertexAdded(this, EventArgs.Empty);97 96 } 98 97 … … 106 105 vertex.ArcRemoved -= OnArcRemoved; 107 106 vertex.Changed -= OnVertexChanged; 108 OnVertexRemoved(this, EventArgs.Empty);109 107 } 110 108 111 public IArc AddArc(IVertex source, IVertex target) {109 public virtual IArc AddArc(IVertex source, IVertex target) { 112 110 var arc = new Arc(source, target); 113 111 AddArc(arc); … … 131 129 } 132 130 133 public event EventHandler VertexAdded;134 protected virtual void OnVertexAdded(object sender, EventArgs args) {135 var added = VertexAdded;136 if (added != null)137 added(sender, args);138 }139 131 140 public event EventHandler VertexChanged; 141 protected virtual void OnVertexChanged(object sender, EventArgs args) { 142 var changed = VertexChanged; 143 if (changed != null) 144 changed(sender, args); 145 } 146 147 public event EventHandler VertexRemoved; 148 protected virtual void OnVertexRemoved(object sender, EventArgs args) { 149 var removed = VertexRemoved; 150 if (removed != null) 151 removed(sender, args); 152 } 132 protected virtual void OnVertexChanged(object sender, EventArgs args) { } 153 133 154 134 protected virtual void OnArcAdded(object sender, EventArgs<IArc> args) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IArc.cs
r11229 r11233 23 23 using HeuristicLab.Core; 24 24 25 namespace HeuristicLab. Problems.DataAnalysis.Symbolic{25 namespace HeuristicLab.EvolutionTracking { 26 26 public interface IArc : IItem { 27 27 event EventHandler Changed; // generic event for when the label, weight or data were changed -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IDirectedGraph.cs
r11229 r11233 23 23 using HeuristicLab.Core; 24 24 25 namespace HeuristicLab. Problems.DataAnalysis.Symbolic{25 namespace HeuristicLab.EvolutionTracking { 26 26 public interface IDirectedGraph : IItem { 27 27 void Clear(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IVertex.cs
r11229 r11233 25 25 using HeuristicLab.Core; 26 26 27 namespace HeuristicLab. Problems.DataAnalysis.Symbolic{27 namespace HeuristicLab.EvolutionTracking { 28 28 public interface IVertex : IItem { 29 29 event EventHandler Changed; // generic event for when the content, label or weight have changed -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Vertex.cs
r11229 r11233 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab. Problems.DataAnalysis.Symbolic{29 namespace HeuristicLab.EvolutionTracking { 30 30 [StorableClass] 31 31 public class Vertex : Item, IVertex { … … 126 126 if (outArcs == null) 127 127 outArcs = new List<IArc>(); 128 else if (outArcs.Contains(arc) || outArcs.Any(a => a.Target == arc.Target && a.Source == arc.Source))128 else if (outArcs.Contains(arc) || outArcs.Any(a => a.Target == arc.Target)) 129 129 throw new InvalidOperationException("Arc already added."); 130 130 outArcs.Add(arc); … … 132 132 if (inArcs == null) 133 133 inArcs = new List<IArc>(); 134 else if (inArcs.Contains(arc) || inArcs.Any(a => a. Target == arc.Target && a.Source == arc.Source))134 else if (inArcs.Contains(arc) || inArcs.Any(a => a.Source == arc.Source)) 135 135 throw new InvalidOperationException("Arc already added."); 136 136 inArcs.Add(arc); … … 175 175 } 176 176 177 public Vertex(object content) : base(content) { } 178 177 179 [StorableConstructor] 178 180 protected Vertex(bool deserializing) : base(deserializing) { } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs
r10903 r11233 32 32 public class GenealogyGraph : DirectedGraph, IGenealogyGraph { 33 33 [Storable] 34 private readonly Dictionary<object, IGenealogyGraphNode> contentMap; 35 36 [Storable] 37 private readonly Dictionary<string, IGenealogyGraphNode> idMap; 38 39 [Storable] 34 40 private Dictionary<double, List<IGenealogyGraphNode>> ranks; // use a linked list for fast insertion/removal 35 41 public Dictionary<double, List<IGenealogyGraphNode>> Ranks { … … 37 43 set { ranks = value; } 38 44 } 39 public new IEnumerable<IGenealogyGraphNode> Vertices {40 get { return from n in base.Vertices select (IGenealogyGraphNode)n; }41 }42 45 43 46 protected GenealogyGraph(GenealogyGraph original, Cloner cloner) 44 47 : base(original, cloner) { 45 48 Ranks = new Dictionary<double, List<IGenealogyGraphNode>>(original.Ranks); 46 } 49 contentMap = new Dictionary<object, IGenealogyGraphNode>(original.contentMap); 50 idMap = new Dictionary<string, IGenealogyGraphNode>(original.idMap); 51 } 52 47 53 public override IDeepCloneable Clone(Cloner cloner) { 48 54 return new GenealogyGraph(this, cloner); 49 55 } 56 50 57 [StorableConstructor] 51 58 protected GenealogyGraph(bool deserializing) : base(deserializing) { } 52 59 public GenealogyGraph() { 53 60 Ranks = new Dictionary<double, List<IGenealogyGraphNode>>(); 61 contentMap = new Dictionary<object, IGenealogyGraphNode>(); 62 idMap = new Dictionary<string, IGenealogyGraphNode>(); 63 } 64 65 public new IEnumerable<IGenealogyGraphNode> Vertices { 66 get { return from n in base.Vertices select (IGenealogyGraphNode)n; } 54 67 } 55 68 56 69 public override IArc AddArc(IVertex source, IVertex target) { 57 70 var arc = new GenealogyGraphArc((IGenealogyGraphNode)source, (IGenealogyGraphNode)target); 58 source.Add ForwardArc(arc);59 target.Add ReverseArc(arc);71 source.AddArc(arc); 72 target.AddArc(arc); 60 73 arcs.Add(arc); 61 74 return arc; … … 68 81 Ranks[node.Rank] = new List<IGenealogyGraphNode>(); 69 82 Ranks[node.Rank].Add(node); 70 } 83 84 if (contentMap.ContainsKey(node.Content)) 85 throw new InvalidOperationException("Duplicate content is not allowed in the genealogy graph."); 86 contentMap[node.Content] = node; 87 88 if (idMap.ContainsKey(node.Id)) 89 throw new InvalidOperationException("Duplicate content is not allowed in the genealogy graph."); 90 idMap[node.Id] = node; 91 92 vertex.Changed += OnVertexChanged; 93 } 94 71 95 public override void RemoveVertex(IVertex vertex) { 72 96 var node = (IGenealogyGraphNode)vertex; 97 contentMap.Remove(node.Content); 98 idMap.Remove(node.Id); 73 99 if (Ranks.ContainsKey(node.Rank)) { 74 100 Ranks[node.Rank].Remove(node); … … 76 102 base.RemoveVertex(vertex); 77 103 } 104 105 public IGenealogyGraphNode GetByContent(object content) { 106 IGenealogyGraphNode result; 107 contentMap.TryGetValue(content, out result); 108 return result; 109 } 110 111 public IGenealogyGraphNode GetById(string id) { 112 IGenealogyGraphNode result; 113 idMap.TryGetValue(id, out result); 114 return result; 115 } 116 117 public bool Contains(object content) { 118 return contentMap.ContainsKey(content); 119 } 120 78 121 public event EventHandler GraphUpdated; 79 122 private void OnGraphUpdated(object sender, EventArgs args) { … … 86 129 ranks.Clear(); 87 130 } 131 132 protected override void OnVertexChanged(object sender, EventArgs args) { 133 base.OnVertexChanged(sender, args); 134 135 var vertex = (IGenealogyGraphNode)sender; 136 if (!contentMap.ContainsKey(vertex.Content)) { 137 // vertex has received new content 138 } 139 } 88 140 } 89 141 142 // [StorableClass] 143 // [Item("GenealogyGraph", "A class representing a genealogy graph")] 144 // public class GenealogyGraph<T> : DirectedGraph, IGenealogyGraph<T> where T : class, IItem { 145 // // members and properties 146 // [Storable] 147 // private Dictionary<double, List<IGenealogyGraphNode>> ranks; 148 // public Dictionary<double, List<IGenealogyGraphNode>> Ranks { 149 // get { return ranks; } 150 // set { ranks = value; } 151 // } 152 // public new IEnumerable<IGenealogyGraphNode<T>> Vertices { 153 // get { return from n in base.Vertices select (IGenealogyGraphNode<T>)n; } 154 // } 155 // // contructors 156 // protected GenealogyGraph(GenealogyGraph<T> original, Cloner cloner) 157 // : base(original, cloner) { 158 // } 159 // public override IDeepCloneable Clone(Cloner cloner) { 160 // return new GenealogyGraph<T>(this, cloner); 161 // } 162 // 163 // [StorableConstructor] 164 // protected GenealogyGraph(bool deserializing) : base(deserializing) { } 165 // public GenealogyGraph() { 166 // Ranks = new Dictionary<double, List<IGenealogyGraphNode>>(); 167 // } 168 // 169 // // methods 170 // public override void AddVertex(IVertex vertex) { 171 // base.AddVertex(vertex); 172 // var node = (IGenealogyGraphNode)vertex; 173 // if (!Ranks.ContainsKey(node.Rank)) { 174 // Ranks[node.Rank] = new List<IGenealogyGraphNode>(); 175 // } 176 // Ranks[node.Rank].Add(node); 177 // } 178 // 179 // public override void RemoveVertex(IVertex vertex) { 180 // var node = (IGenealogyGraphNode<T>)vertex; 181 // if (Ranks.ContainsKey(node.Rank)) { 182 // Ranks[node.Rank].Remove(node); 183 // } 184 // base.RemoveVertex(vertex); 185 // } 186 // 187 // public override IArc AddArc(IVertex source, IVertex target) { 188 // var arc = new GenealogyGraphArc((IGenealogyGraphNode)source, (IGenealogyGraphNode)target); 189 // source.AddArc(arc); 190 // target.AddArc(arc); 191 // arcs.Add(arc); 192 // return arc; 193 // } 194 // 195 // IEnumerable<IGenealogyGraphNode> IGenealogyGraph.Vertices { 196 // get { return Vertices; } 197 // } 198 // 199 // public IGenealogyGraphNode GetByContent(object content) 200 // { 201 // IGenealogyGraphNode result; 202 // contentMap. 203 // } 204 // 205 // public event EventHandler GraphUpdated; 206 // private void OnGraphUpdated(object sender, EventArgs args) { 207 // var updated = GraphUpdated; 208 // if (updated != null) updated(sender, args); 209 // } 210 // } 90 211 [StorableClass] 91 [Item("GenealogyGraph", "A class representing a genealogy graph")] 92 public class GenealogyGraph<T> : DirectedGraph, IGenealogyGraph<T> where T : class, IItem { 93 // members and properties 94 [Storable] 95 private Dictionary<double, List<IGenealogyGraphNode>> ranks; 96 public Dictionary<double, List<IGenealogyGraphNode>> Ranks { 97 get { return ranks; } 98 set { ranks = value; } 99 } 212 213 [Item("GenealogyGraph", "A specialization of the genealogy graph with T as content for vertices")] 214 public class GenealogyGraph<T> : GenealogyGraph, IGenealogyGraph<T> where T : class, IItem { 100 215 public new IEnumerable<IGenealogyGraphNode<T>> Vertices { 101 get { return from n in base.Vertices select (IGenealogyGraphNode<T>)n; } 102 } 103 // contructors 104 protected GenealogyGraph(GenealogyGraph<T> original, Cloner cloner) 105 : base(original, cloner) { 106 } 107 public override IDeepCloneable Clone(Cloner cloner) { 108 return new GenealogyGraph<T>(this, cloner); 109 } 110 [StorableConstructor] 111 protected GenealogyGraph(bool deserializing) : base(deserializing) { } 112 public GenealogyGraph() { 113 Ranks = new Dictionary<double, List<IGenealogyGraphNode>>(); 114 } 115 // methods 116 public override void AddVertex(IVertex vertex) { 117 base.AddVertex(vertex); 118 var node = (IGenealogyGraphNode)vertex; 119 if (!Ranks.ContainsKey(node.Rank)) { 120 Ranks[node.Rank] = new List<IGenealogyGraphNode>(); 121 } 122 Ranks[node.Rank].Add(node); 123 } 124 public override void RemoveVertex(IVertex vertex) { 125 var node = (IGenealogyGraphNode<T>)vertex; 126 if (Ranks.ContainsKey(node.Rank)) { 127 Ranks[node.Rank].Remove(node); 128 } 129 base.RemoveVertex(vertex); 130 } 131 public override IArc AddArc(IVertex source, IVertex target) { 132 var arc = new GenealogyGraphArc((IGenealogyGraphNode)source, (IGenealogyGraphNode)target); 133 source.AddForwardArc(arc); 134 target.AddReverseArc(arc); 135 arcs.Add(arc); 136 return arc; 137 } 138 IEnumerable<IGenealogyGraphNode> IGenealogyGraph.Vertices { 139 get { return Vertices; } 140 } 141 public event EventHandler GraphUpdated; 142 private void OnGraphUpdated(object sender, EventArgs args) { 143 var updated = GraphUpdated; 144 if (updated != null) updated(sender, args); 216 get { return base.Vertices.Cast<IGenealogyGraphNode<T>>(); } 145 217 } 146 218 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphArc.cs
r10903 r11233 33 33 : base(original, cloner) { } 34 34 35 protected GenealogyGraphArc() { } 36 37 public GenealogyGraphArc(IGenealogyGraphNode source, IGenealogyGraphNode target, object data = null) { 38 Source = source; 39 Target = target; 40 Data = data; 35 public GenealogyGraphArc(IGenealogyGraphNode source, IGenealogyGraphNode target) 36 : base(source, target) { 41 37 } 42 38 … … 47 43 public new IGenealogyGraphNode Source { 48 44 get { return (IGenealogyGraphNode)base.Source; } 49 set { base.Source = value; }50 45 } 51 46 52 47 public new IGenealogyGraphNode Target { 53 48 get { return (IGenealogyGraphNode)base.Target; } 54 set { base.Target = value; }55 49 } 56 50 } … … 63 57 protected GenealogyGraphArc(GenealogyGraphArc<T> original, Cloner cloner) 64 58 : base(original, cloner) { 65 Data = (T)original.Data;59 Data = original.Data; 66 60 } 67 61 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphNode.cs
r10897 r11233 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 39 40 } 40 41 41 public GenealogyGraphNode() { } 42 public GenealogyGraphNode(object content) : base(content) { } 42 public GenealogyGraphNode(object content) 43 : base(content) { 44 Id = Guid.NewGuid().ToString(); 45 } 43 46 44 47 public new IEnumerable<IGenealogyGraphArc> InArcs { 45 48 get { return base.InArcs.Cast<IGenealogyGraphArc>(); } 46 set { base.InArcs = value; }47 49 } 48 50 public new IEnumerable<IGenealogyGraphArc> OutArcs { 49 51 get { return base.OutArcs.Cast<IGenealogyGraphArc>(); } 50 set { base.OutArcs = value; }51 52 } 52 53 public IEnumerable<IGenealogyGraphNode> Ancestors { … … 88 89 } 89 90 [Storable] 91 public string Id { get; private set; } 92 93 [Storable] 90 94 private double rank; 91 95 public double Rank { … … 124 128 } 125 129 126 public GenealogyGraphNode() { }127 130 public GenealogyGraphNode(object content) : base(content) { } 128 131 129 132 protected GenealogyGraphNode(GenealogyGraphNode<T> original, Cloner cloner) 130 133 : base(original, cloner) { 134 // we do not clone the content 131 135 Content = original.Content; 132 136 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraph.cs
r10903 r11233 27 27 Dictionary<double, List<IGenealogyGraphNode>> Ranks { get; } 28 28 new IEnumerable<IGenealogyGraphNode> Vertices { get; } 29 IGenealogyGraphNode GetByContent(object content); 30 IGenealogyGraphNode GetById(string id); 31 bool Contains(object content); 29 32 } 30 33 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraphArc.cs
r10888 r11233 20 20 #endregion 21 21 22 using HeuristicLab.Core;23 24 22 namespace HeuristicLab.EvolutionTracking { 25 23 public interface IGenealogyGraphArc : IArc { 26 new IGenealogyGraphNode Source { get; set; } 27 new IGenealogyGraphNode Target { get; set; } 28 } 29 30 public interface IGenealogyGraphArc<T> : IGenealogyGraphArc where T : class, IItem { 31 new T Data { get; set; } 24 new IGenealogyGraphNode Source { get; } 25 new IGenealogyGraphNode Target { get; } 32 26 } 33 27 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraphNode.cs
r10890 r11233 28 28 double Quality { get; set; } 29 29 bool IsElite { get; set; } 30 string Id { get; } 30 31 31 32 IEnumerable<IGenealogyGraphNode> Parents { get; } … … 33 34 IEnumerable<IGenealogyGraphNode> Ancestors { get; } 34 35 IEnumerable<IGenealogyGraphNode> Descendants { get; } 35 new IEnumerable<IGenealogyGraphArc> InArcs { get; set;}36 new IEnumerable<IGenealogyGraphArc> OutArcs { get; set;}36 new IEnumerable<IGenealogyGraphArc> InArcs { get; } 37 new IEnumerable<IGenealogyGraphArc> OutArcs { get; } 37 38 } 38 39 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeCrossoverOperator.cs
r11227 r11233 76 76 77 77 var subScopes = ExecutionContext.Scope.SubScopes; 78 var parentVertices = subScopes.Select(x => (GenealogyGraphNode<T>)GenealogyGraph.Get Vertex(getScopeId(x))).ToList();78 var parentVertices = subScopes.Select(x => (GenealogyGraphNode<T>)GenealogyGraph.GetById(getScopeId(x))).ToList(); 79 79 80 80 var parents = ParentsParameter.ActualValue.ToList(); … … 84 84 GenealogyGraph.AddVertex(childVertex); 85 85 86 foreach (var parentVertex in parentVertices ) {86 foreach (var parentVertex in parentVertices.Distinct()) { 87 87 GenealogyGraph.AddArc(parentVertex, childVertex); 88 88 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs
r11227 r11233 20 20 #endregion 21 21 22 using System.Linq;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; … … 39 38 : base(original, cloner) { 40 39 } 40 41 41 public override IDeepCloneable Clone(Cloner cloner) { 42 42 return new BeforeManipulatorOperator<T>(this, cloner); 43 43 } 44 44 45 [StorableConstructor] 45 46 protected BeforeManipulatorOperator(bool deserializing) : base(deserializing) { } … … 51 52 public override IOperation Apply() { 52 53 // since mutation always takes place after crossover, the vertex for the current child is already in the tree 53 var v = (IGenealogyGraphNode<T>)GenealogyGraph.Get Vertex(ChildParameter.ActualValue);54 var v = (IGenealogyGraphNode<T>)GenealogyGraph.GetByContent(ChildParameter.ActualValue); 54 55 var clone = (T)ChildParameter.ActualValue.Clone(); 55 56 56 57 var c = new GenealogyGraphNode<T>(clone) { Rank = v.Rank - 0.5 }; 57 58 58 foreach (var a in v.InArcs) { 59 a.Target = c; 60 c.AddReverseArc(a); 59 foreach (var arc in v.InArcs) { 60 var p = arc.Source; 61 GenealogyGraph.RemoveArc(arc); 62 GenealogyGraph.AddArc(new GenealogyGraphArc(p, c)); 61 63 } 62 64 63 v.InArcs = Enumerable.Empty<IGenealogyGraphArc>(); 65 // foreach (var a in v.InArcs) { 66 // a.Target = c; 67 // c.AddReverseArc(a); 68 // } 69 70 // v.InArcs = Enumerable.Empty<IGenealogyGraphArc>(); 64 71 65 72 GenealogyGraph.AddVertex(c); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymboldDataAnalysisGenealogyView.cs
r11015 r11233 109 109 var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer)); 110 110 111 var matchingVertices = matchingTrees.Select(x => Content.Get Vertex(x)).Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>();111 var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x)).Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>(); 112 112 graphChart_highlightMatchingVertices(matchingVertices); 113 113 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r11232 r11233 176 176 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" /> 177 177 <Compile Include="Analyzers\SymbolicDataAnalysisGenealogyAnalyzer.cs" /> 178 <Compile Include="Analyzers\SymbolicDataAnalysisPopulationDiversityAnalyzer.cs" />179 178 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" /> 180 179 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs" /> … … 190 189 <SubType>Code</SubType> 191 190 </Compile> 192 <Compile Include="DirectedGraph\Arc.cs" />193 <Compile Include="DirectedGraph\DirectedGraph.cs" />194 <Compile Include="DirectedGraph\Interfaces\IArc.cs" />195 <Compile Include="DirectedGraph\Interfaces\IDirectedGraph.cs" />196 <Compile Include="DirectedGraph\Interfaces\IVertex.cs" />197 <Compile Include="DirectedGraph\Vertex.cs" />198 191 <Compile Include="Interfaces\IModelBacktransformator.cs" /> 199 192 <Compile Include="Interfaces\IDistanceCalculator.cs" /> … … 213 206 <Compile Include="SlidingWindow\SlidingWindowQualitiesAnalyzer.cs" /> 214 207 <Compile Include="SlidingWindow\SlidingWindowVisualizer.cs" /> 215 <Compile Include="SymbolGraph\FPGraph.cs" />216 <Compile Include="SymbolGraph\SymbolGraph.cs" />217 208 <Compile Include="SymbolicDataAnalysisExpressionPruningOperator.cs" /> 218 209 <Compile Include="SymbolicDataAnalysisExpressionTreeSimilarityCalculator.cs" /> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r11232 r11233 235 235 Operators.Add(new SingleObjectivePopulationDiversityAnalyzer()); 236 236 Operators.Add(new BottomUpSimilarityCalculator()); 237 Operators.Add(new SymbolicDataAnalysisGenealogyAnalyzer()); 237 238 ParameterizeOperators(); 238 239 } … … 361 362 op.SimilarityCalculator = operators.OfType<BottomUpSimilarityCalculator>().SingleOrDefault(); 362 363 } 364 // add tracking analyzer 365 foreach (var op in operators.OfType<SymbolicDataAnalysisGenealogyAnalyzer>()) { 366 op.BeforeCrossoverOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionBeforeCrossoverOperator(); 367 op.AfterCrossoverOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionAfterCrossoverOperator(); 368 op.BeforeManipulatorOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionBeforeManipulatorOperator(); 369 op.AfterManipulatorOperatorParameter.ActualValue = new SymbolicDataAnalysisExpressionAfterManipulatorOperator(); 370 // get crossover parameter names 371 var crossover = operators.OfType<ISymbolicExpressionTreeCrossover>().FirstOrDefault(); 372 if (crossover != null) { 373 op.BeforeCrossoverOperator.ParentsParameter.ActualName = crossover.ParentsParameter.Name; 374 op.AfterCrossoverOperator.ParentsParameter.ActualName = crossover.ParentsParameter.Name; 375 op.BeforeCrossoverOperator.ChildParameter.ActualName = crossover.ChildParameter.Name; 376 op.AfterCrossoverOperator.ChildParameter.ActualName = crossover.ChildParameter.Name; 377 } 378 // get manipulator parameter names 379 var manipulator = operators.OfType<ISymbolicExpressionTreeManipulator>().FirstOrDefault(); 380 if (manipulator != null) { 381 op.BeforeManipulatorOperator.ChildParameter.ActualName = manipulator.SymbolicExpressionTreeParameter.Name; 382 op.AfterManipulatorOperator.ChildParameter.ActualName = manipulator.SymbolicExpressionTreeParameter.Name; 383 } 384 var creator = operators.OfType<ISymbolicExpressionTreeCreator>().FirstOrDefault(); 385 if (creator != null) { 386 op.PopulationParameter.ActualName = creator.SymbolicExpressionTreeParameter.ActualName; 387 } 388 } 363 389 } 364 390 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs
r10897 r11233 30 30 public class SymbolicDataAnalysisExpressionAfterCrossoverOperator : AfterCrossoverOperator<ISymbolicExpressionTree> { 31 31 public override IOperation Apply() { 32 var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.Get Vertex(ChildParameter.ActualValue);32 var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetByContent(ChildParameter.ActualValue); 33 33 var arcs = childVertex.InArcs.ToList(); 34 34 var nodes0 = (List<ISymbolicExpressionTreeNode>)arcs[0].Data; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterManipulatorOperator.cs
r10897 r11233 40 40 41 41 public override IOperation Apply() { 42 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.Get Vertex(ChildParameter.ActualValue);42 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetByContent(ChildParameter.ActualValue); 43 43 var nodesBefore = (List<ISymbolicExpressionTreeNode>)vChild.InArcs.First().Data; 44 44 var nodesAfter = ChildParameter.ActualValue.IterateNodesPrefix().ToList(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs
r10897 r11233 30 30 var result = base.Apply(); // the base operator will add the child to the graph before the actual crossover operation takes place 31 31 var parents = ParentsParameter.ActualValue.ToList(); 32 var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.Get Vertex(parents[0]); // use the parent since it is actually the child before crossover (and the ChildParameter doesn't have a value yet)32 var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetByContent(parents[0]); // use the parent since it is actually the child before crossover (and the ChildParameter doesn't have a value yet) 33 33 var arcs = childVertex.InArcs.ToList(); 34 34 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs
r10897 r11233 30 30 var result = base.Apply(); // add the vertex in the genealogy graph 31 31 32 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.Get Vertex(ChildParameter.ActualValue);32 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetByContent(ChildParameter.ActualValue); 33 33 var vClone = vChild.Parents.Last(); 34 34 vChild.InArcs.First().Data = vClone.Content.IterateNodesPrefix().ToList(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs
r10888 r11233 30 30 public static class SymbolicDataAnalysisExpressionTracing { 31 31 public static FragmentGraph TraceSubtree(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, int subtreeIndex) { 32 var graph = new FragmentGraph { AllowDuplicateContent = true };32 var graph = new FragmentGraph(); 33 33 var nodes = Trace(graphNode, subtreeIndex); 34 34 foreach (var n in nodes) { … … 51 51 while (true) { 52 52 if (!node.Parents.Any()) { 53 var fragmentNode = new FragmentNode { 54 Content = node, 53 var fragmentNode = new FragmentNode(node) { 55 54 SubtreeIndex = index, 56 55 }; 57 56 if (parent != null) { 58 57 var arc = new Arc(parent, fragmentNode); 59 parent.AddForwardArc(arc); 60 fragmentNode.AddReverseArc(arc); 58 parent.AddArc(arc); 59 fragmentNode.AddArc(arc); 60 61 // parent.AddForwardArc(arc); 62 // fragmentNode.AddReverseArc(arc); 61 63 } 62 64 yield return fragmentNode; // no tracing if there are no parents … … 79 81 if (parents.Count == 1) { 80 82 // we are tracing a mutation operation 81 var fragmentNode = new FragmentNode { 82 Content = node, 83 var fragmentNode = new FragmentNode(node) { 83 84 SubtreeIndex = index, 84 85 FragmentIndex = fragment.Index1 … … 86 87 if (parent != null) { 87 88 var arc = new Arc(parent, fragmentNode); 88 parent.Add ForwardArc(arc);89 fragmentNode.Add ReverseArc(arc);89 parent.AddArc(arc); 90 fragmentNode.AddArc(arc); 90 91 } 91 92 node = parents[0]; … … 138 139 if (fragment.Index1 < index + subtreeLength) { 139 140 // subtree contains fragment => bifurcation point in the fragment graph 140 var fragmentNode = new FragmentNode { 141 Content = node, 141 var fragmentNode = new FragmentNode(node) { 142 142 SubtreeIndex = index, 143 143 FragmentIndex = fragment.Index1 … … 145 145 if (parent != null) { 146 146 var arc = new Arc(parent, fragmentNode); 147 parent.Add ForwardArc(arc);148 fragmentNode.Add ReverseArc(arc);147 parent.AddArc(arc); 148 fragmentNode.AddArc(arc); 149 149 } 150 150 yield return fragmentNode;
Note: See TracChangeset
for help on using the changeset viewer.