- Timestamp:
- 05/27/14 16:33:17 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/Plugin.cs.frame
r10458 r10897 22 22 using HeuristicLab.PluginInfrastructure; 23 23 24 namespace HeuristicLab.Evolution aryTracking.Views {24 namespace HeuristicLab.EvolutionTracking.Views { 25 25 [Plugin("HeuristicLab.EvolutionTracking.Views", "Provides controls and views for the evolution graph and related structures.", "3.4.2.$WCREV$")] 26 26 [PluginFile("HeuristicLab.EvolutionTracking.Views-3.4.dll", PluginFileType.Assembly)] … … 33 33 [PluginDependency("HeuristicLab.EvolutionTracking", "3.4")] 34 34 35 public class HeuristicLabEvolution aryTrackingPlugin : PluginBase {35 public class HeuristicLabEvolutionTrackingPlugin : PluginBase { 36 36 } 37 37 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r10888 r10897 252 252 for (int i = 0; i < population.Count; ++i) { 253 253 var individual = population[i]; 254 var vertex = new GenealogyGraphNode<T> { Content = individual,Rank = Generations.Value };254 var vertex = new GenealogyGraphNode<T>(individual) { Rank = Generations.Value }; 255 255 GenealogyGraph.AddVertex(vertex); 256 256 // save the vertex id in the individual scope (so that we can identify graph indices) … … 258 258 } 259 259 } else { 260 var elite = population.FirstOrDefault(x => GenealogyGraph.Contains(x)); 260 int index = 0; 261 T elite = null; 262 for (int i = 0; i < population.Count; ++i) { 263 if (GenealogyGraph.Contains(population[i])) { 264 elite = population[i]; 265 index = i; 266 } 267 break; 268 } 269 261 270 if (elite != null) { 262 var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph [elite];271 var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.GetVertex(elite); 263 272 prevVertex.IsElite = true; // mark elites in the graph retroactively 264 273 265 274 var clone = (T)elite.Clone(); 266 275 267 var vertex = new GenealogyGraphNode<T> { 268 Content = prevVertex.Content, 276 var vertex = new GenealogyGraphNode<T>(prevVertex.Content) { 269 277 Rank = Generations.Value, 270 278 Quality = prevVertex.Quality, … … 272 280 }; 273 281 274 GenealogyGraph.SetContent(prevVertex, clone); 275 // swap id 276 var id = prevVertex.Id; 277 GenealogyGraph.SetId(prevVertex, vertex.Id); 278 279 // add new vertex to the graph 280 vertex.Id = id; 282 prevVertex.Content = clone; 283 284 ExecutionContext.Scope.SubScopes[index].Variables["Id"].Value = new StringValue(vertex.Id); 285 281 286 GenealogyGraph.AddVertex(vertex); 282 287 … … 290 295 // update qualities 291 296 for (int i = 0; i < population.Count; ++i) { 292 var vertex = (IGenealogyGraphNode)GenealogyGraph [population[i]];297 var vertex = (IGenealogyGraphNode)GenealogyGraph.GetVertex(population[i]); 293 298 vertex.Quality = qualities[i].Value; 294 299 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Arc.cs
r10888 r10897 31 31 public class Arc : Item, IArc { 32 32 [Storable] 33 p rivate IVertex source;34 public IVertex Source { get { return source; } set { source = value; } } 33 public IVertex Source { get; set; } 34 35 35 [Storable] 36 p rivate IVertex target;37 public IVertex Target { get { return target; } set { target = value; } } 36 public IVertex Target { get; set; } 37 38 38 [Storable] 39 p rivate string label;40 public string Label { get { return label; } set { label = value; } } 39 public string Label { get; set; } 40 41 41 [Storable] 42 p rivate double weight;43 public double Weight { get { return weight; } set { weight = value; } } 42 public double Weight { get; set; } 43 44 44 [Storable] 45 private object data; 46 public object Data { get { return data; } set { data = value; } } 45 public object Data { get; set; } 47 46 48 47 [StorableConstructor] -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/DirectedGraph.cs
r10888 r10897 45 45 [Storable] 46 46 private readonly Dictionary<object, IVertex> contentMap; 47 48 [StorableConstructor] 49 protected DirectedGraph(bool serializing) 50 : base(serializing) { 51 } 52 47 53 public DirectedGraph() { 48 54 nodes = new List<IVertex>(); … … 50 56 idMap = new Dictionary<string, IVertex>(); 51 57 } 52 [StorableConstructor] 53 protected DirectedGraph(bool serializing) 54 : base(serializing) { 55 } 58 56 59 protected DirectedGraph(DirectedGraph original, Cloner cloner) 57 60 : base(original, cloner) { … … 60 63 idMap = new Dictionary<string, IVertex>(original.idMap); 61 64 } 65 62 66 public override IDeepCloneable Clone(Cloner cloner) { 63 67 return new DirectedGraph(this, cloner); 64 68 } 69 65 70 public bool Contains(IVertex t) { 66 71 return nodes.Contains(t); … … 77 82 } 78 83 79 public IVertex this[object key] { 80 get { 81 IVertex result; 82 contentMap.TryGetValue(key, out result); 83 return result; 84 } 85 set { 86 if (contentMap.ContainsKey(key)) { 87 idMap.Remove(contentMap[key].Id); 88 } 89 contentMap[key] = value; 90 idMap[value.Id] = value; 91 } 84 public IVertex GetVertex(object content) { 85 IVertex result; 86 contentMap.TryGetValue(content, out result); 87 return result; 92 88 } 89 93 90 public virtual bool Any(Func<IVertex, bool> predicate) { 94 91 return nodes.Any(predicate); 95 92 } 93 96 94 public virtual bool IsEmpty { 97 95 get { return !nodes.Any(); } 98 96 } 97 99 98 public virtual void Clear() { 100 99 nodes.Clear(); … … 102 101 idMap.Clear(); 103 102 } 103 104 104 public virtual void AddVertex(IVertex vertex) { 105 if (!AllowDuplicateContent && contentMap.ContainsKey(vertex.Content)) { 106 throw new Exception("Content already exists in the graph."); 105 if (vertex.Content != null) { 106 if (!AllowDuplicateContent && contentMap.ContainsKey(vertex.Content)) { 107 throw new Exception("Content already exists in the graph."); 108 } 109 contentMap.Add(vertex.Content, vertex); 107 110 } 108 contentMap[vertex.Content] = vertex; 109 idMap[vertex.Id] = vertex; 111 idMap.Add(vertex.Id, vertex); 110 112 nodes.Add(vertex); 113 114 vertex.PreContentChanged += Vertex_PreContentChanged; 115 vertex.PostContentChanged += Vertex_PostContentChanged; 116 } 117 118 public virtual void RemoveVertex(IVertex vertex) { 119 contentMap.Remove(vertex.Content); 120 idMap.Remove(vertex.Id); 121 nodes.Remove(vertex); 122 123 vertex.PreContentChanged -= Vertex_PreContentChanged; 124 vertex.PostContentChanged -= Vertex_PostContentChanged; 111 125 } 112 126 … … 118 132 } 119 133 120 public virtual void RemoveVertex(IVertex vertex) { 121 nodes.Remove(vertex); 134 private void Vertex_PreContentChanged(object sender, EventArgs args) { 135 var vertex = (IVertex)sender; 136 if (contentMap.ContainsKey(vertex.Content)) { 137 contentMap.Remove(vertex.Content); 138 } 139 } 140 141 private void Vertex_PostContentChanged(object sender, EventArgs args) { 142 var vertex = (IVertex)sender; 143 if (vertex.Content != null) 144 contentMap.Add(vertex.Content, vertex); 122 145 } 123 146 … … 125 148 get { return Common.Resources.VSImageLibrary.Graph; } 126 149 } 127 128 public void SetContent(IVertex vertex, object content) {129 var oldContent = vertex.Content;130 contentMap.Remove(oldContent);131 vertex.Content = content;132 contentMap[content] = vertex;133 }134 135 public void SetId(IVertex vertex, string id) {136 var oldId = vertex.Id;137 idMap.Remove(oldId);138 vertex.Id = id;139 idMap[id] = vertex;140 }141 150 } 142 151 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IDirectedGraph.cs
r10888 r10897 33 33 void RemoveVertex(IVertex vertex); 34 34 IEnumerable<IVertex> Nodes { get; } 35 IVertex this[object content] { get; set; }36 35 bool Contains(object content); 37 36 IVertex GetVertex(string id); 38 void SetContent(IVertex vertex, object content); 39 void SetId(IVertex vertex, string id); 37 IVertex GetVertex(object content); 40 38 } 41 39 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IVertex.cs
r10888 r10897 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Core; … … 25 26 namespace HeuristicLab.EvolutionTracking { 26 27 public interface IVertex : IItem { 27 string Id { get; set; } 28 IEnumerable<IArc> InArcs { get; } 29 IEnumerable<IArc> OutArcs { get; } 28 event EventHandler PreContentChanged; 29 event EventHandler PostContentChanged; 30 31 string Id { get; } 32 IEnumerable<IArc> InArcs { get; set; } 33 IEnumerable<IArc> OutArcs { get; set; } 30 34 31 35 int InDegree { get; } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Vertex.cs
r10890 r10897 30 30 [StorableClass] 31 31 public class Vertex : Item, IVertex { 32 public event EventHandler PreContentChanged; 33 protected virtual void OnPreContentChanged(object sender, EventArgs args) { 34 var changed = PreContentChanged; 35 if (changed != null) { 36 changed(sender, args); 37 } 38 } 39 40 public event EventHandler PostContentChanged; 41 protected virtual void OnPostContentChanged(object sender, EventArgs args) { 42 var changed = PostContentChanged; 43 if (changed != null) { 44 changed(sender, args); 45 } 46 } 47 32 48 [Storable] 33 49 private string id; 50 34 51 public string Id { 35 52 get { return id; } 36 set { id = value; }37 53 } 54 38 55 [Storable] 39 p rivate string label;40 public string Label { get { return label; } set { label = value; } } 56 public string Label { get; set; } 57 41 58 [Storable] 42 private double weight; 43 public double Weight { get { return weight; } set { weight = value; } } 59 public double Weight { get; set; } 60 61 [Storable] 62 protected object content; 63 public object Content { 64 get { return content; } 65 set { 66 OnPreContentChanged(this, EventArgs.Empty); 67 content = value; 68 OnPostContentChanged(this, EventArgs.Empty); 69 } 70 } 71 44 72 [Storable] 45 73 private List<IArc> inArcs; … … 48 76 set { inArcs = value.ToList(); } 49 77 } 78 50 79 [Storable] 51 80 private List<IArc> outArcs; … … 54 83 set { outArcs = value.ToList(); } 55 84 } 56 [Storable]57 public object Content { get; set; }58 85 59 86 [StorableConstructor] … … 64 91 } 65 92 93 public Vertex(object content) 94 : this() { 95 this.content = content; 96 } 97 66 98 protected Vertex(Vertex original, Cloner cloner) 67 99 : base(original, cloner) { 68 Id = Guid.NewGuid().ToString(); 100 id = Guid.NewGuid().ToString(); 101 content = original.content; 69 102 Label = original.Label; 103 Weight = original.Weight; 70 104 inArcs = new List<IArc>(original.inArcs); 71 105 outArcs = new List<IArc>(original.outArcs); … … 79 113 protected void AfterDeserialization() { 80 114 if (Id == null) { 81 Id = Guid.NewGuid().ToString();115 id = Guid.NewGuid().ToString(); 82 116 } 83 117 } … … 117 151 protected Vertex(Vertex<T> original, Cloner cloner) 118 152 : base(original, cloner) { 119 Content = original.Content; // not sure if to Clone()120 153 } 121 154 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs
r10888 r10897 81 81 } 82 82 83 public new IGenealogyGraphNode this[object content] {84 get {85 var result = base[content];86 return result == null ? null : (IGenealogyGraphNode)result;87 }88 set { base[content] = value; }89 }90 91 83 public override void Clear() { 92 84 base.Clear(); … … 123 115 public override void AddVertex(IVertex vertex) { 124 116 base.AddVertex(vertex); 125 var node = (IGenealogyGraphNode <T>)vertex;117 var node = (IGenealogyGraphNode)vertex; 126 118 if (!Ranks.ContainsKey(node.Rank)) { 127 119 Ranks[node.Rank] = new List<IGenealogyGraphNode>(); … … 150 142 if (updated != null) updated(sender, args); 151 143 } 152 public new IGenealogyGraphNode<T> this[object content] {153 get {154 var result = base[content];155 return result == null ? null : (IGenealogyGraphNode<T>)result;156 }157 }158 144 } 159 145 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphNode.cs
r10890 r10897 40 40 41 41 public GenealogyGraphNode() { } 42 public GenealogyGraphNode(object content) : base(content) { } 42 43 43 44 public new IEnumerable<IGenealogyGraphArc> InArcs { … … 122 123 set { base.Content = value; } 123 124 } 125 124 126 public GenealogyGraphNode() { } 127 public GenealogyGraphNode(object content) : base(content) { } 128 125 129 protected GenealogyGraphNode(GenealogyGraphNode<T> original, Cloner cloner) 126 130 : base(original, cloner) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeCrossoverOperator.cs
r10890 r10897 77 77 var parents = ParentsParameter.ActualValue.ToList(); 78 78 79 var childVertex = new GenealogyGraphNode<T> { 80 // the child parameter does not have a value yet (it will be assigned after crossover), 81 // but the first parent is actually the future child so we use this 82 Content = parents[0], 83 Rank = parentVertices[0].Rank + 1 84 }; 79 var childVertex = new GenealogyGraphNode<T>(parents[0]) { Rank = parentVertices[0].Rank + 1 }; 85 80 86 81 GenealogyGraph.AddVertex(childVertex); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs
r10890 r10897 51 51 public override IOperation Apply() { 52 52 // since mutation always takes place after crossover, the vertex for the current child is already in the tree 53 var v = (IGenealogyGraphNode<T>)GenealogyGraph [ChildParameter.ActualValue];53 var v = (IGenealogyGraphNode<T>)GenealogyGraph.GetVertex(ChildParameter.ActualValue); 54 54 55 55 if (!v.Rank.IsAlmost(Generations.Value + 1)) { … … 58 58 var clone = (T)ChildParameter.ActualValue.Clone(); 59 59 60 var c = new GenealogyGraphNode<T> { 61 Rank = v.Rank - 0.5, 62 Content = clone 63 }; 60 var c = new GenealogyGraphNode<T>(clone) { Rank = v.Rank - 0.5 }; 64 61 65 62 foreach (var a in v.InArcs) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymboldDataAnalysisGenealogyView.cs
r10888 r10897 109 109 var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer)); 110 110 111 var matchingVertices = matchingTrees.Select(x => Content [x]).Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>();111 var matchingVertices = matchingTrees.Select(x => Content.GetVertex(x)).Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>(); 112 112 graphChart_highlightMatchingVertices(matchingVertices); 113 113 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs
r10890 r10897 30 30 public class SymbolicDataAnalysisExpressionAfterCrossoverOperator : AfterCrossoverOperator<ISymbolicExpressionTree> { 31 31 public override IOperation Apply() { 32 var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph [ChildParameter.ActualValue];32 var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetVertex(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
r10837 r10897 40 40 41 41 public override IOperation Apply() { 42 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph [ChildParameter.ActualValue];42 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetVertex(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
r10888 r10897 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 [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.GetVertex(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
r10888 r10897 30 30 var result = base.Apply(); // add the vertex in the genealogy graph 31 31 32 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph [ChildParameter.ActualValue];32 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph.GetVertex(ChildParameter.ActualValue); 33 33 var vClone = vChild.Parents.Last(); 34 34 vChild.InArcs.First().Data = vClone.Content.IterateNodesPrefix().ToList();
Note: See TracChangeset
for help on using the changeset viewer.