[14897] | 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 |
|
---|
[14898] | 19 | public StringVectorConstantsErcValue() : this(false, new StringArray[0]) { }
|
---|
| 20 |
|
---|
[14897] | 21 | public StringVectorConstantsErcValue(params StringArray[] arrays) : this(true, arrays) { }
|
---|
| 22 |
|
---|
| 23 | public StringVectorConstantsErcValue(bool isEnabled, params StringArray[] arrays) {
|
---|
| 24 | this.arrays = arrays;
|
---|
[14898] | 25 | Name = "String vector constants";
|
---|
[14897] | 26 | IsEnabled = isEnabled;
|
---|
[14898] | 27 | Parameters.Add(new ValueParameter<ItemCollection<StringArray>>(ConstantsParameterName, new ItemCollection<StringArray>(arrays)));
|
---|
[14897] | 28 | }
|
---|
| 29 |
|
---|
| 30 | [StorableConstructor]
|
---|
| 31 | private StringVectorConstantsErcValue(bool deserializing) : base(deserializing) { }
|
---|
| 32 |
|
---|
| 33 | public StringVectorConstantsErcValue(StringVectorConstantsErcValue origin, Cloner cloner) : base(origin, cloner) { }
|
---|
| 34 |
|
---|
[14898] | 35 | public IValueParameter<ItemCollection<StringArray>> ConstantsParameter
|
---|
[14897] | 36 | {
|
---|
[14898] | 37 | get { return (IValueParameter<ItemCollection<StringArray>>)Parameters[ConstantsParameterName]; }
|
---|
[14897] | 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 | }
|
---|