1 | namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc {
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 |
|
---|
5 | using HeuristicLab.Common;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 | using HeuristicLab.Data;
|
---|
8 | using HeuristicLab.Parameters;
|
---|
9 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
10 | using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Interfaces;
|
---|
11 |
|
---|
12 | [StorableClass]
|
---|
13 | public class StringErcOptions : ErcOption, IReadOnlyStringErcOptions {
|
---|
14 | public const int DefaultStringLength = 10;
|
---|
15 |
|
---|
16 | private const string AllowLowercaseLettersParameterName = "Allow lowercase letters";
|
---|
17 | private const string AllowUppercaseLettersParameterName = "Allow uppercase letters";
|
---|
18 | private const string AllowSpaceParameterName = "Allow space";
|
---|
19 | private const string SpaceProbabilityParameterName = "Space probability";
|
---|
20 | private const string StringLengthParameterName = "String length";
|
---|
21 | private const string ConstantsParameterName = "Constants";
|
---|
22 | private const string AllowDigitsParameterName = "Allow digits";
|
---|
23 | private const string AllowSymbolsParameterName = "Allow symbols";
|
---|
24 | private const string VowelProbabilityParameterName = "Vowel probability";
|
---|
25 |
|
---|
26 | public StringErcOptions() : this(new string[0]) {
|
---|
27 | IsEnabled = false;
|
---|
28 | }
|
---|
29 |
|
---|
30 | public StringErcOptions(string[] constants) {
|
---|
31 | IsEnabled = true;
|
---|
32 | Parameters.Add(new ValueParameter<StringArray>(ConstantsParameterName, new StringArray(constants)));
|
---|
33 | Parameters.Add(new FixedValueParameter<BoolValue>(AllowLowercaseLettersParameterName, new BoolValue(true)));
|
---|
34 | Parameters.Add(new FixedValueParameter<BoolValue>(AllowUppercaseLettersParameterName, new BoolValue(true)));
|
---|
35 | Parameters.Add(new FixedValueParameter<BoolValue>(AllowDigitsParameterName, new BoolValue(true)));
|
---|
36 | Parameters.Add(new FixedValueParameter<BoolValue>(AllowSymbolsParameterName, new BoolValue(true)));
|
---|
37 | Parameters.Add(new FixedValueParameter<BoolValue>(AllowSpaceParameterName, new BoolValue(false)));
|
---|
38 | Parameters.Add(new FixedValueParameter<IntValue>(StringLengthParameterName, new IntValue(DefaultStringLength)));
|
---|
39 | Parameters.Add(new FixedValueParameter<PercentValue>(SpaceProbabilityParameterName));
|
---|
40 | Parameters.Add(new FixedValueParameter<PercentValue>(VowelProbabilityParameterName));
|
---|
41 | }
|
---|
42 |
|
---|
43 | [StorableConstructor]
|
---|
44 | public StringErcOptions(bool deserializing) : base(deserializing) { }
|
---|
45 |
|
---|
46 | public StringErcOptions(StringErcOptions origin, Cloner cloner) : base(origin, cloner) { }
|
---|
47 |
|
---|
48 | public IValueParameter<BoolValue> AllowLowercaseLettersParameter
|
---|
49 | {
|
---|
50 | get { return (IValueParameter<BoolValue>)Parameters[AllowLowercaseLettersParameterName]; }
|
---|
51 | }
|
---|
52 |
|
---|
53 | public bool AllowLowercaseLetters
|
---|
54 | {
|
---|
55 | get { return AllowLowercaseLettersParameter.Value.Value; }
|
---|
56 | set { AllowLowercaseLettersParameter.Value.Value = value; }
|
---|
57 | }
|
---|
58 |
|
---|
59 | public IValueParameter<BoolValue> AllowUppercaseLettersParameter
|
---|
60 | {
|
---|
61 | get { return (IValueParameter<BoolValue>)Parameters[AllowUppercaseLettersParameterName]; }
|
---|
62 | }
|
---|
63 |
|
---|
64 | public bool AllowUppercaseLetters
|
---|
65 | {
|
---|
66 | get { return AllowUppercaseLettersParameter.Value.Value; }
|
---|
67 | set { AllowUppercaseLettersParameter.Value.Value = value; }
|
---|
68 | }
|
---|
69 |
|
---|
70 | public IValueParameter<BoolValue> AllowDigitsParameter
|
---|
71 | {
|
---|
72 | get { return (IValueParameter<BoolValue>)Parameters[AllowDigitsParameterName]; }
|
---|
73 | }
|
---|
74 |
|
---|
75 | public bool AllowDigits
|
---|
76 | {
|
---|
77 | get { return AllowDigitsParameter.Value.Value; }
|
---|
78 | set { AllowDigitsParameter.Value.Value = value; }
|
---|
79 | }
|
---|
80 |
|
---|
81 | public IValueParameter<BoolValue> AllowSymbolsParameter
|
---|
82 | {
|
---|
83 | get { return (IValueParameter<BoolValue>)Parameters[AllowSymbolsParameterName]; }
|
---|
84 | }
|
---|
85 |
|
---|
86 | public bool AllowSymbols
|
---|
87 | {
|
---|
88 | get { return AllowSymbolsParameter.Value.Value; }
|
---|
89 | set { AllowSymbolsParameter.Value.Value = value; }
|
---|
90 | }
|
---|
91 |
|
---|
92 | public IValueParameter<BoolValue> AllowSpaceParameter
|
---|
93 | {
|
---|
94 | get { return (IValueParameter<BoolValue>)Parameters[AllowSpaceParameterName]; }
|
---|
95 | }
|
---|
96 |
|
---|
97 | public bool AllowSpace
|
---|
98 | {
|
---|
99 | get { return AllowSpaceParameter.Value.Value; }
|
---|
100 | set { AllowSpaceParameter.Value.Value = value; }
|
---|
101 | }
|
---|
102 |
|
---|
103 | public IValueParameter<PercentValue> SpaceProbabilityParameter
|
---|
104 | {
|
---|
105 | get { return (IValueParameter<PercentValue>)Parameters[SpaceProbabilityParameterName]; }
|
---|
106 | }
|
---|
107 |
|
---|
108 | public double SpaceProbability
|
---|
109 | {
|
---|
110 | get { return SpaceProbabilityParameter.Value.Value; }
|
---|
111 | set { SpaceProbabilityParameter.Value.Value = value; }
|
---|
112 | }
|
---|
113 |
|
---|
114 | public IValueParameter<PercentValue> VowelProbabilityParameter
|
---|
115 | {
|
---|
116 | get { return (IValueParameter<PercentValue>)Parameters[VowelProbabilityParameterName]; }
|
---|
117 | }
|
---|
118 |
|
---|
119 | public double VowelProbability
|
---|
120 | {
|
---|
121 | get { return VowelProbabilityParameter.Value.Value; }
|
---|
122 | set { VowelProbabilityParameter.Value.Value = value; }
|
---|
123 | }
|
---|
124 |
|
---|
125 | public IValueParameter<IntValue> StringLengthParameter
|
---|
126 | {
|
---|
127 | get { return (IValueParameter<IntValue>)Parameters[StringLengthParameterName]; }
|
---|
128 | }
|
---|
129 |
|
---|
130 | public int StringLength
|
---|
131 | {
|
---|
132 | get { return StringLengthParameter.Value.Value; }
|
---|
133 | set { StringLengthParameter.Value.Value = value; }
|
---|
134 | }
|
---|
135 |
|
---|
136 | public IValueParameter<StringArray> ConstantsParameter
|
---|
137 | {
|
---|
138 | get { return (IValueParameter<StringArray>)Parameters[ConstantsParameterName]; }
|
---|
139 | }
|
---|
140 |
|
---|
141 | public string[] Constants
|
---|
142 | {
|
---|
143 | get { return ConstantsParameter.Value.ToArray(); }
|
---|
144 | set { ConstantsParameter.Value = new StringArray(value); }
|
---|
145 | }
|
---|
146 |
|
---|
147 | IReadOnlyList<string> IReadOnlyErcOptionConstants<string>.Constants
|
---|
148 | {
|
---|
149 | get { return Constants; }
|
---|
150 | }
|
---|
151 |
|
---|
152 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
153 | return new StringErcOptions(this, cloner);
|
---|
154 | }
|
---|
155 | }
|
---|
156 | }
|
---|