Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4675


Ignore:
Timestamp:
10/29/10 18:58:23 (14 years ago)
Author:
swagner
Message:

Finished cloning refactoring of HeuristicLab.SequentialEngine and HeuristicLab.Random (#922)

Location:
branches/CloningRefactoring
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactoring/HeuristicLab.Random/3.3/FastRandom.cs

    r4258 r4675  
    5454
    5555    #region Constructors
     56    /// <summary>
     57    /// Used by HeuristicLab.Persistence to initialize new instances during deserialization.
     58    /// </summary>
     59    /// <param name="deserializing">true, if the constructor is called during deserialization.</param>
     60    [StorableConstructor]
     61    private FastRandom(bool deserializing) : base(deserializing) { }
     62
     63    /// <summary>
     64    /// Initializes a new instance from an existing one (copy constructor).
     65    /// </summary>
     66    /// <param name="original">The original <see cref="FastRandom"/> instance which is used to initialize the new instance.</param>
     67    /// <param name="cloner">A <see cref="Cloner"/> which is used to track all already cloned objects in order to avoid cycles.</param>
     68    private FastRandom(FastRandom original, Cloner cloner)
     69      : base(original, cloner) {
     70      x = original.x;
     71      y = original.y;
     72      z = original.z;
     73      w = original.w;
     74      bitBuffer = original.bitBuffer;
     75      bitMask = original.bitMask;
     76    }
    5677
    5778    /// <summary>
     
    7192      Reinitialise(seed);
    7293    }
    73 
    74     /// <summary>
    75     /// Used by HeuristicLab.Persistence to initialize new instances during deserialization.
    76     /// </summary>
    77     /// <param name="deserializing">true, if the constructor is called during deserialization.</param>
    78     [StorableConstructor]
    79     private FastRandom(bool deserializing) : base(deserializing) { }
    80 
    8194    #endregion
    8295
     
    351364
    352365    public override IDeepCloneable Clone(Cloner cloner) {
    353       FastRandom clone = (FastRandom)base.Clone(cloner);
    354       clone.x = x;
    355       clone.y = y;
    356       clone.z = z;
    357       clone.w = w;
    358       clone.bitBuffer = bitBuffer;
    359       clone.bitMask = bitMask;
    360       return clone;
     366      return new FastRandom(this, cloner);
    361367    }
    362368  }
  • branches/CloningRefactoring/HeuristicLab.Random/3.3/MersenneTwister.cs

    r4477 r4675  
    5555
    5656    /// <summary>
     57    /// Used by HeuristicLab.Persistence to initialize new instances during deserialization.
     58    /// </summary>
     59    /// <param name="deserializing">true, if the constructor is called during deserialization.</param>
     60    [StorableConstructor]
     61    private MersenneTwister(bool deserializing) : base(deserializing) { }
     62    /// <summary>
     63    /// Initializes a new instance from an existing one (copy constructor).
     64    /// </summary>
     65    /// <param name="original">The original <see cref="MersenneTwister"/> instance which is used to initialize the new instance.</param>
     66    /// <param name="cloner">A <see cref="Cloner"/> which is used to track all already cloned objects in order to avoid cycles.</param>
     67    private MersenneTwister(MersenneTwister original, Cloner cloner)
     68      : base(original, cloner) {
     69      state = (uint[])original.state.Clone();
     70      p = original.p;
     71      init = original.init;
     72    }
     73    /// <summary>
    5774    /// Initializes a new instance of <see cref="MersenneTwister"/>.
    5875    /// </summary>
     
    7895      init = true;
    7996    }
    80     /// <summary>
    81     /// Used by HeuristicLab.Persistence to initialize new instances during deserialization.
    82     /// </summary>
    83     /// <param name="deserializing">true, if the constructor is called during deserialization.</param>
    84     [StorableConstructor]
    85     private MersenneTwister(bool deserializing) : base(deserializing) { }
    8697
    8798    /// <summary>
     
    91102    /// <returns>The cloned object as <see cref="MersenneTwister"/>.</returns>
    92103    public override IDeepCloneable Clone(Cloner cloner) {
    93       MersenneTwister clone = (MersenneTwister)base.Clone(cloner);
    94       clone.state = (uint[])state.Clone();
    95       clone.p = p;
    96       clone.init = init;
    97       return clone;
     104      return new MersenneTwister(this, cloner);
    98105    }
    99106
  • branches/CloningRefactoring/HeuristicLab.Random/3.3/NormalDistributedRandom.cs

    r4477 r4675  
    450450
    451451    /// <summary>
     452    /// Used by HeuristicLab.Persistence to initialize new instances during deserialization.
     453    /// </summary>
     454    /// <param name="deserializing">true, if the constructor is called during deserialization.</param>
     455    [StorableConstructor]
     456    private NormalDistributedRandom(bool deserializing) : base(deserializing) { }
     457
     458    /// <summary>
     459    /// Initializes a new instance from an existing one (copy constructor).
     460    /// </summary>
     461    /// <param name="original">The original <see cref="NormalDistributedRandom"/> instance which is used to initialize the new instance.</param>
     462    /// <param name="cloner">A <see cref="Cloner"/> which is used to track all already cloned objects in order to avoid cycles.</param>
     463    private NormalDistributedRandom(NormalDistributedRandom original, Cloner cloner)
     464      : base(original, cloner) {
     465      uniform = cloner.Clone(original.uniform);
     466      mu = original.mu;
     467      sigma = original.sigma;
     468    }
     469
     470    /// <summary>
    452471    /// Initializes a new instance of <see cref="NormalDistributedRandom"/> with µ = 0 and sigma = 1
    453472    /// and a new random number generator.
     
    471490      this.uniform = uniformRandom;
    472491    }
    473     /// <summary>
    474     /// Used by HeuristicLab.Persistence to initialize new instances during deserialization.
    475     /// </summary>
    476     /// <param name="deserializing">true, if the constructor is called during deserialization.</param>
    477     [StorableConstructor]
    478     private NormalDistributedRandom(bool deserializing) : base(deserializing) { }
    479492
    480493    #region IRandom Members
     
    529542    /// <returns>The cloned object as <see cref="NormalDistributedRandom"/>.</returns>
    530543    public override IDeepCloneable Clone(Cloner cloner) {
    531       NormalDistributedRandom clone = (NormalDistributedRandom)base.Clone(cloner);
    532       clone.uniform = (IRandom)cloner.Clone(uniform);
    533       clone.mu = mu;
    534       clone.sigma = sigma;
    535       return clone;
     544      return new NormalDistributedRandom(this, cloner);
    536545    }
    537546
  • branches/CloningRefactoring/HeuristicLab.Random/3.3/NormalRandomizer.cs

    r4477 r4675  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
     
    3334  [Item("NormalRandomizer", "Initializes the value of variable 'Value' to a random value normally distributed with parameters 'Mu' and 'Sigma'")]
    3435  public class NormalRandomizer : SingleSuccessorOperator {
    35     #region parameter properties
     36    #region Parameter Properties
    3637    public ILookupParameter<IRandom> RandomParameter {
    3738      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     
    4748    }
    4849    #endregion
     50
    4951    #region Properties
    5052    public DoubleValue Mu {
     
    5759    }
    5860    #endregion
     61
     62    [StorableConstructor]
     63    protected NormalRandomizer(bool deserializing) : base(deserializing) { }
     64    protected NormalRandomizer(NormalRandomizer original, Cloner cloner) : base(original, cloner) { }
    5965    /// <summary>
    6066    /// Initializes a new instance of <see cref="NormalRandomizer"/> with four variable infos
     
    6773      Parameters.Add(new LookupParameter<DoubleValue>("Value", "The value that should be set to a random value."));
    6874    }
    69     [StorableConstructor]
    70     protected NormalRandomizer(bool deserializing) : base(deserializing) { }
     75
     76    public override IDeepCloneable Clone(Cloner cloner) {
     77      return new NormalRandomizer(this, cloner);
     78    }
    7179
    7280    /// <summary>
  • branches/CloningRefactoring/HeuristicLab.Random/3.3/RandomCreator.cs

    r4258 r4675  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
     
    3334  [StorableClass]
    3435  public sealed class RandomCreator : SingleSuccessorOperator {
     36    #region Parameter Properties
    3537    public ValueLookupParameter<BoolValue> SetSeedRandomlyParameter {
    3638      get { return (ValueLookupParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
     
    4547      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
    4648    }
     49    #endregion
     50
     51    #region Properties
    4752    public BoolValue SetSeedRandomly {
    4853      get { return SetSeedRandomlyParameter.Value; }
     
    5762      set { RandomTypeParameter.Value = value; }
    5863    }
     64    #endregion
    5965
     66    [StorableConstructor]
     67    private RandomCreator(bool deserializing) : base(deserializing) { }
     68    private RandomCreator(RandomCreator original, Cloner cloner) : base(original, cloner) { }
    6069    public RandomCreator()
    6170      : base() {
     
    6574      Parameters.Add(new LookupParameter<IRandom>("Random", "The new pseudo random number generator which is initialized with the given seed."));
    6675    }
    67     [StorableConstructor]
    68     private RandomCreator(bool deserializing) : base(deserializing) { }
    6976
    7077    // BackwardsCompatibility3.3
    7178    #region Backwards compatible code (remove with 3.4)
    7279    [StorableHook(HookType.AfterDeserialization)]
    73     private void AfterDeserializationHook() {
     80    private void AfterDeserialization() {
    7481      if (!Parameters.ContainsKey("RandomType"))
    7582        Parameters.Add(new ValueParameter<IRandom>("RandomType", "The type of pseudo random number generator which is created.", new MersenneTwister()));
    7683    }
    7784    #endregion
     85
     86    public override IDeepCloneable Clone(Cloner cloner) {
     87      return new RandomCreator(this, cloner);
     88    }
    7889
    7990    public override IOperation Apply() {
  • branches/CloningRefactoring/HeuristicLab.Random/3.3/UniformRandomizer.cs

    r4477 r4675  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
     
    3334  [Item("UniformRandomizer", "Initializes the value of variable 'Value' to a random value uniformly distributed between 'Min' and 'Max'")]
    3435  public class UniformRandomizer : SingleSuccessorOperator {
    35     #region parameter properties
     36    #region Parameter Properties
    3637    public ILookupParameter<IRandom> RandomParameter {
    3738      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     
    4748    }
    4849    #endregion
     50
    4951    #region Properties
    5052    public DoubleValue Min {
     
    5860    #endregion
    5961
     62    [StorableConstructor]
     63    protected UniformRandomizer(bool deserializing) : base(deserializing) { }
     64    protected UniformRandomizer(UniformRandomizer original, Cloner cloner) : base(original, cloner) { }
    6065    /// <summary>
    6166    /// Initializes a new instance of <see cref="UniformRandomizer"/> with four variable infos
     
    7075      Parameters.Add(new LookupParameter<DoubleValue>("Value", "The value that should be set to a random value."));
    7176    }
    72     [StorableConstructor]
    73     protected UniformRandomizer(bool deserializing) : base(deserializing) { }
     77
     78    public override IDeepCloneable Clone(Cloner cloner) {
     79      return new UniformRandomizer(this, cloner);
     80    }
    7481
    7582    /// <summary>
  • branches/CloningRefactoring/HeuristicLab.SequentialEngine/3.3/SequentialEngine.cs

    r4477 r4675  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3334  public class SequentialEngine : Engine {
    3435    private IOperator currentOperator;
     36
     37    [StorableConstructor]
     38    protected SequentialEngine(bool deserializing) : base(deserializing) { }
     39    protected SequentialEngine(SequentialEngine original, Cloner cloner) : base(original, cloner) { }
     40    public SequentialEngine() : base() { }
     41
     42    public override IDeepCloneable Clone(Cloner cloner) {
     43      return new SequentialEngine(this, cloner);
     44    }
    3545
    3646    /// <summary>
Note: See TracChangeset for help on using the changeset viewer.