Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 Made ErcOptions checkable

File size: 1.6 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc {
2  using System.Collections.Generic;
3  using System.Linq;
4  using Common;
5  using Core;
6  using Data;
7  using Parameters;
8  using Persistence.Default.CompositeSerializers.Storable;
9  using Random;
10
11  [StorableClass]
12  public abstract class VectorConstantsErcValue<T, TValue> : WeightedErcValueItem<IReadOnlyList<T>>
13    where T : struct
14    where TValue : ValueTypeArray<T> {
15    private const string ConstantsParameterName = "Constants";
16
17    protected VectorConstantsErcValue(params TValue[] arrays) : this(true, 1d, arrays) { }
18
19    protected VectorConstantsErcValue(bool isEnabled, double weight = 1d, params TValue[] arrays) : base(isEnabled, weight) {
20      IsEnabled = isEnabled;
21      Parameters.Add(new ValueParameter<ItemCollection<TValue>>(ConstantsParameterName, new ItemCollection<TValue>(arrays)));
22    }
23
24    [StorableConstructor]
25    private VectorConstantsErcValue(bool deserializing) : base(deserializing) { }
26
27    protected VectorConstantsErcValue(VectorConstantsErcValue<T, TValue> origin, Cloner cloner) : base(origin, cloner) { }
28
29    public IValueParameter<ItemCollection<TValue>> ConstantsParameter
30    {
31      get { return (IValueParameter<ItemCollection<TValue>>)Parameters[ConstantsParameterName]; }
32    }
33
34    public IEnumerable<TValue> Constants
35    {
36      get { return ConstantsParameter.Value; }
37    }
38
39    public override IReadOnlyList<T> GetErcValue(IRandom random) {
40      // TODO: remove ToList when ValueTypeArray implements IReadOnlyList
41      return Constants.SampleRandom(random).ToArray();
42    }
43  }
44}
Note: See TracBrowser for help on using the repository browser.