Changeset 4258
- Timestamp:
- 08/19/10 05:38:47 (14 years ago)
- 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 1 1 using System; 2 using HeuristicLab.Common; 2 3 using HeuristicLab.Core; 3 4 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 43 44 /// </summary> 44 45 [StorableClass] 45 public class FastRandom : Item, IRandom {46 public sealed class FastRandom : Item, IRandom { 46 47 // The +1 ensures NextDouble doesn't generate 1.0 47 48 private const double REAL_UNIT_INT = 1.0 / ((double)int.MaxValue + 1.0); … … 70 71 Reinitialise(seed); 71 72 } 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) { } 72 80 73 81 #endregion … … 319 327 } 320 328 return (bitBuffer & (bitMask >>= 1)) == 0; 321 } 329 } 322 330 // Buffer 32 bits in bitBuffer, return 1 at a time, keep track of how many have been returned 323 331 // with bitBufferIdx. … … 328 336 329 337 330 #endregion 338 #endregion 331 339 332 340 #region IRandom Members … … 340 348 } 341 349 342 #endregion 343 344 public override Common.IDeepCloneable Clone(Common.Cloner cloner) {350 #endregion 351 352 public override IDeepCloneable Clone(Cloner cloner) { 345 353 FastRandom clone = (FastRandom)base.Clone(cloner); 346 354 clone.x = x; -
trunk/sources/HeuristicLab.Random/3.3/HeuristicLab.Random-3.3.csproj
r4243 r4258 108 108 <ItemGroup> 109 109 <None Include="HeuristicLabRandomPlugin.cs.frame" /> 110 <Compile Include="FastRandomCreator.cs" />111 110 <Compile Include="FastRandom.cs" /> 112 111 <Compile Include="HeuristicLabRandomPlugin.cs" /> -
trunk/sources/HeuristicLab.Random/3.3/MersenneTwister.cs
r3376 r4258 43 43 [Item("MersenneTwister", "A high-quality pseudo random number generator which creates uniformly distributed random numbers.")] 44 44 [StorableClass] 45 public class MersenneTwister : Item, IRandom {45 public sealed class MersenneTwister : Item, IRandom { 46 46 private const int n = 624, m = 397; 47 47 … … 78 78 init = true; 79 79 } 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) { } 80 86 81 87 /// <summary> -
trunk/sources/HeuristicLab.Random/3.3/NormalDistributedRandom.cs
r3997 r4258 34 34 [Item("NormalDistributedRandom", "A pseudo random number generator which uses the Ziggurat method to create normally distributed random numbers.")] 35 35 [StorableClass] 36 public class NormalDistributedRandom : Item, IRandom {36 public sealed class NormalDistributedRandom : Item, IRandom { 37 37 [Storable] 38 38 private double mu; … … 471 471 this.uniform = uniformRandom; 472 472 } 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) { } 473 479 474 480 #region IRandom Members -
trunk/sources/HeuristicLab.Random/3.3/NormalRandomizer.cs
r4068 r4258 67 67 Parameters.Add(new LookupParameter<DoubleValue>("Value", "The value that should be set to a random value.")); 68 68 } 69 [StorableConstructor] 70 protected NormalRandomizer(bool deserializing) : base(deserializing) { } 69 71 70 72 /// <summary> -
trunk/sources/HeuristicLab.Random/3.3/RandomCreator.cs
r4068 r4258 39 39 get { return (ValueLookupParameter<IntValue>)Parameters["Seed"]; } 40 40 } 41 public ValueParameter<IRandom> RandomTypeParameter { 42 get { return (ValueParameter<IRandom>)Parameters["RandomType"]; } 43 } 41 44 public LookupParameter<IRandom> RandomParameter { 42 45 get { return (LookupParameter<IRandom>)Parameters["Random"]; } … … 50 53 set { SeedParameter.Value = value; } 51 54 } 55 public IRandom RandomType { 56 get { return RandomTypeParameter.Value; } 57 set { RandomTypeParameter.Value = value; } 58 } 52 59 53 60 public RandomCreator() … … 55 62 Parameters.Add(new ValueLookupParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 56 63 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())); 57 65 Parameters.Add(new LookupParameter<IRandom>("Random", "The new pseudo random number generator which is initialized with the given seed.")); 58 66 } 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 59 78 60 79 public override IOperation Apply() { … … 65 84 66 85 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; 68 89 69 90 return base.Apply(); -
trunk/sources/HeuristicLab.Random/3.3/UniformRandomizer.cs
r4068 r4258 70 70 Parameters.Add(new LookupParameter<DoubleValue>("Value", "The value that should be set to a random value.")); 71 71 } 72 [StorableConstructor] 73 protected UniformRandomizer(bool deserializing) : base(deserializing) { } 72 74 73 75 /// <summary>
Note: See TracChangeset
for help on using the changeset viewer.