Free cookie consent management tool by TermsFeed Policy Generator

Changeset 890


Ignore:
Timestamp:
12/03/08 07:14:04 (16 years ago)
Author:
gkronber
Message:

worked on clone refactoring in HL.GP.

#285 (Cloning could be improved by creating objects at the bottom of the cloning chain with 'new' instead of the top with Activator.CreateInstance())

Location:
branches/CloningRefactorBranch
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactorBranch/HeuristicLab.GP.Boolean/HeuristicLabGPBooleanPlugin.cs

    r720 r890  
    2525using HeuristicLab.PluginInfrastructure;
    2626
    27 namespace HeuristicLab.GP.SantaFe {
     27namespace HeuristicLab.GP.Boolean {
    2828  [ClassInfo(Name = "HeuristicLab.GP.Boolean-1.0")]
    2929  [PluginFile(Filename = "HeuristicLab.GP.Boolean-1.0.dll", Filetype = PluginFileType.Assembly)]
  • branches/CloningRefactorBranch/HeuristicLab.GP.StructureIdentification/Constant.cs

    r656 r890  
    5757    }
    5858
     59    public Constant(Constant original) : this(original, new Dictionary<Guid, object>()) { }
     60    private Constant(Constant original, IDictionary<Guid, object> clonedObjects)
     61      : base(original, clonedObjects) { }
     62
    5963    private void SetupInitialization() {
    6064      // initialization operator
     
    9094      AddVariable(new HeuristicLab.Core.Variable(MANIPULATION, combinedOp));
    9195    }
     96
     97    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     98      return new Constant(this, clonedObjects);
     99    }
    92100  }
    93101}
  • branches/CloningRefactorBranch/HeuristicLab.GP/BakedFunctionTree.cs

    r767 r890  
    9090      foreach(IFunctionTree subTree in tree.SubTrees) {
    9191        AddSubTree(new BakedFunctionTree(subTree));
     92      }
     93    }
     94
     95    public BakedFunctionTree(BakedFunctionTree original) : this(original, new Dictionary<Guid, object>()) { }
     96    protected BakedFunctionTree(BakedFunctionTree original, IDictionary<Guid, object> clonedObjects)
     97      : base(original, clonedObjects) {
     98      // in case the user (de)serialized the tree between evaluation and selection we have to flatten the tree again.
     99      if (original.treesExpanded) original.FlattenTrees();
     100      if (original.variablesExpanded) original.FlattenVariables();
     101      foreach (LightWeightFunction f in original.linearRepresentation) {
     102        this.linearRepresentation.Add(f.Clone());
    92103      }
    93104    }
     
    325336
    326337    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    327       BakedFunctionTree clone = new BakedFunctionTree();
    328       // in case the user (de)serialized the tree between evaluation and selection we have to flatten the tree again.
    329       if(treesExpanded) FlattenTrees();
    330       if(variablesExpanded) FlattenVariables();
    331       foreach(LightWeightFunction f in linearRepresentation) {
    332         clone.linearRepresentation.Add(f.Clone());
    333       }
    334       return clone;
     338      return new BakedFunctionTree(this, clonedObjects);
    335339    }
    336340
     
    338342      return new FunctionTreeView(this);
    339343    }
    340 
    341     //public override string ToString() {
    342     //  SymbolicExpressionExporter exporter = new SymbolicExpressionExporter();
    343     //  exporter.Visit(this);
    344     //  return exporter.GetStringRepresentation();
    345     //}
    346344  }
    347345}
  • branches/CloningRefactorBranch/HeuristicLab.GP/FunctionBase.cs

    r656 r890  
    4040    private int minArity = -1;
    4141    private int maxArity = -1;
     42
     43    /// <summary>
     44    /// Default constructor.
     45    /// </summary>
     46    protected FunctionBase() { }
     47
     48    protected FunctionBase(FunctionBase original, IDictionary<Guid, object> clonedObjects)
     49      : base(original, clonedObjects) {
     50      this.minArity = original.minArity;
     51      this.maxArity = original.maxArity;
     52    }
    4253
    4354    public virtual double Apply() {
  • branches/CloningRefactorBranch/HeuristicLab.GP/GPOperatorLibrary.cs

    r656 r890  
    2828
    2929namespace HeuristicLab.GP {
    30   public class GPOperatorLibrary : ItemBase, IOperatorLibrary, IEditable  {
     30  public class GPOperatorLibrary : ItemBase, IOperatorLibrary, IEditable {
    3131    // constants for variable names
    3232    internal const string MIN_TREE_HEIGHT = "MinTreeHeight";
     
    3939      get { return group; }
    4040    }
     41    public GPOperatorLibrary(GPOperatorLibrary original) : this(original, new Dictionary<Guid, object>()) { }
     42    protected GPOperatorLibrary(GPOperatorLibrary original, IDictionary<Guid, object> clonedObjects)
     43      : base(original, clonedObjects) {
     44      this.group = (GPOperatorGroup)Auxiliary.Clone(original.group, clonedObjects);
     45    }
     46
    4147    #region IOperatorLibrary Members
    4248
     
    5864
    5965    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    60       GPOperatorLibrary clone = (GPOperatorLibrary)base.Clone(clonedObjects);
    61       clone.group = (GPOperatorGroup)group.Clone(clonedObjects);
    62       return clone;
     66      return new GPOperatorLibrary(this, clonedObjects);
    6367    }
    6468
     
    7276    public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    7377      base.Populate(node, restoredObjects);
    74       group = (GPOperatorGroup) PersistenceManager.Restore(node.SelectSingleNode("Group"), restoredObjects);
     78      group = (GPOperatorGroup)PersistenceManager.Restore(node.SelectSingleNode("Group"), restoredObjects);
    7579    }
    7680    #endregion
Note: See TracChangeset for help on using the changeset viewer.