Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/ConstantsErcValue.cs @ 14905

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

#2665 Made ErcOptions checkable

File size: 1.5 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc {
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 abstract class ConstantsWeightedErcValue<T, TArray> : WeightedErcValueItem<T>
10    where T : struct
11    where TArray : ValueTypeArray<T>, new() {
12
13    private const string ConstantsParameterName = "Constants";
14
15    protected ConstantsWeightedErcValue(TArray array) : this(true, array) { }
16    protected ConstantsWeightedErcValue(bool isEnabled, TArray array, double weight = 1d) : base(isEnabled, weight) {
17      Parameters.Add(new FixedValueParameter<TArray>(ConstantsParameterName, array));
18    }
19
20    [StorableConstructor]
21    protected ConstantsWeightedErcValue(bool deserializing) : base(deserializing) { }
22
23    protected ConstantsWeightedErcValue(ConstantsWeightedErcValue<T, TArray> origin, Cloner cloner) : base(origin, cloner) { }
24
25    public IValueParameter<TArray> ConstantsParameter
26    {
27      get { return (IValueParameter<TArray>)Parameters[ConstantsParameterName]; }
28    }
29
30    public TArray Constants
31    {
32      get { return ConstantsParameter.Value; }
33    }
34
35    public override T GetErcValue(IRandom random) {
36      if (Constants.Length == 0) return default(T);
37
38      var x = random.Next(Constants.Length);
39      return Constants[x];
40    }
41  }
42}
Note: See TracBrowser for help on using the repository browser.