Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3484


Ignore:
Timestamp:
04/22/10 08:51:33 (15 years ago)
Author:
gkronber
Message:

Bug fixes in cloning and persistence. #937 (Data types and operators for symbolic expression tree encoding)

Location:
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/GlobalSymbolicExpressionGrammar.cs

    r3462 r3484  
    8383    }
    8484
     85    [StorableHook(HookType.AfterDeserialization)]
     86    private void AfterDeserializationHook() {
     87      Reset();
     88    }
     89
    8590    private new void Reset() {
    8691      base.Reset();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs

    r3462 r3484  
    3939    [Storable]
    4040    private Symbol symbol;
     41    public Symbol Symbol {
     42      get { return symbol; }
     43      protected set { symbol = value; }
     44    }
    4145
    4246    // parent relation is not persisted or cloned (will be set on AddSubtree or RemoveSubtree)
    4347    private SymbolicExpressionTreeNode parent;
    44 
    45     public SymbolicExpressionTreeNode() {
    46       subTrees = new List<SymbolicExpressionTreeNode>();
     48    internal SymbolicExpressionTreeNode Parent {
     49      get { return parent; }
     50      set { parent = value; }
    4751    }
    4852
    49     public SymbolicExpressionTreeNode(Symbol symbol)
    50       : this() {
     53    public SymbolicExpressionTreeNode() { }
     54
     55    public SymbolicExpressionTreeNode(Symbol symbol) {
     56      subTrees = new List<SymbolicExpressionTreeNode>();
    5157      this.symbol = symbol;
    5258    }
     
    6773    public virtual IList<SymbolicExpressionTreeNode> SubTrees {
    6874      get { return subTrees; }
    69     }
    70 
    71     public Symbol Symbol {
    72       get { return symbol; }
    73       protected set { symbol = value; }
    74     }
    75 
    76     internal SymbolicExpressionTreeNode Parent {
    77       get { return parent; }
    78       set { parent = value; }
    7975    }
    8076
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeTerminalNode.cs

    r3462 r3484  
    3131
    3232namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     33  [StorableClass]
    3334  public abstract class SymbolicExpressionTreeTerminalNode : SymbolicExpressionTreeNode {
    3435    private static List<SymbolicExpressionTreeNode> emptyList = new List<SymbolicExpressionTreeNode>();
    3536
    36     protected SymbolicExpressionTreeTerminalNode(Symbol symbol) : base(symbol) { }
    37     protected SymbolicExpressionTreeTerminalNode(SymbolicExpressionTreeTerminalNode original)
    38       : base(original) {
     37    protected SymbolicExpressionTreeTerminalNode() : base() { }
     38    // don't call  base constructors to prevent allocation of sub-trees list in base!
     39    protected SymbolicExpressionTreeTerminalNode(Symbol symbol) {
     40      this.Symbol = symbol;
     41    }
     42    // don't call  base constructors to prevent allocation of sub-trees list in base!
     43    protected SymbolicExpressionTreeTerminalNode(SymbolicExpressionTreeTerminalNode original) {
     44      this.Symbol = original.Symbol;
    3945    }
    4046
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Argument.cs

    r3462 r3484  
    3535      }
    3636    }
    37 
     37    [Storable]
    3838    private int argumentIndex;
    3939    public int ArgumentIndex {
    4040      get { return argumentIndex; }
    4141    }
     42
     43    private Argument() : base() { }
    4244
    4345    public Argument(int argumentIndex)
     
    5052      return new ArgumentTreeNode(this);
    5153    }
     54
     55    public override IDeepCloneable Clone(Cloner cloner) {
     56      Argument clone = (Argument)base.Clone(cloner);
     57      clone.argumentIndex = argumentIndex;
     58      clone.name = "ARG" + argumentIndex;
     59      return clone;
     60    }
    5261  }
    5362}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/ArgumentTreeNode.cs

    r3462 r3484  
    2929      set {
    3030        if (value == null) throw new ArgumentNullException();
    31         if(!(value is Argument)) throw new ArgumentException();
    32         base.Symbol = value; 
     31        if (!(value is Argument)) throw new ArgumentException();
     32        base.Symbol = value;
    3333      }
    3434    }
    35    
     35
     36    private ArgumentTreeNode() : base() { }
     37
    3638    // copy constructor
    3739    private ArgumentTreeNode(ArgumentTreeNode original)
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/DefunTreeNode.cs

    r3462 r3484  
    4040    }
    4141
     42    private DefunTreeNode() : base() { }
     43
    4244    // copy constructor
    4345    private DefunTreeNode(DefunTreeNode original)
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/InvokeFunction.cs

    r3462 r3484  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using System;
    2526namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols {
    2627  /// <summary>
     
    3536      }
    3637    }
    37     public string FunctionName { get; set; }
     38    [Storable]
     39    private string functionName;
     40    public string FunctionName {
     41      get { return functionName; }
     42      set {
     43        if (value == null) throw new ArgumentNullException();
     44        functionName = value;
     45      }
     46    }
     47
     48    private InvokeFunction() : base() { }
    3849
    3950    public InvokeFunction(string functionName)
     
    4657      return new InvokeFunctionTreeNode(this);
    4758    }
     59
     60    public override IDeepCloneable Clone(Cloner cloner) {
     61      InvokeFunction clone = (InvokeFunction)base.Clone(cloner);
     62      clone.functionName = functionName;
     63      clone.name = "Invoke: " + functionName;
     64      return clone;
     65    }
    4866  }
    4967}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/InvokeFunctionTreeNode.cs

    r3462 r3484  
    3434    }
    3535
     36    private InvokeFunctionTreeNode() : base() { }
     37
    3638    // copy constructor
    3739    private InvokeFunctionTreeNode(InvokeFunctionTreeNode original)
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Symbols/Symbol.cs

    r3462 r3484  
    3535  public abstract class Symbol : NamedItem {
    3636    #region Properties
     37    [Storable]
    3738    private double initialFrequency;
    3839    public double InitialFrequency {
     
    5556      return new SymbolicExpressionTreeNode(this);
    5657    }
     58
     59    public override IDeepCloneable Clone(Cloner cloner) {
     60      Symbol clone = (Symbol) base.Clone(cloner);
     61      clone.initialFrequency = initialFrequency;
     62      return clone;
     63    }
    5764  }
    5865}
Note: See TracChangeset for help on using the changeset viewer.