- Timestamp:
- 05/26/14 01:56:35 (11 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphChart.cs
r10833 r10888 208 208 209 209 DrawLineage(visualNode, n => SimpleLineages ? n.IncomingArcs.Take(1) : n.IncomingArcs, a => a.Source); 210 ((SolidBrush)visualNode.Brush).Color = Color.Transparent; 210 211 DrawLineage(visualNode, n => n.OutgoingArcs, a => a.Target); 211 212 } … … 242 243 } 243 244 245 public void HighlightHotPaths() { 246 Chart.UpdateEnabled = false; 247 ClearPrimitives(); 248 var arcs = GenealogyGraph.Nodes.SelectMany(n => n.InArcs).ToList(); 249 foreach (var arc in arcs) { arc.Weight = 1.0; } // reset weights 250 var rank = GenealogyGraph.Ranks.Keys.Max(); 251 foreach (var ggn in GenealogyGraph.Ranks[rank]) { 252 foreach (var ancestor in ggn.Ancestors) { 253 foreach (var arc in ancestor.InArcs) { 254 arc.Weight++; 255 } 256 } 257 } 258 double max = arcs.Max(a => a.Weight); 259 double min = arcs.Min(a => a.Weight); 260 261 if (min.IsAlmost(max)) return; 262 //translate interval (min,max) to interval (0,255) 263 foreach (var arc in arcs) { 264 var vArc = GetMappedArc(arc.Source, arc.Target); 265 int colorIndex = (int)Math.Round((arc.Weight - min) * 255 / (max - min)); 266 if (colorIndex > 254) colorIndex = 254; 267 vArc.Pen = new Pen(ColorGradient.Colors[colorIndex]); 268 // vArc.Pen.Brush = new SolidBrush(ColorGradient.Colors[colorIndex]); 269 } 270 Chart.UpdateEnabled = true; 271 Chart.EnforceUpdate(); 272 } 273 244 274 void MarkSelectedNode() { 245 275 var center = SelectedVisualNode.Center; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/HeuristicLab.EvolutionTracking.Views-3.4.csproj
r10886 r10888 113 113 <Compile Include="VisualGenealogyGraphArc.cs" /> 114 114 <Compile Include="VisualGenealogyGraphNode.cs" /> 115 <Compile Include="VisualGenealogyGraphTextLabel.cs" />116 115 </ItemGroup> 117 116 <ItemGroup> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r10886 r10888 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> { Content = 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 // TODO: eliminate from the graph extra vertices added by the recombination operators when filling the pool of offspring with offspring selection261 262 260 var elite = population.FirstOrDefault(x => GenealogyGraph.Contains(x)); 263 261 if (elite != null) { 262 var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph[elite]; 263 prevVertex.IsElite = true; // mark elites in the graph retroactively 264 265 var clone = (T)elite.Clone(); 266 264 267 var vertex = new GenealogyGraphNode<T> { 265 Content = (T)elite.Clone(),268 Content = prevVertex.Content, 266 269 Rank = Generations.Value, 267 IsElite = true 270 Quality = prevVertex.Quality, 271 IsElite = false 268 272 }; 273 274 GenealogyGraph.SetContent(prevVertex, clone); 275 // swap id 276 var id = prevVertex.Id; 277 GenealogyGraph.SetId(prevVertex, vertex.Id); 278 269 279 // add new vertex to the graph 280 vertex.Id = id; 270 281 GenealogyGraph.AddVertex(vertex); 271 // swap content between current vertex and previous vertex 272 var previousVertex = (IGenealogyGraphNode<T>)GenealogyGraph[elite]; 273 var tmp = vertex.Content; 274 vertex.Content = previousVertex.Content; 275 previousVertex.Content = tmp; 276 // adjust graph content map 277 GenealogyGraph[vertex.Content] = vertex; 278 GenealogyGraph[previousVertex.Content] = previousVertex; 279 GenealogyGraph.AddArc(previousVertex, vertex); // connect current elite with previous elite 280 vertex.Id = previousVertex.Id; // another way would be to introduce the vertex.Id into the scope of the elite 281 vertex.Quality = previousVertex.Quality; 282 283 if (previousVertex.InArcs.Any()) { 284 vertex.InArcs.Last().Data = previousVertex.InArcs.Last().Data; // save the fragment in case there is one 282 283 GenealogyGraph.AddArc(prevVertex, vertex); // connect current elite with previous elite 284 285 if (prevVertex.InArcs.Any()) { 286 vertex.InArcs.Last().Data = prevVertex.InArcs.Last().Data; // save the fragment in case there is one 285 287 } 286 288 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Arc.cs
r10278 r10888 54 54 public Arc() { } 55 55 56 public Arc(IVertex source, IVertex target) { 57 Source = source; 58 Target = target; 59 } 60 56 61 protected Arc(Arc original, Cloner cloner) 57 62 : base(original, cloner) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/DirectedGraph.cs
r10884 r10888 32 32 [StorableClass] 33 33 public class DirectedGraph : Item, IDirectedGraph { 34 public bool AllowDuplicateContent { get; set; } 35 34 36 [Storable] 35 37 private readonly List<IVertex> nodes; // for performance reasons, maybe this should be a linked list (fast remove) … … 101 103 } 102 104 public virtual void AddVertex(IVertex vertex) { 103 if ( contentMap.ContainsKey(vertex.Content)) {105 if (!AllowDuplicateContent && contentMap.ContainsKey(vertex.Content)) { 104 106 throw new Exception("Content already exists in the graph."); 105 107 } … … 109 111 } 110 112 113 public virtual IArc AddArc(IVertex source, IVertex target) { 114 var arc = new Arc(source, target); 115 source.AddForwardArc(arc); 116 target.AddReverseArc(arc); 117 return arc; 118 } 119 111 120 public virtual void RemoveVertex(IVertex vertex) { 112 121 nodes.Remove(vertex); 113 122 } 123 114 124 public override Image ItemImage { 115 125 get { return Common.Resources.VSImageLibrary.Graph; } 116 126 } 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 } 117 141 } 118 142 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IArc.cs
r10278 r10888 20 20 #endregion 21 21 22 22 23 namespace HeuristicLab.EvolutionTracking { 23 24 public interface IArc { 24 25 IVertex Source { get; set; } 25 26 IVertex Target { get; set; } 27 string Label { get; set; } 28 double Weight { get; set; } 29 object Data { get; set; } 30 } 31 32 public interface IArc<T> : IArc where T : class,IVertex { 33 new T Source { get; set; } 34 new T Target { get; set; } 26 35 } 27 36 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IDirectedGraph.cs
r10884 r10888 30 30 void Clear(); 31 31 void AddVertex(IVertex vertex); 32 IArc AddArc(IVertex source, IVertex target); 32 33 void RemoveVertex(IVertex vertex); 33 34 IEnumerable<IVertex> Nodes { get; } … … 35 36 bool Contains(object content); 36 37 IVertex GetVertex(string id); 38 void SetContent(IVertex vertex, object content); 39 void SetId(IVertex vertex, string id); 37 40 } 38 41 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Interfaces/IVertex.cs
r10886 r10888 25 25 namespace HeuristicLab.EvolutionTracking { 26 26 public interface IVertex : IItem { 27 string Id { get; }28 IEnumerable<IArc> InArcs { get; set;}29 IEnumerable<IArc> OutArcs { get; set;}27 string Id { get; set; } 28 IEnumerable<IArc> InArcs { get; } 29 IEnumerable<IArc> OutArcs { get; } 30 30 31 31 int InDegree { get; } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Vertex.cs
r10886 r10888 46 46 public IEnumerable<IArc> InArcs { 47 47 get { return inArcs ?? Enumerable.Empty<IArc>(); } 48 set { inArcs = value.ToList(); }49 48 } 50 49 [Storable] … … 52 51 public IEnumerable<IArc> OutArcs { 53 52 get { return outArcs ?? Enumerable.Empty<IArc>(); } 54 set { outArcs = value.ToList(); }55 53 } 56 57 54 [Storable] 58 55 public object Content { get; set; } … … 69 66 Id = Guid.NewGuid().ToString(); 70 67 Label = original.Label; 71 inArcs = new List<IArc>(original. InArcs);72 outArcs = new List<IArc>(original. OutArcs);68 inArcs = new List<IArc>(original.inArcs); 69 outArcs = new List<IArc>(original.outArcs); 73 70 } 74 71 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs
r10886 r10888 29 29 namespace HeuristicLab.EvolutionTracking { 30 30 [StorableClass] 31 [Item("GenealogyGraph", " ")]31 [Item("GenealogyGraph", "A class representing a genealogy graph")] 32 32 public class GenealogyGraph : DirectedGraph, IGenealogyGraph { 33 33 [Storable] … … 41 41 } 42 42 43 public IGenealogyGraphArc AddArc(IGenealogyGraphNode source, IGenealogyGraphNode target) {44 var arc = new GenealogyGraphArc(source, target);45 source.AddForwardArc(arc);46 target.AddReverseArc(arc);47 return arc;48 }49 50 43 protected GenealogyGraph(GenealogyGraph original, Cloner cloner) 51 44 : base(original, cloner) { 45 Ranks = new Dictionary<double, List<IGenealogyGraphNode>>(original.Ranks); 52 46 } 53 47 public override IDeepCloneable Clone(Cloner cloner) { … … 59 53 Ranks = new Dictionary<double, List<IGenealogyGraphNode>>(); 60 54 } 55 56 public override IArc AddArc(IVertex source, IVertex target) { 57 var arc = new GenealogyGraphArc((IGenealogyGraphNode)source, (IGenealogyGraphNode)target); 58 source.AddForwardArc(arc); 59 target.AddReverseArc(arc); 60 return arc; 61 } 62 61 63 public override void AddVertex(IVertex vertex) { 64 base.AddVertex(vertex); 62 65 var node = (IGenealogyGraphNode)vertex; 63 66 if (!Ranks.ContainsKey(node.Rank)) 64 67 Ranks[node.Rank] = new List<IGenealogyGraphNode>(); 65 68 Ranks[node.Rank].Add(node); 66 base.AddVertex(vertex);67 69 } 68 70 public override void RemoveVertex(IVertex vertex) { … … 94 96 95 97 [StorableClass] 96 [Item("GenealogyGraph", " ")]98 [Item("GenealogyGraph", "A class representing a genealogy graph")] 97 99 public class GenealogyGraph<T> : DirectedGraph, IGenealogyGraph<T> where T : class, IItem { 98 100 // members and properties … … 106 108 get { return from n in base.Nodes select (IGenealogyGraphNode<T>)n; } 107 109 } 108 109 public IGenealogyGraphArc AddArc(IGenealogyGraphNode source, IGenealogyGraphNode target) {110 var arc = new GenealogyGraphArc(source, target);111 source.AddForwardArc(arc);112 target.AddReverseArc(arc);113 return arc;114 }115 116 110 // contructors 117 111 protected GenealogyGraph(GenealogyGraph<T> original, Cloner cloner) … … 128 122 // methods 129 123 public override void AddVertex(IVertex vertex) { 124 base.AddVertex(vertex); 130 125 var node = (IGenealogyGraphNode<T>)vertex; 131 126 if (!Ranks.ContainsKey(node.Rank)) { … … 133 128 } 134 129 Ranks[node.Rank].Add(node); 135 base.AddVertex(vertex);136 130 } 137 131 public override void RemoveVertex(IVertex vertex) { … … 142 136 base.RemoveVertex(vertex); 143 137 } 144 138 public override IArc AddArc(IVertex source, IVertex target) { 139 var arc = new GenealogyGraphArc((IGenealogyGraphNode)source, (IGenealogyGraphNode)target); 140 source.AddForwardArc(arc); 141 target.AddReverseArc(arc); 142 return arc; 143 } 145 144 IEnumerable<IGenealogyGraphNode> IGenealogyGraph.Nodes { 146 145 get { return Nodes; } 147 146 } 148 149 147 public event EventHandler GraphUpdated; 150 148 private void OnGraphUpdated(object sender, EventArgs args) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphArc.cs
r10886 r10888 69 69 protected GenealogyGraphArc(GenealogyGraphArc<T> original, Cloner cloner) 70 70 : base(original, cloner) { 71 Data = (T)original.Data .Clone();71 Data = (T)original.Data; 72 72 } 73 73 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraphNode.cs
r10886 r10888 42 42 43 43 public new IEnumerable<IGenealogyGraphArc> InArcs { 44 get { return base.InArcs.Cast<IGenealogyGraphArc>().ToList(); } 45 set { base.InArcs = value; } 44 get { return base.InArcs.Cast<IGenealogyGraphArc>(); } 46 45 } 47 46 public new IEnumerable<IGenealogyGraphArc> OutArcs { 48 get { return base.OutArcs.Cast<IGenealogyGraphArc>().ToList(); } 49 set { base.InArcs = value; } 47 get { return base.OutArcs.Cast<IGenealogyGraphArc>(); } 50 48 } 51 49 public IEnumerable<IGenealogyGraphNode> Ancestors { … … 131 129 } 132 130 public new IEnumerable<IGenealogyGraphNode<T>> Parents { 133 get { return base.Parents. Select(p => (IGenealogyGraphNode<T>)p); }131 get { return base.Parents.Cast<IGenealogyGraphNode<T>>(); } 134 132 } 135 133 public new IEnumerable<IGenealogyGraphNode<T>> Children { 136 get { return base.Children. Select(c => (IGenealogyGraphNode<T>)c); }134 get { return base.Children.Cast<IGenealogyGraphNode<T>>(); } 137 135 } 138 136 public new IEnumerable<IGenealogyGraphNode<T>> Ancestors { 139 get { return base.Ancestors. Select(x => (IGenealogyGraphNode<T>)x); }137 get { return base.Ancestors.Cast<IGenealogyGraphNode<T>>(); } 140 138 } 141 139 public new IEnumerable<IGenealogyGraphNode<T>> Descendants { 142 get { return base.Descendants. Select(x => (IGenealogyGraphNode<T>)x); }140 get { return base.Descendants.Cast<IGenealogyGraphNode<T>>(); } 143 141 } 144 142 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraph.cs
r10886 r10888 27 27 Dictionary<double, List<IGenealogyGraphNode>> Ranks { get; } 28 28 new IEnumerable<IGenealogyGraphNode> Nodes { get; } 29 IGenealogyGraphArc AddArc(IGenealogyGraphNode source, IGenealogyGraphNode target);30 29 } 31 30 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraphArc.cs
r10347 r10888 26 26 new IGenealogyGraphNode Source { get; set; } 27 27 new IGenealogyGraphNode Target { get; set; } 28 object Data { get; set; }29 28 } 30 29 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/Interfaces/IGenealogyGraphNode.cs
r10677 r10888 33 33 IEnumerable<IGenealogyGraphNode> Ancestors { get; } 34 34 IEnumerable<IGenealogyGraphNode> Descendants { get; } 35 new IEnumerable<IGenealogyGraphArc> InArcs { get; set;}36 new IEnumerable<IGenealogyGraphArc> OutArcs { get; set;}35 new IEnumerable<IGenealogyGraphArc> InArcs { get; } 36 new IEnumerable<IGenealogyGraphArc> OutArcs { get; } 37 37 } 38 38 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeCrossoverOperator.cs
r10886 r10888 43 43 } 44 44 45 public IValueParameter<IntValue> ExecutionCountParameter { 46 get { return (IValueParameter<IntValue>)Parameters["ExecutionCount"]; } 47 } 48 45 49 protected BeforeCrossoverOperator(BeforeCrossoverOperator<T> original, Cloner cloner) 46 50 : base(original, cloner) { … … 53 57 Parameters.Add(new ScopeTreeLookupParameter<T>(ParentsParameterName)); 54 58 Parameters.Add(new LookupParameter<T>(ChildParameterName)); 59 Parameters.Add(new ValueParameter<IntValue>("ExecutionCount", new IntValue(0))); 55 60 } 56 61 … … 65 70 private readonly Func<IScope, string> getScopeId = s => ((StringValue)s.Variables["Id"].Value).Value; 66 71 public override IOperation Apply() { 67 if (CurrentGeneration == null) throw new Exception(); 72 ExecutionCountParameter.Value.Value++; 73 68 74 var subScopes = ExecutionContext.Scope.SubScopes; 69 75 var parentVertices = subScopes.Select(x => (GenealogyGraphNode<T>)GenealogyGraph.GetVertex(getScopeId(x))).ToList(); … … 75 81 // but the first parent is actually the future child so we use this 76 82 Content = parents[0], 83 // Rank = Generations.Value + 1 77 84 Rank = parentVertices[0].Rank + 1 78 85 }; 86 79 87 GenealogyGraph.AddVertex(childVertex); 88 80 89 foreach (var parentVertex in parentVertices) { 81 90 GenealogyGraph.AddArc(parentVertex, childVertex); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Operators/BeforeManipulatorOperator.cs
r10886 r10888 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using System.Linq; 24 23 using HeuristicLab.Common; … … 50 49 51 50 public override IOperation Apply() { 52 if (GenealogyGraph.Contains(ChildParameter.ActualValue)) { 51 var vChild = (IGenealogyGraphNode<T>)GenealogyGraph[ChildParameter.ActualValue]; 52 if (vChild.Rank.IsAlmost(Generations.Value + 1)) { 53 53 // if the graph already contains a vertex representing the child, it means that the child is a product of crossover 54 54 // when mutation follows after crossover, some changes need to be made to the graph to maintain consistency 55 var child = ChildParameter.ActualValue;56 var clone = (T)child.Clone();57 var vChild = (IGenealogyGraphNode<T>)GenealogyGraph[child];58 var vClone = new GenealogyGraphNode<T> { Content = clone, Rank = vChild.Rank - 0.5};55 var vClone = new GenealogyGraphNode<T> { 56 Content = (T)ChildParameter.ActualValue.Clone(), 57 Rank = vChild.Parents.Last().Rank + 0.5 58 }; 59 59 GenealogyGraph.AddVertex(vClone); 60 var parents = vChild.Parents; // parents of child become parents of clone 61 foreach (var p in parents) { 62 var arc = p.OutArcs.First(a => a.Target == vChild); 60 61 foreach (var arc in vChild.InArcs) { 63 62 arc.Target = vClone; 64 63 vClone.AddReverseArc(arc); … … 66 65 67 66 vClone.InArcs.Last().Data = vChild.InArcs.Last().Data; // fragment of child becomes fragment of clone 68 vChild.InArcs = new List<IGenealogyGraphArc>(); // child will be connected to clone69 67 GenealogyGraph.AddArc(vClone, vChild); 70 68 … … 75 73 GenealogyGraph[parent.Content] = parent; 76 74 77 } else { // this needs to be checked 78 var vChild = new GenealogyGraphNode<T> { Content = ChildParameter.ActualValue, Rank = Generations.Value }; 79 GenealogyGraph.AddVertex(vChild); 75 } else if (vChild.Rank.IsAlmost(Generations.Value)) { 76 var clone = (T)ChildParameter.ActualValue.Clone(); 77 GenealogyGraph.SetContent(vChild, clone); 78 var xx = new GenealogyGraphNode<T> { Content = ChildParameter.ActualValue, Rank = Generations.Value + 1 }; 79 GenealogyGraph.AddVertex(xx); 80 GenealogyGraph.AddArc(vChild, xx); 80 81 } 81 82 return base.Apply(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj
r10884 r10888 279 279 <DependentUpon>SymboldDataAnalysisGenealogyView.cs</DependentUpon> 280 280 </Compile> 281 <Compile Include="Tracking\SymbolicDataAnalysisExpressionGenealogyGraphChart.cs" /> 281 <Compile Include="Tracking\SymbolicDataAnalysisExpressionGenealogyGraphChart.cs"> 282 <SubType>UserControl</SubType> 283 </Compile> 282 284 <Compile Include="Tracking\SymbolicDataAnalysisExpressionGenealogyGraphChart.Designer.cs"> 283 285 <DependentUpon>SymbolicDataAnalysisExpressionGenealogyGraphChart.cs</DependentUpon> … … 366 368 </Content> 367 369 </ItemGroup> 368 <ItemGroup /> 370 <ItemGroup> 371 <EmbeddedResource Include="Tracking\SymboldDataAnalysisGenealogyView.resx"> 372 <DependentUpon>SymboldDataAnalysisGenealogyView.cs</DependentUpon> 373 </EmbeddedResource> 374 </ItemGroup> 369 375 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 370 376 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/FragmentGraphView.cs
r10884 r10888 33 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { 34 34 [View("FragmentGraphView")] 35 [Content(typeof( IGenealogyGraph<IFragment<ISymbolicExpressionTreeNode>>), IsDefaultView = true)]35 [Content(typeof(FragmentGraph), IsDefaultView = true)] 36 36 public sealed partial class FragmentGraphView : ItemView { 37 37 private const int PreferredHorizontalSpacing = 10; … … 41 41 private ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionEngine; 42 42 43 private Dictionary< IGenealogyGraphNode<IFragment<ISymbolicExpressionTreeNode>>, TileLayoutNode> tileDictionary;43 private Dictionary<FragmentNode, TileLayoutNode> tileDictionary; 44 44 45 45 private SymbolicExpressionTreeTile Root { get; set; } 46 46 47 public new IGenealogyGraph<IFragment<ISymbolicExpressionTreeNode>>Content {48 get { return ( IGenealogyGraph<IFragment<ISymbolicExpressionTreeNode>>)base.Content; }47 public new FragmentGraph Content { 48 get { return (FragmentGraph)base.Content; } 49 49 set { base.Content = value; } 50 50 } … … 63 63 NodeHeight = 40 64 64 }; 65 tileDictionary = new Dictionary< IGenealogyGraphNode<IFragment<ISymbolicExpressionTreeNode>>, TileLayoutNode>();65 tileDictionary = new Dictionary<FragmentNode, TileLayoutNode>(); 66 66 } 67 67 … … 70 70 tileDictionary.Clear(); 71 71 foreach (var node in Content.Nodes) { 72 var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)node.Content; 72 73 var tile = new SymbolicExpressionTreeTile(chart); 73 74 tile.LayoutEngine = symbolicExpressionEngine; 74 tile.Label = "Generation " + node. Rank + Environment.NewLine +75 "Quality " + String.Format("{0:0.000}", node. Quality);76 tile.Root = node.Content.Root;75 tile.Label = "Generation " + node.Content.Rank + Environment.NewLine + 76 "Quality " + String.Format("{0:0.000}", node.Content.Quality); 77 tile.Root = graphNode.Content.Root; 77 78 var tileNode = new TileLayoutNode { Tile = tile }; 78 79 tileDictionary.Add(node, tileNode); 79 80 } 80 foreach (var node in Content.Nodes.Where(n => n. Children.Any())) {81 foreach (var node in Content.Nodes.Where(n => n.OutArcs.Any())) { 81 82 var layoutNode = tileDictionary[node]; 82 layoutNode.Children = new List<TileLayoutNode>(node. Children.Select(x => tileDictionary[x]));83 layoutNode.Children = new List<TileLayoutNode>(node.OutArcs.Select(a => tileDictionary[(FragmentNode)a.Target])); 83 84 } 84 85 } … … 116 117 var aSize = aTile.Size; 117 118 var aPos = aTile.Position; 118 119 var fragment = node.Content; 120 if ( fragment.Index1> 0) {121 var subtree = fragment.Root.NodeAt(fragment.Index1);119 var graphNode = node.Content; 120 121 if (node.SubtreeIndex > 0) { 122 var subtree = graphNode.Content.Root.NodeAt(node.SubtreeIndex); 122 123 foreach (var s in subtree.IterateNodesPrefix()) { 123 124 var primitive = aTile.GetPrimitive(s); … … 130 131 } 131 132 } 132 if ( fragment.Index2> 0) {133 var subtree = fragment.Root.NodeAt(fragment.Index2);133 if (node.FragmentIndex > 0) { 134 var subtree = graphNode.Content.Root.NodeAt(node.FragmentIndex); 134 135 foreach (var s in subtree.IterateNodesPrefix()) { 135 136 var primitive = aTile.GetPrimitive(s); … … 143 144 } 144 145 145 if (node.Parents.Any() && node == node.Parents.First().Children.First()) { 146 var parent = node.Parents.First(); 147 var index = fragment.Index1 + (parent.Content.Index2 - parent.Content.Index1); 148 // some mutations create discontinuities which invalidate the index 149 if (index >= 0 && index < fragment.Root.GetLength()) { 150 var subtree = fragment.Root.NodeAt(index); 151 var primitive = aTile.GetPrimitive(subtree); 152 primitive.Brush = new SolidBrush(Color.LightCoral); 146 if (node.InArcs.Any()) { 147 var parent = (FragmentNode)node.InArcs.First().Source; 148 if (parent.OutArcs.First().Target == node) { 149 var index = node.SubtreeIndex + (parent.FragmentIndex - parent.SubtreeIndex); 150 // some mutations create discontinuities which invalidate the index 151 if (index >= 0 && index < graphNode.Content.Length) { 152 var subtree = graphNode.Content.NodeAt(index); 153 var primitive = aTile.GetPrimitive(subtree); 154 primitive.Brush = new SolidBrush(Color.LightCoral); 155 } 153 156 } 154 157 } 155 158 156 foreach (var child in node. Children) {159 foreach (var child in node.OutArcs.Select(x => (FragmentNode)x.Target)) { 157 160 var bTile = tileDictionary[child].Tile; 158 161 var bSize = bTile.Size; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymboldDataAnalysisGenealogyView.Designer.cs
r10833 r10888 51 51 this.genealogyGraphChart = new HeuristicLab.Problems.DataAnalysis.Symbolic.Views.SymbolicDataAnalysisExpressionGenealogyGraphChart(); 52 52 this.symbolicExpressionTreeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart(); 53 this.groupBox1 = new System.Windows.Forms.GroupBox(); 54 this.simpleLineages_checkBox = new System.Windows.Forms.CheckBox(); 55 this.lockGraph_checkBox = new System.Windows.Forms.CheckBox(); 53 56 this.trace_checkBox = new System.Windows.Forms.CheckBox(); 54 this.lockGraph_checkBox = new System.Windows.Forms.CheckBox(); 55 this.simpleLineages_checkBox = new System.Windows.Forms.CheckBox(); 57 this.hotPaths_button = new System.Windows.Forms.Button(); 56 58 ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); 57 59 this.splitContainer1.Panel1.SuspendLayout(); 58 60 this.splitContainer1.Panel2.SuspendLayout(); 59 61 this.splitContainer1.SuspendLayout(); 62 this.groupBox1.SuspendLayout(); 60 63 this.SuspendLayout(); 61 64 // 62 65 // splitContainer1 63 66 // 64 this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Bottom; 65 this.splitContainer1.Location = new System.Drawing.Point(0, 33); 67 this.splitContainer1.Location = new System.Drawing.Point(0, 57); 66 68 this.splitContainer1.Name = "splitContainer1"; 67 69 // … … 73 75 // 74 76 this.splitContainer1.Panel2.Controls.Add(this.symbolicExpressionTreeChart); 75 this.splitContainer1.Size = new System.Drawing.Size(1247, 722);77 this.splitContainer1.Size = new System.Drawing.Size(1247, 698); 76 78 this.splitContainer1.SplitterDistance = 607; 77 79 this.splitContainer1.TabIndex = 0; … … 87 89 this.genealogyGraphChart.ScaleOnResize = true; 88 90 this.genealogyGraphChart.SimpleLineages = false; 89 this.genealogyGraphChart.Size = new System.Drawing.Size(607, 722);91 this.genealogyGraphChart.Size = new System.Drawing.Size(607, 698); 90 92 this.genealogyGraphChart.TabIndex = 0; 91 93 this.genealogyGraphChart.TraceFragments = false; … … 98 100 this.symbolicExpressionTreeChart.Location = new System.Drawing.Point(0, 0); 99 101 this.symbolicExpressionTreeChart.Name = "symbolicExpressionTreeChart"; 100 this.symbolicExpressionTreeChart.Size = new System.Drawing.Size(636, 722);102 this.symbolicExpressionTreeChart.Size = new System.Drawing.Size(636, 698); 101 103 this.symbolicExpressionTreeChart.Spacing = 5; 102 104 this.symbolicExpressionTreeChart.SuspendRepaint = false; 103 105 this.symbolicExpressionTreeChart.TabIndex = 0; 104 this.symbolicExpressionTreeChart.TextFont = new System.Drawing.Font( FontFamily.GenericSansSerif, 10);106 this.symbolicExpressionTreeChart.TextFont = new System.Drawing.Font("Microsoft Sans Serif", 10F); 105 107 this.symbolicExpressionTreeChart.Tree = null; 108 // 109 // groupBox1 110 // 111 this.groupBox1.Controls.Add(this.hotPaths_button); 112 this.groupBox1.Controls.Add(this.simpleLineages_checkBox); 113 this.groupBox1.Controls.Add(this.lockGraph_checkBox); 114 this.groupBox1.Controls.Add(this.trace_checkBox); 115 this.groupBox1.Location = new System.Drawing.Point(3, 3); 116 this.groupBox1.Name = "groupBox1"; 117 this.groupBox1.Size = new System.Drawing.Size(1195, 48); 118 this.groupBox1.TabIndex = 4; 119 this.groupBox1.TabStop = false; 120 this.groupBox1.Text = "Controls"; 121 // 122 // simpleLineages_checkBox 123 // 124 this.simpleLineages_checkBox.AutoSize = true; 125 this.simpleLineages_checkBox.Location = new System.Drawing.Point(94, 19); 126 this.simpleLineages_checkBox.Name = "simpleLineages_checkBox"; 127 this.simpleLineages_checkBox.Size = new System.Drawing.Size(103, 17); 128 this.simpleLineages_checkBox.TabIndex = 6; 129 this.simpleLineages_checkBox.Text = "Simple Lineages"; 130 this.simpleLineages_checkBox.UseVisualStyleBackColor = true; 131 this.simpleLineages_checkBox.CheckedChanged += new System.EventHandler(this.simpleLineages_checkBox_CheckedChanged); 132 // 133 // lockGraph_checkBox 134 // 135 this.lockGraph_checkBox.AutoSize = true; 136 this.lockGraph_checkBox.Location = new System.Drawing.Point(6, 19); 137 this.lockGraph_checkBox.Name = "lockGraph_checkBox"; 138 this.lockGraph_checkBox.Size = new System.Drawing.Size(82, 17); 139 this.lockGraph_checkBox.TabIndex = 5; 140 this.lockGraph_checkBox.Text = "Lock Graph"; 141 this.lockGraph_checkBox.UseVisualStyleBackColor = true; 142 this.lockGraph_checkBox.CheckedChanged += new System.EventHandler(this.lockGraph_checkBox_CheckedChanged); 106 143 // 107 144 // trace_checkBox 108 145 // 109 146 this.trace_checkBox.AutoSize = true; 110 this.trace_checkBox.Location = new System.Drawing.Point( 611, 10);147 this.trace_checkBox.Location = new System.Drawing.Point(203, 19); 111 148 this.trace_checkBox.Name = "trace_checkBox"; 112 149 this.trace_checkBox.Size = new System.Drawing.Size(54, 17); 113 this.trace_checkBox.TabIndex = 1;150 this.trace_checkBox.TabIndex = 4; 114 151 this.trace_checkBox.Text = "Trace"; 115 152 this.trace_checkBox.UseVisualStyleBackColor = true; 116 153 this.trace_checkBox.CheckedChanged += new System.EventHandler(this.trace_checkBox_CheckedChanged); 117 154 // 118 // lockGraph_checkBox155 // hotPaths_button 119 156 // 120 this.lockGraph_checkBox.AutoSize = true; 121 this.lockGraph_checkBox.Location = new System.Drawing.Point(4, 10); 122 this.lockGraph_checkBox.Name = "lockGraph_checkBox"; 123 this.lockGraph_checkBox.Size = new System.Drawing.Size(82, 17); 124 this.lockGraph_checkBox.TabIndex = 2; 125 this.lockGraph_checkBox.Text = "Lock Graph"; 126 this.lockGraph_checkBox.UseVisualStyleBackColor = true; 127 this.lockGraph_checkBox.CheckedChanged += new System.EventHandler(this.lockGraph_checkBox_CheckedChanged); 128 // 129 // simpleLineages_checkBox 130 // 131 this.simpleLineages_checkBox.AutoSize = true; 132 this.simpleLineages_checkBox.Location = new System.Drawing.Point(91, 10); 133 this.simpleLineages_checkBox.Name = "simpleLineages_checkBox"; 134 this.simpleLineages_checkBox.Size = new System.Drawing.Size(103, 17); 135 this.simpleLineages_checkBox.TabIndex = 3; 136 this.simpleLineages_checkBox.Text = "Simple Lineages"; 137 this.simpleLineages_checkBox.UseVisualStyleBackColor = true; 138 this.simpleLineages_checkBox.CheckedChanged += new System.EventHandler(this.simpleLineages_checkBox_CheckedChanged); 157 this.hotPaths_button.Location = new System.Drawing.Point(263, 15); 158 this.hotPaths_button.Name = "hotPaths_button"; 159 this.hotPaths_button.Size = new System.Drawing.Size(75, 23); 160 this.hotPaths_button.TabIndex = 7; 161 this.hotPaths_button.Text = "Hot paths"; 162 this.hotPaths_button.UseVisualStyleBackColor = true; 163 this.hotPaths_button.Click += new System.EventHandler(this.hotPaths_button_Click); 139 164 // 140 165 // SymboldDataAnalysisGenealogyView … … 142 167 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 143 168 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 144 this.Controls.Add(this.simpleLineages_checkBox); 145 this.Controls.Add(this.lockGraph_checkBox); 146 this.Controls.Add(this.trace_checkBox); 169 this.Controls.Add(this.groupBox1); 147 170 this.Controls.Add(this.splitContainer1); 148 171 this.Name = "SymboldDataAnalysisGenealogyView"; … … 152 175 ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); 153 176 this.splitContainer1.ResumeLayout(false); 177 this.groupBox1.ResumeLayout(false); 178 this.groupBox1.PerformLayout(); 154 179 this.ResumeLayout(false); 155 this.PerformLayout();156 180 157 181 } … … 162 186 private SymbolicDataAnalysisExpressionGenealogyGraphChart genealogyGraphChart; 163 187 private Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart symbolicExpressionTreeChart; 188 private System.Windows.Forms.GroupBox groupBox1; 189 private System.Windows.Forms.CheckBox simpleLineages_checkBox; 190 private System.Windows.Forms.CheckBox lockGraph_checkBox; 164 191 private System.Windows.Forms.CheckBox trace_checkBox; 165 private System.Windows.Forms.CheckBox lockGraph_checkBox; 166 private System.Windows.Forms.CheckBox simpleLineages_checkBox; 192 private System.Windows.Forms.Button hotPaths_button; 167 193 168 194 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymboldDataAnalysisGenealogyView.cs
r10755 r10888 30 30 using HeuristicLab.EvolutionTracking.Views; 31 31 using HeuristicLab.MainForm; 32 33 32 34 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { … … 161 160 } 162 161 #endregion 162 163 private void hotPaths_button_Click(object sender, System.EventArgs e) { 164 genealogyGraphChart.HighlightHotPaths(); 165 } 163 166 } 164 167 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r10752 r10888 300 300 <Compile Include="Symbols\VariableConditionTreeNode.cs" /> 301 301 <Compile Include="Symbols\VariableTreeNode.cs" /> 302 <Compile Include="Tracking\FragmentGraph\FragmentGraph.cs" /> 302 303 <Compile Include="Tracking\SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs" /> 303 304 <Compile Include="Tracking\SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs" /> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolGraph/FPGraph.cs
r10886 r10888 32 32 [Storable] 33 33 public Dictionary<int, List<SymbolNode>> Levels { get { return levels; } } 34 private Dictionary<int, List<SymbolNode>> levels = new Dictionary<int, List<SymbolNode>>();34 private readonly Dictionary<int, List<SymbolNode>> levels = new Dictionary<int, List<SymbolNode>>(); 35 35 36 36 public void AddNode(SymbolNode node, int level) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolGraph/SymbolGraph.cs
r10886 r10888 73 73 public IVertex Target { get; set; } 74 74 public double Weight { get; set; } 75 75 public string Label { get; set; } 76 76 public object Data { get; set; } 77 77 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs
r10833 r10888 37 37 } 38 38 39 // var parentVertices = childVertex.Parents.ToList();40 //41 // if (parents[0].Length != parentVertices[0].Content.Length || parents[1].Length != parentVertices[1].Content.Length) {42 // throw new Exception("Inconsistency detected in GenealogyGraph.");43 // }44 45 39 return result; 46 40 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs
r10837 r10888 31 31 32 32 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue]; 33 var vClone = (IGenealogyGraphNode<ISymbolicExpressionTree>)vChild.InArcs.Last().Source;33 var vClone = vChild.Parents.Last(); 34 34 vChild.InArcs.First().Data = vClone.Content.IterateNodesPrefix().ToList(); 35 35 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs
r10886 r10888 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 27 using HeuristicLab.EvolutionTracking; 28 using FragmentNode = HeuristicLab.EvolutionTracking.GenealogyGraphNode<HeuristicLab.EvolutionTracking.IFragment<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTreeNode>>;29 using IFragmentNode = HeuristicLab.EvolutionTracking.IGenealogyGraphNode<HeuristicLab.EvolutionTracking.IFragment<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTreeNode>>;30 using IGraphNode = HeuristicLab.EvolutionTracking.IGenealogyGraphNode<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTree>;31 28 32 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 33 30 public static class SymbolicDataAnalysisExpressionTracing { 34 public static IGenealogyGraph<IFragment<ISymbolicExpressionTreeNode>>TraceSubtree(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, int subtreeIndex) {35 var graph = new GenealogyGraph<IFragment<ISymbolicExpressionTreeNode>>();31 public static FragmentGraph TraceSubtree(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, int subtreeIndex) { 32 var graph = new FragmentGraph { AllowDuplicateContent = true }; 36 33 var nodes = Trace(graphNode, subtreeIndex); 37 34 foreach (var n in nodes) { … … 40 37 return graph; 41 38 } 42 43 private static IEnumerable<IFragmentNode> Trace(IGraphNode graphNode, int subtreeIndex, FragmentNode parentNode = null) { 39 /// <summary> 40 /// Traces a subtree in a genealogy of individuals, tracking down it's genetic components 41 /// </summary> 42 /// <param name="graphNode">The point in the genealogy where to start the tracing from</param> 43 /// <param name="subtreeIndex">The traced subtree preorder index in the current tree</param> 44 /// <param name="parentNode">The parent node in the fragment graph if there is any</param> 45 /// <returns></returns> 46 private static IEnumerable<FragmentNode> Trace(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, int subtreeIndex, FragmentNode parentNode = null) { 44 47 var node = graphNode; // current node 45 48 var index = subtreeIndex; // current index … … 49 52 if (!node.Parents.Any()) { 50 53 var fragmentNode = new FragmentNode { 51 Content = new Fragment<ISymbolicExpressionTreeNode> { 52 Root = node.Content.Root, 53 // Root = node.Content.NodeAt(index) 54 Index1 = index 55 }, 56 Rank = node.Rank, 57 Quality = node.Quality 54 Content = node, 55 SubtreeIndex = index, 58 56 }; 59 57 if (parent != null) { 60 var arc = new GenealogyGraphArc(parent, fragmentNode);58 var arc = new Arc(parent, fragmentNode); 61 59 parent.AddForwardArc(arc); 62 60 fragmentNode.AddReverseArc(arc); … … 78 76 var subtreeLength = subtree.GetLength(); 79 77 78 #region mutation tracing 80 79 if (parents.Count == 1) { 81 80 // we are tracing a mutation operation 82 81 var fragmentNode = new FragmentNode { 83 Content = new Fragment<ISymbolicExpressionTreeNode> { 84 Root = tree.Root, 85 // Root = subtree 86 Index1 = index, 87 Index2 = fragment.Index1 88 }, 89 Rank = node.Rank, 90 Quality = node.Quality 82 Content = node, 83 SubtreeIndex = index, 84 FragmentIndex = fragment.Index1 91 85 }; 92 86 if (parent != null) { 93 var arc = new GenealogyGraphArc(parent, fragmentNode);87 var arc = new Arc(parent, fragmentNode); 94 88 parent.AddForwardArc(arc); 95 89 fragmentNode.AddReverseArc(arc); 96 90 } 91 node = parents[0]; 92 if (subtreeIndex == fragment.Index1) { 93 // index stays the same 94 } else if (fragment.Index1 < subtreeIndex) { 95 if (subtreeIndex < fragment.Index1 + fragmentLength) { 96 // subtree contained in fragment, index stays the same 97 } else { 98 index += node.Content.NodeAt(fragment.Index1).GetLength() - fragmentLength; 99 } 100 } else if (subtreeIndex < fragment.Index1) { 101 if (fragment.Index1 < subtreeIndex + subtreeLength) { 102 // subtree contains fragment 103 index = fragment.Index1; 104 } else { 105 // index stays the same 106 } 107 } 108 97 109 yield return fragmentNode; 98 var up = Trace( parents[0], fragment.Index1, fragmentNode);110 var up = Trace(node, index, fragmentNode); 99 111 foreach (var v in up) { yield return v; } 100 112 break; 101 113 } 114 #endregion 102 115 116 #region crossover tracing 103 117 if (parents.Count == 2) { 104 118 // we are tracing a crossover operation … … 125 139 // subtree contains fragment => bifurcation point in the fragment graph 126 140 var fragmentNode = new FragmentNode { 127 Content = new Fragment<ISymbolicExpressionTreeNode> { 128 Root = tree.Root, 129 Index1 = index, 130 Index2 = fragment.Index1 131 }, 132 Rank = node.Rank, 133 Quality = node.Quality 141 Content = node, 142 SubtreeIndex = index, 143 FragmentIndex = fragment.Index1 134 144 }; 135 145 if (parent != null) { 136 var arc = new GenealogyGraphArc(parent, fragmentNode);146 var arc = new Arc(parent, fragmentNode); 137 147 parent.AddForwardArc(arc); 138 148 fragmentNode.AddReverseArc(arc); 139 149 } 140 // fragmentNode.Content.Index1 = fragment.Index1 - index;141 150 yield return fragmentNode; 142 151 … … 154 163 } 155 164 } 165 #endregion 156 166 } 157 167 }
Note: See TracChangeset
for help on using the changeset viewer.