Changeset 11493 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 10/24/14 16:02:59 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/BuildingBlockAnalyzers/SymbolicDataAnalysisPoly10Analyzer.cs
r11462 r11493 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using HeuristicLab.Operators;30 29 using HeuristicLab.Optimization; 31 30 using HeuristicLab.Parameters; … … 37 36 [Item("Poly-10 building blocks analyzer", "An analyzer which attempts to identify parts of the Poly-10 formula")] 38 37 [StorableClass] 39 public class SymbolicDataAnalysisPoly10Analyzer : SingleSuccessorOperator, ISymbolicDataAnalysisAnalyzer { 40 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 41 private const string ResultCollectionParameterName = "Results"; 38 public class SymbolicDataAnalysisPoly10Analyzer : SymbolicDataAnalysisAnalyzer { 42 39 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 43 40 private const string ProblemDataParameterName = "ProblemData"; … … 60 57 } 61 58 62 public IScopeTreeLookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {63 get { return (IScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }64 }65 66 public ILookupParameter<ResultCollection> ResultCollectionParameter {67 get { return (ILookupParameter<ResultCollection>)Parameters[ResultCollectionParameterName]; }68 }69 70 59 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { 71 60 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; } … … 108 97 public SymbolicDataAnalysisPoly10Analyzer() { 109 98 #region Add parameters 110 Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName));111 Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName));112 99 Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName)); 113 100 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName)); … … 132 119 } 133 120 134 public bool EnabledByDefault {121 new public bool EnabledByDefault { 135 122 get { return false; } 136 123 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
r11476 r11493 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 24 using System.Diagnostics; 3 25 using System.Linq; 4 26 using HeuristicLab.Common; … … 73 95 } 74 96 75 int fragmentLength = fragment.Root.GetLength(); 76 int subtreeLength = g.Data.NodeAt(si).GetLength(); 97 int fi = fragment.Index1; // fragment index 98 int fl = fragment.Root.GetLength(); // fragment length 99 int sl = g.Data.NodeAt(si).GetLength(); // subtree length 77 100 78 101 #region trace crossover 79 102 if (parents.Count == 2) { 80 if (f ragment.Index1== si) {103 if (fi == si) { 81 104 g = parents[1]; 82 105 si = fragment.Index2; 83 106 continue; 84 107 } 85 if (f ragment.Index1< si) {86 if (f ragment.Index1 + fragmentLength> si) {108 if (fi < si) { 109 if (fi + fl > si) { 87 110 // fragment contains subtree 88 111 g = parents[1]; 89 si += fragment.Index2 - f ragment.Index1;112 si += fragment.Index2 - fi; 90 113 } else { 91 114 // fragment distinct from subtree 92 115 g = parents[0]; 93 si += g.Data.NodeAt(f ragment.Index1).GetLength() - fragmentLength;116 si += g.Data.NodeAt(fi).GetLength() - fl; 94 117 } 95 118 continue; 96 119 } 97 if (f ragment.Index1> si) {98 if (f ragment.Index1 < si + subtreeLength) {120 if (fi > si) { 121 if (fi < si + sl) { 99 122 // subtree contains fragment => branching point in the fragment graph 100 var n = traceGraph.GetByContent(g.Data); 101 if (n == null) { 102 n = g.Copy(); 103 traceGraph.AddVertex(n); 104 traceMap[n] = new Tuple<int, int>(si, fragment.Index1); 105 } 106 123 var n = GetTraceNode(g, si, fi); 107 124 Trace(parents[0], si, n); 108 125 Trace(parents[1], fragment.Index2, n); … … 117 134 #endregion 118 135 #region trace mutation 136 // mutation is handled in a simple way: we branch every time there is an overlap between the subtree and the fragment 137 // (since mutation effects can be quite unpredictable: replace branch, change node, shake tree, etc) 119 138 if (parents.Count == 1) { 120 if (si == fragment.Index1) { 121 // fragment and subtree coincide 122 // since mutation can potentially alter trees quite drastically, we branch here, 123 // in order not to miss any changes 124 var n = traceGraph.GetByContent(g.Data); 125 if (n == null) { 126 n = g.Copy(); 127 traceGraph.AddVertex(n); 128 traceMap[n] = new Tuple<int, int>(si, fragment.Index1); 129 } 130 Trace(parents[0], si, n); 139 Debug.Assert(fragment.Index1 == fragment.Index2); 140 // check if the subtree and the fragment overlap => branch out 141 if ((si == fi) || (si < fi && fi < si + sl) || (fi < si && si < fi + fl)) { 142 var n = GetTraceNode(g, si, fi); 143 int i = si < fi ? si : fi; 144 Trace(parents[0], i, n); 131 145 break; 132 } 133 if (fragment.Index1 < si) { 134 if (si < fragment.Index1 + fragmentLength) { 135 // fragment contains subtree 136 g = parents[0]; 137 si = fragment.Index2; 138 } else { 139 // fragment and subtree are distinct 140 // since the fragment occurs before the subtree in the prefix node ordering 141 // the subtree index must be adjusted according to the fragment length 142 g = parents[0]; 143 si += g.Data.NodeAt(fragment.Index1).GetLength() - fragmentLength; 144 } 146 } else { 147 // if they don't overlap, go up 148 g = parents[0]; 149 if (fi < si) 150 si += g.Data.NodeAt(fi).GetLength() - fl; 145 151 continue; 146 }147 if (si < fragment.Index1) {148 // subtree occurs before fragment in the prefix node ordering149 if (fragment.Index1 < si + subtreeLength) {150 // subtree contains fragment, we are interested to see what the subtree looked like before151 // but we also want to keep track of what it looks like now, therefore we branch here152 var n = traceGraph.GetByContent(g.Data);153 if (n == null) {154 n = g.Copy();155 traceGraph.AddVertex(n);156 traceMap[n] = new Tuple<int, int>(si, fragment.Index1);157 }158 Trace(parents[0], si, n);159 break;160 } else {161 // fragment and subtree are distinct, subtree index stays the same162 // since the subtree comes before the fragment in the prefix node ordering163 g = parents[0];164 continue;165 }166 152 } 167 153 } … … 171 157 // when we are out of the while the last vertex must be connected with the current one 172 158 ConnectLast(g, si, last); 159 } 160 161 /// <summary> 162 /// Get the trace node from the trace graph which corresponds to node g from the genealogy graph. 163 /// If the trace graph does not contain such a node, one is created by performing a shallow copy of g, then inserted into the trace graph. 164 /// </summary> 165 /// <param name="g">The genealogy graph node</param> 166 /// <param name="si">The subtree index</param> 167 /// <param name="fi">The fragment index</param> 168 /// <returns></returns> 169 private IGenealogyGraphNode<ISymbolicExpressionTree> GetTraceNode(IGenealogyGraphNode<ISymbolicExpressionTree> g, int si, int fi) { 170 var n = traceGraph.GetByContent(g.Data); 171 if (n == null) { 172 n = g.Copy(); 173 traceGraph.AddVertex(n); 174 Debug.Assert(!traceMap.ContainsKey(n)); 175 traceMap[n] = new Tuple<int, int>(si, fi); 176 } 177 return n; 173 178 } 174 179
Note: See TracChangeset
for help on using the changeset viewer.