Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4674


Ignore:
Timestamp:
10/29/10 18:55:22 (14 years ago)
Author:
gkronber
Message:

Refactored cloning in SymbolicExpressionTreeEncoding. #922

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  
    6565
    6666    #endregion
     67    [StorableConstructor]
     68    private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(bool deserializing) : base() { }
     69    protected MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(MinAverageMaxSymbolicExpressionTreeSizeAnalyzer original, Cloner cloner)
     70      : base(original, cloner) {
     71      AfterDeserialization();
     72    }
    6773    public MinAverageMaxSymbolicExpressionTreeSizeAnalyzer()
    6874      : base() {
     
    95101      valueAnalyzer.Successor = null;
    96102
    97       Initialize();
     103      AfterDeserialization();
    98104    }
    99105
    100     [StorableConstructor]
    101     private MinAverageMaxSymbolicExpressionTreeSizeAnalyzer(bool deserializing) : base() { }
    102106
    103107    [StorableHook(HookType.AfterDeserialization)]
    104     private void Initialize() {
     108    private void AfterDeserialization() {
    105109      SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged);
    106110      SymbolicExpressionTreeSizeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeSizeParameter_DepthChanged);
     
    108112
    109113    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);
    113115    }
    114116
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Analyzers/SymbolicExpressionTreeSizeCalculator.cs

    r4068 r4674  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
     
    5556    #endregion
    5657
     58    [StorableConstructor]
     59    private SymbolicExpressionTreeSizeCalculator(bool deserializing) : base(deserializing) { }
     60    private SymbolicExpressionTreeSizeCalculator(SymbolicExpressionTreeSizeCalculator original, Cloner cloner) : base(original, cloner) { }
    5761    public SymbolicExpressionTreeSizeCalculator()
    5862      : base() {
     
    6670      return base.Apply();
    6771    }
     72
     73    public override IDeepCloneable Clone(Cloner cloner) {
     74      return new SymbolicExpressionTreeSizeCalculator(this, cloner);
     75    }
    6876  }
    6977}
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/ArgumentCreater.cs

    r4524 r4674  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     25using HeuristicLab.Common;
    2426using HeuristicLab.Core;
    2527using HeuristicLab.Data;
    2628using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    2729using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using System;
    2930
    3031namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators {
     
    3637  [StorableClass]
    3738  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() { }
    3843    public override sealed void ModifyArchitecture(
    3944      IRandom random,
     
    4449      out bool success) {
    4550      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);
    4655    }
    4756
     
    91100      }
    92101    }
    93 
    94102
    95103    private static bool CreateNewArgumentForDefun(IRandom random, SymbolicExpressionTree tree, DefunTreeNode defunBranch, ArgumentTreeNode newArgumentNode) {
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/ArgumentDeleter.cs

    r4068 r4674  
    2121
    2222using System.Linq;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
     
    3334  [StorableClass]
    3435  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
    3541    public override sealed void ModifyArchitecture(
    3642      IRandom random,
     
    4147      out bool success) {
    4248      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);
    4353    }
    4454
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/ArgumentDuplicater.cs

    r4524 r4674  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using System.Linq;
     25using HeuristicLab.Common;
    2326using HeuristicLab.Core;
    2427using HeuristicLab.Data;
    2528using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    2629using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    27 using System.Collections.Generic;
    28 using System;
    2930
    3031namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators {
     
    3637  [StorableClass]
    3738  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
    3844    public override sealed void ModifyArchitecture(
    3945      IRandom random,
     
    4450      out bool success) {
    4551      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);
    4656    }
    4757
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/MultiSymbolicExpressionTreeArchitectureManipulator.cs

    r4068 r4674  
    2323using System.Linq;
    2424using HeuristicLab.Collections;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Data;
     
    3536  [Item("MultiSymbolicExpressionTreeArchitectureManipulator", "Randomly selects and applies one of its architecture manipulators every time it is called.")]
    3637  [StorableClass]
    37   public class MultiSymbolicExpressionTreeArchitectureManipulator : StochasticMultiBranch<ISymbolicExpressionTreeArchitectureManipulator>, ISymbolicExpressionTreeArchitectureManipulator, IStochasticOperator {
     38  public sealed class MultiSymbolicExpressionTreeArchitectureManipulator : StochasticMultiBranch<ISymbolicExpressionTreeArchitectureManipulator>, ISymbolicExpressionTreeArchitectureManipulator, IStochasticOperator {
    3839    private const string MaxTreeSizeParameterName = "MaxTreeSize";
    3940    private const string MaxTreeHeightParameterName = "MaxTreeHeight";
     
    4647      get { return false; }
    4748    }
    48     protected override bool CreateChildOperation {
     49    private override bool CreateChildOperation {
    4950      get { return true; }
    5051    }
     
    5758    }
    5859    #endregion
    59 
    6060
    6161    #region ISymbolicExpressionTreeManipulator Members
     
    8080    [StorableConstructor]
    8181    private MultiSymbolicExpressionTreeArchitectureManipulator(bool deserializing) : base(deserializing) { }
     82    private MultiSymbolicExpressionTreeArchitectureManipulator(MultiSymbolicExpressionTreeArchitectureManipulator original, Cloner cloner) : base(original, cloner) { }
    8283    public MultiSymbolicExpressionTreeArchitectureManipulator()
    8384      : base() {
     
    9596    }
    9697
    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) {
    98103      base.Operators_ItemsReplaced(sender, e);
    99104      ParameterizeManipulators();
    100105    }
    101106
    102     protected override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeArchitectureManipulator>> e) {
     107    private override void Operators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<ISymbolicExpressionTreeArchitectureManipulator>> e) {
    103108      base.Operators_ItemsAdded(sender, e);
    104109      ParameterizeManipulators();
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/SubroutineCreater.cs

    r4249 r4674  
    2424using System.Linq;
    2525using System.Text;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
     
    3940  public sealed class SubroutineCreater : SymbolicExpressionTreeArchitectureManipulator {
    4041    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    }
    4151
    4252    public override sealed void ModifyArchitecture(
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/SubroutineDeleter.cs

    r4068 r4674  
    2222using System;
    2323using System.Linq;
     24using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Data;
     
    3637  [StorableClass]
    3738  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
    3848    public override sealed void ModifyArchitecture(
    3949      IRandom random,
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/SubroutineDuplicater.cs

    r4249 r4674  
    2424using System.Linq;
    2525using System.Text;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
     
    3738  [StorableClass]
    3839  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
    3951    public override sealed void ModifyArchitecture(
    4052      IRandom random,
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/SymbolicExpressionTreeArchitectureManipulator.cs

    r4068 r4674  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
     
    5152      get { return MaxFunctionArgumentsParameter.ActualValue; }
    5253    }
     54    [StorableConstructor]
     55    protected SymbolicExpressionTreeArchitectureManipulator(bool deserializing) : base(deserializing) { }
     56    protected SymbolicExpressionTreeArchitectureManipulator(SymbolicExpressionTreeArchitectureManipulator original, Cloner cloner) : base(original, cloner) { }
    5357    public SymbolicExpressionTreeArchitectureManipulator()
    5458      : base() {
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs

    r4477 r4674  
    2424using System.Linq;
    2525using System.Text;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
     
    3334  [StorableClass]
    3435  [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 {
    3637    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(
    4348      IRandom random,
    4449      ISymbolicExpressionGrammar grammar,
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/SymbolicExpressionTreeCreator.cs

    r4068 r4674  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
     
    6162
    6263    #endregion
     64    [StorableConstructor]
     65    protected SymbolicExpressionTreeCreator(bool deserializing) : base(deserializing) { }
     66    protected SymbolicExpressionTreeCreator(SymbolicExpressionTreeCreator original, Cloner cloner) : base(original, cloner) { }
    6367    protected SymbolicExpressionTreeCreator()
    6468      : base() {
     
    7175      SymbolicExpressionTree = Create(Random, SymbolicExpressionGrammar,
    7276        MaxTreeSize, MaxTreeHeight, MaxFunctionDefinitions, MaxFunctionArguments);
    73       return null;
     77      return base.Apply();
    7478    }
    7579
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SubtreeCrossover.cs

    r4106 r4674  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Data;
     
    3738  [Item("SubtreeCrossover", "An operator which performs subtree swapping crossover.")]
    3839  [StorableClass]
    39   public class SubtreeCrossover : SymbolicExpressionTreeCrossover {
     40  public sealed class SubtreeCrossover : SymbolicExpressionTreeCrossover {
    4041    public IValueLookupParameter<PercentValue> InternalCrossoverPointProbabilityParameter {
    4142      get { return (IValueLookupParameter<PercentValue>)Parameters["InternalCrossoverPointProbability"]; }
    4243    }
    43 
     44    [StorableConstructor]
     45    private SubtreeCrossover(bool deserializing) : base(deserializing) { }
     46    private SubtreeCrossover(SubtreeCrossover original, Cloner cloner) : base(original, cloner) { }
    4447    public SubtreeCrossover()
    4548      : base() {
    4649      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);
    4754    }
    4855
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SymbolicExpressionTreeCrossover.cs

    r4123 r4674  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
     
    5051      get { return FailedCrossoverEventsParameter.Value; }
    5152    }
     53    [StorableConstructor]
     54    protected SymbolicExpressionTreeCrossover(bool deserializing) : base(deserializing) { }
     55    protected SymbolicExpressionTreeCrossover(SymbolicExpressionTreeCrossover original, Cloner cloner) : base(original, cloner) { }
    5256    protected SymbolicExpressionTreeCrossover()
    5357      : base() {
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/DefaultSymbolicExpressionGrammar.cs

    r4262 r4674  
    8888    private Symbol startSymbol;
    8989
     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    }
    90119    protected DefaultSymbolicExpressionGrammar()
    91120      : base() {
     
    136165    }
    137166
    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);
    144169    }
    145170
     
    289314    }
    290315
    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);
    305325        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));
    324327        }
    325328      }
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/GlobalSymbolicExpressionGrammar.cs

    r4262 r4674  
    6969    private Defun defunSymbol;
    7070
     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
    7182    public GlobalSymbolicExpressionGrammar(ISymbolicExpressionGrammar mainBranchGrammar)
    7283      : base(mainBranchGrammar) {
     
    100111          SetAllowedChild(defunSymbol, Symbols.Where(s => s.Name == symb.Name).First(), 0);
    101112      }
    102     }
    103 
    104     //ctor for cloning
    105     private GlobalSymbolicExpressionGrammar() : base() { }
    106     [StorableConstructor]
    107     private GlobalSymbolicExpressionGrammar(bool deserializing)
    108       : base(deserializing) {
    109113    }
    110114
     
    171175
    172176    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);
    180178    }
    181179  }
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/ChangeNodeTypeManipulation.cs

    r4189 r4674  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Data;
     
    3132  [StorableClass]
    3233  [Item("ChangeNodeTypeManipulation", "Selects a random tree node and changes the symbol.")]
    33   public class ChangeNodeTypeManipulation : SymbolicExpressionTreeManipulator {
     34  public sealed class ChangeNodeTypeManipulation : SymbolicExpressionTreeManipulator {
    3435
    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);
    3743    }
    3844
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/FullTreeShaker.cs

    r4068 r4674  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
     
    2728  [StorableClass]
    2829  [Item("FullTreeShaker", "Manipulates all nodes that have local parameters.")]
    29   public class FullTreeShaker : SymbolicExpressionTreeManipulator {
     30  public sealed class FullTreeShaker : SymbolicExpressionTreeManipulator {
    3031
    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);
    3339    }
    3440
    35     protected override 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) {
    3642      foreach (var node in symbolicExpressionTree.IterateNodesPrefix()) {
    3743        if (node.HasLocalParameters) {
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/MultiSymbolicExpressionTreeManipulator.cs

    r4068 r4674  
    2323using System.Linq;
    2424using HeuristicLab.Collections;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Data;
     
    3536  [Item("MultiSymbolicExpressionTreeManipulator", "Randomly selects and applies one of its manipulators every time it is called.")]
    3637  [StorableClass]
    37   public class MultiSymbolicExpressionTreeManipulator : StochasticMultiBranch<ISymbolicExpressionTreeManipulator>, ISymbolicExpressionTreeManipulator, IStochasticOperator {
     38  public sealed class MultiSymbolicExpressionTreeManipulator : StochasticMultiBranch<ISymbolicExpressionTreeManipulator>, ISymbolicExpressionTreeManipulator, IStochasticOperator {
    3839    private const string MaxTreeSizeParameterName = "MaxTreeSize";
    3940    private const string MaxTreeHeightParameterName = "MaxTreeHeight";
     
    6667    #endregion
    6768
    68 
    6969    [StorableConstructor]
    7070    private MultiSymbolicExpressionTreeManipulator(bool deserializing) : base(deserializing) { }
     71    private MultiSymbolicExpressionTreeManipulator(MultiSymbolicExpressionTreeManipulator original, Cloner cloner) : base(original, cloner) { }
    7172    public MultiSymbolicExpressionTreeManipulator()
    7273      : base() {
     
    8081          Operators.Add((ISymbolicExpressionTreeManipulator)Activator.CreateInstance(type), true);
    8182      }
     83    }
     84
     85    public override IDeepCloneable Clone(Cloner cloner) {
     86      return new MultiSymbolicExpressionTreeManipulator(this, cloner);
    8287    }
    8388
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/OnePointShaker.cs

    r4068 r4674  
    2121
    2222using System.Linq;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
     
    2829  [StorableClass]
    2930  [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() { }
    3136
    32     public OnePointShaker()
    33       : base() {
     37    public override IDeepCloneable Clone(Cloner cloner) {
     38      return new OnePointShaker(this, cloner);
    3439    }
    3540
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/ReplaceBranchManipulation.cs

    r4189 r4674  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Data;
     28using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    2729using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    2830using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
    3031
    3132namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators {
    3233  [StorableClass]
    3334  [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() { }
    3540
    36     public ReplaceBranchManipulation()
    37       : base() {
     41    public override IDeepCloneable Clone(Cloner cloner) {
     42      return new ReplaceBranchManipulation(this, cloner);
    3843    }
    3944
    40     protected override 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) {
    4146      ReplaceRandomBranch(random, symbolicExpressionTree, grammar, maxTreeSize.Value, maxTreeHeight.Value, out success);
    4247    }
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/SymbolicExpressionTreeManipulator.cs

    r4068 r4674  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
     
    5455    #endregion
    5556
     57    [StorableConstructor]
     58    protected SymbolicExpressionTreeManipulator(bool deserializing) : base(deserializing) { }
     59    protected SymbolicExpressionTreeManipulator(SymbolicExpressionTreeManipulator original, Cloner cloner) : base(original, cloner) { }
    5660    public SymbolicExpressionTreeManipulator()
    5761      : base() {
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTree.cs

    r4068 r4674  
    6363    }
    6464
    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);
    6770    }
    68 
     71    public SymbolicExpressionTree() : base() { }
    6972    public SymbolicExpressionTree(SymbolicExpressionTreeNode root)
    7073      : base() {
     
    8487
    8588    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);
    9190    }
    9291  }
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeGrammar.cs

    r4249 r4674  
    3030    [StorableConstructor]
    3131    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() { }
    3440
    3541    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);
    4043    }
    4144  }
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs

    r4524 r4674  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
     
    2930namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    3031  [StorableClass]
    31   public class SymbolicExpressionTreeNode : ICloneable {
     32  public class SymbolicExpressionTreeNode : DeepCloneable {
    3233    [Storable]
    3334    private IList<SymbolicExpressionTreeNode> subTrees;
     
    5152    }
    5253
    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() {
    5469      // don't allocate subtrees list here!
    5570      // because we don't want to allocate it in terminal nodes
    5671    }
    5772
    58     public SymbolicExpressionTreeNode(Symbol symbol) {
     73    public SymbolicExpressionTreeNode(Symbol symbol)
     74      : base() {
    5975      subTrees = new List<SymbolicExpressionTreeNode>(3);
    6076      this.symbol = symbol;
    6177    }
    6278
    63     // copy constructor
    64     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     }
    7179
    7280    [StorableHook(HookType.AfterDeserialization)]
    73     private void AfterDeserializationHook() {
     81    private void AfterDeserialization() {
    7482      foreach (var subtree in SubTrees) {
    7583        subtree.Parent = this;
     
    174182    }
    175183
    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);
    180186    }
    181 
    182     #endregion
    183187
    184188    public override string ToString() {
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeOperator.cs

    r4068 r4674  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
     
    7475    #endregion
    7576
     77    [StorableConstructor]
     78    protected SymbolicExpressionTreeOperator(bool deserializing) : base(deserializing) { }
     79    protected SymbolicExpressionTreeOperator(SymbolicExpressionTreeOperator original, Cloner cloner) : base(original, cloner) { }
    7680    protected SymbolicExpressionTreeOperator()
    7781      : base() {
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeTerminalNode.cs

    r4068 r4674  
    2222using System;
    2323using System.Collections.Generic;
     24using HeuristicLab.Common;
    2425using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    2930  public abstract class SymbolicExpressionTreeTerminalNode : SymbolicExpressionTreeNode {
    3031    private static List<SymbolicExpressionTreeNode> emptyList = new List<SymbolicExpressionTreeNode>();
     32    public override IList<SymbolicExpressionTreeNode> SubTrees {
     33      get {
     34        return SymbolicExpressionTreeTerminalNode.emptyList;
     35      }
     36    }
    3137
     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    }
    3246    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
    3551      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;
    4052    }
    4153
     
    4961      throw new NotSupportedException();
    5062    }
    51     public override IList<SymbolicExpressionTreeNode> SubTrees {
    52       get {
    53         return SymbolicExpressionTreeTerminalNode.emptyList;
    54       }
    55     }
    5663  }
    5764}
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeTopLevelNode.cs

    r4249 r4674  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    2627  [StorableClass]
    2728  public class SymbolicExpressionTreeTopLevelNode : SymbolicExpressionTreeNode {
    28     public SymbolicExpressionTreeTopLevelNode()
    29       : base() {
    30     }
    31 
    32     public SymbolicExpressionTreeTopLevelNode(Symbol symbol)
    33       : base(symbol) {
    34     }
    35 
    3629    [Storable]
    3730    private ISymbolicExpressionGrammar grammar;
     
    4336    }
    4437
    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);
    5143    }
     44    public SymbolicExpressionTreeTopLevelNode() : base() { }
     45    public SymbolicExpressionTreeTopLevelNode(Symbol symbol) : base(symbol) { }
    5246
    53     public override object Clone() {
    54       return new SymbolicExpressionTreeTopLevelNode(this);
     47
     48    public override IDeepCloneable Clone(Cloner cloner) {
     49      return new SymbolicExpressionTreeTopLevelNode(this, cloner);
    5550    }
    5651  }
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Argument.cs

    r4068 r4674  
    4343
    4444    [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    }
    4751    public Argument(int argumentIndex)
    4852      : base("ARG" + argumentIndex, Argument.ArgumentDescription) {
     
    5660
    5761    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);
    6263    }
    6364  }
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ArgumentTreeNode.cs

    r3486 r4674  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2425namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
     
    3435    }
    3536
    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) { }
    4340    public ArgumentTreeNode(Argument argSymbol) : base(argSymbol) { }
    4441
    45     public override object Clone() {
    46       return new ArgumentTreeNode(this);
     42    public override IDeepCloneable Clone(Cloner cloner) {
     43      return new ArgumentTreeNode(this, cloner);
    4744    }
    4845  }
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Defun.cs

    r4068 r4674  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3233    public const string DefunDescription = "Symbol that represents a function defining node.";
    3334
    34     public Defun() : base(Defun.DefunName, Defun.DefunDescription) { }
    3535    [StorableConstructor]
    3636    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    }
    3743
    3844    public override SymbolicExpressionTreeNode CreateTreeNode() {
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/DefunTreeNode.cs

    r4068 r4674  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2324namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
     
    3738    }
    3839
    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) {
    4444      functionName = original.functionName;
    4545      numberOfArguments = original.numberOfArguments;
     
    4848    public DefunTreeNode(Defun defunSymbol) : base(defunSymbol) { }
    4949
    50 
    51     public override object Clone() {
    52       return new DefunTreeNode(this);
     50    public override IDeepCloneable Clone(Cloner cloner) {
     51      return new DefunTreeNode(this, cloner);
    5352    }
    5453
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/InvokeFunction.cs

    r4106 r4674  
    5050    [StorableConstructor]
    5151    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    }
    5257    public InvokeFunction(string functionName)
    5358      : base("Invoke: " + functionName, InvokeFunction.InvokeFunctionDescription) {
     
    6065
    6166    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);
    6668    }
    6769  }
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/InvokeFunctionTreeNode.cs

    r3484 r4674  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2425namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
     
    3435    }
    3536
    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) { }
    4340    public InvokeFunctionTreeNode(InvokeFunction invokeSymbol) : base(invokeSymbol) { }
    4441
    45     public override object Clone() {
    46       return new InvokeFunctionTreeNode(this);
     42    public override IDeepCloneable Clone(Cloner cloner) {
     43      return new InvokeFunctionTreeNode(this, cloner);
    4744    }
    4845  }
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ProgramRootSymbol.cs

    r4068 r4674  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    2930    public const string ProgramRootSymbolDescription = "Special symbol that represents the program root node of a symbolic expression tree.";
    3031
    31     public ProgramRootSymbol() : base(ProgramRootSymbol.ProgramRootSymbolName, ProgramRootSymbol.ProgramRootSymbolDescription) { }
    3232    [StorableConstructor]
    3333    private ProgramRootSymbol(bool deserializing) : base(deserializing) { }
     34    private ProgramRootSymbol(ProgramRootSymbol original, Cloner cloner) : base(original, cloner) { }
     35    public ProgramRootSymbol() : base(ProgramRootSymbol.ProgramRootSymbolName, ProgramRootSymbol.ProgramRootSymbolDescription) { }
    3436
     37    public override IDeepCloneable Clone(Cloner cloner) {
     38      return new ProgramRootSymbol(this, cloner);
     39    }
    3540    public override SymbolicExpressionTreeNode CreateTreeNode() {
    3641      return new SymbolicExpressionTreeTopLevelNode(this);
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ReadOnlySymbol.cs

    r4068 r4674  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    2728  [Item("ReadOnlySymbol", "Represents a symbol in a symbolic function tree that cannot be modified.")]
    2829  public abstract class ReadOnlySymbol : Symbol {
    29     //#region Properties
    30     //[Storable]
    31     //private double initialFrequency;
    32     //public double InitialFrequency {
    33     //  get { return initialFrequency; }
    34     //  set { throw new NotSupportedException(); }
    35     //}
    36     //#endregion
    3730
    3831    public override bool CanChangeName {
     
    4336    }
    4437
    45     protected ReadOnlySymbol() : base() { }
    46     protected ReadOnlySymbol(string name, string description) : base(name, description) { }
    4738    [StorableConstructor]
    4839    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) { }
    4942  }
    5043}
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/StartSymbol.cs

    r4068 r4674  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    2930    public const string StartSymbolDescription = "Special symbol that represents the starting node of the result producing branch of a symbolic expression tree.";
    3031
    31     public StartSymbol() : base(StartSymbol.StartSymbolName, StartSymbol.StartSymbolDescription) { }
    3232    [StorableConstructor]
    3333    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    }
    3440
    3541    public override SymbolicExpressionTreeNode CreateTreeNode() {
  • branches/CloningRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Symbol.cs

    r4477 r4674  
    4747    #endregion
    4848
     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    }
    4955    protected Symbol()
    5056      : base() {
     
    5763    }
    5864
    59     [StorableConstructor]
    60     protected Symbol(bool deserializing) : base(deserializing) { }
    6165
    6266    public virtual SymbolicExpressionTreeNode CreateTreeNode() {
     
    6569
    6670    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);
    7072    }
    7173
Note: See TracChangeset for help on using the changeset viewer.