Last change
on this file since 14897 was
14897,
checked in by pkimmesw, 7 years ago
|
#2665 Dynamic ErcValues, Separate Push from BenchmarkSuite Push
|
File size:
1.6 KB
|
Line | |
---|
1 | namespace 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 | private readonly TValue[] arrays; // perf opt: avoid using parameter getter
|
---|
18 |
|
---|
19 | protected VectorConstantsErcValue(params TValue[] arrays) : this(true, arrays) { }
|
---|
20 |
|
---|
21 | protected VectorConstantsErcValue(bool isEnabled, params TValue[] arrays) {
|
---|
22 | this.arrays = arrays;
|
---|
23 | IsEnabled = isEnabled;
|
---|
24 | Parameters.Add(new ValueParameter<ItemArray<TValue>>(ConstantsParameterName, new ItemArray<TValue>(arrays)));
|
---|
25 | }
|
---|
26 |
|
---|
27 | [StorableConstructor]
|
---|
28 | private VectorConstantsErcValue(bool deserializing) : base(deserializing) { }
|
---|
29 |
|
---|
30 | protected VectorConstantsErcValue(VectorConstantsErcValue<T, TValue> origin, Cloner cloner) : base(origin, cloner) { }
|
---|
31 |
|
---|
32 | public IValueParameter<ItemArray<TValue>> ConstantsParameter
|
---|
33 | {
|
---|
34 | get { return (IValueParameter<ItemArray<TValue>>)Parameters[ConstantsParameterName]; }
|
---|
35 | }
|
---|
36 |
|
---|
37 | public IEnumerable<TValue> Constants
|
---|
38 | {
|
---|
39 | get { return ConstantsParameter.Value; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public override IReadOnlyList<T> GetErcValue(IRandom random) {
|
---|
43 | // TODO: remove ToList when ValueTypeArray implements IReadOnlyList
|
---|
44 | return arrays.SampleRandom(random).ToList();
|
---|
45 | }
|
---|
46 | }
|
---|
47 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.