Changeset 11855 for branches/HeuristicLab.EvolutionTracking
- Timestamp:
- 02/02/15 13:17:23 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs
r11694 r11855 47 47 // the cloning will also clone the vertex data object, therefore reference comparison of node lists will not work 48 48 // 2) replaces the parent of the current individual with the clone, and alters graph connections accordingly 49 // therefore, vChild will be the vertex of the child, and vClone the vertex ofthe cloned parent49 // so that vChild vertex will represent the child, and vClone will represent the cloned parent 50 50 var result = base.Apply(); 51 51 var vChild = GenealogyGraph.GetByContent(ChildParameter.ActualValue); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
r11852 r11855 36 36 private IGenealogyGraph<ISymbolicExpressionTree> traceGraph; 37 37 private Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>> traceMap; 38 private Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>> nodeListCache; 38 39 39 40 public IGenealogyGraph<ISymbolicExpressionTree> TraceGraph { get { return traceGraph; } } … … 42 43 traceGraph = new GenealogyGraph<ISymbolicExpressionTree>(); 43 44 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>>(); 45 nodeListCache = new Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>>(); 44 46 } 45 47 … … 68 70 traceGraph = new GenealogyGraph<ISymbolicExpressionTree>(); 69 71 traceMap = new Dictionary<IGenealogyGraphNode<ISymbolicExpressionTree>, Tuple<int, int>>(); 72 nodeListCache = new Dictionary<ISymbolicExpressionTree, List<ISymbolicExpressionTreeNode>>(); 70 73 TraceRecursive(node, subtreeIndex); 71 74 return traceGraph; … … 100 103 var fragment = (IFragment<ISymbolicExpressionTreeNode>)g.InArcs.Last().Data; 101 104 if (fragment == null) { 102 // if (parents.Count == 2) 103 // throw new Exception("There should always be a crossover fragment."); 105 // TODO: think about what the correct behavior should be here (seems good so far) 104 106 // the node is either an elite node or (in rare cases) no fragment was transferred 105 107 g = parents[0]; … … 109 111 int fi = fragment.Index1; // fragment index 110 112 int fl = fragment.Root.GetLength(); // fragment length 111 int sl = g.Data.NodeAt(si).GetLength(); // subtree length113 int sl = NodeAt(g.Data, si).GetLength(); // subtree length 112 114 113 115 #region trace crossover … … 126 128 // fragment distinct from subtree 127 129 g = parents[0]; 128 si += g.Data.NodeAt(fi).GetLength() - fl;130 si += NodeAt(g.Data, fi).GetLength() - fl; 129 131 } 130 132 continue; … … 160 162 g = parents[0]; 161 163 if (fi < si) 162 si += g.Data.NodeAt(fi).GetLength() - fl;164 si += NodeAt(g.Data, fi).GetLength() - fl; 163 165 continue; 164 166 } … … 188 190 } 189 191 return n; 192 } 193 194 // caching node lists brings ~2.5-2.7x speed improvement (since graph nodes are visited multiple times) 195 // this caching will be even more effective with larger tree sizes 196 private ISymbolicExpressionTreeNode NodeAt(ISymbolicExpressionTree tree, int index) { 197 List<ISymbolicExpressionTreeNode> list; 198 nodeListCache.TryGetValue(tree, out list); 199 if (list == null) { 200 list = tree.IterateNodesPrefix().ToList(); 201 nodeListCache[tree] = list; 202 } 203 return list[index]; 190 204 } 191 205 … … 221 235 return new GenealogyGraphNode<ISymbolicExpressionTree>(node.Data) { Rank = node.Rank, Quality = node.Quality }; 222 236 } 223 public static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTree tree, int index) {224 return NodeAt(tree.Root, index);225 }226 public static ISymbolicExpressionTreeNode NodeAt(this ISymbolicExpressionTreeNode root, int index) {227 return root.IterateNodesPrefix().ElementAt(index);228 }229 237 #endregion 230 238 }
Note: See TracChangeset
for help on using the changeset viewer.