Changeset 7514 for branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators
- Timestamp:
- 02/24/12 10:58:22 (13 years ago)
- Location:
- branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
-
Property
svn:ignore
set to
bin
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding merged eligible /trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTree 3219-3222
-
Property
svn:ignore
set to
-
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
-
Property
svn:ignore
set to
bin
obj
HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin.cs
*.user
*.vs10x
Plugin.cs
-
Property
svn:ignore
set to
-
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ChangeNodeTypeManipulation.cs
r7439 r7514 28 28 [StorableClass] 29 29 [Item("ChangeNodeTypeManipulation", "Selects a random tree node and changes the symbol.")] 30 public sealed class ChangeNodeTypeManipulation : SymbolicExpressionTreeManipulator {30 public sealed class ChangeNodeTypeManipulation : TracingSymbolicExpressionTreeManipulator { 31 31 [StorableConstructor] 32 32 private ChangeNodeTypeManipulation(bool deserializing) : base(deserializing) { } -
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/OnePointShaker.cs
r7439 r7514 31 31 [StorableClass] 32 32 [Item("OnePointShaker", "Selects a random node with local parameters and manipulates the selected node.")] 33 public sealed class OnePointShaker : SymbolicExpressionTreeManipulator {33 public sealed class OnePointShaker : TracingSymbolicExpressionTreeManipulator { 34 34 private const string ShakingFactorParameterName = "ShakingFactor"; 35 35 #region parameter properties -
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs
r7439 r7514 30 30 [StorableClass] 31 31 [Item("ReplaceBranchManipulation", "Selects a branch of the tree randomly and replaces it with a newly initialized branch (using PTC2).")] 32 public sealed class ReplaceBranchManipulation : SymbolicExpressionTreeManipulator, ISymbolicExpressionTreeSizeConstraintOperator {32 public sealed class ReplaceBranchManipulation : TracingSymbolicExpressionTreeManipulator, ISymbolicExpressionTreeSizeConstraintOperator { 33 33 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 34 34 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; -
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/TracingSymbolicExpressionTreeManipulator.cs
r7479 r7514 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 25 using HeuristicLab.Parameters; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 using CloneMapType = HeuristicLab.Core.ItemDictionary<HeuristicLab.Core.IItem, HeuristicLab.Core.IItem>; 29 using TraceMapType = HeuristicLab.Core.ItemDictionary<HeuristicLab.Core.IItem, HeuristicLab.Core.IItemList<HeuristicLab.Core.IItem>>; 27 30 28 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 34 37 public abstract class TracingSymbolicExpressionTreeManipulator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeManipulator { 35 38 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 36 private const string GlobalTrace CacheParameterName = "GlobalTraceCache";37 private const string Global TreeMapParameterName = "GlobalTreeMap";39 private const string GlobalTraceMapParameterName = "GlobalTraceMap"; 40 private const string GlobalCloneMapParameterName = "GlobalCloneMap"; 38 41 39 42 #region Parameter Properties … … 41 44 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 42 45 } 43 public LookupParameter<ItemDictionary<ISymbolicExpressionTree, ISymbolicExpressionTree>> GlobalTreeMapParameter { 44 get { 45 return (LookupParameter<ItemDictionary<ISymbolicExpressionTree, ISymbolicExpressionTree>>)Parameters[GlobalTreeMapParameterName]; 46 } 46 public LookupParameter<CloneMapType> GlobalCloneMapParameter { 47 get { return (LookupParameter<CloneMapType>)Parameters[GlobalCloneMapParameterName]; } 48 } 49 public LookupParameter<TraceMapType> GlobalTraceMapParameter { 50 get { return (LookupParameter<TraceMapType>)Parameters[GlobalTraceMapParameterName]; } 47 51 } 48 52 #endregion … … 52 56 get { return SymbolicExpressionTreeParameter.ActualValue; } 53 57 } 54 public ItemDictionary<ISymbolicExpressionTree, ISymbolicExpressionTree> GlobalTreeMap { 55 get { return GlobalTreeMapParameter.ActualValue; } 58 public CloneMapType GlobalCloneMap { 59 get { return GlobalCloneMapParameter.ActualValue; } 60 } 61 public TraceMapType GlobalTraceMap { 62 get { return GlobalTraceMapParameter.ActualValue; } 56 63 } 57 64 #endregion … … 63 70 : base() { 64 71 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree on which the operator should be applied.")); 65 Parameters.Add(new LookupParameter<ItemDictionary<ISymbolicExpressionTree, ISymbolicExpressionTree>>(GlobalTreeMapParameterName, "A global map keeping track of trees and their clones (made during selection).")); 72 Parameters.Add(new LookupParameter<CloneMapType>(GlobalCloneMapParameterName, "A global map keeping track of trees and their clones (made during selection).")); 73 Parameters.Add(new LookupParameter<TraceMapType>(GlobalTraceMapParameterName, "A global cache containing tracing info.")); 66 74 } 67 75 … … 69 77 ISymbolicExpressionTree tree = SymbolicExpressionTreeParameter.ActualValue; 70 78 79 if (GlobalTraceMap == null) { 80 var gScope = ExecutionContext.Scope; 81 while (gScope.Parent != null) gScope = gScope.Parent; 82 gScope.Variables.Add(new Variable(GlobalTraceMapParameterName, new TraceMapType())); 83 } 84 if (GlobalTraceMap.ContainsKey(tree)) { 85 // 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". 87 // In order to preserve information, a tree clone is created before mutation and added to the trace map. 88 var clone = (IItem)tree.Clone(); 89 GlobalTraceMap[clone] = GlobalTraceMap[tree]; 90 GlobalTraceMap[tree] = new ItemList<IItem> { clone }; 91 } else { 92 var original = GlobalCloneMap[tree]; 93 GlobalTraceMap[tree] = new ItemList<IItem> { original }; 94 } 71 95 Manipulate(RandomParameter.ActualValue, tree); 72 96 73 //AddTraceInfoToGlobalCache();74 75 97 return base.Apply(); 76 }77 78 private void AddTraceInfoToGlobalCache() {79 var globalScope = ExecutionContext.Scope;80 while (globalScope.Parent != null) globalScope = globalScope.Parent;81 82 Variable globalTraceCache;83 if (!globalScope.Variables.ContainsKey(GlobalTraceCacheParameterName)) {84 globalTraceCache = new Variable(GlobalTraceCacheParameterName, new ItemDictionary<ISymbolicExpressionTree, IItemArray<ISymbolicExpressionTree>>());85 globalScope.Variables.Add(globalTraceCache);86 } else87 globalTraceCache = (Variable)globalScope.Variables[GlobalTraceCacheParameterName];88 89 var traceCache = (ItemDictionary<ISymbolicExpressionTree, IItemArray<ISymbolicExpressionTree>>)globalTraceCache.Value;90 91 traceCache.Add(SymbolicExpressionTree, new ItemArray<ISymbolicExpressionTree>(new[] { GlobalTreeMap[SymbolicExpressionTree] }));92 98 } 93 99
Note: See TracChangeset
for help on using the changeset viewer.