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 StringVectorConstantsErc : WeightedErcItem<IReadOnlyList<string>> {
|
---|
15 | private const string ConstantsParameterName = "Constants";
|
---|
16 |
|
---|
17 | public StringVectorConstantsErc() : this(true, 1d) { }
|
---|
18 | public StringVectorConstantsErc(params string[][] arrays) : this(true, 1d, arrays.Select(x => new StringArray(x)).ToArray()) { }
|
---|
19 | public StringVectorConstantsErc(params StringArray[] arrays) : this(true, 1d, arrays) { }
|
---|
20 |
|
---|
21 | public StringVectorConstantsErc(bool isEnabled, double weight = 1d, params StringArray[] arrays) : base(isEnabled, weight) {
|
---|
22 | Name = "String vector constants";
|
---|
23 | IsEnabled = isEnabled;
|
---|
24 | Parameters.Add(new ValueParameter<ItemCollection<StringArray>>(ConstantsParameterName, new ItemCollection<StringArray>(arrays)));
|
---|
25 | }
|
---|
26 |
|
---|
27 | [StorableConstructor]
|
---|
28 | protected StringVectorConstantsErc(bool deserializing) : base(deserializing) { }
|
---|
29 |
|
---|
30 | public StringVectorConstantsErc(StringVectorConstantsErc origin, Cloner cloner) : base(origin, cloner) { }
|
---|
31 |
|
---|
32 | public IValueParameter<ItemCollection<StringArray>> ConstantsParameter
|
---|
33 | {
|
---|
34 | get { return (IValueParameter<ItemCollection<StringArray>>)Parameters[ConstantsParameterName]; }
|
---|
35 | }
|
---|
36 |
|
---|
37 | public IEnumerable<StringArray> Constants
|
---|
38 | {
|
---|
39 | get { return ConstantsParameter.Value; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public override IReadOnlyList<string> GetErcValue(IRandom random) {
|
---|
43 | // TODO: remove ToArray when ValueTypeArray implements IReadOnlyList
|
---|
44 | return Constants.SampleRandom(random).ToArray();
|
---|
45 | }
|
---|
46 |
|
---|
47 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
48 | return new StringVectorConstantsErc(this, cloner);
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|