- Timestamp:
- 08/21/17 11:33:53 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP
- Files:
-
- 1 added
- 1 deleted
- 52 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/Analyzer/IndividualZeroErrorAnalyzer.cs
r15289 r15334 23 23 private const string RESULT_PARAMETER_NAME = "Zero Error Individuals Per Case"; 24 24 private const string RESULT_PARAMETER_DESCRIPTION = "Relative frequency of instructions aggregated over the whole population."; 25 private const string Y_AXIS_TITLE = " Count of zero error individuals";25 private const string Y_AXIS_TITLE = "Relative count of zero error individuals"; 26 26 private const string X_AXIS_TITLE = "Case Nr"; 27 27 private const string ROW_NAME = "Cases"; … … 134 134 YAxisMaximumFixedValue = 1, 135 135 YAxisMinimumAuto = false, 136 SecondYAxisMaximumAuto = false,136 YAxisMaximumAuto = false, 137 137 XAxisMinimumFixedValue = 1, 138 138 XAxisMaximumFixedValue = caseCount, -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Attributes/PushExpressionAttriubte.cs
r15273 r15334 20 20 /// Determines the amount of items fetched form the EXEC stack required for this expression. Used for mapping individuals. 21 21 /// </summary> 22 public readonly uint ExecIn;22 public readonly uint RequiredBlockCount; 23 23 24 24 /// <summary> … … 32 32 string description, 33 33 StackTypes additionalStackDependencies = default(StackTypes), 34 uint execIn= 0,34 uint requiredBlockCount = 0, 35 35 bool isHidden = false, 36 36 int inExpressionNr = -1) { … … 40 40 Name = name; 41 41 Description = description; 42 ExecIn = execIn;42 RequiredBlockCount = requiredBlockCount; 43 43 IsHidden = isHidden; 44 44 InExpressionNr = inExpressionNr > 0 ? inExpressionNr : default(int?); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IReadonlyPushConfiguration.cs
r15289 r15334 9 9 int MaxStringLength { get; } 10 10 int MaxVectorLength { get; } 11 int MaxP ointsInProgram{ get; }11 int MaxProgramLength { get; } 12 12 int MaxPointsInRandomExpression { get; } 13 13 bool TopLevelPushCode { get; } 14 14 bool TopLevelPopCode { get; } 15 int Max ParenthesesClose { get; }16 double ParenthesesCloseBiasLevel { get; }15 int MaxClose { get; } 16 double CloseBiasLevel { get; } 17 17 IReadOnlyErcOptions ErcOptions { get; } 18 18 string FloatStringFormat { get; } 19 bool TopLevelPushInputArguments { get; } 19 20 20 21 bool IsStackEnabled(StackTypes stackType); -
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 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Crossover/AlternationCrossover.cs
r15289 r15334 31 31 ChildParameter.ActualName = "PlushVector"; 32 32 33 Parameters.Add(new LookupParameter<IntValue>("MaxProgramLength", "The max length of children")); 34 33 35 Parameters.Add(new FixedValueParameter<PercentValue>("AlternationRate", "Specifies the probability of switching to another parent.", new PercentValue(0.5))); 34 36 Parameters.Add(new FixedValueParameter<DoubleValue>("AlignmentDeviation", "When alternating between parents, the index at which to continue copying may be offset backward or forward some amount based on a random sample from a normal distribution with mean 0 and standard deviation set by the alignment deviation parameter", new DoubleValue(1.0))); 35 Parameters.Add(new FixedValueParameter<IntValue>("MaxLength", "The max length of a children", new IntValue(100))); 37 36 38 } 37 39 … … 47 49 } 48 50 49 public I ValueParameter<IntValue> MaxLengthParameter51 public ILookupParameter<IntValue> MaxProgramLengthParameter 50 52 { 51 get { return (I ValueParameter<IntValue>)Parameters["MaxLength"]; }53 get { return (ILookupParameter<IntValue>)Parameters["MaxProgramLength"]; } 52 54 } 53 55 54 public int Max Length56 public int MaxProgramLength 55 57 { 56 get { return Max LengthParameter.Value.Value; }57 set { Max LengthParameter.Value.Value = value; }58 get { return MaxProgramLengthParameter.ActualValue.Value; } 59 set { MaxProgramLengthParameter.ActualValue.Value = value; } 58 60 } 59 61 … … 98 100 ParentsParameter.ActualValue, 99 101 AlternationRate, 100 Max Length,102 MaxProgramLength, 101 103 AlignmentDeviation); 102 104 return base.InstrumentedApply(); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/IPooledObject.cs
r15189 r15334 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool { 2 2 public interface IPooledObject { 3 void Init();4 3 void Reset(); 5 4 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/ManagedPoolProvider.cs
r15189 r15334 7 7 using System.Reflection; 8 8 using System.Runtime.Serialization.Formatters.Binary; 9 10 using Microsoft.IO; 9 11 10 12 public interface IManagedPool<T> : IDisposable where T : class, IPooledObject { … … 17 19 private readonly ObjectPool<IManagedPool<T>> managedPools; 18 20 private readonly BinaryFormatter binaryFormatter = new BinaryFormatter(); 21 private readonly RecyclableMemoryStreamManager recyclableMemoryStreamManager = new RecyclableMemoryStreamManager(); 19 22 private byte[] dummyPartition; 20 private staticvolatile object dummyCreationLockObject = new object();23 private volatile object dummyCreationLockObject = new object(); 21 24 22 25 private static readonly FieldInfo InternalListArrayProperty = typeof(List<T[]>).GetField( … … 56 59 57 60 private T[] CloneDummyPartition() { 61 // init dummy partition 58 62 if (dummyPartition == null) { 59 63 lock (dummyCreationLockObject) { … … 65 69 } 66 70 67 using (var m emoryStream = new MemoryStream()) {68 binaryFormatter.Serialize(m emoryStream, temp);69 dummyPartition = m emoryStream.ToArray();71 using (var ms = recyclableMemoryStreamManager.GetStream("dummyPartition")) { 72 binaryFormatter.Serialize(ms, temp); 73 dummyPartition = ms.ToArray(); 70 74 } 71 75 } … … 73 77 } 74 78 75 using (var memoryStream = new MemoryStream(dummyPartition)) { 76 memoryStream.Seek(0, SeekOrigin.Begin); 77 78 var result = (T[])binaryFormatter.Deserialize(memoryStream); 79 80 for (var i = 0; i < result.Length; i++) 81 result[i].Init(); 82 79 using (var ms = recyclableMemoryStreamManager.GetStream("dummyPartition", dummyPartition, 0, dummyPartition.Length)) { 80 ms.Seek(0, SeekOrigin.Begin); 81 var result = (T[])binaryFormatter.Deserialize(ms); 83 82 return result; 84 83 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/PooledList.cs
r15189 r15334 6 6 [Serializable] 7 7 public class PooledList<T> : List<T>, IPooledObject { 8 public Guid Id { get; private set; }9 10 void IPooledObject.Init() {11 Id = Guid.NewGuid();12 }13 8 14 9 void IPooledObject.Reset() { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/PooledObject.cs
r15189 r15334 20 20 } 21 21 22 void IPooledObject.Init() { }23 24 22 public void Reset() { 25 23 resetor(item); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Encoding/PlushEncoding.cs
r15289 r15334 27 27 minLengthParameter = new FixedValueParameter<IntValue>(Name + ".MinLength", new IntValue(25)); 28 28 maxLengthParameter = new FixedValueParameter<IntValue>(Name + ".MaxLength", new IntValue(100)); 29 minCloseParameter = new FixedValueParameter<IntValue>(Name + ".MinClose", new IntValue(0));30 29 maxCloseParameter = new FixedValueParameter<IntValue>(Name + ".MaxClose", new IntValue(3)); 31 30 closeBiasLevelParameter = new FixedValueParameter<DoubleValue>(Name + ".CloseBiasLevel", new DoubleValue(3d)); 32 31 instructionsParameter = new ValueParameter<IExpressionsConfiguration>(Name + ".Instructions"); 33 32 ercOptionsParameter = new ValueParameter<ErcOptions>(Name + ".ErcOptions"); 34 inInstructionProbabilityParameter = new FixedValueParameter<PercentValue>(Name + ".InInstructionProbability" );33 inInstructionProbabilityParameter = new FixedValueParameter<PercentValue>(Name + ".InInstructionProbability", new PercentValue(0.1)); 35 34 36 35 Parameters.Add(minLengthParameter); 37 36 Parameters.Add(maxLengthParameter); 38 Parameters.Add(minCloseParameter);39 37 Parameters.Add(maxCloseParameter); 40 38 Parameters.Add(closeBiasLevelParameter); … … 78 76 ConfigureOperators(Operators); 79 77 } 80 private void OnMinCloseParameterChanged() {81 RegisterMinCloseParameterEvents();82 ConfigureOperators(Operators);83 }84 78 private void OnMaxCloseParameterChanged() { 85 79 RegisterMaxCloseParameterEvents(); … … 106 100 RegisterMinLengthParameterEvents(); 107 101 RegisterMaxLengthParameterEvents(); 108 RegisterMinCloseParameterEvents();109 102 RegisterMaxCloseParameterEvents(); 110 103 RegisterCloseBiasLevelParameterEvents(); … … 124 117 } 125 118 126 private void RegisterMinCloseParameterEvents() {127 MinCloseParameter.ValueChanged += (o, s) => ConfigureOperators(Operators);128 MinCloseParameter.Value.ValueChanged += (o, s) => ConfigureOperators(Operators);129 }130 131 119 private void RegisterMaxCloseParameterEvents() { 132 120 MaxCloseParameter.ValueChanged += (o, s) => ConfigureOperators(Operators); … … 156 144 #region Encoding Parameters 157 145 [Storable] 158 private I FixedValueParameter<IntValue> minLengthParameter;159 public I FixedValueParameter<IntValue> MinLengthParameter146 private IValueParameter<IntValue> minLengthParameter; 147 public IValueParameter<IntValue> MinLengthParameter 160 148 { 161 149 get { return minLengthParameter; } … … 174 162 175 163 [Storable] 176 private I FixedValueParameter<IntValue> maxLengthParameter;177 public I FixedValueParameter<IntValue> MaxLengthParameter164 private IValueParameter<IntValue> maxLengthParameter; 165 public IValueParameter<IntValue> MaxLengthParameter 178 166 { 179 167 get { return maxLengthParameter; } … … 192 180 193 181 [Storable] 194 private IFixedValueParameter<IntValue> minCloseParameter; 195 public IFixedValueParameter<IntValue> MinCloseParameter 196 { 197 get { return minCloseParameter; } 198 set 199 { 200 if (value == null) throw new ArgumentNullException("Min close parameter must not be null."); 201 if (value.Value == null) throw new ArgumentNullException("Min close parameter value must not be null."); 202 if (minCloseParameter == value) return; 203 204 if (minCloseParameter != null) Parameters.Remove(minCloseParameter); 205 minCloseParameter = value; 206 Parameters.Add(minCloseParameter); 207 OnMinCloseParameterChanged(); 208 } 209 } 210 211 [Storable] 212 private IFixedValueParameter<IntValue> maxCloseParameter; 213 public IFixedValueParameter<IntValue> MaxCloseParameter 182 private IValueParameter<IntValue> maxCloseParameter; 183 public IValueParameter<IntValue> MaxCloseParameter 214 184 { 215 185 get { return maxCloseParameter; } … … 228 198 229 199 [Storable] 230 private I FixedValueParameter<DoubleValue> closeBiasLevelParameter;231 public I FixedValueParameter<DoubleValue> CloseBiasLevelParameter200 private IValueParameter<DoubleValue> closeBiasLevelParameter; 201 public IValueParameter<DoubleValue> CloseBiasLevelParameter 232 202 { 233 203 get { return closeBiasLevelParameter; } … … 246 216 247 217 [Storable] 248 private I FixedValueParameter<PercentValue> inInstructionProbabilityParameter;249 public I FixedValueParameter<PercentValue> InInstructionProbabilityParameter218 private IValueParameter<PercentValue> inInstructionProbabilityParameter; 219 public IValueParameter<PercentValue> InInstructionProbabilityParameter 250 220 { 251 221 get { return inInstructionProbabilityParameter; } … … 321 291 } 322 292 323 public int MinClose324 {325 get { return MinCloseParameter.Value.Value; }326 set { MinCloseParameter.Value.Value = value; }327 }328 329 293 public int MaxClose 330 294 { … … 341 305 342 306 #region Operator Discovery 343 private static readonly IEnumerable<Type> encodingSpecificOperatorTypes;307 private static readonly IEnumerable<Type> EncodingSpecificOperatorTypes; 344 308 static PlushEncoding() { 345 encodingSpecificOperatorTypes = new List<Type>() {309 EncodingSpecificOperatorTypes = new List<Type>() { 346 310 typeof (IPlushOperator), 347 311 typeof (IPlushCreator), … … 353 317 private void DiscoverOperators() { 354 318 var assembly = typeof(IPlushOperator).Assembly; 355 var discoveredTypes = ApplicationManager.Manager.GetTypes( encodingSpecificOperatorTypes, assembly, true, false, false);319 var discoveredTypes = ApplicationManager.Manager.GetTypes(EncodingSpecificOperatorTypes, assembly, true, false, false); 356 320 var operators = discoveredTypes.Select(t => (IOperator)Activator.CreateInstance(t)); 357 321 var newOperators = operators.Except(Operators, new TypeEqualityComparer<IOperator>()).ToList(); … … 374 338 creator.MinLengthParameter.ActualName = MinLengthParameter.Name; 375 339 creator.MaxLengthParameter.ActualName = MaxLengthParameter.Name; 376 creator.MinCloseParameter.ActualName = MinCloseParameter.Name; 377 creator.MaxCloseParameter.ActualName = MinCloseParameter.Name; 340 creator.MaxCloseParameter.ActualName = MaxCloseParameter.Name; 378 341 creator.CloseBiasLevelParameter.ActualName = CloseBiasLevelParameter.Name; 379 342 creator.ErcOptionsParameter.ActualName = ErcOptionsParameter.Name; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Encoding/PlushEntry.cs
r15275 r15334 9 9 public PlushEntry() { } 10 10 11 public PlushEntry(Expression instruction = null, int close = 0, bool silent = false) { 12 Instruction = instruction; 13 Close = close; 14 Silent = silent; 15 } 16 17 [StorableConstructor] 11 18 public PlushEntry(bool deserializing) : base(deserializing) { } 12 19 … … 14 21 Instruction = cloner.Clone(origin.Instruction); 15 22 Close = origin.Close; 23 Silent = origin.Silent; 16 24 } 17 25 … … 20 28 [Storable] 21 29 public int Close { get; set; } 30 [Storable] 31 public bool Silent { get; set; } 22 32 23 33 public override IDeepCloneable Clone(Cloner cloner) { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Encoding/PlushVector.cs
r15289 r15334 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Encoding { 2 2 using System.Collections.Generic; 3 4 3 using HeuristicLab.Common; 5 4 using HeuristicLab.Core; … … 9 8 10 9 [StorableClass] 11 public class PlushVector : Item {10 public sealed class PlushVector : Item { 12 11 13 12 [Storable] … … 22 21 23 22 [StorableConstructor] 24 p ublicPlushVector(bool deserializing) : base(deserializing) {23 private PlushVector(bool deserializing) : base(deserializing) { 25 24 } 26 25 27 26 public PlushVector(PlushVector origin, Cloner cloner) : base(origin, cloner) { 28 entries = new List<PlushEntry>(origin.entries); 27 entries = new List<PlushEntry>(origin.entries.Count); 28 for (var i = 0; i < origin.entries.Count; i++) { 29 entries.Add(cloner.Clone(origin.entries[i])); 30 } 31 29 32 pushProgram = origin.pushProgram; 30 33 } … … 62 65 var instructions = new List<Expression>(); 63 66 64 for (var i = currentIndex; i < entries.Count; i++) { 65 var entry = entries[i]; 67 for (; currentIndex < entries.Count; currentIndex++) { 68 var entry = entries[currentIndex]; 69 70 if (entry.Silent) 71 continue; 72 73 close += entry.Close; 74 instructions.Add(entry.Instruction); 75 76 PushExpressionAttribute attribute; 66 77 var instructionType = entry.Instruction.GetType(); 67 78 68 close += entry.Close;69 70 PushExpressionAttribute attribute;71 79 if (ExpressionTable.TypeToAttributeTable.TryGetValue(instructionType, out attribute)) { 72 for (var blockIdx = 0u; blockIdx < attribute.ExecIn && currentIndex < entries.Count; blockIdx++) { 73 if (close != 0) { 80 for (var blockIdx = 0u; blockIdx < attribute.RequiredBlockCount; blockIdx++) { 81 if (close == 0 && currentIndex < entries.Count) { 82 currentIndex++; 83 var subProgram = FromPlush(ref currentIndex, ref close, depth + 1); 84 instructions.Add(subProgram); 85 } else { 74 86 close--; 75 87 instructions.Add(PushProgram.Empty); 76 } else {77 currentIndex++;78 var subProgram = FromPlush(ref currentIndex, ref close, depth + 1);79 var subExpression = subProgram.Count == 1 ? subProgram.Expressions[0] : subProgram;80 81 instructions.Add(subExpression);82 88 } 83 89 } 84 90 } 85 86 instructions.Add(entry.Instruction);87 91 88 92 if (close > 0 && depth > 0) { … … 96 100 } 97 101 102 instructions.Reverse(); 98 103 return new PushProgram(instructions); 99 104 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Evaluator/PushBenchmarkSuiteEvaluator.cs
r15289 r15334 3 3 using System.Collections.Generic; 4 4 using System.Globalization; 5 using System.Linq; 5 6 6 7 using HeuristicLab.BenchmarkSuite; … … 9 10 using HeuristicLab.Parameters; 10 11 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 12 using HeuristicLab.Problems.ProgramSynthesis.Base.Extensions; 11 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 12 14 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; … … 18 20 public class PushBenchmarkSuiteEvaluator : ParameterizedNamedItem, IPushEvaluator { 19 21 20 private const string D ataBoundsParameterName= "DataBounds";21 private const string D ataParameterName= "Data";22 private const string D ataParameterDescription= "Program Synthesis";22 private const string DATA_BOUNDS_PARAMETER_NAME = "DataBounds"; 23 private const string DATA_PARAMETER_NAME = "Data"; 24 private const string DATA_PARAMETER_DESCRIPTION = "Program Synthesis"; 23 25 24 26 public PushBenchmarkSuiteEvaluator() { 25 Parameters.Add(new FixedValueParameter<DataBounds>(D ataBoundsParameterName));27 Parameters.Add(new FixedValueParameter<DataBounds>(DATA_BOUNDS_PARAMETER_NAME)); 26 28 27 29 Parameters.Add(new ValueParameter<ProblemData>( 28 D ataParameterName,29 D ataParameterDescription));30 DATA_PARAMETER_NAME, 31 DATA_PARAMETER_DESCRIPTION)); 30 32 } 31 33 … … 47 49 public IValueParameter<ProblemData> DataParameter 48 50 { 49 get { return (IValueParameter<ProblemData>)Parameters[D ataParameterName]; }51 get { return (IValueParameter<ProblemData>)Parameters[DATA_PARAMETER_NAME]; } 50 52 } 51 53 … … 58 60 public IValueParameter<DataBounds> DataBoundsParameter 59 61 { 60 get { return (IValueParameter<DataBounds>)Parameters[D ataBoundsParameterName]; }62 get { return (IValueParameter<DataBounds>)Parameters[DATA_BOUNDS_PARAMETER_NAME]; } 61 63 } 62 64 … … 131 133 132 134 switch (Data.ProblemType) { 135 // special 133 136 case ProblemType.NumberIO: return NumberIo(interpreter, example); 134 case ProblemType.Median: return Median(interpreter, example); 137 case ProblemType.StringDifferences: return StringDifferences(interpreter, example); 138 case ProblemType.EvenSquares: return EvenSquares(interpreter, example); 139 case ProblemType.WallisPi: return WallisPi(interpreter, example); 140 case ProblemType.VectorSummed: return VectorsSummed(interpreter, example); 141 case ProblemType.XWordLines: return XWordLines(interpreter, example); 142 case ProblemType.NegativeToZero: return NegativeToZero(interpreter, example); 143 case ProblemType.WordStats: return WordStats(interpreter, example); 144 case ProblemType.Checksum: return Checksum(interpreter, example); 145 case ProblemType.Grades: return Grade(interpreter, example); 146 case ProblemType.Syllables: return Syllables(interpreter, example); 147 148 // printed string right/wrong 149 case ProblemType.Smallest: 150 case ProblemType.Median: return PrintedStringRight(interpreter, example); 151 152 // boolean error 153 case ProblemType.MirrorImage: 154 case ProblemType.SuperAnagrams: 155 case ProblemType.CompareStringLengths: return GetDiff(example.OutputBoolean, interpreter.BooleanStack, Data.WorstResult, BooleanDiffer); 156 157 // float error 158 case ProblemType.VectorAverage: return GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision)); 159 160 // integer error 161 case ProblemType.LastIndexOfZero: 162 case ProblemType.CountOdds: 163 case ProblemType.SumOfSquares: 164 case ProblemType.ScrabbleScore: 165 case ProblemType.CollatzNumbers: return GetDiff(example.OutputInteger, interpreter.IntegerStack, Data.WorstResult, IntegerDiffer); 166 167 // levenshtein distance + integer error 168 case ProblemType.ReplaceSpaceWithNewline: 169 return GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, Data.WorstResult) 170 + GetDiff(example.OutputInteger, interpreter.IntegerStack, Data.WorstResult, IntegerDiffer); 171 172 // printed levenshtein distance 173 case ProblemType.ForLoopIndex: 174 case ProblemType.DoubleLetters: 175 case ProblemType.StringLengthsBackwards: 176 case ProblemType.PigLatin: 177 case ProblemType.Digits: 178 case ProblemType.SmallOrLarge: return GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, Data.WorstResult); 135 179 } 136 180 … … 163 207 } 164 208 165 private double Median(IPushInterpreter interpreter, Example example) { 166 return interpreter.PrintStack.IsEmpty || !interpreter.PrintStack.ToString().Equals(example.OutputPrint) ? 1 : 0; 209 private double PrintedStringRight(IPushInterpreter interpreter, Example example) { 210 return interpreter.PrintStack.IsEmpty || 211 !interpreter.PrintStack.ToString().Equals(example.OutputPrint) 212 ? 1 213 : 0; 167 214 } 168 215 169 216 private double NumberIo(IPushInterpreter interpreter, Example example) { 170 if ( interpreter.PrintStack.IsEmpty)217 if (!string.IsNullOrEmpty(example.OutputPrint) && interpreter.PrintStack.IsEmpty) 171 218 return Data.WorstResult; 172 219 … … 176 223 if (double.TryParse(printResult, NumberStyles.Number | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out value)) { 177 224 var diff = Math.Abs(example.OutputFloat[0] - value); 178 var result= Math.Min(diff, Data.WorstResult);179 180 return result;225 diff = Math.Min(diff, Data.WorstResult); 226 227 return diff; 181 228 } 182 229 … … 187 234 Data.WorstResult); 188 235 189 return levenshteinDistance + penaltyError; 236 var result = levenshteinDistance + penaltyError; 237 return Math.Min(result, Data.WorstResult); 238 } 239 240 private double StringDifferences(IPushInterpreter interpreter, Example example) { 241 if (string.IsNullOrEmpty(example.OutputPrint) && interpreter.PrintStack.IsEmpty) { 242 return 0.0; 243 } 244 245 if (!string.IsNullOrEmpty(example.OutputPrint) && interpreter.PrintStack.IsEmpty) { 246 return Data.WorstResult; 247 } 248 249 var printResult = interpreter.PrintStack.ToString(); 250 var distance = example.OutputPrint.LevenshteinDistance(printResult); 251 var lineCountWithCorrectFormat = interpreter.PrintStack.AsStrings().Count(line => { 252 var parts = line.Split(' '); 253 254 if (parts.Length != 3) 255 return false; 256 257 var part0 = parts[0].Trim(); 258 if (part0.Length == 0 || !part0.IsNumeric()) 259 return false; 260 261 var part1 = parts[1].Trim(); 262 if (part1.Length != 1) 263 return false; 264 265 var part2 = parts[2].Trim(); 266 if (part2.Length != 1) 267 return false; 268 269 return true; 270 }); 271 272 var lineCountWithInvalidFormat = example.OutputPrintLineCount - lineCountWithCorrectFormat; 273 lineCountWithInvalidFormat = Math.Min(lineCountWithInvalidFormat, example.OutputPrintLineCount); 274 275 var result = distance + lineCountWithInvalidFormat; 276 return Math.Min(result, Data.WorstResult); 277 } 278 279 private double EvenSquares(IPushInterpreter interpreter, Example example) { 280 if (string.IsNullOrEmpty(example.OutputPrint) && interpreter.PrintStack.IsEmpty) { 281 return 0.0; 282 } 283 284 if (!string.IsNullOrEmpty(example.OutputPrint) && interpreter.PrintStack.IsEmpty) { 285 return Data.WorstResult; 286 } 287 288 var distance = example.OutputPrint.LevenshteinDistance(interpreter.PrintStack.ToString()); 289 var printLines = interpreter.PrintStack.AsStrings().ToArray(); 290 var lineCountWithCorrectFormat = printLines.Count(line => line.IsNumeric()); 291 var lineCountWithInvalidFormat = example.OutputPrintLineCount - lineCountWithCorrectFormat; 292 293 lineCountWithInvalidFormat = Math.Abs(Math.Min(lineCountWithInvalidFormat, example.OutputPrintLineCount)); 294 295 var compareLength = Math.Min(printLines.Length, example.OutputPrintLineCount); 296 long integerError = 0; 297 298 for (var i = 0; i < compareLength; i++) { 299 long value; 300 if (long.TryParse(printLines[i], out value)) { 301 integerError += Math.Abs(value - example.OutputIntegerVector[0][i]); 302 } else { 303 integerError += example.OutputPrintLineCount > 0 304 ? (long)(Data.WorstResult / example.OutputPrintLineCount) 305 : 0; 306 } 307 } 308 309 var result = distance + lineCountWithInvalidFormat + integerError; 310 return Math.Min(result, Data.WorstResult); 311 } 312 313 private double WallisPi(IPushInterpreter interpreter, Example example) { 314 if (interpreter.FloatStack.IsEmpty) 315 return Data.WorstResult; 316 317 var floatDiff = GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision)); 318 var expectedStr = example.OutputFloat[0].ToString(Data.FloatStringFormat, CultureInfo.CurrentCulture); 319 var resultStr = interpreter.FloatStack.TopOrDefault.ToString(Data.FloatStringFormat, CultureInfo.CurrentCulture); 320 var distance = expectedStr.LevenshteinDistance(resultStr); 321 322 var result = floatDiff + distance; 323 return Math.Min(result, Data.WorstResult); 324 } 325 326 private double VectorsSummed(IPushInterpreter interpreter, Example example) { 327 if (interpreter.IntegerVectorStack.IsEmpty && example.OutputIntegerVector.Length > 0) 328 return Data.WorstResult; 329 330 var resultVector = interpreter.IntegerVectorStack[0]; 331 var expectedVector = example.OutputIntegerVector[0]; 332 var comparableLength = Math.Min(resultVector.Count, expectedVector.Length); 333 334 // add penalty if length does not match 335 var result = expectedVector.Length > 0 336 ? (expectedVector.Length - comparableLength) * (Data.WorstResult / expectedVector.Length) 337 : 0; 338 339 for (var i = 0; i < comparableLength; i++) { 340 result += Math.Abs(resultVector[i] - expectedVector[i]); 341 } 342 343 return Math.Min(result, Data.WorstResult); 344 } 345 346 private double XWordLines(IPushInterpreter interpreter, Example example) { 347 if (string.IsNullOrEmpty(example.OutputPrint) && interpreter.PrintStack.IsEmpty) { 348 return 0.0; 349 } 350 351 if (!string.IsNullOrEmpty(example.OutputPrint) && interpreter.PrintStack.IsEmpty) 352 return Data.WorstResult; 353 354 var estimatedWordsPerLineCount = example.InputInteger[0]; 355 var estimatedWordCount = example.OutputInteger[0]; 356 var estimatedLastWordCount = estimatedWordCount - estimatedWordsPerLineCount * Math.Max(0, example.OutputPrintLineCount - 1); 357 var printResult = interpreter.PrintStack.ToString(); 358 var distance = example.OutputPrint.LevenshteinDistance(printResult); 359 var lineCount = interpreter.PrintStack.Count; 360 var lineCountError = Math.Abs(example.OutputPrintLineCount - lineCount); 361 var totalWordsPerLineError = 0L; 362 363 for (var i = 0; i < interpreter.PrintStack.Lines.Count - 1; i++) { 364 totalWordsPerLineError += Math.Abs(interpreter.PrintStack.Lines[i].Split(' ').Length - estimatedWordsPerLineCount); 365 } 366 367 // last line 368 var lastLine = interpreter.PrintStack.Lines[interpreter.PrintStack.Lines.Count - 1]; 369 totalWordsPerLineError += Math.Abs(lastLine.Split(' ').Length - estimatedLastWordCount); 370 371 var result = distance + lineCountError + totalWordsPerLineError; 372 return Math.Min(result, Data.WorstResult); 373 } 374 375 private double NegativeToZero(IPushInterpreter interpreter, Example example) { 376 if (interpreter.IntegerVectorStack.IsEmpty && example.OutputIntegerVector.Length > 0) 377 return Data.WorstResult; 378 379 var resultVector = interpreter.IntegerVectorStack.Top; 380 var expectedVector = example.OutputIntegerVector[0]; 381 var comparableLength = Math.Min(resultVector.Count, expectedVector.Length); 382 383 // add penalty if length does not match 384 var result = expectedVector.Length > 0 385 ? (expectedVector.Length - comparableLength) * (Data.WorstResult / expectedVector.Length) 386 : 0; 387 388 for (var i = 0; i < comparableLength; i++) { 389 var expectedStr = expectedVector[i].ToString(); 390 var resultStr = resultVector[i].ToString(); 391 result += expectedStr.LevenshteinDistance(resultStr); 392 } 393 394 return Math.Min(result, Data.WorstResult); 395 } 396 397 private double WordStats(IPushInterpreter interpreter, Example example) { 398 if (string.IsNullOrEmpty(example.OutputPrint) && interpreter.PrintStack.IsEmpty) { 399 return 0.0; 400 } 401 402 if (!string.IsNullOrEmpty(example.OutputPrint) && interpreter.PrintStack.IsEmpty) 403 return Data.WorstResult; 404 405 var printStr = interpreter.PrintStack.ToString(); 406 var distance = example.OutputPrint.LevenshteinDistance(printStr); 407 408 var statsError = 0.0; 409 long numberOfSentences; 410 var expectedNumberOfSentences = example.OutputInteger[0]; 411 statsError += BenchmarkSuite.Problems.WordStats.GetNumberOfSentences(printStr, out numberOfSentences) 412 ? Math.Abs(expectedNumberOfSentences - numberOfSentences) 413 : Data.WorstResult / 3.0; 414 415 double averageSentenceLength; 416 var expectedAverageSentenceLength = example.OutputFloat[0]; 417 statsError += BenchmarkSuite.Problems.WordStats.GetAverageSentenceLength(printStr, out averageSentenceLength) 418 ? Math.Abs(expectedAverageSentenceLength - averageSentenceLength) 419 : Data.WorstResult / 3.0; 420 421 var result = distance + statsError; 422 return Math.Min(result, Data.WorstResult); 423 } 424 425 private double Checksum(IPushInterpreter interpreter, Example example) { 426 if (!string.IsNullOrEmpty(example.OutputPrint) && interpreter.PrintStack.IsEmpty) 427 return Data.WorstResult; 428 429 var printStr = interpreter.PrintStack.ToString(); 430 var distance = example.OutputPrint.LevenshteinDistance(printStr); 431 432 var expectedLastCharIndex = example.OutputPrint.Length - 1; 433 var result = distance; 434 435 if (expectedLastCharIndex >= 0) { 436 var expectedLastChar = example.OutputPrint[expectedLastCharIndex]; 437 var resultLastCharIndex = printStr.Length - 1; 438 439 if (resultLastCharIndex >= 0) { 440 var resultLastChar = printStr[resultLastCharIndex]; 441 result += Math.Abs(expectedLastChar - resultLastChar); 442 } 443 } 444 445 return Math.Min(result, Data.WorstResult); 446 } 447 448 private double Syllables(IPushInterpreter interpreter, Example example) { 449 if (!string.IsNullOrEmpty(example.OutputPrint) && interpreter.PrintStack.IsEmpty) 450 return Data.WorstResult; 451 452 var printStr = interpreter.PrintStack.ToString(); 453 var distance = example.OutputPrint.LevenshteinDistance(printStr); 454 455 long numberOfSyllables; 456 var expectedNumberOfSyllables = example.OutputInteger[0]; 457 var numberOfSyllablesError = BenchmarkSuite.Problems.Syllables.GetNumberOfSyllables(printStr, out numberOfSyllables) 458 ? Math.Abs(expectedNumberOfSyllables - numberOfSyllables) 459 : Data.WorstResult / 2.0; 460 461 var result = distance + numberOfSyllablesError; 462 return Math.Min(result, Data.WorstResult); 463 } 464 465 private double Grade(IPushInterpreter interpreter, Example example) { 466 if (!string.IsNullOrEmpty(example.OutputPrint) && interpreter.PrintStack.IsEmpty) 467 return Data.WorstResult; 468 469 var printStr = interpreter.PrintStack.ToString(); 470 var distance = example.OutputPrint.LevenshteinDistance(printStr); 471 472 char grade; 473 var expectedGrade = example.OutputChar[0]; 474 var gradeError = BenchmarkSuite.Problems.Grades.GetGrade(printStr, out grade) 475 ? Math.Abs(expectedGrade - grade) 476 : Data.WorstResult / 2; 477 478 var result = distance + gradeError; 479 return Math.Min(result, Data.WorstResult); 190 480 } 191 481 … … 215 505 216 506 private static double StringDiffer(string a, string b) { 217 return LevenshteinDistance(a,b);507 return a.LevenshteinDistance(b); 218 508 } 219 509 … … 240 530 241 531 private static double GetPrintDiffer(string estimated, string printResult, double worstResult) { 242 var distance = LevenshteinDistance(estimated,printResult);532 var distance = estimated.LevenshteinDistance(printResult); 243 533 244 534 return Math.Min(distance, worstResult); … … 247 537 private static double GetPrintDiffer(string estimated, IPrintStack printStack, double worstResult) { 248 538 var printResult = printStack.ToString(); 249 var distance = LevenshteinDistance(estimated,printResult);539 var distance = estimated.LevenshteinDistance(printResult); 250 540 251 541 return Math.Min(distance, worstResult); … … 293 583 return diff; 294 584 } 295 296 /// <summary>297 /// https://www.dotnetperls.com/levenshtein298 /// </summary>299 private static int LevenshteinDistance(string source, string target) {300 if (source == null && target == null) return 0;301 if (source == null) return target.Length;302 if (target == null) return source.Length;303 304 int n = source.Length;305 int m = target.Length;306 int[,] d = new int[n + 1, m + 1];307 308 // Step 1309 if (n == 0) {310 return m;311 }312 313 if (m == 0) {314 return n;315 }316 317 // Step 2318 for (int i = 0; i <= n; d[i, 0] = i++) {319 }320 321 for (int j = 0; j <= m; d[0, j] = j++) {322 }323 324 // Step 3325 for (int i = 1; i <= n; i++) {326 //Step 4327 for (int j = 1; j <= m; j++) {328 // Step 5329 int cost = (target[j - 1] == source[i - 1]) ? 0 : 1;330 331 // Step 6332 d[i, j] = Math.Min(333 Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1),334 d[i - 1, j - 1] + cost);335 }336 }337 // Step 7338 return d[n, m];339 }340 585 } 341 586 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/CodeExpressions.cs
r15032 r15334 94 94 "CODE.QUOTE", 95 95 "Specifies that the next expression submitted for execution will instead be pushed literally onto the CODE stack.", 96 StackTypes.Exec)] 96 StackTypes.Exec, 97 requiredBlockCount: 1)] 97 98 [StorableClass] 98 99 public class CodeQuoteExpression : StatelessExpression { … … 175 176 176 177 if (secondProgram.Depth > interpreter.Configuration.MaxDepth || 177 firstProgram.Count + secondProgram.Count > interpreter.Configuration.MaxP ointsInProgram)178 firstProgram.Count + secondProgram.Count > interpreter.Configuration.MaxProgramLength) 178 179 return; 179 } else if (firstProgram.Count + 1 > interpreter.Configuration.MaxP ointsInProgram) return;180 } else if (firstProgram.Count + 1 > interpreter.Configuration.MaxProgramLength) return; 180 181 } else if (second.IsProgram) { 181 182 secondProgram = (PushProgram)second; 182 183 183 184 if (secondProgram.Depth > interpreter.Configuration.MaxDepth 184 || secondProgram.Count + 1 > interpreter.Configuration.MaxP ointsInProgram) return;185 } else if (interpreter.Configuration.MaxP ointsInProgram<= 2) {185 || secondProgram.Count + 1 > interpreter.Configuration.MaxProgramLength) return; 186 } else if (interpreter.Configuration.MaxProgramLength <= 2) { 186 187 return; 187 188 } … … 318 319 return interpreter.CodeStack.Count < 2 || 319 320 (interpreter.CodeStack.Top.IsProgram && 320 ((PushProgram)interpreter.CodeStack.Top).Expressions.Count + 1 > interpreter.Configuration.MaxP ointsInProgram);321 ((PushProgram)interpreter.CodeStack.Top).Expressions.Count + 1 > interpreter.Configuration.MaxProgramLength); 321 322 } 322 323 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DefineExpressions.cs
r15032 r15334 68 68 "Defines the name on top of the NAME stack as an instruction that will push the top item of the EXEC stack onto the EXEC stack.", 69 69 StackTypes.Name, 70 execIn: 1)]70 requiredBlockCount: 1)] 71 71 [StorableClass] 72 72 public class ExecDefineExpression : DefineExpression<Expression> { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DoCountExpressions.cs
r15032 r15334 57 57 "An iteration instruction that performs a loop (the body of which is taken from the EXEC stack) the number of times indicated by the INTEGER argument, pushing an index (which runs from zero to one less than the number of iterations) onto the INTEGER stack prior to each execution of the loop body.", 58 58 StackTypes.Integer, 59 execIn: 1)]59 requiredBlockCount: 1)] 60 60 public class ExecDoCountExpression : StatelessExpression { 61 61 public ExecDoCountExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DoRangeExpressions.cs
r15032 r15334 83 83 description: "An iteration instruction that executes the top item on the EXEC stack a number of times that depends on the top two integers, while also pushing the loop counter onto the INTEGER stack for possible access during the execution of the body of the loop.", 84 84 additionalStackDependencies: StackTypes.Integer, 85 execIn: 1)]85 requiredBlockCount: 1)] 86 86 public class ExecDoRangeExpression : StatelessExpression { 87 87 public ExecDoRangeExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DoTimesExpressions.cs
r15032 r15334 68 68 [Serializable] 69 69 [StorableClass] 70 [PushExpression(StackTypes.Exec, "EXEC.DO*TIMES", "Like EXEC.DO*COUNT but does not push the loop counter", StackTypes.Integer, execIn: 1)]70 [PushExpression(StackTypes.Exec, "EXEC.DO*TIMES", "Like EXEC.DO*COUNT but does not push the loop counter", StackTypes.Integer, requiredBlockCount: 1)] 71 71 public class ExecDoTimesExpression : StatelessExpression { 72 72 public ExecDoTimesExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DuplicateExpressions.cs
r15032 r15334 88 88 89 89 [StorableClass] 90 [PushExpression(StackTypes.Exec, "EXEC.DUP", "Duplicates the top item on the EXEC stack." , execIn: 1)]90 [PushExpression(StackTypes.Exec, "EXEC.DUP", "Duplicates the top item on the EXEC stack." , requiredBlockCount: 1)] 91 91 public class ExecDuplicateExpression : DuplicateExpression<Expression> { 92 92 public ExecDuplicateExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/EmptyExpression.cs
r15032 r15334 72 72 } 73 73 74 [StorableClass] 74 75 [PushExpression( 75 76 StackTypes.Float, … … 85 86 } 86 87 88 [StorableClass] 87 89 [PushExpression( 88 90 StackTypes.Boolean, 89 91 "BOOLEAN.EMPTY", 90 "Pushes TRUE onto the BOOLEAN stack if the BOOLEAN stack is empty, otherwise FALSE.", 91 StackTypes.Boolean)] 92 "Pushes TRUE onto the BOOLEAN stack if the BOOLEAN stack is empty, otherwise FALSE.")] 92 93 public class BooleanEmptyExpression : EmptyExpression<bool> { 93 94 public BooleanEmptyExpression() { } … … 99 100 } 100 101 102 [StorableClass] 101 103 [PushExpression( 102 104 StackTypes.Char, … … 113 115 } 114 116 117 [StorableClass] 115 118 [PushExpression( 116 119 StackTypes.String, … … 127 130 } 128 131 132 [StorableClass] 129 133 [PushExpression( 130 134 StackTypes.IntegerVector, … … 141 145 } 142 146 147 [StorableClass] 143 148 [PushExpression( 144 149 StackTypes.FloatVector, … … 155 160 } 156 161 162 [StorableClass] 157 163 [PushExpression( 158 164 StackTypes.BooleanVector, … … 169 175 } 170 176 177 [StorableClass] 171 178 [PushExpression( 172 179 StackTypes.StringVector, -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/EqualsExpressions.cs
r15032 r15334 83 83 StackTypes.Boolean, 84 84 "BOOLEAN.=", 85 "Pushes TRUE onto the BOOLEAN stack if the top two BOOLEAN items are equal, or FALSE otherwise.", 86 StackTypes.Boolean)] 85 "Pushes TRUE onto the BOOLEAN stack if the top two BOOLEAN items are equal, or FALSE otherwise.")] 87 86 public class BooleanEqualsExpression : EqualsExpression<bool> { 88 87 public BooleanEqualsExpression() { } … … 125 124 "Pushes TRUE onto the BOOLEAN stack if the top two EXEC items are equal, or FALSE otherwise.", 126 125 StackTypes.Boolean, 127 execIn: 0)]126 requiredBlockCount: 0)] 128 127 public class ExecEqualsExpression : EqualsExpression<Expression> { 129 128 public ExecEqualsExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExecExpressions.cs
r15032 r15334 20 20 "If the top item of the BOOLEAN stack is TRUE then this removes the second item on the EXEC stack, leaving the first item to be executed. If it is false then it removes the first item, leaving the second to be executed.", 21 21 StackTypes.Boolean, 22 execIn: 2)]22 requiredBlockCount: 2)] 23 23 public class ExecIfExpression : StatelessExpression { 24 24 public ExecIfExpression() { } … … 45 45 "EXEC.Y", 46 46 "Inserts beneath the top item of the EXEC stack a new item of the form \"( EXEC.Y <TopItem> )\"", 47 execIn: 1)]47 requiredBlockCount: 1)] 48 48 [StorableClass] 49 49 public class ExecYExpression : StatelessExpression { … … 54 54 public override bool IsNoop(IInternalPushInterpreter interpreter) { 55 55 return interpreter.ExecStack.Count == 0 || 56 interpreter.Configuration.MaxP ointsInProgram< 2 ||56 interpreter.Configuration.MaxProgramLength < 2 || 57 57 (interpreter.ExecStack.Top.IsProgram && ((PushProgram)interpreter.ExecStack.Top).Depth == interpreter.Configuration.MaxDepth); 58 58 } … … 80 80 "EXEC.K", 81 81 "Removes the second item on the EXEC stack.", 82 execIn: 2)]82 requiredBlockCount: 2)] 83 83 [StorableClass] 84 84 public class ExecKExpression : StatelessExpression { … … 106 106 "EXEC.S", 107 107 "Pops 3 items from the EXEC stack called A, B, and C. Then pushes a list containing B and C back onto the EXEC stack, followed by another instance of C, followed by another instance of A.", 108 execIn: 3)]108 requiredBlockCount: 3)] 109 109 [StorableClass] 110 110 public class ExecSExpression : StatelessExpression { … … 167 167 "EXEC.WHILE", 168 168 "Executes top EXEC item recursively as long top BOOLEAN is TRUE.", 169 StackTypes.Boolean, execIn: 1)]169 StackTypes.Boolean, requiredBlockCount: 1)] 170 170 [StorableClass] 171 171 public class ExecWhileExpression : StatelessExpression { … … 196 196 "EXEC.DO*WHILE", 197 197 "Executes top EXEC item recursively until max. amount of eval. expressions is reached or top EXEC item removes the the recursive call.", 198 execIn: 1)]198 requiredBlockCount: 1)] 199 199 [StorableClass] 200 200 public class ExecDoWhileExpression : StatelessExpression { … … 220 220 "Top EXEC item is only executed, if top BOOLEAN is TRUE.", 221 221 StackTypes.Boolean, 222 execIn: 1)]222 requiredBlockCount: 1)] 223 223 [StorableClass] 224 224 public class ExecWhenExpression : StatelessExpression { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/Expression.cs
r15189 r15334 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 2 using System; 3 using System.Collections.Generic;4 3 5 4 using HeuristicLab.Common; … … 20 19 public bool IsProgram { get { return GetType() == typeof(PushProgram); } } 21 20 22 public static readonly IReadOnlyCollection<Expression> EmptyContainer = new Expression[0]; 23 24 public abstract string StringRepresentation 25 { 26 get; 27 } 21 public abstract string StringRepresentation { get; } 28 22 29 23 public abstract bool IsNoop(IInternalPushInterpreter interpreter); … … 43 37 44 38 public object Clone() { 45 return Clone(new Cloner());39 return this; 46 40 } 47 41 … … 50 44 } 51 45 52 void IPooledObject.Init() { }53 54 46 void IPooledObject.Reset() { } 55 47 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExpressionTable.cs
r15273 r15334 6 6 using Attributes; 7 7 using Data.Pool; 8 9 using HeuristicLab.Problems.ProgramSynthesis.Base.Extensions; 10 8 11 using Stack; 9 12 … … 124 127 } 125 128 126 private static bool IsSubclassOf(Type type, Type baseType) { 127 if (type == null || baseType == null || type == baseType) 128 return false; 129 130 if (baseType.IsGenericType == false) { 131 if (type.IsGenericType == false) 132 return type.IsSubclassOf(baseType); 133 } else { 134 baseType = baseType.GetGenericTypeDefinition(); 135 } 136 137 type = type.BaseType; 138 var objectType = typeof(object); 139 while (type != objectType && type != null) { 140 var curentType = type.IsGenericType ? type.GetGenericTypeDefinition() : type; 141 if (curentType == baseType) 142 return true; 143 144 type = type.BaseType; 145 } 146 147 return false; 148 } 129 149 130 150 131 private static IEnumerable<Type> GetExpressionTypes(Type baseType) { … … 152 133 from assemblyType in domainAssembly.GetTypes() 153 134 where !assemblyType.IsAbstract && 154 IsSubclassOf(assemblyType,baseType) &&135 assemblyType.IsSubclass(baseType) && 155 136 assemblyType.GetConstructor(Type.EmptyTypes) != null 156 137 select assemblyType; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/FloatExpressions.cs
r15032 r15334 341 341 /// </summary> 342 342 [PushExpression(StackTypes.Float, "FLOAT.COS", "Pushes the cosine of the top item.")] 343 [StorableClass] 343 344 public class FloatCosineExpression : StatelessExpression { 344 345 public FloatCosineExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PopExpressions.cs
r15032 r15334 84 84 85 85 [StorableClass] 86 [PushExpression(StackTypes.Exec, "EXEC.POP", "Pops the top EXEC item.", execIn: 1)]86 [PushExpression(StackTypes.Exec, "EXEC.POP", "Pops the top EXEC item.", requiredBlockCount: 1)] 87 87 public class ExecPopExpression : PopExpression<Expression> { 88 88 public ExecPopExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PrintExpressions.cs
r15289 r15334 26 26 27 27 [StorableClass] 28 [PushExpression(StackTypes.Print, "PRINT.ENSURE_NEWLINE", "Pushes an empty string onto the PRINT STACK if current line isn't empty already.")] 29 public class PrintEnsureNewLineExpression : StatelessExpression { 30 public PrintEnsureNewLineExpression() { } 31 [StorableConstructor] 32 protected PrintEnsureNewLineExpression(bool deserializing) : base(deserializing) { } 33 34 public override bool IsNoop(IInternalPushInterpreter interpreter) { 35 return interpreter.PrintStack.IsCurrentLineEmpty; 36 } 37 38 public override void Eval(IInternalPushInterpreter interpreter) { 39 interpreter.PrintStack.NewLine(); 40 } 41 } 42 43 [StorableClass] 28 44 public abstract class PrintExpression<T> : StatelessExpression { 29 45 protected PrintExpression() { } … … 104 120 "Pushes the top BOOLEAN onto the EXEC stack.", 105 121 StackTypes.Exec, 106 execIn: 1)]122 requiredBlockCount: 1)] 107 123 public class ExecPrintExpression : PrintExpression<Expression> { 108 124 public ExecPrintExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PushProgram.cs
r15189 r15334 5 5 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 6 6 using System.Diagnostics; 7 using System.Diagnostics.CodeAnalysis; 8 7 9 using Constants; 8 10 using Data.Pool; … … 38 40 39 41 [StorableConstructor] 40 p ublicPushProgram(bool deserializing) : this(EmptyExpressions) { }42 private PushProgram(bool deserializing) : this(EmptyExpressions) { } 41 43 42 44 public PushProgram(IReadOnlyList<Expression> expressions) { … … 67 69 } 68 70 69 void IPooledObject.Init() { }70 71 71 void IPooledObject.Reset() { 72 72 expressions = null; … … 159 159 [NonSerialized] 160 160 private int? hashCode; 161 [SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")] 161 162 public override int GetHashCode() { 162 163 if (hashCode == null) hashCode = expressions.HashCode(); … … 256 257 get 257 258 { 258 if (branches == null) { 259 branches = 1; 260 261 for (var i = 0; i < Count; i++) { 262 var expression = expressions[i]; 263 264 if (!expression.IsProgram) 265 continue; 266 267 var program = (PushProgram)expression; 268 branches += program.Branches; 269 } 270 } 271 259 if (branches == null) CountBranches(); 272 260 return branches.Value; 261 } 262 } 263 264 private void CountBranches() { 265 branches = 1; 266 267 for (var i = 0; i < Count; i++) { 268 var expression = expressions[i]; 269 270 if (!expression.IsProgram) 271 continue; 272 273 var program = (PushProgram)expression; 274 branches += program.Branches; 273 275 } 274 276 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/RotateExpressions.cs
r15032 r15334 100 100 "EXEC.ROT", 101 101 "Rotates the top 3 items of the EXEC stack clockwise.", 102 execIn: 3)]102 requiredBlockCount: 3)] 103 103 [StorableClass] 104 104 public class ExecRotateExpression : RotateExpression<Expression> { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ShoveExpressions.cs
r15032 r15334 107 107 "Moves the top EXEC item to a specific stack index, whereby the index is taken from the INTEGER stack.", 108 108 StackTypes.Integer, 109 execIn: 1)]109 requiredBlockCount: 1)] 110 110 [StorableClass] 111 111 public class ExecShoveExpression : ShoveExpression<Expression> { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StatefulExpression.cs
r15189 r15334 69 69 } 70 70 71 void IPooledObject.Init() { }72 73 71 public void Reset() { 74 72 State = default(T); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StringExpressions.cs
r15189 r15334 122 122 public override bool IsNoop(IInternalPushInterpreter interpreter) { 123 123 return interpreter.StringStack.Count < 2 || 124 interpreter.StringStack.Top.Length + interpreter.StringStack[1].Length > =interpreter.Configuration.MaxStringLength;124 interpreter.StringStack.Top.Length + interpreter.StringStack[1].Length > interpreter.Configuration.MaxStringLength; 125 125 } 126 126 … … 148 148 return interpreter.StringStack.IsEmpty || 149 149 interpreter.CharStack.IsEmpty || 150 interpreter.StringStack.Top.Length + 1 > =interpreter.Configuration.MaxStringLength;150 interpreter.StringStack.Top.Length + 1 > interpreter.Configuration.MaxStringLength; 151 151 } 152 152 … … 618 618 619 619 public override void Eval(IInternalPushInterpreter interpreter) { 620 var result = GetResultString(interpreter); 621 622 // Should be checked in isNoop but would require to calculate result twice which is an expensive operation 623 if (result.Length > interpreter.Configuration.MaxStringLength) 624 return; 625 626 interpreter.StringStack.Remove(2); 627 interpreter.StringStack.Top = result; 628 } 629 630 private static string GetResultString(IInternalPushInterpreter interpreter) { 620 631 var third = interpreter.StringStack[2]; 621 632 var second = interpreter.StringStack[1]; 622 633 var first = interpreter.StringStack[0]; 623 interpreter.StringStack.Remove(2); 624 625 interpreter.StringStack.Top = third.Length == 0 || second.Length == 0 634 635 var result = third.Length == 0 || second.Length == 0 626 636 ? third 627 637 : third.Replace(second, first); 638 639 return result; 628 640 } 629 641 } … … 647 659 648 660 public override void Eval(IInternalPushInterpreter interpreter) { 661 var result = GetResultString(interpreter); 662 663 // Should be checked in isNoop but would require to calculate result twice which is an expensive operation 664 if (result.Length > interpreter.Configuration.MaxStringLength) 665 return; 666 667 interpreter.StringStack.Remove(2); 668 interpreter.StringStack.Top = result; 669 } 670 671 private static string GetResultString(IInternalPushInterpreter interpreter) { 649 672 var third = interpreter.StringStack[2]; 650 673 var second = interpreter.StringStack[1]; 651 674 var first = interpreter.StringStack[0]; 652 interpreter.StringStack.Remove(2); 653 654 interpreter.StringStack.Top = third.Length == 0 || second.Length == 0 675 676 var result = third.Length == 0 || second.Length == 0 655 677 ? third 656 678 : ReplaceFirst(third, second, first); 679 return result; 657 680 } 658 681 … … 802 825 "STRING.ITERATE", 803 826 "Iterates over the top STRING using the CODE on the EXEC stack.", 804 StackTypes.Exec | StackTypes.Char, execIn: 1)]827 StackTypes.Exec | StackTypes.Char, requiredBlockCount: 1)] 805 828 public class StringIterateExpression : StatelessExpression { 806 829 public StringIterateExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/SwapExpressions.cs
r15032 r15334 104 104 "EXEC.SWAP", 105 105 "Swaps the top two items on the stack.", 106 execIn: 2)]106 requiredBlockCount: 2)] 107 107 public class ExecSwapExpression : SwapExpression<Expression> { 108 108 public ExecSwapExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorIterateExpressions.cs
r15189 r15334 67 67 "Iterates in reverse order (due to performance reasons) over the top INTEGER[] using the top item of the EXEC stack.", 68 68 StackTypes.Integer | StackTypes.Exec, 69 execIn: 1)]69 requiredBlockCount: 1)] 70 70 public class IntegerVectorIterateExpression : VectorIterateExpression<long> { 71 71 public IntegerVectorIterateExpression() { } … … 87 87 "FLOAT[].ITERATE", 88 88 "Iterates in reverse order (due to performance reasons) over the top FLOAT[] using the top item of the EXEC stack.", 89 StackTypes.Float | StackTypes.Exec, execIn: 1)]89 StackTypes.Float | StackTypes.Exec, requiredBlockCount: 1)] 90 90 public class FloatVectorIterateExpression : VectorIterateExpression<double> { 91 91 public FloatVectorIterateExpression() { } … … 107 107 "BOOLEAN[].ITERATE", 108 108 "Iterates in reverse order (due to performance reasons) over the top BOOLEAN[] using the top item of the EXEC stack.", 109 StackTypes.Boolean | StackTypes.Exec, execIn: 1)]109 StackTypes.Boolean | StackTypes.Exec, requiredBlockCount: 1)] 110 110 public class BooleanVectorIterateExpression : VectorIterateExpression<bool> { 111 111 public BooleanVectorIterateExpression() { } … … 127 127 "STRING[].ITERATE", 128 128 "Iterates in reverse order (due to performance reasons) over the top STRING[] using the top item of the EXEC stack.", 129 StackTypes.String | StackTypes.Exec, execIn: 1)]129 StackTypes.String | StackTypes.Exec, requiredBlockCount: 1)] 130 130 public class StringVectorIterateExpression : VectorIterateExpression<string> { 131 131 public StringVectorIterateExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/YankDuplicateExpressions.cs
r15032 r15334 116 116 "EXEC.YANKDUP", 117 117 "Pushes a copy of an indexed item \"deep\" in the stack onto the top of the stack, without removing the deep item.", 118 StackTypes.Integer, execIn: 0)]118 StackTypes.Integer, requiredBlockCount: 0)] 119 119 public class ExecYankDuplicateExpression : YankDuplicateExpression<Expression> { 120 120 public ExecYankDuplicateExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/YankExpressions.cs
r15032 r15334 115 115 "Removes an indexed item from \"deep\" in the stack and pushes it on top of the stack.", 116 116 StackTypes.Integer, 117 execIn: 0)]117 requiredBlockCount: 0)] 118 118 public class ExecYankExpression : YankExpression<Expression> { 119 119 public ExecYankExpression() { } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Extensions/ControlExntensions.cs
r14834 r15334 17 17 18 18 if (propertyInfo == null || 19 // ReSharper disable once AssignNullToNotNullAttribute 19 20 !control.GetType().IsSubclassOf(propertyInfo.ReflectedType) || 20 21 control.GetType().GetProperty( -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Individual/InduvidualMapper.cs
r15273 r15334 47 47 var expressionType = expression.GetType(); 48 48 49 if (config. ParenthesesCloseBiasLevel > 0) {50 close += random.NextBiased(0, config.Max ParenthesesClose, config.ParenthesesCloseBiasLevel);49 if (config.CloseBiasLevel > 0) { 50 close += random.NextBiased(0, config.MaxClose, config.CloseBiasLevel); 51 51 52 52 // check if expression requires additional blocks … … 54 54 var attr = ExpressionTable.TypeToAttributeTable[expressionType]; 55 55 56 for (var blockIdx = 0u; blockIdx < attr. ExecIn&& currentIndex < vector.Length; blockIdx++) {56 for (var blockIdx = 0u; blockIdx < attr.RequiredBlockCount && currentIndex < vector.Length; blockIdx++) { 57 57 if (close != 0) { 58 58 close--; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/Extensions.cs
r15289 r15334 77 77 78 78 public static void PrintStacks(this IPushInterpreter interpreter) { 79 var maxStackNameLength = interpreter.Stacks.Max(x => x.Key.ToString().Length); 80 var totalLength = maxStackNameLength + 6; 81 79 82 foreach (var pair in interpreter.Stacks) { 80 83 var stackName = pair.Key.ToString(); 81 84 var stack = interpreter.Stacks[pair.Key]; 82 85 83 if (stack.IsEmpty || !stack.IsEnabled) continue; 86 if (stack.IsEmpty || !stack.IsEnabled) 87 continue; 84 88 85 var stackString = string.Join(" ", interpreter.StringifyStack(pair.Key).Reverse()); 86 Console.WriteLine("--------- {0} ---------\n{1}\n", stackName, stackString); 89 var stackString = string.Join(" ", interpreter.StringifyStack(pair.Key)); 90 91 //var padLength = (totalLength - stackName.Length) / 2; 92 //var padLengthLeft = stackName.Length + padLength; 93 //var padLengthRight = padLengthLeft + padLength; 94 //Console.WriteLine("{0}\n{1}\n", stackName.PadLeft(padLengthLeft, '-').PadRight(padLengthRight, '-'), stackString); 95 96 Console.WriteLine("{0}: {1}", stackName, stackString); 87 97 } 88 98 … … 96 106 97 107 public static void InitExample(this IPushInterpreter interpreter, Example example) { 98 interpreter.BooleanStack.Push(example.InputBoolean); 99 interpreter.IntegerStack.Push(example.InputInteger); 100 interpreter.FloatStack.Push(example.InputFloat); 101 interpreter.CharStack.Push(example.InputChar); 102 interpreter.StringStack.Push(example.InputString); 103 interpreter.StringVectorStack.Push(example.InputStringVector); 104 interpreter.IntegerVectorStack.Push(example.InputIntegerVector); 105 interpreter.FloatVectorStack.Push(example.InputFloatVector); 108 if (interpreter.Configuration.TopLevelPushInputArguments) { 109 interpreter.BooleanStack.Push(example.InputBoolean); 110 interpreter.IntegerStack.Push(example.InputInteger); 111 interpreter.FloatStack.Push(example.InputFloat); 112 interpreter.CharStack.Push(example.InputChar); 113 interpreter.StringStack.Push(example.InputString); 114 interpreter.StringVectorStack.Push(example.InputStringVector); 115 interpreter.IntegerVectorStack.Push(example.InputIntegerVector); 116 interpreter.FloatVectorStack.Push(example.InputFloatVector); 117 } 106 118 119 // init in expressions 107 120 interpreter.SetInput( 108 121 integers: example.InputInteger, -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
r15273 r15334 31 31 32 32 // setting the capacity of the Stacks to max points ensures that there will be enough memory at runtime 33 ExecStack = new PushStack<Expression>(Configuration.MaxP ointsInProgram);33 ExecStack = new PushStack<Expression>(Configuration.MaxProgramLength); 34 34 CodeStack = new PushStack<Expression>(); 35 35 NameStack = new PushStack<string>(); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs
r15273 r15334 22 22 ExpressionListPoolProvider = new ManagedPoolProvider<PooledList<Expression>>(poolPartitionSize, () => new PooledList<Expression>(), maxPartitionCount); 23 23 24 pool = new ObjectPool<PooledPushInterpreter>(() => { 25 var poolContainer = new InterpreterPoolContainer(PushProgramPoolProvider, ExpressionListPoolProvider); 26 return new PooledPushInterpreter(this, PushConfiguration, poolContainer); 27 }, size); 24 pool = new ObjectPool<PooledPushInterpreter>(CreateInterpreter, size); 25 } 26 27 private PooledPushInterpreter CreateInterpreter() { 28 var poolContainer = new InterpreterPoolContainer(PushProgramPoolProvider, ExpressionListPoolProvider); 29 return new PooledPushInterpreter(this, PushConfiguration, poolContainer); 28 30 } 29 31 … … 31 33 32 34 public PooledPushInterpreter Create(IRandom random = null) { 33 var interpreter = pool.Allocate(); 34 interpreter.Reset(random); 35 //var interpreter = pool.Allocate(); 36 //interpreter.Reset(random); 37 38 var poolContainer = new InterpreterPoolContainer(PushProgramPoolProvider, ExpressionListPoolProvider); 39 var interpreter = new PooledPushInterpreter(this, PushConfiguration, poolContainer, random); 35 40 36 41 return interpreter; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Manipulator/UniformMutation.cs
r15289 r15334 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Manipulator { 1 // ReSharper disable CompareOfFloatsByEqualityOperator 2 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Manipulator { 2 3 3 4 using HeuristicLab.Common; … … 9 10 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 10 11 using HeuristicLab.Problems.ProgramSynthesis.Base.Erc; 12 using HeuristicLab.Problems.ProgramSynthesis.Base.Extensions; 11 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 12 14 using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding; 15 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 13 16 using HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator; 14 17 … … 27 30 Parameters.Add(new ValueLookupParameter<PercentValue>("InInstructionProbability", "The probability of IN Instructions")); 28 31 29 Parameters.Add(new FixedValueParameter<PercentValue>("InstructionMutationProbability", "The probability an instruction gets mutated", new PercentValue(0.02))); 30 Parameters.Add(new FixedValueParameter<PercentValue>("CloseMutationProbability", "The probability close gets mutated", new PercentValue(0.02))); 31 Parameters.Add(new FixedValueParameter<PercentValue>("CloseIncrementRate", "When mutating individual, the increment rate specifies if close should be increased or decreased by 1.", new PercentValue(0.5))); 32 Parameters.Add(new FixedValueParameter<PercentValue>("InstructionMutationProbability", "The probability instructions get mutated", new PercentValue(0.8))); 33 Parameters.Add(new FixedValueParameter<PercentValue>("InstructionMutationRate", "The probability an instruction gets mutated", new PercentValue(0.01))); 34 Parameters.Add(new FixedValueParameter<PercentValue>("InstructionConstantTweakRate", "When mutating an instruction, this parameter specifies if mutation is related to the current type (e.g. INTEGER, FLOAT) or not. ", new PercentValue(0))); 35 Parameters.Add(new FixedValueParameter<PercentValue>("CloseMutationProbability", "The probability close gets mutated", new PercentValue(0.2))); 36 Parameters.Add(new FixedValueParameter<PercentValue>("CloseIncrementRate", "When mutating individual, the increment rate specifies if close should be increased or decreased by 1.", new PercentValue(0.1))); 32 37 } 33 38 … … 47 52 get { return InstructionMutationProbabilityParameter.Value.Value; } 48 53 set { InstructionMutationProbabilityParameter.Value.Value = value; } 54 } 55 56 public IValueParameter<PercentValue> InstructionMutationRateParameter 57 { 58 get { return (IValueParameter<PercentValue>)Parameters["InstructionMutationRate"]; } 59 } 60 61 public double InstructionMutationRate 62 { 63 get { return InstructionMutationRateParameter.Value.Value; } 64 set { InstructionMutationRateParameter.Value.Value = value; } 65 } 66 67 public IValueParameter<PercentValue> InstructionConstantTweakRateParameter 68 { 69 get { return (IValueParameter<PercentValue>)Parameters["InstructionConstantTweakRate"]; } 70 } 71 72 public double InstructionConstantTweakRate 73 { 74 get { return InstructionConstantTweakRateParameter.Value.Value; } 75 set { InstructionConstantTweakRateParameter.Value.Value = value; } 49 76 } 50 77 … … 104 131 RandomParameter.ActualValue, 105 132 PlushVectorParameter.ActualValue, 106 CloseIncrementRate,107 133 ErcOptionsParameter.ActualValue, 108 134 InstructionsParameter.ActualValue, 109 135 InInstructionProbabilityParameter.ActualValue.Value, 110 136 CloseMutationProbability, 111 InstructionMutationProbability); 137 CloseIncrementRate, 138 InstructionMutationProbability, 139 InstructionMutationRate, 140 InstructionConstantTweakRate); 112 141 return base.InstrumentedApply(); 113 142 } … … 116 145 IRandom random, 117 146 PlushVector plushVector, 118 double closeIncrementRate,119 147 IReadOnlyErcOptions ercOptions, 120 148 IReadOnlyExpressionsConfiguration instructions, 121 149 double inInstructionProbability, 122 150 double closeMutationProbability, 123 double instructionMutationProbability 151 double closeIncrementRate, 152 double instructionMutationProbability, 153 double instructionMutationRate, 154 double constantTweakRate 124 155 ) { 125 156 126 for (var i = 0; i < plushVector.Entries.Count; i++) { 127 var entry = plushVector[i]; 128 var x = random.NextDouble(); 129 130 if (x < instructionMutationProbability) { 131 var instruction = CodeGeneratorUtils.GetRandomExpression( 132 random, 133 ercOptions, 134 instructions, 135 inInstructionProbability); 136 entry.Instruction = instruction; 157 var x = random.NextDouble(); 158 159 // instruction manipulation 160 if (x < instructionMutationProbability) { 161 if (instructionMutationRate == 0) return; 162 for (var i = 0; i < plushVector.Entries.Count; i++) { 163 MutateInstruction(random, ercOptions, instructions, inInstructionProbability, instructionMutationRate, constantTweakRate, plushVector[i]); 137 164 } 138 165 139 x = random.NextDouble(); 140 141 if (x < closeMutationProbability) { 142 x = random.NextDouble(); 143 entry.Close += x < closeIncrementRate ? 1 : -1; 144 145 if (entry.Close < 0) 146 entry.Close = 0; 166 plushVector.UpdatePushProgram(); 167 return; 168 } 169 170 // close manipulation 171 if (x < instructionMutationProbability + closeMutationProbability) { 172 if (closeIncrementRate == 0) return; 173 for (var i = 0; i < plushVector.Entries.Count; i++) { 174 MutateClose(random, closeIncrementRate, plushVector[i]); 147 175 } 176 177 plushVector.UpdatePushProgram(); 178 return; 148 179 } 149 150 // specifies that the program cached within entry must be updated before reuse 151 plushVector.UpdatePushProgram(); 180 } 181 182 private static void MutateClose(IRandom random, double closeIncrementRate, PlushEntry entry) { 183 entry.Close += random.NextDouble() < closeIncrementRate ? 1 : -1; 184 185 if (entry.Close < 0) 186 entry.Close = 0; 187 } 188 189 private static void MutateInstruction( 190 IRandom random, 191 IReadOnlyErcOptions ercOptions, 192 IReadOnlyExpressionsConfiguration instructions, 193 double inInstructionProbability, 194 double instructionMutationRate, 195 double constantTweakRate, 196 PlushEntry entry) { 197 198 if (random.NextDouble() >= instructionMutationRate) 199 return; 200 201 var entryType = entry.Instruction.GetType(); 202 203 if (constantTweakRate > 0 && random.NextDouble() < constantTweakRate && 204 entryType.IsSubclass(typeof(PushExpression<>))) { 205 var attribute = ExpressionTable.TypeToAttributeTable[entryType]; 206 entry.Instruction = CodeGeneratorUtils.CreateRandomErcExpression(attribute.StackType, random, ercOptions); 207 return; 208 } 209 210 entry.Instruction = CodeGeneratorUtils.GetRandomExpression( 211 random, 212 ercOptions, 213 instructions, 214 inInstructionProbability); 152 215 } 153 216 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/IntegerVectorPushBenchmarkSuiteProblem.cs
r15289 r15334 51 51 Description = data.Description; 52 52 BestKnownQuality = data.BestResult; 53 Config.MaxP ointsInProgram= data.MaxSize;53 Config.MaxProgramLength = data.MaxSize; 54 54 Config.EvalPushLimit = data.EvalLimit; 55 55 Config.ErcOptions = data.ErcOptions; … … 62 62 Encoding.Bounds[0, 1] = Config.EnabledExpressions.Count; 63 63 64 Encoding.Length = data.MaxSize; 64 Encoding.Length = data.MaxSize / 2; 65 65 66 } 66 67 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PlushPushBenchmarkSuiteProblem.cs
r15289 r15334 48 48 Description = data.Description; 49 49 BestKnownQuality = data.BestResult; 50 Config.MaxP ointsInProgram= data.MaxSize;50 Config.MaxProgramLength = data.MaxSize; 51 51 Config.EvalPushLimit = data.EvalLimit; 52 52 Config.ErcOptions = data.ErcOptions; … … 56 56 Config.InitInExpressions(data.TotalInputArgumentCount); 57 57 58 Encoding.MaxLength = data.MaxSize; 58 Encoding.MinLength = 0; 59 Encoding.MaxLength = data.MaxSize / 2; 59 60 } 60 61 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/IntegerVectorPushProblem.cs
r15289 r15334 59 59 Encoding.Bounds[0, 0] = 0; 60 60 Encoding.Bounds[0, 1] = Config.EnabledExpressions.Count; 61 Encoding.Length = Config.MaxP ointsInProgram;61 Encoding.Length = Config.MaxProgramLength; 62 62 } 63 63 … … 72 72 73 73 solutionCreator.ErcOptions = Config.ErcOptions; 74 solutionCreator.MinLength = Config.MinProgramLength; 74 75 75 76 if (!Operators.OfType<PushExpressionFrequencyAnalyzer>().Any()) { 76 77 Operators.Add(new PushExpressionFrequencyAnalyzer()); 78 } 79 80 if (!Operators.OfType<IndividualZeroErrorAnalyzer>().Any()) { 81 Operators.Add(new IndividualZeroErrorAnalyzer()); 77 82 } 78 83 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PlushPushProblem.cs
r15289 r15334 3 3 4 4 using HeuristicLab.Common; 5 using HeuristicLab.Core;6 using HeuristicLab.Data;7 5 using HeuristicLab.Optimization; 8 6 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 31 29 Encoding.ErcOptionsParameter = Config.ErcOptionsParameter; 32 30 Encoding.InstructionsParameter = Config.InstructionsParameter; 33 Encoding.MaxLength = Config.MaxPointsInProgram; 31 Encoding.MinLengthParameter = Config.MinProgramLengthParameter; 32 Encoding.MaxLengthParameter = Config.MaxProgramLengthParameter; 33 Encoding.MaxCloseParameter = Config.MaxCloseParameter; 34 Encoding.CloseBiasLevelParameter = Config.CloseBiasLevelParameter; 34 35 } 35 36 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblemBase.cs
r15289 r15334 20 20 public abstract class PushProblemBase<T> : SingleObjectiveBasicProblem<T> where T : class, IEncoding { 21 21 [Storable] 22 p rotected readonly PushConfigurationParameterCollection Config;22 public readonly PushConfiguration Config; 23 23 24 24 protected PushInterpreterPool Pool; … … 37 37 38 38 protected PushProblemBase(IPushEvaluator evaluator) { 39 Config = new PushConfiguration ParameterCollection();39 Config = new PushConfiguration(); 40 40 PushEvaluator = evaluator; 41 41 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/SolutionCreator/IPlushCreator.cs
r15289 r15334 10 10 IValueLookupParameter<IntValue> MinLengthParameter { get; } 11 11 IValueLookupParameter<IntValue> MaxLengthParameter { get; } 12 IValueLookupParameter<IntValue> MinCloseParameter { get; }13 12 IValueLookupParameter<IntValue> MaxCloseParameter { get; } 14 13 IValueLookupParameter<DoubleValue> CloseBiasLevelParameter { get; } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/SolutionCreator/PlushCreator.cs
r15289 r15334 24 24 Parameters.Add(new ValueLookupParameter<IntValue>("MinLength", "The min length of the vector.")); 25 25 Parameters.Add(new ValueLookupParameter<IntValue>("MaxLength", "The max length of the vector.")); 26 Parameters.Add(new ValueLookupParameter<IntValue>("MinClose", "The min close variable for a plush genome entry."));27 26 Parameters.Add(new ValueLookupParameter<IntValue>("MaxClose", "The max close variable for a plush genome entry.")); 28 27 Parameters.Add(new ValueLookupParameter<DoubleValue>("CloseBiasLevel", "Determines how strongly the random close variable is biased towards 0.")); … … 69 68 get { return (IValueLookupParameter<PercentValue>)Parameters["InInstructionProbability"]; } 70 69 } 71 public IValueLookupParameter<IntValue> MinCloseParameter72 {73 get { return (IValueLookupParameter<IntValue>)Parameters["MinClose"]; }74 }75 70 public IValueLookupParameter<IntValue> MaxCloseParameter 76 71 { … … 97 92 var instructions = InstructionsParameter.ActualValue; 98 93 var inInstructionProbability = InInstructionProbabilityParameter.ActualValue.Value; 99 var minClose = MinCloseParameter.ActualValue.Value;100 94 var maxClose = MaxCloseParameter.ActualValue.Value; 101 95 var biasLevel = CloseBiasLevelParameter.ActualValue.Value; … … 103 97 if (minLength > maxLength) 104 98 throw new InvalidOperationException("MinLength > MaxLength"); 105 106 if (minClose > maxClose)107 throw new InvalidOperationException("MinClose > MaxClose");108 99 109 100 var length = random.Next(minLength, maxLength); … … 117 108 inInstructionProbability); 118 109 119 var close = random.NextBiased(minClose, maxClose, biasLevel);110 var close = maxClose == 0 ? 1 : random.NextBiased(0, maxClose, biasLevel); 120 111 121 112 result.Add(new PlushEntry { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/IPrintStack.cs
r15289 r15334 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Stack { 2 using System.Collections.Generic; 3 2 4 public interface IPrintStack : IPushStack { 5 bool IsCurrentLineEmpty { get; } 6 IReadOnlyList<string> Lines { get; } 7 3 8 void NewLine(); 4 9 void Push<T>(T item); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PrintStack.cs
r15289 r15334 14 14 public class PrintStack : IPrintStack { 15 15 private int lineCount = 0; 16 private int length = 0; 17 private IReadOnlyList<string> lines; 16 18 private readonly StringBuilder stringBuilder = new StringBuilder(); 17 19 20 public PrintStack() { 21 IsCurrentLineEmpty = true; 22 } 23 24 public bool IsCurrentLineEmpty { get; private set; } 25 18 26 IEnumerator IEnumerable.GetEnumerator() { 19 var lines = AsStrings(); 20 return lines.GetEnumerator(); 27 return Lines.GetEnumerator(); 21 28 } 22 29 … … 25 32 } 26 33 34 public IReadOnlyList<string> Lines 35 { 36 get 37 { 38 if (stringBuilder.Length == length) return lines; 39 length = stringBuilder.Length; 40 lines = stringBuilder.ToString().Split(PushEnvironment.NewLine); 41 42 return lines; 43 } 44 } 45 27 46 void IPushStack.Clear() { 47 lineCount = 0; 48 length = 0; 49 lines = null; 50 IsCurrentLineEmpty = true; 28 51 stringBuilder.Clear(); 29 52 } … … 31 54 public void NewLine() { 32 55 stringBuilder.Append(PushEnvironment.NewLine); 56 IsCurrentLineEmpty = true; 33 57 lineCount++; 34 58 } … … 36 60 public void Push<T>(T item) { 37 61 if (IsEmpty) lineCount = 1; 38 stringBuilder.Append(item); 62 var str = item.ToString(); 63 stringBuilder.Append(str); 64 IsCurrentLineEmpty = IsCurrentLineEmpty && string.IsNullOrEmpty(str); 39 65 } 40 66 … … 42 68 if (IsEmpty) lineCount = 1; 43 69 stringBuilder.Concat(item); 70 IsCurrentLineEmpty = false; 44 71 } 45 72 … … 47 74 if (IsEmpty) lineCount = 1; 48 75 stringBuilder.Concat(item); 76 IsCurrentLineEmpty = false; 49 77 } 50 78 … … 52 80 if (IsEmpty) lineCount = 1; 53 81 stringBuilder.Concat(item); 82 IsCurrentLineEmpty = false; 54 83 } 55 84 … … 57 86 if (IsEmpty) lineCount = 1; 58 87 stringBuilder.Concat(item); 88 IsCurrentLineEmpty = false; 59 89 } 60 90 … … 62 92 if (IsEmpty) lineCount = 1; 63 93 stringBuilder.Append(item); 94 IsCurrentLineEmpty = false; 64 95 } 65 96 … … 67 98 if (IsEmpty) lineCount = 1; 68 99 stringBuilder.Append(item); 100 IsCurrentLineEmpty = false; 69 101 } 70 71 102 72 103 public void Push(string item) { 73 104 if (IsEmpty) lineCount = 1; 74 105 stringBuilder.Append(item); 106 IsCurrentLineEmpty = IsCurrentLineEmpty && string.IsNullOrEmpty(item); 75 107 } 76 108 … … 78 110 for (var i = startIndex; i < items.Count; i++) 79 111 stringBuilder.Append(items[i]); 112 113 IsCurrentLineEmpty = false; 80 114 } 81 115 … … 87 121 foreach (var item in items) 88 122 stringBuilder.Append(item); 123 124 IsCurrentLineEmpty = false; 89 125 } 90 126 91 127 public IEnumerable<string> AsStrings() { 92 var lines = stringBuilder.ToString().Split(PushEnvironment.NewLine); 93 return lines; 128 return Lines; 94 129 } 95 130 96 131 public IEnumerable<object> AsObjects() { 97 return AsStrings();132 return Lines; 98 133 } 99 134
Note: See TracChangeset
for help on using the changeset viewer.