Changeset 10654 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4
- Timestamp:
- 03/24/14 23:50:17 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymboldDataAnalysisGenealogyView.cs
r10650 r10654 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Drawing; … … 110 111 graphChart_highlightMatchingVertices(vertices); 111 112 } else { 112 // perform matching like before 113 // perform matching like it was done before 114 // currently there is no possibility to specify the subtree matching criteria 113 115 var trees = Content.Nodes.Select(x => (ISymbolicExpressionTree)x.Content); 114 116 var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer)); … … 174 176 } 175 177 176 private void Trace(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, ISymbolicExpressionTreeNode subtree, FragmentGraph fragmentGraph, FragmentNode fragmentNode = null) { 177 // add the subtree as a vertex in the fragment graph 178 var fn = new FragmentNode { Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree }, Rank = graphNode.Rank }; 179 fragmentGraph.AddVertex(fn); 180 181 // maybe we reached the end of the genealogy 178 private void Trace(IGenealogyGraphNode<ISymbolicExpressionTree> graphNode, ISymbolicExpressionTreeNode subtree, FragmentGraph fragmentGraph, FragmentNode parentNode = null) { 182 179 if (graphNode.InArcs == null) return; 183 184 180 // the subtree must belong to the currently displayed tree which in turn must belong to the currently selected graph node 185 181 var tree = graphNode.Content; … … 190 186 var fragmentLength = fragment.Root.GetLength(); 191 187 192 if (fragment.Index <= index && index < fragment.Index + fragmentLength) { 193 // the selected subtree is contained by the fragment 194 var fn1 = new FragmentNode { Content = fragment }; 195 if (fragmentNode != null) { 196 AddChild(fragmentNode, fn1); 197 } 198 fragmentGraph.AddVertex(fn1); 188 if (fragment.Index == index) { 189 // the selected subtree is the actual fragment 190 if (fragmentLength != length) throw new Exception("Fragment and subtree lengths should be the same!"); 191 192 var node = new FragmentNode { Content = fragment, Rank = graphNode.Rank }; 193 194 if (parentNode != null) { 195 AddChild(parentNode, node); 196 } 197 198 fragmentGraph.AddVertex(node); 199 199 200 graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs.Last().Source; 200 201 subtree = graphNode.Content.IterateNodesPrefix().ToList()[fragment.OldIndex]; 201 Trace(graphNode, subtree, fragmentGraph, fn1); 202 } else if (fragment.Index > index && fragment.Index < index + length) { 202 Trace(graphNode, subtree, fragmentGraph, node); 203 } else if (fragment.Index < index && index < fragment.Index + fragmentLength) { 204 // the fragment contains the selected subtree 205 if (length >= fragmentLength) throw new Exception("Fragment contains subtree, so subtree length should be less than the fragment length."); 206 207 var node = new FragmentNode { Content = fragment, Rank = graphNode.Rank }; 208 if (parentNode != null) { 209 AddChild(parentNode, node); 210 } 211 212 fragmentGraph.AddVertex(node); 213 214 graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs.Last().Source; 215 var i = fragment.Root.IterateNodesPrefix().ToList().IndexOf(subtree); 216 subtree = graphNode.Content.IterateNodesPrefix().ToList()[fragment.OldIndex + i]; 217 Trace(graphNode, subtree, fragmentGraph, node); 218 219 } else if (index < fragment.Index && fragment.Index < index + length) { 203 220 // the selected subtree contains the fragment 204 // first trace the fragment, then trace the subtree 205 graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs.Last().Source; 206 subtree = graphNode.Content.IterateNodesPrefix().ToList()[fragment.OldIndex]; 207 208 var fn0 = new FragmentNode { Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree } }; 209 var fn1 = new FragmentNode { Content = fragment }; 210 211 if (fragmentNode != null) { 212 AddChild(fragmentNode, fn0); 213 AddChild(fragmentNode, fn1); 214 } 215 fragmentGraph.AddVertex(fn0); 216 fragmentGraph.AddVertex(fn1); 221 if (fragmentLength >= length) throw new Exception("Subtree contains fragment, so fragment length should be less than the subtree length."); 222 223 var node = new FragmentNode { Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree }, Rank = graphNode.Rank }; 224 225 if (parentNode != null) { 226 AddChild(parentNode, node); 227 } 228 fragmentGraph.AddVertex(node); 217 229 218 230 var graphNode0 = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs[0].Source; 219 231 var subtree0 = graphNode0.Content.IterateNodesPrefix().ToList()[index]; 220 Trace(graphNode0, subtree0, fragmentGraph, fn0); 221 222 var graphNode1 = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs.Last().Source; 223 var subtree1 = graphNode1.Content.IterateNodesPrefix().ToList()[fragment.OldIndex]; 224 Trace(graphNode1, subtree1, fragmentGraph, fn1); 225 } else { 226 // the fragment is not contained by the selected subtree, so we go one level up 227 graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs[0].Source; 228 subtree = graphNode.Content.IterateNodesPrefix().ToList()[index]; 229 fragmentGraph.Clear(); // restart the trace one level up 230 Trace(graphNode, subtree, fragmentGraph); 232 Trace(graphNode0, subtree0, fragmentGraph, node); 233 234 if (graphNode.InArcs.Count > 1) { 235 var graphNode1 = (IGenealogyGraphNode<ISymbolicExpressionTree>)graphNode.InArcs[1].Source; 236 var subtree1 = graphNode1.Content.IterateNodesPrefix().ToList()[fragment.OldIndex]; 237 Trace(graphNode1, subtree1, fragmentGraph, node); 238 } 231 239 } 232 240 }
Note: See TracChangeset
for help on using the changeset viewer.