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