Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfigurationParameterCollection.cs @ 15032

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

#2665 Fixed bias 0 issue, PushExpressionFrequencyAnalyzer, Fixed probability for ERC settings, Fixed enable/disable instructions, Added expression descriptions

File size: 13.5 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 PushConfigurationParameterCollection : PushConfigurationBase, IReadOnlyPushConfiguration {
13    private const string InstructionsParameterName = "Instructions";
14    private const string InstructionsParameterDescription = "Enables/Disables Instructions";
15    private const string EvalPushLimitParameterName = "EvalPushLimit";
16    private const string EvalPushLimitParameterDescription = "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 MaxPointsInProgramParameterName = "MaxProgramLength";
18    private const string MaxProgramLengthParameterDescription = "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 TopLevelPushCodeParameterName = "TopLevelPushCode";
20    private const string TopLevelPushCodeParameterDescription = "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 TopLevelPopCodeParameterName = "TopLevelPopCode";
22    private const string TopLevelPopCodeParameterDescription = "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 MaxPointsInRandomInstructionParameterName = "MaxPointsInRandomInstruction";
24    private const string MaxPointsInRandomInstructionParameterDescription = "MaxPointsInRandomInstruction";
25    private const string ErcOptionsParameterName = "ERC options";
26    private const string MaxStringLengthParameterName = "Max. string length";
27    private const string MaxDepthParameterName = "Max. program recursion";
28    private const string MaxParenthesesCloseParameterName = "Max. parentheses close";
29    private const string MaxParenthesesCloseParameterDescription = "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 ParenthesesCloseBiasLevelParameterName = "Parentheses close bias level";
31    private const string ParenthesesCloseBiasLevelParameterDescription = "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 MaxVectorLengthParameterName = "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(InstructionsParameterName))
65        Parameters.Add(new ValueParameter<IEnabledExpressionsConfiguration>(
66          InstructionsParameterName,
67          InstructionsParameterDescription,
68          this));
69
70      if (!Parameters.ContainsKey(ErcOptionsParameterName))
71        Parameters.Add(new ValueParameter<ErcOptions>(ErcOptionsParameterName));
72
73      if (!Parameters.ContainsKey(MaxVectorLengthParameterName))
74        Parameters.Add(new FixedValueParameter<IntValue>(
75          MaxVectorLengthParameterName,
76          new IntValue(500)) { Hidden = true });
77
78      if (!Parameters.ContainsKey(EvalPushLimitParameterName))
79        Parameters.Add(new FixedValueParameter<IntValue>(
80          EvalPushLimitParameterName,
81          EvalPushLimitParameterDescription,
82          new IntValue(1000)));
83
84      if (!Parameters.ContainsKey(MaxPointsInProgramParameterName))
85        Parameters.Add(new FixedValueParameter<IntValue>(
86          MaxPointsInProgramParameterName,
87          MaxProgramLengthParameterDescription,
88          new IntValue(200)));
89
90      if (!Parameters.ContainsKey(MaxParenthesesCloseParameterName))
91        Parameters.Add(new FixedValueParameter<IntValue>(
92          MaxParenthesesCloseParameterName,
93          MaxParenthesesCloseParameterDescription,
94          new IntValue(4)) { Hidden = true });
95
96      if (!Parameters.ContainsKey(ParenthesesCloseBiasLevelParameterName))
97        Parameters.Add(new FixedValueParameter<DoubleValue>(
98          ParenthesesCloseBiasLevelParameterName,
99          ParenthesesCloseBiasLevelParameterDescription,
100          new DoubleValue(4)) { Hidden = true });
101
102      if (!Parameters.ContainsKey(TopLevelPushCodeParameterName))
103        Parameters.Add(new FixedValueParameter<BoolValue>(
104          TopLevelPushCodeParameterName,
105          TopLevelPushCodeParameterDescription,
106          new BoolValue(true)) { Hidden = true });
107
108      if (!Parameters.ContainsKey(TopLevelPopCodeParameterName))
109        Parameters.Add(new FixedValueParameter<BoolValue>(
110          TopLevelPopCodeParameterName,
111          TopLevelPopCodeParameterDescription,
112          new BoolValue(false)) { Hidden = true });
113
114      if (!Parameters.ContainsKey(MaxPointsInRandomInstructionParameterName))
115        Parameters.Add(new FixedValueParameter<IntValue>(
116          MaxPointsInRandomInstructionParameterName,
117          MaxPointsInRandomInstructionParameterDescription,
118          new IntValue(50)) { Hidden = true });
119
120      if (!Parameters.ContainsKey(MaxStringLengthParameterName))
121        Parameters.Add(new FixedValueParameter<IntValue>(
122          MaxStringLengthParameterName,
123          new IntValue(1000)) { Hidden = true });
124
125      if (!Parameters.ContainsKey(MaxDepthParameterName))
126        Parameters.Add(new FixedValueParameter<IntValue>(
127          MaxDepthParameterName,
128          new IntValue(1000)) { Hidden = true });
129    }
130
131    public IValueParameter<IEnabledExpressionsConfiguration> InstructionsParameter
132    {
133      get { return (IValueParameter<IEnabledExpressionsConfiguration>)Parameters[InstructionsParameterName]; }
134    }
135
136    public IEnabledExpressionsConfiguration 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[ErcOptionsParameterName]; }
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[EvalPushLimitParameterName]; }
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[ParenthesesCloseBiasLevelParameterName]; }
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[MaxParenthesesCloseParameterName]; }
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[MaxDepthParameterName]; }
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[MaxPointsInProgramParameterName]; }
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[MaxVectorLengthParameterName]; }
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[MaxPointsInRandomInstructionParameterName]; }
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[TopLevelPushCodeParameterName]; }
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[TopLevelPopCodeParameterName]; }
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[MaxStringLengthParameterName]; }
329    }
330
331    public int MaxStringLength
332    {
333      get { return MaxStringLengthParameter.Value.Value; }
334      set { MaxStringLengthParameter.Value.Value = value; }
335    }
336  }
337}
Note: See TracBrowser for help on using the repository browser.