Changeset 4258


Ignore:
Timestamp:
08/19/10 05:38:47 (12 years ago)
Author:
swagner
Message:

Worked in integration of FastRandom PRNG (#1114)

Location:
trunk/sources/HeuristicLab.Random/3.3
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Random/3.3/FastRandom.cs

    r4243 r4258  
    11using System;
     2using HeuristicLab.Common;
    23using HeuristicLab.Core;
    34using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    4344  /// </summary>
    4445  [StorableClass]
    45   public class FastRandom : Item, IRandom {
     46  public sealed class FastRandom : Item, IRandom {
    4647    // The +1 ensures NextDouble doesn't generate 1.0
    4748    private const double REAL_UNIT_INT = 1.0 / ((double)int.MaxValue + 1.0);
     
    7071      Reinitialise(seed);
    7172    }
     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) { }
    7280
    7381    #endregion
     
    319327      }
    320328      return (bitBuffer & (bitMask >>= 1)) == 0;
    321     }           
     329    }
    322330    // Buffer 32 bits in bitBuffer, return 1 at a time, keep track of how many have been returned
    323331    // with bitBufferIdx.
     
    328336
    329337
    330     #endregion   
     338    #endregion
    331339
    332340    #region IRandom Members
     
    340348    }
    341349
    342     #endregion   
    343 
    344     public override Common.IDeepCloneable Clone(Common.Cloner cloner) {
     350    #endregion
     351
     352    public override IDeepCloneable Clone(Cloner cloner) {
    345353      FastRandom clone = (FastRandom)base.Clone(cloner);
    346354      clone.x = x;
  • trunk/sources/HeuristicLab.Random/3.3/HeuristicLab.Random-3.3.csproj

    r4243 r4258  
    108108  <ItemGroup>
    109109    <None Include="HeuristicLabRandomPlugin.cs.frame" />
    110     <Compile Include="FastRandomCreator.cs" />
    111110    <Compile Include="FastRandom.cs" />
    112111    <Compile Include="HeuristicLabRandomPlugin.cs" />
  • trunk/sources/HeuristicLab.Random/3.3/MersenneTwister.cs

    r3376 r4258  
    4343  [Item("MersenneTwister", "A high-quality pseudo random number generator which creates uniformly distributed random numbers.")]
    4444  [StorableClass]
    45   public class MersenneTwister : Item, IRandom {
     45  public sealed class MersenneTwister : Item, IRandom {
    4646    private const int n = 624, m = 397;
    4747
     
    7878      init = true;
    7979    }
     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) { }
    8086
    8187    /// <summary>
  • trunk/sources/HeuristicLab.Random/3.3/NormalDistributedRandom.cs

    r3997 r4258  
    3434  [Item("NormalDistributedRandom", "A pseudo random number generator which uses the Ziggurat method to create normally distributed random numbers.")]
    3535  [StorableClass]
    36   public class NormalDistributedRandom : Item, IRandom {
     36  public sealed class NormalDistributedRandom : Item, IRandom {
    3737    [Storable]
    3838    private double mu;
     
    471471      this.uniform = uniformRandom;
    472472    }
     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) { }
    473479
    474480    #region IRandom Members
  • trunk/sources/HeuristicLab.Random/3.3/NormalRandomizer.cs

    r4068 r4258  
    6767      Parameters.Add(new LookupParameter<DoubleValue>("Value", "The value that should be set to a random value."));
    6868    }
     69    [StorableConstructor]
     70    protected NormalRandomizer(bool deserializing) : base(deserializing) { }
    6971
    7072    /// <summary>
  • trunk/sources/HeuristicLab.Random/3.3/RandomCreator.cs

    r4068 r4258  
    3939      get { return (ValueLookupParameter<IntValue>)Parameters["Seed"]; }
    4040    }
     41    public ValueParameter<IRandom> RandomTypeParameter {
     42      get { return (ValueParameter<IRandom>)Parameters["RandomType"]; }
     43    }
    4144    public LookupParameter<IRandom> RandomParameter {
    4245      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     
    5053      set { SeedParameter.Value = value; }
    5154    }
     55    public IRandom RandomType {
     56      get { return RandomTypeParameter.Value; }
     57      set { RandomTypeParameter.Value = value; }
     58    }
    5259
    5360    public RandomCreator()
     
    5562      Parameters.Add(new ValueLookupParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    5663      Parameters.Add(new ValueLookupParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
     64      Parameters.Add(new ValueParameter<IRandom>("RandomType", "The type of pseudo random number generator which is created.", new MersenneTwister()));
    5765      Parameters.Add(new LookupParameter<IRandom>("Random", "The new pseudo random number generator which is initialized with the given seed."));
    5866    }
     67    [StorableConstructor]
     68    private RandomCreator(bool deserializing) : base(deserializing) { }
     69
     70    // BackwardsCompatibility3.3
     71    #region Backwards compatible code (remove with 3.4)
     72    [StorableHook(HookType.AfterDeserialization)]
     73    private void AfterDeserializationHook() {
     74      if (!Parameters.ContainsKey("RandomType"))
     75        Parameters.Add(new ValueParameter<IRandom>("RandomType", "The type of pseudo random number generator which is created.", new MersenneTwister()));
     76    }
     77    #endregion
    5978
    6079    public override IOperation Apply() {
     
    6584
    6685      if (setSeedRandomly) seed.Value = new System.Random().Next();
    67       RandomParameter.ActualValue = new MersenneTwister((uint)seed.Value);
     86      IRandom random = (IRandom)RandomType.Clone();
     87      random.Reset(seed.Value);
     88      RandomParameter.ActualValue = random;
    6889
    6990      return base.Apply();
  • trunk/sources/HeuristicLab.Random/3.3/UniformRandomizer.cs

    r4068 r4258  
    7070      Parameters.Add(new LookupParameter<DoubleValue>("Value", "The value that should be set to a random value."));
    7171    }
     72    [StorableConstructor]
     73    protected UniformRandomizer(bool deserializing) : base(deserializing) { }
    7274
    7375    /// <summary>
Note: See TracChangeset for help on using the changeset viewer.