namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Float { using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; [StorableClass] public class FloatRangeErc : WeightedErcItem { private const string RangeParameterName = "Range"; public FloatRangeErc() : this(true, 0d, 0d) { } public FloatRangeErc(double start, double end) : this(true, start, end) { } public FloatRangeErc(bool isEnabled, double start, double end, double weight = 1d) : base(isEnabled, weight) { Parameters.Add(new FixedValueParameter(RangeParameterName, new DoubleRange(start, end))); RangeParameter.Value.ToStringChanged += (sender, args) => UpdateName(); UpdateName(); } private void UpdateName() { Name = RangeParameter.Value.ToString(); } [StorableConstructor] public FloatRangeErc(bool deseralizing) : base(deseralizing) { } public FloatRangeErc(FloatRangeErc origin, Cloner cloner) : base(origin, cloner) { } public IValueParameter RangeParameter { get { return (IValueParameter)Parameters[RangeParameterName]; } } public double Start { get { return RangeParameter.Value.Start; } set { RangeParameter.Value.Start = value; } } public double End { get { return RangeParameter.Value.End; } set { RangeParameter.Value.End = value; } } public override double GetErcValue(IRandom random) { return Start < End && IsEnabled ? random.NextDouble() * (End - Start) + Start : 0d; } public override IDeepCloneable Clone(Cloner cloner) { return new FloatRangeErc(this, cloner); } } }