Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs @ 15334

Last change on this file since 15334 was 15334, checked in by pkimmesw, 7 years ago

#2665 Testet Problems, Testet error functions, Small fixes, Created HL files

File size: 15.0 KB
Line 
1namespace 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    }
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 = true });
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    {
148      get { return (IValueParameter<IExpressionsConfiguration>)Parameters[INSTRUCTIONS_PARAMETER_NAME]; }
149    }
150
151    public IExpressionsConfiguration Instructions
152    {
153      get { return InstructionsParameter.Value; }
154      set { InstructionsParameter.Value = value; }
155    }
156
157    public IValueParameter<ErcOptions> ErcOptionsParameter
158    {
159      get { return (IValueParameter<ErcOptions>)Parameters[ERC_OPTIONS_PARAMETER_NAME]; }
160    }
161
162    public ErcOptions ErcOptions
163    {
164      get { return ErcOptionsParameter.Value; }
165      set
166      {
167        ErcOptionsParameter.Value = value;
168      }
169    }
170
171    IReadOnlyList<string> IReadOnlyExpressionsConfiguration.EnabledExpressions
172    {
173      get
174      {
175        return enabledExpressions;
176      }
177    }
178
179    IReadOnlyErcOptions IReadOnlyPushConfiguration.ErcOptions
180    {
181      get
182      {
183        return ErcOptions;
184      }
185    }
186
187    /// <summary>
188    ///     This is the maximum allowed number of "executions" in a single top-level call to the interpreter.
189    ///     The execution of a single Push instruction counts as one execution, as does the processing of a single literal,
190    ///     as does the descent into one layer of parentheses (that is, the processing of the "(" counts as one execution).
191    ///     When this limit is exceeded the interpreter aborts immediately, leaving its stacks in the states they were in prior
192    ///     to the abort (so they may still be examined by a calling program). Whether or not this counts as an "abnormal"
193    ///     termination
194    ///     is up to the calling program.
195    /// </summary>
196    public IValueParameter<IntValue> EvalPushLimitParameter
197    {
198      get { return (IValueParameter<IntValue>)Parameters[EVAL_PUSH_LIMIT_PARAMETER_NAME]; }
199    }
200
201    public int EvalPushLimit
202    {
203      get { return EvalPushLimitParameter.Value.Value; }
204      set { EvalPushLimitParameter.Value.Value = value; }
205    }
206
207
208    /// <summary>
209    /// Determines the likelihood of smaller or bigger values.
210    /// x greater than 1 means that result is biased towards min.
211    /// x smaller than 1 means that result is biased towards max.
212    /// </summary>
213    public IValueParameter<DoubleValue> CloseBiasLevelParameter
214    {
215      get { return (IValueParameter<DoubleValue>)Parameters[CLOSE_BIAS_LEVEL_PARAMETER_NAME]; }
216    }
217
218    public double CloseBiasLevel
219    {
220      get { return CloseBiasLevelParameter.Value.Value; }
221      set { CloseBiasLevelParameter.Value.Value = value; }
222    }
223
224    /// <summary>
225    /// Determines the maximum of blocks which will be closed.
226    /// </summary>
227    public IValueParameter<IntValue> MaxCloseParameter
228    {
229      get { return (IValueParameter<IntValue>)Parameters[MAX_CLOSE_PARAMETER_NAME]; }
230    }
231
232    public int MaxClose
233    {
234      get { return MaxCloseParameter.Value.Value; }
235      set
236      {
237        MaxCloseParameter.Value.Value = value;
238      }
239    }
240
241    /// <summary>
242    /// This is the maximum of depth a push program can have. Expressions, which lead to exceed this limit are interpreted as NOOP.
243    /// </summary>
244    public IValueParameter<IntValue> MaxDepthParameter
245    {
246      get { return (IValueParameter<IntValue>)Parameters[MAX_DEPTH_PARAMETER_NAME]; }
247    }
248
249    public int MaxDepth
250    {
251      get { return MaxDepthParameter.Value.Value; }
252      set
253      {
254        MaxDepthParameter.Value.Value = value;
255      }
256    }
257
258    public IValueParameter<IntValue> MinProgramLengthParameter
259    {
260      get { return (IValueParameter<IntValue>)Parameters[MIN_PROGRAM_LENGTH]; }
261    }
262
263    public int MinProgramLength
264    {
265      get { return MinProgramLengthParameter.Value.Value; }
266      set
267      {
268        MinProgramLengthParameter.Value.Value = value;
269      }
270    }
271
272    /// <summary>
273    ///     This is the maximum size of an item on the CODE stack, expressed as a number of points.
274    ///     A point is an instruction, a literal, or a pair of parentheses. Any instruction that would cause this limit to be
275    ///     exceeded should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the
276    ///     instruction.
277    /// </summary>
278    public IValueParameter<IntValue> MaxProgramLengthParameter
279    {
280      get { return (IValueParameter<IntValue>)Parameters[MAX_PROGRAM_LENGTH]; }
281    }
282
283    public int MaxProgramLength
284    {
285      get { return MaxProgramLengthParameter.Value.Value; }
286      set
287      {
288        MaxProgramLengthParameter.Value.Value = value;
289      }
290    }
291
292    public IValueParameter<IntValue> MaxVectorLengthParameter
293    {
294      get { return (IValueParameter<IntValue>)Parameters[MAX_VECTOR_LENGTH_PARAMETER_NAME]; }
295    }
296
297    public int MaxVectorLength
298    {
299      get { return MaxVectorLengthParameter.Value.Value; }
300      set { MaxVectorLengthParameter.Value.Value = value; }
301    }
302
303    /// <summary>
304    ///     The maximum number of points in an expression produced by the CODE.RAND instruction.
305    /// </summary>
306    public IValueParameter<IntValue> MaxPointsInRandomExpressionParameter
307    {
308      get { return (IValueParameter<IntValue>)Parameters[MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME]; }
309    }
310
311    public int MaxPointsInRandomExpression
312    {
313      get { return MaxPointsInRandomExpressionParameter.Value.Value; }
314      set
315      {
316        MaxPointsInRandomExpressionParameter.Value.Value = value;
317      }
318    }
319
320    /// <summary>
321    ///     When TRUE (which is the default), code passed to the top level of the interpreter
322    ///     will be pushed onto the CODE stack prior to execution.
323    /// </summary>
324    public IValueParameter<BoolValue> TopLevelPushCodeParameter
325    {
326      get { return (IValueParameter<BoolValue>)Parameters[TOP_LEVEL_PUSH_CODE_PARAMETER_NAME]; }
327    }
328
329    public bool TopLevelPushCode
330    {
331      get { return TopLevelPushCodeParameter.Value.Value; }
332      set
333      {
334        TopLevelPushCodeParameter.Value.Value = value;
335      }
336    }
337
338    /// <summary>
339    ///     When TRUE, the CODE stack will be popped at the end of top level calls to the interpreter. The default is FALSE.
340    /// </summary>
341    public IValueParameter<BoolValue> TopLevelPopCodeParameter
342    {
343      get { return (IValueParameter<BoolValue>)Parameters[TOP_LEVEL_POP_CODE_PARAMETER_NAME]; }
344    }
345
346    public bool TopLevelPopCode
347    {
348      get { return TopLevelPopCodeParameter.Value.Value; }
349      set
350      {
351        TopLevelPopCodeParameter.Value.Value = value;
352      }
353    }
354
355    public IValueParameter<IntValue> MaxStringLengthParameter
356    {
357      get { return (IValueParameter<IntValue>)Parameters[MAX_STRING_LENGTH_PARAMETER_NAME]; }
358    }
359
360    public int MaxStringLength
361    {
362      get { return MaxStringLengthParameter.Value.Value; }
363      set { MaxStringLengthParameter.Value.Value = value; }
364    }
365
366    public IValueParameter<BoolValue> TopLevelPushInputArgumentsParameter
367    {
368      get { return (IValueParameter<BoolValue>)Parameters[TOP_LEVEL_PUSH_INPUT_ARGUMENTS]; }
369    }
370
371    public bool TopLevelPushInputArguments
372    {
373      get { return TopLevelPushInputArgumentsParameter.Value.Value; }
374      set { TopLevelPushInputArgumentsParameter.Value.Value = value; }
375    }
376  }
377}
Note: See TracBrowser for help on using the repository browser.