Changeset 15334 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs
- Timestamp:
- 08/21/17 11:33:53 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP
- Property svn:ignore
-
old new 1 1 *.user 2 packages 3 TestResults
-
- Property svn:ignore
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs
r15289 r15334 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Configuration { 2 2 using System.Collections.Generic; 3 using Base.Erc; 4 using Common; 5 using Persistence.Default.CompositeSerializers.Storable; 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; 6 10 7 11 [StorableClass] 8 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 9 37 public PushConfiguration() { 10 Name = "Push Configuration"; 11 12 ErcOptions = new ErcOptions(); 13 EvalPushLimit = 1024; 14 MinPointsInProgram = 25; 15 MaxPointsInProgram = 200; 16 TopLevelPushCode = true; 17 TopLevelPopCode = false; 18 MaxPointsInRandomExpression = 64; 19 MaxStringLength = 1000; 20 MaxVectorLength = 500; 21 MaxDepth = 100; 38 Parameters = new ParameterCollection(); 39 InitParameters(); 40 22 41 FloatStringFormat = "R"; 23 MaxParenthesesClose = 4; 24 ParenthesesCloseBiasLevel = 1; 25 } 26 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 } 27 51 28 52 [StorableConstructor] 29 public PushConfiguration(bool deserializing) 30 : base(deserializing) { 31 } 32 33 public PushConfiguration(PushConfiguration origin, Cloner cloner) : base(origin, cloner) { 34 35 ErcOptions = cloner.Clone(origin.ErcOptions); 36 EvalPushLimit = origin.EvalPushLimit; 37 MinPointsInProgram = origin.MinPointsInProgram; 38 MaxPointsInProgram = origin.MaxPointsInProgram; 39 MaxPointsInRandomExpression = origin.MaxPointsInRandomExpression; 40 TopLevelPushCode = origin.TopLevelPushCode; 41 TopLevelPopCode = origin.TopLevelPopCode; 42 MaxStringLength = origin.MaxStringLength; 43 MaxVectorLength = origin.MaxVectorLength; 44 MaxDepth = origin.MaxDepth; 45 FloatStringFormat = origin.FloatStringFormat; 46 MaxParenthesesClose = origin.MaxParenthesesClose; 47 ParenthesesCloseBiasLevel = origin.ParenthesesCloseBiasLevel; 48 } 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; } 49 63 50 64 [Storable] 51 65 public string FloatStringFormat { get; set; } 52 66 53 54 IReadOnlyList<string> IReadOnlyExpressionsConfiguration.EnabledExpressions { get { return enabledExpressions; } } 55 56 [Storable] 57 public int MaxParenthesesClose { get; set; } 58 [Storable] 59 public double ParenthesesCloseBiasLevel { get; set; } 60 61 62 [Storable] 63 public ErcOptions ErcOptions { get; set; } 64 65 IReadOnlyErcOptions IReadOnlyPushConfiguration.ErcOptions { get { return ErcOptions; } } 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 } 66 186 67 187 /// <summary> … … 74 194 /// is up to the calling program. 75 195 /// </summary> 76 [Storable] 77 public int EvalPushLimit { get; set; } 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 } 78 240 79 241 /// <summary> 80 242 /// This is the maximum of depth a push program can have. Expressions, which lead to exceed this limit are interpreted as NOOP. 81 243 /// </summary> 82 [Storable] 83 public int MaxDepth { get; set; } 84 85 /// <summary> 86 /// This is the minimum size of an item on the CODE stack, expressed as a number of points. 87 /// A point is an instruction, a literal, or a pair of parentheses. Any instruction that would cause this limit to be 88 /// exceeded should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the 89 /// instruction. 90 /// </summary> 91 [Storable] 92 public int MinPointsInProgram { get; set; } 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 } 93 271 94 272 /// <summary> … … 98 276 /// instruction. 99 277 /// </summary> 100 [Storable] 101 public int MaxPointsInProgram { get; set; } 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 } 102 302 103 303 /// <summary> 104 304 /// The maximum number of points in an expression produced by the CODE.RAND instruction. 105 305 /// </summary> 106 [Storable] 107 public int MaxPointsInRandomExpression { get; set; } 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 } 108 319 109 320 /// <summary> … … 111 322 /// will be pushed onto the CODE stack prior to execution. 112 323 /// </summary> 113 [Storable] 114 public bool TopLevelPushCode { get; set; } 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 } 115 337 116 338 /// <summary> 117 339 /// When TRUE, the CODE stack will be popped at the end of top level calls to the interpreter. The default is FALSE. 118 340 /// </summary> 119 [Storable] 120 public bool TopLevelPopCode { get; set; } 121 122 [Storable] 123 public int MaxStringLength { get; set; } 124 125 [Storable] 126 public int MaxVectorLength { get; set; } 127 128 public override IDeepCloneable Clone(Cloner cloner) { 129 return new PushConfiguration(this, cloner); 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; } 130 375 } 131 376 }
Note: See TracChangeset
for help on using the changeset viewer.