Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/02/08 21:10:17 (15 years ago)
Author:
gkronber
Message:

Refactored cloning in all plugins except: HL.Communication, HL.Hive, HL.GP, HL.Routing, HL.Scheduling, HL.SimOpt, HL.Visualization

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactorBranch/HeuristicLab.Random/NormalDistributedRandom.cs

    r344 r887  
    452452    }
    453453
     454    /// <summary>
     455    /// Copy constructor to create deep clones.
     456    /// </summary>
     457    /// <param name="original">The instance to be cloned.</param>
     458    public NormalDistributedRandom(NormalDistributedRandom original) : this(original, new Dictionary<Guid, object>()) { }
     459    /// <summary>
     460    /// Copy constructor to create deep clones reusing already cloned object references.
     461    /// </summary>
     462    /// <param name="original">The instance to be cloned.</param>
     463    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     464    protected NormalDistributedRandom(NormalDistributedRandom original, IDictionary<Guid, object> clonedObjects)
     465      : base(original, clonedObjects) {
     466      this.uniform = (IRandom)Auxiliary.Clone(original.uniform, clonedObjects);
     467      this.mu = original.mu;
     468      this.sigma = original.sigma;
     469    }
     470
    454471    #region IRandom Members
    455472
     
    511528    #endregion
    512529
     530    /// <summary>
     531    /// Creates a deep clone with the copy constructor reusing already cloned
     532    /// object references.
     533    /// </summary>
     534    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     535    /// <returns>The cloned instance.</returns>
     536    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     537      return new NormalDistributedRandom(this, clonedObjects);
     538    }
    513539    #region persistence
    514540    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
     
    536562    }
    537563
    538     public override object Clone(IDictionary<Guid, object> clonedObjects) {
    539       NormalDistributedRandom clone = new NormalDistributedRandom((IRandom)Auxiliary.Clone(uniform, clonedObjects), mu, sigma);
    540       clonedObjects.Add(Guid, clone);
    541       return clone;
    542     }
    543 
    544564    #endregion
    545565  }
Note: See TracChangeset for help on using the changeset viewer.