1 | using System.Linq;
|
---|
2 |
|
---|
3 | namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc.StringVector {
|
---|
4 | using System.Collections.Generic;
|
---|
5 |
|
---|
6 | using HeuristicLab.Common;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.Data;
|
---|
9 | using HeuristicLab.Parameters;
|
---|
10 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
11 | using HeuristicLab.Random;
|
---|
12 |
|
---|
13 | [StorableClass]
|
---|
14 | public class StringVectorConstantsErcValue : WeightedErcValueItem<IReadOnlyList<string>> {
|
---|
15 | private const string ConstantsParameterName = "Constants";
|
---|
16 |
|
---|
17 | private readonly StringArray[] arrays; // perf opt: avoid using parameter getter
|
---|
18 |
|
---|
19 | public StringVectorConstantsErcValue() : this(false, new StringArray[0]) { }
|
---|
20 |
|
---|
21 | public StringVectorConstantsErcValue(params StringArray[] arrays) : this(true, arrays) { }
|
---|
22 |
|
---|
23 | public StringVectorConstantsErcValue(bool isEnabled, params StringArray[] arrays) {
|
---|
24 | this.arrays = arrays;
|
---|
25 | Name = "String vector constants";
|
---|
26 | IsEnabled = isEnabled;
|
---|
27 | Parameters.Add(new ValueParameter<ItemCollection<StringArray>>(ConstantsParameterName, new ItemCollection<StringArray>(arrays)));
|
---|
28 | }
|
---|
29 |
|
---|
30 | [StorableConstructor]
|
---|
31 | private StringVectorConstantsErcValue(bool deserializing) : base(deserializing) { }
|
---|
32 |
|
---|
33 | public StringVectorConstantsErcValue(StringVectorConstantsErcValue origin, Cloner cloner) : base(origin, cloner) { }
|
---|
34 |
|
---|
35 | public IValueParameter<ItemCollection<StringArray>> ConstantsParameter
|
---|
36 | {
|
---|
37 | get { return (IValueParameter<ItemCollection<StringArray>>)Parameters[ConstantsParameterName]; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public IEnumerable<StringArray> Constants
|
---|
41 | {
|
---|
42 | get { return ConstantsParameter.Value; }
|
---|
43 | }
|
---|
44 |
|
---|
45 | public override IReadOnlyList<string> GetErcValue(IRandom random) {
|
---|
46 | // TODO: remove ToList when ValueTypeArray implements IReadOnlyList
|
---|
47 | return arrays.SampleRandom(random).ToList();
|
---|
48 | }
|
---|
49 |
|
---|
50 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
51 | return new StringVectorConstantsErcValue(this, cloner);
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|