Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs @ 16003

Last change on this file since 16003 was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

File size: 14.8 KB
RevLine 
[15771]1namespace HeuristicLab.Problems.ProgramSynthesis {
[14744]2  using System.Collections.Generic;
3
[15334]4  using HeuristicLab.Common;
5  using HeuristicLab.Core;
6  using HeuristicLab.Data;
7  using HeuristicLab.Parameters;
8  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9
[14744]10  [StorableClass]
[15032]11  public class PushConfiguration : PushConfigurationBase, IReadOnlyPushConfiguration {
[15334]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
[14744]36    public PushConfiguration() {
[15334]37      Parameters = new ParameterCollection();
38      InitParameters();
[14744]39
[15017]40      FloatStringFormat = "R";
[14744]41    }
42
[15334]43    public PushConfiguration(PushConfiguration origin, Cloner cloner) : base(origin, cloner) {
44      Parameters = cloner.Clone(origin.Parameters);
[15344]45      FloatStringFormat = origin.FloatStringFormat;
[15334]46    }
[14834]47
[15334]48    public override IDeepCloneable Clone(Cloner cloner) {
49      return new PushConfiguration(this, cloner);
[14777]50    }
[14744]51
[15334]52    [StorableConstructor]
53    protected PushConfiguration(bool deserialize) { }
[14744]54
[15334]55    [StorableHook(HookType.AfterDeserialization)]
56    // ReSharper disable once UnusedMember.Local
57    private void AfterDeserialization() {
58      InitParameters();
[14834]59    }
[14744]60
[15017]61    [Storable]
[15334]62    public ParameterCollection Parameters { get; private set; }
63
64    [Storable]
[15017]65    public string FloatStringFormat { get; set; }
[14875]66
[15334]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));
[14744]73
[15334]74      if (!Parameters.ContainsKey(ERC_OPTIONS_PARAMETER_NAME))
75        Parameters.Add(new ValueParameter<ErcOptions>(ERC_OPTIONS_PARAMETER_NAME));
[14744]76
[15334]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 });
[15017]81
[15334]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)));
[15017]87
[15334]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)));
[14744]93
[15334]94      if (!Parameters.ContainsKey(MIN_PROGRAM_LENGTH))
95        Parameters.Add(new FixedValueParameter<IntValue>(
96          MIN_PROGRAM_LENGTH,
97          MIN_PROGRAM_LENGTH_PARAMETER_DESCRIPTION,
[15341]98          new IntValue(0)) { Hidden = false });
[14744]99
[15334]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
[15771]146    public IValueParameter<IExpressionsConfiguration> InstructionsParameter {
[15334]147      get { return (IValueParameter<IExpressionsConfiguration>)Parameters[INSTRUCTIONS_PARAMETER_NAME]; }
148    }
149
[15771]150    public IExpressionsConfiguration Instructions {
[15334]151      get { return InstructionsParameter.Value; }
152      set { InstructionsParameter.Value = value; }
153    }
154
[15771]155    public IValueParameter<ErcOptions> ErcOptionsParameter {
[15334]156      get { return (IValueParameter<ErcOptions>)Parameters[ERC_OPTIONS_PARAMETER_NAME]; }
157    }
158
[15771]159    public ErcOptions ErcOptions {
[15334]160      get { return ErcOptionsParameter.Value; }
[15771]161      set {
[15334]162        ErcOptionsParameter.Value = value;
163      }
164    }
165
[15771]166    IReadOnlyList<string> IReadOnlyExpressionsConfiguration.EnabledExpressions {
167      get {
[15334]168        return enabledExpressions;
169      }
170    }
171
[15771]172    IReadOnlyErcOptions IReadOnlyPushConfiguration.ErcOptions {
173      get {
[15334]174        return ErcOptions;
175      }
176    }
177
[14744]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>
[15771]187    public IValueParameter<IntValue> EvalPushLimitParameter {
[15334]188      get { return (IValueParameter<IntValue>)Parameters[EVAL_PUSH_LIMIT_PARAMETER_NAME]; }
189    }
[14744]190
[15771]191    public int EvalPushLimit {
[15334]192      get { return EvalPushLimitParameter.Value.Value; }
193      set { EvalPushLimitParameter.Value.Value = value; }
194    }
195
196
[14744]197    /// <summary>
[15334]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.
[14744]201    /// </summary>
[15771]202    public IValueParameter<DoubleValue> CloseBiasLevelParameter {
[15334]203      get { return (IValueParameter<DoubleValue>)Parameters[CLOSE_BIAS_LEVEL_PARAMETER_NAME]; }
204    }
[14744]205
[15771]206    public double CloseBiasLevel {
[15334]207      get { return CloseBiasLevelParameter.Value.Value; }
208      set { CloseBiasLevelParameter.Value.Value = value; }
209    }
210
[14744]211    /// <summary>
[15334]212    /// Determines the maximum of blocks which will be closed.
[14897]213    /// </summary>
[15771]214    public IValueParameter<IntValue> MaxCloseParameter {
[15334]215      get { return (IValueParameter<IntValue>)Parameters[MAX_CLOSE_PARAMETER_NAME]; }
216    }
[14897]217
[15771]218    public int MaxClose {
[15334]219      get { return MaxCloseParameter.Value.Value; }
[15771]220      set {
[15334]221        MaxCloseParameter.Value.Value = value;
222      }
223    }
224
[14897]225    /// <summary>
[15334]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>
[15771]228    public IValueParameter<IntValue> MaxDepthParameter {
[15334]229      get { return (IValueParameter<IntValue>)Parameters[MAX_DEPTH_PARAMETER_NAME]; }
230    }
231
[15771]232    public int MaxDepth {
[15334]233      get { return MaxDepthParameter.Value.Value; }
[15771]234      set {
[15334]235        MaxDepthParameter.Value.Value = value;
236      }
237    }
238
[15771]239    public IValueParameter<IntValue> MinProgramLengthParameter {
[15334]240      get { return (IValueParameter<IntValue>)Parameters[MIN_PROGRAM_LENGTH]; }
241    }
242
[15771]243    public int MinProgramLength {
[15334]244      get { return MinProgramLengthParameter.Value.Value; }
[15771]245      set {
[15334]246        MinProgramLengthParameter.Value.Value = value;
247      }
248    }
249
250    /// <summary>
[14744]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
[14897]253    ///     exceeded should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the
[14744]254    ///     instruction.
255    /// </summary>
[15771]256    public IValueParameter<IntValue> MaxProgramLengthParameter {
[15334]257      get { return (IValueParameter<IntValue>)Parameters[MAX_PROGRAM_LENGTH]; }
258    }
[14744]259
[15771]260    public int MaxProgramLength {
[15334]261      get { return MaxProgramLengthParameter.Value.Value; }
[15771]262      set {
[15334]263        MaxProgramLengthParameter.Value.Value = value;
264      }
265    }
266
[15771]267    public IValueParameter<IntValue> MaxVectorLengthParameter {
[15334]268      get { return (IValueParameter<IntValue>)Parameters[MAX_VECTOR_LENGTH_PARAMETER_NAME]; }
269    }
270
[15771]271    public int MaxVectorLength {
[15334]272      get { return MaxVectorLengthParameter.Value.Value; }
273      set { MaxVectorLengthParameter.Value.Value = value; }
274    }
275
[14744]276    /// <summary>
277    ///     The maximum number of points in an expression produced by the CODE.RAND instruction.
278    /// </summary>
[15771]279    public IValueParameter<IntValue> MaxPointsInRandomExpressionParameter {
[15334]280      get { return (IValueParameter<IntValue>)Parameters[MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME]; }
281    }
[14744]282
[15771]283    public int MaxPointsInRandomExpression {
[15334]284      get { return MaxPointsInRandomExpressionParameter.Value.Value; }
[15771]285      set {
[15334]286        MaxPointsInRandomExpressionParameter.Value.Value = value;
287      }
288    }
289
[14744]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>
[15771]294    public IValueParameter<BoolValue> TopLevelPushCodeParameter {
[15334]295      get { return (IValueParameter<BoolValue>)Parameters[TOP_LEVEL_PUSH_CODE_PARAMETER_NAME]; }
296    }
[14744]297
[15771]298    public bool TopLevelPushCode {
[15334]299      get { return TopLevelPushCodeParameter.Value.Value; }
[15771]300      set {
[15334]301        TopLevelPushCodeParameter.Value.Value = value;
302      }
303    }
304
[14744]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>
[15771]308    public IValueParameter<BoolValue> TopLevelPopCodeParameter {
[15334]309      get { return (IValueParameter<BoolValue>)Parameters[TOP_LEVEL_POP_CODE_PARAMETER_NAME]; }
310    }
[14744]311
[15771]312    public bool TopLevelPopCode {
[15334]313      get { return TopLevelPopCodeParameter.Value.Value; }
[15771]314      set {
[15334]315        TopLevelPopCodeParameter.Value.Value = value;
316      }
317    }
[14777]318
[15771]319    public IValueParameter<IntValue> MaxStringLengthParameter {
[15334]320      get { return (IValueParameter<IntValue>)Parameters[MAX_STRING_LENGTH_PARAMETER_NAME]; }
321    }
[14744]322
[15771]323    public int MaxStringLength {
[15334]324      get { return MaxStringLengthParameter.Value.Value; }
325      set { MaxStringLengthParameter.Value.Value = value; }
[14744]326    }
[15334]327
[15771]328    public IValueParameter<BoolValue> TopLevelPushInputArgumentsParameter {
[15334]329      get { return (IValueParameter<BoolValue>)Parameters[TOP_LEVEL_PUSH_INPUT_ARGUMENTS]; }
330    }
331
[15771]332    public bool TopLevelPushInputArguments {
[15334]333      get { return TopLevelPushInputArgumentsParameter.Value.Value; }
334      set { TopLevelPushInputArgumentsParameter.Value.Value = value; }
335    }
[14744]336  }
[15334]337}
Note: See TracBrowser for help on using the repository browser.