Free cookie consent management tool by TermsFeed Policy Generator

Changeset 887


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())

Location:
branches/CloningRefactorBranch
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactorBranch/HeuristicLab.CEDMA.Charting/HeuristicLab.CEDMA.Charting.csproj

    r656 r887  
    44    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    55    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    6     <ProductVersion>9.0.21022</ProductVersion>
     6    <ProductVersion>9.0.30729</ProductVersion>
    77    <SchemaVersion>2.0</SchemaVersion>
    88    <ProjectGuid>{1BF17271-5350-476A-8F6D-FC74FA3E82CA}</ProjectGuid>
  • branches/CloningRefactorBranch/HeuristicLab.CEDMA.Core/OperatorLink.cs

    r513 r887  
    4444    }
    4545
    46     public OperatorLink() : base() { } // for cloning and persistence
     46    public OperatorLink() { } // for cloning and persistence
    4747
    4848    public OperatorLink(long id, IOperator op)
     
    5151      this.myOperator = op;
    5252      Name = myOperator.Name;
     53    }
     54
     55    public OperatorLink(OperatorLink original) : this(original, new Dictionary<Guid, object>()) { }
     56    protected OperatorLink(OperatorLink original, IDictionary<Guid, object> clonedObjects)
     57      : base(original, clonedObjects) {
     58      this.id = original.id;
     59      this.myOperator = (IOperator)Auxiliary.Clone(Operator, clonedObjects);
    5360    }
    5461
     
    6269
    6370    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    64       OperatorLink clone = (OperatorLink)base.Clone(clonedObjects);
    65       clone.id = id;
    66       clone.myOperator = Operator;
    67       return clone;
     71      return new OperatorLink(this, clonedObjects);
    6872    }
    6973
  • branches/CloningRefactorBranch/HeuristicLab.Core/OperatorBase.cs

    r885 r887  
    105105
    106106    /// <summary>
    107     /// Copy constructor.
    108     /// </summary>
    109     /// <param name="original">The original instance to be cloned</param>
     107    /// Copy constructor to create deep clones reusing already cloned object references.
     108    /// </summary>
     109    /// <param name="original">The instance to be cloned.</param>
    110110    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
    111111    protected OperatorBase(OperatorBase original, IDictionary<Guid, object> clonedObjects)
     
    130130    public override IView CreateView() {
    131131      return new OperatorBaseView(this);
     132    }
     133
     134    /// <summary>
     135    /// Creates a deep clone with the copy constructor reusing already cloned
     136    /// object references.
     137    /// </summary>
     138    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     139    /// <returns>The cloned instance.</returns>
     140    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     141      // override clone for all classes inheriting from OperatorBase, so
     142      // we don't need to implement Clone() and the copy constructors in
     143      // every single operator.
     144      return Activator.CreateInstance(this.GetType(), this, clonedObjects);
    132145    }
    133146
  • branches/CloningRefactorBranch/HeuristicLab.DataAnalysis/Dataset.cs

    r534 r887  
    105105    }
    106106
     107    /// <summary>
     108    /// Copy constructor to create deep clones.
     109    /// </summary>
     110    /// <param name="original">The instance to be cloned.</param>
     111    public Dataset(Dataset original) : this(original, new Dictionary<Guid, object>()) { }
     112    /// <summary>
     113    /// Copy constructor to create deep clones reusing already cloned object references.
     114    /// </summary>
     115    /// <param name="original">The instance to be cloned.</param>
     116    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     117    protected Dataset(Dataset original, IDictionary<Guid, object> clonedObjects)
     118      : base(original, clonedObjects) {
     119      double[] cloneSamples = new double[original.rows * original.columns];
     120      Array.Copy(original.samples, cloneSamples, original.samples.Length);
     121      this.rows = original.rows;
     122      this.columns = original.columns;
     123      this.Samples = cloneSamples;
     124      this.Name = original.Name;
     125      this.VariableNames = new string[original.VariableNames.Length];
     126      Array.Copy(original.VariableNames, this.VariableNames, original.VariableNames.Length);
     127      Array.Copy(original.scalingFactor, this.scalingFactor, original.columns);
     128      Array.Copy(original.scalingOffset, this.scalingOffset, original.columns);
     129    }
     130
    107131    private void CreateDictionaries() {
    108132      // keep a means and ranges dictionary for each column (possible target variable) of the dataset.
     
    119143    }
    120144
     145    /// <summary>
     146    /// Creates a deep clone with the copy constructor reusing already cloned
     147    /// object references.
     148    /// </summary>
     149    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     150    /// <returns>The cloned instance.</returns>
    121151    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    122       Dataset clone = new Dataset();
    123       clonedObjects.Add(Guid, clone);
    124       double[] cloneSamples = new double[rows * columns];
    125       Array.Copy(samples, cloneSamples, samples.Length);
    126       clone.rows = rows;
    127       clone.columns = columns;
    128       clone.Samples = cloneSamples;
    129       clone.Name = Name;
    130       clone.VariableNames = new string[VariableNames.Length];
    131       Array.Copy(VariableNames, clone.VariableNames, VariableNames.Length);
    132       Array.Copy(scalingFactor, clone.scalingFactor, columns);
    133       Array.Copy(scalingOffset, clone.scalingOffset, columns);
    134       return clone;
     152      return new Dataset(this, clonedObjects);
    135153    }
    136154
  • branches/CloningRefactorBranch/HeuristicLab.DistributedEngine/DistributedEngine.cs

    r438 r887  
    4747      }
    4848    }
     49
     50    /// <summary>
     51    /// Default constructor
     52    /// </summary>
     53    public DistributedEngine() { }
     54
     55    /// <summary>
     56    /// Copy constructor to create deep clones.
     57    /// </summary>
     58    /// <param name="original">The instance to be cloned.</param>
     59    public DistributedEngine(DistributedEngine original) : this(original, new Dictionary<Guid, object>()) { }
     60
     61    /// <summary>
     62    /// Copy constructor for DistributedEngine clones (deep clone) reusing already cloned object references
     63    /// </summary>
     64    /// <remarks>Calls the copy constructor of the base class <see cref="EngineBase"/></remarks>
     65    /// <param name="original">Instance to be cloned</param>
     66    /// <param name="clonedObjects">Already cloned object reference</param>
     67    protected DistributedEngine(DistributedEngine original, IDictionary<Guid, object> clonedObjects)
     68      : base(original, clonedObjects) {
     69      this.ServerAddress = original.ServerAddress;
     70    }
     71    /// <summary>
     72    /// Creates a deep clone with the copy constructor reusing already cloned
     73    /// object references.
     74    /// </summary>
     75    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     76    /// <returns>The cloned instance.</returns>
    4977    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    50       DistributedEngine clone = (DistributedEngine)base.Clone(clonedObjects);
    51       clone.ServerAddress = serverAddress;
    52       return clone;
     78      return new DistributedEngine(this, clonedObjects);
    5379    }
    5480
     
    313339    }
    314340
     341
    315342    #region Persistence Methods
    316343    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
  • branches/CloningRefactorBranch/HeuristicLab.ES/ES.cs

    r98 r887  
    548548    }
    549549
     550    public ES(ES original) : this(original, new Dictionary<Guid, object>()) { }
     551    protected ES(ES original, IDictionary<Guid, object> clonedObjects)
     552      : base(original, clonedObjects) {
     553      this.myEngine = (IEngine)Auxiliary.Clone(original.Engine, clonedObjects);
     554    }
     555
    550556    public override IView CreateView() {
    551557      return new ESEditor(this);
     
    556562
    557563    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    558       ES clone = new ES();
    559       clonedObjects.Add(Guid, clone);
    560       clone.myEngine = (IEngine)Auxiliary.Clone(Engine, clonedObjects);
    561       return clone;
     564      return new ES(this, clonedObjects);
    562565    }
    563566
  • branches/CloningRefactorBranch/HeuristicLab.Logging/Linechart.cs

    r2 r887  
    5959    }
    6060
     61    /// <summary>
     62    /// Copy constructor to create deep clones.
     63    /// </summary>
     64    /// <param name="original">The instance to be cloned.</param>
     65    public Linechart(Linechart original) : this(original, new Dictionary<Guid, object>()) { }
    6166
     67
     68    /// <summary>
     69    /// Copy constructor for DistributedEngine clones (deep clone) reusing already cloned object references
     70    /// </summary>
     71    /// <remarks>Calls the copy constructor of the base class <see cref="EngineBase"/></remarks>
     72    /// <param name="original">Instance to be cloned</param>
     73    /// <param name="clonedObjects">Already cloned object reference</param>
     74    protected Linechart(Linechart original, IDictionary<Guid, object> clonedObjects)
     75      : base(original, clonedObjects) {
     76      this.myNumberOfLines = (IntData)Auxiliary.Clone(original.myNumberOfLines,clonedObjects);
     77      this.myValues = (ItemList)Auxiliary.Clone(original.Values, clonedObjects);
     78    }
     79
     80    /// <summary>
     81    /// Creates a deep clone with the copy constructor reusing already cloned
     82    /// object references.
     83    /// </summary>
     84    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     85    /// <returns>The cloned instance.</returns>
    6286    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    63       Linechart clone = (Linechart)base.Clone(clonedObjects);
    64       clone.myNumberOfLines = (IntData)Auxiliary.Clone(myNumberOfLines, clonedObjects);
    65       clone.myValues = (ItemList)Auxiliary.Clone(Values, clonedObjects);
    66       return clone;
     87      return new Linechart(this, clonedObjects);
    6788    }
    6889
  • branches/CloningRefactorBranch/HeuristicLab.Logging/Log.cs

    r2 r887  
    4141    }
    4242
     43    /// <summary>
     44    /// Copy constructor to create deep clones.
     45    /// </summary>
     46    /// <param name="original">The instance to be cloned.</param>
     47    public Log(Log original) : this(original, new Dictionary<Guid, object>()) { }
     48    /// <summary>
     49    /// Copy constructor for DistributedEngine clones (deep clone) reusing already cloned object references
     50    /// </summary>
     51    /// <remarks>Calls the copy constructor of the base class <see cref="EngineBase"/></remarks>
     52    /// <param name="original">Instance to be cloned</param>
     53    /// <param name="clonedObjects">Already cloned object reference</param>
     54    protected Log(Log original, IDictionary<Guid, object> clonedObjects)
     55      : base(original, clonedObjects) {
     56      this.myItems = (ItemList)Auxiliary.Clone(original.Items, clonedObjects);
     57    }
    4358
     59    /// <summary>
     60    /// Creates a deep clone with the copy constructor reusing already cloned
     61    /// object references.
     62    /// </summary>
     63    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     64    /// <returns>The cloned instance.</returns>
    4465    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    45       Log clone = (Log)base.Clone(clonedObjects);
    46       clone.myItems = (ItemList)Auxiliary.Clone(Items, clonedObjects);
    47       return clone;
     66      return new Log(this, clonedObjects);
    4867    }
    4968
  • branches/CloningRefactorBranch/HeuristicLab.Logging/PointXYChart.cs

    r677 r887  
    6161    }
    6262
     63    /// <summary>
     64    /// Copy constructor to create deep clones.
     65    /// </summary>
     66    /// <param name="original">The instance to be cloned.</param>
     67    public PointXYChart(PointXYChart original) : this(original, new Dictionary<Guid, object>()) { }
     68    /// <summary>
     69    /// Copy constructor for DistributedEngine clones (deep clone) reusing already cloned object references
     70    /// </summary>
     71    /// <remarks>Calls the copy constructor of the base class <see cref="EngineBase"/></remarks>
     72    /// <param name="original">Instance to be cloned</param>
     73    /// <param name="clonedObjects">Already cloned object reference</param>
     74    protected PointXYChart(PointXYChart original, IDictionary<Guid, object> clonedObjects)
     75      : base(original, clonedObjects) {
     76      this.myValues = (ItemList)Auxiliary.Clone(original.Values, clonedObjects);
     77    }
     78
     79    /// <summary>
     80    /// Creates a deep clone with the copy constructor reusing already cloned
     81    /// object references.
     82    /// </summary>
     83    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     84    /// <returns>The cloned instance.</returns>
    6385    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    64       PointXYChart clone = (PointXYChart)base.Clone(clonedObjects);
    65       clone.myValues = (ItemList)Auxiliary.Clone(Values, clonedObjects);
    66       return clone;
     86      return new PointXYChart(this, clonedObjects);
    6787    }
    6888
  • branches/CloningRefactorBranch/HeuristicLab.Operators.Programmable/HeuristicLabOperatorsProgrammablePlugin.cs

    r582 r887  
    2525using HeuristicLab.PluginInfrastructure;
    2626
    27 namespace HeuristicLab.Operators {
     27namespace HeuristicLab.Operators.Programmable {
    2828  [ClassInfo(Name = "HeuristicLab.Operators.Programmable-3.2")]
    2929  [PluginFile(Filename = "HeuristicLab.Operators.Programmable-3.2.dll", Filetype = PluginFileType.Assembly)]
  • branches/CloningRefactorBranch/HeuristicLab.Operators.Programmable/ProgrammableOperator.cs

    r694 r887  
    5555    }
    5656
     57    /// <summary>
     58    /// Default constructor.
     59    /// </summary>
    5760    public ProgrammableOperator() {
    5861      myCode = "Result.Data = true;";
     
    6063      AddVariableInfo(new VariableInfo("Result", "A computed variable", typeof(BoolData), VariableKind.New | VariableKind.Out));
    6164      executeMethod = null;
     65    }
     66
     67
     68    /// <summary>
     69    /// Copy constructor to create deep clones.
     70    /// </summary>
     71    /// <param name="original">The instance to be cloned.</param>
     72    public ProgrammableOperator(ProgrammableOperator original) : this(original, new Dictionary<Guid, object>()) { }
     73    /// <summary>
     74    /// Copy constructor to create a deep clone of an ProgrammableOperator instance.
     75    /// </summary>
     76    /// <param name="original">The original instance to be cloned.</param>
     77    /// <param name="clonedObjects">Already cloned object references.</param>
     78    protected ProgrammableOperator(ProgrammableOperator original, IDictionary<Guid, object> clonedObjects)
     79      : base(original, clonedObjects) {
     80      this.myDescription = original.Description;
     81      this.myCode = original.Code;
     82      this.executeMethod = original.executeMethod;
    6283    }
    6384
     
    143164    }
    144165
    145     public override object Clone(IDictionary<Guid, object> clonedObjects) {
    146       ProgrammableOperator clone = (ProgrammableOperator)base.Clone(clonedObjects);
    147       clone.myDescription = Description;
    148       clone.myCode = Code;
    149       clone.executeMethod = executeMethod;
    150       return clone;
    151     }
    152 
    153166    public override IOperation Apply(IScope scope) {
    154167      if (executeMethod == null) {
     
    196209    }
    197210
     211
     212    /// <summary>
     213    /// Creates a deep clone with the copy constructor reusing already cloned
     214    /// object references.
     215    /// </summary>
     216    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     217    /// <returns>The cloned instance.</returns>
     218    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     219      return new ProgrammableOperator(this, clonedObjects);
     220    }
    198221    #region Persistence Methods
    199222    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
  • branches/CloningRefactorBranch/HeuristicLab.Operators.Stopwatch/Stopwatch.cs

    r693 r887  
    4040    }
    4141
     42    /// <summary>
     43    /// Copy constructor to create deep clones.
     44    /// </summary>
     45    /// <param name="original">The instance to be cloned.</param>
     46    public Stopwatch(Stopwatch original) : this(original, new Dictionary<Guid, object>()) { }
     47    /// <summary>
     48    /// Copy constructor to create deep clones reusing already cloned object references.
     49    /// </summary>
     50    /// <param name="original">The instance to be cloned.</param>
     51    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     52    protected Stopwatch(Stopwatch original, IDictionary<Guid, object> clonedObjects)
     53      : base(original, clonedObjects) {
     54      elapsedTime = original.elapsedTime;
     55      if (original.running) this.Start();
     56    }
     57
    4258    public void Start() {
    4359      stopwatch.Start();
     
    5874    }
    5975
     76    /// <summary>
     77    /// Creates a deep clone with the copy constructor reusing already cloned
     78    /// object references.
     79    /// </summary>
     80    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     81    /// <returns>The cloned instance.</returns>
    6082    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    61       Stopwatch clone = (Stopwatch)base.Clone(clonedObjects);
    62       if(running) clone.Start();
    63       clone.elapsedTime = elapsedTime;
    64       return clone;
     83      return new Stopwatch(this, clonedObjects);
    6584    }
    6685
    67     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
     86    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    6887      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    6988      XmlAttribute runningAttr = document.CreateAttribute("Running");
     
    7594      return node;
    7695    }
    77     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
     96    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    7897      long elapsedTicks = long.Parse(node.Attributes["ElapsedTicks"].Value);
    7998      elapsedTime = TimeSpan.FromTicks(elapsedTicks);
    8099      running = bool.Parse(node.Attributes["Running"].Value);
    81       if(running) stopwatch.Start();
     100      if (running) stopwatch.Start();
    82101      base.Populate(node, restoredObjects);
    83102    }
  • branches/CloningRefactorBranch/HeuristicLab.Operators/CombinedOperator.cs

    r801 r887  
    6161
    6262    /// <summary>
     63    /// Copy constructor for CombinedOperators (deep clone).
     64    /// </summary>
     65    /// <remarks>Calls <see cref="OperatorBase
     66    /// (System.Collections.Generic.IDictionary&lt;System.Guid, object&gt;)"/>
     67    /// of base class <see cref="DelegatingOperator"/>.<br/>
     68    /// Deep clone through <see cref="Auxiliary.Clone"/> method of helper class
     69    /// <see cref="Auxiliary"/>.</remarks>
     70    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
     71    /// <returns>The cloned object as <see cref="CombinedOperator"/>.</returns>
     72    public CombinedOperator(CombinedOperator original, IDictionary<Guid, object> clonedObjects)
     73      : base(original, clonedObjects) {
     74      this.myDescription = original.Description;
     75      this.myOperatorGraph = (IOperatorGraph)Auxiliary.Clone(original.OperatorGraph, clonedObjects);
     76    }
     77
     78    /// <summary>
    6379    /// Sets the description of the current instance.
    6480    /// </summary>
     
    7995    /// Clones the current instance (deep clone).
    8096    /// </summary>
    81     /// <remarks>Calls <see cref="OperatorBase.Clone
    82     /// (System.Collections.Generic.IDictionary&lt;System.Guid, object&gt;)"/>
    83     /// of base class <see cref="DelegatingOperator"/>.<br/>
    84     /// Deep clone through <see cref="Auxiliary.Clone"/> method of helper class
    85     /// <see cref="Auxiliary"/>.</remarks>
     97    /// <remarks>Calls the copy constructor <see cref="CombinedOperator
     98    /// (System.Collections.Generic.IDictionary&lt;System.Guid, object&gt;)"/> .<br/>
     99    ///</remarks>
    86100    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
    87101    /// <returns>The cloned object as <see cref="CombinedOperator"/>.</returns>
    88102    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    89       CombinedOperator clone = (CombinedOperator)base.Clone(clonedObjects);
    90       clone.myDescription = Description;
    91       clone.myOperatorGraph = (IOperatorGraph)Auxiliary.Clone(OperatorGraph, clonedObjects);
    92       return clone;
     103      return new CombinedOperator(this, clonedObjects);
    93104    }
    94105
  • branches/CloningRefactorBranch/HeuristicLab.Operators/DelegatingOperator.cs

    r801 r887  
    3131  /// </summary>
    3232  public abstract class DelegatingOperator : OperatorBase {
     33
     34    /// <summary>
     35    ///  Default constructor for DelegatingOperator
     36    /// </summary>
     37    public DelegatingOperator() { }
     38
     39    public DelegatingOperator(DelegatingOperator original, IDictionary<Guid, object> clonedObjects)
     40      : base(original, clonedObjects) { }
     41
    3342    /// <summary>
    3443    /// Executes the specified operator in the given <paramref name="scope"/>.
     
    4251      myCanceled = false;
    4352
    44       if(scope.GetVariable(Guid.ToString()) == null) { // contained operator not yet executed
     53      if (scope.GetVariable(Guid.ToString()) == null) { // contained operator not yet executed
    4554        // add marker
    4655        scope.AddVariable(new Variable(Guid.ToString(), new NullData()));
  • branches/CloningRefactorBranch/HeuristicLab.Permutation/Permutation.cs

    r2 r887  
    3535    }
    3636
     37    public Permutation(Permutation original) : this(original, new Dictionary<Guid, object>()) { }
     38    protected Permutation(Permutation original, IDictionary<Guid, object> clonedObjects)
     39      : base(original, clonedObjects) {
     40      this.Data = (int[])original.Data.Clone();
     41    }
     42
    3743    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    38       Permutation clone = new Permutation((int[])Data.Clone());
    39       clonedObjects.Add(Guid, clone);
    40       return clone;
     44      return new Permutation(this, clonedObjects);
    4145    }
    4246  }
  • branches/CloningRefactorBranch/HeuristicLab.Random/MersenneTwister.cs

    r2 r887  
    5959      init = true;
    6060    }
    61 
     61    /// <summary>
     62    /// Copy constructor to create deep clones.
     63    /// </summary>
     64    /// <param name="original">The instance to be cloned.</param>
     65    public MersenneTwister(MersenneTwister original) : this(original, new Dictionary<Guid, object>()) { }
     66    /// <summary>
     67    /// Copy constructor to create deep clones reusing already cloned object references.
     68    /// </summary>
     69    /// <param name="original">The instance to be cloned.</param>
     70    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     71    protected MersenneTwister(MersenneTwister original, IDictionary<Guid, object> clonedObjects)
     72      : base(original, clonedObjects) {
     73      this.state = (uint[])original.state.Clone();
     74      this.p = original.p;
     75      this.init = original.init;
     76    }
     77
     78    /// <summary>
     79    /// Creates a deep clone with the copy constructor reusing already cloned
     80    /// object references.
     81    /// </summary>
     82    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     83    /// <returns>The cloned instance.</returns>
    6284    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    63       MersenneTwister clone = new MersenneTwister();
    64       clonedObjects.Add(Guid, clone);
    65       clone.state = (uint[])state.Clone();
    66       clone.p = p;
    67       clone.init = init;
    68       return clone;
     85      return new MersenneTwister(this, clonedObjects);
    6986    }
    7087
  • 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  }
  • branches/CloningRefactorBranch/HeuristicLab.SGA/SGA.cs

    r65 r887  
    458458      SetReferences();
    459459    }
     460    public SGA(SGA original) : this(original, new Dictionary<Guid, object>()) { }
     461    protected SGA(SGA original, IDictionary<Guid, object> clonedObjects)
     462      : base(original, clonedObjects) {
     463      this.myEngine = (IEngine)Auxiliary.Clone(original.Engine, clonedObjects);
     464    }
    460465
    461466    public override IView CreateView() {
     
    467472
    468473    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    469       SGA clone = new SGA();
    470       clonedObjects.Add(Guid, clone);
    471       clone.myEngine = (IEngine)Auxiliary.Clone(Engine, clonedObjects);
    472       return clone;
     474      return new SGA(this, clonedObjects);
    473475    }
    474476
  • branches/CloningRefactorBranch/HeuristicLab.SequentialEngine/SequentialEngine.cs

    r2 r887  
    3030    private IOperator currentOperator;
    3131
     32    /// <summary>
     33    /// Default constructor
     34    /// </summary>
     35    public SequentialEngine() { }
     36
     37    /// <summary>
     38    /// Copy constructor to create deep clones.
     39    /// </summary>
     40    /// <param name="original">The instance to be cloned.</param>
     41    public SequentialEngine(SequentialEngine original) : this(original, new Dictionary<Guid, object>()) { }
     42    /// <summary>
     43    /// Copy constructor to create deep clones reusing already cloned object references.
     44    /// </summary>
     45    /// <param name="original">The instance to be cloned.</param>
     46    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     47    protected SequentialEngine(SequentialEngine original, IDictionary<Guid, object> clonedObjects)
     48      : base(original, clonedObjects) { }
    3249    public override IView CreateView() {
    3350      return new SequentialEngineEditor(this);
     
    5673          myExecutionStack.Push(atomicOperation);
    5774          Abort();
    58           ThreadPool.QueueUserWorkItem(delegate(object state) { OnExceptionOccurred(ex);});
     75          ThreadPool.QueueUserWorkItem(delegate(object state) { OnExceptionOccurred(ex); });
    5976        }
    6077        if (next != null)
     
    6885      }
    6986    }
     87
     88    /// <summary>
     89    /// Creates a deep clone with the copy constructor reusing already cloned
     90    /// object references.
     91    /// </summary>
     92    /// <param name="clonedObjects">Already cloned objects (for referential integrity).</param>
     93    /// <returns>The cloned instance.</returns>
     94    public override object Clone(IDictionary<Guid, object> clonedObjects) {
     95      return new SequentialEngine(this, clonedObjects);
     96    }
    7097  }
    7198}
  • branches/CloningRefactorBranch/HeuristicLab.ThreadParallelEngine/ThreadParallelEngine.cs

    r2 r887  
    5858    }
    5959
     60    public ThreadParallelEngine(ThreadParallelEngine original) : this(original, new Dictionary<Guid, object>()) { }
     61    protected ThreadParallelEngine(ThreadParallelEngine original, IDictionary<Guid, object> clonedObjects)
     62      : base(original, clonedObjects) {
     63      this.myWorkers = original.Workers;
     64    }
    6065
    6166    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    62       ThreadParallelEngine clone = (ThreadParallelEngine)base.Clone(clonedObjects);
    63       clone.myWorkers = Workers;
    64       return clone;
     67      return new ThreadParallelEngine(this, clonedObjects);
    6568    }
    6669
Note: See TracChangeset for help on using the changeset viewer.