Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/Float/FloatRangeErc.cs @ 15032

Last change on this file since 15032 was 15032, checked in by pkimmesw, 7 years ago

#2665 Fixed bias 0 issue, PushExpressionFrequencyAnalyzer, Fixed probability for ERC settings, Fixed enable/disable instructions, Added expression descriptions

File size: 1.8 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Float {
2  using HeuristicLab.Common;
3  using HeuristicLab.Core;
4  using HeuristicLab.Data;
5  using HeuristicLab.Parameters;
6  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7
8  [StorableClass]
9  public class FloatRangeErc : WeightedErcItem<double> {
10    private const string RangeParameterName = "Range";
11
12    public FloatRangeErc() : this(true, 0d, 0d) { }
13
14    public FloatRangeErc(double start, double end) : this(true, start, end) { }
15
16    public FloatRangeErc(bool isEnabled, double start, double end, double weight = 1d) : base(isEnabled, weight) {
17      Parameters.Add(new FixedValueParameter<DoubleRange>(RangeParameterName, new DoubleRange(start, end)));
18      RangeParameter.Value.ToStringChanged += (sender, args) => UpdateName();
19      UpdateName();
20    }
21
22    private void UpdateName() {
23      Name = RangeParameter.Value.ToString();
24    }
25
26    [StorableConstructor]
27    public FloatRangeErc(bool deseralizing) : base(deseralizing) { }
28
29    public FloatRangeErc(FloatRangeErc origin, Cloner cloner) : base(origin, cloner) { }
30
31    public IValueParameter<DoubleRange> RangeParameter
32    {
33      get { return (IValueParameter<DoubleRange>)Parameters[RangeParameterName]; }
34    }
35
36    public double Start
37    {
38      get { return RangeParameter.Value.Start; }
39      set { RangeParameter.Value.Start = value; }
40    }
41
42    public double End
43    {
44      get { return RangeParameter.Value.End; }
45      set { RangeParameter.Value.End = value; }
46    }
47
48    public override double GetErcValue(IRandom random) {
49      return Start < End && IsEnabled ? random.NextDouble() * (End - Start) + Start : 0d;
50    }
51
52    public override IDeepCloneable Clone(Cloner cloner) {
53      return new FloatRangeErc(this, cloner);
54    }
55  }
56}
Note: See TracBrowser for help on using the repository browser.