Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push.Base/Erc/VectorConstantsErc.cs @ 16724

Last change on this file since 16724 was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

File size: 1.6 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis {
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.