Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/VectorConstantsErc.cs @ 14952

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

#2665 Added IsNoop to Expression, Made Expressions storable, Fixed Debugger, Fixed and improved problem data and result visualisation, Added custom ErcOption view, Added problem difficulty to problem data name

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 VectorConstantsErc<T, TValue> : WeightedErcItem<IReadOnlyList<T>>
13    where T : struct
14    where TValue : ValueTypeArray<T> {
15    private const string ConstantsParameterName = "Constants";
16
17    protected VectorConstantsErc(params TValue[] arrays) : this(true, 1d, arrays) { }
18
19    protected VectorConstantsErc(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 VectorConstantsErc(bool deserializing) : base(deserializing) { }
26
27    protected VectorConstantsErc(VectorConstantsErc<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.