Changeset 7792 for branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/TracingSymbolicExpressionTreeManipulator.cs
- Timestamp:
- 05/10/12 17:17:14 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/TracingSymbolicExpressionTreeManipulator.cs
r7514 r7792 21 21 22 22 using System; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 25 27 using HeuristicLab.Parameters; 26 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 39 41 private const string GlobalTraceMapParameterName = "GlobalTraceMap"; 40 42 private const string GlobalCloneMapParameterName = "GlobalCloneMap"; 43 private const string GlobalFragmentMapParameterName = "GlobalFragmentMap"; 41 44 42 45 #region Parameter Properties … … 49 52 public LookupParameter<TraceMapType> GlobalTraceMapParameter { 50 53 get { return (LookupParameter<TraceMapType>)Parameters[GlobalTraceMapParameterName]; } 54 } 55 public LookupParameter<CloneMapType> GlobalFragmentMapParameter { 56 get { return (LookupParameter<CloneMapType>)Parameters[GlobalFragmentMapParameterName]; } 51 57 } 52 58 #endregion … … 62 68 get { return GlobalTraceMapParameter.ActualValue; } 63 69 } 70 public CloneMapType GlobalFragmentMap { 71 get { return GlobalFragmentMapParameter.ActualValue; } 72 } 64 73 #endregion 65 74 … … 72 81 Parameters.Add(new LookupParameter<CloneMapType>(GlobalCloneMapParameterName, "A global map keeping track of trees and their clones (made during selection).")); 73 82 Parameters.Add(new LookupParameter<TraceMapType>(GlobalTraceMapParameterName, "A global cache containing tracing info.")); 83 Parameters.Add(new LookupParameter<CloneMapType>(GlobalFragmentMapParameterName, "A global map keeping track of tree fragments received via crossover.")); 74 84 } 75 85 … … 77 87 ISymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue; 78 88 79 if (GlobalTraceMap == null) { 80 var gScope = ExecutionContext.Scope; 81 while (gScope.Parent != null) gScope = gScope.Parent; 89 var gScope = ExecutionContext.Scope; 90 while (gScope.Parent != null) 91 gScope = gScope.Parent; 92 93 if (GlobalTraceMap == null) 82 94 gScope.Variables.Add(new Variable(GlobalTraceMapParameterName, new TraceMapType())); 83 } 95 if (GlobalFragmentMap == null) 96 gScope.Variables.Add(new Variable(GlobalFragmentMapParameterName, new CloneMapType())); 97 84 98 if (GlobalTraceMap.ContainsKey(tree)) { 85 99 // tree was affected by crossover before mutation 86 // if the tree to be manipulated is already a product of crossover (in the current reproduction phase), then there exists no relationship with the original "parent". 100 // if the tree to be manipulated is already a product of crossover (in the current reproduction phase), 101 // then there exists no relationship with the original "parent". 87 102 // In order to preserve information, a tree clone is created before mutation and added to the trace map. 88 103 var clone = (IItem)tree.Clone(); 89 104 GlobalTraceMap[clone] = GlobalTraceMap[tree]; 90 105 GlobalTraceMap[tree] = new ItemList<IItem> { clone }; 106 GlobalFragmentMap[clone] = GlobalFragmentMap[tree]; 91 107 } else { 92 108 var original = GlobalCloneMap[tree]; 93 109 GlobalTraceMap[tree] = new ItemList<IItem> { original }; 94 110 } 111 var nodes0 = tree.IterateNodesBreadth().ToList(); 95 112 Manipulate(RandomParameter.ActualValue, tree); 113 var nodes1 = tree.IterateNodesBreadth().ToList(); 114 int i, min = Math.Max(nodes0.Count, nodes1.Count); 115 for (i = 0; i != min; ++i) 116 if (nodes0[i] != nodes1[i]) break; 117 if (i == min) i = 0; 118 GlobalFragmentMap[tree] = new IntValue(i); 96 119 97 120 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.