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.5 KB
|
Line | |
---|
1 | namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc.String {
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | using HeuristicLab.Common;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using HeuristicLab.Parameters;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 |
|
---|
10 | [StorableClass]
|
---|
11 | public class StringConstantErcValue : WeightedErcValueItem<string> {
|
---|
12 |
|
---|
13 | private const string ConstantsParameterName = "Constants";
|
---|
14 | private readonly StringArray array; // perf opt: reduce parameter getter usage
|
---|
15 |
|
---|
16 | public StringConstantErcValue() : this(new string[0]) { }
|
---|
17 |
|
---|
18 | public StringConstantErcValue(params string[] constants) {
|
---|
19 | array = new StringArray(constants);
|
---|
20 | Parameters.Add(new FixedValueParameter<StringArray>(ConstantsParameterName, array));
|
---|
21 | }
|
---|
22 |
|
---|
23 | [StorableConstructor]
|
---|
24 | public StringConstantErcValue(bool deserializing) : base(deserializing) {
|
---|
25 | }
|
---|
26 |
|
---|
27 | public StringConstantErcValue(StringConstantErcValue origin, Cloner cloner) : base(origin, cloner) {
|
---|
28 | }
|
---|
29 |
|
---|
30 | public IValueParameter<StringArray> ConstantsParameter
|
---|
31 | {
|
---|
32 | get { return (IValueParameter<StringArray>)Parameters[ConstantsParameterName]; }
|
---|
33 | }
|
---|
34 |
|
---|
35 | public IEnumerable<string> Constants
|
---|
36 | {
|
---|
37 | get { return ConstantsParameter.Value; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
41 | return new StringConstantErcValue(this, cloner);
|
---|
42 | }
|
---|
43 |
|
---|
44 | public override string GetErcValue(IRandom random) {
|
---|
45 | var x = random.Next(array.Length);
|
---|
46 | return array[x];
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.