Changeset 11318
- Timestamp:
- 08/31/14 18:28:25 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs
r11288 r11318 272 272 var prevVertex = (IGenealogyGraphNode<T>)GenealogyGraph.GetByContent(elite); 273 273 prevVertex.IsElite = true; // mark elites in the graph retroactively 274 var w = (IGenealogyGraphNode<T>)prevVertex.Clone(); 275 var v = new GenealogyGraphNode<T>(prevVertex.Data) { 274 var v = new GenealogyGraphNode<T>((IDeepCloneable)prevVertex.Data.Clone()) { 276 275 Rank = generation, 277 276 Quality = prevVertex.Quality, 278 277 IsElite = false 279 278 }; 280 281 object data = null;282 if (prevVertex.InArcs.Any())283 data = prevVertex.InArcs.Last().Data;284 var children = prevVertex.Children.ToList();285 var parents = prevVertex.Parents.ToList();286 287 GenealogyGraph.RemoveVertex(prevVertex);288 GenealogyGraph.AddVertex(w);289 279 GenealogyGraph.AddVertex(v); 290 GenealogyGraph.AddArc(w, v); // connect current elite with previous elite 291 292 // recreate connections after prevVertex was replaced with w 293 foreach (var c in children) GenealogyGraph.AddArc(w, c); 294 foreach (var p in parents) GenealogyGraph.AddArc(p, w); 295 296 v.InArcs.Last().Data = data; 297 298 if (w.InArcs.Any()) 299 w.InArcs.Last().Data = data; 280 GenealogyGraph.AddArc(prevVertex, v); 300 281 301 282 // inject the graph node unique id to the scope 283 ExecutionContext.Scope.SubScopes[index].Variables[BeforeManipulatorOperator.ChildParameter.ActualName].Value = v.Data; 302 284 ExecutionContext.Scope.SubScopes[index].Variables["Id"].Value = new StringValue(v.Id); 303 285 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/GenealogyGraph/GenealogyGraph.cs
r11257 r11318 38 38 39 39 [Storable] 40 private Dictionary<double, List<IGenealogyGraphNode>> ranks; // use a linked list for fast insertion/removal 40 private Dictionary<double, List<IGenealogyGraphNode>> ranks; 41 41 42 public Dictionary<double, List<IGenealogyGraphNode>> Ranks { 42 43 get { return ranks; } … … 56 57 57 58 [StorableConstructor] 58 protected GenealogyGraph(bool deserializing) : base(deserializing) { } 59 protected GenealogyGraph(bool deserializing) 60 : base(deserializing) { 61 } 62 59 63 public GenealogyGraph() { 60 64 Ranks = new Dictionary<double, List<IGenealogyGraphNode>>(); … … 85 89 86 90 if (idMap.ContainsKey(node.Id)) 87 throw new InvalidOperationException("Duplicate content isnot allowed in the genealogy graph.");91 throw new InvalidOperationException("Duplicate ids are not allowed in the genealogy graph."); 88 92 idMap[node.Id] = node; 89 93 } … … 118 122 119 123 public event EventHandler GraphUpdated; 124 120 125 private void OnGraphUpdated(object sender, EventArgs args) { 121 126 var updated = GraphUpdated; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/FragmentGraphView.cs
r11253 r11318 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views; 29 using HeuristicLab.EvolutionTracking;30 29 using HeuristicLab.MainForm; 31 30 using HeuristicLab.Visualization; … … 38 37 private const int PreferredVerticalSpacing = 25; 39 38 40 private ReingoldTilfordLayoutEngine<TileLayoutNode> layoutEngine;41 private ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionEngine;42 43 private Dictionary<FragmentNode, TileLayoutNode> tileDictionary;39 private readonly ReingoldTilfordLayoutEngine<TileLayoutNode> layoutEngine; 40 private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionEngine; 41 42 private readonly Dictionary<FragmentNode, TileLayoutNode> nodeToTileMap; 44 43 45 44 private SymbolicExpressionTreeTile Root { get; set; } … … 63 62 NodeHeight = 40 64 63 }; 65 tileDictionary= new Dictionary<FragmentNode, TileLayoutNode>();64 nodeToTileMap = new Dictionary<FragmentNode, TileLayoutNode>(); 66 65 } 67 66 68 67 private void MakeTiles() { 69 68 var chart = symbolicExpressionChartControl.Chart; 70 tileDictionary.Clear();69 nodeToTileMap.Clear(); 71 70 foreach (var node in Content.Vertices) { 72 var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)node.Data;73 71 var tile = new SymbolicExpressionTreeTile(chart); 74 72 tile.LayoutEngine = symbolicExpressionEngine; 75 73 tile.Label = "Generation " + node.Data.Rank + Environment.NewLine + 76 74 "Quality " + String.Format("{0:0.000}", node.Data.Quality); 77 tile.Root = graphNode.Data.Root;75 tile.Root = node.Data.Data.Root; 78 76 var tileNode = new TileLayoutNode { Tile = tile }; 79 tileDictionary.Add(node, tileNode);77 nodeToTileMap.Add(node, tileNode); 80 78 } 81 79 foreach (var node in Content.Vertices.Where(n => n.OutArcs.Any())) { 82 var layoutNode = tileDictionary[node];83 layoutNode.Children = new List<TileLayoutNode>(node.OutArcs.Select(a => tileDictionary[(FragmentNode)a.Target]));80 var layoutNode = nodeToTileMap[node]; 81 layoutNode.Children = new List<TileLayoutNode>(node.OutArcs.Select(a => nodeToTileMap[(FragmentNode)a.Target])); 84 82 } 85 83 } … … 89 87 var nodes = Content.Vertices.ToList(); 90 88 var root = nodes[0]; 91 var fragmentRoot = tileDictionary[root];89 var fragmentRoot = nodeToTileMap[root]; 92 90 int maxTileWidth = 0, maxTileHeight = 0; 93 var tiles = nodes.Select(x => tileDictionary[x].Tile).ToList();91 var tiles = nodes.Select(x => nodeToTileMap[x].Tile).ToList(); 94 92 95 93 foreach (var tile in tiles) { … … 114 112 // add connections between the tiles 115 113 foreach (var node in nodes) { 116 var aTile = tileDictionary[node].Tile;114 var aTile = nodeToTileMap[node].Tile; 117 115 var aSize = aTile.Size; 118 116 var aPos = aTile.Position; … … 158 156 159 157 foreach (var child in node.OutArcs.Select(x => (FragmentNode)x.Target)) { 160 var bTile = tileDictionary[child].Tile;158 var bTile = nodeToTileMap[child].Tile; 161 159 var bSize = bTile.Size; 162 160 var bPos = bTile.Position; … … 169 167 } 170 168 // center display on the root of the fragment graph 171 symbolicExpressionChartControl.Chart.Move( tileDictionary[root].Tile.Position.X, tileDictionary[root].Tile.Position.Y);169 symbolicExpressionChartControl.Chart.Move(nodeToTileMap[root].Tile.Position.X, nodeToTileMap[root].Tile.Position.Y); 172 170 symbolicExpressionChartControl.UpdateEnabled = true; 173 171 symbolicExpressionChartControl.EnforceUpdate(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r11253 r11318 173 173 </ItemGroup> 174 174 <ItemGroup> 175 <Compile Include="Analyzers\SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs" /> 176 <Compile Include="Analyzers\SymbolicDataAnalysisPhenotypicDiversityAnalyzer.cs" /> 175 177 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" /> 176 178 <Compile Include="Analyzers\SymbolicDataAnalysisGenealogyAnalyzer.cs" /> … … 198 200 <Compile Include="SimilarityCalculators\BottomUpSimilarityCalculator.cs" /> 199 201 <Compile Include="SimilarityCalculators\MaxCommonSubtreeSimilarityCalculator.cs" /> 202 <Compile Include="SimilarityCalculators\PhenotypicSimilarityCalculator.cs" /> 200 203 <Compile Include="SymbolicExpressionTreeBacktransformator.cs" /> 201 204 <Compile Include="SlidingWindow\GenerationalSlidingWindowAnalyzer.cs" /> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs
r11253 r11318 46 46 } 47 47 48 if (fragment == null) 49 throw new InvalidOperationException("Could not identify crossover fragment."); 50 48 51 arcs[0].Data = null; 49 52 arcs[1].Data = fragment; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs
r11253 r11318 32 32 public static FragmentGraph TraceSubtree(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, int subtreeIndex) { 33 33 var graph = new FragmentGraph(); 34 var nodes = Trace(graphNode, subtreeIndex); 35 foreach (var n in nodes) { 36 graph.AddVertex(n); 37 } 34 var vertices = Trace(graphNode, subtreeIndex).ToList(); 35 graph.AddVertices(vertices); 38 36 return graph; 39 37 } … … 52 50 while (true) { 53 51 if (!node.Parents.Any()) { 54 var fragmentNode = new FragmentNode(node) { 55 SubtreeIndex = index, 56 }; 52 // no tracing if there are no parents, return a fragment node representing the current trace 53 var fragmentNode = new FragmentNode(node) { SubtreeIndex = index }; 57 54 if (parent != null) { 58 55 var arc = new Arc(parent, fragmentNode); 59 56 parent.AddArc(arc); 60 57 fragmentNode.AddArc(arc); 61 62 // parent.AddForwardArc(arc);63 // fragmentNode.AddReverseArc(arc);64 58 } 65 yield return fragmentNode; // no tracing if there are no parents59 yield return fragmentNode; 66 60 break; 67 61 } 68 62 var parents = node.Parents.ToList(); 69 var fragment = (IFragment<ISymbolicExpressionTreeNode>)node.InArcs.Last().Data; 70 71 if (node.IsElite || fragment == null) { 63 if (node.IsElite) { 72 64 // skip elite, go up the graph to original individual 73 65 node = parents[0]; 74 66 continue; 75 67 } 68 var fragment = (IFragment<ISymbolicExpressionTreeNode>)node.InArcs.Last().Data; 69 70 if (node.Rank > 1 && fragment == null) 71 throw new ArgumentNullException("Fragment cannot be null"); 72 76 73 var fragmentLength = fragment.Root.GetLength(); 77 74 var tree = node.Data; … … 139 136 if (fragment.Index1 > index) { 140 137 if (fragment.Index1 < index + subtreeLength) { 141 // subtree contains fragment => b ifurcationpoint in the fragment graph138 // subtree contains fragment => branching point in the fragment graph 142 139 var fragmentNode = new FragmentNode(node) { 143 140 SubtreeIndex = index,
Note: See TracChangeset
for help on using the changeset viewer.