- Timestamp:
- 04/10/17 00:27:31 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis
- Files:
-
- 59 added
- 6 deleted
- 55 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/HeuristicLab.Problems.ProgramSynthesis.csproj
r14777 r14834 95 95 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath> 96 96 </Reference> 97 <Reference Include="HeuristicLab.Selection-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 98 <SpecificVersion>False</SpecificVersion> 99 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Selection-3.3.dll</HintPath> 100 </Reference> 97 101 <Reference Include="System" /> 98 102 <Reference Include="System.ComponentModel.DataAnnotations" /> … … 115 119 </Compile> 116 120 <Compile Include="Push\Attributes\PushExpressionAttriubte.cs" /> 121 <Compile Include="Push\Attributes\PushStackAttribute.cs" /> 117 122 <Compile Include="Push\Configuration\IEnabledExpressionsConfiguration.cs" /> 118 123 <Compile Include="Push\Creator\PointsBasedPushProgramCreator.cs" /> … … 125 130 <Compile Include="Push\Data\Tree\TreeExtensions.cs" /> 126 131 <Compile Include="Push\Data\Tree\TreeNode.cs" /> 132 <Compile Include="Push\Erc\BooleanErcOptions.cs" /> 133 <Compile Include="Push\Erc\CharErcOptions.cs" /> 134 <Compile Include="Push\Erc\ErcOption.cs" /> 135 <Compile Include="Push\Erc\FloatErcOptions.cs" /> 136 <Compile Include="Push\Erc\IntegerErcOptions.cs" /> 137 <Compile Include="Push\Erc\Interfaces\IReadOnlyBooleanErcOptions.cs" /> 138 <Compile Include="Push\Erc\Interfaces\IReadOnlyCharErcOptions.cs" /> 139 <Compile Include="Push\Erc\Interfaces\IReadOnlyErcOption.cs" /> 140 <Compile Include="Push\Erc\Interfaces\IReadOnlyErcOptionConstants.cs" /> 141 <Compile Include="Push\Erc\Interfaces\IReadOnlyErcOptionRange.cs" /> 142 <Compile Include="Push\Erc\Interfaces\IReadOnlyFloatErcOptions.cs" /> 143 <Compile Include="Push\Erc\Interfaces\IReadOnlyIntegerErcOptions.cs" /> 144 <Compile Include="Push\Erc\Interfaces\IReadOnlyErcOptions.cs" /> 145 <Compile Include="Push\Erc\Interfaces\IReadOnlyNameErcOptions.cs" /> 146 <Compile Include="Push\Erc\Interfaces\IReadOnlyStringErcOptions.cs" /> 147 <Compile Include="Push\Erc\ErcOptions.cs" /> 148 <Compile Include="Push\Erc\NameErcOptions.cs" /> 149 <Compile Include="Push\Erc\StringErcOptions.cs" /> 127 150 <Compile Include="Push\Exporter\Exporter.cs" /> 128 151 <Compile Include="Push\Expressions\BooleanExpressions.cs" /> … … 134 157 <Compile Include="Push\Expressions\DoTimesExpressions.cs" /> 135 158 <Compile Include="Push\Expressions\DuplicateExpressions.cs" /> 136 <Compile Include="Push\Expressions\EmptyExpresssion s.cs" />159 <Compile Include="Push\Expressions\EmptyExpresssion.cs" /> 137 160 <Compile Include="Push\Expressions\EqualsExpressions.cs" /> 138 161 <Compile Include="Push\Expressions\ExecExpressions.cs" /> … … 155 178 <Compile Include="Push\Expressions\StatelessExpression.cs" /> 156 179 <Compile Include="Push\Expressions\StringExpressions.cs" /> 180 <Compile Include="Push\Expressions\VectorContainsExpressions.cs" /> 181 <Compile Include="Push\Expressions\VectorEmptyExpressions.cs" /> 182 <Compile Include="Push\Expressions\VectorIndexOfExpressions.cs" /> 183 <Compile Include="Push\Expressions\VectorIterateExpressions.cs" /> 184 <Compile Include="Push\Expressions\VectorLengthExpressions.cs" /> 185 <Compile Include="Push\Expressions\VectorNthExpressions.cs" /> 186 <Compile Include="Push\Expressions\VectorLastExpressions.cs" /> 187 <Compile Include="Push\Expressions\VectorFirstExpressions.cs" /> 188 <Compile Include="Push\Expressions\VectorButLastExpressions.cs" /> 189 <Compile Include="Push\Expressions\VectorRemoveExpressions.cs" /> 190 <Compile Include="Push\Expressions\VectorReplaceFirstExpressions.cs" /> 191 <Compile Include="Push\Expressions\VectorReplaceExpressions.cs" /> 192 <Compile Include="Push\Expressions\VectorSetExpressions.cs" /> 193 <Compile Include="Push\Expressions\VectorOccurrenceOfExpressions.cs" /> 194 <Compile Include="Push\Expressions\VectorPushAllExpressions.cs" /> 195 <Compile Include="Push\Expressions\VectorRestExpressions.cs" /> 196 <Compile Include="Push\Expressions\VectorReverseExpressions.cs" /> 197 <Compile Include="Push\Expressions\VectorSubExpressions.cs" /> 157 198 <Compile Include="Push\Expressions\SwapExpressions.cs" /> 199 <Compile Include="Push\Expressions\VectorConcatExpressions.cs" /> 200 <Compile Include="Push\Expressions\VectorConjExpressions.cs" /> 201 <Compile Include="Push\Expressions\VectorTakeExpressions.cs" /> 158 202 <Compile Include="Push\Expressions\YankDuplicateExpressions.cs" /> 159 203 <Compile Include="Push\Expressions\YankExpressions.cs" /> 160 <Compile Include="Push\Generators\LinearCodeGenerator.cs" /> 161 <Compile Include="Push\Generators\RecursiveCodeGenerator.cs" /> 162 <Compile Include="Push\Generators\NameGenerator.cs" /> 204 <Compile Include="Push\Extensions\CollectionExtensions.cs" /> 205 <Compile Include="Push\Extensions\ControlExntensions.cs" /> 206 <Compile Include="Push\Generators\CodeGenerator\CodeGeneratorUtils.cs" /> 207 <Compile Include="Push\Generators\CodeGenerator\LinearCodeGenerator.cs" /> 208 <Compile Include="Push\Generators\CodeGenerator\RecursiveCodeGenerator.cs" /> 209 <Compile Include="Push\Generators\ErcUtils.cs" /> 210 <Compile Include="Push\Generators\StringGenerator.cs" /> 211 <Compile Include="Push\Interpreter\Extensions.cs" /> 212 <Compile Include="Push\Interpreter\IInternalPushInterpreter.cs" /> 163 213 <Compile Include="Push\Interpreter\InterpreterPoolContainer.cs" /> 164 214 <Compile Include="Push\Interpreter\IPushInterpreter.cs" /> … … 171 221 <Compile Include="Push\Creator\IPushProgramCreator.cs" /> 172 222 <Compile Include="Push\Problem\DataBounds.cs" /> 173 <Compile Include="Push\Problem\PushEncoding.cs" /> 223 <Compile Include="Push\Problem\EvaluationResult.cs" /> 224 <Compile Include="Push\Problem\IndividualMapper.cs" /> 174 225 <Compile Include="Push\Problem\PushEvaluator.cs" /> 175 226 <Compile Include="Push\Problem\PushProblem.cs" /> 176 227 <Compile Include="Properties\AssemblyInfo.cs" /> 177 228 <Compile Include="Push\Problem\PushSolution.cs" /> 229 <Compile Include="Push\Data\Pool\PooledObject.cs" /> 230 <Compile Include="Push\Selector\ICaseSingleObjectiveSelector.cs" /> 231 <Compile Include="Push\Selector\LexicaseSelector.cs" /> 178 232 <Compile Include="Push\Simplifier\Simplifier.cs" /> 179 <Compile Include="Push\Stack\IStack.cs" /> 233 <Compile Include="Push\Stack\IPushStack.cs" /> 234 <Compile Include="Push\Stack\IPushStackBase.cs" /> 180 235 <Compile Include="Push\Stack\PushStack.cs" /> 181 236 <Compile Include="Push\Stack\StackTypes.cs" /> … … 211 266 </ProjectReference> 212 267 </ItemGroup> 213 <ItemGroup />214 268 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 215 269 <PropertyGroup> -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/HeuristicLab.Problems.ProgramSynthesis.csproj.user
r14777 r14834 2 2 <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 3 <PropertyGroup> 4 <ProjectView> ShowAllFiles</ProjectView>4 <ProjectView>ProjectFiles</ProjectView> 5 5 </PropertyGroup> 6 6 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Attributes/PushExpressionAttriubte.cs
r14777 r14834 6 6 [AttributeUsage(AttributeTargets.Class)] 7 7 public class PushExpressionAttribute : Attribute { 8 public readonly StackTypes StackType s;8 public readonly StackTypes StackType; 9 9 public readonly StackTypes AdditionalStackDependencies; 10 10 public readonly string ExpressionName; 11 11 12 public PushExpressionAttribute(StackTypes stackType s, string expressionName, StackTypes additionalStackDependencies = default(StackTypes)) {13 this.StackType s = stackTypes;12 public PushExpressionAttribute(StackTypes stackType, string expressionName, StackTypes additionalStackDependencies = default(StackTypes)) { 13 this.StackType = stackType; 14 14 this.AdditionalStackDependencies = additionalStackDependencies; 15 15 this.ExpressionName = expressionName; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IEnabledExpressionsConfiguration.cs
r14777 r14834 22 22 IList<string> EnabledExpressions { get; } 23 23 24 void EnableStack(StackTypes types); 25 void DisableStack(StackTypes types); 24 void EnableStack(StackTypes types, bool enableExpressions = false); 25 void DisableStack(StackTypes type, bool disableExpressions = false); 26 void SetStack(StackTypes type, bool state, bool cascadeForExpressions = false); 26 27 void EnableExpressionOfStack(StackTypes types); 27 28 void DisableExpressionOfStack(StackTypes types); 28 void EnableExpression(string name); 29 void DisableExpression(string name); 30 void EnableExpression<T>() where T : Expression; 31 void DisableExpression<T>() where T : Expression; 29 void EnableExpression(string name, bool enableStackIfDisabled = false); 30 void DisableExpression(string name, bool disableStackIfEnabled = false); 31 void SetExpression(string name, bool state, bool cascadeForStack = false); 32 void SetExpression<T>(bool state, bool cascadeForStack = false) where T : Expression; 33 void EnableExpression<T>(bool enableStackIfDisabled = false) where T : Expression; 34 void DisableExpression<T>(bool disableStackIfEnabled = false) where T : Expression; 32 35 } 33 36 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/IReadonlyPushConfiguration.cs
r14777 r14834 3 3 4 4 using HeuristicLab.Common; 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Erc.Interfaces; 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 5 7 6 8 public interface IReadOnlyPushConfiguration : IDeepCloneable { 7 bool IsBooleanStackEnabled { get; } 8 bool IsIntegerStackEnabled { get; } 9 bool IsFloatStackEnabled { get; } 10 bool IsCharStackEnabled { get; } 11 bool IsStringStackEnabled { get; } 12 bool IsCodeStackEnabled { get; } 13 bool IsNameStackEnabled { get; } 14 double ErcProbability { get; } 9 IReadOnlyDictionary<StackTypes, bool> EnabledStacks { get; } 15 10 int EvalPushLimit { get; } 16 11 int MaxDepth { get; } 17 12 int MaxStringLength { get; } 13 int MaxVectorLength { get; } 18 14 int MaxPointsInProgram { get; } 19 15 int MaxPointsInRandomExpression { get; } 20 16 bool TopLevelPushCode { get; } 21 17 bool TopLevelPopCode { get; } 22 int MinRandomInteger { get; } 23 int MaxRandomInteger { get; } 24 double MinRandomFloat { get; } 25 double MaxRandomFloat { get; } 26 double NewErcNameProbability { get; } 27 18 IReadOnlyErcOptions ErcOptions { get; } 28 19 IReadOnlyList<string> EnabledExpressions { get; } 29 20 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Configuration/PushConfiguration.cs
r14777 r14834 3 3 using System.Collections.Generic; 4 4 using System.Linq; 5 6 using HeuristicLab.Common; 7 using HeuristicLab.Core; 8 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 5 using Attributes; 6 using Common; 7 using Core; 8 using Erc; 9 using Erc.Interfaces; 10 using Expressions; 11 using Persistence.Default.CompositeSerializers.Storable; 12 using Stack; 12 13 13 14 [StorableClass] 14 public class PushConfiguration : NamedItem, IReadOnlyPushConfiguration, IEnabledExpressionsConfiguration { 15 private static readonly string itemName = "Push Configuration"; 15 public class PushConfiguration : ParameterizedNamedItem, IReadOnlyPushConfiguration, IEnabledExpressionsConfiguration { 16 17 16 18 17 19 public PushConfiguration() { 18 this.EvalPushLimit = 1024; 19 this.MaxPointsInProgram = 128; 20 this.MaxPointsInRandomExpression = 64; 21 this.MaxDepth = 4; 22 this.MaxStringLength = 64; 23 24 this.TopLevelPushCode = true; 25 this.TopLevelPopCode = false; 26 27 this.MinRandomInteger = -128; 28 this.MaxRandomInteger = 128; 29 this.MinRandomFloat = -128D; 30 this.MaxRandomFloat = 128D; 31 this.NewErcNameProbability = 0.5; 32 this.ErcProbability = 0.2; 33 34 this.enabledExpressions = ExpressionTable.ExpressionNames.ToList(); 20 Name = "Push Configuration"; 21 22 enabledExpressions = ExpressionTable.ExpressionNames.ToList(); 23 EnabledStacks = new Dictionary<StackTypes, bool>(); 24 25 ErcOptions = new ErcOptions(); 26 EvalPushLimit = 1024; 27 MaxPointsInProgram = 128; 28 TopLevelPushCode = true; 29 TopLevelPopCode = false; 30 MaxPointsInRandomExpression = 64; 31 MaxStringLength = 32; 32 MaxVectorLength = 64; 33 MaxDepth = 32; 34 35 InitEnabledStacks(); 36 } 37 38 private void InitEnabledStacks(bool state = true) { 39 foreach (StackTypes type in Enum.GetValues(typeof(StackTypes))) { 40 if (!EnabledStacks.ContainsKey(type)) 41 EnabledStacks.Add(type, state); 42 } 35 43 } 36 44 … … 41 49 42 50 public PushConfiguration(PushConfiguration origin, Cloner cloner) : base(origin, cloner) { 43 this.EnabledExpressions = origin.EnabledExpressions.ToList();44 45 this.EvalPushLimit = origin.EvalPushLimit; 46 this.MaxPointsInProgram = origin.MaxPointsInProgram;47 this.MaxPointsInRandomExpression = origin.MaxPointsInRandomExpression;48 this.MaxDepth = origin.MaxDepth;49 this.MaxStringLength = origin.MaxStringLength;50 51 this.TopLevelPushCode = origin.TopLevelPushCode;52 this.TopLevelPopCode = origin.TopLevelPopCode;53 54 this.MinRandomInteger = origin.MinRandomInteger;55 this.MaxRandomInteger = origin.MaxRandomInteger;56 this.MinRandomFloat = origin.MinRandomFloat; 57 this.MaxRandomFloat = origin.MaxRandomFloat;58 this.NewErcNameProbability = origin.NewErcNameProbability;59 this.ErcProbability = origin.ErcProbability;60 61 this.isBooleanStackEnabled = origin.IsBooleanStackEnabled;62 this.isIntegerStackEnabled = origin.IsIntegerStackEnabled;63 this.isFloatStackEnabled = origin.IsFloatStackEnabled; 64 this.isNameStackEnabled = origin.IsNameStackEnabled;65 this.isCodeStackEnabled = origin.IsCodeStackEnabled;66 this.isExecStackEnabled = origin.IsExecStackEnabled; 67 }51 enabledExpressions = origin.EnabledExpressions.ToList(); 52 EnabledStacks = origin.EnabledStacks.ToDictionary(x => x.Key, x => x.Value); 53 54 ErcOptions = cloner.Clone(origin.ErcOptions); 55 EvalPushLimit = origin.EvalPushLimit; 56 MaxPointsInProgram = origin.MaxPointsInProgram; 57 MaxPointsInRandomExpression = origin.MaxPointsInRandomExpression; 58 TopLevelPushCode = origin.TopLevelPushCode; 59 TopLevelPopCode = origin.TopLevelPopCode; 60 MaxStringLength = origin.MaxStringLength; 61 MaxVectorLength = origin.MaxVectorLength; 62 MaxDepth = origin.MaxDepth; 63 } 64 65 [StorableHook(HookType.AfterDeserialization)] 66 // ReSharper disable once UnusedMember.Local 67 private void AfterDeserialization() { 68 // Ensures that all types added after last serialization are available in enabledStacks 69 InitEnabledStacks(false); 70 } 71 72 [Storable] 73 public IDictionary<StackTypes, bool> EnabledStacks { get; set; } 74 75 IReadOnlyDictionary<StackTypes, bool> IReadOnlyPushConfiguration.EnabledStacks { get { return EnabledStacks as IReadOnlyDictionary<StackTypes, bool>; } } 68 76 69 77 public event EventHandler<EnabledExpressionsChangedEventArgs> EnabledExpressionsChanged; 70 78 71 72 private readonly List<string> enabledExpressions = new List<string>(); 73 74 [Storable] 79 [Storable] 80 private readonly List<string> enabledExpressions; 81 75 82 public IList<string> EnabledExpressions 76 83 { 77 get 78 { 79 return enabledExpressions; 80 } 84 get { return enabledExpressions; } 81 85 set 82 86 { 87 var removedExpressions = enabledExpressions.ToArray(); 83 88 enabledExpressions.Clear(); 84 89 enabledExpressions.AddRange(value); 85 } 86 } 87 88 IReadOnlyList<string> IReadOnlyPushConfiguration.EnabledExpressions { get { return this.EnabledExpressions as IReadOnlyList<string>; } } 89 90 [Storable] 91 private bool isBooleanStackEnabled = true; 92 93 public bool IsBooleanStackEnabled 94 { 95 get 96 { 97 return this.isBooleanStackEnabled; 98 } 99 100 set 101 { 102 if (this.isBooleanStackEnabled == value) return; 103 104 this.isBooleanStackEnabled = value; 105 106 if (this.isBooleanStackEnabled) EnableExpressionOfStack(StackTypes.Boolean); 107 else DisableExpressionOfStack(StackTypes.Boolean); 108 } 109 } 110 111 [Storable] 112 private bool isIntegerStackEnabled = true; 113 114 public bool IsIntegerStackEnabled 115 { 116 get 117 { 118 return this.isIntegerStackEnabled; 119 } 120 121 set 122 { 123 if (this.isIntegerStackEnabled == value) return; 124 125 this.isIntegerStackEnabled = value; 126 127 if (this.isIntegerStackEnabled) EnableExpressionOfStack(StackTypes.Integer); 128 else DisableExpressionOfStack(StackTypes.Integer); 129 } 130 } 131 132 [Storable] 133 private bool isFloatStackEnabled = true; 134 135 public bool IsFloatStackEnabled 136 { 137 get 138 { 139 return this.isFloatStackEnabled; 140 } 141 142 set 143 { 144 if (this.isFloatStackEnabled == value) return; 145 146 this.isFloatStackEnabled = value; 147 148 if (this.isFloatStackEnabled) EnableExpressionOfStack(StackTypes.Float); 149 else DisableExpressionOfStack(StackTypes.Float); 150 } 151 } 152 153 [Storable] 154 private bool isCodeStackEnabled = true; 155 156 public bool IsCodeStackEnabled 157 { 158 get 159 { 160 return this.isCodeStackEnabled; 161 } 162 163 set 164 { 165 if (this.isCodeStackEnabled == value) return; 166 167 this.isCodeStackEnabled = value; 168 169 if (this.isCodeStackEnabled) EnableExpressionOfStack(StackTypes.Code); 170 else DisableExpressionOfStack(StackTypes.Code); 171 } 172 } 173 174 [Storable] 175 private bool isExecStackEnabled = true; 176 177 public bool IsExecStackEnabled 178 { 179 get 180 { 181 return this.isExecStackEnabled; 182 } 183 184 set 185 { 186 if (this.isExecStackEnabled == value) return; 187 188 this.isExecStackEnabled = value; 189 190 if (this.isExecStackEnabled) EnableExpressionOfStack(StackTypes.Exec); 191 else DisableExpressionOfStack(StackTypes.Exec); 192 } 193 } 194 195 [Storable] 196 private bool isCharStackEnabled = true; 197 198 public bool IsCharStackEnabled 199 { 200 get 201 { 202 return this.isCharStackEnabled; 203 } 204 205 set 206 { 207 if (this.isCharStackEnabled == value) return; 208 209 this.isCharStackEnabled = value; 210 211 if (this.isCharStackEnabled) EnableExpressionOfStack(StackTypes.Char); 212 else DisableExpressionOfStack(StackTypes.Char); 213 } 214 } 215 216 [Storable] 217 private bool isStringStackEnabled = true; 218 219 public bool IsStringStackEnabled 220 { 221 get 222 { 223 return this.isStringStackEnabled; 224 } 225 226 set 227 { 228 if (this.isStringStackEnabled == value) return; 229 230 this.isStringStackEnabled = value; 231 232 if (this.isStringStackEnabled) EnableExpressionOfStack(StackTypes.String); 233 else DisableExpressionOfStack(StackTypes.String); 234 } 235 } 236 237 [Storable] 238 private bool isNameStackEnabled = true; 239 240 public bool IsNameStackEnabled 241 { 242 get 243 { 244 return this.isNameStackEnabled; 245 } 246 247 set 248 { 249 if (this.isNameStackEnabled == value) return; 250 251 this.isNameStackEnabled = value; 252 253 if (this.isNameStackEnabled) EnableExpressionOfStack(StackTypes.Name); 254 else DisableExpressionOfStack(StackTypes.Name); 255 } 256 } 257 258 [Storable] 259 public double ErcProbability { get; set; } 90 91 if (EnabledExpressionsChanged != null) { 92 EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(value, removedExpressions)); 93 } 94 } 95 } 96 97 IReadOnlyList<string> IReadOnlyPushConfiguration.EnabledExpressions { get { return EnabledExpressions as IReadOnlyList<string>; } } 98 99 [Storable] 100 public ErcOptions ErcOptions { get; set; } 101 102 IReadOnlyErcOptions IReadOnlyPushConfiguration.ErcOptions { get { return ErcOptions; } } 260 103 261 104 /// <summary> … … 309 152 public int MaxStringLength { get; set; } 310 153 311 /// <summary> 312 /// The minimum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND. 313 /// </summary> 314 [Storable] 315 public int MinRandomInteger { get; set; } 316 317 /// <summary> 318 /// The maximum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND. 319 /// </summary> 320 [Storable] 321 public int MaxRandomInteger { get; set; } 322 323 /// <summary> 324 /// The minimum FLOAT that will be produced as an ephemeral random FLOAT constant or from a call to FLOAT.RAND. 325 /// </summary> 326 [Storable] 327 public double MinRandomFloat { get; set; } 328 329 /// <summary> 330 /// The maximum FLOAT that will be produced as an ephemeral random FLOAT constant or from a call to FLOAT.RAND. 331 /// </summary> 332 [Storable] 333 public double MaxRandomFloat { get; set; } 334 335 /// <summary> 336 /// The probability that the selection of the ephemeral 337 /// random NAME constant for inclusion in randomly generated code will produce a new name 338 /// (rather than a name that was previously generated). 339 /// </summary> 340 [Storable] 341 public double NewErcNameProbability { get; set; } 154 [Storable] 155 public int MaxVectorLength { get; set; } 342 156 343 157 public void EnableExpressionOfStack(StackTypes types) { 344 foreach (var name in ExpressionTable.StackTypeToNamesTable[types]) { 345 EnableExpression(name); 158 var names = ExpressionTable.StackTypeToNamesTable[types] 159 .Except(EnabledExpressions) 160 .ToArray(); 161 162 foreach (var name in names) 163 EnabledExpressions.Add(name); 164 165 if (EnabledExpressionsChanged != null) { 166 EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(names, new string[0])); 346 167 } 347 168 } 348 169 349 170 public void DisableExpressionOfStack(StackTypes types) { 350 foreach (var name in ExpressionTable.StackTypeToNamesTable[types]) { 351 DisableExpression(name); 352 } 353 } 354 355 public void EnableExpression(string name) { 171 var names = ExpressionTable.StackTypeToNamesTable[types] 172 .Intersect(EnabledExpressions) 173 .ToArray(); 174 175 foreach (var name in names) 176 EnabledExpressions.Remove(name); 177 178 if (EnabledExpressionsChanged != null) { 179 EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs(new string[0], names)); 180 } 181 } 182 183 public void EnableExpression(string name, bool enableStackIfDisabled = false) { 356 184 if (EnabledExpressions.Contains(name)) return; 357 185 358 186 EnabledExpressions.Add(name); 359 187 360 if (EnabledExpressionsChanged != null) { 361 EnabledExpressionsChanged.Invoke(this, new EnabledExpressionsChangedEventArgs( 188 if (enableStackIfDisabled) { 189 var type = ExpressionTable.TypeToNameTable.Single(x => x.Value == name).Key; 190 var attribute = ExpressionTable.TypeToAttributeTable[type]; 191 EnabledStacks[attribute.StackType] = true; 192 } 193 194 if (EnabledExpressionsChanged != null) { 195 EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs( 362 196 new[] { name }, 363 197 new string[0])); … … 365 199 } 366 200 367 public void DisableExpression(string name ) {201 public void DisableExpression(string name, bool disableStackIfEnabled = false) { 368 202 if (!EnabledExpressions.Contains(name)) return; 369 203 370 204 EnabledExpressions.Remove(name); 371 205 372 if (EnabledExpressionsChanged != null) { 373 EnabledExpressionsChanged.Invoke(this, new EnabledExpressionsChangedEventArgs( 206 if (disableStackIfEnabled) { 207 var type = ExpressionTable.TypeToNameTable.Single(x => x.Value == name).Key; 208 var attribute = ExpressionTable.TypeToAttributeTable[type]; 209 EnabledStacks[attribute.StackType] = false; 210 } 211 212 if (EnabledExpressionsChanged != null) { 213 EnabledExpressionsChanged(this, new EnabledExpressionsChangedEventArgs( 374 214 new string[0], 375 215 new[] { name })); … … 377 217 } 378 218 379 public void EnableExpression<T>( ) where T : Expression {219 public void EnableExpression<T>(bool enableStackIfDisabled = false) where T : Expression { 380 220 var attribute = (PushExpressionAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(PushExpressionAttribute)); 381 EnableExpression(attribute.ExpressionName );382 } 383 384 public void DisableExpression<T>( ) where T : Expression {221 EnableExpression(attribute.ExpressionName, enableStackIfDisabled); 222 } 223 224 public void DisableExpression<T>(bool disableStackIfEnabled = false) where T : Expression { 385 225 var attribute = (PushExpressionAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(PushExpressionAttribute)); 386 DisableExpression(attribute.ExpressionName); 387 } 388 389 public void EnableStack(StackTypes types) { 390 SetStack(types, true); 391 } 392 393 public void DisableStack(StackTypes types) { 394 SetStack(types, false); 395 } 396 397 public void SetStack(StackTypes types, bool value) { 398 switch (types) { 399 case StackTypes.Boolean: 400 IsBooleanStackEnabled = value; 401 break; 402 case StackTypes.Integer: 403 IsIntegerStackEnabled = value; 404 break; 405 case StackTypes.Float: 406 IsFloatStackEnabled = value; 407 break; 408 case StackTypes.Name: 409 IsNameStackEnabled = value; 410 break; 411 case StackTypes.Code: 412 IsCodeStackEnabled = value; 413 break; 414 case StackTypes.Exec: 415 this.IsExecStackEnabled = value; 416 break; 417 case StackTypes.Char: 418 this.IsCharStackEnabled = value; 419 break; 420 case StackTypes.String: 421 this.IsStringStackEnabled = value; 422 break; 423 default: throw new InvalidOperationException("Stacktype unknown"); 424 } 226 DisableExpression(attribute.ExpressionName, disableStackIfEnabled); 227 } 228 229 public void SetExpression(string name, bool state, bool cascadeForStack = false) { 230 if (state) EnableExpression(name, cascadeForStack); 231 else DisableExpression(name, cascadeForStack); 232 } 233 234 public void SetExpression<T>(bool state, bool cascadeForStack = false) where T : Expression { 235 if (state) EnableExpression<T>(cascadeForStack); 236 else DisableExpression<T>(cascadeForStack); 237 } 238 239 public void EnableStack(StackTypes type, bool enableExpressions = false) { 240 EnabledStacks[type] = true; 241 242 if (enableExpressions) 243 EnableExpressionOfStack(type); 244 } 245 246 public void DisableStack(StackTypes type, bool disableExpressions = false) { 247 EnabledStacks[type] = false; 248 249 if (disableExpressions) 250 DisableExpressionOfStack(type); 251 } 252 253 public void SetStack(StackTypes type, bool state, bool cascadeForExpressions = false) { 254 if (state) EnableStack(type, cascadeForExpressions); 255 else DisableStack(type, cascadeForExpressions); 425 256 } 426 257 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Creator/IPushProgramCreator.cs
r14777 r14834 7 7 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Creator { 8 8 using HeuristicLab.Core; 9 using HeuristicLab.Encodings.IntegerVectorEncoding; 9 10 using HeuristicLab.Optimization; 10 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 11 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 12 13 13 public interface IPushProgramCreator : ISolutionCreator 14 { 14 public interface IPushProgramCreator : IIntegerVectorCreator { 15 15 PushProgram CreateProgram(IRandom random, IReadOnlyPushConfiguration config); 16 16 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Creator/PointsBasedPushProgramCreator.cs
r14777 r14834 1 //namespace HeuristicLab.Problems.ProgramSynthesis.Push.Creator {1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Creator { 2 2 3 // using HeuristicLab.Common;4 // using HeuristicLab.Core;5 // using HeuristicLab.Operators;6 // using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;7 // using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;8 // using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;9 // using HeuristicLab.Problems.ProgramSynthesis.Push.Generators;3 using Common; 4 using Configuration; 5 using Core; 6 using Encodings.IntegerVectorEncoding; 7 using Erc; 8 using Expressions; 9 using Generators.CodeGenerator; 10 10 11 // [Item("PointBasedPushProgramCreator", "Creates a Push program whereby points specify the max size but not the min size of the program.")] 12 // [StorableClass] 13 // public class PointsBasedPushProgramCreator : InstrumentedOperator, IPushProgramCreator { 11 using HeuristicLab.Data; 14 12 15 // public PointsBasedPushProgramCreator(bool deserializing) : base(deserializing) { } 13 using Persistence.Default.CompositeSerializers.Storable; 16 14 17 // public PointsBasedPushProgramCreator(PointsBasedPushProgramCreator origin, Cloner cloner) : base(origin, cloner) { 15 [Item("PointBasedPushProgramCreator", "Creates a Push program whereby points specify the max size but not the min size of the program.")] 16 [StorableClass] 17 public class PointsBasedPushProgramCreator : UniformRandomIntegerVectorCreator, IPushProgramCreator { 18 //private const string ErcOptionsParameterName = "ERC Options"; 18 19 19 // } 20 public PointsBasedPushProgramCreator(ErcOptions ercOptions) { 21 //Parameters.Add(new FixedValueParameter<ErcOptions>(ErcOptionsParameterName, ercOptions)); 22 } 20 23 21 // public override IDeepCloneable Clone(Cloner cloner) { 22 // return new PointsBasedPushProgramCreator(this, cloner); 23 // } 24 [StorableConstructor] 25 public PointsBasedPushProgramCreator(bool deserializing) : base(deserializing) { } 24 26 25 // public PushProgram CreateProgram(IRandom random, IReadOnlyPushConfiguration config) { 26 // return CodeGenerator.RandomProgram(10, random, config); 27 // } 28 // } 29 //} 27 public PointsBasedPushProgramCreator(PointsBasedPushProgramCreator origin, Cloner cloner) : base(origin, cloner) { 28 } 29 30 public override IDeepCloneable Clone(Cloner cloner) { 31 return new PointsBasedPushProgramCreator(this, cloner); 32 } 33 34 public PushProgram CreateProgram(IRandom random, IReadOnlyPushConfiguration config) { 35 return LinearCodeGenerator.RandomProgram(LengthParameter.Value.Value, random, config); 36 } 37 38 protected override IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds) { 39 var x = random.Next(length.Value + 1); 40 return base.Create(random, new IntValue(x), bounds); 41 } 42 } 43 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Pool/ManagedPoolProvider.cs
r14777 r14834 5 5 using System.Collections.Concurrent; 6 6 using System.IO; 7 using System. Linq;7 using System.Reflection; 8 8 using System.Runtime.Serialization.Formatters.Binary; 9 9 … … 18 18 private byte[] dummyPartition; 19 19 20 private static readonly FieldInfo InternalListArrayProperty = typeof(List<T[]>).GetField( 21 "_items", 22 BindingFlags.NonPublic | BindingFlags.Instance); 23 20 24 private readonly Func<T> factory; 21 25 … … 29 33 this.factory = factory; 30 34 31 managedPools = new ObjectPool<IManagedPool<T>>(() => new ManagedPool <T>(this), MaxParitionCount);35 managedPools = new ObjectPool<IManagedPool<T>>(() => new ManagedPool(this)); 32 36 } 33 37 public int InstanceCount { get { return partitions.Count * PartitionSize; } } … … 46 50 } 47 51 48 public void ReleasePartitions( params T[][] partition) {49 if (partitions.Count < = MaxParitionCount && partition.Length > 0)50 partitions.PushRange( partition);52 public void ReleasePartitions(List<T[]> releasedPartitions) { 53 if (partitions.Count < MaxParitionCount) 54 partitions.PushRange((T[][])InternalListArrayProperty.GetValue(releasedPartitions), 0, releasedPartitions.Count); 51 55 } 52 56 … … 71 75 } 72 76 73 private class ManagedPool <T> : IManagedPool<T> where T : class, IPooledObject{77 private class ManagedPool : IManagedPool<T> { 74 78 private readonly ManagedPoolProvider<T> provider; 75 private readonly IList<T[]> partitions = new List<T[]>();79 private readonly List<T[]> partitions = new List<T[]>(); 76 80 private T[] currentPartition; 77 81 private int entryIndex; … … 82 86 } 83 87 84 public T Get(bool reset = true) {88 public T Get(bool resetEntry = true) { 85 89 if (entryIndex == provider.PartitionSize) { 86 90 currentPartition = provider.GetPartition(); … … 90 94 91 95 var entry = currentPartition[entryIndex++]; 92 93 if (reset) entry.Reset(); 94 96 if (resetEntry) entry.Reset(); 95 97 return entry; 96 98 } 97 99 98 100 public void Dispose() { 99 provider.ReleasePartitions(partitions.ToArray()); 100 partitions.Clear(); 101 entryIndex = provider.PartitionSize; 101 if (partitions.Count > 0) { 102 provider.ReleasePartitions(partitions); 103 partitions.Clear(); 104 currentPartition = null; 105 entryIndex = provider.PartitionSize; 106 } 107 102 108 provider.managedPools.Free(this); 103 109 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Tree/TreeExtensions.cs
r14777 r14834 27 27 } 28 28 29 public static IEnumerable<TreeNode<T>> Depth First<T>(this TreeNode<T> node) {29 public static IEnumerable<TreeNode<T>> DepthLast<T>(this TreeNode<T> node) { 30 30 foreach (var child in node.Children) { 31 31 if (child.Children.Count > 0) { 32 foreach (var subChild in child.Depth First()) {32 foreach (var subChild in child.DepthLast()) { 33 33 yield return subChild; 34 34 } … … 37 37 } 38 38 39 public static IEnumerable<T> Depth First<T>(this TreeNode<T> node, Func<IEnumerable<T>, T> resolveParent) {39 public static IEnumerable<T> DepthLast<T>(this TreeNode<T> node, Func<IEnumerable<T>, T> resolveParent) { 40 40 foreach (var child in node.Children) { 41 41 if (child.Children.Count > 0) { 42 var subExpressions = child.Depth First(resolveParent);42 var subExpressions = child.DepthLast(resolveParent); 43 43 yield return resolveParent(subExpressions); 44 44 } else yield return child.Value; … … 47 47 48 48 public static PushProgram ToPushProgram(this TreeNode<Expression> tree, Func<Expression, bool> condition = null) { 49 var expressions = tree.Depth First(e => ResolveProgram(e, condition));49 var expressions = tree.DepthLast(e => ResolveProgram(e, condition)); 50 50 51 51 return ResolveProgram(expressions, condition); -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/BooleanExpressions.cs
r14777 r14834 11 11 [PushExpression(StackTypes.Boolean, "BOOLEAN.AND")] 12 12 public class BooleanAndExpression : PushResultExpression<bool> { 13 public override bool Eval(I PushInterpreter interpreter) {13 public override bool Eval(IInternalPushInterpreter interpreter) { 14 14 return Eval(interpreter.BooleanStack, 2, values => values[0] && values[1]); 15 15 } … … 21 21 [PushExpression(StackTypes.Boolean, "BOOLEAN.OR")] 22 22 public class BooleanOrExpression : PushResultExpression<bool> { 23 public override bool Eval(I PushInterpreter interpreter) {23 public override bool Eval(IInternalPushInterpreter interpreter) { 24 24 return Eval(interpreter.BooleanStack, 2, values => values[0] || values[1]); 25 25 } … … 31 31 [PushExpression(StackTypes.Boolean, "BOOLEAN.NOT")] 32 32 public class BooleanNotExpression : PushResultExpression<bool> { 33 public override bool Eval(I PushInterpreter interpreter) {33 public override bool Eval(IInternalPushInterpreter interpreter) { 34 34 return Eval(interpreter.BooleanStack, 1, values => !values[0]); 35 35 } … … 41 41 [PushExpression(StackTypes.Boolean, "BOOLEAN.FROMFLOAT", StackTypes.Float)] 42 42 public class BooleanFromFloatExpression : StatelessExpression { 43 public override bool Eval(I PushInterpreter interpreter) {43 public override bool Eval(IInternalPushInterpreter interpreter) { 44 44 if (interpreter.FloatStack.Count == 0) return false; 45 45 … … 56 56 [PushExpression(StackTypes.Boolean, "BOOLEAN.FROMINTEGER", StackTypes.Integer)] 57 57 public class BooleanFromIntegerExpression : StatelessExpression { 58 public override bool Eval(I PushInterpreter interpreter) {58 public override bool Eval(IInternalPushInterpreter interpreter) { 59 59 if (interpreter.IntegerStack.Count == 0) return false; 60 60 … … 71 71 [PushExpression(StackTypes.Boolean, "BOOLEAN.INVERT_FIRST_THEN_AND")] 72 72 public class BooleanInvertFirstThenAnd : PushResultExpression<bool> { 73 public override bool Eval(I PushInterpreter interpreter) {73 public override bool Eval(IInternalPushInterpreter interpreter) { 74 74 return Eval(interpreter.BooleanStack, 2, values => !values[0] && values[1]); 75 75 } … … 81 81 [PushExpression(StackTypes.Boolean, "BOOLEAN.INVERT_SECOND_THEN_AND")] 82 82 public class BooleanInvertSecondThenAnd : PushResultExpression<bool> { 83 public override bool Eval(I PushInterpreter interpreter) {83 public override bool Eval(IInternalPushInterpreter interpreter) { 84 84 return Eval(interpreter.BooleanStack, 2, values => values[0] && !values[1]); 85 85 } … … 92 92 [PushExpression(StackTypes.Boolean, "BOOLEAN.XOR")] 93 93 public class BooleanXorExpression : PushResultExpression<bool> { 94 public override bool Eval(I PushInterpreter interpreter) {94 public override bool Eval(IInternalPushInterpreter interpreter) { 95 95 return Eval(interpreter.BooleanStack, 2, values => values[0] ^ values[1]); 96 96 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/CharExpressions.cs
r14777 r14834 8 8 [PushExpression(StackTypes.Char, "CHAR.ISWHITESPACE", StackTypes.Boolean)] 9 9 public class CharIsWhitespaceExpression : StatelessExpression { 10 public override bool Eval(I PushInterpreter interpreter) {10 public override bool Eval(IInternalPushInterpreter interpreter) { 11 11 if (interpreter.CharStack.IsEmpty) return false; 12 12 … … 19 19 [PushExpression(StackTypes.Char, "CHAR.ISLETTER", StackTypes.Boolean)] 20 20 public class CharIsLetterExpression : StatelessExpression { 21 public override bool Eval(I PushInterpreter interpreter) {21 public override bool Eval(IInternalPushInterpreter interpreter) { 22 22 if (interpreter.CharStack.IsEmpty) return false; 23 23 … … 30 30 [PushExpression(StackTypes.Char, "CHAR.ISDIGIT", StackTypes.Boolean)] 31 31 public class CharIsDigitExpression : StatelessExpression { 32 public override bool Eval(I PushInterpreter interpreter) {32 public override bool Eval(IInternalPushInterpreter interpreter) { 33 33 if (interpreter.CharStack.IsEmpty) return false; 34 34 … … 41 41 [PushExpression(StackTypes.Char, "CHAR.FROMINTEGER", StackTypes.Integer)] 42 42 public class CharFromIntegerExpression : StatelessExpression { 43 public override bool Eval(I PushInterpreter interpreter) {43 public override bool Eval(IInternalPushInterpreter interpreter) { 44 44 if (interpreter.IntegerStack.IsEmpty) return false; 45 45 … … 54 54 [PushExpression(StackTypes.Char, "CHAR.FROMFLOAT", StackTypes.Float)] 55 55 public class CharFromFloatExpression : StatelessExpression { 56 public override bool Eval(I PushInterpreter interpreter) {56 public override bool Eval(IInternalPushInterpreter interpreter) { 57 57 if (interpreter.FloatStack.IsEmpty) return false; 58 58 … … 67 67 [PushExpression(StackTypes.Char, "CHAR.ALLFROMSTRING", StackTypes.String)] 68 68 public class CharAllFromStringExpression : StatelessExpression { 69 public override bool Eval(I PushInterpreter interpreter) {69 public override bool Eval(IInternalPushInterpreter interpreter) { 70 70 if (interpreter.StringStack.IsEmpty) return false; 71 71 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/CodeExpressions.cs
r14777 r14834 9 9 using System.Collections.Generic; 10 10 using System.Linq; 11 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 14 11 using Attributes; 15 12 using Interpreter; 13 using Stack; 16 14 17 15 /// <summary> … … 22 20 [PushExpression(StackTypes.Code, "CODE.DO", StackTypes.Exec)] 23 21 public class CodeDoExpression : StatelessExpression { 24 public override bool Eval(I PushInterpreter interpreter) {22 public override bool Eval(IInternalPushInterpreter interpreter) { 25 23 // not enough arguments on stack 26 24 if (interpreter.CodeStack.Count == 0) return false; … … 38 36 [PushExpression(StackTypes.Code, "CODE.DO*", StackTypes.Exec)] 39 37 public class CodeDoXExpression : StatelessExpression { 40 public override bool Eval(I PushInterpreter interpreter) {38 public override bool Eval(IInternalPushInterpreter interpreter) { 41 39 // not enough arguments on stack 42 40 if (interpreter.CodeStack.Count == 0) return false; … … 54 52 [PushExpression(StackTypes.Code, "CODE.NOOP")] 55 53 public class CodeNoopExpression : StatelessExpression { 56 public override bool Eval(I PushInterpreter interpreter) {54 public override bool Eval(IInternalPushInterpreter interpreter) { 57 55 return false; 58 56 } … … 65 63 [PushExpression(StackTypes.Code, "CODE.QUOTE", StackTypes.Exec)] 66 64 public class CodeQuoteExpression : StatelessExpression { 67 public override bool Eval(I PushInterpreter interpreter) {65 public override bool Eval(IInternalPushInterpreter interpreter) { 68 66 // not enough arguments on stack 69 67 if (interpreter.ExecStack.Count == 0) return false; … … 83 81 [PushExpression(StackTypes.Code, "CODE.IF", StackTypes.Exec | StackTypes.Boolean)] 84 82 public class CodeIfExpression : StatelessExpression { 85 public override bool Eval(I PushInterpreter interpreter) {83 public override bool Eval(IInternalPushInterpreter interpreter) { 86 84 // not enough arguments on stack 87 85 if ((interpreter.BooleanStack.Count == 0) || (interpreter.CodeStack.Count < 2)) return false; … … 102 100 [PushExpression(StackTypes.Code, "CODE.APPEND")] 103 101 public class CodeAppendExpression : StatelessExpression { 104 public override bool Eval(I PushInterpreter interpreter) {102 public override bool Eval(IInternalPushInterpreter interpreter) { 105 103 if (interpreter.CodeStack.Count < 2) return false; 106 104 … … 164 162 [PushExpression(StackTypes.Code, "CODE.ATOM", StackTypes.Boolean)] 165 163 public class CodeAtomExpression : StatelessExpression { 166 public override bool Eval(I PushInterpreter interpreter) {164 public override bool Eval(IInternalPushInterpreter interpreter) { 167 165 if (interpreter.CodeStack.Count == 0) return false; 168 166 … … 183 181 [PushExpression(StackTypes.Code, "CODE.CAR")] 184 182 public class CodeCarExpression : StatelessExpression { 185 public override bool Eval(I PushInterpreter interpreter) {183 public override bool Eval(IInternalPushInterpreter interpreter) { 186 184 if (interpreter.CodeStack.Count == 0 || 187 interpreter.CodeStack.Top.IsProgram) return false;185 !interpreter.CodeStack.Top.IsProgram) return false; 188 186 189 187 var expand = interpreter.CodeStack.Top as PushProgram; … … 205 203 [PushExpression(StackTypes.Code, "CODE.CDR")] 206 204 public class CodeCdrExpression : StatelessExpression { 207 public override bool Eval(I PushInterpreter interpreter) {205 public override bool Eval(IInternalPushInterpreter interpreter) { 208 206 if (interpreter.CodeStack.Count == 0) return false; 209 207 … … 236 234 [PushExpression(StackTypes.Code, "CODE.CONS")] 237 235 public class CodeConsExpression : StatelessExpression { 238 public override bool Eval(I PushInterpreter interpreter) {236 public override bool Eval(IInternalPushInterpreter interpreter) { 239 237 if (interpreter.CodeStack.Count < 2 || 240 238 (interpreter.CodeStack.Top.IsProgram && … … 242 240 return false; 243 241 244 PushProgram result;245 246 242 var expressions = interpreter.PoolContainer.ExpressionListPool.Get(); 247 243 var first = interpreter.CodeStack.Pop(); … … 254 250 255 251 expressions.Add(interpreter.CodeStack.Top); 256 result = PushProgram.Create(interpreter.PoolContainer.PushProgramPool, expressions);252 var result = PushProgram.Create(interpreter.PoolContainer.PushProgramPool, expressions); 257 253 interpreter.CodeStack.SetTop(result); 258 254 … … 271 267 [PushExpression(StackTypes.Code, "CODE.CONTAINER")] 272 268 public class CodeContainerExpression : StatelessExpression { 273 public override bool Eval(I PushInterpreter interpreter) {269 public override bool Eval(IInternalPushInterpreter interpreter) { 274 270 if ((interpreter.CodeStack.Count < 2) || 275 271 (interpreter.CodeStack[interpreter.CodeStack.Count - 2].GetType() != … … 310 306 [PushExpression(StackTypes.Code, "CODE.CONTAINS", StackTypes.Boolean)] 311 307 public class CodeContainsExpression : StatelessExpression { 312 public override bool Eval(I PushInterpreter interpreter) {308 public override bool Eval(IInternalPushInterpreter interpreter) { 313 309 if (interpreter.CodeStack.Count < 2 || 314 310 !interpreter.CodeStack[interpreter.CodeStack.Count - 2].IsProgram) … … 332 328 [PushExpression(StackTypes.Code, "CODE.DEFINITION", StackTypes.Name)] 333 329 public class CodeDefinitionExpression : StatelessExpression { 334 public override bool Eval(I PushInterpreter interpreter) {330 public override bool Eval(IInternalPushInterpreter interpreter) { 335 331 if ((interpreter.NameStack.Count == 0) || 336 332 !interpreter.CustomExpressions.ContainsKey(interpreter.NameStack.Top)) return false; … … 372 368 [PushExpression(StackTypes.Code, "CODE.DISCREPANCY", StackTypes.Integer)] 373 369 public class CodeDiscrepancyExpression : StatelessExpression { 374 public override bool Eval(I PushInterpreter interpreter) {370 public override bool Eval(IInternalPushInterpreter interpreter) { 375 371 if (interpreter.CodeStack.Count < 2) return false; 376 372 … … 430 426 [PushExpression(StackTypes.Code, "CODE.EXTRACT", StackTypes.Integer)] 431 427 public class CodeExtractExpression : StatelessExpression { 432 public override bool Eval(I PushInterpreter interpreter) {428 public override bool Eval(IInternalPushInterpreter interpreter) { 433 429 if (interpreter.IntegerStack.Count == 0 || 434 430 interpreter.CodeStack.Count == 0 || … … 451 447 [PushExpression(StackTypes.Code, "CODE.FROMBOOLEAN", StackTypes.Boolean)] 452 448 public class CodeFromBooleanExpression : StatelessExpression { 453 public override bool Eval(I PushInterpreter interpreter) {449 public override bool Eval(IInternalPushInterpreter interpreter) { 454 450 if (interpreter.BooleanStack.Count == 0) return false; 455 451 … … 468 464 [PushExpression(StackTypes.Code, "CODE.FROMFLOAT", StackTypes.Float)] 469 465 public class CodeFromFloatExpression : StatelessExpression { 470 public override bool Eval(I PushInterpreter interpreter) {466 public override bool Eval(IInternalPushInterpreter interpreter) { 471 467 if (interpreter.FloatStack.Count == 0) return false; 472 468 … … 485 481 [PushExpression(StackTypes.Code, "CODE.FROMINTEGER", StackTypes.Integer)] 486 482 public class CodeFromIntegerExpression : StatelessExpression { 487 public override bool Eval(I PushInterpreter interpreter) {483 public override bool Eval(IInternalPushInterpreter interpreter) { 488 484 if (interpreter.IntegerStack.Count == 0) return false; 489 485 … … 502 498 [PushExpression(StackTypes.Code, "CODE.FROMNAME", StackTypes.Name)] 503 499 public class CodeFromNameExpression : StatelessExpression { 504 public override bool Eval(I PushInterpreter interpreter) {500 public override bool Eval(IInternalPushInterpreter interpreter) { 505 501 if (interpreter.NameStack.Count == 0) return false; 506 502 … … 520 516 [PushExpression(StackTypes.Code, "CODE.CODEINSERT", StackTypes.Integer)] 521 517 public class CodeInsertExpression : StatelessExpression { 522 public override bool Eval(I PushInterpreter interpreter) {518 public override bool Eval(IInternalPushInterpreter interpreter) { 523 519 if (interpreter.IntegerStack.Count == 0 || 524 520 interpreter.CodeStack.Count < 2 || … … 558 554 [PushExpression(StackTypes.Code, "CODE.LENGTH", StackTypes.Integer)] 559 555 public class CodeLengthExpression : StatelessExpression { 560 public override bool Eval(I PushInterpreter interpreter) {556 public override bool Eval(IInternalPushInterpreter interpreter) { 561 557 if (interpreter.CodeStack.Count == 0) return false; 562 558 … … 578 574 [PushExpression(StackTypes.Code, "CODE.LIST")] 579 575 public class CodeListExpression : StatelessExpression { 580 public override bool Eval(I PushInterpreter interpreter) {576 public override bool Eval(IInternalPushInterpreter interpreter) { 581 577 if (interpreter.CodeStack.Count < 2 || 582 578 (interpreter.CodeStack.Top.IsProgram && ((PushProgram)interpreter.CodeStack.Top).Depth == interpreter.Configuration.MaxDepth) || … … 605 601 [PushExpression(StackTypes.Code, "CODE.MEMBER", StackTypes.Boolean)] 606 602 public class CodeMemberExpression : StatelessExpression { 607 public override bool Eval(I PushInterpreter interpreter) {603 public override bool Eval(IInternalPushInterpreter interpreter) { 608 604 if (interpreter.CodeStack.Count < 2) return false; 609 605 … … 627 623 [PushExpression(StackTypes.Code, "CODE.NTH", StackTypes.Integer)] 628 624 public class CodeNthExpression : StatelessExpression { 629 public override bool Eval(I PushInterpreter interpreter) {625 public override bool Eval(IInternalPushInterpreter interpreter) { 630 626 if ((interpreter.CodeStack.Count == 0) || (interpreter.IntegerStack.Count == 0)) return false; 631 627 … … 665 661 [PushExpression(StackTypes.Code, "CODE.NTHCDR", StackTypes.Integer)] 666 662 public class CodeNthCdrExpression : StatelessExpression { 667 public override bool Eval(I PushInterpreter interpreter) {663 public override bool Eval(IInternalPushInterpreter interpreter) { 668 664 if ((interpreter.CodeStack.Count == 0) || (interpreter.IntegerStack.Count == 0)) return false; 669 665 … … 698 694 [PushExpression(StackTypes.Code, "CODE.NULL", StackTypes.Boolean)] 699 695 public class CodeNullExpression : StatelessExpression { 700 public override bool Eval(I PushInterpreter interpreter) {696 public override bool Eval(IInternalPushInterpreter interpreter) { 701 697 if (interpreter.CodeStack.Count == 0) return false; 702 698 … … 715 711 [PushExpression(StackTypes.Code, "CODE.POSITION", StackTypes.Integer)] 716 712 public class CodePositionExpression : StatelessExpression { 717 public override bool Eval(I PushInterpreter interpreter) {713 public override bool Eval(IInternalPushInterpreter interpreter) { 718 714 if (interpreter.CodeStack.Count < 2) return false; 719 715 … … 742 738 [PushExpression(StackTypes.Code, "CODE.SIZE", StackTypes.Integer)] 743 739 public class CodeSizeExpression : StatelessExpression { 744 public override bool Eval(I PushInterpreter interpreter) {740 public override bool Eval(IInternalPushInterpreter interpreter) { 745 741 if (interpreter.CodeStack.Count == 0) return false; 746 742 … … 764 760 [PushExpression(StackTypes.Code, "CODE.SUBST")] 765 761 public class CodeSubstitutionExpression : StatelessExpression { 766 public override bool Eval(I PushInterpreter interpreter) {762 public override bool Eval(IInternalPushInterpreter interpreter) { 767 763 if ((interpreter.CodeStack.Count < 3) || 768 764 (interpreter.CodeStack.Top.GetType() != typeof(PushProgram))) -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DefineExpressions.cs
r14777 r14834 14 14 public abstract class DefineExpression<T> : StatelessExpression { 15 15 protected bool Eval( 16 I Stack<T> stack,17 I Stack<string> nameStack,16 IPushStack<T> stack, 17 IPushStack<string> nameStack, 18 18 IDictionary<string, Expression> customExpressions, 19 19 Func<T, Expression> creator) { … … 33 33 [PushExpression(StackTypes.Code, "CODE.DEFINE", StackTypes.Name)] 34 34 public class CodeDefineExpression : DefineExpression<Expression> { 35 public override bool Eval(I PushInterpreter interpreter) {35 public override bool Eval(IInternalPushInterpreter interpreter) { 36 36 if (interpreter.Configuration.TopLevelPushCode && (interpreter.CodeStack.Count < 2)) return false; 37 37 … … 50 50 [PushExpression(StackTypes.Exec, "EXEC.DEFINE", StackTypes.Name)] 51 51 public class ExecDefineExpression : DefineExpression<Expression> { 52 public override bool Eval(I PushInterpreter interpreter) {52 public override bool Eval(IInternalPushInterpreter interpreter) { 53 53 if (interpreter.ExecStack.Count < 2) return false; 54 54 … … 69 69 public class FloatDefineExpression : DefineExpression<double> { 70 70 71 public override bool Eval(I PushInterpreter interpreter) {71 public override bool Eval(IInternalPushInterpreter interpreter) { 72 72 return this.Eval( 73 73 interpreter.FloatStack, … … 80 80 [PushExpression(StackTypes.Integer, "INTEGER.DEFINE", StackTypes.Name)] 81 81 public class IntegerDefineExpression : DefineExpression<long> { 82 public override bool Eval(I PushInterpreter interpreter) {82 public override bool Eval(IInternalPushInterpreter interpreter) { 83 83 return this.Eval( 84 84 interpreter.IntegerStack, … … 91 91 [PushExpression(StackTypes.Boolean, "BOOLEAN.DEFINE", StackTypes.Name)] 92 92 public class BooleanDefineExpression : DefineExpression<bool> { 93 public override bool Eval(I PushInterpreter interpreter) {93 public override bool Eval(IInternalPushInterpreter interpreter) { 94 94 return this.Eval( 95 95 interpreter.BooleanStack, … … 102 102 [PushExpression(StackTypes.Char, "CHAR.DEFINE", StackTypes.Name)] 103 103 public class CharDefineExpression : DefineExpression<char> { 104 public override bool Eval(I PushInterpreter interpreter) {104 public override bool Eval(IInternalPushInterpreter interpreter) { 105 105 return Eval( 106 106 interpreter.CharStack, … … 113 113 [PushExpression(StackTypes.String, "STRING.DEFINE", StackTypes.Name)] 114 114 public class StringDefineExpression : DefineExpression<string> { 115 public override bool Eval(I PushInterpreter interpreter) {115 public override bool Eval(IInternalPushInterpreter interpreter) { 116 116 return Eval( 117 117 interpreter.StringStack, … … 121 121 } 122 122 } 123 124 [PushExpression(StackTypes.IntegerVector, "INTEGER[].DEFINE", StackTypes.Name)] 125 public class IntegerVectorDefineExpression : DefineExpression<List<long>> { 126 public override bool Eval(IInternalPushInterpreter interpreter) { 127 return Eval( 128 interpreter.IntegerVectorStack, 129 interpreter.NameStack, 130 interpreter.CustomExpressions, 131 v => new IntegerVectorPushExpression(v)); 132 } 133 } 123 134 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DoCountExpressions.cs
r14777 r14834 11 11 protected DoCountExpression() { } 12 12 protected DoCountExpression(LoopState state) : base(state) { } 13 protected override bool HasInsufficientArguments(I PushInterpreter interpreter, IStack<Expression> sourceStack) {13 protected override bool HasInsufficientArguments(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack) { 14 14 return interpreter.IntegerStack.Count < 1 || 15 15 sourceStack.Count == 0 || … … 17 17 } 18 18 19 protected override LoopState InitState(I PushInterpreter interpreter, IStack<Expression> sourceStack) {19 protected override LoopState InitState(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack) { 20 20 var state = LoopState.Create(interpreter.PoolContainer.LoopStatePool, 21 21 body: sourceStack.Pop(), … … 51 51 public CodeDoCountExpression(LoopState state) : base(state) { } 52 52 53 public override bool Eval(I PushInterpreter interpreter) {53 public override bool Eval(IInternalPushInterpreter interpreter) { 54 54 return this.Eval(interpreter, interpreter.CodeStack); 55 55 } 56 56 57 protected override LoopExpression Clone(LoopState state, I PushInterpreter interpreter) {57 protected override LoopExpression Clone(LoopState state, IInternalPushInterpreter interpreter) { 58 58 var expression = interpreter.PoolContainer.GetStatefulExpression<CodeDoCountExpression>(); 59 59 expression.State = state; … … 83 83 public ExecDoCountExpression(LoopState state) : base(state) { } 84 84 85 public override bool Eval(I PushInterpreter interpreter) {85 public override bool Eval(IInternalPushInterpreter interpreter) { 86 86 return this.Eval(interpreter, interpreter.ExecStack); 87 87 } 88 88 89 protected override LoopExpression Clone(LoopState state, I PushInterpreter interpreter) {89 protected override LoopExpression Clone(LoopState state, IInternalPushInterpreter interpreter) { 90 90 var expression = interpreter.PoolContainer.GetStatefulExpression<ExecDoCountExpression>(); 91 91 expression.State = state; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DoRangeExpressions.cs
r14777 r14834 10 10 protected DoRangeExpression() { } 11 11 protected DoRangeExpression(LoopState state) : base(state) { } 12 protected override bool HasInsufficientArguments(I PushInterpreter interpreter, IStack<Expression> sourceStack) {12 protected override bool HasInsufficientArguments(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack) { 13 13 return interpreter.IntegerStack.Count < 2 || 14 14 sourceStack.Count == 0 || … … 16 16 } 17 17 18 protected override LoopState InitState(I PushInterpreter interpreter, IStack<Expression> sourceStack) {18 protected override LoopState InitState(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack) { 19 19 var destinationIndex = interpreter.IntegerStack.Pop(); 20 20 var incrementor = destinationIndex < interpreter.IntegerStack.Top ? -1 : 1; … … 33 33 /// execution of 34 34 /// the body of the loop. The top integer is the "destination index" and the second integer is the "current index." 35 /// First the code35 /// Last the code 36 36 /// and the integer arguments are saved locally and popped. Then the integers are compared. If the integers are equal 37 37 /// then the current … … 56 56 57 57 public CodeDoRangeExpression(LoopState state) : base(state) { } 58 public override bool Eval(I PushInterpreter interpreter) {58 public override bool Eval(IInternalPushInterpreter interpreter) { 59 59 return this.Eval(interpreter, interpreter.CodeStack); 60 60 } 61 61 62 protected override LoopExpression Clone(LoopState state, I PushInterpreter interpreter) {62 protected override LoopExpression Clone(LoopState state, IInternalPushInterpreter interpreter) { 63 63 var expression = interpreter.PoolContainer.GetStatefulExpression<CodeDoRangeExpression>(); 64 64 expression.State = state; … … 74 74 /// the loop. 75 75 /// This is similar to CODE.DO*COUNT except that it takes its code argument from the EXEC stack. The top integer is the 76 /// "destination index" and the second integer is the "current index." First the code and the integer arguments are76 /// "destination index" and the second integer is the "current index." Last the code and the integer arguments are 77 77 /// saved locally 78 78 /// and popped. Then the integers are compared. If the integers are equal then the current index is pushed onto the … … 98 98 99 99 public ExecDoRangeExpression(LoopState state) : base(state) { } 100 public override bool Eval(I PushInterpreter interpreter) {100 public override bool Eval(IInternalPushInterpreter interpreter) { 101 101 return this.Eval(interpreter, interpreter.ExecStack); 102 102 } 103 protected override LoopExpression Clone(LoopState state, I PushInterpreter interpreter) {103 protected override LoopExpression Clone(LoopState state, IInternalPushInterpreter interpreter) { 104 104 var expression = interpreter.PoolContainer.GetStatefulExpression<ExecDoRangeExpression>(); 105 105 expression.State = state; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DoTimesExpressions.cs
r14777 r14834 10 10 protected DoTimesExpression() { } 11 11 protected DoTimesExpression(LoopState state) : base(state) { } 12 protected override bool HasInsufficientArguments(I PushInterpreter interpreter, IStack<Expression> sourceStack) {12 protected override bool HasInsufficientArguments(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack) { 13 13 return (interpreter.IntegerStack.Count < 1) || (sourceStack.Count == 0) || (interpreter.IntegerStack.Top <= 0); 14 14 } 15 15 16 protected override LoopState InitState(I PushInterpreter interpreter, IStack<Expression> sourceStack) {16 protected override LoopState InitState(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack) { 17 17 return LoopState.Create(interpreter.PoolContainer.LoopStatePool, 18 18 body: sourceStack.Pop(), … … 22 22 } 23 23 24 protected override void PushIteration(I PushInterpreter interpreter) {24 protected override void PushIteration(IInternalPushInterpreter interpreter) { 25 25 var newState = LoopState.Create(interpreter.PoolContainer.LoopStatePool, State.Body, State.CurrentIndex + this.State.Incrementor, State.DestinationIndex, State.Incrementor); 26 26 var nextLoopExpression = Clone(newState, interpreter); … … 29 29 } 30 30 31 protected override void PushLastIteration(I PushInterpreter interpreter) {31 protected override void PushLastIteration(IInternalPushInterpreter interpreter) { 32 32 interpreter.ExecStack.Push(this.State.Body); 33 33 } … … 46 46 public CodeDoTimesExpression(LoopState state) : base(state) { } 47 47 48 public override bool Eval(I PushInterpreter interpreter) {48 public override bool Eval(IInternalPushInterpreter interpreter) { 49 49 return this.Eval(interpreter, interpreter.CodeStack); 50 50 } 51 51 52 protected override LoopExpression Clone(LoopState state, I PushInterpreter interpreter) {52 protected override LoopExpression Clone(LoopState state, IInternalPushInterpreter interpreter) { 53 53 var expression = interpreter.PoolContainer.GetStatefulExpression<CodeDoTimesExpression>(); 54 54 expression.State = state; … … 73 73 public ExecDoTimesExpression(LoopState state) : base(state) { } 74 74 75 public override bool Eval(I PushInterpreter interpreter) {75 public override bool Eval(IInternalPushInterpreter interpreter) { 76 76 return this.Eval(interpreter, interpreter.ExecStack); 77 77 } 78 78 79 protected override LoopExpression Clone(LoopState state, I PushInterpreter interpreter) {79 protected override LoopExpression Clone(LoopState state, IInternalPushInterpreter interpreter) { 80 80 var expression = interpreter.PoolContainer.GetStatefulExpression<ExecDoTimesExpression>(); 81 81 expression.State = state; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DuplicateExpressions.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 using System.Collections.Generic; 3 2 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 3 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; … … 10 12 /// <typeparam name="T">Stacktype</typeparam> 11 13 public abstract class DuplicateExpression<T> : StatelessExpression { 12 protected bool Eval(I Stack<T> stack) {14 protected bool Eval(IPushStack<T> stack) { 13 15 if (stack.Count == 0) return false; 14 16 … … 17 19 return true; 18 20 } 19 20 protected bool Eval(IStack<Expression> stack) {21 if (stack.Count == 0) return false;22 23 var top = stack.Top;24 25 stack.Push(top);26 return true;27 }28 21 } 29 22 30 23 [PushExpression(StackTypes.Integer, "INTEGER.DUP")] 31 24 public class IntegerDuplicateExpression : DuplicateExpression<long> { 32 public override bool Eval(I PushInterpreter interpreter) {25 public override bool Eval(IInternalPushInterpreter interpreter) { 33 26 return this.Eval(interpreter.IntegerStack); 34 27 } … … 37 30 [PushExpression(StackTypes.Float, "FLOAT.DUP")] 38 31 public class FloatDuplicateExpression : DuplicateExpression<double> { 39 public override bool Eval(I PushInterpreter interpreter) {32 public override bool Eval(IInternalPushInterpreter interpreter) { 40 33 return this.Eval(interpreter.FloatStack); 41 34 } … … 44 37 [PushExpression(StackTypes.Boolean, "BOOLEAN.DUP")] 45 38 public class BooleanDuplicateExpression : DuplicateExpression<bool> { 46 public override bool Eval(I PushInterpreter interpreter) {39 public override bool Eval(IInternalPushInterpreter interpreter) { 47 40 return this.Eval(interpreter.BooleanStack); 48 41 } … … 51 44 [PushExpression(StackTypes.Name, "NAME.DUP")] 52 45 public class NameDuplicateExpression : DuplicateExpression<string> { 53 public override bool Eval(I PushInterpreter interpreter) {46 public override bool Eval(IInternalPushInterpreter interpreter) { 54 47 return this.Eval(interpreter.NameStack); 55 48 } … … 58 51 [PushExpression(StackTypes.Exec, "EXEC.DUP")] 59 52 public class ExecDuplicateExpression : DuplicateExpression<Expression> { 60 public override bool Eval(I PushInterpreter interpreter) {53 public override bool Eval(IInternalPushInterpreter interpreter) { 61 54 return this.Eval(interpreter.ExecStack); 62 55 } … … 65 58 [PushExpression(StackTypes.Code, "CODE.DUP")] 66 59 public class CodeDuplicateExpression : DuplicateExpression<Expression> { 67 public override bool Eval(I PushInterpreter interpreter) {60 public override bool Eval(IInternalPushInterpreter interpreter) { 68 61 return this.Eval(interpreter.CodeStack); 69 62 } 70 63 } 64 65 [PushExpression(StackTypes.IntegerVector, "INTEGER[].DUP")] 66 public class IntegerVectorDuplicateExpression : DuplicateExpression<List<long>> { 67 public override bool Eval(IInternalPushInterpreter interpreter) { 68 return this.Eval(interpreter.IntegerVectorStack); 69 } 70 } 71 71 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/EqualsExpressions.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 using System.Collections.Generic; 3 4 using HeuristicLab.Common; 2 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 3 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; … … 9 12 /// <typeparam name="T">Stacktype</typeparam> 10 13 public abstract class EqualsExpression<T> : StatelessExpression { 11 public bool Eval(I Stack<T> stack, IStack<bool> booleanStack) {14 public bool Eval(IPushStack<T> stack, IPushStack<bool> booleanStack) { 12 15 if (stack.Count < 2) return false; 13 16 … … 22 25 [PushExpression(StackTypes.Integer, "INTEGER.=", StackTypes.Boolean)] 23 26 public class IntegerEqualsExpression : EqualsExpression<long> { 24 public override bool Eval(I PushInterpreter interpreter) {27 public override bool Eval(IInternalPushInterpreter interpreter) { 25 28 return Eval(interpreter.IntegerStack, interpreter.BooleanStack); 26 29 } … … 29 32 [PushExpression(StackTypes.Float, "FLOAT.=", StackTypes.Boolean)] 30 33 public class FloatEqualsExpression : EqualsExpression<double> { 31 public override bool Eval(IPushInterpreter interpreter) { 32 return Eval(interpreter.FloatStack, interpreter.BooleanStack); 34 public override bool Eval(IInternalPushInterpreter interpreter) { 35 if (interpreter.FloatStack.Count < 2) return false; 36 37 var items = interpreter.FloatStack.Pop(2); 38 interpreter.BooleanStack.Push(items[0].IsAlmost(items[1])); 39 return true; 33 40 } 34 41 } … … 36 43 [PushExpression(StackTypes.Boolean, "BOOLEAN.=", StackTypes.Boolean)] 37 44 public class BooleanEqualsExpression : EqualsExpression<bool> { 38 public override bool Eval(I PushInterpreter interpreter) {45 public override bool Eval(IInternalPushInterpreter interpreter) { 39 46 return Eval(interpreter.BooleanStack, interpreter.BooleanStack); 40 47 } … … 43 50 [PushExpression(StackTypes.Name, "NAME.=", StackTypes.Boolean)] 44 51 public class NameEqualsExpression : EqualsExpression<string> { 45 public override bool Eval(I PushInterpreter interpreter) {52 public override bool Eval(IInternalPushInterpreter interpreter) { 46 53 return Eval(interpreter.NameStack, interpreter.BooleanStack); 47 54 } … … 50 57 [PushExpression(StackTypes.Exec, "EXEC.=", StackTypes.Boolean)] 51 58 public class ExecEqualsExpression : EqualsExpression<Expression> { 52 public override bool Eval(I PushInterpreter interpreter) {59 public override bool Eval(IInternalPushInterpreter interpreter) { 53 60 return Eval(interpreter.ExecStack, interpreter.BooleanStack); 54 61 } … … 57 64 [PushExpression(StackTypes.Code, "CODE.=", StackTypes.Boolean)] 58 65 public class CodeEqualsExpression : EqualsExpression<Expression> { 59 public override bool Eval(I PushInterpreter interpreter) {66 public override bool Eval(IInternalPushInterpreter interpreter) { 60 67 return Eval(interpreter.CodeStack, interpreter.BooleanStack); 61 68 } … … 64 71 [PushExpression(StackTypes.Char, "CHAR.=", StackTypes.Boolean)] 65 72 public class CharEqualsExpression : EqualsExpression<char> { 66 public override bool Eval(I PushInterpreter interpreter) {73 public override bool Eval(IInternalPushInterpreter interpreter) { 67 74 return Eval(interpreter.CharStack, interpreter.BooleanStack); 68 75 } … … 71 78 [PushExpression(StackTypes.String, "STRING.=", StackTypes.Boolean)] 72 79 public class StringEqualsExpression : EqualsExpression<string> { 73 public override bool Eval(I PushInterpreter interpreter) {80 public override bool Eval(IInternalPushInterpreter interpreter) { 74 81 return Eval(interpreter.StringStack, interpreter.BooleanStack); 75 82 } 76 83 } 84 85 [PushExpression(StackTypes.IntegerVector, "INTEGER[].=", StackTypes.Boolean)] 86 public class IntegerVectorEqualsExpression : EqualsExpression<List<long>> { 87 public override bool Eval(IInternalPushInterpreter interpreter) { 88 return Eval(interpreter.IntegerVectorStack, interpreter.BooleanStack); 89 } 90 } 77 91 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExecExpressions.cs
r14777 r14834 14 14 [PushExpression(StackTypes.Exec, "EXEC.IF", StackTypes.Boolean)] 15 15 public class ExecIfExpression : StatelessExpression { 16 public override bool Eval(I PushInterpreter interpreter) {16 public override bool Eval(IInternalPushInterpreter interpreter) { 17 17 // not enough arguments on stack 18 18 if ((interpreter.BooleanStack.Count == 0) || (interpreter.ExecStack.Count < 2)) return false; … … 33 33 [PushExpression(StackTypes.Exec, "EXEC.Y")] 34 34 public class ExecYExpression : StatelessExpression { 35 public override bool Eval(I PushInterpreter interpreter) {35 public override bool Eval(IInternalPushInterpreter interpreter) { 36 36 // not enough arguments on stack 37 37 if (interpreter.ExecStack.Count == 0 || … … 64 64 [PushExpression(StackTypes.Exec, "EXEC.K")] 65 65 public class ExecKExpression : StatelessExpression { 66 public override bool Eval(I PushInterpreter interpreter) {66 public override bool Eval(IInternalPushInterpreter interpreter) { 67 67 if (interpreter.ExecStack.Count < 2) return false; 68 68 … … 81 81 [PushExpression(StackTypes.Exec, "EXEC.S")] 82 82 public class ExecSExpression : StatelessExpression { 83 public override bool Eval(I PushInterpreter interpreter) {83 public override bool Eval(IInternalPushInterpreter interpreter) { 84 84 if (interpreter.ExecStack.Count < 3) return false; 85 85 … … 112 112 [PushExpression(StackTypes.Exec, "EXEC.NOOP")] 113 113 public class ExecNoopExpression : StatelessExpression { 114 public override bool Eval(I PushInterpreter interpreter) {114 public override bool Eval(IInternalPushInterpreter interpreter) { 115 115 return false; 116 116 } … … 119 119 [PushExpression(StackTypes.Exec, "EXEC.WHILE", StackTypes.Boolean)] 120 120 public class ExecWhileExpression : StatelessExpression { 121 public override bool Eval(I PushInterpreter interpreter) {121 public override bool Eval(IInternalPushInterpreter interpreter) { 122 122 if (interpreter.ExecStack.IsEmpty) 123 123 return false; … … 142 142 [PushExpression(StackTypes.Exec, "EXEC.DO*WHILE")] 143 143 public class ExecDoWhileExpression : StatelessExpression { 144 public override bool Eval(I PushInterpreter interpreter) {144 public override bool Eval(IInternalPushInterpreter interpreter) { 145 145 if (interpreter.ExecStack.IsEmpty) 146 146 return false; … … 153 153 [PushExpression(StackTypes.Exec, "EXEC.WHEN", StackTypes.Boolean)] 154 154 public class ExecWhenExpression : StatelessExpression { 155 public override bool Eval(I PushInterpreter interpreter) {155 public override bool Eval(IInternalPushInterpreter interpreter) { 156 156 if (interpreter.ExecStack.IsEmpty || 157 157 interpreter.BooleanStack.IsEmpty) -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/Expression.cs
r14777 r14834 26 26 } 27 27 28 public abstract bool Eval(I PushInterpreter interpreter);28 public abstract bool Eval(IInternalPushInterpreter interpreter); 29 29 30 30 public override string ToString() { -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExpressionTable.cs
r14777 r14834 14 14 public static readonly IDictionary<int, string> IndexToNameTable = new Dictionary<int, string>(); 15 15 public static readonly IDictionary<Type, string> TypeToNameTable = new Dictionary<Type, string>(); 16 public static readonly IDictionary<Type, PushExpressionAttribute> TypeToAttributeTable = new Dictionary<Type, PushExpressionAttribute>(); 16 17 public static readonly IDictionary<StackTypes, IList<string>> StackDependencyToNamesTable = new Dictionary<StackTypes, IList<string>>(); 17 18 public static readonly string[] ExpressionNames; … … 56 57 var attribute = (PushExpressionAttribute)Attribute.GetCustomAttribute(type, typeof(PushExpressionAttribute)); 57 58 59 TypeToAttributeTable.Add(type, attribute); 58 60 dictionary.Add(attribute.ExpressionName, expression); 59 61 IndexToNameTable.Add(IndexToNameTable.Keys.Count, attribute.ExpressionName); 60 62 TypeToNameTable.Add(type, attribute.ExpressionName); 61 63 62 if (!StackTypeToNamesTable.ContainsKey(attribute.StackType s)) {63 StackTypeToNamesTable.Add(attribute.StackType s, new List<string>());64 } 65 66 StackTypeToNamesTable[attribute.StackType s].Add(attribute.ExpressionName);67 68 var dependencies = attribute.StackType s| attribute.AdditionalStackDependencies;64 if (!StackTypeToNamesTable.ContainsKey(attribute.StackType)) { 65 StackTypeToNamesTable.Add(attribute.StackType, new List<string>()); 66 } 67 68 StackTypeToNamesTable[attribute.StackType].Add(attribute.ExpressionName); 69 70 var dependencies = attribute.StackType | attribute.AdditionalStackDependencies; 69 71 if (!StackDependencyToNamesTable.ContainsKey(dependencies)) { 70 72 StackDependencyToNamesTable.Add(dependencies, new List<string>()); … … 88 90 var attribute = (PushExpressionAttribute)Attribute.GetCustomAttribute(type, typeof(PushExpressionAttribute)); 89 91 92 TypeToAttributeTable.Add(type, attribute); 90 93 dictionary.Add(attribute.ExpressionName, creator); 91 94 IndexToNameTable.Add(IndexToNameTable.Keys.Count, attribute.ExpressionName); 92 95 TypeToNameTable.Add(type, attribute.ExpressionName); 93 96 94 if (!StackTypeToNamesTable.ContainsKey(attribute.StackType s)) {95 StackTypeToNamesTable.Add(attribute.StackType s, new List<string>());96 } 97 98 StackTypeToNamesTable[attribute.StackType s].Add(attribute.ExpressionName);99 100 var dependencies = attribute.StackType s| attribute.AdditionalStackDependencies;97 if (!StackTypeToNamesTable.ContainsKey(attribute.StackType)) { 98 StackTypeToNamesTable.Add(attribute.StackType, new List<string>()); 99 } 100 101 StackTypeToNamesTable[attribute.StackType].Add(attribute.ExpressionName); 102 103 var dependencies = attribute.StackType | attribute.AdditionalStackDependencies; 101 104 if (!StackDependencyToNamesTable.ContainsKey(dependencies)) { 102 105 StackDependencyToNamesTable.Add(dependencies, new List<string>()); … … 142 145 } 143 146 144 public static IReadOnlyList<string> GetE nabledExpressionsByStackTypes(StackTypes allowedTypes) {147 public static IReadOnlyList<string> GetExpressionsByStackTypes(StackTypes allowedTypes) { 145 148 return StackDependencyToNamesTable 146 149 .Where(entry => (entry.Key & ~allowedTypes) == StackTypes.None) -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/FloatExpressions.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 2 using System; 3 3 using Common; 4 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 5 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; … … 11 11 [PushExpression(StackTypes.Float, "FLOAT.+")] 12 12 public class FloatAddExpression : PushResultExpression<double> { 13 public override bool Eval(IPushInterpreter interpreter) { 14 return Eval(interpreter.FloatStack, 2, values => values[0] + values[1]); 13 public override bool Eval(IInternalPushInterpreter interpreter) { 14 return Eval(interpreter.FloatStack, 2, 15 values => { 16 var result = values[0] + values[1]; 17 18 if (double.IsPositiveInfinity(result)) return double.MaxValue; 19 if (double.IsNegativeInfinity(result)) return double.MinValue; 20 21 return result; 22 }); 15 23 } 16 24 } … … 21 29 [PushExpression(StackTypes.Float, "FLOAT.-")] 22 30 public class FloatSubtractExpression : PushResultExpression<double> { 23 public override bool Eval(IPushInterpreter interpreter) { 24 return Eval(interpreter.FloatStack, 2, values => values[0] - values[1]); 31 public override bool Eval(IInternalPushInterpreter interpreter) { 32 return Eval(interpreter.FloatStack, 2, 33 values => { 34 var result = values[0] - values[1]; 35 36 if (double.IsPositiveInfinity(result)) return double.MaxValue; 37 if (double.IsNegativeInfinity(result)) return double.MinValue; 38 39 return result; 40 }); 25 41 } 26 42 } … … 31 47 [PushExpression(StackTypes.Float, "FLOAT.*")] 32 48 public class FloatMultiplyExpression : PushResultExpression<double> { 33 public override bool Eval(IPushInterpreter interpreter) { 34 return Eval(interpreter.FloatStack, 2, values => values[0] * values[1]); 49 public override bool Eval(IInternalPushInterpreter interpreter) { 50 return Eval(interpreter.FloatStack, 2, 51 values => { 52 var result = values[0] * values[1]; 53 54 if (double.IsPositiveInfinity(result)) return double.MaxValue; 55 if (double.IsNegativeInfinity(result)) return double.MinValue; 56 57 return result; 58 }); 35 59 } 36 60 } … … 42 66 [PushExpression(StackTypes.Float, "FLOAT./")] 43 67 public class FloatDivideExpression : PushResultExpression<double> { 44 public override bool Eval(IPushInterpreter interpreter) { 45 return Eval(interpreter.FloatStack, 2, values => values[0] / values[1], 0); 68 public override bool Eval(IInternalPushInterpreter interpreter) { 69 return Eval(interpreter.FloatStack, 2, values => { 70 var result = values[0] / values[1]; 71 72 if (double.IsPositiveInfinity(result)) return double.MaxValue; 73 if (double.IsNegativeInfinity(result)) return double.MinValue; 74 75 return result; 76 }, 0); 46 77 } 47 78 } … … 56 87 [PushExpression(StackTypes.Float, "FLOAT.%")] 57 88 public class FloatModuloExpression : PushResultExpression<double> { 58 public override bool Eval(I PushInterpreter interpreter) {89 public override bool Eval(IInternalPushInterpreter interpreter) { 59 90 return Eval(interpreter.FloatStack, 2, values => values[0] % values[1], 0); 60 91 } … … 66 97 [PushExpression(StackTypes.Float, "FLOAT.MIN")] 67 98 public class FloatMinExpression : PushResultExpression<double> { 68 public override bool Eval(I PushInterpreter interpreter) {99 public override bool Eval(IInternalPushInterpreter interpreter) { 69 100 return Eval(interpreter.FloatStack, 2, values => Math.Min(values[0], values[1])); 70 101 } … … 76 107 [PushExpression(StackTypes.Float, "FLOAT.MAX")] 77 108 public class FloatMaxExpression : PushResultExpression<double> { 78 public override bool Eval(I PushInterpreter interpreter) {109 public override bool Eval(IInternalPushInterpreter interpreter) { 79 110 return Eval(interpreter.FloatStack, 2, values => Math.Max(values[0], values[1])); 80 111 } … … 86 117 [PushExpression(StackTypes.Float, "FLOAT.<", StackTypes.Boolean)] 87 118 public class FloatSmallerThanExpression : PushResultExpression<double> { 88 public override bool Eval(I PushInterpreter interpreter) {119 public override bool Eval(IInternalPushInterpreter interpreter) { 89 120 return Eval(interpreter.FloatStack, interpreter.BooleanStack, 2, values => values[0] < values[1]); 90 121 } … … 96 127 [PushExpression(StackTypes.Float, "FLOAT.<=", StackTypes.Boolean)] 97 128 public class FloatSmallerThanOrEqualExpression : PushResultExpression<double> { 98 public override bool Eval(I PushInterpreter interpreter) {99 return Eval(interpreter.FloatStack, interpreter.BooleanStack, 2, values => values[0] < = values[1]);129 public override bool Eval(IInternalPushInterpreter interpreter) { 130 return Eval(interpreter.FloatStack, interpreter.BooleanStack, 2, values => values[0] < values[1] || values[0].IsAlmost(values[1])); 100 131 } 101 132 } … … 106 137 [PushExpression(StackTypes.Float, "FLOAT.>", StackTypes.Boolean)] 107 138 public class FloatGreaterThanExpression : PushResultExpression<double> { 108 public override bool Eval(I PushInterpreter interpreter) {139 public override bool Eval(IInternalPushInterpreter interpreter) { 109 140 return Eval(interpreter.FloatStack, interpreter.BooleanStack, 2, values => values[0] > values[1]); 110 141 } … … 116 147 [PushExpression(StackTypes.Float, "FLOAT.>=", StackTypes.Boolean)] 117 148 public class FloatGreaterThanOrEqualExpression : PushResultExpression<double> { 118 public override bool Eval(I PushInterpreter interpreter) {119 return Eval(interpreter.FloatStack, interpreter.BooleanStack, 2, values => values[0] > = values[1]);149 public override bool Eval(IInternalPushInterpreter interpreter) { 150 return Eval(interpreter.FloatStack, interpreter.BooleanStack, 2, values => values[0] > values[1] || values[0].IsAlmost(values[1])); 120 151 } 121 152 } … … 126 157 [PushExpression(StackTypes.Float, "FLOAT.SIN")] 127 158 public class FloatSineExpression : PushResultExpression<double> { 128 public override bool Eval(I PushInterpreter interpreter) {159 public override bool Eval(IInternalPushInterpreter interpreter) { 129 160 return Eval(interpreter.FloatStack, 1, values => Math.Sin(values[0])); 130 161 } … … 136 167 [PushExpression(StackTypes.Float, "FLOAT.COS")] 137 168 public class FloatCosineExpression : PushResultExpression<double> { 138 public override bool Eval(I PushInterpreter interpreter) {169 public override bool Eval(IInternalPushInterpreter interpreter) { 139 170 return Eval(interpreter.FloatStack, 1, values => Math.Cos(values[0])); 140 171 } … … 146 177 [PushExpression(StackTypes.Float, "FLOAT.FROMBOOLEAN", StackTypes.Boolean)] 147 178 public class FloatFromBooleanExpression : StatelessExpression { 148 public override bool Eval(I PushInterpreter interpreter) {179 public override bool Eval(IInternalPushInterpreter interpreter) { 149 180 if (interpreter.BooleanStack.Count == 0) return false; 150 181 … … 163 194 [PushExpression(StackTypes.Float, "FLOAT.FROMINTEGER", StackTypes.Integer)] 164 195 public class FloatFromIntegerExpression : StatelessExpression { 165 public override bool Eval(I PushInterpreter interpreter) {196 public override bool Eval(IInternalPushInterpreter interpreter) { 166 197 if (interpreter.IntegerStack.Count == 0) return false; 167 198 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/FlushExpressions.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 using System.Collections.Generic; 3 2 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 3 5 … … 10 12 /// <typeparam name="T">Stacktype</typeparam> 11 13 public abstract class FlushExpression<T> : StatelessExpression { 12 public bool Eval(I Stack<T> stack) {14 public bool Eval(IPushStack<T> stack) { 13 15 stack.Clear(); 14 16 return true; … … 18 20 [PushExpression(StackTypes.Integer, "INTEGER.FLUSH")] 19 21 public class IntegerFlushExpression : FlushExpression<long> { 20 public override bool Eval(I PushInterpreter interpreter) {22 public override bool Eval(IInternalPushInterpreter interpreter) { 21 23 return Eval(interpreter.IntegerStack); 22 24 } … … 25 27 [PushExpression(StackTypes.Float, "FLOAT.FLUSH")] 26 28 public class FloatFlushExpression : FlushExpression<double> { 27 public override bool Eval(I PushInterpreter interpreter) {29 public override bool Eval(IInternalPushInterpreter interpreter) { 28 30 return Eval(interpreter.FloatStack); 29 31 } … … 32 34 [PushExpression(StackTypes.Boolean, "BOOLEAN.FLUSH")] 33 35 public class BooleanFlushExpression : FlushExpression<bool> { 34 public override bool Eval(I PushInterpreter interpreter) {36 public override bool Eval(IInternalPushInterpreter interpreter) { 35 37 return Eval(interpreter.BooleanStack); 36 38 } … … 39 41 [PushExpression(StackTypes.Name, "NAME.FLUSH")] 40 42 public class NameFlushExpression : FlushExpression<string> { 41 public override bool Eval(I PushInterpreter interpreter) {43 public override bool Eval(IInternalPushInterpreter interpreter) { 42 44 return Eval(interpreter.NameStack); 43 45 } … … 46 48 [PushExpression(StackTypes.Exec, "EXEC.FLUSH")] 47 49 public class ExecFlushExpression : FlushExpression<Expression> { 48 public override bool Eval(I PushInterpreter interpreter) {50 public override bool Eval(IInternalPushInterpreter interpreter) { 49 51 return Eval(interpreter.ExecStack); 50 52 } … … 53 55 [PushExpression(StackTypes.Code, "CODE.FLUSH")] 54 56 public class CodeFlushExpression : FlushExpression<Expression> { 55 public override bool Eval(I PushInterpreter interpreter) {57 public override bool Eval(IInternalPushInterpreter interpreter) { 56 58 return Eval(interpreter.CodeStack); 57 59 } … … 60 62 [PushExpression(StackTypes.Char, "CHAR.FLUSH")] 61 63 public class CharFlushExpression : FlushExpression<char> { 62 public override bool Eval(I PushInterpreter interpreter) {64 public override bool Eval(IInternalPushInterpreter interpreter) { 63 65 return Eval(interpreter.CharStack); 64 66 } … … 67 69 [PushExpression(StackTypes.String, "STRING.FLUSH")] 68 70 public class StringFlushExpression : FlushExpression<string> { 69 public override bool Eval(I PushInterpreter interpreter) {71 public override bool Eval(IInternalPushInterpreter interpreter) { 70 72 return Eval(interpreter.StringStack); 71 73 } 72 74 } 75 76 [PushExpression(StackTypes.IntegerVector, "INTEGER[].FLUSH")] 77 public class IntegerVectorFlushExpression : FlushExpression<List<long>> { 78 public override bool Eval(IInternalPushInterpreter interpreter) { 79 return Eval(interpreter.IntegerVectorStack); 80 } 81 } 73 82 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/IntegerExpressions.cs
r14777 r14834 12 12 [PushExpression(StackTypes.Integer, "INTEGER.+")] 13 13 public class IntegerAddExpression : PushResultExpression<long> { 14 public override bool Eval(I PushInterpreter interpreter) {14 public override bool Eval(IInternalPushInterpreter interpreter) { 15 15 return Eval(interpreter.IntegerStack, 2, values => values[0] + values[1]); 16 16 } … … 22 22 [PushExpression(StackTypes.Integer, "INTEGER.-")] 23 23 public class IntegerSubtractExpression : PushResultExpression<long> { 24 public override bool Eval(I PushInterpreter interpreter) {24 public override bool Eval(IInternalPushInterpreter interpreter) { 25 25 return Eval(interpreter.IntegerStack, 2, values => values[0] - values[1]); 26 26 } … … 32 32 [PushExpression(StackTypes.Integer, "INTEGER.*")] 33 33 public class IntegerMultiplyExpression : PushResultExpression<long> { 34 public override bool Eval(I PushInterpreter interpreter) {34 public override bool Eval(IInternalPushInterpreter interpreter) { 35 35 return Eval(interpreter.IntegerStack, 2, values => values[0] * values[1]); 36 36 } … … 43 43 [PushExpression(StackTypes.Integer, "INTEGER./")] 44 44 public class IntegerDivideExpression : PushResultExpression<long> { 45 public override bool Eval(I PushInterpreter interpreter) {45 public override bool Eval(IInternalPushInterpreter interpreter) { 46 46 return Eval(interpreter.IntegerStack, 2, values => values[0] / values[1], 0); 47 47 } … … 58 58 [PushExpression(StackTypes.Integer, "INTEGER.%")] 59 59 public class IntegerModuloExpression : PushResultExpression<long> { 60 public override bool Eval(I PushInterpreter interpreter) {60 public override bool Eval(IInternalPushInterpreter interpreter) { 61 61 return Eval(interpreter.IntegerStack, 2, values => values[0] % values[1], 0); 62 62 } … … 68 68 [PushExpression(StackTypes.Integer, "INTEGER.MIN")] 69 69 public class IntegerMinExpression : PushResultExpression<long> { 70 public override bool Eval(I PushInterpreter interpreter) {70 public override bool Eval(IInternalPushInterpreter interpreter) { 71 71 return Eval(interpreter.IntegerStack, 2, values => Math.Min(values[0], values[1])); 72 72 } … … 78 78 [PushExpression(StackTypes.Integer, "INTEGER.MAX")] 79 79 public class IntegerMaxExpression : PushResultExpression<long> { 80 public override bool Eval(I PushInterpreter interpreter) {80 public override bool Eval(IInternalPushInterpreter interpreter) { 81 81 return Eval(interpreter.IntegerStack, 2, values => Math.Max(values[0], values[1])); 82 82 } … … 88 88 [PushExpression(StackTypes.Integer, "INTEGER.<", StackTypes.Boolean)] 89 89 public class IntegerSmallerThanExpression : PushResultExpression<long> { 90 public override bool Eval(I PushInterpreter interpreter) {90 public override bool Eval(IInternalPushInterpreter interpreter) { 91 91 return Eval(interpreter.IntegerStack, interpreter.BooleanStack, 2, values => values[0] < values[1]); 92 92 } … … 98 98 [PushExpression(StackTypes.Integer, "INTEGER.>", StackTypes.Boolean)] 99 99 public class IntegerGreaterThanExpression : PushResultExpression<long> { 100 public override bool Eval(I PushInterpreter interpreter) {100 public override bool Eval(IInternalPushInterpreter interpreter) { 101 101 return Eval(interpreter.IntegerStack, interpreter.BooleanStack, 2, values => values[0] > values[1]); 102 102 } … … 108 108 [PushExpression(StackTypes.Integer, "INTEGER.FROMBOOLEAN", StackTypes.Boolean)] 109 109 public class IntegerFromBooleanExpression : StatelessExpression { 110 public override bool Eval(I PushInterpreter interpreter) {110 public override bool Eval(IInternalPushInterpreter interpreter) { 111 111 if (interpreter.BooleanStack.Count == 0) return false; 112 112 … … 125 125 [PushExpression(StackTypes.Integer, "INTEGER.FROMFLOAT", StackTypes.Float)] 126 126 public class IntegerFromFloatExpression : StatelessExpression { 127 public override bool Eval(I PushInterpreter interpreter) {127 public override bool Eval(IInternalPushInterpreter interpreter) { 128 128 if (interpreter.FloatStack.Count == 0) return false; 129 129 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/LoopExpression.cs
r14777 r14834 62 62 protected LoopExpression(LoopState state) : base(state) { } 63 63 64 protected bool Eval(I PushInterpreter interpreter, IStack<Expression> sourceStack, bool pushCurrentIndex = false) {64 protected bool Eval(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack, bool pushCurrentIndex = false) { 65 65 // if not initialized 66 66 if (this.State.Body == null) { … … 99 99 } 100 100 101 protected virtual void PushIteration(I PushInterpreter interpreter) {101 protected virtual void PushIteration(IInternalPushInterpreter interpreter) { 102 102 interpreter.IntegerStack.Push(this.State.CurrentIndex); 103 103 … … 114 114 } 115 115 116 protected virtual void PushLastIteration(I PushInterpreter interpreter) {116 protected virtual void PushLastIteration(IInternalPushInterpreter interpreter) { 117 117 interpreter.IntegerStack.Push(State.CurrentIndex); 118 118 interpreter.ExecStack.Push(State.Body); 119 119 } 120 120 121 protected abstract LoopExpression Clone(LoopState state, I PushInterpreter interpreter);122 protected abstract bool HasInsufficientArguments(I PushInterpreter interpreter, IStack<Expression> sourceStack);123 protected abstract LoopState InitState(I PushInterpreter interpreter, IStack<Expression> sourceStack);121 protected abstract LoopExpression Clone(LoopState state, IInternalPushInterpreter interpreter); 122 protected abstract bool HasInsufficientArguments(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack); 123 protected abstract LoopState InitState(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack); 124 124 } 125 125 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/NameExpressions.cs
r14777 r14834 8 8 public NameDefineXExecExpression(string state) : base(state) { } 9 9 10 public override bool Eval(I PushInterpreter interpreter) {10 public override bool Eval(IInternalPushInterpreter interpreter) { 11 11 Expression expression; 12 12 if (!interpreter.IsNameQuoteFlagSet && … … 31 31 [PushExpression(StackTypes.Name, "NAME.QUOTE")] 32 32 public class NameQuoteExpression : StatelessExpression { 33 public override bool Eval(I PushInterpreter interpreter) {33 public override bool Eval(IInternalPushInterpreter interpreter) { 34 34 if (interpreter.IsNameQuoteFlagSet) return false; 35 35 … … 44 44 [PushExpression(StackTypes.Name, "NAME.RANDBOUNDNAME")] 45 45 public class NameRandBoundNameExpression : StatelessExpression { 46 public override bool Eval(I PushInterpreter interpreter) {46 public override bool Eval(IInternalPushInterpreter interpreter) { 47 47 if (interpreter.CustomExpressions.Count == 0) 48 48 return false; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PopExpressions.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 using System.Collections.Generic; 3 2 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 3 5 … … 6 8 7 9 public abstract class PopExpression<T> : StatelessExpression { 8 public bool Eval(I Stack<T> stack) {10 public bool Eval(IPushStack<T> stack) { 9 11 if (stack.Count == 0) return false; 10 12 … … 16 18 [PushExpression(StackTypes.Integer, "INTEGER.POP")] 17 19 public class IntegerPopExpression : PopExpression<long> { 18 public override bool Eval(I PushInterpreter interpreter) {20 public override bool Eval(IInternalPushInterpreter interpreter) { 19 21 return Eval(interpreter.IntegerStack); 20 22 } … … 23 25 [PushExpression(StackTypes.Float, "FLOAT.POP")] 24 26 public class FloatPopExpression : PopExpression<double> { 25 public override bool Eval(I PushInterpreter interpreter) {27 public override bool Eval(IInternalPushInterpreter interpreter) { 26 28 return Eval(interpreter.FloatStack); 27 29 } … … 30 32 [PushExpression(StackTypes.Boolean, "BOOLEAN.POP")] 31 33 public class BooleanPopExpression : PopExpression<bool> { 32 public override bool Eval(I PushInterpreter interpreter) {34 public override bool Eval(IInternalPushInterpreter interpreter) { 33 35 return Eval(interpreter.BooleanStack); 34 36 } … … 37 39 [PushExpression(StackTypes.Name, "NAME.POP")] 38 40 public class NamePopExpression : PopExpression<string> { 39 public override bool Eval(I PushInterpreter interpreter) {41 public override bool Eval(IInternalPushInterpreter interpreter) { 40 42 return Eval(interpreter.NameStack); 41 43 } … … 44 46 [PushExpression(StackTypes.Exec, "EXEC.POP")] 45 47 public class ExecPopExpression : PopExpression<Expression> { 46 public override bool Eval(I PushInterpreter interpreter) {48 public override bool Eval(IInternalPushInterpreter interpreter) { 47 49 return Eval(interpreter.ExecStack); 48 50 } … … 51 53 [PushExpression(StackTypes.Code, "CODE.POP")] 52 54 public class CodePopExpression : PopExpression<Expression> { 53 public override bool Eval(I PushInterpreter interpreter) {55 public override bool Eval(IInternalPushInterpreter interpreter) { 54 56 return Eval(interpreter.CodeStack); 55 57 } … … 58 60 [PushExpression(StackTypes.Char, "CHAR.POP")] 59 61 public class CharPopExpression : PopExpression<char> { 60 public override bool Eval(I PushInterpreter interpreter) {62 public override bool Eval(IInternalPushInterpreter interpreter) { 61 63 return Eval(interpreter.CharStack); 62 64 } … … 65 67 [PushExpression(StackTypes.String, "STRING.POP")] 66 68 public class StringPopExpression : PopExpression<string> { 67 public override bool Eval(I PushInterpreter interpreter) {69 public override bool Eval(IInternalPushInterpreter interpreter) { 68 70 return Eval(interpreter.StringStack); 69 71 } 70 72 } 73 74 [PushExpression(StackTypes.IntegerVector, "INTEGER[].POP")] 75 public class IntegerVectorPopExpression : PopExpression<List<long>> { 76 public override bool Eval(IInternalPushInterpreter interpreter) { 77 return Eval(interpreter.IntegerVectorStack); 78 } 79 } 71 80 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PushExpressions.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 using System.Collections.Generic; 3 2 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; 3 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; … … 7 9 protected PushExpression(T state) : base(state) { } 8 10 9 protected bool Eval(I Stack<T> stack) {11 protected bool Eval(IPushStack<T> stack) { 10 12 stack.Push(this.State); 11 13 return true; … … 20 22 } 21 23 22 public override bool Eval(I PushInterpreter interpreter) {24 public override bool Eval(IInternalPushInterpreter interpreter) { 23 25 return Eval(interpreter.IntegerStack); 24 26 } … … 30 32 } 31 33 32 public override bool Eval(I PushInterpreter interpreter) {34 public override bool Eval(IInternalPushInterpreter interpreter) { 33 35 return Eval(interpreter.FloatStack); 34 36 } … … 40 42 } 41 43 42 public override bool Eval(I PushInterpreter interpreter) {44 public override bool Eval(IInternalPushInterpreter interpreter) { 43 45 return Eval(interpreter.BooleanStack); 44 46 } … … 50 52 } 51 53 52 public override bool Eval(I PushInterpreter interpreter) {54 public override bool Eval(IInternalPushInterpreter interpreter) { 53 55 return Eval(interpreter.NameStack); 54 56 } … … 60 62 } 61 63 62 public override bool Eval(I PushInterpreter interpreter) {64 public override bool Eval(IInternalPushInterpreter interpreter) { 63 65 return Eval(interpreter.ExecStack); 64 66 } … … 70 72 } 71 73 72 public override bool Eval(I PushInterpreter interpreter) {74 public override bool Eval(IInternalPushInterpreter interpreter) { 73 75 return Eval(interpreter.CharStack); 74 76 } … … 80 82 } 81 83 82 public override bool Eval(I PushInterpreter interpreter) {84 public override bool Eval(IInternalPushInterpreter interpreter) { 83 85 return Eval(interpreter.StringStack); 84 86 } 85 87 } 88 89 public class IntegerVectorPushExpression : PushExpression<List<long>> { 90 public IntegerVectorPushExpression(List<long> state) 91 : base(state) { 92 } 93 94 public override bool Eval(IInternalPushInterpreter interpreter) { 95 return Eval(interpreter.IntegerVectorStack); 96 } 97 } 86 98 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PushProgram.cs
r14777 r14834 167 167 } 168 168 169 public override bool Eval(I PushInterpreter interpreter) {169 public override bool Eval(IInternalPushInterpreter interpreter) { 170 170 interpreter.ExecStack.Push(this.expressions); 171 171 return true; … … 191 191 } 192 192 193 public IEnumerable<Expression> Depth First() {193 public IEnumerable<Expression> DepthLast() { 194 194 foreach (var expr in this.expressions) { 195 195 if (expr.IsProgram) 196 foreach (var sub in ((PushProgram)expr).Depth First())196 foreach (var sub in ((PushProgram)expr).DepthLast()) 197 197 yield return sub; 198 198 else yield return expr; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/PushResultExpression.cs
r14744 r14834 5 5 6 6 public abstract class PushResultExpression<T> : StatelessExpression { 7 protected bool Eval(I Stack<T> stack, int count, Func<T[], T> templateFunc) {7 protected bool Eval(IPushStack<T> stack, int count, Func<T[], T> templateFunc) { 8 8 if (stack.Count < count) return false; 9 9 … … 12 12 } 13 13 14 protected bool Eval(I Stack<T> stack, int count, Func<T[], T> templateFunc, T ignoreValue) {14 protected bool Eval(IPushStack<T> stack, int count, Func<T[], T> templateFunc, T ignoreValue) { 15 15 if ((stack.Count < count) || stack.Top.Equals(ignoreValue)) return false; 16 16 … … 19 19 } 20 20 21 protected bool Eval<R>(I Stack<T> stack, IStack<R> resultStack, int count, Func<T[], R> templateFunc) {21 protected bool Eval<R>(IPushStack<T> stack, IPushStack<R> resultStack, int count, Func<T[], R> templateFunc) { 22 22 if (stack.Count < count) return false; 23 23 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/RandExpressions.cs
r14777 r14834 2 2 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 3 3 using HeuristicLab.Problems.ProgramSynthesis.Push.Generators; 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator; 4 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; 5 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 7 using HeuristicLab.Random; 6 8 7 9 /// <summary> … … 10 12 [PushExpression(StackTypes.Name, "NAME.RAND")] 11 13 public class NameRandExpression : StatelessExpression { 12 public override bool Eval(IPushInterpreter interpreter) { 13 var name = NameGenerator.RandomName(interpreter.Random); 14 public override bool Eval(IInternalPushInterpreter interpreter) { 15 if (!interpreter.Configuration.ErcOptions.NameErcOptions.IsEnabled) 16 return false; 17 18 var name = interpreter.CustomExpressions.Count == 0 || interpreter.Random.NextDouble() < interpreter.Configuration.ErcOptions.NameErcOptions.NewNameProbability 19 ? ErcUtils.GetName(interpreter.Configuration.ErcOptions.NameErcOptions, interpreter.Random) 20 : interpreter.CustomExpressions.Keys.SampleRandom(interpreter.Random); 14 21 15 22 interpreter.NameStack.Push(name); … … 23 30 [PushExpression(StackTypes.Integer, "INTEGER.RAND")] 24 31 public class IntegerRandExpression : StatelessExpression { 25 public override bool Eval(IPushInterpreter interpreter) { 26 var value = interpreter.Random.Next( 27 interpreter.Configuration.MinRandomInteger, 28 interpreter.Configuration.MaxRandomInteger); 32 public override bool Eval(IInternalPushInterpreter interpreter) { 33 if (!interpreter.Configuration.ErcOptions.IntegerErcOptions.IsEnabled) 34 return false; 29 35 36 var value = ErcUtils.GetInteger(interpreter.Configuration.ErcOptions.IntegerErcOptions, interpreter.Random); 30 37 interpreter.IntegerStack.Push(value); 31 38 return true; … … 38 45 [PushExpression(StackTypes.Float, "FLOAT.RAND")] 39 46 public class FloatRandExpression : StatelessExpression { 40 public override bool Eval(IPushInterpreter interpreter) { 41 var value = interpreter.Random.NextDouble() * (interpreter.Configuration.MaxRandomFloat - interpreter.Configuration.MinRandomFloat) + interpreter.Configuration.MinRandomFloat; 47 public override bool Eval(IInternalPushInterpreter interpreter) { 48 if (!interpreter.Configuration.ErcOptions.FloatErcOptions.IsEnabled) 49 return false; 42 50 51 var value = ErcUtils.GetDouble(interpreter.Configuration.ErcOptions.FloatErcOptions, interpreter.Random); 43 52 interpreter.FloatStack.Push(value); 44 53 return true; … … 51 60 [PushExpression(StackTypes.Boolean, "BOOLEAN.RAND")] 52 61 public class BooleanRandExpression : StatelessExpression { 53 public override bool Eval(IPushInterpreter interpreter) { 54 var value = interpreter.Random.NextDouble() > 0.5; 62 public override bool Eval(IInternalPushInterpreter interpreter) { 63 if (!interpreter.Configuration.ErcOptions.BooleanErcOptions.IsEnabled) 64 return false; 55 65 66 var value = ErcUtils.GetBoolean(interpreter.Configuration.ErcOptions.BooleanErcOptions, interpreter.Random); 56 67 interpreter.BooleanStack.Push(value); 57 68 return true; … … 64 75 [PushExpression(StackTypes.Code, "CODE.RAND")] 65 76 public class CodeRandExpression : StatelessExpression { 66 public override bool Eval(I PushInterpreter interpreter) {77 public override bool Eval(IInternalPushInterpreter interpreter) { 67 78 if (interpreter.IntegerStack.Count == 0 || 68 79 interpreter.IntegerStack.Top < 1) return false; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/RotateExpressions.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 using System.Collections.Generic; 3 2 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 3 5 … … 6 8 7 9 public abstract class RotateExpression<T> : StatelessExpression { 8 public bool Eval(I Stack<T> stack) {10 public bool Eval(IPushStack<T> stack) { 9 11 if (stack.Count < 3) return false; 10 12 … … 17 19 [PushExpression(StackTypes.Integer, "INTEGER.ROT")] 18 20 public class IntegerRotateExpression : RotateExpression<long> { 19 public override bool Eval(I PushInterpreter interpreter) {21 public override bool Eval(IInternalPushInterpreter interpreter) { 20 22 return Eval(interpreter.IntegerStack); 21 23 } … … 24 26 [PushExpression(StackTypes.Float, "FLOAT.ROT")] 25 27 public class FloatRotateExpression : RotateExpression<double> { 26 public override bool Eval(I PushInterpreter interpreter) {28 public override bool Eval(IInternalPushInterpreter interpreter) { 27 29 return Eval(interpreter.FloatStack); 28 30 } … … 31 33 [PushExpression(StackTypes.Boolean, "BOOLEAN.ROT")] 32 34 public class BooleanRotateExpression : RotateExpression<bool> { 33 public override bool Eval(I PushInterpreter interpreter) {35 public override bool Eval(IInternalPushInterpreter interpreter) { 34 36 return Eval(interpreter.BooleanStack); 35 37 } … … 38 40 [PushExpression(StackTypes.Name, "NAME.ROT")] 39 41 public class NameRotateExpression : RotateExpression<string> { 40 public override bool Eval(I PushInterpreter interpreter) {42 public override bool Eval(IInternalPushInterpreter interpreter) { 41 43 return Eval(interpreter.NameStack); 42 44 } … … 45 47 [PushExpression(StackTypes.Exec, "EXEC.ROT")] 46 48 public class ExecRotateExpression : RotateExpression<Expression> { 47 public override bool Eval(I PushInterpreter interpreter) {49 public override bool Eval(IInternalPushInterpreter interpreter) { 48 50 return Eval(interpreter.ExecStack); 49 51 } … … 52 54 [PushExpression(StackTypes.Code, "CODE.ROT")] 53 55 public class CodeRotateExpression : RotateExpression<Expression> { 54 public override bool Eval(I PushInterpreter interpreter) {56 public override bool Eval(IInternalPushInterpreter interpreter) { 55 57 return Eval(interpreter.CodeStack); 56 58 } … … 59 61 [PushExpression(StackTypes.Char, "CHAR.ROT")] 60 62 public class CharRotateExpression : RotateExpression<char> { 61 public override bool Eval(I PushInterpreter interpreter) {63 public override bool Eval(IInternalPushInterpreter interpreter) { 62 64 return Eval(interpreter.CharStack); 63 65 } … … 66 68 [PushExpression(StackTypes.String, "STRING.ROT")] 67 69 public class StringRotateExpression : RotateExpression<string> { 68 public override bool Eval(I PushInterpreter interpreter) {70 public override bool Eval(IInternalPushInterpreter interpreter) { 69 71 return Eval(interpreter.StringStack); 70 72 } 71 73 } 74 75 [PushExpression(StackTypes.IntegerVector, "INTEGER[].ROT")] 76 public class IntegerVectorRotateExpression : RotateExpression<List<long>> { 77 public override bool Eval(IInternalPushInterpreter interpreter) { 78 return Eval(interpreter.IntegerVectorStack); 79 } 80 } 72 81 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ShoveExpressions.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 using System.Collections.Generic; 3 2 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 3 5 … … 6 8 7 9 public abstract class ShoveExpression<T> : StatelessExpression { 8 protected bool Eval(I Stack<T> stack, IStack<long> integerStack, int count = 1) {10 protected bool Eval(IPushStack<T> stack, IPushStack<long> integerStack, int count = 1) { 9 11 if (integerStack.Count == 0 || 10 12 integerStack.Top > stack.Count - count || … … 23 25 [PushExpression(StackTypes.Integer, "INTEGER.SHOVE")] 24 26 public class IntegerShoveExpression : ShoveExpression<long> { 25 public override bool Eval(I PushInterpreter interpreter) {27 public override bool Eval(IInternalPushInterpreter interpreter) { 26 28 return Eval(interpreter.IntegerStack, interpreter.IntegerStack, 2); 27 29 } … … 30 32 [PushExpression(StackTypes.Float, "FLOAT.SHOVE", StackTypes.Integer)] 31 33 public class FloatShoveExpression : ShoveExpression<double> { 32 public override bool Eval(I PushInterpreter interpreter) {34 public override bool Eval(IInternalPushInterpreter interpreter) { 33 35 return Eval(interpreter.FloatStack, interpreter.IntegerStack); 34 36 } … … 37 39 [PushExpression(StackTypes.Boolean, "BOOLEAN.SHOVE", StackTypes.Integer)] 38 40 public class BooleanShoveExpression : ShoveExpression<bool> { 39 public override bool Eval(I PushInterpreter interpreter) {41 public override bool Eval(IInternalPushInterpreter interpreter) { 40 42 return Eval(interpreter.BooleanStack, interpreter.IntegerStack); 41 43 } … … 44 46 [PushExpression(StackTypes.Name, "NAME.SHOVE", StackTypes.Integer)] 45 47 public class NameShoveExpression : ShoveExpression<string> { 46 public override bool Eval(I PushInterpreter interpreter) {48 public override bool Eval(IInternalPushInterpreter interpreter) { 47 49 return Eval(interpreter.NameStack, interpreter.IntegerStack); 48 50 } … … 51 53 [PushExpression(StackTypes.Exec, "EXEC.SHOVE", StackTypes.Integer)] 52 54 public class ExecShoveExpression : ShoveExpression<Expression> { 53 public override bool Eval(I PushInterpreter interpreter) {55 public override bool Eval(IInternalPushInterpreter interpreter) { 54 56 return Eval(interpreter.ExecStack, interpreter.IntegerStack); 55 57 } … … 58 60 [PushExpression(StackTypes.Code, "CODE.SHOVE", StackTypes.Integer)] 59 61 public class CodeShoveExpression : ShoveExpression<Expression> { 60 public override bool Eval(I PushInterpreter interpreter) {62 public override bool Eval(IInternalPushInterpreter interpreter) { 61 63 return Eval(interpreter.CodeStack, interpreter.IntegerStack); 62 64 } … … 65 67 [PushExpression(StackTypes.Char, "CHAR.SHOVE", StackTypes.Integer)] 66 68 public class CharShoveExpression : ShoveExpression<char> { 67 public override bool Eval(I PushInterpreter interpreter) {69 public override bool Eval(IInternalPushInterpreter interpreter) { 68 70 return Eval(interpreter.CharStack, interpreter.IntegerStack); 69 71 } … … 72 74 [PushExpression(StackTypes.String, "STRING.SHOVE", StackTypes.Integer)] 73 75 public class StringShoveExpression : ShoveExpression<string> { 74 public override bool Eval(I PushInterpreter interpreter) {76 public override bool Eval(IInternalPushInterpreter interpreter) { 75 77 return Eval(interpreter.StringStack, interpreter.IntegerStack); 76 78 } 77 79 } 80 81 [PushExpression(StackTypes.IntegerVector, "INTEGER[].SHOVE", StackTypes.Integer)] 82 public class IntegerVectorShoveExpression : ShoveExpression<List<long>> { 83 public override bool Eval(IInternalPushInterpreter interpreter) { 84 return Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack); 85 } 86 } 78 87 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StackdepthExpressions.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 using System.Collections.Generic; 3 2 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 3 5 … … 10 12 /// <typeparam name="T">Stacktype</typeparam> 11 13 public abstract class StackdepthExpression<T> : StatelessExpression { 12 public bool Eval(I Stack<T> stack, IStack<long> integerStack, bool incremental = false) {14 public bool Eval(IPushStack<T> stack, IPushStack<long> integerStack, bool incremental = false) { 13 15 var count = stack.Count; 14 16 … … 23 25 public class IntegerStackdepthExpression : StackdepthExpression<long> { 24 26 25 public override bool Eval(I PushInterpreter interpreter) {27 public override bool Eval(IInternalPushInterpreter interpreter) { 26 28 return Eval(interpreter.IntegerStack, interpreter.IntegerStack, true); 27 29 } … … 30 32 [PushExpression(StackTypes.Float, "FLOAT.STACKDEPTH", StackTypes.Integer)] 31 33 public class FloatStackdepthExpression : StackdepthExpression<double> { 32 public override bool Eval(I PushInterpreter interpreter) {34 public override bool Eval(IInternalPushInterpreter interpreter) { 33 35 return Eval(interpreter.FloatStack, interpreter.IntegerStack); 34 36 } … … 37 39 [PushExpression(StackTypes.Boolean, "BOOLEAN.STACKDEPTH", StackTypes.Integer)] 38 40 public class BooleanStackdepthExpression : StackdepthExpression<bool> { 39 public override bool Eval(I PushInterpreter interpreter) {41 public override bool Eval(IInternalPushInterpreter interpreter) { 40 42 return Eval(interpreter.BooleanStack, interpreter.IntegerStack); 41 43 } … … 44 46 [PushExpression(StackTypes.Name, "NAME.STACKDEPTH", StackTypes.Integer)] 45 47 public class NameStackdepthExpression : StackdepthExpression<string> { 46 public override bool Eval(I PushInterpreter interpreter) {48 public override bool Eval(IInternalPushInterpreter interpreter) { 47 49 return Eval(interpreter.NameStack, interpreter.IntegerStack); 48 50 } … … 51 53 [PushExpression(StackTypes.Exec, "EXEC.STACKDEPTH", StackTypes.Integer)] 52 54 public class ExecStackdepthExpression : StackdepthExpression<Expression> { 53 public override bool Eval(I PushInterpreter interpreter) {55 public override bool Eval(IInternalPushInterpreter interpreter) { 54 56 return Eval(interpreter.ExecStack, interpreter.IntegerStack); 55 57 } … … 58 60 [PushExpression(StackTypes.Code, "CODE.STACKDEPTH", StackTypes.Integer)] 59 61 public class CodeStackdepthExpression : StackdepthExpression<Expression> { 60 public override bool Eval(I PushInterpreter interpreter) {62 public override bool Eval(IInternalPushInterpreter interpreter) { 61 63 return Eval(interpreter.CodeStack, interpreter.IntegerStack); 62 64 } … … 65 67 [PushExpression(StackTypes.Char, "CHAR.STACKDEPTH", StackTypes.Integer)] 66 68 public class CharStackdepthExpression : StackdepthExpression<char> { 67 public override bool Eval(I PushInterpreter interpreter) {69 public override bool Eval(IInternalPushInterpreter interpreter) { 68 70 return Eval(interpreter.CharStack, interpreter.IntegerStack); 69 71 } … … 72 74 [PushExpression(StackTypes.String, "STRING.STACKDEPTH", StackTypes.Integer)] 73 75 public class StringStackdepthExpression : StackdepthExpression<string> { 74 public override bool Eval(I PushInterpreter interpreter) {76 public override bool Eval(IInternalPushInterpreter interpreter) { 75 77 return Eval(interpreter.StringStack, interpreter.IntegerStack); 76 78 } 77 79 } 80 81 [PushExpression(StackTypes.IntegerVector, "INTEGER[].STACKDEPTH", StackTypes.Integer)] 82 public class IntegerVectorStackdepthExpression : StackdepthExpression<List<long>> { 83 public override bool Eval(IInternalPushInterpreter interpreter) { 84 return Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack); 85 } 86 } 78 87 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StringExpressions.cs
r14777 r14834 9 9 [PushExpression(StackTypes.String, "STRING.FROMINTEGER", StackTypes.Integer)] 10 10 public class StringFromIntegerExpression : StatelessExpression { 11 public override bool Eval(I PushInterpreter interpreter) {11 public override bool Eval(IInternalPushInterpreter interpreter) { 12 12 if (interpreter.IntegerStack.IsEmpty) 13 13 return false; … … 21 21 [PushExpression(StackTypes.String, "STRING.FROMFLOAT", StackTypes.Float)] 22 22 public class StringFromFloatExpression : StatelessExpression { 23 public override bool Eval(I PushInterpreter interpreter) {23 public override bool Eval(IInternalPushInterpreter interpreter) { 24 24 if (interpreter.FloatStack.IsEmpty) 25 25 return false; … … 33 33 [PushExpression(StackTypes.String, "STRING.FROMBOOLEAN", StackTypes.Boolean)] 34 34 public class StringFromBooleanExpression : StatelessExpression { 35 public override bool Eval(I PushInterpreter interpreter) {35 public override bool Eval(IInternalPushInterpreter interpreter) { 36 36 if (interpreter.BooleanStack.IsEmpty) 37 37 return false; … … 45 45 [PushExpression(StackTypes.String, "STRING.FROMCHAR", StackTypes.Char)] 46 46 public class StringFromCharExpression : StatelessExpression { 47 public override bool Eval(I PushInterpreter interpreter) {47 public override bool Eval(IInternalPushInterpreter interpreter) { 48 48 if (interpreter.CharStack.IsEmpty) 49 49 return false; … … 57 57 [PushExpression(StackTypes.String, "STRING.CONCAT")] 58 58 public class StringConcatExpression : StatelessExpression { 59 public override bool Eval(I PushInterpreter interpreter) {59 public override bool Eval(IInternalPushInterpreter interpreter) { 60 60 if (interpreter.StringStack.Count < 2 || 61 61 interpreter.StringStack.Top.Length + interpreter.StringStack.ReverseElementAt(1).Length >= interpreter.Configuration.MaxStringLength) … … 73 73 [PushExpression(StackTypes.String, "STRING.CONJCHAR", StackTypes.Char)] 74 74 public class StringConjCharExpression : StatelessExpression { 75 public override bool Eval(I PushInterpreter interpreter) {75 public override bool Eval(IInternalPushInterpreter interpreter) { 76 76 if (interpreter.StringStack.IsEmpty || 77 77 interpreter.CharStack.IsEmpty || … … 87 87 [PushExpression(StackTypes.String, "STRING.TAKE", StackTypes.Integer)] 88 88 public class StringTakeExpression : StatelessExpression { 89 public override bool Eval(I PushInterpreter interpreter) {89 public override bool Eval(IInternalPushInterpreter interpreter) { 90 90 if (interpreter.StringStack.IsEmpty || 91 91 interpreter.IntegerStack.IsEmpty) … … 111 111 [PushExpression(StackTypes.String, "STRING.SUBSTRING", StackTypes.Integer)] 112 112 public class StringSubstringExpression : StatelessExpression { 113 public override bool Eval(I PushInterpreter interpreter) {113 public override bool Eval(IInternalPushInterpreter interpreter) { 114 114 if (interpreter.StringStack.IsEmpty || 115 115 interpreter.IntegerStack.Count < 2) … … 131 131 [PushExpression(StackTypes.String, "STRING.FIRST")] 132 132 public class StringFirstExpression : StatelessExpression { 133 public override bool Eval(I PushInterpreter interpreter) {133 public override bool Eval(IInternalPushInterpreter interpreter) { 134 134 if (interpreter.StringStack.IsEmpty || 135 135 interpreter.StringStack.Top.Length == 0) … … 144 144 [PushExpression(StackTypes.String, "STRING.LAST")] 145 145 public class StringLastExpression : StatelessExpression { 146 public override bool Eval(I PushInterpreter interpreter) {146 public override bool Eval(IInternalPushInterpreter interpreter) { 147 147 if (interpreter.StringStack.IsEmpty || 148 148 interpreter.StringStack.Top.Length == 0) … … 158 158 [PushExpression(StackTypes.String, "STRING.NTH", StackTypes.Integer)] 159 159 public class StringNthExpression : StatelessExpression { 160 public override bool Eval(I PushInterpreter interpreter) {160 public override bool Eval(IInternalPushInterpreter interpreter) { 161 161 if (interpreter.StringStack.IsEmpty || 162 162 interpreter.IntegerStack.IsEmpty || … … 174 174 [PushExpression(StackTypes.String, "STRING.REST")] 175 175 public class StringRestExpression : StatelessExpression { 176 public override bool Eval(I PushInterpreter interpreter) {176 public override bool Eval(IInternalPushInterpreter interpreter) { 177 177 if (interpreter.StringStack.IsEmpty || 178 178 interpreter.StringStack.Top.Length == 0) … … 187 187 [PushExpression(StackTypes.String, "STRING.BUTLAST")] 188 188 public class StringButLastExpression : StatelessExpression { 189 public override bool Eval(I PushInterpreter interpreter) {189 public override bool Eval(IInternalPushInterpreter interpreter) { 190 190 if (interpreter.StringStack.IsEmpty || 191 191 interpreter.StringStack.Top.Length == 0) … … 200 200 [PushExpression(StackTypes.String, "STRING.LENGTH", StackTypes.Integer)] 201 201 public class StringLengthExpression : StatelessExpression { 202 public override bool Eval(I PushInterpreter interpreter) {202 public override bool Eval(IInternalPushInterpreter interpreter) { 203 203 if (interpreter.StringStack.IsEmpty) 204 204 return false; … … 212 212 [PushExpression(StackTypes.String, "STRING.REVERSE")] 213 213 public class StringReverseExpression : StatelessExpression { 214 public override bool Eval(I PushInterpreter interpreter) {214 public override bool Eval(IInternalPushInterpreter interpreter) { 215 215 if (interpreter.StringStack.IsEmpty) 216 216 return false; … … 223 223 [PushExpression(StackTypes.String, "STRING.PARSETOCHARS")] 224 224 public class StringParseToCharsExpression : StatelessExpression { 225 public override bool Eval(I PushInterpreter interpreter) {225 public override bool Eval(IInternalPushInterpreter interpreter) { 226 226 if (interpreter.StringStack.IsEmpty) 227 227 return false; … … 250 250 [PushExpression(StackTypes.String, "STRING.SPLIT")] 251 251 public class StringSplitExpression : StatelessExpression { 252 public override bool Eval(I PushInterpreter interpreter) {252 public override bool Eval(IInternalPushInterpreter interpreter) { 253 253 if (interpreter.StringStack.IsEmpty) 254 254 return false; … … 274 274 [PushExpression(StackTypes.String, "STRING.EMPTYSTRING", StackTypes.Boolean)] 275 275 public class StringEmptyStringExpression : StatelessExpression { 276 public override bool Eval(I PushInterpreter interpreter) {276 public override bool Eval(IInternalPushInterpreter interpreter) { 277 277 if (interpreter.StringStack.IsEmpty) 278 278 return false; … … 289 289 [PushExpression(StackTypes.String, "STRING.CONTAINS", StackTypes.Boolean)] 290 290 public class StringContainsExpression : StatelessExpression { 291 public override bool Eval(I PushInterpreter interpreter) {291 public override bool Eval(IInternalPushInterpreter interpreter) { 292 292 if (interpreter.StringStack.Count < 2) 293 293 return false; … … 304 304 [PushExpression(StackTypes.String, "STRING.CONTAINSCHAR", StackTypes.Boolean | StackTypes.Char)] 305 305 public class StringContainsCharExpression : StatelessExpression { 306 public override bool Eval(I PushInterpreter interpreter) {306 public override bool Eval(IInternalPushInterpreter interpreter) { 307 307 if (interpreter.StringStack.IsEmpty || 308 308 interpreter.CharStack.IsEmpty) … … 322 322 [PushExpression(StackTypes.String, "STRING.INDEXOFCHAR", StackTypes.Integer | StackTypes.Char)] 323 323 public class StringIndexOfCharExpression : StatelessExpression { 324 public override bool Eval(I PushInterpreter interpreter) {324 public override bool Eval(IInternalPushInterpreter interpreter) { 325 325 if (interpreter.StringStack.IsEmpty || 326 326 interpreter.CharStack.IsEmpty) … … 340 340 [PushExpression(StackTypes.String, "STRING.OCCURENCESOFCHAR", StackTypes.Integer | StackTypes.Char)] 341 341 public class StringOccurrencesOfCharExpression : StatelessExpression { 342 public override bool Eval(I PushInterpreter interpreter) {342 public override bool Eval(IInternalPushInterpreter interpreter) { 343 343 if (interpreter.StringStack.IsEmpty || 344 344 interpreter.CharStack.IsEmpty) … … 362 362 [PushExpression(StackTypes.String, "STRING.REPLACE")] 363 363 public class StringReplaceExpression : StatelessExpression { 364 public override bool Eval(I PushInterpreter interpreter) {364 public override bool Eval(IInternalPushInterpreter interpreter) { 365 365 if (interpreter.StringStack.Count < 3) 366 366 return false; … … 383 383 /// </summary> 384 384 [PushExpression(StackTypes.String, "STRING.REPLACEFIRST")] 385 public class StringReplace FirstExpression : StatelessExpression {386 public override bool Eval(I PushInterpreter interpreter) {385 public class StringReplaceLastExpression : StatelessExpression { 386 public override bool Eval(IInternalPushInterpreter interpreter) { 387 387 if (interpreter.StringStack.Count < 3) 388 388 return false; … … 409 409 [PushExpression(StackTypes.String, "STRING.REPLACECHAR", StackTypes.Char)] 410 410 public class StringReplaceCharExpression : StatelessExpression { 411 public override bool Eval(I PushInterpreter interpreter) {411 public override bool Eval(IInternalPushInterpreter interpreter) { 412 412 if (interpreter.StringStack.IsEmpty || 413 413 interpreter.CharStack.Count < 2) … … 425 425 /// </summary> 426 426 [PushExpression(StackTypes.String, "STRING.REPLACEFIRSTCHAR", StackTypes.Char)] 427 public class StringReplace FirstCharExpression : StatelessExpression {428 public override bool Eval(I PushInterpreter interpreter) {427 public class StringReplaceLastCharExpression : StatelessExpression { 428 public override bool Eval(IInternalPushInterpreter interpreter) { 429 429 if (interpreter.StringStack.IsEmpty || 430 430 interpreter.CharStack.Count < 2) … … 451 451 [PushExpression(StackTypes.String, "STRING.REMOVECHAR", StackTypes.Char)] 452 452 public class StringRemoveCharExpression : StatelessExpression { 453 public override bool Eval(I PushInterpreter interpreter) {453 public override bool Eval(IInternalPushInterpreter interpreter) { 454 454 if (interpreter.StringStack.IsEmpty || 455 455 interpreter.CharStack.IsEmpty) … … 468 468 [PushExpression(StackTypes.String, "STRING.SETCHAR", StackTypes.Char | StackTypes.Integer)] 469 469 public class StringSetCharExpression : StatelessExpression { 470 public override bool Eval(I PushInterpreter interpreter) {470 public override bool Eval(IInternalPushInterpreter interpreter) { 471 471 if (interpreter.StringStack.IsEmpty || 472 472 interpreter.CharStack.IsEmpty || -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/SwapExpressions.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 using System.Collections.Generic; 3 2 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 3 5 … … 10 12 /// <typeparam name="T">Stacktype</typeparam> 11 13 public abstract class SwapExpression<T> : StatelessExpression { 12 public bool Eval(I Stack<T> stack) {14 public bool Eval(IPushStack<T> stack) { 13 15 if (stack.Count < 2) 14 16 return false; … … 21 23 [PushExpression(StackTypes.Integer, "INTEGER.SWAP")] 22 24 public class IntegerSwapExpression : SwapExpression<long> { 23 public override bool Eval(I PushInterpreter interpreter) {25 public override bool Eval(IInternalPushInterpreter interpreter) { 24 26 return Eval(interpreter.IntegerStack); 25 27 } … … 28 30 [PushExpression(StackTypes.Float, "FLOAT.SWAP")] 29 31 public class FloatSwapExpression : SwapExpression<double> { 30 public override bool Eval(I PushInterpreter interpreter) {32 public override bool Eval(IInternalPushInterpreter interpreter) { 31 33 return Eval(interpreter.FloatStack); 32 34 } … … 35 37 [PushExpression(StackTypes.Boolean, "BOOLEAN.SWAP")] 36 38 public class BooleanSwapExpression : SwapExpression<bool> { 37 public override bool Eval(I PushInterpreter interpreter) {39 public override bool Eval(IInternalPushInterpreter interpreter) { 38 40 return Eval(interpreter.BooleanStack); 39 41 } … … 42 44 [PushExpression(StackTypes.Name, "NAME.SWAP")] 43 45 public class NameSwapExpression : SwapExpression<string> { 44 public override bool Eval(I PushInterpreter interpreter) {46 public override bool Eval(IInternalPushInterpreter interpreter) { 45 47 return Eval(interpreter.NameStack); 46 48 } … … 49 51 [PushExpression(StackTypes.Exec, "EXEC.SWAP")] 50 52 public class ExecSwapExpression : SwapExpression<Expression> { 51 public override bool Eval(I PushInterpreter interpreter) {53 public override bool Eval(IInternalPushInterpreter interpreter) { 52 54 return Eval(interpreter.ExecStack); 53 55 } … … 56 58 [PushExpression(StackTypes.Code, "CODE.SWAP")] 57 59 public class CodeSwapExpression : SwapExpression<Expression> { 58 public override bool Eval(I PushInterpreter interpreter) {60 public override bool Eval(IInternalPushInterpreter interpreter) { 59 61 return Eval(interpreter.CodeStack); 60 62 } … … 63 65 [PushExpression(StackTypes.Char, "CHAR.SWAP")] 64 66 public class CharSwapExpression : SwapExpression<char> { 65 public override bool Eval(I PushInterpreter interpreter) {67 public override bool Eval(IInternalPushInterpreter interpreter) { 66 68 return Eval(interpreter.CharStack); 67 69 } … … 70 72 [PushExpression(StackTypes.String, "STRING.SWAP")] 71 73 public class StringSwapExpression : SwapExpression<string> { 72 public override bool Eval(I PushInterpreter interpreter) {74 public override bool Eval(IInternalPushInterpreter interpreter) { 73 75 return Eval(interpreter.StringStack); 74 76 } 75 77 } 78 79 [PushExpression(StackTypes.IntegerVector, "INTEGER[].SWAP")] 80 public class IntegerVectorSwapExpression : SwapExpression<List<long>> { 81 public override bool Eval(IInternalPushInterpreter interpreter) { 82 return Eval(interpreter.IntegerVectorStack); 83 } 84 } 76 85 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/YankDuplicateExpressions.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 using System.Collections.Generic; 3 2 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 3 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; … … 10 12 /// <typeparam name="T">Stacktype</typeparam> 11 13 public abstract class YankDuplicateExpression<T> : StatelessExpression { 12 public bool Eval(I Stack<T> stack, IStack<long> integerStack) {14 public bool Eval(IPushStack<T> stack, IPushStack<long> integerStack) { 13 15 T item; 14 16 if (!this.TryGetItem(stack, integerStack, out item)) … … 19 21 } 20 22 21 public bool Eval(I Stack<Expression> stack, IStack<long> integerStack) {23 public bool Eval(IPushStack<Expression> stack, IPushStack<long> integerStack) { 22 24 Expression item; 23 25 if (!this.TryGetItem(stack, integerStack, out item)) … … 28 30 } 29 31 30 public bool Eval(I Stack<long> integerStack) {32 public bool Eval(IPushStack<long> integerStack) { 31 33 if ((integerStack.Count < 2) || (integerStack.Top > integerStack.Count - 2) || 32 34 (integerStack.Top < 0)) return false; … … 39 41 } 40 42 41 private bool TryGetItem<E>(I Stack<E> stack, IStack<long> integerStack, out E item) {43 private bool TryGetItem<E>(IPushStack<E> stack, IPushStack<long> integerStack, out E item) { 42 44 if ((integerStack.Count == 0) || 43 45 (integerStack.Top >= stack.Count) || … … 57 59 [PushExpression(StackTypes.Integer, "INTEGER.YANKDUP")] 58 60 public class IntegerYankDuplicateExpression : YankDuplicateExpression<long> { 59 public override bool Eval(I PushInterpreter interpreter) {61 public override bool Eval(IInternalPushInterpreter interpreter) { 60 62 return this.Eval(interpreter.IntegerStack); 61 63 } … … 64 66 [PushExpression(StackTypes.Float, "FLOAT.YANKDUP", StackTypes.Integer)] 65 67 public class FloatYankDuplicateExpression : YankDuplicateExpression<double> { 66 public override bool Eval(I PushInterpreter interpreter) {68 public override bool Eval(IInternalPushInterpreter interpreter) { 67 69 return this.Eval(interpreter.FloatStack, interpreter.IntegerStack); 68 70 } … … 71 73 [PushExpression(StackTypes.Boolean, "BOOLEAN.YANKDUP", StackTypes.Integer)] 72 74 public class BooleanYankDuplicateExpression : YankDuplicateExpression<bool> { 73 public override bool Eval(I PushInterpreter interpreter) {75 public override bool Eval(IInternalPushInterpreter interpreter) { 74 76 return this.Eval(interpreter.BooleanStack, interpreter.IntegerStack); 75 77 } … … 78 80 [PushExpression(StackTypes.Name, "NAME.YANKDUP", StackTypes.Integer)] 79 81 public class NameYankDuplicateExpression : YankDuplicateExpression<string> { 80 public override bool Eval(I PushInterpreter interpreter) {82 public override bool Eval(IInternalPushInterpreter interpreter) { 81 83 return this.Eval(interpreter.NameStack, interpreter.IntegerStack); 82 84 } … … 85 87 [PushExpression(StackTypes.Exec, "EXEC.YANKDUP", StackTypes.Integer)] 86 88 public class ExecYankDuplicateExpression : YankDuplicateExpression<Expression> { 87 public override bool Eval(I PushInterpreter interpreter) {89 public override bool Eval(IInternalPushInterpreter interpreter) { 88 90 return this.Eval(interpreter.ExecStack, interpreter.IntegerStack); 89 91 } … … 92 94 [PushExpression(StackTypes.Code, "CODE.YANKDUP", StackTypes.Integer)] 93 95 public class CodeYankDuplicateExpression : YankDuplicateExpression<Expression> { 94 public override bool Eval(I PushInterpreter interpreter) {96 public override bool Eval(IInternalPushInterpreter interpreter) { 95 97 return this.Eval(interpreter.CodeStack, interpreter.IntegerStack); 96 98 } … … 99 101 [PushExpression(StackTypes.Char, "CHAR.YANKDUP", StackTypes.Integer)] 100 102 public class CharYankDuplicateExpression : YankDuplicateExpression<char> { 101 public override bool Eval(I PushInterpreter interpreter) {103 public override bool Eval(IInternalPushInterpreter interpreter) { 102 104 return Eval(interpreter.CharStack, interpreter.IntegerStack); 103 105 } … … 106 108 [PushExpression(StackTypes.String, "STRING.YANKDUP", StackTypes.Integer)] 107 109 public class StringYankDuplicateExpression : YankDuplicateExpression<string> { 108 public override bool Eval(I PushInterpreter interpreter) {110 public override bool Eval(IInternalPushInterpreter interpreter) { 109 111 return Eval(interpreter.StringStack, interpreter.IntegerStack); 110 112 } 111 113 } 114 115 [PushExpression(StackTypes.IntegerVector, "INTEGER[].YANKDUP", StackTypes.Integer)] 116 public class IntegerVectorYankDuplicateExpression : YankDuplicateExpression<List<long>> { 117 public override bool Eval(IInternalPushInterpreter interpreter) { 118 return Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack); 119 } 120 } 112 121 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/YankExpressions.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 using System.Collections.Generic; 3 2 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 3 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; … … 10 12 /// <typeparam name="T">Stacktype</typeparam> 11 13 public abstract class YankExpression<T> : StatelessExpression { 12 public bool Eval(I Stack<T> stack, IStack<long> integerStack, int count = 1) {14 public bool Eval(IPushStack<T> stack, IPushStack<long> integerStack, int count = 1) { 13 15 if (integerStack.Count == 0) return false; 14 16 … … 26 28 [PushExpression(StackTypes.Integer, "INTEGER.YANK")] 27 29 public class IntegerYankExpression : YankExpression<long> { 28 public override bool Eval(I PushInterpreter interpreter) {30 public override bool Eval(IInternalPushInterpreter interpreter) { 29 31 return this.Eval(interpreter.IntegerStack, interpreter.IntegerStack, 2); 30 32 } … … 33 35 [PushExpression(StackTypes.Float, "FLOAT.YANK", StackTypes.Integer)] 34 36 public class FloatYankExpression : YankExpression<double> { 35 public override bool Eval(I PushInterpreter interpreter) {37 public override bool Eval(IInternalPushInterpreter interpreter) { 36 38 return this.Eval(interpreter.FloatStack, interpreter.IntegerStack); 37 39 } … … 40 42 [PushExpression(StackTypes.Boolean, "BOOLEAN.YANK", StackTypes.Integer)] 41 43 public class BooleanYankExpression : YankExpression<bool> { 42 public override bool Eval(I PushInterpreter interpreter) {44 public override bool Eval(IInternalPushInterpreter interpreter) { 43 45 return this.Eval(interpreter.BooleanStack, interpreter.IntegerStack); 44 46 } … … 47 49 [PushExpression(StackTypes.Name, "NAME.YANK", StackTypes.Integer)] 48 50 public class NameYankExpression : YankExpression<string> { 49 public override bool Eval(I PushInterpreter interpreter) {51 public override bool Eval(IInternalPushInterpreter interpreter) { 50 52 return this.Eval(interpreter.NameStack, interpreter.IntegerStack); 51 53 } … … 54 56 [PushExpression(StackTypes.Exec, "EXEC.YANK", StackTypes.Integer)] 55 57 public class ExecYankExpression : YankExpression<Expression> { 56 public override bool Eval(I PushInterpreter interpreter) {58 public override bool Eval(IInternalPushInterpreter interpreter) { 57 59 return this.Eval(interpreter.ExecStack, interpreter.IntegerStack); 58 60 } … … 61 63 [PushExpression(StackTypes.Code, "CODE.YANK", StackTypes.Integer)] 62 64 public class CodeYankExpression : YankExpression<Expression> { 63 public override bool Eval(I PushInterpreter interpreter) {65 public override bool Eval(IInternalPushInterpreter interpreter) { 64 66 return this.Eval(interpreter.CodeStack, interpreter.IntegerStack); 65 67 } … … 68 70 [PushExpression(StackTypes.Char, "CHAR.YANK", StackTypes.Integer)] 69 71 public class CharYankExpression : YankExpression<char> { 70 public override bool Eval(I PushInterpreter interpreter) {72 public override bool Eval(IInternalPushInterpreter interpreter) { 71 73 return Eval(interpreter.CharStack, interpreter.IntegerStack); 72 74 } … … 75 77 [PushExpression(StackTypes.String, "STRING.YANK", StackTypes.Integer)] 76 78 public class StringYankExpression : YankExpression<string> { 77 public override bool Eval(I PushInterpreter interpreter) {79 public override bool Eval(IInternalPushInterpreter interpreter) { 78 80 return Eval(interpreter.StringStack, interpreter.IntegerStack); 79 81 } 80 82 } 83 84 [PushExpression(StackTypes.IntegerVector, "INTEGER[].YANK", StackTypes.Integer)] 85 public class IntegerVectorYankExpression : YankExpression<List<long>> { 86 public override bool Eval(IInternalPushInterpreter interpreter) { 87 return Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack); 88 } 89 } 81 90 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/IPushInterpreter.cs
r14777 r14834 7 7 8 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool;10 9 11 10 using Stack; … … 13 12 public interface IPushInterpreter { 14 13 IRandom Random { get; set; } 15 16 IStack<Expression> CodeStack { get; } 17 IStack<Expression> ExecStack { get; } 18 IStack<string> NameStack { get; } 19 IStack<bool> BooleanStack { get; } 20 IStack<long> IntegerStack { get; } 21 IStack<double> FloatStack { get; } 22 IStack<char> CharStack { get; } 23 IStack<string> StringStack { get; } 24 14 IPushStack<Expression> CodeStack { get; } 15 IPushStack<Expression> ExecStack { get; } 16 IPushStack<string> NameStack { get; } 17 IPushStack<bool> BooleanStack { get; } 18 IPushStack<long> IntegerStack { get; } 19 IPushStack<double> FloatStack { get; } 20 IPushStack<char> CharStack { get; } 21 IPushStack<string> StringStack { get; } 22 IPushStack<List<long>> IntegerVectorStack { get; } 23 IPushStack<List<double>> FloatVectorStack { get; } 24 IPushStack<List<bool>> BooleanVectorStack { get; } 25 IPushStack<List<string>> StringVectorStack { get; } 25 26 IDictionary<string, Expression> CustomExpressions { get; } 26 27 27 IReadOnlyPushConfiguration Configuration { get; } 28 29 InterpreterPoolContainer PoolContainer { get; }30 31 bool IsNameQuoteFlagSet { get; set; }32 33 28 void Clear(); 34 29 void Run(string code, bool stepwise = false); 35 30 void Run(Expression expression, bool stepwise = false); 36 Task RunAsync(Expression expression, bool paused = false,CancellationToken token = default(CancellationToken));37 Task RunAsync(string code, bool paused = false,CancellationToken token = default(CancellationToken));31 Task RunAsync(Expression expression, CancellationToken token = default(CancellationToken)); 32 Task RunAsync(string code, CancellationToken token = default(CancellationToken)); 38 33 Task AbortAndResetAsync(); 39 34 Task AbortAsync(); … … 41 36 void Resume(); 42 37 Task ResumeAsync(); 43 44 38 bool Step(); 45 void PrintStacks();46 39 } 47 40 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/InterpreterPoolContainer.cs
r14777 r14834 22 22 expressionListPoolProvider = new ManagedPoolProvider<PooledList<Expression>>(partitionSize, () => new PooledList<Expression>(), maxPartitionCount); 23 23 24 InitStatefulExpressionPools( );24 InitStatefulExpressionPools(partitionSize, maxPartitionCount); 25 25 } 26 26 … … 33 33 this.expressionListPoolProvider = expressionListPoolProvider; 34 34 35 InitStatefulExpressionPools( );35 InitStatefulExpressionPools(1024, 2048); 36 36 } 37 37 38 public IManagedPool<PushProgram> PushProgramPool { get; private set; } 39 public IManagedPool<LoopState> LoopStatePool { get; private set; } 40 public IManagedPool<PooledList<Expression>> ExpressionListPool { get; private set; } 38 private IManagedPool<PushProgram> pushProgramPool; 39 public IManagedPool<PushProgram> PushProgramPool 40 { 41 get 42 { 43 if (pushProgramPool == null) pushProgramPool = pushProgramPoolProvider.CreatePool(); 44 return pushProgramPool; 45 } 46 } 41 47 42 private void InitStatefulExpressionPools() { 48 private IManagedPool<LoopState> loopStatePool; 49 public IManagedPool<LoopState> LoopStatePool 50 { 51 get 52 { 53 if (loopStatePool == null) loopStatePool = loopStatePoolProvider.CreatePool(); 54 return loopStatePool; 55 } 56 } 57 58 private IManagedPool<PooledList<Expression>> expressionListPool; 59 public IManagedPool<PooledList<Expression>> ExpressionListPool 60 { 61 get 62 { 63 if (expressionListPool == null) expressionListPool = expressionListPoolProvider.CreatePool(); 64 return expressionListPool; 65 } 66 } 67 68 private void InitStatefulExpressionPools(int partitionSize, int maxPartitionCount) { 43 69 for (var i = 0; i < ExpressionTable.StatefulExpressionTypes.Length; i++) { 44 70 var type = ExpressionTable.StatefulExpressionTypes[i]; 45 71 var name = ExpressionTable.TypeToNameTable[type]; 46 var factory = ExpressionTable.StatefulExpressionFactory[name];47 72 48 statefulExpressionPoolProviders.Add(type, new ManagedPoolProvider<Expression>(1024, factory)); 73 statefulExpressionPoolProviders.Add(type, new ManagedPoolProvider<Expression>( 74 partitionSize, 75 ExpressionTable.StatefulExpressionFactory[name], 76 maxPartitionCount)); 49 77 50 78 statefulExpressionPools.Add(type, null); … … 52 80 } 53 81 54 public IManagedPool<Expression> GetStatefulExpressionPool<T, StateT>() where T : StatefulExpression<StateT> { 55 return statefulExpressionPools[typeof(T)]; 82 public T GetStatefulExpression<T>() where T : Expression { 83 var type = typeof(T); 84 if (statefulExpressionPools[type] == null) 85 statefulExpressionPools[type] = statefulExpressionPoolProviders[type].CreatePool(); 86 87 return (T)statefulExpressionPools[type].Get(); 56 88 } 57 89 58 public T GetStatefulExpression<T>() where T : Expression { 59 return (T)statefulExpressionPools[typeof(T)].Get(); 60 } 90 public void DisposePools() { 91 if (pushProgramPool != null) { 92 pushProgramPool.Dispose(); 93 pushProgramPool = null; 94 } 61 95 62 public void CreatePools() { 63 PushProgramPool = pushProgramPoolProvider.CreatePool(); 64 LoopStatePool = loopStatePoolProvider.CreatePool(); 65 ExpressionListPool = expressionListPoolProvider.CreatePool(); 96 if (loopStatePool != null) { 97 loopStatePool.Dispose(); 98 loopStatePool = null; 99 } 100 101 if (expressionListPool != null) { 102 expressionListPool.Dispose(); 103 expressionListPool = null; 104 } 66 105 67 106 for (var i = 0; i < ExpressionTable.StatefulExpressionTypes.Length; i++) { 68 107 var type = ExpressionTable.StatefulExpressionTypes[i]; 69 statefulExpressionPools[type] = statefulExpressionPoolProviders[type].CreatePool(); 70 } 71 } 108 var pool = statefulExpressionPools[type]; 72 109 73 public void DisposePools() { 74 if (PushProgramPool != null) PushProgramPool.Dispose(); 75 if (LoopStatePool != null) LoopStatePool.Dispose(); 76 if (ExpressionListPool != null) ExpressionListPool.Dispose(); 77 78 for (var i = 0; i < ExpressionTable.StatefulExpressionTypes.Length; i++) { 79 var type = ExpressionTable.StatefulExpressionTypes[i]; 80 if (statefulExpressionPools[type] != null) statefulExpressionPools[type].Dispose(); 110 if (pool != null) { 111 pool.Dispose(); 112 statefulExpressionPools[type] = null; 113 } 81 114 } 82 115 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PooledPushInterpreter.cs
r14777 r14834 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter { 2 using System;3 2 4 3 using HeuristicLab.Core; 5 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 6 5 7 public class PooledPushInterpreter : PushInterpreter , IDisposable{6 public class PooledPushInterpreter : PushInterpreter { 8 7 9 8 private readonly PushInterpreterPool pool; … … 14 13 } 15 14 16 public void Dispose() {17 this.Reset();18 this.Configuration = this.Configuration;19 this.pool.Free(this);15 public override void Dispose() { 16 base.Dispose(); 17 Reset(); 18 pool.Free(this); 20 19 } 21 20 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreter.cs
r14777 r14834 2 2 using System; 3 3 using System.Collections.Generic; 4 #if DEBUG5 #endif6 4 using System.Runtime.CompilerServices; 7 5 using System.Threading; 8 6 using System.Threading.Tasks; 9 using HeuristicLab.Core; 10 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 11 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Parser; 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 14 using HeuristicLab.Random; 15 16 public class PushInterpreter : IPushInterpreter { 7 using Attributes; 8 using Configuration; 9 using Core; 10 using Expressions; 11 using Parser; 12 using Random; 13 using Stack; 14 15 #if DEBUG 16 using System.Diagnostics; 17 using System.Linq; 18 #endif 19 20 public class PushInterpreter : IInternalPushInterpreter, IDisposable { 17 21 private Task currentTask; 18 22 … … 27 31 28 32 CodeStack = new PushStack<Expression>(Configuration.EvalPushLimit) { 29 IsEnabled = Configuration. IsCodeStackEnabled33 IsEnabled = Configuration.EnabledStacks[StackTypes.Code] 30 34 }; 31 35 32 36 NameStack = new PushStack<string> { 33 IsEnabled = Configuration. IsNameStackEnabled37 IsEnabled = Configuration.EnabledStacks[StackTypes.Code] 34 38 }; 35 39 BooleanStack = new PushStack<bool> { 36 IsEnabled = Configuration. IsBooleanStackEnabled40 IsEnabled = Configuration.EnabledStacks[StackTypes.Boolean] 37 41 }; 38 42 IntegerStack = new PushStack<long> { 39 IsEnabled = Configuration. IsIntegerStackEnabled43 IsEnabled = Configuration.EnabledStacks[StackTypes.Integer] 40 44 }; 41 45 FloatStack = new PushStack<double> { 42 IsEnabled = Configuration. IsFloatStackEnabled46 IsEnabled = Configuration.EnabledStacks[StackTypes.Float] 43 47 }; 44 48 CharStack = new PushStack<char> { 45 IsEnabled = Configuration. IsCharStackEnabled49 IsEnabled = Configuration.EnabledStacks[StackTypes.Char] 46 50 }; 47 51 StringStack = new PushStack<string> { 48 IsEnabled = Configuration.IsStringStackEnabled 52 IsEnabled = Configuration.EnabledStacks[StackTypes.String] 53 }; 54 IntegerVectorStack = new PushStack<List<long>> { 55 IsEnabled = Configuration.EnabledStacks[StackTypes.IntegerVector] 56 }; 57 FloatVectorStack = new PushStack<List<double>> { 58 IsEnabled = Configuration.EnabledStacks[StackTypes.FloatVector] 59 }; 60 BooleanVectorStack = new PushStack<List<bool>> { 61 IsEnabled = Configuration.EnabledStacks[StackTypes.BooleanVector] 62 }; 63 StringVectorStack = new PushStack<List<string>> { 64 IsEnabled = Configuration.EnabledStacks[StackTypes.StringVector] 49 65 }; 50 66 … … 81 97 get 82 98 { 83 return ExecStack. Count == 0;99 return ExecStack.IsEmpty || ExecCounter >= Configuration.EvalPushLimit; 84 100 } 85 101 } … … 97 113 public IReadOnlyPushConfiguration Configuration { get; protected set; } 98 114 99 public IStack<Expression> CodeStack { get; private set; } 100 101 public IStack<Expression> ExecStack { get; private set; } 102 103 public IStack<string> NameStack { get; private set; } 104 105 public IStack<bool> BooleanStack { get; private set; } 106 107 public IStack<long> IntegerStack { get; private set; } 108 109 public IStack<double> FloatStack { get; private set; } 110 public IStack<char> CharStack { get; private set; } 111 public IStack<string> StringStack { get; private set; } 115 [PushStack(StackTypes.Code)] 116 public IPushStack<Expression> CodeStack { get; private set; } 117 118 [PushStack(StackTypes.Exec)] 119 public IPushStack<Expression> ExecStack { get; private set; } 120 121 [PushStack(StackTypes.Name)] 122 public IPushStack<string> NameStack { get; private set; } 123 124 [PushStack(StackTypes.Boolean)] 125 public IPushStack<bool> BooleanStack { get; private set; } 126 127 [PushStack(StackTypes.Integer)] 128 public IPushStack<long> IntegerStack { get; private set; } 129 130 [PushStack(StackTypes.Float)] 131 public IPushStack<double> FloatStack { get; private set; } 132 133 [PushStack(StackTypes.Char)] 134 public IPushStack<char> CharStack { get; private set; } 135 136 [PushStack(StackTypes.String)] 137 public IPushStack<string> StringStack { get; private set; } 138 139 [PushStack(StackTypes.IntegerVector)] 140 public IPushStack<List<long>> IntegerVectorStack { get; private set; } 141 142 [PushStack(StackTypes.FloatVector)] 143 public IPushStack<List<double>> FloatVectorStack { get; private set; } 144 145 [PushStack(StackTypes.BooleanVector)] 146 public IPushStack<List<bool>> BooleanVectorStack { get; private set; } 147 148 [PushStack(StackTypes.StringVector)] 149 public IPushStack<List<string>> StringVectorStack { get; private set; } 112 150 113 151 public IDictionary<string, Expression> CustomExpressions { get; private set; } … … 115 153 public bool IsNameQuoteFlagSet { get; set; } 116 154 117 public Task RunAsync(string code, bool stepwise = false,CancellationToken token = default(CancellationToken)) {155 public Task RunAsync(string code, CancellationToken token = default(CancellationToken)) { 118 156 var program = PushParser.Parse(code); 119 120 currentTask = RunAsync(program, stepwise, token); 121 157 currentTask = RunAsync(program, token); 122 158 return currentTask; 123 159 } 124 public async Task RunAsync( 125 Expression expression, 126 bool stepwise = false, 127 CancellationToken token = default(CancellationToken)) { 128 await Task.Run(() => Run(expression, stepwise), token); 160 public async Task RunAsync(Expression expression, CancellationToken token = default(CancellationToken)) { 161 await Task.Run(() => Run(expression, false), token); 129 162 } 130 163 … … 134 167 } 135 168 136 public void Run(Expression program, bool stepwise = false) { 137 PoolContainer.CreatePools(); 138 169 public void Run(Expression expression, bool stepwise = false) { 139 170 IsPaused = stepwise; 140 171 141 172 /* Push top expression so the loop is able to enter 142 * If the top expression is a single statement then the loop has nothing to do 143 * Otherwise the expand expression will be evaluated and pushes code onto the EXEC stack */ 144 ExecStack.Push(program); 145 146 if (Configuration.TopLevelPushCode) CodeStack.Insert(0, program); 147 148 // run top expression 149 DoStep(); 150 Interpret(); 151 152 PoolContainer.DisposePools(); 173 * If the top expression is a single statement then the loop has nothing to do. 174 * Otherwise the expand expression will be evaluated and pushes code onto the EXEC stack. 175 * Expanding the initial program is not counted */ 176 ExecStack.Push(expression); 177 178 if (Configuration.TopLevelPushCode) CodeStack.Insert(0, expression); 179 180 // expand if program 181 if (expression.IsProgram) 182 DoStep(); 183 184 Run(); 153 185 } 154 186 … … 188 220 189 221 IsPaused = false; 190 Interpret();222 this.Run(); 191 223 } 192 224 … … 196 228 197 229 var successful = DoStep(); 198 Finally(); 230 231 if (IsCompleted) 232 Finally(); 199 233 200 234 return successful; … … 204 238 public void Step(int count) { 205 239 for (var i = 0; i < count; i++) Step(); 206 }207 208 public void PrintStacks() {209 PrintStack("EXEC", ExecStack);210 PrintStack("CODE", CodeStack);211 PrintStack("NAME", NameStack);212 PrintStack("BOOLEAN", BooleanStack);213 PrintStack("FLOAT", FloatStack);214 PrintStack("INTEGER", IntegerStack);215 216 if (CustomExpressions.Count > 0) {217 Console.WriteLine("--------- Custom Expressions ---------");218 foreach (var ce in CustomExpressions) {219 Console.WriteLine("{0}: {1}", ce.Key, ce.Value);220 }221 }222 240 } 223 241 … … 226 244 /// </summary> 227 245 public void Reset() { 246 ExecCounter = 0; 247 228 248 IsAborted = false; 229 249 IsPaused = false; … … 234 254 235 255 /// <summary> 236 /// Clears stacks 256 /// Clears stacks and custom expressions 237 257 /// </summary> 238 258 public void Clear() { 239 ExecCounter = 0;240 241 259 ExecStack.Clear(); 242 260 CodeStack.Clear(); 243 244 261 NameStack.Clear(); 245 262 BooleanStack.Clear(); … … 251 268 252 269 [MethodImpl(MethodImplOptions.AggressiveInlining)] 253 private void Interpret() {254 while (IsRunning) {270 private void Run() { 271 while (IsRunning) 255 272 DoStep(); 256 ExecCounter++; 257 } 258 259 Finally(); 273 274 if (IsCompleted) 275 Finally(); 260 276 } 261 277 262 278 [MethodImpl(MethodImplOptions.AggressiveInlining)] 263 279 private void Finally() { 264 if (!IsCompleted) 265 return; 266 267 if (Configuration.TopLevelPopCode && (CodeStack.Count > 0)) 280 if (Configuration.TopLevelPopCode && !CodeStack.IsEmpty) 268 281 CodeStack.Pop(); 282 283 PoolContainer.DisposePools(); 269 284 } 270 285 … … 272 287 private Expression last; 273 288 private bool DoStep() { 289 double[] bk; 290 if (!FloatStack.IsEmpty) { 291 bk = FloatStack.Peek(Math.Min(FloatStack.Count, 3)); 292 } 293 274 294 var expression = ExecStack.Pop(); 275 276 //if (ExecStack.Any(e => e == null)) {277 // throw new InvalidProgramException();278 //}279 280 295 var succ = expression.Eval(this); 281 //last = expression; 282 296 297 if ((ExecStack.Count > 0 && ExecStack.Top == null) || 298 (CodeStack.Count > 0 && CodeStack.Top == null) || 299 FloatStack.Any(x => double.IsNaN(x) || double.IsInfinity(x)) || 300 StringStack.Count > 0 && StringStack.Any(x => x == null)) { 301 Debugger.Break(); 302 } 303 304 ExecCounter++; 305 last = expression; 283 306 return succ; 284 307 } … … 286 309 [MethodImpl(MethodImplOptions.AggressiveInlining)] 287 310 private bool DoStep() { 311 ExecCounter++; 288 312 return ExecStack.Pop().Eval(this); 289 313 } … … 291 315 292 316 private Task InterpretAsync() { 293 currentTask = Task.Run(() => Interpret());317 currentTask = Task.Run(() => this.Run()); 294 318 295 319 return currentTask; 296 320 } 297 321 298 private void PrintStack<T>(string name, IStack<T> stack) { 299 if (stack.IsEmpty) return; 300 Console.WriteLine("--------- {0} ---------\n{1}\n", name, stack); 322 public virtual void Dispose() { 323 PoolContainer.DisposePools(); 301 324 } 302 325 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Interpreter/PushInterpreterPool.cs
r14777 r14834 14 14 public readonly ManagedPoolProvider<PooledList<Expression>> ExpressionListPoolProvider; 15 15 16 17 16 public PushInterpreterPool(IReadOnlyPushConfiguration config = null) 18 17 : this(Environment.ProcessorCount * 2, 1024, null, config) { 19 18 } 20 19 21 public PushInterpreterPool(int size, int p ushProgramPoolPartitionSize, int? maxPartitionCount = null, IReadOnlyPushConfiguration config = null) {20 public PushInterpreterPool(int size, int poolPartitionSize, int? maxPartitionCount = null, IReadOnlyPushConfiguration config = null) { 22 21 PushGpConfiguration = config ?? new PushConfiguration(); 23 22 24 PushProgramPoolProvider = new ManagedPoolProvider<PushProgram>(p ushProgramPoolPartitionSize, () => new PushProgram(), maxPartitionCount);25 LoopStatePoolProvider = new ManagedPoolProvider<LoopState>(p ushProgramPoolPartitionSize, () => new LoopState(), maxPartitionCount);26 ExpressionListPoolProvider = new ManagedPoolProvider<PooledList<Expression>>(p ushProgramPoolPartitionSize * 2, () => new PooledList<Expression>(), maxPartitionCount);23 PushProgramPoolProvider = new ManagedPoolProvider<PushProgram>(poolPartitionSize, () => new PushProgram(), maxPartitionCount); 24 LoopStatePoolProvider = new ManagedPoolProvider<LoopState>(poolPartitionSize, () => new LoopState(), maxPartitionCount); 25 ExpressionListPoolProvider = new ManagedPoolProvider<PooledList<Expression>>(poolPartitionSize * 2, () => new PooledList<Expression>(), maxPartitionCount); 27 26 28 27 pool = new ObjectPool<PooledPushInterpreter>(() => { … … 35 34 36 35 public PooledPushInterpreter Create(IRandom random = null) { 37 var interpreter = this.pool.Allocate();38 interpreter.Random = random ?? new FastRandom();36 var interpreter = pool.Allocate(); 37 interpreter.Random = random ?? new MersenneTwister(); 39 38 40 39 return interpreter; … … 42 41 43 42 public void Free(PooledPushInterpreter interpreter) { 44 this.pool.Free(interpreter);43 pool.Free(interpreter); 45 44 } 46 45 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/DataBounds.cs
r14777 r14834 7 7 8 8 [StorableClass] 9 public class DataBounds : Parameter Collection{9 public class DataBounds : ParameterizedNamedItem { 10 10 11 11 private const string TrainingParameterName = "Training"; … … 16 16 17 17 public DataBounds(int trainingStart, int trainingEnd, int testStart, int testEnd) { 18 Add(new FixedValueParameter<IntRange>(TrainingParameterName, new IntRange(trainingStart, trainingEnd)));19 Add(new FixedValueParameter<IntRange>(TestParameterName, new IntRange(testStart, testEnd)));18 Parameters.Add(new FixedValueParameter<IntRange>(TrainingParameterName, new IntRange(trainingStart, trainingEnd))); 19 Parameters.Add(new FixedValueParameter<IntRange>(TestParameterName, new IntRange(testStart, testEnd))); 20 20 } 21 21 … … 29 29 public IValueParameter<IntRange> TrainingParameter 30 30 { 31 get { return (IValueParameter<IntRange>) this[TrainingParameterName]; }31 get { return (IValueParameter<IntRange>)Parameters[TrainingParameterName]; } 32 32 } 33 33 … … 40 40 public IValueParameter<IntRange> TestParameter 41 41 { 42 get { return (IValueParameter<IntRange>) this[TestParameterName]; }42 get { return (IValueParameter<IntRange>)Parameters[TestParameterName]; } 43 43 } 44 44 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushEvaluator.cs
r14777 r14834 6 6 using HeuristicLab.BenchmarkSuite.Problems; 7 7 using HeuristicLab.Core; 8 using HeuristicLab.Optimization;9 8 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 10 9 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; … … 19 18 interpreter.Run(program); 20 19 21 return GetDiff(example.OutputInt, interpreter.IntegerStack, worstResult, LongDiffer) 22 + GetDiff(example.OutputFloat, interpreter.FloatStack, worstResult, DoubleDiffer) 23 + GetDiff(example.OutputBoolean, interpreter.BooleanStack, worstResult, BooleanDiffer); 20 var result = GetDiff(example.OutputInt, interpreter.IntegerStack, worstResult, LongDiffer) 21 + GetDiff(example.OutputFloat, interpreter.FloatStack, worstResult, DoubleDiffer) 22 + GetDiff(example.OutputBoolean, interpreter.BooleanStack, worstResult, BooleanDiffer); 23 24 return result; 24 25 } 25 26 26 public static double Evaluate(PushProgram program, PushInterpreterPool pool, IRandom random, Data data, int startIndex, int endIndex) { 27 if (endIndex - startIndex <= 0) return default(double); 28 var result = 0d; 27 public static EvaluationResult Evaluate(PushProgram program, PushInterpreterPool pool, IRandom random, Data data, int startIndex, int endIndex) { 28 var length = endIndex - startIndex; 29 if (length <= 0) return null; 30 31 var evaluationResult = new EvaluationResult(length); 29 32 30 33 using (var interpreter = pool.Create(random)) { 31 34 for (var i = startIndex; i < endIndex; i++) { 32 result += Evaluate(interpreter, program, data.Examples[i], data.WorstResult); 33 interpreter.Clear(); 35 var result = Evaluate(interpreter, program, data.Examples[i], data.WorstResult); 36 evaluationResult.ExampleQualities[i - startIndex] = result; 37 evaluationResult.TotalQuality += result; 38 interpreter.Reset(); 34 39 } 35 40 } 36 41 37 return result / (endIndex - startIndex); 42 evaluationResult.TotalQuality /= length; 43 44 return evaluationResult; 38 45 } 39 46 40 public static doubleEvaluate(Individual individual, PushInterpreterPool pool, IRandom random, Data data, int startIndex, int endIndex) {41 var program = individual.PushProgram(pool.PushGpConfiguration.EnabledExpressions as IReadOnlyList<string>);42 return Evaluate(program, pool, random, data, startIndex, endIndex);43 }47 //public static EvaluationResult Evaluate(Individual individual, PushInterpreterPool pool, IRandom random, Data data, int startIndex, int endIndex) { 48 // var program = individual.ToPushProgram(pool.PushGpConfiguration); 49 // return Evaluate(program, pool, random, data, startIndex, endIndex); 50 //} 44 51 45 52 private static double DoubleDiffer(double a, double b) { 46 53 var result = a - b; 47 54 48 return result == double.MinValue ? double.MaxValue : Math.Abs(result); 55 if (result == double.MinValue || double.IsPositiveInfinity(result) || double.IsNaN(result)) 56 return double.MaxValue; 57 58 if (result == double.MaxValue || double.IsNegativeInfinity(result)) 59 return double.MinValue; 60 61 return Math.Abs(result); 49 62 } 50 63 … … 59 72 } 60 73 61 private static double GetDiff<T>(IReadOnlyList<T> estimated, I Stack<T> resultStack, double worstResult, Func<T, T, double> differ)74 private static double GetDiff<T>(IReadOnlyList<T> estimated, IPushStack<T> resultStack, double worstResult, Func<T, T, double> differ) 62 75 where T : IComparable { 76 if (estimated.Count == 0) return 0d; 63 77 64 var count = Math.Min(estimated.Count, resultStack.Count);65 var result = resultStack.Peek(count);66 var comparableLength = Math.Min(estimated.Count, result.Length);67 78 var diff = 0d; 79 var comparableLength = 0; 68 80 69 for (var i = 0; i < comparableLength; i++) { 70 diff += Math.Min(differ(estimated[i], result[0]), worstResult); 81 if (!resultStack.IsEmpty) { 82 var count = Math.Min(estimated.Count, resultStack.Count); 83 var result = resultStack.Peek(count); 84 comparableLength = Math.Min(estimated.Count, result.Length); 85 86 for (var i = 0; i < comparableLength; i++) { 87 diff += Math.Min(differ(estimated[i], result[i]), worstResult); 88 } 71 89 } 72 90 73 if (estimated.Count > result.Length) {74 diff += worstResult * (estimated.Count - comparableLength);91 for (var i = comparableLength; i < estimated.Count - comparableLength; i++) { 92 diff += differ(estimated[i], default(T)); 75 93 } 76 94 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushProblem.cs
r14777 r14834 4 4 using System.Collections.Generic; 5 5 using System.Linq; 6 using BenchmarkSuite.Problems; 6 7 using Common; 7 8 using Configuration; 8 9 using Core; 10 using Data.Pool; 9 11 using Encodings.IntegerVectorEncoding; 10 11 using HeuristicLab.BenchmarkSuite; 12 using HeuristicLab.BenchmarkSuite.Problems; 12 using Expressions; 13 13 using HeuristicLab.Data; 14 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 15 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 14 using HeuristicLab.Problems.ProgramSynthesis.Push.Erc; 16 15 17 16 using Instances; … … 20 19 using Parameters; 21 20 using Persistence.Default.CompositeSerializers.Storable; 21 using Random; 22 using Stack; 22 23 23 24 [StorableClass] … … 28 29 private readonly PushConfiguration config; 29 30 private PushInterpreterPool pool; 30 private IBenchmarkSuiteDataDescriptor dataDescriptor; 31 private readonly ObjectPool<IRandom> randomPool = new ObjectPool<IRandom>(() => new MersenneTwister()); 32 33 public const string CaseQualitiesScopeParameterName = "CaseQualities"; 31 34 32 35 public PushProblem() { 33 36 config = new PushConfiguration(); 34 pool = new PushInterpreterPool(10000, 4096, 65536, config); 35 37 38 InitData(); 36 39 InitEvents(); 37 40 InitParameters(); 38 Instructions = config;39 41 } 40 42 … … 47 49 : base(original, cloner) { 48 50 config = cloner.Clone(original.config); 49 pool = new PushInterpreterPool(65536, 1024, 65536, config); 50 51 Instructions = config; 52 53 this.InitEvents(); 51 52 InitData(); 53 InitEvents(); 54 54 } 55 55 … … 57 57 // ReSharper disable once UnusedMember.Local 58 58 private void AfterDeserialization() { 59 pool = new PushInterpreterPool(config); 60 Instructions = config; 61 59 InitData(); 62 60 InitEvents(); 61 } 62 63 private void InitData() { 64 pool = new PushInterpreterPool(Environment.ProcessorCount * 2, 4096, 1024, config); 65 66 //var solutionCreator = new PointsBasedPushProgramCreator(config.ErcOptions); 67 //SolutionCreator = solutionCreator; 68 //Encoding.SolutionCreator = solutionCreator; 63 69 } 64 70 … … 68 74 69 75 private void EnabledExpressionsChanged(object sender, EnabledExpressionsChangedEventArgs e) { 70 this.Encoding.Bounds[0, 1] = config.EnabledExpressions.Count - 1;71 this.Encoding.BoundsParameter.Value[0, 1] = config.EnabledExpressions.Count - 1;76 this.Encoding.Bounds[0, 1] = config.EnabledExpressions.Count; 77 this.Encoding.BoundsParameter.Value[0, 1] = config.EnabledExpressions.Count; 72 78 } 73 79 74 80 #region Parameters 75 81 82 private const string DataBoundsParameterName = "DataBounds"; 83 private const string DataParameterName = "Data"; 84 private const string DataParameterDescription = "Program Synthesis"; 85 private const string InstructionsParameterName = "Instructions"; 86 private const string InstructionsParameterDescription = "Enables/Disables Instructions"; 76 87 private const string EvalPushLimitParameterName = "EvalPushLimit"; 77 88 private const string EvalPushLimitParameterDescription = "This is the maximum allowed number of \"executions\" in a single top-level call to the interpreter. The execution of a single Push instruction counts as one execution, as does the processing of a single literal, as does the descent into one layer of parentheses (that is, the processing of the \"(\" counts as one execution)."; 78 private const string MaxP rogramLengthParameterName = "MaxProgramLength";89 private const string MaxPointsInProgramParameterName = "MaxProgramLength"; 79 90 private const string MaxProgramLengthParameterDescription = "This is the maximum size of an item on the CODE stack, expressed as a number of points. A point is an instruction, a literal, or a pair of parentheses."; 80 91 private const string TopLevelPushCodeParameterName = "TopLevelPushCode"; … … 82 93 private const string TopLevelPopCodeParameterName = "TopLevelPopCode"; 83 94 private const string TopLevelPopCodeParameterDescription = "When TRUE, the CODE stack will be popped at the end of top level calls to the interpreter. The default is FALSE."; 84 private const string InstructionsParameterName = "Instructions";85 private const string InstructionsParameterDescription = "Enables/Disables Instructions";86 private const string DataParameterName = "Data";87 private const string DataParameterDescription = "Program Synthesis";88 95 private const string MinRandomIntegerParameterName = "MinRandomInteger"; 89 96 private const string MinRandomIntegerParameterDescription = "The minimum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND."; … … 96 103 private const string NewErcNameProbabilityParameterName = "NewErcNameProbability"; 97 104 private const string NewErcNameProbabilityParameterDescription = "The probability that the selection of the ephemeral random NAME constant for inclusion in randomly generated code will produce a new name."; 98 private const string ErcProbabilityParameterName = "ErcProbability";99 private const string ErcProbabilityParameterDescription = "The probability that the selection of a epheral random literal constant for inclusion in randomly generated code will produce a new literal.";100 105 private const string MaxPointsInRandomInstructionParameterName = "MaxPointsInRandomInstruction"; 101 106 private const string MaxPointsInRandomInstructionParameterDescription = "MaxPointsInRandomInstruction"; 102 private const string DataBoundsParameterName = "DataBounds";103 private const string Max ProgramDepthParameterName = "MaxProgramDepth";104 private const string Max ProgramDepthParameterDescription = "";107 private const string ErcOptionsParameterName = "ERC options"; 108 private const string MaxStringLengthParameterName = "Max. string length"; 109 private const string MaxDepthParameterName = "Max. program recursion"; 105 110 106 111 private void InitParameters() { 107 108 112 Parameters.Add(new FixedValueParameter<DataBounds>(DataBoundsParameterName)); 113 114 Parameters.Add(new ValueParameter<IEnabledExpressionsConfiguration>( 115 InstructionsParameterName, 116 InstructionsParameterDescription, 117 config)); 118 119 Parameters.Add(new ValueParameter<Data>( 120 DataParameterName, 121 DataParameterDescription)); 122 123 Parameters.Add(new FixedValueParameter<ErcOptions>(ErcOptionsParameterName, config.ErcOptions)); 109 124 110 125 Parameters.Add(new FixedValueParameter<IntValue>( … … 114 129 115 130 Parameters.Add(new FixedValueParameter<IntValue>( 116 MaxP rogramLengthParameterName,131 MaxPointsInProgramParameterName, 117 132 MaxProgramLengthParameterDescription, 118 133 new IntValue(config.MaxPointsInProgram))); 134 Encoding.LengthParameter = Parameters[MaxPointsInProgramParameterName] as IFixedValueParameter<IntValue>; 119 135 120 136 Parameters.Add(new FixedValueParameter<BoolValue>( … … 128 144 new BoolValue(config.TopLevelPopCode)) { Hidden = true }); 129 145 130 Parameters.Add(new ValueParameter<IEnabledExpressionsConfiguration>(131 InstructionsParameterName,132 InstructionsParameterDescription));133 134 Parameters.Add(new FixedValueParameter<IntValue>(135 MinRandomIntegerParameterName,136 MinRandomIntegerParameterDescription,137 new IntValue(config.MinRandomInteger)) { Hidden = true });138 139 Parameters.Add(new FixedValueParameter<IntValue>(140 MaxRandomIntegerParameterName,141 MaxRandomIntegerParameterDescription,142 new IntValue(config.MaxRandomInteger)) { Hidden = true });143 144 Parameters.Add(new FixedValueParameter<DoubleValue>(145 MinRandomFloatParameterName,146 MinRandomFloatParameterDescription,147 new DoubleValue(config.MinRandomFloat)) { Hidden = true });148 149 Parameters.Add(new FixedValueParameter<DoubleValue>(150 MaxRandomFloatParameterName,151 MaxRandomFloatParameterDescription,152 new DoubleValue(config.MaxRandomFloat)) { Hidden = true });153 154 Parameters.Add(new FixedValueParameter<PercentValue>(155 NewErcNameProbabilityParameterName,156 NewErcNameProbabilityParameterDescription,157 new PercentValue(config.NewErcNameProbability)) { Hidden = true });158 159 Parameters.Add(new FixedValueParameter<PercentValue>(160 ErcProbabilityParameterName,161 ErcProbabilityParameterDescription,162 new PercentValue(config.ErcProbability)) { Hidden = true });163 164 146 Parameters.Add(new FixedValueParameter<IntValue>( 165 147 MaxPointsInRandomInstructionParameterName, … … 167 149 new IntValue(config.MaxPointsInRandomExpression)) { Hidden = true }); 168 150 169 Parameters.Add( 170 new FixedValueParameter<IntValue>( 171 MaxProgramDepthParameterName, 172 MaxProgramDepthParameterDescription, 173 new IntValue(config.MaxDepth))); 174 175 Parameters.Add(new ValueParameter<Data>( 176 DataParameterName, 177 DataParameterDescription)); 151 Parameters.Add(new FixedValueParameter<IntValue>( 152 MaxStringLengthParameterName, 153 new IntValue(config.MaxStringLength)) { Hidden = true }); 154 155 Parameters.Add(new FixedValueParameter<IntValue>( 156 MaxDepthParameterName, 157 new IntValue(config.MaxDepth)) { Hidden = true }); 158 159 Parameters.Add(new LookupParameter<BoolArray>("Cases", "The training cases that have been successfully executed.")); 160 Parameters.Add(new LookupParameter<DoubleArray>(CaseQualitiesScopeParameterName, "The quality of every single training case for each individual")); 178 161 179 162 Encoding.Bounds[0, 0] = 0; 180 Encoding.Bounds[0, 1] = config.EnabledExpressions.Count - 1;163 Encoding.Bounds[0, 1] = config.EnabledExpressions.Count; 181 164 Encoding.Length = config.MaxPointsInProgram; 182 165 } … … 216 199 } 217 200 201 public IValueParameter<ErcOptions> ErcOptionsParameter 202 { 203 get { return (IValueParameter<ErcOptions>)Parameters[ErcOptionsParameterName]; } 204 } 205 206 public ErcOptions ErcOptions 207 { 208 get { return config.ErcOptions; } 209 set 210 { 211 ErcOptionsParameter.Value = value; 212 config.ErcOptions = value; 213 } 214 } 215 216 /// <summary> 217 /// This is the maximum allowed number of "executions" in a single top-level call to the interpreter. 218 /// The execution of a single Push instruction counts as one execution, as does the processing of a single literal, 219 /// as does the descent into one layer of parentheses (that is, the processing of the "(" counts as one execution). 220 /// When this limit is exceeded the interpreter aborts immediately, leaving its stacks in the states they were in prior 221 /// to the abort (so they may still be examined by a calling program). Whether or not this counts as an "abnormal" 222 /// termination 223 /// is up to the calling program. 224 /// </summary> 218 225 public IValueParameter<IntValue> EvalPushLimitParameter 219 226 { … … 226 233 set 227 234 { 228 this.EvalPushLimitParameter.Value.Value = value;235 EvalPushLimitParameter.Value.Value = value; 229 236 config.EvalPushLimit = value; 230 237 } 231 238 } 232 239 240 /// <summary> 241 /// This is the maximum of depth a push program can have. Expressions, which lead to exceed this limit are interpreted as NOOP. 242 /// </summary> 233 243 public IValueParameter<IntValue> MaxDepthParameter 234 244 { 235 get { return (IValueParameter<IntValue>) this.Parameters[MaxProgramDepthParameterName]; }245 get { return (IValueParameter<IntValue>)Parameters[MaxDepthParameterName]; } 236 246 } 237 247 … … 241 251 set 242 252 { 243 this.MaxDepthParameter.Value.Value = value;253 MaxDepthParameter.Value.Value = value; 244 254 config.MaxDepth = value; 245 255 } 246 256 } 247 257 248 public IValueParameter<IntValue> MaxProgramLengthParameter 249 { 250 get { return (IValueParameter<IntValue>)this.Parameters[MaxProgramLengthParameterName]; } 251 } 252 253 public int MaxProgramLength 258 /// <summary> 259 /// This is the maximum size of an item on the CODE stack, expressed as a number of points. 260 /// A point is an instruction, a literal, or a pair of parentheses. Any instruction that would cause this limit to be 261 /// exceeded 262 /// should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the 263 /// instruction. 264 /// </summary> 265 public IValueParameter<IntValue> MaxPointsInProgramParameter 266 { 267 get { return (IValueParameter<IntValue>)this.Parameters[MaxPointsInProgramParameterName]; } 268 } 269 270 public int MaxPointsInProgram 254 271 { 255 272 get { return config.MaxPointsInProgram; } 256 273 set 257 274 { 258 this.MaxProgramLengthParameter.Value.Value = value; 259 this.Encoding.LengthParameter.Value.Value = value; 275 MaxPointsInProgramParameter.Value.Value = value; 260 276 config.MaxPointsInProgram = value; 261 277 } 262 278 } 263 279 264 public IValueParameter<BoolValue> TopLevelPushParameter 280 /// <summary> 281 /// The maximum number of points in an expression produced by the CODE.RAND instruction. 282 /// </summary> 283 public IValueParameter<IntValue> MaxPointsInRandomExpressionParameter 284 { 285 get { return (IValueParameter<IntValue>)Parameters[MaxPointsInRandomInstructionParameterName]; } 286 } 287 288 public int MaxPointsInRandomExpression 289 { 290 get { return config.MaxPointsInRandomExpression; } 291 set 292 { 293 MaxPointsInRandomExpressionParameter.Value.Value = value; 294 config.MaxPointsInRandomExpression = value; 295 } 296 } 297 298 /// <summary> 299 /// When TRUE (which is the default), code passed to the top level of the interpreter 300 /// will be pushed onto the CODE stack prior to execution. 301 /// </summary> 302 public IValueParameter<BoolValue> TopLevelPushCodeParameter 265 303 { 266 304 get { return (IValueParameter<BoolValue>)this.Parameters[TopLevelPushCodeParameterName]; } … … 272 310 set 273 311 { 274 this.TopLevelPushParameter.Value.Value = value;312 TopLevelPushCodeParameter.Value.Value = value; 275 313 config.TopLevelPushCode = value; 276 314 } 277 315 } 278 316 279 public IValueParameter<BoolValue> TopLevelPopParameter 317 /// <summary> 318 /// When TRUE, the CODE stack will be popped at the end of top level calls to the interpreter. The default is FALSE. 319 /// </summary> 320 public IValueParameter<BoolValue> TopLevelPopCodeParameter 280 321 { 281 322 get { return (IValueParameter<BoolValue>)this.Parameters[TopLevelPopCodeParameterName]; } … … 287 328 set 288 329 { 289 this.TopLevelPushParameter.Value.Value = value;330 TopLevelPopCodeParameter.Value.Value = value; 290 331 config.TopLevelPopCode = value; 291 332 } 292 333 } 293 334 294 public IValueParameter<IntValue> MinRandomIntegerParameter 295 { 296 get { return (IValueParameter<IntValue>)this.Parameters[MinRandomIntegerParameterName]; } 297 } 298 299 public int MinRandomInteger 300 { 301 get { return config.MinRandomInteger; } 302 set 303 { 304 this.MinRandomIntegerParameter.Value.Value = value; 305 config.MinRandomInteger = value; 306 } 307 } 308 309 public IValueParameter<IntValue> MaxRandomIntegerParameter 310 { 311 get { return (IValueParameter<IntValue>)this.Parameters[MaxRandomIntegerParameterName]; } 312 } 313 314 public int MaxRandomInteger 315 { 316 get { return config.MaxRandomInteger; } 317 set 318 { 319 this.MaxRandomIntegerParameter.Value.Value = value; 320 config.MaxRandomInteger = value; 321 } 322 } 323 324 public IValueParameter<DoubleValue> MinRandomFloatParameter 325 { 326 get { return (IValueParameter<DoubleValue>)this.Parameters[MinRandomFloatParameterName]; } 327 } 328 329 public double MinRandomFloat 330 { 331 get { return config.MinRandomFloat; } 332 set 333 { 334 this.MinRandomFloatParameter.Value.Value = value; 335 config.MinRandomFloat = value; 336 } 337 } 338 339 public IValueParameter<DoubleValue> MaxRandomFloatParameter 340 { 341 get { return (IValueParameter<DoubleValue>)this.Parameters[MaxRandomFloatParameterName]; } 342 } 343 344 public double MaxRandomFloat 345 { 346 get { return config.MaxRandomFloat; } 347 set 348 { 349 this.MaxRandomFloatParameter.Value.Value = value; 350 config.MaxRandomFloat = value; 351 } 352 } 353 354 public IValueParameter<PercentValue> NewErcNameProbabilityParameter 355 { 356 get { return (IValueParameter<PercentValue>)this.Parameters[NewErcNameProbabilityParameterName]; } 357 } 358 359 public double NewErcNameProbability 360 { 361 get { return config.NewErcNameProbability; } 362 set 363 { 364 this.NewErcNameProbabilityParameter.Value.Value = value; 365 config.NewErcNameProbability = value; 366 } 367 } 368 369 public IValueParameter<PercentValue> ErcProbabilityParameter 370 { 371 get { return (IValueParameter<PercentValue>)this.Parameters[ErcProbabilityParameterName]; } 372 } 373 374 public double ErcProbability 375 { 376 get { return config.ErcProbability; } 377 set 378 { 379 this.ErcProbabilityParameter.Value.Value = value; 380 config.ErcProbability = value; 381 } 382 } 383 384 public IValueParameter<IntValue> MaxPointsInRandomInstructionParameter 385 { 386 get { return (IValueParameter<IntValue>)Parameters[MaxPointsInRandomInstructionParameterName]; } 387 } 388 389 public int MaxPointsInRandomInstruction 390 { 391 get { return config.MaxPointsInRandomExpression; } 392 set 393 { 394 this.MaxPointsInRandomInstructionParameter.Value.Value = value; 395 config.MaxPointsInRandomExpression = value; 396 } 397 } 398 335 public IValueParameter<IntValue> MaxStringLengthParameter 336 { 337 get { return (IValueParameter<IntValue>)Parameters[MaxStringLengthParameterName]; } 338 } 339 340 public int MaxStringLength 341 { 342 get { return config.MaxStringLength; } 343 set 344 { 345 MaxStringLengthParameter.Value.Value = value; 346 config.MaxStringLength = value; 347 } 348 } 399 349 #endregion 400 350 … … 414 364 if (!results.ContainsKey(bestSolutionResultName)) { 415 365 results.Add(new Result(bestSolutionResultName, solution)); 416 } else if (((PushSolution)results[bestSolutionResultName].Value).Quality < qualities[bestIdx]) { 417 results[bestSolutionResultName].Value = solution; 366 } else { 367 var currentBestQuality = ((PushSolution)results[bestSolutionResultName].Value).Quality; 368 369 if (Maximization && currentBestQuality < bestQuality || 370 !Maximization && currentBestQuality > bestQuality) { 371 results[bestSolutionResultName].Value = solution; 372 } 418 373 } 419 374 } 420 375 421 376 public override double Evaluate(Individual individual, IRandom random) { 422 return PushEvaluator.Evaluate(individual, pool, random, Data, DataBounds.TrainingRange.Start, DataBounds.TrainingRange.End); 377 var program = individual.ToPushProgram(config, randomPool); 378 var result = PushEvaluator.Evaluate( 379 program, 380 pool, 381 random, 382 Data, 383 DataBounds.TrainingRange.Start, 384 DataBounds.TrainingRange.End); 385 386 individual.SetScopeValue(CaseQualitiesScopeParameterName, new DoubleArray(result.ExampleQualities)); 387 388 return result.TotalQuality; 423 389 } 424 390 … … 426 392 Data = data; 427 393 BestKnownQuality = data.BestResult; 428 MaxP rogramLength= data.MaxSize;394 MaxPointsInProgram = data.MaxSize; 429 395 EvalPushLimit = data.EvalLimit; 430 396 431 config.EnabledExpressions = (IList<string>)ExpressionTable.GetE nabledExpressionsByStackTypes((StackTypes)data.EnabledDataTypes);397 config.EnabledExpressions = (IList<string>)ExpressionTable.GetExpressionsByStackTypes((StackTypes)data.EnabledDataTypes); 432 398 433 399 // update enabled stack types 434 400 foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) { 435 var enable dStackExpressions = config.EnabledExpressions.Intersect(ExpressionTable.StackTypeToNamesTable[stackType]);436 config.SetStack(stackType, enable dStackExpressions.Any());401 var enable = config.EnabledExpressions.Intersect(ExpressionTable.StackTypeToNamesTable[stackType]).Any(); 402 config.SetStack(stackType, enable); 437 403 } 438 404 439 405 Encoding.Bounds[0, 0] = 0; 440 Encoding.Bounds[0, 1] = config.EnabledExpressions.Count - 1;406 Encoding.Bounds[0, 1] = config.EnabledExpressions.Count; 441 407 Encoding.Length = config.MaxPointsInProgram; 442 408 443 // TODO444 // data.MaxGenerations445 // data.ProgEvalBudget446 447 409 DataBounds.TrainingRange.Start = 0; 448 DataBounds.TrainingRange.End = Data.OriginalTrainingCount - 1;410 DataBounds.TrainingRange.End = Data.OriginalTrainingCount; 449 411 DataBounds.TestRange.Start = Data.OriginalTrainingCount; 450 412 DataBounds.TestRange.End = Data.OriginalTrainingCount + Data.OriginalTestCount; -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/PushSolution.cs
r14777 r14834 24 24 public readonly int DataEnd; 25 25 26 public PushSolution(IntegerVector integerVector, double quality, Data data, IRandom random, IReadOnlyPushConfiguration config, int dataStart, int dataEnd) 26 [Storable] 27 public readonly bool Simplify; 28 29 public PushSolution(IntegerVector integerVector, double quality, Data data, IRandom random, IReadOnlyPushConfiguration config, int dataStart, int dataEnd, bool simplify = false) 27 30 : base("Solution", "A push solution.") { 28 31 IntegerVector = integerVector; … … 33 36 DataStart = dataStart; 34 37 DataEnd = dataEnd; 38 Simplify = simplify; 35 39 } 36 40 … … 43 47 DataStart = origin.DataStart; 44 48 DataEnd = origin.DataEnd; 49 Simplify = origin.Simplify; 45 50 } 46 51 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Selector/ICaseSingleObjectiveSelector.cs
r14778 r14834 4 4 using HeuristicLab.Optimization; 5 5 6 public interface ICaseSing elObjectiveSelector : ISingleObjectiveSelector {6 public interface ICaseSingleObjectiveSelector : ISingleObjectiveSelector { 7 7 ILookupParameter<ItemArray<DoubleArray>> CaseQualitiesParameter { get; } 8 8 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Selector/LexicaseSelector.cs
r14778 r14834 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 25 using HeuristicLab.Common; 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Random; 31 using HeuristicLab.Selection; 22 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Selector { 23 using System; 24 using System.Collections.Generic; 25 using System.Linq; 32 26 33 namespace HeuristicLab.Misc { 34 using HeuristicLab.Problems.ProgramSynthesis.Push.Selector; 27 using HeuristicLab.Common; 28 using HeuristicLab.Core; 29 using HeuristicLab.Data; 30 using HeuristicLab.Parameters; 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using HeuristicLab.Problems.ProgramSynthesis.Push.Extensions; 33 using HeuristicLab.Problems.ProgramSynthesis.Push.Problem; 34 using HeuristicLab.Selection; 35 using Random; 35 36 36 37 /// <summary> … … 44 45 public ILookupParameter<ItemArray<DoubleArray>> CaseQualitiesParameter 45 46 { 46 get { return (ILookupParameter<ItemArray<DoubleArray>>)Parameters[ "CaseQualities"]; }47 get { return (ILookupParameter<ItemArray<DoubleArray>>)Parameters[PushProblem.CaseQualitiesScopeParameterName]; } 47 48 } 48 49 … … 54 55 } 55 56 56 public LexicaseSelector() 57 : base() { 58 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("CaseQualities", "The quality of every single training case for each individual.")); 57 public LexicaseSelector() { 58 this.Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>( 59 PushProblem.CaseQualitiesScopeParameterName, 60 "The quality of every single training case for each individual.")); 59 61 } 60 62 61 protected override IScope[] Select(List<IScope> scopes) { 62 int count = NumberOfSelectedSubScopesParameter.ActualValue.Value; 63 bool copy = CopySelectedParameter.Value.Value; 64 IRandom random = RandomParameter.ActualValue; 65 bool maximization = MaximizationParameter.ActualValue.Value; 66 List<double> qualities = QualityParameter.ActualValue.Where(x => IsValidQuality(x.Value)).Select(x => x.Value).ToList(); 67 List<DoubleArray> caseQualities = CaseQualitiesParameter.ActualValue.ToList(); 63 protected override IScope[] Select(List<IScope> population) { 64 var count = NumberOfSelectedSubScopesParameter.ActualValue.Value; 65 var copy = CopySelectedParameter.Value.Value; 66 var maximization = MaximizationParameter.ActualValue.Value; 67 var random = RandomParameter.ActualValue; 68 var selected = new IScope[count]; 69 var caseQualities = CaseQualitiesParameter.ActualValue; 70 var repeats = Math.Ceiling(count / (double)population.Count); 71 var caseCount = caseQualities[0].Length; 72 var source = population.Select((x, i) => Tuple.Create(i, x)); 68 73 69 // remove scopes, qualities and case qualities, if the case qualities are empty 70 var removeindices = Enumerable.Range(0, caseQualities.Count) 71 .Zip(caseQualities, (i, c) => new { Index = i, CaseQuality = c }) 72 .Where(c => c.CaseQuality.Count() == 0) 73 .Select(c => c.Index) 74 .Reverse(); 75 foreach (var i in removeindices) { 76 scopes.RemoveAt(i); 77 qualities.RemoveAt(i); 78 caseQualities.RemoveAt(i); 74 for (var k = 0; k < repeats; k++) { 75 // The fitness cases are shuffled. 76 var fitnessCaseIndexes = Enumerable.Range(0, caseCount).Shuffle(random).ToArray(); 77 var pool = source.ToList(); 78 var countLimit = Math.Min(count - k * population.Count, population.Count); 79 80 for (var i = 0; i < countLimit; i++) { 81 var bestIndividuals = pool; 82 83 for (var j = 0; j < fitnessCaseIndexes.Length && bestIndividuals.Count > 1; j++) 84 bestIndividuals = GetBestIndividuals(maximization, caseQualities, bestIndividuals, fitnessCaseIndexes[j]); 85 86 /* If only one individual remains, it is the chosen parent. If no more fitness cases are left, a parent is 87 chosen randomly from the remaining individuals */ 88 var currentSelected = bestIndividuals.Count == 1 ? bestIndividuals[0] : bestIndividuals.Random(random); 89 selected[k * population.Count + i] = copy ? (IScope)currentSelected.Item2.Clone() : currentSelected.Item2; 90 91 pool.Remove(currentSelected); 92 } 79 93 } 80 94 81 if (caseQualities.Any(x => x.Count() != caseQualities[0].Length)) { throw new ArgumentException("Not all case qualities have the same length"); }82 83 IScope[] selected = new IScope[count];84 85 for (int i = 0; i < count; i++) {86 int index = LexicaseSelect(caseQualities, RandomParameter.ActualValue, maximization);87 88 if (copy)89 selected[i] = (IScope)scopes[index].Clone();90 else {91 selected[i] = scopes[index];92 scopes.RemoveAt(index);93 qualities.RemoveAt(index);94 caseQualities.RemoveAt(index);95 }96 }97 95 return selected; 98 96 } 99 97 100 private int LexicaseSelect(List<DoubleArray> caseQualities, IRandom random, bool maximization) {101 IList<int> candidates = Enumerable.Range(0, caseQualities.Count()).ToList();102 IEnumerable<int> order = Enumerable.Range(0, caseQualities[0].Count()).Shuffle(random);98 private static List<Tuple<int, IScope>> GetBestIndividuals(bool maximization, ItemArray<DoubleArray> caseQualities, List<Tuple<int, IScope>> bestIndividuals, int index) { 99 var bestFitness = maximization ? double.NegativeInfinity : double.PositiveInfinity; 100 var result = new List<Tuple<int, IScope>>(); 103 101 104 foreach (int curCase in order) { 105 List<int> nextCandidates = new List<int>(); 106 double best = maximization ? double.NegativeInfinity : double.PositiveInfinity; 107 foreach (int candidate in candidates) { 108 if (caseQualities[candidate][curCase].IsAlmost(best)) { 109 // if the individuals is as good as the best one, add it 110 nextCandidates.Add(candidate); 111 } else if (((maximization) && (caseQualities[candidate][curCase] > best)) || 112 ((!maximization) && (caseQualities[candidate][curCase] < best))) { 113 // if the individuals is better than the best one, remove all previous candidates and add the new one 114 nextCandidates.Clear(); 115 nextCandidates.Add(candidate); 116 // also set the nes best quality value 117 best = caseQualities[candidate][curCase]; 118 } 119 // else {do nothing} 102 for (var l = 0; l < bestIndividuals.Count; l++) { 103 var individual = bestIndividuals[l]; 104 var caseQuality = caseQualities[individual.Item1][index]; 105 106 if (bestFitness == caseQuality) { 107 result.Add(individual); 108 } else if (maximization && bestFitness < caseQuality || 109 !maximization && bestFitness > caseQuality) { 110 bestFitness = caseQuality; 111 result.Clear(); 112 result.Add(individual); 120 113 } 121 114 122 if (nextCandidates.Count == 1) { 123 return nextCandidates.First(); 124 } else if (nextCandidates.Count < 1) { 125 return candidates.SampleRandom(random); 126 } 127 candidates = nextCandidates; 115 bestIndividuals = result; 128 116 } 129 117 130 131 if (candidates.Count == 1) { 132 return candidates.First(); 133 } 134 return candidates.SampleRandom(random); 118 return bestIndividuals; 135 119 } 136 120 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/PushStack.cs
r14777 r14834 17 17 /// </summary> 18 18 /// <typeparam name="T">The item type of the collection.</typeparam> 19 public class PushStack<T> : I Stack<T> {19 public class PushStack<T> : IPushStack<T> { 20 20 private const string Delimiter = " "; 21 21 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Stack/StackTypes.cs
r14777 r14834 13 13 Code = 0x80, 14 14 Exec = 0x100, 15 IntegerVector = 0x200, 16 FloatVector = 0x400, 17 BooleanVector = 0x800, 18 StringVector = 0x1000 15 19 } 16 20 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/ExpressionSelectionView.cs
r14777 r14834 19 19 public ExpressionSelectionView() { 20 20 InitializeComponent(); 21 21 22 InitEvents(); 22 23 Name = "Push Expression Selection Editor"; … … 28 29 set 29 30 { 31 if (Content != null) Content.EnabledExpressionsChanged -= EnabledExpressionsChanged; 30 32 base.Content = value; 31 33 } … … 35 37 base.OnReadOnlyChanged(); 36 38 37 this.expressionsTreeView.Enabled = !ReadOnly;39 expressionsTreeView.Enabled = !ReadOnly; 38 40 } 39 41 40 42 private void InitEvents() { 41 this.expressionsTreeView.AfterCheck += ExpressionsTreeViewAfterCheck;43 expressionsTreeView.AfterCheck += ExpressionsTreeViewAfterCheck; 42 44 } 43 45 44 46 private void ExpressionsTreeViewAfterCheck(object sender, TreeViewEventArgs e) { 45 var isStackNode = e.Node.Tag is StackTypes; 47 if (e.Action == TreeViewAction.Unknown) 48 return; 46 49 47 if (isStackNode) { 48 if (e.Node.Checked) { 49 Content.EnableStack((StackTypes)e.Node.Tag); 50 foreach (var subNode in e.Node.Nodes.Cast<TreeNode>()) 51 subNode.Checked = true; 52 } else { 53 Content.DisableStack((StackTypes)e.Node.Tag); 54 foreach (var subNode in e.Node.Nodes.Cast<TreeNode>()) 55 subNode.Checked = false; 56 } 50 Content.EnabledExpressionsChanged -= EnabledExpressionsChanged; 51 var stackType = (StackTypes)e.Node.Tag; 52 53 if (e.Node.Parent == null) { 54 Content.SetStack(stackType, e.Node.Checked, true); 55 SetStackNodeText(e.Node); 56 foreach (var subNode in e.Node.Nodes.OfType<TreeNode>().Where(n => n.Checked != e.Node.Checked)) 57 subNode.Checked = e.Node.Checked; 57 58 } else { 58 if (e.Node.Checked) { 59 Content.EnableExpression(e.Node.Text); 60 } else { 61 Content.DisableExpression(e.Node.Text); 62 } 59 Content.SetExpression(e.Node.Text, e.Node.Checked, true); 60 SetStackNodeText(e.Node.Parent); 61 62 if ((e.Node.Checked && !e.Node.Parent.Checked) || 63 (!e.Node.Checked && !e.Node.Parent.Nodes.OfType<TreeNode>().Any(n => n.Checked))) 64 e.Node.Parent.Checked = e.Node.Checked; 63 65 } 66 67 Content.EnabledExpressionsChanged += EnabledExpressionsChanged; 64 68 } 65 69 66 70 protected override void OnContentChanged() { 67 71 expressionsTreeView.Nodes.Clear(); 72 nameTextBox.Text = "Push Expression Selection"; 68 73 69 74 if (Content == null) { … … 71 76 } 72 77 73 this.nameTextBox.Text = "Push Expression Selection"; 78 Content.EnabledExpressionsChanged += EnabledExpressionsChanged; 79 var treeNodes = GetTreeNodes(Content.EnabledExpressions).ToArray(); 80 expressionsTreeView.Nodes.AddRange(treeNodes); 81 } 82 83 private void EnabledExpressionsChanged(object sender, EnabledExpressionsChangedEventArgs e) { 84 if (InvokeRequired) Invoke(new MethodInvoker(UpdateNodes)); 85 else UpdateNodes(); 86 } 87 88 private void UpdateNodes() { 89 expressionsTreeView.Nodes.Clear(); 74 90 75 91 var treeNodes = GetTreeNodes(Content.EnabledExpressions).ToArray(); … … 80 96 foreach (var stackType in ExpressionTable.StackTypeToNamesTable.Keys) { 81 97 var stackTreeNode = new TreeNode { 82 Tag = stackType, 83 Text = Enum.GetName(typeof(StackTypes), stackType), 98 Tag = stackType 84 99 }; 85 100 86 101 var stackExpressions = ExpressionTable.StackTypeToNamesTable[stackType]; 87 var enabledStackExpressions = enabledExpressions.Intersect( ExpressionTable.StackTypeToNamesTable[stackType]);102 var enabledStackExpressions = enabledExpressions.Intersect(stackExpressions).ToList(); 88 103 104 SetStackNodeText(stackTreeNode); 89 105 stackTreeNode.Checked = enabledStackExpressions.Any(); 90 106 … … 93 109 .Select(name => new TreeNode { 94 110 Text = name, 111 Tag = stackType, 95 112 Checked = enabledStackExpressions.Contains(name), 96 113 }).ToArray(); … … 101 118 } 102 119 } 120 121 private void SetStackNodeText(TreeNode node) { 122 var stackType = (StackTypes)node.Tag; 123 var stackExpressions = ExpressionTable.StackTypeToNamesTable[stackType]; 124 var enabledStackExpressions = Content.EnabledExpressions.Intersect(stackExpressions).ToList(); 125 126 node.Text = string.Format( 127 "{0} ({1}/{2})", 128 Enum.GetName(typeof(StackTypes), stackType), 129 enabledStackExpressions.Count, 130 ExpressionTable.StackTypeToNamesTable[stackType].Count); 131 } 103 132 } 104 133 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushProgramDebuggerView.Designer.cs
r14777 r14834 36 36 this.label1 = new System.Windows.Forms.Label(); 37 37 this.debugTableLayout = new System.Windows.Forms.TableLayoutPanel(); 38 this.codeGroupBox = new System.Windows.Forms.GroupBox();39 this.codeList = new System.Windows.Forms.ListBox();40 this.nameGroupBox = new System.Windows.Forms.GroupBox();41 this.nameList = new System.Windows.Forms.ListBox();42 this.integerGroupBox = new System.Windows.Forms.GroupBox();43 this.integerList = new System.Windows.Forms.ListBox();44 this.floatGroupBox = new System.Windows.Forms.GroupBox();45 this.groupBox2 = new System.Windows.Forms.GroupBox();46 this.listBox2 = new System.Windows.Forms.ListBox();47 this.floatList = new System.Windows.Forms.ListBox();48 38 this.execGroupBox = new System.Windows.Forms.GroupBox(); 49 this.execList = new System.Windows.Forms.ListView(); 50 this.booleanGroupBox = new System.Windows.Forms.GroupBox(); 51 this.groupBox4 = new System.Windows.Forms.GroupBox(); 52 this.listBox3 = new System.Windows.Forms.ListBox(); 53 this.booleanList = new System.Windows.Forms.ListBox(); 54 this.stringGroupBox = new System.Windows.Forms.GroupBox(); 55 this.groupBox6 = new System.Windows.Forms.GroupBox(); 56 this.listBox5 = new System.Windows.Forms.ListBox(); 57 this.stringList = new System.Windows.Forms.ListBox(); 58 this.charGroupBox = new System.Windows.Forms.GroupBox(); 59 this.groupBox8 = new System.Windows.Forms.GroupBox(); 60 this.listBox7 = new System.Windows.Forms.ListBox(); 61 this.charList = new System.Windows.Forms.ListBox(); 39 this.execList = new System.Windows.Forms.ListBox(); 62 40 this.tabPage2 = new System.Windows.Forms.TabPage(); 63 41 this.resultsDataGrid = new System.Windows.Forms.DataGridView(); … … 67 45 ((System.ComponentModel.ISupportInitialize)(this.stepWidthBox)).BeginInit(); 68 46 this.debugTableLayout.SuspendLayout(); 69 this.codeGroupBox.SuspendLayout();70 this.nameGroupBox.SuspendLayout();71 this.integerGroupBox.SuspendLayout();72 this.floatGroupBox.SuspendLayout();73 this.groupBox2.SuspendLayout();74 47 this.execGroupBox.SuspendLayout(); 75 this.booleanGroupBox.SuspendLayout();76 this.groupBox4.SuspendLayout();77 this.stringGroupBox.SuspendLayout();78 this.groupBox6.SuspendLayout();79 this.charGroupBox.SuspendLayout();80 this.groupBox8.SuspendLayout();81 48 this.tabPage2.SuspendLayout(); 82 49 ((System.ComponentModel.ISupportInitialize)(this.resultsDataGrid)).BeginInit(); … … 87 54 this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 88 55 this.errorProvider.SetIconPadding(this.nameTextBox, 2); 89 this.nameTextBox.Size = new System.Drawing.Size( 1176, 20);56 this.nameTextBox.Size = new System.Drawing.Size(889, 20); 90 57 // 91 58 // infoLabel 92 59 // 93 this.infoLabel.Location = new System.Drawing.Point( 1259, 3);60 this.infoLabel.Location = new System.Drawing.Point(972, 3); 94 61 // 95 62 // tabControl … … 103 70 this.tabControl.Name = "tabControl"; 104 71 this.tabControl.SelectedIndex = 0; 105 this.tabControl.Size = new System.Drawing.Size( 1269, 698);72 this.tabControl.Size = new System.Drawing.Size(982, 668); 106 73 this.tabControl.TabIndex = 12; 107 74 // 108 75 // tabPage1 109 76 // 77 this.tabPage1.AutoScroll = true; 110 78 this.tabPage1.Controls.Add(this.simplifyButton); 111 79 this.tabPage1.Controls.Add(this.skipNoopsCheckBox); … … 120 88 this.tabPage1.Name = "tabPage1"; 121 89 this.tabPage1.Padding = new System.Windows.Forms.Padding(3); 122 this.tabPage1.Size = new System.Drawing.Size( 1261, 672);90 this.tabPage1.Size = new System.Drawing.Size(974, 642); 123 91 this.tabPage1.TabIndex = 0; 124 92 this.tabPage1.Text = "Debug"; … … 127 95 // simplifyButton 128 96 // 129 this.simplifyButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles. Left)));130 this.simplifyButton.Location = new System.Drawing.Point( 237, 640);97 this.simplifyButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 98 this.simplifyButton.Location = new System.Drawing.Point(909, 610); 131 99 this.simplifyButton.Name = "simplifyButton"; 132 100 this.simplifyButton.Size = new System.Drawing.Size(62, 26); … … 142 110 this.skipNoopsCheckBox.Checked = true; 143 111 this.skipNoopsCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; 144 this.skipNoopsCheckBox.Location = new System.Drawing.Point(150, 6 46);112 this.skipNoopsCheckBox.Location = new System.Drawing.Point(150, 616); 145 113 this.skipNoopsCheckBox.Name = "skipNoopsCheckBox"; 146 114 this.skipNoopsCheckBox.Size = new System.Drawing.Size(81, 17); … … 153 121 this.runButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 154 122 this.runButton.Image = ((System.Drawing.Image)(resources.GetObject("runButton.Image"))); 155 this.runButton.Location = new System.Drawing.Point(40, 6 40);123 this.runButton.Location = new System.Drawing.Point(40, 610); 156 124 this.runButton.Name = "runButton"; 157 125 this.runButton.Size = new System.Drawing.Size(28, 26); … … 164 132 this.stepWidthBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 165 133 this.stepWidthBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 166 this.stepWidthBox.Location = new System.Drawing.Point(73, 6 41);134 this.stepWidthBox.Location = new System.Drawing.Point(73, 611); 167 135 this.stepWidthBox.Maximum = new decimal(new int[] { 168 136 99999, … … 188 156 this.resetButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 189 157 this.resetButton.Image = ((System.Drawing.Image)(resources.GetObject("resetButton.Image"))); 190 this.resetButton.Location = new System.Drawing.Point(6, 6 40);158 this.resetButton.Location = new System.Drawing.Point(6, 610); 191 159 this.resetButton.Name = "resetButton"; 192 160 this.resetButton.Size = new System.Drawing.Size(28, 26); 193 161 this.resetButton.TabIndex = 14; 194 this.toolTip.SetToolTip(this.resetButton, "Reset to start");162 this.toolTip.SetToolTip(this.resetButton, "ResetDebugging to start"); 195 163 this.resetButton.UseVisualStyleBackColor = true; 196 164 // … … 199 167 this.stepButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 200 168 this.stepButton.Image = ((System.Drawing.Image)(resources.GetObject("stepButton.Image"))); 201 this.stepButton.Location = new System.Drawing.Point(112, 6 40);169 this.stepButton.Location = new System.Drawing.Point(112, 610); 202 170 this.stepButton.Name = "stepButton"; 203 171 this.stepButton.Size = new System.Drawing.Size(28, 26); … … 213 181 this.exampleComboBox.Location = new System.Drawing.Point(58, 6); 214 182 this.exampleComboBox.Name = "exampleComboBox"; 215 this.exampleComboBox.Size = new System.Drawing.Size( 1165, 21);183 this.exampleComboBox.Size = new System.Drawing.Size(910, 21); 216 184 this.exampleComboBox.TabIndex = 11; 217 185 // … … 232 200 this.debugTableLayout.AutoScroll = true; 233 201 this.debugTableLayout.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; 234 this.debugTableLayout.ColumnCount = 9; 235 this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 270F)); 236 this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 270F)); 202 this.debugTableLayout.ColumnCount = 2; 203 this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 250F)); 237 204 this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); 238 this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());239 this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());240 this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());241 this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());242 this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());243 this.debugTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());244 this.debugTableLayout.Controls.Add(this.codeGroupBox, 1, 0);245 this.debugTableLayout.Controls.Add(this.nameGroupBox, 2, 0);246 this.debugTableLayout.Controls.Add(this.integerGroupBox, 3, 0);247 this.debugTableLayout.Controls.Add(this.floatGroupBox, 4, 0);248 205 this.debugTableLayout.Controls.Add(this.execGroupBox, 0, 0); 249 this.debugTableLayout.Controls.Add(this.booleanGroupBox, 5, 0);250 this.debugTableLayout.Controls.Add(this.stringGroupBox, 6, 0);251 this.debugTableLayout.Controls.Add(this.charGroupBox, 7, 0);252 206 this.debugTableLayout.Location = new System.Drawing.Point(6, 33); 253 207 this.debugTableLayout.Name = "debugTableLayout"; 254 208 this.debugTableLayout.RowCount = 1; 255 209 this.debugTableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle()); 256 this.debugTableLayout.Size = new System.Drawing.Size( 1259, 601);210 this.debugTableLayout.Size = new System.Drawing.Size(962, 563); 257 211 this.debugTableLayout.TabIndex = 2; 258 //259 // codeGroupBox260 //261 this.codeGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)262 | System.Windows.Forms.AnchorStyles.Left)263 | System.Windows.Forms.AnchorStyles.Right)));264 this.codeGroupBox.Controls.Add(this.codeList);265 this.codeGroupBox.Location = new System.Drawing.Point(273, 3);266 this.codeGroupBox.Name = "codeGroupBox";267 this.codeGroupBox.Size = new System.Drawing.Size(264, 595);268 this.codeGroupBox.TabIndex = 5;269 this.codeGroupBox.TabStop = false;270 this.codeGroupBox.Text = "Code";271 //272 // codeList273 //274 this.codeList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)275 | System.Windows.Forms.AnchorStyles.Left)276 | System.Windows.Forms.AnchorStyles.Right)));277 this.codeList.FormattingEnabled = true;278 this.codeList.HorizontalScrollbar = true;279 this.codeList.Location = new System.Drawing.Point(7, 19);280 this.codeList.Name = "codeList";281 this.codeList.SelectionMode = System.Windows.Forms.SelectionMode.None;282 this.codeList.Size = new System.Drawing.Size(251, 563);283 this.codeList.TabIndex = 1;284 //285 // nameGroupBox286 //287 this.nameGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)288 | System.Windows.Forms.AnchorStyles.Left)289 | System.Windows.Forms.AnchorStyles.Right)));290 this.nameGroupBox.Controls.Add(this.nameList);291 this.nameGroupBox.Location = new System.Drawing.Point(543, 3);292 this.nameGroupBox.Name = "nameGroupBox";293 this.nameGroupBox.Size = new System.Drawing.Size(119, 595);294 this.nameGroupBox.TabIndex = 5;295 this.nameGroupBox.TabStop = false;296 this.nameGroupBox.Text = "Name";297 //298 // nameList299 //300 this.nameList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)301 | System.Windows.Forms.AnchorStyles.Left)302 | System.Windows.Forms.AnchorStyles.Right)));303 this.nameList.FormattingEnabled = true;304 this.nameList.HorizontalScrollbar = true;305 this.nameList.Location = new System.Drawing.Point(6, 19);306 this.nameList.Name = "nameList";307 this.nameList.SelectionMode = System.Windows.Forms.SelectionMode.None;308 this.nameList.Size = new System.Drawing.Size(107, 563);309 this.nameList.TabIndex = 2;310 //311 // integerGroupBox312 //313 this.integerGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)314 | System.Windows.Forms.AnchorStyles.Left)315 | System.Windows.Forms.AnchorStyles.Right)));316 this.integerGroupBox.Controls.Add(this.integerList);317 this.integerGroupBox.Location = new System.Drawing.Point(668, 3);318 this.integerGroupBox.Name = "integerGroupBox";319 this.integerGroupBox.Size = new System.Drawing.Size(119, 595);320 this.integerGroupBox.TabIndex = 4;321 this.integerGroupBox.TabStop = false;322 this.integerGroupBox.Text = "Integer";323 //324 // integerList325 //326 this.integerList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)327 | System.Windows.Forms.AnchorStyles.Left)328 | System.Windows.Forms.AnchorStyles.Right)));329 this.integerList.FormattingEnabled = true;330 this.integerList.HorizontalScrollbar = true;331 this.integerList.Location = new System.Drawing.Point(6, 19);332 this.integerList.Name = "integerList";333 this.integerList.SelectionMode = System.Windows.Forms.SelectionMode.None;334 this.integerList.Size = new System.Drawing.Size(107, 563);335 this.integerList.TabIndex = 3;336 //337 // floatGroupBox338 //339 this.floatGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)340 | System.Windows.Forms.AnchorStyles.Left)341 | System.Windows.Forms.AnchorStyles.Right)));342 this.floatGroupBox.Controls.Add(this.groupBox2);343 this.floatGroupBox.Controls.Add(this.floatList);344 this.floatGroupBox.Location = new System.Drawing.Point(793, 3);345 this.floatGroupBox.Name = "floatGroupBox";346 this.floatGroupBox.Size = new System.Drawing.Size(119, 595);347 this.floatGroupBox.TabIndex = 5;348 this.floatGroupBox.TabStop = false;349 this.floatGroupBox.Text = "Float";350 //351 // groupBox2352 //353 this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)354 | System.Windows.Forms.AnchorStyles.Left)355 | System.Windows.Forms.AnchorStyles.Right)));356 this.groupBox2.Controls.Add(this.listBox2);357 this.groupBox2.Location = new System.Drawing.Point(1003, 3);358 this.groupBox2.Name = "groupBox2";359 this.groupBox2.Size = new System.Drawing.Size(253, 595);360 this.groupBox2.TabIndex = 6;361 this.groupBox2.TabStop = false;362 this.groupBox2.Text = "Float";363 //364 // listBox2365 //366 this.listBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)367 | System.Windows.Forms.AnchorStyles.Left)368 | System.Windows.Forms.AnchorStyles.Right)));369 this.listBox2.FormattingEnabled = true;370 this.listBox2.HorizontalScrollbar = true;371 this.listBox2.Location = new System.Drawing.Point(6, 19);372 this.listBox2.Name = "listBox2";373 this.listBox2.SelectionMode = System.Windows.Forms.SelectionMode.None;374 this.listBox2.Size = new System.Drawing.Size(107, 563);375 this.listBox2.TabIndex = 4;376 //377 // floatList378 //379 this.floatList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)380 | System.Windows.Forms.AnchorStyles.Left)381 | System.Windows.Forms.AnchorStyles.Right)));382 this.floatList.FormattingEnabled = true;383 this.floatList.HorizontalScrollbar = true;384 this.floatList.Location = new System.Drawing.Point(6, 19);385 this.floatList.Name = "floatList";386 this.floatList.SelectionMode = System.Windows.Forms.SelectionMode.None;387 this.floatList.Size = new System.Drawing.Size(107, 563);388 this.floatList.TabIndex = 4;389 212 // 390 213 // execGroupBox … … 393 216 | System.Windows.Forms.AnchorStyles.Left) 394 217 | System.Windows.Forms.AnchorStyles.Right))); 218 this.execGroupBox.AutoSize = true; 219 this.execGroupBox.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; 395 220 this.execGroupBox.Controls.Add(this.execList); 396 221 this.execGroupBox.Location = new System.Drawing.Point(3, 3); 397 222 this.execGroupBox.Name = "execGroupBox"; 398 this.execGroupBox.Size = new System.Drawing.Size(2 64, 595);223 this.execGroupBox.Size = new System.Drawing.Size(244, 557); 399 224 this.execGroupBox.TabIndex = 3; 400 225 this.execGroupBox.TabStop = false; … … 403 228 // execList 404 229 // 405 this.execList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 406 | System.Windows.Forms.AnchorStyles.Left) 407 | System.Windows.Forms.AnchorStyles.Right))); 230 this.execList.Dock = System.Windows.Forms.DockStyle.Fill; 231 this.execList.FormattingEnabled = true; 408 232 this.execList.Location = new System.Drawing.Point(3, 16); 409 233 this.execList.Name = "execList"; 410 this.execList.Size = new System.Drawing.Size(255, 571); 411 this.execList.TabIndex = 1; 412 this.execList.UseCompatibleStateImageBehavior = false; 413 this.execList.View = System.Windows.Forms.View.List; 414 this.execList.VirtualMode = true; 415 // 416 // booleanGroupBox 417 // 418 this.booleanGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 419 | System.Windows.Forms.AnchorStyles.Left) 420 | System.Windows.Forms.AnchorStyles.Right))); 421 this.booleanGroupBox.Controls.Add(this.groupBox4); 422 this.booleanGroupBox.Controls.Add(this.booleanList); 423 this.booleanGroupBox.Location = new System.Drawing.Point(918, 3); 424 this.booleanGroupBox.Name = "booleanGroupBox"; 425 this.booleanGroupBox.Size = new System.Drawing.Size(119, 595); 426 this.booleanGroupBox.TabIndex = 7; 427 this.booleanGroupBox.TabStop = false; 428 this.booleanGroupBox.Text = "Boolean"; 429 // 430 // groupBox4 431 // 432 this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 433 | System.Windows.Forms.AnchorStyles.Left) 434 | System.Windows.Forms.AnchorStyles.Right))); 435 this.groupBox4.Controls.Add(this.listBox3); 436 this.groupBox4.Location = new System.Drawing.Point(1003, 3); 437 this.groupBox4.Name = "groupBox4"; 438 this.groupBox4.Size = new System.Drawing.Size(253, 595); 439 this.groupBox4.TabIndex = 6; 440 this.groupBox4.TabStop = false; 441 this.groupBox4.Text = "Float"; 442 // 443 // listBox3 444 // 445 this.listBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 446 | System.Windows.Forms.AnchorStyles.Left) 447 | System.Windows.Forms.AnchorStyles.Right))); 448 this.listBox3.FormattingEnabled = true; 449 this.listBox3.HorizontalScrollbar = true; 450 this.listBox3.Location = new System.Drawing.Point(6, 19); 451 this.listBox3.Name = "listBox3"; 452 this.listBox3.SelectionMode = System.Windows.Forms.SelectionMode.None; 453 this.listBox3.Size = new System.Drawing.Size(107, 563); 454 this.listBox3.TabIndex = 4; 455 // 456 // booleanList 457 // 458 this.booleanList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 459 | System.Windows.Forms.AnchorStyles.Left) 460 | System.Windows.Forms.AnchorStyles.Right))); 461 this.booleanList.FormattingEnabled = true; 462 this.booleanList.HorizontalScrollbar = true; 463 this.booleanList.Location = new System.Drawing.Point(6, 19); 464 this.booleanList.Name = "booleanList"; 465 this.booleanList.SelectionMode = System.Windows.Forms.SelectionMode.None; 466 this.booleanList.Size = new System.Drawing.Size(107, 563); 467 this.booleanList.TabIndex = 4; 468 // 469 // stringGroupBox 470 // 471 this.stringGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 472 | System.Windows.Forms.AnchorStyles.Left) 473 | System.Windows.Forms.AnchorStyles.Right))); 474 this.stringGroupBox.Controls.Add(this.groupBox6); 475 this.stringGroupBox.Controls.Add(this.stringList); 476 this.stringGroupBox.Location = new System.Drawing.Point(1043, 3); 477 this.stringGroupBox.Name = "stringGroupBox"; 478 this.stringGroupBox.Size = new System.Drawing.Size(120, 595); 479 this.stringGroupBox.TabIndex = 8; 480 this.stringGroupBox.TabStop = false; 481 this.stringGroupBox.Text = "String"; 482 // 483 // groupBox6 484 // 485 this.groupBox6.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 486 | System.Windows.Forms.AnchorStyles.Left) 487 | System.Windows.Forms.AnchorStyles.Right))); 488 this.groupBox6.Controls.Add(this.listBox5); 489 this.groupBox6.Location = new System.Drawing.Point(1003, 3); 490 this.groupBox6.Name = "groupBox6"; 491 this.groupBox6.Size = new System.Drawing.Size(254, 595); 492 this.groupBox6.TabIndex = 6; 493 this.groupBox6.TabStop = false; 494 this.groupBox6.Text = "Float"; 495 // 496 // listBox5 497 // 498 this.listBox5.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 499 | System.Windows.Forms.AnchorStyles.Left) 500 | System.Windows.Forms.AnchorStyles.Right))); 501 this.listBox5.FormattingEnabled = true; 502 this.listBox5.HorizontalScrollbar = true; 503 this.listBox5.Location = new System.Drawing.Point(6, 19); 504 this.listBox5.Name = "listBox5"; 505 this.listBox5.SelectionMode = System.Windows.Forms.SelectionMode.None; 506 this.listBox5.Size = new System.Drawing.Size(108, 563); 507 this.listBox5.TabIndex = 4; 508 // 509 // stringList 510 // 511 this.stringList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 512 | System.Windows.Forms.AnchorStyles.Left) 513 | System.Windows.Forms.AnchorStyles.Right))); 514 this.stringList.FormattingEnabled = true; 515 this.stringList.HorizontalScrollbar = true; 516 this.stringList.Location = new System.Drawing.Point(6, 19); 517 this.stringList.Name = "stringList"; 518 this.stringList.SelectionMode = System.Windows.Forms.SelectionMode.None; 519 this.stringList.Size = new System.Drawing.Size(108, 563); 520 this.stringList.TabIndex = 4; 521 // 522 // charGroupBox 523 // 524 this.charGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 525 | System.Windows.Forms.AnchorStyles.Left) 526 | System.Windows.Forms.AnchorStyles.Right))); 527 this.charGroupBox.Controls.Add(this.groupBox8); 528 this.charGroupBox.Controls.Add(this.charList); 529 this.charGroupBox.Location = new System.Drawing.Point(1169, 3); 530 this.charGroupBox.Name = "charGroupBox"; 531 this.charGroupBox.Size = new System.Drawing.Size(119, 595); 532 this.charGroupBox.TabIndex = 9; 533 this.charGroupBox.TabStop = false; 534 this.charGroupBox.Text = "Char"; 535 // 536 // groupBox8 537 // 538 this.groupBox8.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 539 | System.Windows.Forms.AnchorStyles.Left) 540 | System.Windows.Forms.AnchorStyles.Right))); 541 this.groupBox8.Controls.Add(this.listBox7); 542 this.groupBox8.Location = new System.Drawing.Point(1003, 3); 543 this.groupBox8.Name = "groupBox8"; 544 this.groupBox8.Size = new System.Drawing.Size(253, 595); 545 this.groupBox8.TabIndex = 6; 546 this.groupBox8.TabStop = false; 547 this.groupBox8.Text = "Float"; 548 // 549 // listBox7 550 // 551 this.listBox7.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 552 | System.Windows.Forms.AnchorStyles.Left) 553 | System.Windows.Forms.AnchorStyles.Right))); 554 this.listBox7.FormattingEnabled = true; 555 this.listBox7.HorizontalScrollbar = true; 556 this.listBox7.Location = new System.Drawing.Point(6, 19); 557 this.listBox7.Name = "listBox7"; 558 this.listBox7.SelectionMode = System.Windows.Forms.SelectionMode.None; 559 this.listBox7.Size = new System.Drawing.Size(107, 563); 560 this.listBox7.TabIndex = 4; 561 // 562 // charList 563 // 564 this.charList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 565 | System.Windows.Forms.AnchorStyles.Left) 566 | System.Windows.Forms.AnchorStyles.Right))); 567 this.charList.FormattingEnabled = true; 568 this.charList.HorizontalScrollbar = true; 569 this.charList.Location = new System.Drawing.Point(6, 19); 570 this.charList.Name = "charList"; 571 this.charList.SelectionMode = System.Windows.Forms.SelectionMode.None; 572 this.charList.Size = new System.Drawing.Size(107, 563); 573 this.charList.TabIndex = 4; 234 this.execList.Size = new System.Drawing.Size(238, 538); 235 this.execList.TabIndex = 0; 574 236 // 575 237 // tabPage2 … … 579 241 this.tabPage2.Name = "tabPage2"; 580 242 this.tabPage2.Padding = new System.Windows.Forms.Padding(3); 581 this.tabPage2.Size = new System.Drawing.Size( 1261, 672);243 this.tabPage2.Size = new System.Drawing.Size(974, 608); 582 244 this.tabPage2.TabIndex = 1; 583 245 this.tabPage2.Text = "Results"; … … 588 250 this.resultsDataGrid.AllowUserToAddRows = false; 589 251 this.resultsDataGrid.AllowUserToDeleteRows = false; 590 this.resultsDataGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)591 | System.Windows.Forms.AnchorStyles.Left)592 | System.Windows.Forms.AnchorStyles.Right)));593 252 this.resultsDataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 253 this.resultsDataGrid.Dock = System.Windows.Forms.DockStyle.Fill; 594 254 this.resultsDataGrid.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; 595 this.resultsDataGrid.Location = new System.Drawing.Point( 7, 7);255 this.resultsDataGrid.Location = new System.Drawing.Point(3, 3); 596 256 this.resultsDataGrid.Name = "resultsDataGrid"; 597 257 this.resultsDataGrid.ReadOnly = true; 598 this.resultsDataGrid.Size = new System.Drawing.Size( 1248, 659);258 this.resultsDataGrid.Size = new System.Drawing.Size(968, 602); 599 259 this.resultsDataGrid.TabIndex = 0; 600 260 // … … 605 265 this.Controls.Add(this.tabControl); 606 266 this.Name = "PushProgramDebuggerView"; 607 this.Size = new System.Drawing.Size( 1278, 727);267 this.Size = new System.Drawing.Size(991, 697); 608 268 this.Controls.SetChildIndex(this.tabControl, 0); 609 269 this.Controls.SetChildIndex(this.nameLabel, 0); … … 616 276 ((System.ComponentModel.ISupportInitialize)(this.stepWidthBox)).EndInit(); 617 277 this.debugTableLayout.ResumeLayout(false); 618 this.codeGroupBox.ResumeLayout(false); 619 this.nameGroupBox.ResumeLayout(false); 620 this.integerGroupBox.ResumeLayout(false); 621 this.floatGroupBox.ResumeLayout(false); 622 this.groupBox2.ResumeLayout(false); 278 this.debugTableLayout.PerformLayout(); 623 279 this.execGroupBox.ResumeLayout(false); 624 this.booleanGroupBox.ResumeLayout(false);625 this.groupBox4.ResumeLayout(false);626 this.stringGroupBox.ResumeLayout(false);627 this.groupBox6.ResumeLayout(false);628 this.charGroupBox.ResumeLayout(false);629 this.groupBox8.ResumeLayout(false);630 280 this.tabPage2.ResumeLayout(false); 631 281 ((System.ComponentModel.ISupportInitialize)(this.resultsDataGrid)).EndInit(); … … 646 296 private System.Windows.Forms.ComboBox exampleComboBox; 647 297 private System.Windows.Forms.Label label1; 648 private System.Windows.Forms.TableLayoutPanel debugTableLayout;649 private System.Windows.Forms.GroupBox codeGroupBox;650 private System.Windows.Forms.ListBox codeList;651 private System.Windows.Forms.GroupBox nameGroupBox;652 private System.Windows.Forms.ListBox nameList;653 private System.Windows.Forms.GroupBox integerGroupBox;654 private System.Windows.Forms.ListBox integerList;655 private System.Windows.Forms.GroupBox floatGroupBox;656 private System.Windows.Forms.ListBox floatList;657 private System.Windows.Forms.GroupBox execGroupBox;658 private System.Windows.Forms.ListView execList;659 298 private System.Windows.Forms.TabPage tabPage2; 660 299 private System.Windows.Forms.DataGridView resultsDataGrid; 661 300 private System.Windows.Forms.Button simplifyButton; 662 private System.Windows.Forms.GroupBox stringGroupBox; 663 private System.Windows.Forms.GroupBox groupBox6; 664 private System.Windows.Forms.ListBox listBox5; 665 private System.Windows.Forms.ListBox stringList; 666 private System.Windows.Forms.GroupBox booleanGroupBox; 667 private System.Windows.Forms.GroupBox groupBox4; 668 private System.Windows.Forms.ListBox listBox3; 669 private System.Windows.Forms.ListBox booleanList; 670 private System.Windows.Forms.GroupBox groupBox2; 671 private System.Windows.Forms.ListBox listBox2; 672 private System.Windows.Forms.GroupBox charGroupBox; 673 private System.Windows.Forms.GroupBox groupBox8; 674 private System.Windows.Forms.ListBox listBox7; 675 private System.Windows.Forms.ListBox charList; 301 private System.Windows.Forms.GroupBox execGroupBox; 302 private System.Windows.Forms.TableLayoutPanel debugTableLayout; 303 private System.Windows.Forms.ListBox execList; 676 304 } 677 305 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Views/PushProgramDebuggerView.cs
r14777 r14834 6 6 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Views { 7 7 using System; 8 using System.Collections.Generic; 9 using System.Drawing; 10 using System.Globalization; 8 11 using System.Linq; 9 12 … … 11 14 using HeuristicLab.BenchmarkSuite.Problems; 12 15 using HeuristicLab.BenchmarkSuite.Views; 16 using HeuristicLab.Core; 17 using HeuristicLab.Encodings.IntegerVectorEncoding; 18 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 13 19 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 14 20 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; 15 21 using HeuristicLab.Problems.ProgramSynthesis.Push.Problem; 16 22 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack; 17 using HeuristicLab.Random;18 23 19 24 [View("Push Program Debugger")] 20 25 [Content(typeof(PushSolution), true)] 21 26 public partial class PushProgramDebuggerView : NamedItemView { 27 private readonly IDictionary<StackTypes, ListBox> debugControlDict = new Dictionary<StackTypes, ListBox>(); 28 22 29 private const string Separator = ", "; 23 30 private const string EmptySign = "-"; 31 32 private const string exampleSplitter = " => "; 33 private const string AbsoluteDiffHeaderText = "Absolute Diff."; 34 private const string RelativeDiffHeaderText = "Relative Diff."; 35 private const string InputHeaderStringFormat = "Input {0} : {1}"; 36 private const string EstimatedOuputHeaderStringFormat = "Estimated Output {0} : {1}"; 37 private const string OutputHeaderStringFormat = "Output {0} : {1}"; 38 private const string GroupBoxTextStringFormat = "{0}[{1}]"; 39 24 40 private PushProgram program; 25 26 private ListViewItem[] execListCache; //array to cache items for the virtual list 27 private int firstExecListItemIndex; //stores the index of the first item in the cache 28 29 private const string exampleSplitter = " => "; 30 private PushInterpreter interpreter; 41 private PooledPushInterpreter interpreter; 42 private PooledPushInterpreter interpreter2; // used to determine noops 43 private PushInterpreterPool pool; 31 44 32 45 public PushProgramDebuggerView() { … … 36 49 37 50 InitEvents(); 38 InitExecList(); 51 } 52 53 ~PushProgramDebuggerView() { 54 interpreter.Dispose(); 55 interpreter2.Dispose(); 39 56 } 40 57 … … 48 65 49 66 private void SimplifyButtonClick(object sender, EventArgs e) { 50 51 } 52 53 private void InitExecList() { 54 execList.RetrieveVirtualItem += ExecListRetrieveVirtualItem; 55 execList.CacheVirtualItems += ExecListCacheVirtualItems; 56 57 execList.View = View.Details; 58 execList.HeaderStyle = ColumnHeaderStyle.None; 59 execList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.None); 60 execList.Columns.Add(new ColumnHeader { Width = execList.Width - 40 }); 61 execList.VirtualMode = true; 62 execList.VirtualListSize = 100; 63 } 64 65 private void ExecListCacheVirtualItems(object sender, CacheVirtualItemsEventArgs e) { 66 //We've gotten a request to refresh the cache. 67 //First check if it's really neccesary. 68 if (execListCache != null && 69 e.StartIndex >= firstExecListItemIndex && 70 e.EndIndex <= firstExecListItemIndex + execListCache.Length) { 71 //If the newly requested cache is a subset of the old cache, 72 //no need to rebuild everything, so do nothing. 73 return; 74 } 75 76 //Now we need to rebuild the cache. 77 UpdateListCache(e.StartIndex, e.EndIndex); 78 } 79 80 private void ExecListRetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e) { 81 //check to see if the requested item is currently in the cache 82 if (execListCache == null || 83 e.ItemIndex < firstExecListItemIndex || 84 e.ItemIndex >= firstExecListItemIndex + execListCache.Length) { 85 UpdateListCache(e.ItemIndex, execList.VirtualListSize); 86 } 87 88 e.Item = e.ItemIndex >= firstExecListItemIndex && e.ItemIndex < firstExecListItemIndex + execListCache.Length 89 ? execListCache[e.ItemIndex - firstExecListItemIndex] 90 : e.Item = new ListViewItem(); 91 } 92 93 private void UpdateListCache(int startIndex, int endIndex) { 94 if (interpreter == null) { 95 execListCache = new ListViewItem[0]; 96 return; 97 } 98 99 this.firstExecListItemIndex = startIndex; 100 var length = Math.Min(endIndex - startIndex + 1, interpreter.ExecStack.Count); //indexes are inclusive 101 this.execListCache = new ListViewItem[length]; 102 103 var expressions = this.interpreter.ExecStack.Peek(length); 104 105 //Fill the cache with the appropriate ListViewItems. 106 for (var i = 0; i < length; i++) 107 this.execListCache[i] = new ListViewItem(expressions[length - 1 - i].ToString()); 108 109 execList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.None); 110 execList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); 111 } 112 113 //protected override void OnEnabledChanged(EventArgs e) { 114 // SetReadonlyFields(); 115 //} 116 117 //protected override void OnReadOnlyChanged() { 118 // base.OnReadOnlyChanged(); 119 120 // SetReadonlyFields(); 121 //} 122 123 //protected override void SetEnabledStateOfControls() 124 //{ 125 // SetReadonlyFields(); 126 //} 127 128 private void SetReadonlyFields() { 129 var enabled = !ReadOnly; 130 131 exampleComboBox.Enabled = enabled; 132 execList.Enabled = enabled; 133 codeList.Enabled = enabled; 134 nameList.Enabled = enabled; 135 integerList.Enabled = enabled; 136 floatList.Enabled = enabled; 137 booleanList.Enabled = enabled; 138 stringList.Enabled = enabled; 139 charList.Enabled = enabled; 140 stepButton.Enabled = enabled; 141 runButton.Enabled = enabled; 142 resetButton.Enabled = enabled; 143 skipNoopsCheckBox.Enabled = enabled; 144 stepWidthBox.Enabled = enabled; 67 var newContent = new PushSolution( 68 (IntegerVector)Content.IntegerVector.Clone(), 69 Content.Quality, 70 (Data)Content.Data.Clone(), 71 (IRandom)Content.Random.Clone(), 72 Content.Config, 73 Content.DataStart, 74 Content.DataEnd, 75 true); 76 77 MainFormManager.MainForm.ShowContent(newContent, GetType()); 145 78 } 146 79 … … 156 89 } 157 90 158 private void SyncExecList() {159 UpdateExecList();160 161 this.execGroupBox.Text = string.Format("Exec [{0}]", this.interpreter.ExecStack.Count);162 }163 164 91 private void StepButtonClick(object sender, EventArgs e) { 165 92 if (interpreter == null || stepWidthBox.Value <= 0) … … 168 95 var count = Math.Min(stepWidthBox.Value, interpreter.ExecStack.Count); 169 96 97 if (!interpreter.CanStep) 98 return; 99 100 // skip leading noops 101 if (interpreter2.ExecCounter == (program.IsProgram ? 1 : 0) && 102 skipNoopsCheckBox.Checked && 103 SkipNoops()) { 104 count = 0; // no entries left, cause all were noops 105 } 106 170 107 for (var i = 0; i < count; i++) { 171 108 if (skipNoopsCheckBox.Checked) { 172 bool noop; 173 174 do { 175 noop = !interpreter.Step(); 176 } 177 while (interpreter.CanStep && noop); 178 } else interpreter.Step(); 179 } 180 181 stepWidthBox.Maximum = interpreter.ExecStack.Count; 182 183 SyncExecList(); 109 interpreter.Step(); 110 111 if (SkipNoops()) 112 break; 113 } else { 114 interpreter.Step(); 115 interpreter2.Step(); 116 } 117 } 118 119 stepWidthBox.Maximum = Math.Max(1, interpreter.ExecStack.Count); 120 121 UpdateExecList(); 184 122 UpdateValueLists(); 185 123 CheckIfButtonsCanBeEnabled(); 186 124 } 187 125 126 private bool SkipNoops() { 127 var skipCount = 0; 128 bool isNoop; 129 130 do { 131 skipCount++; 132 isNoop = !interpreter2.Step(); 133 } while (interpreter2.CanStep && isNoop); 134 135 if (isNoop) { 136 interpreter.Step(skipCount); 137 } else if (skipCount > 1) { 138 interpreter.Step(skipCount - 1); 139 } 140 141 return isNoop; 142 } 143 188 144 private void CheckIfButtonsCanBeEnabled() { 189 if (interpreter == null) 190 return; 191 192 runButton.Enabled = interpreter.CanStep; 193 stepButton.Enabled = interpreter.CanStep; 194 stepWidthBox.Enabled = interpreter.CanStep; 195 } 196 197 private void ResetButtonClick(object sender, System.EventArgs e) { 198 Reset(); 199 } 200 201 private void SelectedExampleIndexChanged(object sender, System.EventArgs e) { 202 Reset(); 145 runButton.Enabled = interpreter != null && interpreter.CanStep; 146 stepButton.Enabled = interpreter != null && interpreter.CanStep; 147 stepWidthBox.Enabled = interpreter != null && interpreter.CanStep; 148 } 149 150 private void ResetButtonClick(object sender, EventArgs e) { 151 this.ResetDebugging(); 152 } 153 154 private void SelectedExampleIndexChanged(object sender, EventArgs e) { 155 this.ResetDebugging(); 203 156 } 204 157 … … 212 165 } 213 166 214 private void Reset () {167 private void ResetDebugging() { 215 168 if (Content == null || 216 interpreter == null || 217 this.exampleComboBox.SelectedIndex < 0) 169 pool == null || 170 program == null || 171 exampleComboBox.SelectedIndex < 0) 218 172 return; 219 173 220 interpreter.Clear(); 221 222 var example = Content.Data.Examples[this.exampleComboBox.SelectedIndex]; 174 var example = Content.Data.Examples[exampleComboBox.SelectedIndex]; 175 176 if (interpreter != null) { 177 interpreter.Reset(); 178 interpreter2.Reset(); 179 } 223 180 224 181 interpreter.BooleanStack.Push(example.InputBoolean); … … 226 183 interpreter.FloatStack.Push(example.InputFloat); 227 184 185 interpreter2.BooleanStack.Push(example.InputBoolean); 186 interpreter2.IntegerStack.Push(example.InputInt); 187 interpreter2.FloatStack.Push(example.InputFloat); 188 228 189 interpreter.Run(program, true); 190 interpreter2.Run(program, true); 191 229 192 stepWidthBox.Maximum = interpreter.ExecStack.Count; 230 193 … … 237 200 if (Content == null) return; 238 201 239 this.nameTextBox.Text = "Push Solution"; 240 241 var random = Content.Random ?? new FastRandom(); 242 interpreter = new PushInterpreter(Content.Config, random); 243 program = Content.IntegerVector.MapToPushProgram(Content.Config.EnabledExpressions); 202 Name = "Push Solution"; 203 nameTextBox.Text = Name; 204 205 pool = new PushInterpreterPool(Content.Config); 206 program = Content.IntegerVector.ToPushProgram(Content.Config); 207 208 if (interpreter != null) { 209 interpreter.Dispose(); 210 interpreter2.Dispose(); 211 } 212 213 interpreter = pool.Create(Content.Random); 214 interpreter2 = pool.Create(Content.Random); 215 216 if (Content.Simplify) 217 program = Simplifier.Simplifier.Simplify(program, p => PushEvaluator.Evaluate(p, pool, Content.Random, Content.Data, Content.DataStart, Content.DataEnd).TotalQuality); 244 218 245 219 UpdateExamples(Content.Data); 220 221 if (exampleComboBox.SelectedIndex < 0) { 222 exampleComboBox.SelectedIndex = 0; // Triggers ResetDebugging via event 223 } else { 224 ResetDebugging(); 225 } 226 227 InitDebugLists(Content.Config); 246 228 InitResultGrid(); 247 248 if (this.exampleComboBox.SelectedIndex < 0) { 249 this.exampleComboBox.SelectedIndex = 0; // Triggers Reset via event 250 } else { 251 Reset(); 252 } 229 ClearLists(); 230 UpdateExecList(); 231 UpdateValueLists(); 253 232 } 254 233 255 234 private void InitResultGrid() { 235 resultsDataGrid.Columns.Clear(); 236 resultsDataGrid.Rows.Clear(); 237 256 238 var cellTemplate = new DataGridViewTextBoxCell(); 257 239 … … 259 241 var headerTypeName = ViewHelper.GetHeaderTypeName(Content.Data.InputArgumentTypes[i]); 260 242 var column = new DataGridViewColumn { 261 HeaderText = string.Format( "Input {0} : {1}", i + 1, headerTypeName),243 HeaderText = string.Format(InputHeaderStringFormat, i + 1, headerTypeName), 262 244 AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, 263 245 CellTemplate = cellTemplate 264 246 }; 265 247 248 column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; 266 249 resultsDataGrid.Columns.Add(column); 267 250 } … … 271 254 272 255 var estimatedOutputColumn = new DataGridViewColumn { 273 HeaderText = string.Format("Estimated Output {0} : {1}", i + 1, headerTypeName), 256 HeaderText = string.Format(EstimatedOuputHeaderStringFormat, i + 1, headerTypeName), 257 AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, 258 CellTemplate = cellTemplate, 259 }; 260 261 var outputColumn = new DataGridViewColumn { 262 HeaderText = string.Format(OutputHeaderStringFormat, i + 1, headerTypeName), 274 263 AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, 275 264 CellTemplate = cellTemplate 276 265 }; 277 266 278 var outputColumn = new DataGridViewColumn { 279 HeaderText = string.Format("Output {0} : {1}", i + 1, headerTypeName), 280 AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, 281 CellTemplate = cellTemplate 282 }; 267 estimatedOutputColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; 268 outputColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; 283 269 284 270 resultsDataGrid.Columns.Add(estimatedOutputColumn); … … 286 272 } 287 273 288 resultsDataGrid.Columns.Add( 289 new DataGridViewColumn { 290 HeaderText = "Absolute Diff.", 291 AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader, 292 CellTemplate = cellTemplate 293 }); 294 295 resultsDataGrid.Columns.Add( 296 new DataGridViewColumn { 297 HeaderText = "Relative Diff.", 298 AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader, 299 CellTemplate = cellTemplate, 300 }); 301 302 var pool = new PushInterpreterPool(Content.Config); 303 var program = Content.IntegerVector.MapToPushProgram(Content.Config.EnabledExpressions); 274 var absoluteDiffColumn = new DataGridViewColumn { 275 HeaderText = AbsoluteDiffHeaderText, 276 AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader, 277 CellTemplate = cellTemplate 278 }; 279 280 var relativeDiffColumn = new DataGridViewColumn { 281 HeaderText = RelativeDiffHeaderText, 282 AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader, 283 CellTemplate = cellTemplate, 284 }; 285 286 absoluteDiffColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; 287 relativeDiffColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; 288 289 resultsDataGrid.Columns.Add(absoluteDiffColumn); 290 resultsDataGrid.Columns.Add(relativeDiffColumn); 304 291 305 292 using (var pushInterpreter = pool.Create(Content.Random)) { … … 325 312 326 313 this.resultsDataGrid.Rows.Add(row); 327 pushInterpreter. Clear();314 pushInterpreter.Reset(); 328 315 } 329 316 } … … 336 323 337 324 case ExampleArgumentType.Float: 338 case ExampleArgumentType.FloatCollection: return interpreter.FloatStack.IsEmpty ? EmptySign : string.Join(valueSeparator, interpreter.FloatStack.Peek(GetCount(interpreter.FloatStack, example.OutputFloat)) );325 case ExampleArgumentType.FloatCollection: return interpreter.FloatStack.IsEmpty ? EmptySign : string.Join(valueSeparator, interpreter.FloatStack.Peek(GetCount(interpreter.FloatStack, example.OutputFloat)).Select(d => d.ToString(CultureInfo.CurrentUICulture))); 339 326 340 327 case ExampleArgumentType.Bool: return interpreter.BooleanStack.IsEmpty ? EmptySign : interpreter.BooleanStack.Top.ToString(); … … 347 334 } 348 335 349 private int GetCount<T>(I Stack<T> stack, T[] data) {336 private int GetCount<T>(IPushStack<T> stack, T[] data) { 350 337 return Math.Max(0, Math.Min(data.Length, stack.Count)); 351 338 } 352 339 353 340 private void ClearLists() { 354 codeList.Items.Clear(); 355 nameList.Items.Clear(); 356 booleanList.Items.Clear(); 357 integerList.Items.Clear(); 358 floatList.Items.Clear(); 341 foreach (var list in debugControlDict.Values) { 342 list.Items.Clear(); 343 } 359 344 } 360 345 361 346 private void UpdateExecList() { 362 UpdateListCache(0, execList.VirtualListSize); 363 execList.Update(); 364 365 this.execGroupBox.Text = string.Format("Exec [{0}]", this.execList.Items.Count); 366 } 347 execList.Items.Clear(); 348 var expressions = interpreter.ExecStack 349 .Reverse() 350 .Select(e => e.StringRepresentation) 351 .ToArray(); 352 353 execList.Items.AddRange(expressions); 354 execGroupBox.Text = string.Format(GroupBoxTextStringFormat, Enum.GetName(typeof(StackTypes), StackTypes.Exec), interpreter.ExecStack.Count); 355 } 356 357 private void InitDebugLists(IReadOnlyPushConfiguration config) { 358 debugControlDict.Clear(); 359 360 // 2 = ExecList + EmptyColumn which is required to fill empty space 361 while (debugTableLayout.ColumnCount > 2) { 362 debugTableLayout.Controls.RemoveAt(1); 363 debugTableLayout.ColumnCount--; 364 } 365 366 foreach (StackTypes stackType in Enum.GetValues(typeof(StackTypes))) { 367 if (stackType != StackTypes.Exec && 368 ExpressionTable.GetExpressionsByStackTypes(stackType).Intersect(config.EnabledExpressions).Any()) { 369 var list = GetDebugList(stackType); 370 debugControlDict.Add(stackType, list); 371 } 372 } 373 } 374 375 private ListBox GetDebugList(StackTypes type) { 376 var groupBox = new GroupBox { 377 Anchor = AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top, 378 AutoSize = true, 379 AutoSizeMode = AutoSizeMode.GrowAndShrink, 380 Text = Enum.GetName(typeof(StackTypes), type) 381 }; 382 383 var list = new ListBox { 384 Dock = DockStyle.Fill, 385 DrawMode = DrawMode.OwnerDrawFixed 386 }; 387 388 var stackEntryType = type.GetStackEntryType(); 389 if (stackEntryType == typeof(double) || 390 stackEntryType == typeof(long)) { 391 list.DrawItem += (sender, e) => { 392 if (e.Index <= -1) return; 393 var item = list.Items[e.Index]; 394 395 e.DrawBackground(); 396 e.DrawFocusRectangle(); 397 398 var brush = new SolidBrush(e.ForeColor); 399 var size = e.Graphics.MeasureString(item.ToString(), e.Font); 400 401 e.Graphics.DrawString( 402 item.ToString(), 403 e.Font, 404 brush, 405 e.Bounds.Right - size.Width, 406 e.Bounds.Top + (e.Bounds.Height / 2 - size.Height / 2)); 407 }; 408 } 409 410 groupBox.Controls.Add(list); 411 412 var columnWidth = stackEntryType == typeof(Expression) ? 250 : 150; 413 414 debugTableLayout.ColumnCount++; 415 debugTableLayout.ColumnStyles.Insert(1, new ColumnStyle(SizeType.Absolute, columnWidth)); 416 debugTableLayout.Controls.Add(groupBox); 417 debugTableLayout.Controls.SetChildIndex(groupBox, 1); 418 419 return list; 420 } 421 367 422 368 423 private void UpdateValueLists() { … … 372 427 return; 373 428 374 ManageStackType(interpreter.Configuration.IsCodeStackEnabled, codeList, codeGroupBox, interpreter.CodeStack, "Code"); 375 ManageStackType(interpreter.Configuration.IsIntegerStackEnabled, integerList, integerGroupBox, interpreter.IntegerStack, "Integer"); 376 ManageStackType(interpreter.Configuration.IsFloatStackEnabled, floatList, floatGroupBox, interpreter.FloatStack, "Float"); 377 ManageStackType(interpreter.Configuration.IsBooleanStackEnabled, booleanList, booleanGroupBox, interpreter.BooleanStack, "Boolean"); 378 ManageStackType(interpreter.Configuration.IsNameStackEnabled, nameList, nameGroupBox, interpreter.NameStack, "Name"); 379 ManageStackType(interpreter.Configuration.IsStringStackEnabled, stringList, stringGroupBox, interpreter.StringStack, "String"); 380 ManageStackType(interpreter.Configuration.IsCharStackEnabled, charList, charGroupBox, interpreter.CharStack, "Char"); 381 } 382 383 private void ManageStackType<T>(bool enabled, ListBox listbox, GroupBox groupBox, IStack<T> stack, string name) { 384 if (enabled) { 385 listbox.Enabled = true; 386 387 foreach (var item in stack.Reverse()) 388 listbox.Items.Add(item); 389 390 groupBox.Text = string.Format("{0} [{1}]", name, listbox.Items.Count); 391 } else { 392 listbox.Enabled = false; 393 groupBox.Text = string.Format("{0} - DISABLED", name); 429 foreach (var pair in debugControlDict) { 430 var stack = interpreter.GetStackEntriesByType<object>(pair.Key); 431 var name = Enum.GetName(typeof(StackTypes), pair.Key); 432 433 pair.Value.Items.AddRange(stack.Reverse().ToArray()); 434 ((GroupBox)pair.Value.Parent).Text = string.Format(GroupBoxTextStringFormat, name, pair.Value.Items.Count); 394 435 } 395 436 } 396 437 397 438 private void UpdateExamples(Data data) { 439 exampleComboBox.Items.Clear(); 398 440 if (data == null) return; 399 441 … … 403 445 string.Join(Separator, e.OutputArgs)); 404 446 405 exampleComboBox.Items.Clear();406 447 foreach (var str in stringRepresentations) { 407 448 exampleComboBox.Items.Add(str);
Note: See TracChangeset
for help on using the changeset viewer.