Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/Integer/IntegerRangeErc.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.Integer {
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 IntegerRangeErc : WeightedErcItem<int> {
10    private const string RangeParameterName = "Range";
11
12    public IntegerRangeErc() : this(true, 0, 0) { }
13
14    public IntegerRangeErc(int start, int end) : this(true, start, end) { }
15
16    public IntegerRangeErc(bool isEnabled, int start, int end, double weight = 1d) : base(isEnabled, weight) {
17      Parameters.Add(new FixedValueParameter<IntRange>(RangeParameterName, new IntRange(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    protected IntegerRangeErc(bool deseralizing) : base(deseralizing) { }
28
29    public IntegerRangeErc(IntegerRangeErc origin, Cloner cloner) : base(origin, cloner) { }
30
31    public IValueParameter<IntRange> RangeParameter
32    {
33      get { return (IValueParameter<IntRange>)Parameters[RangeParameterName]; }
34    }
35
36    public int Start
37    {
38      get { return RangeParameter.Value.Start; }
39      set { RangeParameter.Value.Start = value; }
40    }
41
42    public int End
43    {
44      get { return RangeParameter.Value.End; }
45      set { RangeParameter.Value.End = value; }
46    }
47
48    public override int GetErcValue(IRandom random) {
49
50      return Start < End ? random.Next(Start, End) : 0;
51    }
52
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new IntegerRangeErc(this, cloner);
55    }
56  }
57}
Note: See TracBrowser for help on using the repository browser.