1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Configuration {
|
---|
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 | using HeuristicLab.Problems.ProgramSynthesis.Base.Erc;
|
---|
10 |
|
---|
11 | [StorableClass]
|
---|
12 | public class PushConfigurationParameterCollection : PushConfigurationBase, IReadOnlyPushConfiguration {
|
---|
13 | private const string INSTRUCTIONS_PARAMETER_NAME = "Instructions";
|
---|
14 | private const string INSTRUCTIONS_PARAMETER_DESCRIPTION = "Enables/Disables Instructions";
|
---|
15 | private const string EVAL_PUSH_LIMIT_PARAMETER_NAME = "EvalPushLimit";
|
---|
16 | private const string EVAL_PUSH_LIMIT_PARAMETER_DESCRIPTION = "This is the maximum allowed number of \"executions\" in a single top-level call to the interpreter. The execution of a single Push instruction counts as one execution, as does the processing of a single literal, as does the descent into one layer of parentheses (that is, the processing of the \"(\" counts as one execution).";
|
---|
17 | private const string MAX_POINTS_IN_PROGRAM_PARAMETER_NAME = "MaxProgramLength";
|
---|
18 | private const string MAX_PROGRAM_LENGTH_PARAMETER_DESCRIPTION = "This is the maximum size of an item on the CODE/EXEC stack, expressed as a number of points. A point is an instruction, a literal, or a pair of parentheses.";
|
---|
19 | private const string TOP_LEVEL_PUSH_CODE_PARAMETER_NAME = "TopLevelPushCode";
|
---|
20 | private const string TOP_LEVEL_PUSH_CODE_PARAMETER_DESCRIPTION = "When TRUE (which is the default), code passed to the top level of the interpreter will be pushed onto the CODE stack prior to execution.";
|
---|
21 | private const string TOP_LEVEL_POP_CODE_PARAMETER_NAME = "TopLevelPopCode";
|
---|
22 | private const string TOP_LEVEL_POP_CODE_PARAMETER_DESCRIPTION = "When TRUE, the CODE stack will be popped at the end of top level calls to the interpreter. The default is FALSE.";
|
---|
23 | private const string MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME = "MaxPointsInRandomInstruction";
|
---|
24 | private const string MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_DESCRIPTION = "MaxPointsInRandomInstruction";
|
---|
25 | private const string ERC_OPTIONS_PARAMETER_NAME = "ERC options";
|
---|
26 | private const string MAX_STRING_LENGTH_PARAMETER_NAME = "Max. string length";
|
---|
27 | private const string MAX_DEPTH_PARAMETER_NAME = "Max. program recursion";
|
---|
28 | private const string MAX_PARENTHESES_CLOSE_PARAMETER_NAME = "Max. parentheses close";
|
---|
29 | private const string MAX_PARENTHESES_CLOSE_PARAMETER_DESCRIPTION = "Specifies how many sub programs are closed if open during the recursive translation of an individual to a push program. Value is exclusive.";
|
---|
30 | private const string PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_NAME = "Parentheses close bias level";
|
---|
31 | private const string PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_DESCRIPTION = "Specifies how strong a random value between 0 .. 'Max. parentheses close' is biased towards 0. In other words, this parameter controls the length of sub programs.";
|
---|
32 | private const string MAX_VECTOR_LENGTH_PARAMETER_NAME = "Max. vector length";
|
---|
33 |
|
---|
34 | public PushConfigurationParameterCollection() {
|
---|
35 | Parameters = new ParameterCollection();
|
---|
36 |
|
---|
37 | InitParameters();
|
---|
38 | }
|
---|
39 |
|
---|
40 | public PushConfigurationParameterCollection(PushConfigurationParameterCollection origin, Cloner cloner) : base(origin, cloner) {
|
---|
41 | Parameters = cloner.Clone(origin.Parameters);
|
---|
42 | }
|
---|
43 |
|
---|
44 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
45 | return new PushConfigurationParameterCollection(this, cloner);
|
---|
46 | }
|
---|
47 |
|
---|
48 | [StorableConstructor]
|
---|
49 | protected PushConfigurationParameterCollection(bool deserialize) { }
|
---|
50 |
|
---|
51 | [StorableHook(HookType.AfterDeserialization)]
|
---|
52 | // ReSharper disable once UnusedMember.Local
|
---|
53 | private void AfterDeserialization() {
|
---|
54 | InitParameters();
|
---|
55 | }
|
---|
56 |
|
---|
57 | [Storable]
|
---|
58 | public ParameterCollection Parameters { get; private set; }
|
---|
59 |
|
---|
60 | [Storable]
|
---|
61 | public string FloatStringFormat { get; set; }
|
---|
62 |
|
---|
63 | private void InitParameters() {
|
---|
64 | if (!Parameters.ContainsKey(INSTRUCTIONS_PARAMETER_NAME))
|
---|
65 | Parameters.Add(new ValueParameter<IExpressionsConfiguration>(
|
---|
66 | INSTRUCTIONS_PARAMETER_NAME,
|
---|
67 | INSTRUCTIONS_PARAMETER_DESCRIPTION,
|
---|
68 | this));
|
---|
69 |
|
---|
70 | if (!Parameters.ContainsKey(ERC_OPTIONS_PARAMETER_NAME))
|
---|
71 | Parameters.Add(new ValueParameter<ErcOptions>(ERC_OPTIONS_PARAMETER_NAME));
|
---|
72 |
|
---|
73 | if (!Parameters.ContainsKey(MAX_VECTOR_LENGTH_PARAMETER_NAME))
|
---|
74 | Parameters.Add(new FixedValueParameter<IntValue>(
|
---|
75 | MAX_VECTOR_LENGTH_PARAMETER_NAME,
|
---|
76 | new IntValue(500)) { Hidden = true });
|
---|
77 |
|
---|
78 | if (!Parameters.ContainsKey(EVAL_PUSH_LIMIT_PARAMETER_NAME))
|
---|
79 | Parameters.Add(new FixedValueParameter<IntValue>(
|
---|
80 | EVAL_PUSH_LIMIT_PARAMETER_NAME,
|
---|
81 | EVAL_PUSH_LIMIT_PARAMETER_DESCRIPTION,
|
---|
82 | new IntValue(1000)));
|
---|
83 |
|
---|
84 | if (!Parameters.ContainsKey(MAX_POINTS_IN_PROGRAM_PARAMETER_NAME))
|
---|
85 | Parameters.Add(new FixedValueParameter<IntValue>(
|
---|
86 | MAX_POINTS_IN_PROGRAM_PARAMETER_NAME,
|
---|
87 | MAX_PROGRAM_LENGTH_PARAMETER_DESCRIPTION,
|
---|
88 | new IntValue(200)));
|
---|
89 |
|
---|
90 | if (!Parameters.ContainsKey(MAX_PARENTHESES_CLOSE_PARAMETER_NAME))
|
---|
91 | Parameters.Add(new FixedValueParameter<IntValue>(
|
---|
92 | MAX_PARENTHESES_CLOSE_PARAMETER_NAME,
|
---|
93 | MAX_PARENTHESES_CLOSE_PARAMETER_DESCRIPTION,
|
---|
94 | new IntValue(4)) { Hidden = true });
|
---|
95 |
|
---|
96 | if (!Parameters.ContainsKey(PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_NAME))
|
---|
97 | Parameters.Add(new FixedValueParameter<DoubleValue>(
|
---|
98 | PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_NAME,
|
---|
99 | PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_DESCRIPTION,
|
---|
100 | new DoubleValue(4)) { Hidden = true });
|
---|
101 |
|
---|
102 | if (!Parameters.ContainsKey(TOP_LEVEL_PUSH_CODE_PARAMETER_NAME))
|
---|
103 | Parameters.Add(new FixedValueParameter<BoolValue>(
|
---|
104 | TOP_LEVEL_PUSH_CODE_PARAMETER_NAME,
|
---|
105 | TOP_LEVEL_PUSH_CODE_PARAMETER_DESCRIPTION,
|
---|
106 | new BoolValue(true)) { Hidden = true });
|
---|
107 |
|
---|
108 | if (!Parameters.ContainsKey(TOP_LEVEL_POP_CODE_PARAMETER_NAME))
|
---|
109 | Parameters.Add(new FixedValueParameter<BoolValue>(
|
---|
110 | TOP_LEVEL_POP_CODE_PARAMETER_NAME,
|
---|
111 | TOP_LEVEL_POP_CODE_PARAMETER_DESCRIPTION,
|
---|
112 | new BoolValue(false)) { Hidden = true });
|
---|
113 |
|
---|
114 | if (!Parameters.ContainsKey(MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME))
|
---|
115 | Parameters.Add(new FixedValueParameter<IntValue>(
|
---|
116 | MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME,
|
---|
117 | MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_DESCRIPTION,
|
---|
118 | new IntValue(50)) { Hidden = true });
|
---|
119 |
|
---|
120 | if (!Parameters.ContainsKey(MAX_STRING_LENGTH_PARAMETER_NAME))
|
---|
121 | Parameters.Add(new FixedValueParameter<IntValue>(
|
---|
122 | MAX_STRING_LENGTH_PARAMETER_NAME,
|
---|
123 | new IntValue(1000)) { Hidden = true });
|
---|
124 |
|
---|
125 | if (!Parameters.ContainsKey(MAX_DEPTH_PARAMETER_NAME))
|
---|
126 | Parameters.Add(new FixedValueParameter<IntValue>(
|
---|
127 | MAX_DEPTH_PARAMETER_NAME,
|
---|
128 | new IntValue(1000)) { Hidden = true });
|
---|
129 | }
|
---|
130 |
|
---|
131 | public IValueParameter<IExpressionsConfiguration> InstructionsParameter
|
---|
132 | {
|
---|
133 | get { return (IValueParameter<IExpressionsConfiguration>)Parameters[INSTRUCTIONS_PARAMETER_NAME]; }
|
---|
134 | }
|
---|
135 |
|
---|
136 | public IExpressionsConfiguration Instructions
|
---|
137 | {
|
---|
138 | get { return InstructionsParameter.Value; }
|
---|
139 | set { InstructionsParameter.Value = value; }
|
---|
140 | }
|
---|
141 |
|
---|
142 | public IValueParameter<ErcOptions> ErcOptionsParameter
|
---|
143 | {
|
---|
144 | get { return (IValueParameter<ErcOptions>)Parameters[ERC_OPTIONS_PARAMETER_NAME]; }
|
---|
145 | }
|
---|
146 |
|
---|
147 | public ErcOptions ErcOptions
|
---|
148 | {
|
---|
149 | get { return ErcOptionsParameter.Value; }
|
---|
150 | set
|
---|
151 | {
|
---|
152 | ErcOptionsParameter.Value = value;
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | IReadOnlyList<string> IReadOnlyPushConfiguration.EnabledExpressions
|
---|
157 | {
|
---|
158 | get
|
---|
159 | {
|
---|
160 | return enabledExpressions;
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | IReadOnlyErcOptions IReadOnlyPushConfiguration.ErcOptions
|
---|
165 | {
|
---|
166 | get
|
---|
167 | {
|
---|
168 | return ErcOptions;
|
---|
169 | }
|
---|
170 | }
|
---|
171 |
|
---|
172 | /// <summary>
|
---|
173 | /// This is the maximum allowed number of "executions" in a single top-level call to the interpreter.
|
---|
174 | /// The execution of a single Push instruction counts as one execution, as does the processing of a single literal,
|
---|
175 | /// as does the descent into one layer of parentheses (that is, the processing of the "(" counts as one execution).
|
---|
176 | /// When this limit is exceeded the interpreter aborts immediately, leaving its stacks in the states they were in prior
|
---|
177 | /// to the abort (so they may still be examined by a calling program). Whether or not this counts as an "abnormal"
|
---|
178 | /// termination
|
---|
179 | /// is up to the calling program.
|
---|
180 | /// </summary>
|
---|
181 | public IValueParameter<IntValue> EvalPushLimitParameter
|
---|
182 | {
|
---|
183 | get { return (IValueParameter<IntValue>)Parameters[EVAL_PUSH_LIMIT_PARAMETER_NAME]; }
|
---|
184 | }
|
---|
185 |
|
---|
186 | public int EvalPushLimit
|
---|
187 | {
|
---|
188 | get { return EvalPushLimitParameter.Value.Value; }
|
---|
189 | set { EvalPushLimitParameter.Value.Value = value; }
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | /// <summary>
|
---|
194 | /// Determines the likelyhood of smaller or bigger values.
|
---|
195 | /// x greater than 1 means that result is biased towards min.
|
---|
196 | /// x smaller than 1 means that result is biased towards max.
|
---|
197 | /// </summary>
|
---|
198 | public IValueParameter<DoubleValue> ParenthesesCloseBiasLevelParameter
|
---|
199 | {
|
---|
200 | get { return (IValueParameter<DoubleValue>)Parameters[PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_NAME]; }
|
---|
201 | }
|
---|
202 |
|
---|
203 | public double ParenthesesCloseBiasLevel
|
---|
204 | {
|
---|
205 | get { return ParenthesesCloseBiasLevelParameter.Value.Value; }
|
---|
206 | set { ParenthesesCloseBiasLevelParameter.Value.Value = value; }
|
---|
207 | }
|
---|
208 |
|
---|
209 | /// <summary>
|
---|
210 | /// Determines the maximum of blocks which will be closed.
|
---|
211 | /// </summary>
|
---|
212 | public IValueParameter<IntValue> MaxParenthesesCloseParameter
|
---|
213 | {
|
---|
214 | get { return (IValueParameter<IntValue>)Parameters[MAX_PARENTHESES_CLOSE_PARAMETER_NAME]; }
|
---|
215 | }
|
---|
216 |
|
---|
217 | public int MaxParenthesesClose
|
---|
218 | {
|
---|
219 | get { return MaxParenthesesCloseParameter.Value.Value; }
|
---|
220 | set
|
---|
221 | {
|
---|
222 | MaxParenthesesCloseParameter.Value.Value = value;
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 | /// <summary>
|
---|
227 | /// This is the maximum of depth a push program can have. Expressions, which lead to exceed this limit are interpreted as NOOP.
|
---|
228 | /// </summary>
|
---|
229 | public IValueParameter<IntValue> MaxDepthParameter
|
---|
230 | {
|
---|
231 | get { return (IValueParameter<IntValue>)Parameters[MAX_DEPTH_PARAMETER_NAME]; }
|
---|
232 | }
|
---|
233 |
|
---|
234 | public int MaxDepth
|
---|
235 | {
|
---|
236 | get { return MaxDepthParameter.Value.Value; }
|
---|
237 | set
|
---|
238 | {
|
---|
239 | MaxDepthParameter.Value.Value = value;
|
---|
240 | }
|
---|
241 | }
|
---|
242 |
|
---|
243 | /// <summary>
|
---|
244 | /// This is the maximum size of an item on the CODE stack, expressed as a number of points.
|
---|
245 | /// A point is an instruction, a literal, or a pair of parentheses. Any instruction that would cause this limit to be
|
---|
246 | /// exceeded should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the
|
---|
247 | /// instruction.
|
---|
248 | /// </summary>
|
---|
249 | public IValueParameter<IntValue> MaxPointsInProgramParameter
|
---|
250 | {
|
---|
251 | get { return (IValueParameter<IntValue>)Parameters[MAX_POINTS_IN_PROGRAM_PARAMETER_NAME]; }
|
---|
252 | }
|
---|
253 |
|
---|
254 | public int MaxPointsInProgram
|
---|
255 | {
|
---|
256 | get { return MaxPointsInProgramParameter.Value.Value; }
|
---|
257 | set
|
---|
258 | {
|
---|
259 | MaxPointsInProgramParameter.Value.Value = value;
|
---|
260 | }
|
---|
261 | }
|
---|
262 |
|
---|
263 | public IValueParameter<IntValue> MaxVectorLengthParameter
|
---|
264 | {
|
---|
265 | get { return (IValueParameter<IntValue>)Parameters[MAX_VECTOR_LENGTH_PARAMETER_NAME]; }
|
---|
266 | }
|
---|
267 |
|
---|
268 | public int MaxVectorLength
|
---|
269 | {
|
---|
270 | get { return MaxVectorLengthParameter.Value.Value; }
|
---|
271 | set { MaxVectorLengthParameter.Value.Value = value; }
|
---|
272 | }
|
---|
273 |
|
---|
274 | /// <summary>
|
---|
275 | /// The maximum number of points in an expression produced by the CODE.RAND instruction.
|
---|
276 | /// </summary>
|
---|
277 | public IValueParameter<IntValue> MaxPointsInRandomExpressionParameter
|
---|
278 | {
|
---|
279 | get { return (IValueParameter<IntValue>)Parameters[MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME]; }
|
---|
280 | }
|
---|
281 |
|
---|
282 | public int MaxPointsInRandomExpression
|
---|
283 | {
|
---|
284 | get { return MaxPointsInRandomExpressionParameter.Value.Value; }
|
---|
285 | set
|
---|
286 | {
|
---|
287 | MaxPointsInRandomExpressionParameter.Value.Value = value;
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | /// <summary>
|
---|
292 | /// When TRUE (which is the default), code passed to the top level of the interpreter
|
---|
293 | /// will be pushed onto the CODE stack prior to execution.
|
---|
294 | /// </summary>
|
---|
295 | public IValueParameter<BoolValue> TopLevelPushCodeParameter
|
---|
296 | {
|
---|
297 | get { return (IValueParameter<BoolValue>)Parameters[TOP_LEVEL_PUSH_CODE_PARAMETER_NAME]; }
|
---|
298 | }
|
---|
299 |
|
---|
300 | public bool TopLevelPushCode
|
---|
301 | {
|
---|
302 | get { return TopLevelPushCodeParameter.Value.Value; }
|
---|
303 | set
|
---|
304 | {
|
---|
305 | TopLevelPushCodeParameter.Value.Value = value;
|
---|
306 | }
|
---|
307 | }
|
---|
308 |
|
---|
309 | /// <summary>
|
---|
310 | /// When TRUE, the CODE stack will be popped at the end of top level calls to the interpreter. The default is FALSE.
|
---|
311 | /// </summary>
|
---|
312 | public IValueParameter<BoolValue> TopLevelPopCodeParameter
|
---|
313 | {
|
---|
314 | get { return (IValueParameter<BoolValue>)Parameters[TOP_LEVEL_POP_CODE_PARAMETER_NAME]; }
|
---|
315 | }
|
---|
316 |
|
---|
317 | public bool TopLevelPopCode
|
---|
318 | {
|
---|
319 | get { return TopLevelPopCodeParameter.Value.Value; }
|
---|
320 | set
|
---|
321 | {
|
---|
322 | TopLevelPopCodeParameter.Value.Value = value;
|
---|
323 | }
|
---|
324 | }
|
---|
325 |
|
---|
326 | public IValueParameter<IntValue> MaxStringLengthParameter
|
---|
327 | {
|
---|
328 | get { return (IValueParameter<IntValue>)Parameters[MAX_STRING_LENGTH_PARAMETER_NAME]; }
|
---|
329 | }
|
---|
330 |
|
---|
331 | public int MaxStringLength
|
---|
332 | {
|
---|
333 | get { return MaxStringLengthParameter.Value.Value; }
|
---|
334 | set { MaxStringLengthParameter.Value.Value = value; }
|
---|
335 | }
|
---|
336 | }
|
---|
337 | }
|
---|