Changeset 15273 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration
- Timestamp:
- 07/19/17 12:55:58 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IEnabledExpressionsConfiguration.cs
r15032 r15273 17 17 } 18 18 19 public interface IEnabledExpressionsConfiguration : INamedItem { 19 public interface IReadOnlyExpressionsConfiguration : INamedItem { 20 int InExpressionCount { get; } 21 22 IReadOnlyList<string> EnabledExpressions { get; } 23 IReadOnlyDictionary<StackTypes, int> ExpressionsPerStackCount { get; } 24 } 25 26 public interface IExpressionsConfiguration : IReadOnlyExpressionsConfiguration { 20 27 event EventHandler<EnabledExpressionsChangedEventArgs> EnabledExpressionsChanged; 21 28 22 IReadOnlyList<string> EnabledExpressions { get; }23 24 29 void EnableStack(StackTypes types, bool enableDependencies = false); 25 void DisableStack(StackTypes type, bool enableDepen encies = false);30 void DisableStack(StackTypes type, bool enableDependencies = false); 26 31 void SetStack(StackTypes type, bool state, bool setDependencies = false); 27 32 void EnableExpressionOfStack(StackTypes types); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IReadonlyPushConfiguration.cs
r15032 r15273 2 2 using System.Collections.Generic; 3 3 using Base.Erc; 4 using Common;5 6 using HeuristicLab.Core;7 4 8 5 using Stack; 9 6 10 public interface IReadOnlyPushConfiguration : IItem { 7 public interface IReadOnlyPushConfiguration : IReadOnlyExpressionsConfiguration { 8 int Seed { get; } 11 9 int EvalPushLimit { get; } 12 10 int MaxDepth { get; } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfigurationBase.cs
r15189 r15273 12 12 13 13 [StorableClass] 14 public abstract class PushConfigurationBase : NamedItem, IE nabledExpressionsConfiguration {14 public abstract class PushConfigurationBase : NamedItem, IExpressionsConfiguration { 15 15 16 16 protected PushConfigurationBase() { … … 28 28 enabledExpressions = origin.EnabledExpressions.ToList(); 29 29 expressionsPerStackCount = origin.expressionsPerStackCount.ToDictionary(x => x.Key, x => x.Value); 30 } 30 InExpressionCount = origin.InExpressionCount; 31 Seed = origin.Seed; 32 } 33 34 [Storable] 35 public int Seed { get; set; } 36 37 [Storable] 38 public int InExpressionCount { get; private set; } 31 39 32 40 [Storable] 33 41 private readonly Dictionary<StackTypes, int> expressionsPerStackCount; 42 43 public IReadOnlyDictionary<StackTypes, int> ExpressionsPerStackCount { get { return expressionsPerStackCount; } } 34 44 35 45 public event EventHandler<EnabledExpressionsChangedEventArgs> EnabledExpressionsChanged; … … 112 122 113 123 private void EnableExpressions(IEnumerable<string> expressionNames) { 114 foreach (var expressionName in expressionNames.Except(EnabledExpressions)) 124 var addedExpressions = expressionNames as IList<string> ?? expressionNames.ToList(); 125 126 foreach (var expressionName in addedExpressions.Except(EnabledExpressions)) 115 127 EnableExpression(expressionName, false); 116 128 117 129 if (EnabledExpressionsChanged != null) { 118 EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs( expressionNames, new string[0]));130 EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(addedExpressions, new string[0])); 119 131 } 120 132 } … … 133 145 134 146 private void DisableExpressions(IEnumerable<string> expressionNames) { 135 foreach (var expressionName in expressionNames.Intersect(EnabledExpressions)) 147 var removedExpressions = expressionNames as IList<string> ?? expressionNames.ToList(); 148 149 foreach (var expressionName in removedExpressions.Intersect(EnabledExpressions)) 136 150 DisableExpression(expressionName, false); 137 151 138 152 if (EnabledExpressionsChanged != null) { 139 EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(new string[0], expressionNames));153 EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(new string[0], removedExpressions)); 140 154 } 141 155 } … … 229 243 else DisableStack(type, setDependencies); 230 244 } 245 246 public void InitInExpressions(int totalInputArgumentCount) { 247 InExpressionCount = totalInputArgumentCount; 248 249 for (var i = 0; i < ExpressionTable.InExpressionTable.Count; i++) { 250 var expression = ExpressionTable.InExpressionTable[i]; 251 var expressionName = ExpressionTable.TypeToNameTable[expression.GetType()]; 252 253 DisableExpression(expressionName); 254 } 255 256 if (totalInputArgumentCount > ExpressionTable.InExpressionTable.Count) 257 throw new InvalidOperationException("More input arguments defined as InExpression types"); 258 259 for (var i = 0; i < totalInputArgumentCount; i++) { 260 var expression = ExpressionTable.InExpressionTable[i]; 261 var expressionName = ExpressionTable.TypeToNameTable[expression.GetType()]; 262 263 EnableExpression(expressionName); 264 } 265 } 231 266 } 232 267 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfigurationParameterCollection.cs
r15032 r15273 11 11 [StorableClass] 12 12 public class PushConfigurationParameterCollection : PushConfigurationBase, IReadOnlyPushConfiguration { 13 private const string I nstructionsParameterName= "Instructions";14 private const string I nstructionsParameterDescription= "Enables/Disables Instructions";15 private const string E valPushLimitParameterName= "EvalPushLimit";16 private const string E valPushLimitParameterDescription= "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 M axPointsInProgramParameterName= "MaxProgramLength";18 private const string M axProgramLengthParameterDescription= "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 T opLevelPushCodeParameterName= "TopLevelPushCode";20 private const string T opLevelPushCodeParameterDescription= "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 T opLevelPopCodeParameterName= "TopLevelPopCode";22 private const string T opLevelPopCodeParameterDescription= "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 M axPointsInRandomInstructionParameterName= "MaxPointsInRandomInstruction";24 private const string M axPointsInRandomInstructionParameterDescription= "MaxPointsInRandomInstruction";25 private const string E rcOptionsParameterName= "ERC options";26 private const string M axStringLengthParameterName= "Max. string length";27 private const string M axDepthParameterName= "Max. program recursion";28 private const string M axParenthesesCloseParameterName= "Max. parentheses close";29 private const string M axParenthesesCloseParameterDescription= "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 P arenthesesCloseBiasLevelParameterName= "Parentheses close bias level";31 private const string P arenthesesCloseBiasLevelParameterDescription= "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 M axVectorLengthParameterName= "Max. vector length";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 MAX_POINTS_IN_PROGRAM_PARAMETER_NAME = "MaxProgramLength"; 18 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."; 19 private const string TOP_LEVEL_PUSH_CODE_PARAMETER_NAME = "TopLevelPushCode"; 20 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."; 21 private const string TOP_LEVEL_POP_CODE_PARAMETER_NAME = "TopLevelPopCode"; 22 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."; 23 private const string MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME = "MaxPointsInRandomInstruction"; 24 private const string MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_DESCRIPTION = "MaxPointsInRandomInstruction"; 25 private const string ERC_OPTIONS_PARAMETER_NAME = "ERC options"; 26 private const string MAX_STRING_LENGTH_PARAMETER_NAME = "Max. string length"; 27 private const string MAX_DEPTH_PARAMETER_NAME = "Max. program recursion"; 28 private const string MAX_PARENTHESES_CLOSE_PARAMETER_NAME = "Max. parentheses close"; 29 private const string MAX_PARENTHESES_CLOSE_PARAMETER_DESCRIPTION = "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 PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_NAME = "Parentheses close bias level"; 31 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."; 32 private const string MAX_VECTOR_LENGTH_PARAMETER_NAME = "Max. vector length"; 33 33 34 34 public PushConfigurationParameterCollection() { … … 62 62 63 63 private void InitParameters() { 64 if (!Parameters.ContainsKey(I nstructionsParameterName))65 Parameters.Add(new ValueParameter<IE nabledExpressionsConfiguration>(66 I nstructionsParameterName,67 I nstructionsParameterDescription,64 if (!Parameters.ContainsKey(INSTRUCTIONS_PARAMETER_NAME)) 65 Parameters.Add(new ValueParameter<IExpressionsConfiguration>( 66 INSTRUCTIONS_PARAMETER_NAME, 67 INSTRUCTIONS_PARAMETER_DESCRIPTION, 68 68 this)); 69 69 70 if (!Parameters.ContainsKey(E rcOptionsParameterName))71 Parameters.Add(new ValueParameter<ErcOptions>(E rcOptionsParameterName));72 73 if (!Parameters.ContainsKey(M axVectorLengthParameterName))74 Parameters.Add(new FixedValueParameter<IntValue>( 75 M axVectorLengthParameterName,70 if (!Parameters.ContainsKey(ERC_OPTIONS_PARAMETER_NAME)) 71 Parameters.Add(new ValueParameter<ErcOptions>(ERC_OPTIONS_PARAMETER_NAME)); 72 73 if (!Parameters.ContainsKey(MAX_VECTOR_LENGTH_PARAMETER_NAME)) 74 Parameters.Add(new FixedValueParameter<IntValue>( 75 MAX_VECTOR_LENGTH_PARAMETER_NAME, 76 76 new IntValue(500)) { Hidden = true }); 77 77 78 if (!Parameters.ContainsKey(E valPushLimitParameterName))79 Parameters.Add(new FixedValueParameter<IntValue>( 80 E valPushLimitParameterName,81 E valPushLimitParameterDescription,78 if (!Parameters.ContainsKey(EVAL_PUSH_LIMIT_PARAMETER_NAME)) 79 Parameters.Add(new FixedValueParameter<IntValue>( 80 EVAL_PUSH_LIMIT_PARAMETER_NAME, 81 EVAL_PUSH_LIMIT_PARAMETER_DESCRIPTION, 82 82 new IntValue(1000))); 83 83 84 if (!Parameters.ContainsKey(M axPointsInProgramParameterName))85 Parameters.Add(new FixedValueParameter<IntValue>( 86 M axPointsInProgramParameterName,87 M axProgramLengthParameterDescription,84 if (!Parameters.ContainsKey(MAX_POINTS_IN_PROGRAM_PARAMETER_NAME)) 85 Parameters.Add(new FixedValueParameter<IntValue>( 86 MAX_POINTS_IN_PROGRAM_PARAMETER_NAME, 87 MAX_PROGRAM_LENGTH_PARAMETER_DESCRIPTION, 88 88 new IntValue(200))); 89 89 90 if (!Parameters.ContainsKey(M axParenthesesCloseParameterName))91 Parameters.Add(new FixedValueParameter<IntValue>( 92 M axParenthesesCloseParameterName,93 M axParenthesesCloseParameterDescription,90 if (!Parameters.ContainsKey(MAX_PARENTHESES_CLOSE_PARAMETER_NAME)) 91 Parameters.Add(new FixedValueParameter<IntValue>( 92 MAX_PARENTHESES_CLOSE_PARAMETER_NAME, 93 MAX_PARENTHESES_CLOSE_PARAMETER_DESCRIPTION, 94 94 new IntValue(4)) { Hidden = true }); 95 95 96 if (!Parameters.ContainsKey(P arenthesesCloseBiasLevelParameterName))96 if (!Parameters.ContainsKey(PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_NAME)) 97 97 Parameters.Add(new FixedValueParameter<DoubleValue>( 98 P arenthesesCloseBiasLevelParameterName,99 P arenthesesCloseBiasLevelParameterDescription,98 PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_NAME, 99 PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_DESCRIPTION, 100 100 new DoubleValue(4)) { Hidden = true }); 101 101 102 if (!Parameters.ContainsKey(T opLevelPushCodeParameterName))102 if (!Parameters.ContainsKey(TOP_LEVEL_PUSH_CODE_PARAMETER_NAME)) 103 103 Parameters.Add(new FixedValueParameter<BoolValue>( 104 T opLevelPushCodeParameterName,105 T opLevelPushCodeParameterDescription,104 TOP_LEVEL_PUSH_CODE_PARAMETER_NAME, 105 TOP_LEVEL_PUSH_CODE_PARAMETER_DESCRIPTION, 106 106 new BoolValue(true)) { Hidden = true }); 107 107 108 if (!Parameters.ContainsKey(T opLevelPopCodeParameterName))108 if (!Parameters.ContainsKey(TOP_LEVEL_POP_CODE_PARAMETER_NAME)) 109 109 Parameters.Add(new FixedValueParameter<BoolValue>( 110 T opLevelPopCodeParameterName,111 T opLevelPopCodeParameterDescription,110 TOP_LEVEL_POP_CODE_PARAMETER_NAME, 111 TOP_LEVEL_POP_CODE_PARAMETER_DESCRIPTION, 112 112 new BoolValue(false)) { Hidden = true }); 113 113 114 if (!Parameters.ContainsKey(M axPointsInRandomInstructionParameterName))115 Parameters.Add(new FixedValueParameter<IntValue>( 116 M axPointsInRandomInstructionParameterName,117 M axPointsInRandomInstructionParameterDescription,114 if (!Parameters.ContainsKey(MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME)) 115 Parameters.Add(new FixedValueParameter<IntValue>( 116 MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME, 117 MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_DESCRIPTION, 118 118 new IntValue(50)) { Hidden = true }); 119 119 120 if (!Parameters.ContainsKey(M axStringLengthParameterName))121 Parameters.Add(new FixedValueParameter<IntValue>( 122 M axStringLengthParameterName,120 if (!Parameters.ContainsKey(MAX_STRING_LENGTH_PARAMETER_NAME)) 121 Parameters.Add(new FixedValueParameter<IntValue>( 122 MAX_STRING_LENGTH_PARAMETER_NAME, 123 123 new IntValue(1000)) { Hidden = true }); 124 124 125 if (!Parameters.ContainsKey(M axDepthParameterName))126 Parameters.Add(new FixedValueParameter<IntValue>( 127 M axDepthParameterName,125 if (!Parameters.ContainsKey(MAX_DEPTH_PARAMETER_NAME)) 126 Parameters.Add(new FixedValueParameter<IntValue>( 127 MAX_DEPTH_PARAMETER_NAME, 128 128 new IntValue(1000)) { Hidden = true }); 129 129 } 130 130 131 public IValueParameter<IE nabledExpressionsConfiguration> InstructionsParameter132 { 133 get { return (IValueParameter<IE nabledExpressionsConfiguration>)Parameters[InstructionsParameterName]; }134 } 135 136 public IE nabledExpressionsConfiguration Instructions131 public IValueParameter<IExpressionsConfiguration> InstructionsParameter 132 { 133 get { return (IValueParameter<IExpressionsConfiguration>)Parameters[INSTRUCTIONS_PARAMETER_NAME]; } 134 } 135 136 public IExpressionsConfiguration Instructions 137 137 { 138 138 get { return InstructionsParameter.Value; } … … 142 142 public IValueParameter<ErcOptions> ErcOptionsParameter 143 143 { 144 get { return (IValueParameter<ErcOptions>)Parameters[E rcOptionsParameterName]; }144 get { return (IValueParameter<ErcOptions>)Parameters[ERC_OPTIONS_PARAMETER_NAME]; } 145 145 } 146 146 … … 181 181 public IValueParameter<IntValue> EvalPushLimitParameter 182 182 { 183 get { return (IValueParameter<IntValue>)Parameters[E valPushLimitParameterName]; }183 get { return (IValueParameter<IntValue>)Parameters[EVAL_PUSH_LIMIT_PARAMETER_NAME]; } 184 184 } 185 185 … … 198 198 public IValueParameter<DoubleValue> ParenthesesCloseBiasLevelParameter 199 199 { 200 get { return (IValueParameter<DoubleValue>)Parameters[P arenthesesCloseBiasLevelParameterName]; }200 get { return (IValueParameter<DoubleValue>)Parameters[PARENTHESES_CLOSE_BIAS_LEVEL_PARAMETER_NAME]; } 201 201 } 202 202 … … 212 212 public IValueParameter<IntValue> MaxParenthesesCloseParameter 213 213 { 214 get { return (IValueParameter<IntValue>)Parameters[M axParenthesesCloseParameterName]; }214 get { return (IValueParameter<IntValue>)Parameters[MAX_PARENTHESES_CLOSE_PARAMETER_NAME]; } 215 215 } 216 216 … … 229 229 public IValueParameter<IntValue> MaxDepthParameter 230 230 { 231 get { return (IValueParameter<IntValue>)Parameters[M axDepthParameterName]; }231 get { return (IValueParameter<IntValue>)Parameters[MAX_DEPTH_PARAMETER_NAME]; } 232 232 } 233 233 … … 249 249 public IValueParameter<IntValue> MaxPointsInProgramParameter 250 250 { 251 get { return (IValueParameter<IntValue>)Parameters[M axPointsInProgramParameterName]; }251 get { return (IValueParameter<IntValue>)Parameters[MAX_POINTS_IN_PROGRAM_PARAMETER_NAME]; } 252 252 } 253 253 … … 263 263 public IValueParameter<IntValue> MaxVectorLengthParameter 264 264 { 265 get { return (IValueParameter<IntValue>)Parameters[M axVectorLengthParameterName]; }265 get { return (IValueParameter<IntValue>)Parameters[MAX_VECTOR_LENGTH_PARAMETER_NAME]; } 266 266 } 267 267 … … 277 277 public IValueParameter<IntValue> MaxPointsInRandomExpressionParameter 278 278 { 279 get { return (IValueParameter<IntValue>)Parameters[M axPointsInRandomInstructionParameterName]; }279 get { return (IValueParameter<IntValue>)Parameters[MAX_POINTS_IN_RANDOM_INSTRUCTION_PARAMETER_NAME]; } 280 280 } 281 281 … … 295 295 public IValueParameter<BoolValue> TopLevelPushCodeParameter 296 296 { 297 get { return (IValueParameter<BoolValue>)Parameters[T opLevelPushCodeParameterName]; }297 get { return (IValueParameter<BoolValue>)Parameters[TOP_LEVEL_PUSH_CODE_PARAMETER_NAME]; } 298 298 } 299 299 … … 312 312 public IValueParameter<BoolValue> TopLevelPopCodeParameter 313 313 { 314 get { return (IValueParameter<BoolValue>)Parameters[T opLevelPopCodeParameterName]; }314 get { return (IValueParameter<BoolValue>)Parameters[TOP_LEVEL_POP_CODE_PARAMETER_NAME]; } 315 315 } 316 316 … … 326 326 public IValueParameter<IntValue> MaxStringLengthParameter 327 327 { 328 get { return (IValueParameter<IntValue>)Parameters[M axStringLengthParameterName]; }328 get { return (IValueParameter<IntValue>)Parameters[MAX_STRING_LENGTH_PARAMETER_NAME]; } 329 329 } 330 330
Note: See TracChangeset
for help on using the changeset viewer.