Free cookie consent management tool by TermsFeed Policy Generator

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/Symbols
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • 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.