Changeset 4674
- Timestamp:
- 10/29/10 18:55:22 (14 years ago)
- Location:
- branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3
- Files:
-
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Analyzers/MinAverageMaxSymbolicExpressionTreeSizeAnalyzer.cs
r4068 r4674 65 65 66 66 #endregion 67 [StorableConstructor] 68 private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(bool deserializing) : base() { } 69 protected MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(MinAverageMaxSymbolicExpressionTreeSizeAnalyzer original, Cloner cloner) 70 : base(original, cloner) { 71 AfterDeserialization(); 72 } 67 73 public MinAverageMaxSymbolicExpressionTreeSizeAnalyzer() 68 74 : base() { … … 95 101 valueAnalyzer.Successor = null; 96 102 97 Initialize();103 AfterDeserialization(); 98 104 } 99 105 100 [StorableConstructor]101 private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(bool deserializing) : base() { }102 106 103 107 [StorableHook(HookType.AfterDeserialization)] 104 private void Initialize() {108 private void AfterDeserialization() { 105 109 SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged); 106 110 SymbolicExpressionTreeSizeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeSizeParameter_DepthChanged); … … 108 112 109 113 public override IDeepCloneable Clone(Cloner cloner) { 110 MinAverageMaxSymbolicExpressionTreeSizeAnalyzer clone = (MinAverageMaxSymbolicExpressionTreeSizeAnalyzer)base.Clone(cloner); 111 clone.Initialize(); 112 return clone; 114 return new MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(this, cloner); 113 115 } 114 116 -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Analyzers/SymbolicExpressionTreeSizeCalculator.cs
r4068 r4674 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; … … 55 56 #endregion 56 57 58 [StorableConstructor] 59 private SymbolicExpressionTreeSizeCalculator(bool deserializing) : base(deserializing) { } 60 private SymbolicExpressionTreeSizeCalculator(SymbolicExpressionTreeSizeCalculator original, Cloner cloner) : base(original, cloner) { } 57 61 public SymbolicExpressionTreeSizeCalculator() 58 62 : base() { … … 66 70 return base.Apply(); 67 71 } 72 73 public override IDeepCloneable Clone(Cloner cloner) { 74 return new SymbolicExpressionTreeSizeCalculator(this, cloner); 75 } 68 76 } 69 77 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/ArgumentCreater.cs
r4524 r4674 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; 25 27 using HeuristicLab.Data; 26 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 27 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System;29 30 30 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators { … … 36 37 [StorableClass] 37 38 public sealed class ArgumentCreater : SymbolicExpressionTreeArchitectureManipulator { 39 [StorableConstructor] 40 private ArgumentCreater(bool deserializing) : base(deserializing) { } 41 private ArgumentCreater(ArgumentCreater original, Cloner cloner) : base(original, cloner) { } 42 public ArgumentCreater() : base() { } 38 43 public override sealed void ModifyArchitecture( 39 44 IRandom random, … … 44 49 out bool success) { 45 50 success = CreateNewArgument(random, symbolicExpressionTree, grammar, maxTreeSize.Value, maxTreeHeight.Value, maxFunctionDefiningBranches.Value, maxFunctionArguments.Value); 51 } 52 53 public override IDeepCloneable Clone(Cloner cloner) { 54 return new ArgumentCreater(this, cloner); 46 55 } 47 56 … … 91 100 } 92 101 } 93 94 102 95 103 private static bool CreateNewArgumentForDefun(IRandom random, SymbolicExpressionTree tree, DefunTreeNode defunBranch, ArgumentTreeNode newArgumentNode) { -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/ArgumentDeleter.cs
r4068 r4674 21 21 22 22 using System.Linq; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Data; … … 33 34 [StorableClass] 34 35 public sealed class ArgumentDeleter : SymbolicExpressionTreeArchitectureManipulator { 36 [StorableConstructor] 37 private ArgumentDeleter(bool deserializing) : base(deserializing) { } 38 private ArgumentDeleter(ArgumentDeleter original, Cloner cloner) : base(original, cloner) { } 39 public ArgumentDeleter() : base() { } 40 35 41 public override sealed void ModifyArchitecture( 36 42 IRandom random, … … 41 47 out bool success) { 42 48 success = DeleteArgument(random, symbolicExpressionTree, grammar, maxTreeSize.Value, maxTreeHeight.Value, maxFunctionDefiningBranches.Value, maxFunctionArguments.Value); 49 } 50 51 public override IDeepCloneable Clone(Cloner cloner) { 52 return new ArgumentDeleter(this, cloner); 43 53 } 44 54 -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/ArgumentDuplicater.cs
r4524 r4674 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using System.Linq; 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Core; 24 27 using HeuristicLab.Data; 25 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 26 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using System.Collections.Generic;28 using System;29 30 30 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators { … … 36 37 [StorableClass] 37 38 public sealed class ArgumentDuplicater : SymbolicExpressionTreeArchitectureManipulator { 39 [StorableConstructor] 40 private ArgumentDuplicater(bool deserializing) : base(deserializing) { } 41 private ArgumentDuplicater(ArgumentDuplicater original, Cloner cloner) : base(original, cloner) { } 42 public ArgumentDuplicater() : base() { } 43 38 44 public override sealed void ModifyArchitecture( 39 45 IRandom random, … … 44 50 out bool success) { 45 51 success = DuplicateArgument(random, symbolicExpressionTree, grammar, maxTreeSize.Value, maxTreeHeight.Value, maxFunctionDefiningBranches.Value, maxFunctionArguments.Value); 52 } 53 54 public override IDeepCloneable Clone(Cloner cloner) { 55 return new ArgumentDuplicater(this, cloner); 46 56 } 47 57 -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/MultiSymbolicExpressionTreeArchitectureManipulator.cs
r4068 r4674 23 23 using System.Linq; 24 24 using HeuristicLab.Collections; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Data; … … 35 36 [Item("MultiSymbolicExpressionTreeArchitectureManipulator", "Randomly selects and applies one of its architecture manipulators every time it is called.")] 36 37 [StorableClass] 37 public class MultiSymbolicExpressionTreeArchitectureManipulator : StochasticMultiBranch<ISymbolicExpressionTreeArchitectureManipulator>, ISymbolicExpressionTreeArchitectureManipulator, IStochasticOperator {38 public sealed class MultiSymbolicExpressionTreeArchitectureManipulator : StochasticMultiBranch<ISymbolicExpressionTreeArchitectureManipulator>, ISymbolicExpressionTreeArchitectureManipulator, IStochasticOperator { 38 39 private const string MaxTreeSizeParameterName = "MaxTreeSize"; 39 40 private const string MaxTreeHeightParameterName = "MaxTreeHeight"; … … 46 47 get { return false; } 47 48 } 48 pr otectedoverride bool CreateChildOperation {49 private override bool CreateChildOperation { 49 50 get { return true; } 50 51 } … … 57 58 } 58 59 #endregion 59 60 60 61 61 #region ISymbolicExpressionTreeManipulator Members … … 80 80 [StorableConstructor] 81 81 private MultiSymbolicExpressionTreeArchitectureManipulator(bool deserializing) : base(deserializing) { } 82 private MultiSymbolicExpressionTreeArchitectureManipulator(MultiSymbolicExpressionTreeArchitectureManipulator original, Cloner cloner) : base(original, cloner) { } 82 83 public MultiSymbolicExpressionTreeArchitectureManipulator() 83 84 : base() { … … 95 96 } 96 97 97 protected override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeArchitectureManipulator>> e) { 98 public override IDeepCloneable Clone(Cloner cloner) { 99 return new MultiSymbolicExpressionTreeArchitectureManipulator(this, cloner); 100 } 101 102 private override void Operators_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeArchitectureManipulator>> e) { 98 103 base.Operators_ItemsReplaced(sender, e); 99 104 ParameterizeManipulators(); 100 105 } 101 106 102 pr otectedoverride void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeArchitectureManipulator>> e) {107 private override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeArchitectureManipulator>> e) { 103 108 base.Operators_ItemsAdded(sender, e); 104 109 ParameterizeManipulators(); -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/SubroutineCreater.cs
r4249 r4674 24 24 using System.Linq; 25 25 using System.Text; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; … … 39 40 public sealed class SubroutineCreater : SymbolicExpressionTreeArchitectureManipulator { 40 41 private const double ARGUMENT_CUTOFF_PROBABILITY = 0.05; 42 43 [StorableConstructor] 44 private SubroutineCreater(bool deserializing) : base(deserializing) { } 45 private SubroutineCreater(SubroutineCreater original, Cloner cloner) : base(original, cloner) { } 46 public SubroutineCreater() : base() { } 47 48 public override IDeepCloneable Clone(Cloner cloner) { 49 return new SubroutineCreater(this, cloner); 50 } 41 51 42 52 public override sealed void ModifyArchitecture( -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/SubroutineDeleter.cs
r4068 r4674 22 22 using System; 23 23 using System.Linq; 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Data; … … 36 37 [StorableClass] 37 38 public sealed class SubroutineDeleter : SymbolicExpressionTreeArchitectureManipulator { 39 [StorableConstructor] 40 private SubroutineDeleter(bool deserializing) : base(deserializing) { } 41 private SubroutineDeleter(SubroutineDeleter original, Cloner cloner) : base(original, cloner) { } 42 public SubroutineDeleter() : base() { } 43 44 public override IDeepCloneable Clone(Cloner cloner) { 45 return new SubroutineDeleter(this, cloner); 46 } 47 38 48 public override sealed void ModifyArchitecture( 39 49 IRandom random, -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/SubroutineDuplicater.cs
r4249 r4674 24 24 using System.Linq; 25 25 using System.Text; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; … … 37 38 [StorableClass] 38 39 public sealed class SubroutineDuplicater : SymbolicExpressionTreeArchitectureManipulator { 40 [StorableConstructor] 41 private SubroutineDuplicater(bool deserializing) : base(deserializing) { } 42 private SubroutineDuplicater(SubroutineDuplicater original, Cloner cloner) 43 : base(original, cloner) { 44 } 45 public SubroutineDuplicater() : base() { } 46 47 public override IDeepCloneable Clone(Cloner cloner) { 48 return new SubroutineDuplicater(this, cloner); 49 } 50 39 51 public override sealed void ModifyArchitecture( 40 52 IRandom random, -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/SymbolicExpressionTreeArchitectureManipulator.cs
r4068 r4674 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; … … 51 52 get { return MaxFunctionArgumentsParameter.ActualValue; } 52 53 } 54 [StorableConstructor] 55 protected SymbolicExpressionTreeArchitectureManipulator(bool deserializing) : base(deserializing) { } 56 protected SymbolicExpressionTreeArchitectureManipulator(SymbolicExpressionTreeArchitectureManipulator original, Cloner cloner) : base(original, cloner) { } 53 57 public SymbolicExpressionTreeArchitectureManipulator() 54 58 : base() { -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs
r4477 r4674 24 24 using System.Linq; 25 25 using System.Text; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; … … 33 34 [StorableClass] 34 35 [Item("ProbabilisticTreeCreator", "An operator that creates new symbolic expression trees with uniformly distributed size")] 35 public class ProbabilisticTreeCreator : SymbolicExpressionTreeCreator {36 public sealed class ProbabilisticTreeCreator : SymbolicExpressionTreeCreator { 36 37 private const int MAX_TRIES = 100; 37 38 public ProbabilisticTreeCreator() 39 : base() { 40 } 41 42 protected override SymbolicExpressionTree Create( 38 [StorableConstructor] 39 private ProbabilisticTreeCreator(bool deserializing) : base(deserializing) { } 40 private ProbabilisticTreeCreator(ProbabilisticTreeCreator original, Cloner cloner) : base(original, cloner) { } 41 public ProbabilisticTreeCreator() : base() { } 42 43 public override IDeepCloneable Clone(Cloner cloner) { 44 return new ProbabilisticTreeCreator(this, cloner); 45 } 46 47 private override SymbolicExpressionTree Create( 43 48 IRandom random, 44 49 ISymbolicExpressionGrammar grammar, -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/SymbolicExpressionTreeCreator.cs
r4068 r4674 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; … … 61 62 62 63 #endregion 64 [StorableConstructor] 65 protected SymbolicExpressionTreeCreator(bool deserializing) : base(deserializing) { } 66 protected SymbolicExpressionTreeCreator(SymbolicExpressionTreeCreator original, Cloner cloner) : base(original, cloner) { } 63 67 protected SymbolicExpressionTreeCreator() 64 68 : base() { … … 71 75 SymbolicExpressionTree = Create(Random, SymbolicExpressionGrammar, 72 76 MaxTreeSize, MaxTreeHeight, MaxFunctionDefinitions, MaxFunctionArguments); 73 return null;77 return base.Apply(); 74 78 } 75 79 -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SubtreeCrossover.cs
r4106 r4674 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Data; … … 37 38 [Item("SubtreeCrossover", "An operator which performs subtree swapping crossover.")] 38 39 [StorableClass] 39 public class SubtreeCrossover : SymbolicExpressionTreeCrossover {40 public sealed class SubtreeCrossover : SymbolicExpressionTreeCrossover { 40 41 public IValueLookupParameter<PercentValue> InternalCrossoverPointProbabilityParameter { 41 42 get { return (IValueLookupParameter<PercentValue>)Parameters["InternalCrossoverPointProbability"]; } 42 43 } 43 44 [StorableConstructor] 45 private SubtreeCrossover(bool deserializing) : base(deserializing) { } 46 private SubtreeCrossover(SubtreeCrossover original, Cloner cloner) : base(original, cloner) { } 44 47 public SubtreeCrossover() 45 48 : base() { 46 49 Parameters.Add(new ValueLookupParameter<PercentValue>("InternalCrossoverPointProbability", "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9))); 50 } 51 52 public override IDeepCloneable Clone(Cloner cloner) { 53 return new SubtreeCrossover(this, cloner); 47 54 } 48 55 -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SymbolicExpressionTreeCrossover.cs
r4123 r4674 21 21 22 22 using System; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Data; … … 50 51 get { return FailedCrossoverEventsParameter.Value; } 51 52 } 53 [StorableConstructor] 54 protected SymbolicExpressionTreeCrossover(bool deserializing) : base(deserializing) { } 55 protected SymbolicExpressionTreeCrossover(SymbolicExpressionTreeCrossover original, Cloner cloner) : base(original, cloner) { } 52 56 protected SymbolicExpressionTreeCrossover() 53 57 : base() { -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/DefaultSymbolicExpressionGrammar.cs
r4262 r4674 88 88 private Symbol startSymbol; 89 89 90 [StorableConstructor] 91 protected DefaultSymbolicExpressionGrammar(bool deserializing) 92 : base(deserializing) { 93 cachedMinExpressionLength = new Dictionary<string, int>(); 94 cachedMaxExpressionLength = new Dictionary<string, int>(); 95 cachedMinExpressionDepth = new Dictionary<string, int>(); 96 } 97 // cloning ctor 98 protected DefaultSymbolicExpressionGrammar(DefaultSymbolicExpressionGrammar original, Cloner cloner) 99 : base(original, cloner) { 100 this.cachedMinExpressionLength = new Dictionary<string, int>(); 101 this.cachedMaxExpressionLength = new Dictionary<string, int>(); 102 this.cachedMinExpressionDepth = new Dictionary<string, int>(); 103 minSubTreeCount = new Dictionary<string, int>(original.minSubTreeCount); 104 maxSubTreeCount = new Dictionary<string, int>(original.maxSubTreeCount); 105 106 allSymbols = new Dictionary<string, Symbol>(); 107 foreach (Symbol symbol in original.allSymbols.Values.Select(s => cloner.Clone(s))) 108 allSymbols.Add(symbol.Name, symbol); 109 110 startSymbol = cloner.Clone<Symbol>(original.startSymbol); 111 allowedChildSymbols = new Dictionary<string, List<List<string>>>(); 112 foreach (var entry in original.allowedChildSymbols) { 113 allowedChildSymbols[entry.Key] = new List<List<string>>(entry.Value.Count); 114 foreach (var set in entry.Value) { 115 allowedChildSymbols[entry.Key].Add(new List<string>(set)); 116 } 117 } 118 } 90 119 protected DefaultSymbolicExpressionGrammar() 91 120 : base() { … … 136 165 } 137 166 138 [StorableConstructor] 139 protected DefaultSymbolicExpressionGrammar(bool deserializing) 140 : base(deserializing) { 141 cachedMinExpressionLength = new Dictionary<string, int>(); 142 cachedMaxExpressionLength = new Dictionary<string, int>(); 143 cachedMinExpressionDepth = new Dictionary<string, int>(); 167 public override IDeepCloneable Clone(Cloner cloner) { 168 return new DefaultSymbolicExpressionGrammar(this, cloner); 144 169 } 145 170 … … 289 314 } 290 315 291 public override IDeepCloneable Clone(Cloner cloner) { 292 DefaultSymbolicExpressionGrammar clone = (DefaultSymbolicExpressionGrammar)base.Clone(cloner); 293 294 clone.minSubTreeCount = new Dictionary<string, int>(this.minSubTreeCount); 295 clone.maxSubTreeCount = new Dictionary<string, int>(this.maxSubTreeCount); 296 297 clone.allSymbols = new Dictionary<string, Symbol>(); 298 foreach (Symbol symbol in this.allSymbols.Values.Select(s => cloner.Clone(s))) 299 clone.allSymbols.Add(symbol.Name, symbol); 300 301 clone.startSymbol = (Symbol)cloner.Clone(this.startSymbol); 302 clone.allowedChildSymbols = new Dictionary<string, List<List<string>>>(); 303 foreach (var entry in this.allowedChildSymbols) { 304 clone.allowedChildSymbols[entry.Key] = new List<List<string>>(entry.Value.Count); 316 protected void InitializeShallowClone(DefaultSymbolicExpressionGrammar original) { 317 minSubTreeCount = new Dictionary<string, int>(original.minSubTreeCount); 318 maxSubTreeCount = new Dictionary<string, int>(original.maxSubTreeCount); 319 320 allSymbols = new Dictionary<string, Symbol>(original.allSymbols); 321 startSymbol = original.startSymbol; 322 allowedChildSymbols = new Dictionary<string, List<List<string>>>(original.allowedChildSymbols.Count); 323 foreach (var entry in original.allowedChildSymbols) { 324 allowedChildSymbols[entry.Key] = new List<List<string>>(entry.Value.Count); 305 325 foreach (var set in entry.Value) { 306 clone.allowedChildSymbols[entry.Key].Add(new List<string>(set)); 307 } 308 } 309 310 return clone; 311 } 312 313 protected void InitializeShallowClone(DefaultSymbolicExpressionGrammar clone) { 314 clone.minSubTreeCount = new Dictionary<string, int>(this.minSubTreeCount); 315 clone.maxSubTreeCount = new Dictionary<string, int>(this.maxSubTreeCount); 316 317 clone.allSymbols = new Dictionary<string, Symbol>(this.allSymbols); 318 clone.startSymbol = this.startSymbol; 319 clone.allowedChildSymbols = new Dictionary<string, List<List<string>>>(this.allowedChildSymbols.Count); 320 foreach (var entry in this.allowedChildSymbols) { 321 clone.allowedChildSymbols[entry.Key] = new List<List<string>>(entry.Value.Count); 322 foreach (var set in entry.Value) { 323 clone.allowedChildSymbols[entry.Key].Add(new List<string>(set)); 326 allowedChildSymbols[entry.Key].Add(new List<string>(set)); 324 327 } 325 328 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/GlobalSymbolicExpressionGrammar.cs
r4262 r4674 69 69 private Defun defunSymbol; 70 70 71 [StorableConstructor] 72 private GlobalSymbolicExpressionGrammar(bool deserializing) : base(deserializing) { } 73 private GlobalSymbolicExpressionGrammar(GlobalSymbolicExpressionGrammar original, Cloner cloner) 74 : base(original, cloner) { 75 defunSymbol = (Defun)cloner.Clone(original.defunSymbol); 76 maxFunctionArguments = original.maxFunctionArguments; 77 minFunctionArguments = original.minFunctionArguments; 78 maxFunctionDefinitions = original.maxFunctionDefinitions; 79 minFunctionDefinitions = original.minFunctionDefinitions; 80 } 81 71 82 public GlobalSymbolicExpressionGrammar(ISymbolicExpressionGrammar mainBranchGrammar) 72 83 : base(mainBranchGrammar) { … … 100 111 SetAllowedChild(defunSymbol, Symbols.Where(s => s.Name == symb.Name).First(), 0); 101 112 } 102 }103 104 //ctor for cloning105 private GlobalSymbolicExpressionGrammar() : base() { }106 [StorableConstructor]107 private GlobalSymbolicExpressionGrammar(bool deserializing)108 : base(deserializing) {109 113 } 110 114 … … 171 175 172 176 public override IDeepCloneable Clone(Cloner cloner) { 173 GlobalSymbolicExpressionGrammar clone = (GlobalSymbolicExpressionGrammar)base.Clone(cloner); 174 clone.defunSymbol = (Defun)cloner.Clone(this.defunSymbol); 175 clone.maxFunctionArguments = this.maxFunctionArguments; 176 clone.minFunctionArguments = this.minFunctionArguments; 177 clone.maxFunctionDefinitions = this.maxFunctionDefinitions; 178 clone.minFunctionDefinitions = this.minFunctionDefinitions; 179 return clone; 177 return new GlobalSymbolicExpressionGrammar(this, cloner); 180 178 } 181 179 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/ChangeNodeTypeManipulation.cs
r4189 r4674 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Data; … … 31 32 [StorableClass] 32 33 [Item("ChangeNodeTypeManipulation", "Selects a random tree node and changes the symbol.")] 33 public class ChangeNodeTypeManipulation : SymbolicExpressionTreeManipulator {34 public sealed class ChangeNodeTypeManipulation : SymbolicExpressionTreeManipulator { 34 35 35 public ChangeNodeTypeManipulation() 36 : base() { 36 [StorableConstructor] 37 private ChangeNodeTypeManipulation(bool deserializing) : base(deserializing) { } 38 private ChangeNodeTypeManipulation(ChangeNodeTypeManipulation original, Cloner cloner) : base(original, cloner) { } 39 public ChangeNodeTypeManipulation() : base() { } 40 41 public override IDeepCloneable Clone(Cloner cloner) { 42 return new ChangeNodeTypeManipulation(this, cloner); 37 43 } 38 44 -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/FullTreeShaker.cs
r4068 r4674 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; … … 27 28 [StorableClass] 28 29 [Item("FullTreeShaker", "Manipulates all nodes that have local parameters.")] 29 public class FullTreeShaker : SymbolicExpressionTreeManipulator {30 public sealed class FullTreeShaker : SymbolicExpressionTreeManipulator { 30 31 31 public FullTreeShaker() 32 : base() { 32 [StorableConstructor] 33 private FullTreeShaker(bool deserializing) : base(deserializing) { } 34 private FullTreeShaker(FullTreeShaker original, Cloner cloner) : base(original, cloner) { } 35 public FullTreeShaker() : base() { } 36 37 public override IDeepCloneable Clone(Cloner cloner) { 38 return new FullTreeShaker(this, cloner); 33 39 } 34 40 35 pr otectedoverride void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree, ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, out bool success) {41 private override void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree, ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, out bool success) { 36 42 foreach (var node in symbolicExpressionTree.IterateNodesPrefix()) { 37 43 if (node.HasLocalParameters) { -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/MultiSymbolicExpressionTreeManipulator.cs
r4068 r4674 23 23 using System.Linq; 24 24 using HeuristicLab.Collections; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Data; … … 35 36 [Item("MultiSymbolicExpressionTreeManipulator", "Randomly selects and applies one of its manipulators every time it is called.")] 36 37 [StorableClass] 37 public class MultiSymbolicExpressionTreeManipulator : StochasticMultiBranch<ISymbolicExpressionTreeManipulator>, ISymbolicExpressionTreeManipulator, IStochasticOperator {38 public sealed class MultiSymbolicExpressionTreeManipulator : StochasticMultiBranch<ISymbolicExpressionTreeManipulator>, ISymbolicExpressionTreeManipulator, IStochasticOperator { 38 39 private const string MaxTreeSizeParameterName = "MaxTreeSize"; 39 40 private const string MaxTreeHeightParameterName = "MaxTreeHeight"; … … 66 67 #endregion 67 68 68 69 69 [StorableConstructor] 70 70 private MultiSymbolicExpressionTreeManipulator(bool deserializing) : base(deserializing) { } 71 private MultiSymbolicExpressionTreeManipulator(MultiSymbolicExpressionTreeManipulator original, Cloner cloner) : base(original, cloner) { } 71 72 public MultiSymbolicExpressionTreeManipulator() 72 73 : base() { … … 80 81 Operators.Add((ISymbolicExpressionTreeManipulator)Activator.CreateInstance(type), true); 81 82 } 83 } 84 85 public override IDeepCloneable Clone(Cloner cloner) { 86 return new MultiSymbolicExpressionTreeManipulator(this, cloner); 82 87 } 83 88 -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/OnePointShaker.cs
r4068 r4674 21 21 22 22 using System.Linq; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Data; … … 28 29 [StorableClass] 29 30 [Item("OnePointShaker", "Selects a random node with local parameters and manipulates the selected node.")] 30 public class OnePointShaker : SymbolicExpressionTreeManipulator { 31 public sealed class OnePointShaker : SymbolicExpressionTreeManipulator { 32 [StorableConstructor] 33 private OnePointShaker(bool deserializing) : base(deserializing) { } 34 private OnePointShaker(OnePointShaker original, Cloner cloner) : base(original, cloner) { } 35 public OnePointShaker() : base() { } 31 36 32 public OnePointShaker()33 : base() {37 public override IDeepCloneable Clone(Cloner cloner) { 38 return new OnePointShaker(this, cloner); 34 39 } 35 40 -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/ReplaceBranchManipulation.cs
r4189 r4674 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators; 27 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 28 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;30 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators { 32 33 [StorableClass] 33 34 [Item("ReplaceBranchManipulation", "Selects a branch of the tree randomly and replaces it with a newly initialized branch (using PTC2).")] 34 public class ReplaceBranchManipulation : SymbolicExpressionTreeManipulator { 35 public sealed class ReplaceBranchManipulation : SymbolicExpressionTreeManipulator { 36 [StorableConstructor] 37 private ReplaceBranchManipulation(bool deserializing) : base(deserializing) { } 38 private ReplaceBranchManipulation(ReplaceBranchManipulation original, Cloner cloner) : base(original, cloner) { } 39 public ReplaceBranchManipulation() : base() { } 35 40 36 public ReplaceBranchManipulation()37 : base() {41 public override IDeepCloneable Clone(Cloner cloner) { 42 return new ReplaceBranchManipulation(this, cloner); 38 43 } 39 44 40 pr otectedoverride void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree, ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, out bool success) {45 private override void Manipulate(IRandom random, SymbolicExpressionTree symbolicExpressionTree, ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, out bool success) { 41 46 ReplaceRandomBranch(random, symbolicExpressionTree, grammar, maxTreeSize.Value, maxTreeHeight.Value, out success); 42 47 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/SymbolicExpressionTreeManipulator.cs
r4068 r4674 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; … … 54 55 #endregion 55 56 57 [StorableConstructor] 58 protected SymbolicExpressionTreeManipulator(bool deserializing) : base(deserializing) { } 59 protected SymbolicExpressionTreeManipulator(SymbolicExpressionTreeManipulator original, Cloner cloner) : base(original, cloner) { } 56 60 public SymbolicExpressionTreeManipulator() 57 61 : base() { -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTree.cs
r4068 r4674 63 63 } 64 64 65 public SymbolicExpressionTree() 66 : base() { 65 [StorableConstructor] 66 protected SymbolicExpressionTree(bool deserializing) : base(deserializing) { } 67 protected SymbolicExpressionTree(SymbolicExpressionTree original, Cloner cloner) 68 : base(original, cloner) { 69 root = cloner.Clone(original.Root); 67 70 } 68 71 public SymbolicExpressionTree() : base() { } 69 72 public SymbolicExpressionTree(SymbolicExpressionTreeNode root) 70 73 : base() { … … 84 87 85 88 public override IDeepCloneable Clone(Cloner cloner) { 86 SymbolicExpressionTree clone = new SymbolicExpressionTree(); 87 cloner.RegisterClonedObject(this, clone); 88 if (root != null) 89 clone.root = (SymbolicExpressionTreeNode)this.root.Clone(); 90 return clone; 89 return new SymbolicExpressionTree(this, cloner); 91 90 } 92 91 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeGrammar.cs
r4249 r4674 30 30 [StorableConstructor] 31 31 private SymbolicExpressionTreeGrammar(bool deserializing) : base(deserializing) { } 32 //default ctor for cloning 33 private SymbolicExpressionTreeGrammar() : base(false) { } 32 // don't call storable ctor of base class to prevent full cloning 33 // instead use storable ctor to initialize an empty grammar and fill with InizializeShallowClone 34 private SymbolicExpressionTreeGrammar(SymbolicExpressionTreeGrammar original, Cloner cloner) 35 : base(false) { 36 cloner.RegisterClonedObject(original, this); 37 InitializeShallowClone(original); 38 } 39 private SymbolicExpressionTreeGrammar() : base() { } 34 40 35 41 public override IDeepCloneable Clone(Cloner cloner) { 36 SymbolicExpressionTreeGrammar clone = new SymbolicExpressionTreeGrammar(); 37 cloner.RegisterClonedObject(this, clone); 38 InitializeShallowClone(clone); 39 return clone; 42 return new SymbolicExpressionTreeGrammar(this, cloner); 40 43 } 41 44 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs
r4524 r4674 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; … … 29 30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 30 31 [StorableClass] 31 public class SymbolicExpressionTreeNode : ICloneable {32 public class SymbolicExpressionTreeNode : DeepCloneable { 32 33 [Storable] 33 34 private IList<SymbolicExpressionTreeNode> subTrees; … … 51 52 } 52 53 53 internal SymbolicExpressionTreeNode() { 54 [StorableConstructor] 55 protected SymbolicExpressionTreeNode(bool deserializing) { } 56 protected SymbolicExpressionTreeNode(SymbolicExpressionTreeNode original, Cloner cloner) 57 : base() { 58 symbol = original.symbol; // symbols are reused 59 subTrees = new List<SymbolicExpressionTreeNode>(original.SubTrees.Count); 60 foreach (var subtree in original.SubTrees) { 61 var clonedSubTree = cloner.Clone(subtree); 62 subTrees.Add(clonedSubTree); 63 clonedSubTree.Parent = this; 64 } 65 } 66 67 internal SymbolicExpressionTreeNode() 68 : base() { 54 69 // don't allocate subtrees list here! 55 70 // because we don't want to allocate it in terminal nodes 56 71 } 57 72 58 public SymbolicExpressionTreeNode(Symbol symbol) { 73 public SymbolicExpressionTreeNode(Symbol symbol) 74 : base() { 59 75 subTrees = new List<SymbolicExpressionTreeNode>(3); 60 76 this.symbol = symbol; 61 77 } 62 78 63 // copy constructor64 protected SymbolicExpressionTreeNode(SymbolicExpressionTreeNode original) {65 symbol = original.symbol;66 subTrees = new List<SymbolicExpressionTreeNode>(original.SubTrees.Count);67 foreach (var subtree in original.SubTrees) {68 AddSubTree((SymbolicExpressionTreeNode)subtree.Clone());69 }70 }71 79 72 80 [StorableHook(HookType.AfterDeserialization)] 73 private void AfterDeserialization Hook() {81 private void AfterDeserialization() { 74 82 foreach (var subtree in SubTrees) { 75 83 subtree.Parent = this; … … 174 182 } 175 183 176 #region ICloneable Members 177 178 public virtual object Clone() { 179 return new SymbolicExpressionTreeNode(this); 184 public override IDeepCloneable Clone(Cloner cloner) { 185 return new SymbolicExpressionTreeNode(this, cloner); 180 186 } 181 182 #endregion183 187 184 188 public override string ToString() { -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeOperator.cs
r4068 r4674 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; … … 74 75 #endregion 75 76 77 [StorableConstructor] 78 protected SymbolicExpressionTreeOperator(bool deserializing) : base(deserializing) { } 79 protected SymbolicExpressionTreeOperator(SymbolicExpressionTreeOperator original, Cloner cloner) : base(original, cloner) { } 76 80 protected SymbolicExpressionTreeOperator() 77 81 : base() { -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeTerminalNode.cs
r4068 r4674 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 29 30 public abstract class SymbolicExpressionTreeTerminalNode : SymbolicExpressionTreeNode { 30 31 private static List<SymbolicExpressionTreeNode> emptyList = new List<SymbolicExpressionTreeNode>(); 32 public override IList<SymbolicExpressionTreeNode> SubTrees { 33 get { 34 return SymbolicExpressionTreeTerminalNode.emptyList; 35 } 36 } 31 37 38 [StorableConstructor] 39 protected SymbolicExpressionTreeTerminalNode(bool deserializing) : base(deserializing) { } 40 // don't call storable constructor of base to prevent allocation of sub-trees list in base! 41 protected SymbolicExpressionTreeTerminalNode(SymbolicExpressionTreeTerminalNode original, Cloner cloner) 42 : base() { 43 // symbols are reused 44 this.Symbol = original.Symbol; 45 } 32 46 protected SymbolicExpressionTreeTerminalNode() : base() { } 33 // don't call base constructors to prevent allocation of sub-trees list in base! 34 protected SymbolicExpressionTreeTerminalNode(Symbol symbol) { 47 48 protected SymbolicExpressionTreeTerminalNode(Symbol symbol) 49 : base() { 50 // symbols are reused 35 51 this.Symbol = symbol; 36 }37 // don't call base constructors to prevent allocation of sub-trees list in base!38 protected SymbolicExpressionTreeTerminalNode(SymbolicExpressionTreeTerminalNode original) {39 this.Symbol = original.Symbol;40 52 } 41 53 … … 49 61 throw new NotSupportedException(); 50 62 } 51 public override IList<SymbolicExpressionTreeNode> SubTrees {52 get {53 return SymbolicExpressionTreeTerminalNode.emptyList;54 }55 }56 63 } 57 64 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeTopLevelNode.cs
r4249 r4674 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 26 27 [StorableClass] 27 28 public class SymbolicExpressionTreeTopLevelNode : SymbolicExpressionTreeNode { 28 public SymbolicExpressionTreeTopLevelNode()29 : base() {30 }31 32 public SymbolicExpressionTreeTopLevelNode(Symbol symbol)33 : base(symbol) {34 }35 36 29 [Storable] 37 30 private ISymbolicExpressionGrammar grammar; … … 43 36 } 44 37 45 // copy constructor 46 protected SymbolicExpressionTreeTopLevelNode(SymbolicExpressionTreeTopLevelNode original) 47 : base(original) { 48 if (original.Grammar != null) 49 grammar = (ISymbolicExpressionGrammar)original.Grammar.Clone(); 50 //grammar = original.grammar; 38 [StorableConstructor] 39 protected SymbolicExpressionTreeTopLevelNode(bool deserializing) : base(deserializing) { } 40 protected SymbolicExpressionTreeTopLevelNode(SymbolicExpressionTreeTopLevelNode original, Cloner cloner) 41 : base(original, cloner) { 42 grammar = cloner.Clone(original.Grammar); 51 43 } 44 public SymbolicExpressionTreeTopLevelNode() : base() { } 45 public SymbolicExpressionTreeTopLevelNode(Symbol symbol) : base(symbol) { } 52 46 53 public override object Clone() { 54 return new SymbolicExpressionTreeTopLevelNode(this); 47 48 public override IDeepCloneable Clone(Cloner cloner) { 49 return new SymbolicExpressionTreeTopLevelNode(this, cloner); 55 50 } 56 51 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Argument.cs
r4068 r4674 43 43 44 44 [StorableConstructor] 45 private Argument() : base() { } 46 45 private Argument(bool deserializing) : base(deserializing) { } 46 private Argument(Argument original, Cloner cloner) 47 : base(original, cloner) { 48 argumentIndex = original.argumentIndex; 49 name = "ARG" + original.argumentIndex; 50 } 47 51 public Argument(int argumentIndex) 48 52 : base("ARG" + argumentIndex, Argument.ArgumentDescription) { … … 56 60 57 61 public override IDeepCloneable Clone(Cloner cloner) { 58 Argument clone = (Argument)base.Clone(cloner); 59 clone.argumentIndex = argumentIndex; 60 clone.name = "ARG" + argumentIndex; 61 return clone; 62 return new Argument(this, cloner); 62 63 } 63 64 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ArgumentTreeNode.cs
r3486 r4674 21 21 22 22 using System; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { … … 34 35 } 35 36 36 private ArgumentTreeNode() : base() { } 37 38 // copy constructor 39 private ArgumentTreeNode(ArgumentTreeNode original) 40 : base(original) { 41 } 42 37 [StorableConstructor] 38 private ArgumentTreeNode(bool deserializing) : base(deserializing) { } 39 protected ArgumentTreeNode(ArgumentTreeNode original, Cloner cloner) : base(original, cloner) { } 43 40 public ArgumentTreeNode(Argument argSymbol) : base(argSymbol) { } 44 41 45 public override object Clone() {46 return new ArgumentTreeNode(this );42 public override IDeepCloneable Clone(Cloner cloner) { 43 return new ArgumentTreeNode(this, cloner); 47 44 } 48 45 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Defun.cs
r4068 r4674 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 32 33 public const string DefunDescription = "Symbol that represents a function defining node."; 33 34 34 public Defun() : base(Defun.DefunName, Defun.DefunDescription) { }35 35 [StorableConstructor] 36 36 private Defun(bool deserializing) : base(deserializing) { } 37 private Defun(Defun original, Cloner cloner) : base(original, cloner) { } 38 public Defun() : base(Defun.DefunName, Defun.DefunDescription) { } 39 40 public override IDeepCloneable Clone(Cloner cloner) { 41 return new Defun(this, cloner); 42 } 37 43 38 44 public override SymbolicExpressionTreeNode CreateTreeNode() { -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/DefunTreeNode.cs
r4068 r4674 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 23 24 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { … … 37 38 } 38 39 39 private DefunTreeNode() : base() { } 40 41 // copy constructor 42 private DefunTreeNode(DefunTreeNode original) 43 : base(original) { 40 [StorableConstructor] 41 private DefunTreeNode(bool deserializing) : base(deserializing) { } 42 protected DefunTreeNode(DefunTreeNode original, Cloner cloner) 43 : base(original, cloner) { 44 44 functionName = original.functionName; 45 45 numberOfArguments = original.numberOfArguments; … … 48 48 public DefunTreeNode(Defun defunSymbol) : base(defunSymbol) { } 49 49 50 51 public override object Clone() { 52 return new DefunTreeNode(this); 50 public override IDeepCloneable Clone(Cloner cloner) { 51 return new DefunTreeNode(this, cloner); 53 52 } 54 53 -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/InvokeFunction.cs
r4106 r4674 50 50 [StorableConstructor] 51 51 private InvokeFunction(bool deserializing) : base(deserializing) { } 52 private InvokeFunction(InvokeFunction original, Cloner cloner) 53 : base(original, cloner) { 54 functionName = original.functionName; 55 name = "Invoke: " + original.functionName; 56 } 52 57 public InvokeFunction(string functionName) 53 58 : base("Invoke: " + functionName, InvokeFunction.InvokeFunctionDescription) { … … 60 65 61 66 public override IDeepCloneable Clone(Cloner cloner) { 62 InvokeFunction clone = (InvokeFunction)base.Clone(cloner); 63 clone.functionName = functionName; 64 clone.name = "Invoke: " + functionName; 65 return clone; 67 return new InvokeFunction(this, cloner); 66 68 } 67 69 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/InvokeFunctionTreeNode.cs
r3484 r4674 21 21 22 22 using System; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 25 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols { … … 34 35 } 35 36 36 private InvokeFunctionTreeNode() : base() { } 37 38 // copy constructor 39 private InvokeFunctionTreeNode(InvokeFunctionTreeNode original) 40 : base(original) { 41 } 42 37 [StorableConstructor] 38 private InvokeFunctionTreeNode(bool deserializing) : base(deserializing) { } 39 protected InvokeFunctionTreeNode(InvokeFunctionTreeNode original, Cloner cloner) : base(original, cloner) { } 43 40 public InvokeFunctionTreeNode(InvokeFunction invokeSymbol) : base(invokeSymbol) { } 44 41 45 public override object Clone() {46 return new InvokeFunctionTreeNode(this );42 public override IDeepCloneable Clone(Cloner cloner) { 43 return new InvokeFunctionTreeNode(this, cloner); 47 44 } 48 45 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ProgramRootSymbol.cs
r4068 r4674 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 29 30 public const string ProgramRootSymbolDescription = "Special symbol that represents the program root node of a symbolic expression tree."; 30 31 31 public ProgramRootSymbol() : base(ProgramRootSymbol.ProgramRootSymbolName, ProgramRootSymbol.ProgramRootSymbolDescription) { }32 32 [StorableConstructor] 33 33 private ProgramRootSymbol(bool deserializing) : base(deserializing) { } 34 private ProgramRootSymbol(ProgramRootSymbol original, Cloner cloner) : base(original, cloner) { } 35 public ProgramRootSymbol() : base(ProgramRootSymbol.ProgramRootSymbolName, ProgramRootSymbol.ProgramRootSymbolDescription) { } 34 36 37 public override IDeepCloneable Clone(Cloner cloner) { 38 return new ProgramRootSymbol(this, cloner); 39 } 35 40 public override SymbolicExpressionTreeNode CreateTreeNode() { 36 41 return new SymbolicExpressionTreeTopLevelNode(this); -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ReadOnlySymbol.cs
r4068 r4674 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 27 28 [Item("ReadOnlySymbol", "Represents a symbol in a symbolic function tree that cannot be modified.")] 28 29 public abstract class ReadOnlySymbol : Symbol { 29 //#region Properties30 //[Storable]31 //private double initialFrequency;32 //public double InitialFrequency {33 // get { return initialFrequency; }34 // set { throw new NotSupportedException(); }35 //}36 //#endregion37 30 38 31 public override bool CanChangeName { … … 43 36 } 44 37 45 protected ReadOnlySymbol() : base() { }46 protected ReadOnlySymbol(string name, string description) : base(name, description) { }47 38 [StorableConstructor] 48 39 protected ReadOnlySymbol(bool deserializing) : base(deserializing) { } 40 protected ReadOnlySymbol(ReadOnlySymbol original, Cloner cloner) : base(original, cloner) { } 41 protected ReadOnlySymbol(string name, string description) : base(name, description) { } 49 42 } 50 43 } -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/StartSymbol.cs
r4068 r4674 20 20 #endregion 21 21 22 using HeuristicLab.Common; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 29 30 public const string StartSymbolDescription = "Special symbol that represents the starting node of the result producing branch of a symbolic expression tree."; 30 31 31 public StartSymbol() : base(StartSymbol.StartSymbolName, StartSymbol.StartSymbolDescription) { }32 32 [StorableConstructor] 33 33 private StartSymbol(bool deserializing) : base(deserializing) { } 34 private StartSymbol(StartSymbol original, Cloner cloner) : base(original, cloner) { } 35 public StartSymbol() : base(StartSymbol.StartSymbolName, StartSymbol.StartSymbolDescription) { } 36 37 public override IDeepCloneable Clone(Cloner cloner) { 38 return new StartSymbol(this, cloner); 39 } 34 40 35 41 public override SymbolicExpressionTreeNode CreateTreeNode() { -
branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Symbol.cs
r4477 r4674 47 47 #endregion 48 48 49 [StorableConstructor] 50 protected Symbol(bool deserializing) : base(deserializing) { } 51 protected Symbol(Symbol original, Cloner cloner) 52 : base(original, cloner) { 53 initialFrequency = original.initialFrequency; 54 } 49 55 protected Symbol() 50 56 : base() { … … 57 63 } 58 64 59 [StorableConstructor]60 protected Symbol(bool deserializing) : base(deserializing) { }61 65 62 66 public virtual SymbolicExpressionTreeNode CreateTreeNode() { … … 65 69 66 70 public override IDeepCloneable Clone(Cloner cloner) { 67 Symbol clone = (Symbol)base.Clone(cloner); 68 clone.initialFrequency = initialFrequency; 69 return clone; 71 return new Symbol(this, cloner); 70 72 } 71 73
Note: See TracChangeset
for help on using the changeset viewer.