#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Operators {
[Item("LocalRandomCreator", "Creates a local pseudo random number generator from a global random number generator.")]
[StorableType("F079CB55-983E-4684-9CB1-1BAF113D1044")]
public sealed class LocalRandomCreator : SingleSuccessorOperator {
#region Parameter Properties
public LookupParameter GlobalRandomParameter {
get { return (LookupParameter)Parameters["GlobalRandom"]; }
}
public LookupParameter LocalRandomParameter {
get { return (LookupParameter)Parameters["LocalRandom"]; }
}
#endregion
[StorableConstructor]
private LocalRandomCreator(bool deserializing) : base(deserializing) { }
private LocalRandomCreator(LocalRandomCreator original, Cloner cloner)
: base(original, cloner) {
}
public LocalRandomCreator()
: base() {
#region Create parameters
Parameters.Add(new LookupParameter("GlobalRandom", "The global random number generator which is used to initialize the local random number generator."));
Parameters.Add(new LookupParameter("LocalRandom", "The local pseudo random number generator."));
#endregion
}
public override IDeepCloneable Clone(Cloner cloner) {
return new LocalRandomCreator(this, cloner);
}
public override IOperation Apply() {
IRandom globalRandom = GlobalRandomParameter.ActualValue;
IRandom localRandom = (IRandom)globalRandom.Clone();
localRandom.Reset(globalRandom.Next());
LocalRandomParameter.ActualValue = localRandom;
return base.Apply();
}
}
}