[15017] | 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 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 | /// This is the maximum of depth a push program can have. Expressions, which lead to exceed this limit are interpreted as NOOP.
|
---|
| 195 | /// </summary>
|
---|
| 196 | public IValueParameter<DoubleValue> ParenthesesCloseBiasLevelParameter
|
---|
| 197 | {
|
---|
| 198 | get { return (IValueParameter<DoubleValue>)Parameters[ParenthesesCloseBiasLevelParameterName]; }
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | public double ParenthesesCloseBiasLevel
|
---|
| 202 | {
|
---|
| 203 | get { return ParenthesesCloseBiasLevelParameter.Value.Value; }
|
---|
| 204 | set { ParenthesesCloseBiasLevelParameter.Value.Value = value; }
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | /// <summary>
|
---|
| 208 | /// This is the maximum of depth a push program can have. Expressions, which lead to exceed this limit are interpreted as NOOP.
|
---|
| 209 | /// </summary>
|
---|
| 210 | public IValueParameter<IntValue> MaxParenthesesCloseParameter
|
---|
| 211 | {
|
---|
| 212 | get { return (IValueParameter<IntValue>)Parameters[MaxParenthesesCloseParameterName]; }
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | public int MaxParenthesesClose
|
---|
| 216 | {
|
---|
| 217 | get { return MaxParenthesesCloseParameter.Value.Value; }
|
---|
| 218 | set
|
---|
| 219 | {
|
---|
| 220 | MaxParenthesesCloseParameter.Value.Value = value;
|
---|
| 221 | }
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | /// <summary>
|
---|
| 225 | /// This is the maximum of depth a push program can have. Expressions, which lead to exceed this limit are interpreted as NOOP.
|
---|
| 226 | /// </summary>
|
---|
| 227 | public IValueParameter<IntValue> MaxDepthParameter
|
---|
| 228 | {
|
---|
| 229 | get { return (IValueParameter<IntValue>)Parameters[MaxDepthParameterName]; }
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | public int MaxDepth
|
---|
| 233 | {
|
---|
| 234 | get { return MaxDepthParameter.Value.Value; }
|
---|
| 235 | set
|
---|
| 236 | {
|
---|
| 237 | MaxDepthParameter.Value.Value = value;
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | /// <summary>
|
---|
| 242 | /// This is the maximum size of an item on the CODE stack, expressed as a number of points.
|
---|
| 243 | /// A point is an instruction, a literal, or a pair of parentheses. Any instruction that would cause this limit to be
|
---|
| 244 | /// exceeded should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the
|
---|
| 245 | /// instruction.
|
---|
| 246 | /// </summary>
|
---|
| 247 | public IValueParameter<IntValue> MaxPointsInProgramParameter
|
---|
| 248 | {
|
---|
| 249 | get { return (IValueParameter<IntValue>)Parameters[MaxPointsInProgramParameterName]; }
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | public int MaxPointsInProgram
|
---|
| 253 | {
|
---|
| 254 | get { return MaxPointsInProgramParameter.Value.Value; }
|
---|
| 255 | set
|
---|
| 256 | {
|
---|
| 257 | MaxPointsInProgramParameter.Value.Value = value;
|
---|
| 258 | }
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | public IValueParameter<IntValue> MaxVectorLengthParameter
|
---|
| 262 | {
|
---|
| 263 | get { return (IValueParameter<IntValue>)Parameters[MaxVectorLengthParameterName]; }
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | public int MaxVectorLength
|
---|
| 267 | {
|
---|
| 268 | get { return MaxVectorLengthParameter.Value.Value; }
|
---|
| 269 | set { MaxVectorLengthParameter.Value.Value = value; }
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | /// <summary>
|
---|
| 273 | /// The maximum number of points in an expression produced by the CODE.RAND instruction.
|
---|
| 274 | /// </summary>
|
---|
| 275 | public IValueParameter<IntValue> MaxPointsInRandomExpressionParameter
|
---|
| 276 | {
|
---|
| 277 | get { return (IValueParameter<IntValue>)Parameters[MaxPointsInRandomInstructionParameterName]; }
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | public int MaxPointsInRandomExpression
|
---|
| 281 | {
|
---|
| 282 | get { return MaxPointsInRandomExpressionParameter.Value.Value; }
|
---|
| 283 | set
|
---|
| 284 | {
|
---|
| 285 | MaxPointsInRandomExpressionParameter.Value.Value = value;
|
---|
| 286 | }
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | /// <summary>
|
---|
| 290 | /// When TRUE (which is the default), code passed to the top level of the interpreter
|
---|
| 291 | /// will be pushed onto the CODE stack prior to execution.
|
---|
| 292 | /// </summary>
|
---|
| 293 | public IValueParameter<BoolValue> TopLevelPushCodeParameter
|
---|
| 294 | {
|
---|
| 295 | get { return (IValueParameter<BoolValue>)Parameters[TopLevelPushCodeParameterName]; }
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | public bool TopLevelPushCode
|
---|
| 299 | {
|
---|
| 300 | get { return TopLevelPushCodeParameter.Value.Value; }
|
---|
| 301 | set
|
---|
| 302 | {
|
---|
| 303 | TopLevelPushCodeParameter.Value.Value = value;
|
---|
| 304 | }
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | /// <summary>
|
---|
| 308 | /// When TRUE, the CODE stack will be popped at the end of top level calls to the interpreter. The default is FALSE.
|
---|
| 309 | /// </summary>
|
---|
| 310 | public IValueParameter<BoolValue> TopLevelPopCodeParameter
|
---|
| 311 | {
|
---|
| 312 | get { return (IValueParameter<BoolValue>)Parameters[TopLevelPopCodeParameterName]; }
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | public bool TopLevelPopCode
|
---|
| 316 | {
|
---|
| 317 | get { return TopLevelPopCodeParameter.Value.Value; }
|
---|
| 318 | set
|
---|
| 319 | {
|
---|
| 320 | TopLevelPopCodeParameter.Value.Value = value;
|
---|
| 321 | }
|
---|
| 322 | }
|
---|
| 323 |
|
---|
| 324 | public IValueParameter<IntValue> MaxStringLengthParameter
|
---|
| 325 | {
|
---|
| 326 | get { return (IValueParameter<IntValue>)Parameters[MaxStringLengthParameterName]; }
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 | public int MaxStringLength
|
---|
| 330 | {
|
---|
| 331 | get { return MaxStringLengthParameter.Value.Value; }
|
---|
| 332 | set { MaxStringLengthParameter.Value.Value = value; }
|
---|
| 333 | }
|
---|
| 334 | }
|
---|
| 335 | }
|
---|