Changeset 10654 for branches/HeuristicLab.EvolutionTracking
- Timestamp:
- 03/24/14 23:50:17 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 3 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 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs
r10650 r10654 9 9 public class SymbolicDataAnalysisExpressionAfterCrossoverOperator : AfterCrossoverOperator<ISymbolicExpressionTree> { 10 10 public override IOperation Apply() { 11 var childVertex = GenealogyGraph[ChildParameter.ActualValue].Last(); 11 var child = ChildParameter.ActualValue; 12 var childVertex = GenealogyGraph[child].Last(); 12 13 var arc0 = (IGenealogyGraphArc)childVertex.InArcs[0]; 13 14 var arc1 = (IGenealogyGraphArc)childVertex.InArcs[1]; 14 15 var nodes0 = (List<ISymbolicExpressionTreeNode>)arc0.Data; 15 16 var nodes1 = (List<ISymbolicExpressionTreeNode>)arc1.Data; 16 var childNodes = ChildParameter.ActualValue.IterateNodesBreadth().ToList();17 var childNodes = child.IterateNodesPrefix().ToList(); 17 18 IFragment<ISymbolicExpressionTreeNode> fragment = null; 18 19 19 for (int i = 0; i < Math.Min(nodes0.Count, childNodes.Count); ++i) { 20 20 if (nodes0[i] == childNodes[i]) continue; 21 21 fragment = new Fragment<ISymbolicExpressionTreeNode> { 22 22 Root = childNodes[i], 23 Index = i 23 Index = i, 24 24 }; 25 fragment.OldIndex = nodes1.IndexOf(fragment.Root); 26 break; 25 27 } 26 28 if (fragment == null) throw new Exception("Could not determine fragment!"); 27 28 for (int i = 0; i < nodes1.Count; ++i) {29 if (nodes1[i] != fragment.Root) continue;30 fragment.OldIndex = i;31 }32 29 33 30 arc0.Data = null; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs
r10459 r10654 7 7 public class SymbolicDataAnalysisExpressionBeforeCrossoverOperator : BeforeCrossoverOperator<ISymbolicExpressionTree> { 8 8 public override IOperation Apply() { 9 var result = base.Apply(); 9 var result = base.Apply(); // the child will be added to the graph before the crossover 10 10 var parents = ParentsParameter.ActualValue.ToList(); 11 11 var childVertex = GenealogyGraph[parents[0]].Last(); // use the parent since it is actually the child before crossover (and the ChildParameter doesn't have a value yet) 12 12 // var parentVertices = ExecutionContext.Scope.SubScopes.Select(s => CurrentGeneration[int.Parse(s.Name)]).ToList(); 13 13 14 // we add the breadth list of nodes of each parent as the data element of the arc from the parent to the child 14 15 for (int i = 0; i < parents.Count; ++i) { 15 var nodes = parents[i].IterateNodes Breadth().ToList();16 var nodes = parents[i].IterateNodesPrefix().ToList(); 16 17 var arc = (IGenealogyGraphArc)childVertex.InArcs[i]; 17 18 arc.Data = nodes;
Note: See TracChangeset
for help on using the changeset viewer.