Changeset 10838 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 05/11/14 21:17:30 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionTracing.cs
r10837 r10838 29 29 if (!node.Parents.Any()) { 30 30 var fragmentNode = new FragmentNode { 31 Content = new Fragment<ISymbolicExpressionTreeNode> { Root = node.Content.NodeAt(index) }, 31 Content = new Fragment<ISymbolicExpressionTreeNode> { 32 Root = node.Content.Root, 33 // Root = node.Content.NodeAt(index) 34 Index1 = index 35 }, 32 36 Rank = node.Rank, 33 37 Quality = node.Quality … … 36 40 var arc = new GenealogyGraphArc { Source = parent, Target = fragmentNode }; 37 41 parent.AddForwardArc(arc); 42 fragmentNode.AddReverseArc(parent); 38 43 } 39 44 yield return fragmentNode; // no tracing if there are no parents … … 41 46 } 42 47 var parents = node.Parents.ToList(); 43 if (node.IsElite) { 48 var fragment = (IFragment<ISymbolicExpressionTreeNode>)node.InArcs.Last().Data; 49 50 if (node.IsElite || fragment == null) { 44 51 // skip elite, go up the graph to original individual 45 node = parents[0];46 continue;47 }48 var fragment = (IFragment<ISymbolicExpressionTreeNode>)node.InArcs.Last().Data;49 if (fragment == null) {50 // the fragment can be null when crossover or mutation did not actually make any change => then we skip51 52 node = parents[0]; 52 53 continue; … … 60 61 // we are tracing a mutation operation 61 62 var fragmentNode = new FragmentNode { 62 Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree }, 63 Content = new Fragment<ISymbolicExpressionTreeNode> { 64 Root = tree.Root, 65 // Root = subtree 66 Index1 = index, 67 Index2 = fragment.Index1 68 }, 63 69 Rank = node.Rank, 64 70 Quality = node.Quality … … 67 73 var arc = new GenealogyGraphArc { Source = parent, Target = fragmentNode }; 68 74 parent.AddForwardArc(arc); 75 fragmentNode.AddReverseArc(parent); 69 76 } 70 77 yield return fragmentNode; … … 98 105 // subtree contains fragment => bifurcation point in the fragment graph 99 106 var fragmentNode = new FragmentNode { 100 Content = new Fragment<ISymbolicExpressionTreeNode> { Root = subtree }, 107 Content = new Fragment<ISymbolicExpressionTreeNode> { 108 Root = tree.Root, 109 Index1 = index, 110 Index2 = fragment.Index1 111 }, 101 112 Rank = node.Rank, 102 113 Quality = node.Quality … … 105 116 var arc = new GenealogyGraphArc { Source = parent, Target = fragmentNode }; 106 117 parent.AddForwardArc(arc); 118 fragmentNode.AddReverseArc(parent); 107 119 } 108 fragmentNode.Content.Index1 = fragment.Index1 - index;120 // fragmentNode.Content.Index1 = fragment.Index1 - index; 109 121 yield return fragmentNode; 110 122 … … 131 143 } 132 144 #region some helper methods for shortening the tracing code 133 private static void AddChild(this IGenealogyGraphNode parent, IGenealogyGraphNode child) {134 parent.AddForwardArc(child);135 child.AddReverseArc(parent);136 child.Rank = parent.Rank - 1;137 }138 145 private static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTree tree, int position) { 139 146 return NodeAt(tree.Root, position); … … 142 149 return root.IterateNodesPrefix().ElementAt(position); 143 150 } 144 private static int IndexOf(this ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode node) {145 return IndexOf(tree.Root, node);146 }147 private static int IndexOf(this ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode node) {148 int i = 0;149 foreach (var n in root.IterateNodesPrefix()) {150 if (n == node) return i;151 ++i;152 }153 return -1;154 }155 151 #endregion 156 152 }
Note: See TracChangeset
for help on using the changeset viewer.