Changeset 10755 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking
- Timestamp:
- 04/16/14 17:15:33 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterCrossoverOperator.cs
r10752 r10755 10 10 public override IOperation Apply() { 11 11 var child = ChildParameter.ActualValue; 12 var childVertex = (IGenealogyGraphNode)GenealogyGraph[child] .Last();12 var childVertex = (IGenealogyGraphNode)GenealogyGraph[child]; 13 13 var arcs = childVertex.InArcs.ToList(); 14 14 var nodes0 = (List<ISymbolicExpressionTreeNode>)arcs[0].Data; … … 20 20 fragment = new Fragment<ISymbolicExpressionTreeNode> { 21 21 Root = childNodes[i], 22 Index = i,22 Index1 = i, 23 23 }; 24 fragment. OldIndex= nodes1.IndexOf(fragment.Root);24 fragment.Index2 = nodes1.IndexOf(fragment.Root); 25 25 break; 26 26 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionAfterManipulatorOperator.cs
r10677 r10755 7 7 8 8 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 9 public class SymbolicDataAnalysisExpressionAfterManipulatorOperator : BeforeManipulatorOperator<ISymbolicExpressionTree> {9 public class SymbolicDataAnalysisExpressionAfterManipulatorOperator : AfterManipulatorOperator<ISymbolicExpressionTree> { 10 10 private readonly SymbolicExpressionTreeNodeSimilarityComparer comparer; 11 11 … … 19 19 20 20 public override IOperation Apply() { 21 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue] .First();21 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue]; 22 22 var nodesBefore = (List<ISymbolicExpressionTreeNode>)vChild.InArcs.First().Data; 23 var nodesAfter = ChildParameter.ActualValue.IterateNodes Breadth().ToList();23 var nodesAfter = ChildParameter.ActualValue.IterateNodesPrefix().ToList(); 24 24 IFragment<ISymbolicExpressionTreeNode> fragment = null; 25 25 26 26 for (int i = 0; i < Math.Min(nodesAfter.Count, nodesBefore.Count); ++i) { 27 if (comparer.Equals(nodesAfter[i], nodesBefore[i])) continue; 27 var a = nodesAfter[i]; 28 var b = nodesBefore[i]; 29 if (ReferenceEquals(a, b) && comparer.Equals(a, b)) continue; 28 30 fragment = new Fragment<ISymbolicExpressionTreeNode> { 29 Root = nodesAfter[i],30 Index = i31 Root = a, 32 Index1 = i 31 33 }; 32 34 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeCrossoverOperator.cs
r10752 r10755 31 31 var result = base.Apply(); // the base operator will add the child to the graph before the actual crossover operation takes place 32 32 var parents = ParentsParameter.ActualValue.ToList(); 33 var childVertex = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[parents[0]] .Last(); // use the parent since it is actually the child before crossover (and the ChildParameter doesn't have a value yet)33 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) 34 34 var arcs = childVertex.InArcs.ToList(); 35 35 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs
r10677 r10755 7 7 public class SymbolicDataAnalysisExpressionBeforeManipulatorOperator : BeforeManipulatorOperator<ISymbolicExpressionTree> { 8 8 public override IOperation Apply() { 9 var result = base.Apply(); 9 var result = base.Apply(); // add the vertex in the genealogy graph 10 10 11 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue] .Last();12 vChild.InArcs.First().Data = vChild.Content.IterateNodes Breadth().ToList();11 var vChild = (IGenealogyGraphNode<ISymbolicExpressionTree>)GenealogyGraph[ChildParameter.ActualValue]; 12 vChild.InArcs.First().Data = vChild.Content.IterateNodesPrefix().ToList(); 13 13 14 14 return result; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs
r10752 r10755 1 1 2 using System; 2 3 using System.Collections.Generic; 3 4 using System.IO; … … 24 25 var index = subtreeIndex; // current index 25 26 var parent = parentNode; // current parent 27 26 28 while (true) { 29 if (!node.Parents.Any()) { 30 var fragmentNode = new FragmentNode { 31 Content = new Fragment<ISymbolicExpressionTreeNode> { Root = node.Content.NodeAt(index) }, 32 Rank = node.Rank 33 }; 34 if (parent != null) { 35 var arc = new GenealogyGraphArc { Source = parent, Target = fragmentNode }; 36 parent.AddForwardArc(arc); 37 // fragmentNode.Content.Index1 = parent.Content.Index1; 38 } 39 yield return fragmentNode; // no tracing if there are no parents 40 break; 41 } 42 43 if (node.IsElite) { 44 node = node.Parents.First(); 45 continue; 46 } // skip elite, go up the graph to original individual 47 27 48 var tree = node.Content; 28 49 var subtree = tree.NodeAt(index); 29 50 var subtreeLength = subtree.GetLength(); 30 var fragmentNode = new FragmentNode { 31 Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree }, 32 Rank = node.Rank 33 }; 34 if (parent != null) { 35 var arc = new GenealogyGraphArc { Source = parent, Target = fragmentNode }; 36 parent.AddForwardArc(arc); 37 } 38 parent = fragmentNode; 39 yield return fragmentNode; 40 if (!node.Parents.Any()) break; 41 if (node.IsElite) { 42 node = node.Parents.First(); 43 continue; 44 } 51 45 52 var fragment = (IFragment<ISymbolicExpressionTreeNode>)node.InArcs.Last().Data; 46 53 if (fragment == null) break; 47 54 var fragmentLength = fragment.Root.GetLength(); 48 if (fragment.Index == index) { 55 56 if (fragment.Index1 == index) { 49 57 node = node.Parents.Last(); // take second parent which contains the fragment 50 index = fragment.OldIndex; 51 } else if (fragment.Index < index) { 52 if (fragment.Index + fragmentLength > index) { // fragment contains subtree 53 node = node.Parents.Last(); // take second parent 54 index += fragment.OldIndex - fragment.Index; 55 } else { // fragment distinct from subtree 58 index = fragment.Index2; 59 } else if (fragment.Index1 < index) { 60 if (fragment.Index1 + fragmentLength > index) { 61 node = node.Parents.Last(); // fragment contains subtree, take second parent 62 index += fragment.Index2 - fragment.Index1; // the subtree has the same index relative to the fragment 63 } else { 64 // fragment distinct from subtree 56 65 node = node.Parents.First(); // take first parent which contains the subtree 57 index += node.Content.NodeAt(fragment.Index ).GetLength() - fragmentLength; // subtreeIndex must be adjusted according to swapped fragments sizes66 index += node.Content.NodeAt(fragment.Index1).GetLength() - fragmentLength; // subtreeIndex must be adjusted according to swapped fragments sizes 58 67 } 59 } else if (fragment.Index > index) { 60 if (fragment.Index < index + subtreeLength) { // subtree contains fragment => bifurcation point in the fragment graph 61 fragmentNode.Content.Index = fragment.Index - index; 68 } else if (fragment.Index1 > index) { 69 if (fragment.Index1 < index + subtreeLength) { 70 // subtree contains fragment => bifurcation point in the fragment graph 71 var fragmentNode = new FragmentNode { 72 Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree }, 73 Rank = node.Rank 74 }; 75 if (parent != null) { 76 var arc = new GenealogyGraphArc { Source = parent, Target = fragmentNode }; 77 parent.AddForwardArc(arc); 78 } 79 fragmentNode.Content.Index1 = fragment.Index1 - index; 80 yield return fragmentNode; 81 62 82 var left = Trace(node.Parents.First(), index, fragmentNode); // trace subtree 63 var right = Trace(node.Parents.Last(), fragment.OldIndex, fragmentNode); // trace fragment 64 foreach (var v in left.Concat(right)) { yield return v; } 83 84 if (node.Parents.Last().Content.NodeAt(fragment.Index2).GetLength() != fragmentLength) { 85 throw new Exception("Fragment lengths should match!"); 86 } 87 var right = Trace(node.Parents.Last(), fragment.Index2, fragmentNode); // trace fragment 88 foreach (var v in left.Concat(right)) { 89 yield return v; 90 } 65 91 break; 92 } else { 93 node = node.Parents.First(); // fragment distinct from subtree: update node, index remains unchanged 66 94 } 67 node = node.Parents.First(); // fragment distinct from subtree: update node, index remains unchanged68 95 } 69 96 }
Note: See TracChangeset
for help on using the changeset viewer.