Changeset 11881 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking
- Timestamp:
- 02/04/15 00:43:44 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
r11866 r11881 58 58 tc.Trace(node, subtreeIndex); 59 59 return tc.TraceGraph; 60 }61 62 public IGenealogyGraph<ISymbolicExpressionTree> PartialTrace(IGenealogyGraphNode<ISymbolicExpressionTree> node,63 int subtreeIndex, ISymbolicExpressionTreeNode subtree) {64 traceGraph = new GenealogyGraph<ISymbolicExpressionTree>();65 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, TraceData>();66 return null;67 60 } 68 61 … … 97 90 private void TraceRecursive(IGenealogyGraphNode<ISymbolicExpressionTree> node, int subtreeIndex, IGenealogyGraphNode<ISymbolicExpressionTree> last = null) { 98 91 var g = node; 99 int si = subtreeIndex; 92 int si = subtreeIndex; // subtree index 93 int fi = 0; // fragment index 100 94 while (g.Parents.Any()) { 101 95 Debug.Assert(si < g.Data.Length); … … 109 103 } 110 104 111 intfi = fragment.Index1; // fragment index105 fi = fragment.Index1; // fragment index 112 106 int fl = fragment.Root.GetLength(); // fragment length 113 107 int sl = NodeAt(g.Data, si).GetLength(); // subtree length … … 137 131 if (fi < si + sl) { 138 132 // subtree contains fragment => branching point in the fragment graph 139 var n = GetTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent133 var n = AddTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent 140 134 TraceRecursive(parent0, si, n); 141 135 TraceRecursive(parent1, fragment.Index2, n); … … 157 151 // check if the subtree and the fragment overlap => branch out 158 152 if ((si == fi) || (si < fi && fi < si + sl) || (fi < si && si < fi + fl)) { 159 var n = GetTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent153 var n = AddTraceNode(g, si, fi); // current node becomes "last" as we restart tracing from the parent 160 154 int i = si < fi ? si : fi; 161 155 TraceRecursive(parent0, i, n); … … 173 167 } 174 168 // when we are out of the while the last vertex must be connected with the current one 175 ConnectLast(g, si, last); 169 // if there is no last vertex, it means the tracing reached the top of the genealogy graph 170 var current = AddTraceNode(g, si, fi); 171 if (last != null) 172 ConnectLast(current, last, si, fi); 176 173 } 177 174 … … 184 181 /// <param name="fi">The fragment index</param> 185 182 /// <returns></returns> 186 private IGenealogyGraphNode<ISymbolicExpressionTree> GetTraceNode(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, int fi) {183 private IGenealogyGraphNode<ISymbolicExpressionTree> AddTraceNode(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, int fi) { 187 184 var n = traceGraph.GetByContent(g.Data); 188 185 if (n == null) { … … 211 208 /// of the genealogy graph node @g. 212 209 /// </summary> 213 /// <param name="g">The current node in the genealogy graph</param> 210 /// <param name="current">The current node in the genealogy graph</param> 211 /// <param name="last">The last added node in the trace graph</param> 214 212 /// <param name="si">The index of the traced subtree</param> 215 /// <param name="last">The last added node in the trace graph</param> 216 private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, IGenealogyGraphNode<ISymbolicExpressionTree> last) { 217 var inArcs = (List<IArc>)((IVertex)g).InArcs; 218 var fragment = g.Parents.Any() ? (IFragment<ISymbolicExpressionTreeNode>)inArcs.Last().Data : null; 219 int fi = fragment == null ? 0 : fragment.Index1; // fragment index 220 var n = GetTraceNode(g, si, fi); // will append n to the trace graph if it does not exist 221 if (last == null) 222 return; 213 /// <param name="fi">The index of the fragment</param> 214 private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> current, IGenealogyGraphNode<ISymbolicExpressionTree> last, int si, int fi) { 223 215 var lastTraceData = traceMap[last]; 224 216 int lastSi = lastTraceData.SubtreeIndex; // last subtree index (index of the traced subtree in the previous trace node) 225 217 int lastFi = lastTraceData.FragmentIndex; // last fragment index (index of the fragment in the previous trace node) 226 218 var td = new TraceData(si, fi, lastSi, lastFi); // trace data 227 var arc = n.OutArcs.SingleOrDefault(a => a.Target == last && a.Data.Equals(td));219 var arc = current.OutArcs.SingleOrDefault(a => a.Target == last && a.Data.Equals(td)); 228 220 if (arc == null) { 229 arc = new GenealogyGraphArc( n, last) { Data = td };221 arc = new GenealogyGraphArc(current, last) { Data = td }; 230 222 traceGraph.AddArc(arc); 231 223 } … … 233 225 } 234 226 // this class is here to help clarify the semantics 235 internalclass TraceData : Tuple<int, int, int, int> {227 public class TraceData : Tuple<int, int, int, int> { 236 228 public TraceData(int currentSubtreeIndex, int currentFragmentIndex, int lastSubtreeIndex, int lastFragmentIndex) 237 229 : base(currentSubtreeIndex, currentFragmentIndex, lastSubtreeIndex, lastFragmentIndex) {
Note: See TracChangeset
for help on using the changeset viewer.