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