# Changeset 14328

Ignore:
Timestamp:
10/08/16 12:04:25 (3 years ago)
Message:

#2665 Set .NET version to 4.5, C# version to 5.0, Added expression templates and factory

Location:
branches/PushGP/HeuristicLab.Algorithms.PushGP
Files:
41 deleted
31 edited

Unmodified
Removed
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.Cli/App.config

 r14320 ﻿
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.Cli/HeuristicLab.Algorithms.PushGP.Cli.csproj

 r14320 HeuristicLab.Algorithms.PushGP.CliHeuristicLab.Algorithms.PushGP.Cliv4.5.2v4.5512true prompt 4 5

• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Code/CodeDefineExpression.cs

 r14320 ﻿using HeuristicLab.Algorithms.PushGP.Stack; ﻿using HeuristicLab.Algorithms.PushGP.Expressions.Exec; using HeuristicLab.Algorithms.PushGP.Interpreter; namespace HeuristicLab.Algorithms.PushGP.Expressions namespace HeuristicLab.Algorithms.PushGP.Expressions.Code { public class CodeDefineExpression : Expression { public CodeDefineExpression() : base(OpCode.CodeDefine) { } public override bool IsCodeOp { get { return true; } } public override void Eval(IInterpreterService interpreterService) public override void Eval(IInterpreter interpreter) { Define( interpreterService.CodeStack, interpreterService.NameStack, interpreterService.CustomExpressions, value => new ExecPushExpression(value)); // not enough arguments on stack if (interpreter.NameStack.Count == 0 || interpreter.CodeStack.Count == 0) return; // as the interpreter does not pop code expressions interpreterService.CodeStack.Pop(); var name = interpreter.NameStack.Pop(); var expression = new ExecPushExpression(interpreter.CodeStack.Top); if (interpreter.CustomExpressions.ContainsKey(name)) { interpreter.CustomExpressions[name] = expression; } else { interpreter.CustomExpressions.Add(name, expression); } interpreter.CodeStack.Pop(); } public override string ToString() { return Symbols.CodeDefine; } }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Code/CodeDoExpression.cs

 r14320 ﻿using HeuristicLab.Algorithms.PushGP.Stack; ﻿using HeuristicLab.Algorithms.PushGP.Interpreter; namespace HeuristicLab.Algorithms.PushGP.Expressions namespace HeuristicLab.Algorithms.PushGP.Expressions.Code { public class CodeDoExpression : Expression { public CodeDoExpression() : base(OpCode.CodeDo) { } public override bool IsCodeOp { get { return true; } } public override void Eval(IInterpreterService interpreterService) public override void Eval(IInterpreter interpreter) { // not enough arguments on stack if (interpreterService.CodeStack.Count == 0) if (interpreter.CodeStack.Count == 0) return; var expression = interpreterService.CodeStack.Pop(); interpreterService.ExecStack.Push(expression); var expression = interpreter.CodeStack.Pop(); interpreter.ExecStack.Push(expression); } public override string ToString() { return Symbols.CodeDo; } }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Code/CodeIfExpression.cs

 r14320 ﻿using HeuristicLab.Algorithms.PushGP.Stack; ﻿using HeuristicLab.Algorithms.PushGP.Interpreter; namespace HeuristicLab.Algorithms.PushGP.Expressions namespace HeuristicLab.Algorithms.PushGP.Expressions.Code { public class CodeIfExpression : Expression { public CodeIfExpression() : base(OpCode.CodeIf) { } public override bool IsCodeOp { get { return true; } } public override void Eval(IInterpreterService interpreterService) public override void Eval(IInterpreter interpreter) { // not enough arguments on stack if (interpreterService.BooleanStack.Count == 0 || interpreterService.CodeStack.Count < 2) if (interpreter.BooleanStack.Count == 0 || interpreter.CodeStack.Count < 2) return; var condition = interpreterService.BooleanStack.Pop(); var expressionFalse = interpreterService.CodeStack.Pop(); var expressionTrue = interpreterService.CodeStack.Pop(); var condition = interpreter.BooleanStack.Pop(); var expressionFalse = interpreter.CodeStack.Pop(); var expressionTrue = interpreter.CodeStack.Pop(); interpreterService.ExecStack.Push(condition interpreter.ExecStack.Push(condition ? expressionTrue : expressionFalse); } public override string ToString() { return Symbols.CodeIf; } } }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Code/CodeNoopExpression.cs

 r14320 ﻿using HeuristicLab.Algorithms.PushGP.Stack; ﻿using HeuristicLab.Algorithms.PushGP.Interpreter; namespace HeuristicLab.Algorithms.PushGP.Expressions namespace HeuristicLab.Algorithms.PushGP.Expressions.Code { public class CodeNoopExpression : Expression { public CodeNoopExpression() : base(OpCode.CodeNoop) public override bool IsCodeOp { get { return true; } } public override void Eval(IInterpreter interpreter) { } public override void Eval(IInterpreterService interpreterService) { // nothing to do // do nothing } }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Code/CodeQuoteExpression.cs

 r14320 ﻿using HeuristicLab.Algorithms.PushGP.Stack; ﻿using HeuristicLab.Algorithms.PushGP.Interpreter; namespace HeuristicLab.Algorithms.PushGP.Expressions namespace HeuristicLab.Algorithms.PushGP.Expressions.Code { public class CodeQuoteExpression : Expression { public CodeQuoteExpression() : base(OpCode.CodeQuote) { } public override bool IsCodeOp { get { return true; } } public override void Eval(IInterpreterService interpreterService) public override void Eval(IInterpreter interpreter) { // not enough arguments on stack if (interpreterService.ExecStack.Count == 0) if (interpreter.ExecStack.Count == 0) return; var expression = interpreterService.ExecStack.Pop(); interpreterService.CodeStack.Push(expression); var expression = interpreter.ExecStack.Pop(); interpreter.CodeStack.Push(expression); } public override string ToString() { return Symbols.CodeQuote; } }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Exec/ExecDefineExpression.cs

 r14320 ﻿using HeuristicLab.Algorithms.PushGP.Stack; ﻿using HeuristicLab.Algorithms.PushGP.Expressions.Exec; using HeuristicLab.Algorithms.PushGP.Interpreter; namespace HeuristicLab.Algorithms.PushGP.Expressions namespace HeuristicLab.Algorithms.PushGP.Expressions.Code { public class ExecDefineExpression : Expression { public ExecDefineExpression() : base(OpCode.ExecDefine) { } public override bool IsCodeOp { get { return false; } } public override void Eval(IInterpreterService interpreterService) public override void Eval(IInterpreter interpreter) { Define( interpreterService.ExecStack, interpreterService.NameStack, interpreterService.CustomExpressions, value => new ExecPushExpression(value)); // not enough arguments on stack if (interpreter.NameStack.Count == 0 || interpreter.CodeStack.Count == 0) return; // as the interpreter does not pop code expressions interpreterService.ExecStack.Pop(); var name = interpreter.NameStack.Pop(); var expression = new ExecPushExpression(interpreter.ExecStack.Top); if (interpreter.CustomExpressions.ContainsKey(name)) { interpreter.CustomExpressions[name] = expression; } else { interpreter.CustomExpressions.Add(name, expression); } interpreter.ExecStack.Pop(); } public override string ToString() { return Symbols.CodeDefine; } }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Exec/ExecDoRangeExpression.cs

 r14320 ﻿using HeuristicLab.Algorithms.PushGP.Stack; ﻿using HeuristicLab.Algorithms.PushGP.Interpreter; namespace HeuristicLab.Algorithms.PushGP.Expressions namespace HeuristicLab.Algorithms.PushGP.Expressions.Exec { public class ExecDoRangeExpression : Expression { public ExecDoRangeExpression() : base(OpCode.ExecDoXRange) { } public override bool IsCodeOp { get { return false; } } public override void Eval(IInterpreterService interpreterService) public override void Eval(IInterpreter interpreter) { // not enough arguments on stack if (interpreterService.IntegerStack.Count < 2 || interpreterService.ExecStack.Count == 0) if (interpreter.IntegerStack.Count < 2 || interpreter.ExecStack.Count == 0) return; var destinationIndex = interpreterService.IntegerStack.Pop(); var currentIndex = interpreterService.IntegerStack.Pop(); var loopBody = interpreterService.ExecStack.Pop(); var destinationIndex = interpreter.IntegerStack.Pop(); var currentIndex = interpreter.IntegerStack.Pop(); var loopBody = interpreter.ExecStack.Pop(); if (destinationIndex == currentIndex) { interpreterService.IntegerStack.Push(currentIndex); interpreterService.ExecStack.Push(loopBody); interpreter.IntegerStack.Push(currentIndex); interpreter.ExecStack.Push(loopBody); } else : currentIndex + 1; interpreterService.IntegerStack.Push(currentIndex); interpreterService.IntegerStack.Push(nextIndex); interpreterService.IntegerStack.Push(destinationIndex); interpreter.IntegerStack.Push(currentIndex); interpreter.IntegerStack.Push(nextIndex); interpreter.IntegerStack.Push(destinationIndex); var expression = new ExecDoRangeExpression(); interpreterService.ExecStack.Push(loopBody); interpreterService.ExecStack.Push(loopBody); interpreterService.ExecStack.Push(expression); interpreter.ExecStack.Push(loopBody); interpreter.ExecStack.Push(loopBody); interpreter.ExecStack.Push(expression); } } public override string ToString() { return Symbols.ExecDoXRange; } }

• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Exec/ExecYExpression.cs

 r14323 ﻿using HeuristicLab.Algorithms.PushGP.Stack; ﻿using HeuristicLab.Algorithms.PushGP.Interpreter; namespace HeuristicLab.Algorithms.PushGP.Expressions namespace HeuristicLab.Algorithms.PushGP.Expressions.Exec { public class ExecYExpression : Expression { public ExecYExpression() : base(OpCode.ExecY) { } public override bool IsCodeOp { get { return false; } } public override void Eval(IInterpreterService interpreterService) public override void Eval(IInterpreter interpreter) { // not enough arguments on stack if (interpreterService.ExecStack.Count == 0) if (interpreter.ExecStack.Count == 0) return; var expandExpression = new ExecExpandExpression(new[] { interpreterService.ExecStack.Top, interpreter.ExecStack.Top, new ExecYExpression() }); interpreterService.ExecStack.Insert(interpreterService.ExecStack.Count - 1, expandExpression); interpreter.ExecStack.Insert(interpreter.ExecStack.Count - 1, expandExpression); } public override string ToString() { return Symbols.ExecY; } }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Expression.cs

 r14323 ﻿using System; using System.Collections.Generic; using HeuristicLab.Algorithms.PushGP.Interpreter; using HeuristicLab.Algorithms.PushGP.Stack; public abstract class Expression { public Expression(OpCode opCode) { this.OpCode = opCode; } public abstract bool IsCodeOp { get; } public abstract void Eval(IInterpreter interpreter); public OpCode OpCode { get; } public abstract void Eval(IInterpreterService interpreterService); public override string ToString() { return SymbolTable.GetSymbol(this.OpCode); } protected static void PushResult(IStack stack, int count, Func templateFunc) public void PushResult(IStack stack, int count, Func templateFunc) { PushResult(stack, stack, count, templateFunc); } protected static void PushResult(IStack sourceStack, IStack targetStack, int count, Func templateFunc) public void PushResult(IStack sourceStack, IStack targetStack, int count, Func templateFunc) { // not enough arguments on stack } protected static void Duplicate(IStack stack) public void Duplicate(IStack stack) { // not enough arguments on stack

• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Name/NameDefineXExecExpression.cs

 r14320 ﻿using HeuristicLab.Algorithms.PushGP.Stack; ﻿using HeuristicLab.Algorithms.PushGP.Interpreter; namespace HeuristicLab.Algorithms.PushGP.Expressions namespace HeuristicLab.Algorithms.PushGP.Expressions.Name { public class NameDefineXExecExpression : Expression { public NameDefineXExecExpression(string value) : base(OpCode.NameDefineXExec) private readonly string name; public NameDefineXExecExpression(string name) { this.Value = value; this.name = name; } public string Value { get; } public override bool IsCodeOp { get { return false; } } public override void Eval(IInterpreterService interpreterService) public override void Eval(IInterpreter interpreter) { Expression expression; if (interpreterService.CustomExpressions.TryGetValue(this.Value, out expression)) if (interpreter.CustomExpressions.TryGetValue(this.name, out expression)) { interpreterService.ExecStack.Push(expression); interpreter.ExecStack.Push(expression); } else { interpreterService.NameStack.Push(this.Value); interpreter.NameStack.Push(this.name); } } public override string ToString() { return this.Value; return this.name; } }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Generators/CodeGenerator.cs

 r14323 ﻿using System; using System.Collections.Generic; ﻿using System.Collections.Generic; using System.Linq; using HeuristicLab.Algorithms.PushGP.Expressions; using HeuristicLab.Random; namespace HeuristicLab.Algorithms.PushGP.Generators public static class CodeGenerator { private static FastRandom random = new FastRandom(); public static IEnumerable RandomCode(int maxPoints) { var actualPoints = StaticRandom.Next(1, maxPoints); var actualPoints = random.Next(1, maxPoints); return RandomCodeWithSize(actualPoints).ToArray(); if (points == 1) { OpCode opCode; Func creator; // TODO: If this is an "ephemeral random constant"???? then return a randomly - chosen value of the appropriate type; var opCode = (OpCode)random.Next(OpCodeExtensions.Min, OpCodeExtensions.Max); do { // TODO: If this is an "ephemeral random constant"???? then return a randomly - chosen value of the appropriate type; opCode = (OpCode)StaticRandom.Next(OpCodeExtensions.Min, OpCodeExtensions.Max); } while (!ExpressionCreatorTable.TryGetCreator(opCode, out creator)); return new[] { creator.Invoke() }; return new[] { ExpressionFactory.Create(opCode) }; } else var sizesThisLevel = Decompose(points - 1, points - 1); return sizesThisLevel.SelectMany(size => RandomCodeWithSize(size)); return sizesThisLevel.SelectMany(size => RandomCodeWithSize(size)).Shuffle(random); } } else { var thisPart = StaticRandom.Next(1, number - 1); var thisPart = random.Next(1, number - 1); return new[] { thisPart }.Concat(Decompose(number - thisPart, maxParts - 1));
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Generators/Configuration.cs

 r14323 public class Configuration { public Configuration() { this.MinRandomInteger = long.MinValue; this.MaxRandomInteger = long.MaxValue; this.MinRandomFloat = double.MaxValue; this.MaxRandomFloat = double.MaxValue; this.NewErcNameProbability = 0.5; } /// /// The minimum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND. /// public long MinRandomInteger { get; set; } = long.MinValue; public long MinRandomInteger { get; set; } /// /// The maximum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND. /// public long MaxRandomInteger { get; set; } = long.MaxValue; public long MaxRandomInteger { get; set; } /// /// The minimum FLOAT that will be produced as an ephemeral random FLOAT constant or from a call to FLOAT.RAND. /// public double MinRandomFloag { get; set; } = double.MinValue; public double MinRandomFloat { get; set; } /// /// The maximum FLOAT that will be produced as an ephemeral random FLOAT constant or from a call to FLOAT.RAND. /// public double MaxRandomFloag { get; set; } = double.MaxValue; public double MaxRandomFloat { get; set; } /// /// (rather than a name that was previously generated). /// public double NewErcNameProbability { get; set; } = 0.5; public double NewErcNameProbability { get; set; } } }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.csproj

 r14323 HeuristicLab.Algorithms.PushGPHeuristicLab.Algorithms.PushGPv4.5.2v4.5512 prompt 4 5 ..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll ..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll ..\..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Interpreter/Configuration.cs

 r14323 namespace HeuristicLab.Algorithms.PushGP.Interpreter { public class Configuration public class Configuration : Generators.Configuration { public bool IsBooleanStackEnabled { get; set; } = true; public bool IsIntegerStackEnabled { get; set; } = true; public bool IsFloatStackEnabled { get; set; } = true; public bool IsCodeStackEnabled { get; set; } = true; public bool IsNameStackEnabled { get; set; } = true; public Configuration() { this.IsBooleanStackEnabled = true; this.IsIntegerStackEnabled = true; this.IsFloatStackEnabled = true; this.IsCodeStackEnabled = true; this.IsNameStackEnabled = true; public IList AllowedInstructions { get; set; } this.EvalPushLimit = uint.MaxValue; this.MaxPointsInProgram = uint.MaxValue; this.MaxPointsInRandomExpression = uint.MaxValue; this.TopLevelPushCode = true; this.TopLevelPopCode = true; this.RandomSeedMax = 30081; this.RandomSeedMin = 0; this.RandomSeed = null; } public bool IsBooleanStackEnabled { get; set; } public bool IsIntegerStackEnabled { get; set; } public bool IsFloatStackEnabled { get; set; } public bool IsCodeStackEnabled { get; set; } public bool IsNameStackEnabled { get; set; } public IList AllowedInclassions { get; set; } public IList PredefinedExpressions { get; set; } /// /// The minimum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND. /// public long MinRandomInteger { get; set; } = long.MinValue; /// /// The maximum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND. /// public long MaxRandomInteger { get; set; } = long.MaxValue; /// /// The minimum FLOAT that will be produced as an ephemeral random FLOAT constant or from a call to FLOAT.RAND. /// public double MinRandomFloag { get; set; } = double.MinValue; /// /// The maximum FLOAT that will be produced as an ephemeral random FLOAT constant or from a call to FLOAT.RAND. /// public double MaxRandomFloag { get; set; } = double.MaxValue; /// /// 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, /// The execution of a single Push inclassion 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). /// When this limit is exceeded the interpreter aborts immediately, leaving its stacks in the states they were in prior /// is up to the calling program. /// public uint EvalPushLimit { get; set; } = uint.MaxValue; public uint EvalPushLimit { get; set; } /// /// 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. Any instruction that would cause this limit to be exceeded /// should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the instruction. /// A point is an inclassion, a literal, or a pair of parentheses. Any inclassion that would cause this limit to be exceeded /// should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the inclassion. /// public uint MaxPointsInProgram { get; set; } = uint.MaxValue; public uint MaxPointsInProgram { get; set; } /// /// The maximum number of points in an expression produced by the CODE.RAND instruction. /// The maximum number of points in an expression produced by the CODE.RAND inclassion. /// public uint MaxPointsInRandomExpression { get; set; } = uint.MaxValue; public uint MaxPointsInRandomExpression { get; set; } /// /// will be pushed onto the CODE stack prior to execution. /// public bool TopLevelPushCode { get; set; } = true; public bool TopLevelPushCode { get; set; } /// /// When TRUE, the CODE stack will be popped at the end of top level calls to the interpreter. The default is FALSE. /// public bool TopLevelPopCode { get; set; } = true; public bool TopLevelPopCode { get; set; } /// /// The probability that the selection of the ephemeral /// random NAME constant for inclusion in randomly generated code will produce a new name /// (rather than a name that was previously generated). /// public double NewErcNameProbability { get; set; } = 0.5; public ushort RandomSeedMax { get; set; } public ushort RandomSeedMin { get; set; } public ushort RandomSeedMax { get; set; } = 30081; public ushort RandomSeedMin { get; set; } = 0; public ushort? RandomSeed { get; set; } = null; public ushort? RandomSeed { get; set; } } }

• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/OpCode.cs

 r14320 /// /// BOOLEAN.DEFINE: /// Defines the name on top of the NAME stack as an instruction that will push the top item of the BOOLEAN stack onto the EXEC stack. /// Defines the name on top of the NAME stack as an inclassion that will push the top item of the BOOLEAN stack onto the EXEC stack. /// BooleanDefine, /// /// BOOLEAN.DUP: /// Duplicates the top item on the BOOLEAN stack. Does not pop its argument (which, if it did, would negate the effect of the duplication!) /// BooleanDup, /// Duplicatelicates the top item on the BOOLEAN stack. Does not pop its argument (which, if it did, would negate the effect of the duplication!) /// BooleanDuplicate, /// /// Pushes a copy of an indexed item "deep" in the stack onto the top of the stack, without removing the deep item. The index is taken from the INTEGER stack. /// BooleanYankDup, BooleanYankDuplicate, #endregion Boolean /// /// CODE.APPEND: /// Pushes the result of appending the top two pieces of code. If one of the pieces of code is a single instruction or literal (that is, something not surrounded by parentheses) then it is surrounded by parentheses first. /// Pushes the result of appending the top two pieces of code. If one of the pieces of code is a single inclassion or literal (that is, something not surrounded by parentheses) then it is surrounded by parentheses first. /// CodeAppend, /// /// CODE.ATOM: /// Pushes TRUE onto the BOOLEAN stack if the top piece of code is a single instruction or a literal, and FALSE otherwise (that is, if it is something surrounded by parentheses). /// Pushes TRUE onto the BOOLEAN stack if the top piece of code is a single inclassion or a literal, and FALSE otherwise (that is, if it is something surrounded by parentheses). /// CodeAtom, /// /// CODE.DEFINE: /// Defines the name on top of the NAME stack as an instruction that will push the top item of the CODE stack onto the EXEC stack. /// Defines the name on top of the NAME stack as an inclassion that will push the top item of the CODE stack onto the EXEC stack. /// CodeDefine, /// /// CODE.DEFINITION: /// Pushes the definition associated with the top NAME on the NAME stack (if any) onto the CODE stack. This extracts the definition for inspection/manipulation, rather than for immediate execution (although it may then be executed with a call to CODE.DO or a similar instruction). /// Pushes the definition associated with the top NAME on the NAME stack (if any) onto the CODE stack. This extracts the definition for inspection/manipulation, rather than for immediate execution (although it may then be executed with a call to CODE.DO or a similar inclassion). /// CodeDefinition, /// CODE.DESCREPANCY: /// Pushes a measure of the discrepancy between the top two CODE stack items onto the INTEGER stack. This will be zero if the top two items are equivalent, and will be higher the 'more different' the items are from one another. The calculation is as follows: /// 1. Construct a list of all of the unique items in both of the lists (where uniqueness is determined by equalp). Sub-lists and atoms all count as items. /// 1. Conclass a list of all of the unique items in both of the lists (where uniqueness is determined by equalp). Sub-lists and atoms all count as items. /// 2. Initialize the result to zero. /// 3. For each unique item increment the result by the difference between the number of occurrences of the item in the two pieces of code. /// /// CODE.DO*COUNT: /// An iteration instruction that performs a loop (the body of which is taken from the CODE stack) the number of times indicated by the INTEGER argument, pushing an index (which runs from zero to one less than the number of iterations) onto the INTEGER stack prior to each execution of the loop body. This should be implemented as a macro that expands into a call to CODE.DO*RANGE. CODE.DO*COUNT takes a single INTEGER argument (the number of times that the loop will be executed) and a single CODE argument (the body of the loop). If the provided INTEGER argument is negative or zero then this becomes a NOOP. Otherwise it expands into: /// An iteration inclassion that performs a loop (the body of which is taken from the CODE stack) the number of times indicated by the INTEGER argument, pushing an index (which runs from zero to one less than the number of iterations) onto the INTEGER stack prior to each execution of the loop body. This should be implemented as a macro that expands into a call to CODE.DO*RANGE. CODE.DO*COUNT takes a single INTEGER argument (the number of times that the loop will be executed) and a single CODE argument (the body of the loop). If the provided INTEGER argument is negative or zero then this becomes a NOOP. Otherwise it expands into: /// ( 0 '1 - IntegerArg' CODE.QUOTE CODE.DO*RANGE ) /// /// /// CODE.DO*RANGE: /// An iteration instruction that executes the top item on the CODE stack a number of times that depends on the top two integers, while also pushing the loop counter onto the INTEGER stack for possible access during the execution of the body of the loop. The top integer is the "destination index" and the second integer is the "current index." First the code and the integer arguments are saved locally and popped. Then the integers are compared. If the integers are equal then the current index is pushed onto the INTEGER stack and the code (which is the "body" of the loop) is pushed onto the EXEC stack for subsequent execution. If the integers are not equal then the current index will still be pushed onto the INTEGER stack but two items will be pushed onto the EXEC stack -- first a recursive call to CODE.DO*RANGE (with the same code and destination index, but with a current index that has been either incremented or decremented by 1 to be closer to the destination index) and then the body code. Note that the range is inclusive of both endpoints; a call with integer arguments 3 and 5 will cause its body to be executed 3 times, with the loop counter having the values 3, 4, and 5. Note also that one can specify a loop that "counts down" by providing a destination index that is less than the specified current index. /// An iteration inclassion that executes the top item on the CODE stack a number of times that depends on the top two integers, while also pushing the loop counter onto the INTEGER stack for possible access during the execution of the body of the loop. The top integer is the "destination index" and the second integer is the "current index." First the code and the integer arguments are saved locally and popped. Then the integers are compared. If the integers are equal then the current index is pushed onto the INTEGER stack and the code (which is the "body" of the loop) is pushed onto the EXEC stack for subsequent execution. If the integers are not equal then the current index will still be pushed onto the INTEGER stack but two items will be pushed onto the EXEC stack -- first a recursive call to CODE.DO*RANGE (with the same code and destination index, but with a current index that has been either incremented or decremented by 1 to be closer to the destination index) and then the body code. Note that the range is inclusive of both endpoints; a call with integer arguments 3 and 5 will cause its body to be executed 3 times, with the loop counter having the values 3, 4, and 5. Note also that one can specify a loop that "counts down" by providing a destination index that is less than the specified current index. /// CodeDoXRange, /// /// CODE.DUP: /// Duplicates the top item on the CODE stack. Does not pop its argument (which, if it did, would negate the effect of the duplication!). /// CodeDup, /// Duplicatelicates the top item on the CODE stack. Does not pop its argument (which, if it did, would negate the effect of the duplication!). /// CodeDuplicate, /// /// CODE.EXTRACT: /// Pushes the sub-expression of the top item of the CODE stack that is indexed by the top item of the INTEGER stack. The indexing here counts "points," where each parenthesized expression and each literal/instruction is considered a point, and it proceeds in depth first order. The entire piece of code is at index 0; if it is a list then the first item in the list is at index 1, etc. The integer used as the index is taken modulo the number of points in the overall expression (and its absolute value is taken in case it is negative) to ensure that it is within the meaningful range. /// Pushes the sub-expression of the top item of the CODE stack that is indexed by the top item of the INTEGER stack. The indexing here counts "points," where each parenthesized expression and each literal/inclassion is considered a point, and it proceeds in depth first order. The entire piece of code is at index 0; if it is a list then the first item in the list is at index 1, etc. The integer used as the index is taken modulo the number of points in the overall expression (and its absolute value is taken in case it is negative) to ensure that it is within the meaningful range. /// CodeExtract, /// /// CODE.INSTRUCTIONS: /// Pushes a list of all active instructions in the interpreter's current configuration. /// CodeInstructions, /// /// CODE.INSERT: /// Pushes the result of inserting the second item of the CODE stack into the first item, at the position indexed by the top item of the INTEGER stack (and replacing whatever was there formerly). The indexing is computed as in CODE.EXTRACT. /// /// CODE.INSTRUCTIONS: /// Pushes a list of all active instructions in the interpreter's current configuration. /// CodeInstructions, /// Pushes a list of all active inclassions in the interpreter's current configuration. /// CodeInclassions, /// /// /// CODE.NULL: Pushes TRUE onto the BOOLEAN stack if the top item of the CODE stack is an empty list, or FALSE otherwise. /// CodeNull, /// /// CODE.POSITION: /// Pushes onto the INTEGER stack the position of the second item on the CODE stack within the first item (which is coerced to a list if necessary). Pushes -1 if no match is found. /// CodePosition, /// /// CODE.QUOTE: /// Specifies that the next expression submitted for execution will instead be pushed literally onto the CODE stack. This can be implemented by moving the top item on the EXEC stack onto the CODE stack. /// /// CODE.SIZE: Pushes the number of "points" in the top piece of CODE onto the INTEGER stack. Each instruction, literal, and pair of parentheses counts as a point. /// CODE.SIZE: Pushes the number of "points" in the top piece of CODE onto the INTEGER stack. Each inclassion, literal, and pair of parentheses counts as a point. /// CodeSize, /// Pushes a copy of an indexed item "deep" in the stack onto the top of the stack, without removing the deep item. The index is taken from the INTEGER stack. /// CodeYankDup, CodeYankDuplicate, #endregion Code /// /// EXEC.DEFINE: /// Defines the name on top of the NAME stack as an instruction that will push the top item of the EXEC stack back onto the EXEC stack. /// Defines the name on top of the NAME stack as an inclassion that will push the top item of the EXEC stack back onto the EXEC stack. /// ExecDefine, /// /// EXEC.DO*COUNT: /// An iteration instruction that performs a loop (the body of which is taken from the EXEC stack) the number of times indicated by the INTEGER argument, pushing an index (which runs from zero to one less than the number of iterations) onto the INTEGER stack prior to each execution of the loop body. This is similar to CODE.DO*COUNT except that it takes its code argument from the EXEC stack. This should be implemented as a macro that expands into a call to EXEC.DO*RANGE. EXEC.DO*COUNT takes a single INTEGER argument (the number of times that the loop will be executed) and a single EXEC argument (the body of the loop). If the provided INTEGER argument is negative or zero then this becomes a NOOP. Otherwise it expands into: /// An iteration inclassion that performs a loop (the body of which is taken from the EXEC stack) the number of times indicated by the INTEGER argument, pushing an index (which runs from zero to one less than the number of iterations) onto the INTEGER stack prior to each execution of the loop body. This is similar to CODE.DO*COUNT except that it takes its code argument from the EXEC stack. This should be implemented as a macro that expands into a call to EXEC.DO*RANGE. EXEC.DO*COUNT takes a single INTEGER argument (the number of times that the loop will be executed) and a single EXEC argument (the body of the loop). If the provided INTEGER argument is negative or zero then this becomes a NOOP. Otherwise it expands into: /// ( 0 <1 - IntegerArg> EXEC.DO*RANGE ) /// /// /// EXEC.DO*RANGE: /// An iteration instruction that executes the top item on the EXEC stack a number of times that depends on the top two integers, while also pushing the loop counter onto the INTEGER stack for possible access during the execution of the body of the loop. This is similar to CODE.DO*COUNT except that it takes its code argument from the EXEC stack. The top integer is the "destination index" and the second integer is the "current index." First the code and the integer arguments are saved locally and popped. Then the integers are compared. If the integers are equal then the current index is pushed onto the INTEGER stack and the code (which is the "body" of the loop) is pushed onto the EXEC stack for subsequent execution. If the integers are not equal then the current index will still be pushed onto the INTEGER stack but two items will be pushed onto the EXEC stack -- first a recursive call to EXEC.DO*RANGE (with the same code and destination index, but with a current index that has been either incremented or decremented by 1 to be closer to the destination index) and then the body code. Note that the range is inclusive of both endpoints; a call with integer arguments 3 and 5 will cause its body to be executed 3 times, with the loop counter having the values 3, 4, and 5. Note also that one can specify a loop that "counts down" by providing a destination index that is less than the specified current index. /// An iteration inclassion that executes the top item on the EXEC stack a number of times that depends on the top two integers, while also pushing the loop counter onto the INTEGER stack for possible access during the execution of the body of the loop. This is similar to CODE.DO*COUNT except that it takes its code argument from the EXEC stack. The top integer is the "destination index" and the second integer is the "current index." First the code and the integer arguments are saved locally and popped. Then the integers are compared. If the integers are equal then the current index is pushed onto the INTEGER stack and the code (which is the "body" of the loop) is pushed onto the EXEC stack for subsequent execution. If the integers are not equal then the current index will still be pushed onto the INTEGER stack but two items will be pushed onto the EXEC stack -- first a recursive call to EXEC.DO*RANGE (with the same code and destination index, but with a current index that has been either incremented or decremented by 1 to be closer to the destination index) and then the body code. Note that the range is inclusive of both endpoints; a call with integer arguments 3 and 5 will cause its body to be executed 3 times, with the loop counter having the values 3, 4, and 5. Note also that one can specify a loop that "counts down" by providing a destination index that is less than the specified current index. /// ExecDoXRange, /// /// EXEC.DUP: /// Duplicates the top item on the EXEC stack. Does not pop its argument (which, if it did, would negate the effect of the duplication!). This may be thought of as a "DO TWICE" instruction. /// ExecDup, /// Duplicatelicates the top item on the EXEC stack. Does not pop its argument (which, if it did, would negate the effect of the duplication!). This may be thought of as a "DO TWICE" inclassion. /// ExecDuplicate, /// /// EXEC.FLUSH: /// Empties the EXEC stack. This may be thought of as a "HALT" instruction. /// Empties the EXEC stack. This may be thought of as a "HALT" inclassion. /// ExecFlush, /// /// EXEC.POP: Pops the EXEC stack. This may be thought of as a "DONT" instruction. /// EXEC.POP: Pops the EXEC stack. This may be thought of as a "DONT" inclassion. /// ExecPop, /// /// EXEC.S: /// The Push implementation of the "S combinator". Pops 3 items from the EXEC stack, which we will call A, B, and C (with A being the first one popped). Then pushes a list containing B and C back onto the EXEC stack, followed by another instance of C, followed by another instance of A. /// ExecS, /// /// EXEC.SHOVE: /// Inserts the top EXEC item "deep" in the stack, at the position indexed by the top INTEGER. This may be thought of as a "DO LATER" instruction. /// Inserts the top EXEC item "deep" in the stack, at the position indexed by the top INTEGER. This may be thought of as a "DO LATER" inclassion. /// ExecShove, /// /// EXEC.YANK: /// Removes an indexed item from "deep" in the stack and pushes it on top of the stack. The index is taken from the INTEGER stack. This may be thought of as a "DO SOONER" instruction. /// Removes an indexed item from "deep" in the stack and pushes it on top of the stack. The index is taken from the INTEGER stack. This may be thought of as a "DO SOONER" inclassion. /// ExecYank, /// Pushes a copy of an indexed item "deep" in the stack onto the top of the stack, without removing the deep item. The index is taken from the INTEGER stack. /// ExecYankDup, ExecYankDuplicate, #endregion Exec /// /// FLOAT.DEFINE: /// Defines the name on top of the NAME stack as an instruction that will push the top item of the FLOAT stack onto the EXEC stack. /// Defines the name on top of the NAME stack as an inclassion that will push the top item of the FLOAT stack onto the EXEC stack. /// FloatDefine, /// /// FLOAT.DUP: /// Duplicates the top item on the FLOAT stack. Does not pop its argument (which, if it did, would negate the effect of the duplication!). /// FloatDup, /// Duplicatelicates the top item on the FLOAT stack. Does not pop its argument (which, if it did, would negate the effect of the duplication!). /// FloatDuplicate, /// /// Pushes a copy of an indexed item "deep" in the stack onto the top of the stack, without removing the deep item. The index is taken from the INTEGER stack. /// FloatYankDup, FloatYankDuplicate, #endregion Float /// /// INTEGER.COS: /// Pushes the cosine of the top item. /// IntegerCos, /// /// INTEGER.DEFINE: /// Defines the name on top of the NAME stack as an instruction that will push the top item of the INTEGER stack onto the EXEC stack. /// Defines the name on top of the NAME stack as an inclassion that will push the top item of the INTEGER stack onto the EXEC stack. /// IntegerDefine, /// /// INTEGER.DUP: /// Duplicates the top item on the INTEGER stack. Does not pop its argument (which, if it did, would negate the effect of the duplication!). /// IntegerDup, /// Duplicatelicates the top item on the INTEGER stack. Does not pop its argument (which, if it did, would negate the effect of the duplication!). /// IntegerDuplicate, /// /// /// INTEGER.SIN: /// Pushes the sine of the top item. /// IntegerSin, /// /// INTEGER.STACKDEPTH: /// Pushes the stack depth onto the INTEGER stack. /// /// INTEGER.TAN: /// Pushes the tangent of the top item. /// IntegerTan, /// /// INTEGER.YANK: /// Removes an indexed item from "deep" in the stack and pushes it on top of the stack. The index is taken from the INTEGER stack. /// Pushes a copy of an indexed item "deep" in the stack onto the top of the stack, without removing the deep item. The index is taken from the INTEGER stack. /// IntegerYankDup, IntegerYankDuplicate, #endregion Integer /// /// NAME.DUP: /// Duplicates the top item on the NAME stack. Does not pop its argument (which, if it did, would negate the effect of the duplication!). /// NameDup, /// Duplicatelicates the top item on the NAME stack. Does not pop its argument (which, if it did, would negate the effect of the duplication!). /// NameDuplicate, /// /// Pushes a copy of an indexed item "deep" in the stack onto the top of the stack, without removing the deep item. The index is taken from the INTEGER stack. /// NameYankDup, NameYankDuplicate, #endregion Name }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/OpCodeExtensions.cs

 r14323 public static class OpCodeExtensions { public readonly static byte Min = 0; public const byte Min = 0; public readonly static byte Max = Enum.GetValues(typeof(OpCode)).Cast().Last(); public static bool IsCodeOp(this OpCode opCode) { return opCode >= OpCode.CodeEquals && opCode < OpCode.CodeYankDup; } } }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Parser/Parser.cs

 r14323 using System.Globalization; using HeuristicLab.Algorithms.PushGP.Expressions; using HeuristicLab.Algorithms.PushGP.Expressions.Boolean; using HeuristicLab.Algorithms.PushGP.Expressions.Code; using HeuristicLab.Algorithms.PushGP.Expressions.Exec; using HeuristicLab.Algorithms.PushGP.Expressions.Float; using HeuristicLab.Algorithms.PushGP.Expressions.Integer; using HeuristicLab.Algorithms.PushGP.Expressions.Name; namespace HeuristicLab.Algorithms.PushGP { public class Parser public static class Parser { private readonly CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture("en-US"); private static readonly CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture("en-US"); private const string OpenBrace = "("; private const string CloseBrace = ")"; private readonly char[] symbolTrim = new[] { '\r', '\n' }; private const string openBrace = "("; private const string closeBrace = ")"; private const char delimiter = ' '; private static readonly char[] symbolTrim = new[] { '\r', '\n' }; public Expression Parse(string source, int startIndex = 0) public static Expression Parse(string source, int startIndex = 0) { var symbols = source.Split(' '); var symbols = source.Split(delimiter); int endIndex; return this.Parse(symbols, 0, out endIndex); return Parse(symbols, 0, out endIndex); } private Expression Parse(string[] symbols, int startIndex, out int endIndex) private static Expression Parse(string[] symbols, int startIndex, out int endIndex) { var expressions = new List(); { var symbol = symbols[i].TrimEnd(symbolTrim); if (string.IsNullOrWhiteSpace(symbol)) { } if (symbol == OpenBrace) if (symbol == openBrace) { var subExpression = Parse(symbols, i + 1, out endIndex); continue; } else if (symbol == CloseBrace) else if (symbol == closeBrace) { endIndex = i; ? new ExecExpandExpression(expressions.ToArray()) : new CodeNoopExpression() as Expression; } if (string.IsNullOrWhiteSpace(symbol)) { continue; } } // instruction // expression OpCode opCode; if (SymbolTable.TryGetOpCode(symbol, out opCode)) { expression = ExpressionCreatorTable.GetCreator(opCode).Invoke(); expression = ExpressionFactory.Create(opCode); expressions.Insert(0, expression); continue; } // identifier - custom instruction or named literals // identifier - custom expression or named literals expressions.Insert(0, new NameDefineXExecExpression(symbol)); } } private bool TryParseLiteral(string word, out Expression expression) private static bool TryParseLiteral(string word, out Expression expression) { long longValue;
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Parser/SymbolTable.cs

 r14323 ﻿using System; using System.Collections.Generic; using System.Linq; namespace HeuristicLab.Algorithms.PushGP { #region Code { "CODE.NOOP", OpCode.CodeNoop }, { "CODE.PUSH", OpCode.CodePush }, { "CODE.IF", OpCode.CodeIf }, { "CODE.DEFINE", OpCode.CodeDefine }, { "CODE.DUP", OpCode.CodeDup }, { "CODE.QUOTE", OpCode.CodeQuote }, { "CODE.DO", OpCode.CodeDo }, { Symbols.CodeIf, OpCode.CodeIf }, { Symbols.CodeDefine, OpCode.CodeDefine }, { Symbols.CodeDuplicate, OpCode.CodeDuplicate }, { Symbols.CodeQuote, OpCode.CodeQuote }, { Symbols.CodeDo, OpCode.CodeDo }, { Symbols.CodeEquals, OpCode.CodeEquals }, { Symbols.CodeAppend, OpCode.CodeAppend }, { Symbols.CodeAtom, OpCode.CodeAtom }, { Symbols.CodeCar, OpCode.CodeCar }, { Symbols.CodeCdr, OpCode.CodeCdr }, { Symbols.CodeCons, OpCode.CodeCons }, { Symbols.CodeContainer, OpCode.CodeContainer }, { Symbols.CodeContains, OpCode.CodeContains }, { Symbols.CodeDefinition, OpCode.CodeDefinition }, { Symbols.CodeDiscrepancy, OpCode.CodeDiscrepancy }, { Symbols.CodeDoX, OpCode.CodeDoX }, { Symbols.CodeDoXCount, OpCode.CodeDoXCount }, { Symbols.CodeDoXRange, OpCode.CodeDoXRange }, { Symbols.CodeDoXTimes, OpCode.CodeDoXTimes }, { Symbols.CodeExtract, OpCode.CodeExtract }, { Symbols.CodeFlush, OpCode.CodeFlush }, { Symbols.CodeFromFloat, OpCode.CodeFromFloat }, { Symbols.CodeFromInteger, OpCode.CodeFromInteger }, { Symbols.CodeFromName, OpCode.CodeFromName }, { Symbols.CodeInsert, OpCode.CodeInsert }, { Symbols.CodeInstructions, OpCode.CodeInstructions }, { Symbols.CodeLength, OpCode.CodeLength }, { Symbols.CodeList, OpCode.CodeList }, { Symbols.CodeMember, OpCode.CodeMember }, { Symbols.CodeNoop, OpCode.CodeNoop }, { Symbols.CodeNth, OpCode.CodeNth }, { Symbols.CodeNthCdr, OpCode.CodeNthCdr }, { Symbols.CodeNull, OpCode.CodeNull }, { Symbols.CodePosition, OpCode.CodePosition }, { Symbols.CodeRand, OpCode.CodeRand }, { Symbols.CodeRot, OpCode.CodeRot }, { Symbols.CodeShove, OpCode.CodeShove }, { Symbols.CodeSize, OpCode.CodeSize }, { Symbols.CodeStackDepth, OpCode.CodeStackDepth }, { Symbols.CodeSubst, OpCode.CodeSubst }, { Symbols.CodeSwap, OpCode.CodeSwap }, { Symbols.CodeYank, OpCode.CodeYank }, { Symbols.CodeYankDuplicate, OpCode.CodeYankDuplicate }, #endregion Code #region Exec { "EXEC.EXPAND", OpCode.ExecExpand }, { "EXEC.PUSH", OpCode.ExecPush }, { "EXEC.IF", OpCode.ExecIf }, { "EXEC.DEFINE", OpCode.ExecDefine }, { "EXEC.DUP", OpCode.ExecDup }, { "EXEC.POP", OpCode.ExecPop }, { "EXEC.Y", OpCode.ExecY }, { "EXEC.DO*RANGE", OpCode.ExecDoXRange }, { Symbols.ExecIf, OpCode.ExecIf }, { Symbols.ExecDefine, OpCode.ExecDefine }, { Symbols.ExecDuplicate, OpCode.ExecDuplicate }, { Symbols.ExecPop, OpCode.ExecPop }, { Symbols.ExecY, OpCode.ExecY }, { Symbols.ExecDoXRange, OpCode.ExecDoXRange }, { Symbols.ExecEquals, OpCode.ExecEquals }, { Symbols.ExecDoXCount, OpCode.ExecDoXCount }, { Symbols.ExecDoXTimes, OpCode.ExecDoXTimes }, { Symbols.ExecFlush, OpCode.ExecFlush }, { Symbols.ExecK, OpCode.ExecK }, { Symbols.ExecRot, OpCode.ExecRot }, { Symbols.ExecS, OpCode.ExecS }, { Symbols.ExecShove, OpCode.ExecShove }, { Symbols.ExecStackDepth, OpCode.ExecStackDepth }, { Symbols.ExecSwap, OpCode.ExecSwap }, { Symbols.ExecYank, OpCode.ExecYank }, { Symbols.ExecYankDuplicate, OpCode.ExecYankDuplicate }, #endregion Exec #region Name { "NAME.DEFINE*EXEC", OpCode.NameDefineXExec }, { "NAME.POP", OpCode.NamePop }, { "NAME.DUP", OpCode.NameDup }, { Symbols.NamePop, OpCode.NamePop }, { Symbols.NameDuplicate, OpCode.NameDuplicate }, { Symbols.NameEquals, OpCode.NameEquals }, { Symbols.NameFlush, OpCode.NameFlush }, { Symbols.NameQuote, OpCode.NameQuote }, { Symbols.NameRand, OpCode.NameRand }, { Symbols.NameRandBoundName, OpCode.NameRand }, { Symbols.NameRot, OpCode.NameRot }, { Symbols.NameShove, OpCode.NameShove }, { Symbols.NameStackDepth, OpCode.NameStackDepth }, { Symbols.NameSwap, OpCode.NameSwap }, { Symbols.NameYank, OpCode.NameYank }, { Symbols.NameYankDuplicate, OpCode.NameYankDuplicate }, #endregion Name #region Boolean { "BOOLEAN.PUSH", OpCode.BooleanPush }, { "BOOLEAN.POP", OpCode.BooleanPop }, { "BOOLEAN.DUP", OpCode.BooleanDup }, { "BOOLEAN.AND", OpCode.BooleanAnd }, { "BOOLEAN.OR", OpCode.BooleanOr }, { Symbols.BooleanPop, OpCode.BooleanPop }, { Symbols.BooleanDuplicate, OpCode.BooleanDuplicate }, { Symbols.BooleanAnd, OpCode.BooleanAnd }, { Symbols.BooleanOr, OpCode.BooleanOr }, { Symbols.BooleanEquals, OpCode.BooleanEquals }, { Symbols.BooleanFlush, OpCode.BooleanFlush }, { Symbols.BooleanFromFloat, OpCode.BooleanFromFloat }, { Symbols.BooleanFromInteger, OpCode.BooleanFromInteger }, { Symbols.BooleanNot, OpCode.BooleanNot }, { Symbols.BooleanRand, OpCode.BooleanRand }, { Symbols.BooleanRot, OpCode.BooleanRot }, { Symbols.BooleanShove, OpCode.BooleanShove }, { Symbols.BooleanStackDepth, OpCode.BooleanStackDepth }, { Symbols.BooleanSwap, OpCode.BooleanSwap }, { Symbols.BooleanYank, OpCode.BooleanYank }, { Symbols.BooleanYankDuplicate, OpCode.BooleanYankDuplicate }, #endregion Boolean #region Integer { "INTEGER.PUSH", OpCode.IntegerPush }, { "INTEGER.POP", OpCode.IntegerPop }, { "INTEGER.DUP", OpCode.IntegerDup }, { "INTEGER.DEFINE", OpCode.IntegerDefine }, { "INTEGER.+", OpCode.IntegerAdd }, { "INTEGER.-", OpCode.IntegerSubtract }, { "INTEGER.*", OpCode.IntegerMultiply }, { "INTEGER./", OpCode.IntegerDivide }, { "INTEGER.<", OpCode.IntegerSmallerThan }, { "INTEGER.>", OpCode.IntegerGreaterThan }, { "INTEGER.=", OpCode.IntegerEquals }, { "INTEGER.MIN", OpCode.IntegerMin }, { "INTEGER.MAX", OpCode.IntegerMax }, { Symbols.IntegerPop, OpCode.IntegerPop }, { Symbols.IntegerDuplicate, OpCode.IntegerDuplicate }, { Symbols.IntegerDefine, OpCode.IntegerDefine }, { Symbols.IntegerAdd, OpCode.IntegerAdd }, { Symbols.IntegerSubtract, OpCode.IntegerSubtract }, { Symbols.IntegerMultiply, OpCode.IntegerMultiply }, { Symbols.IntegerDivide, OpCode.IntegerDivide }, { Symbols.IntegerSmallerThan, OpCode.IntegerSmallerThan }, { Symbols.IntegerGreaterThan, OpCode.IntegerGreaterThan }, { Symbols.IntegerEquals, OpCode.IntegerEquals }, { Symbols.IntegerMin, OpCode.IntegerMin }, { Symbols.IntegerMax, OpCode.IntegerMax }, { Symbols.IntegerModulo, OpCode.IntegerModulo }, { Symbols.IntegerFlush, OpCode.IntegerFlush }, { Symbols.IntegerFromBoolean, OpCode.IntegerFromBoolean }, { Symbols.IntegerFromFloat, OpCode.IntegerFromFloat }, { Symbols.IntegerRand, OpCode.IntegerRand }, { Symbols.IntegerRot, OpCode.IntegerRot }, { Symbols.IntegerShove, OpCode.IntegerShove }, { Symbols.IntegerStackDepth, OpCode.IntegerStackDepth }, { Symbols.IntegerSwap, OpCode.IntegerSwap }, { Symbols.IntegerYank, OpCode.IntegerYank }, { Symbols.IntegerYankDuplicate, OpCode.IntegerYankDuplicate }, #endregion Integer #region Float { "FLOAT.PUSH", OpCode.FloatPush }, { "FLOAT.POP", OpCode.FloatPop }, { "FLOAT.DUP", OpCode.FloatDup }, { "FLOAT.DEFINE", OpCode.FloatDefine }, { "FLOAT.+", OpCode.FloatAdd }, { "FLOAT.-", OpCode.FloatSubtract }, { "FLOAT.*", OpCode.FloatMultiply }, { "FLOAT./", OpCode.FloatDivide }, { "FLOAT.<", OpCode.FloatSmallerThan }, { "FLOAT.>", OpCode.FloatGreaterThan }, { "FLOAT.=", OpCode.FloatEquals }, { "FLOAT.MIN", OpCode.FloatMin }, { "FLOAT.MAX", OpCode.FloatMax }, { Symbols.FloatPop, OpCode.FloatPop }, { Symbols.FloatDuplicate, OpCode.FloatDuplicate }, { Symbols.FloatDefine, OpCode.FloatDefine }, { Symbols.FloatAdd, OpCode.FloatAdd }, { Symbols.FloatSubtract, OpCode.FloatSubtract }, { Symbols.FloatMultiply, OpCode.FloatMultiply }, { Symbols.FloatDivide, OpCode.FloatDivide }, { Symbols.FloatSmallerThan, OpCode.FloatSmallerThan }, { Symbols.FloatGreaterThan, OpCode.FloatGreaterThan }, { Symbols.FloatEquals, OpCode.FloatEquals }, { Symbols.FloatMin, OpCode.FloatMin }, { Symbols.FloatMax, OpCode.FloatMax }, { Symbols.FloatCos, OpCode.FloatCos }, { Symbols.FloatSin, OpCode.FloatSin }, { Symbols.FloatTan, OpCode.FloatTan }, { Symbols.FloatFromBoolean, OpCode.FloatFromBoolean }, { Symbols.FloatFromInteger, OpCode.FloatFromInteger }, { Symbols.FloatRand, OpCode.FloatRand }, { Symbols.FloatRot, OpCode.FloatRot }, { Symbols.FloatShove, OpCode.FloatShove }, { Symbols.FloatStackDepth, OpCode.FloatStackDepth }, { Symbols.FloatSwap, OpCode.FloatSwap }, { Symbols.FloatYank, OpCode.FloatYank }, { Symbols.FloatYankDuplicate, OpCode.FloatYankDuplicate }, #endregion Float }; OpCode opCode; if (symbolTable.TryGetValue(operationName, out opCode)) return opCode; else throw new NotSupportedException("Symbol: " + operationName); else throw new NotSupportedException("Operation not supported: " + operationName); } return symbolTable.TryGetValue(operationName, out opCode); } public static string GetSymbol(OpCode opCode) { var symbol = symbolTable.SingleOrDefault(pair => pair.Value == opCode); return !symbol.Equals(default(KeyValuePair)) ? symbol.Key : null; } } }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Stack/PushGPStack.cs

 r14323 using System.Collections; using System.Collections.Generic; using System.Text; namespace HeuristicLab.Algorithms.PushGP.Stack { /// /// While Push's stacks are generally treated as genuine stacks---that is, instructions take their arguments from the tops of /// the stacks and push their results onto the tops of the stacks---a few instructions (like YANK and SHOVE) do allow direct access /// While Push's stacks are generally treated as genuine stacks---that is, inclassions take their arguments from the tops of /// the stacks and push their results onto the tops of the stacks---a few inclassions (like YANK and SHOVE) do allow direct access /// to "deep" stack elements by means of integer indices. To this extent the stacks can be used as general, random access memory /// structures. This is one of the features that ensures the Turing-completeness of Push (another being the arbitrary name/value /// classures. This is one of the features that ensures the Turing-completeness of Push (another being the arbitrary name/value /// bindings supported by the NAME data type and DEFINE methods; see below). /// public class PushGPStack : IStack { private List data = new List(); private readonly List data; private const string delimiter = " "; public T Top => this.data[Count - 1]; public int Count => data.Count; public bool IsEmpty => this.Count == 0; public PushGPStack(int capacity = 0) { this.data = new List(); } public T Top { get { return this.data[Count - 1]; } } public int Count { get { return this.data.Count; } } public int Capacity { get { return this.data.Capacity; } } public bool IsEmpty { get { return this.Count == 0; } } public bool IsReadOnly public T Pop() { var index = Count - 1; var value = this.data[index]; this.data.RemoveAt(index); var value = this.data[Count - 1]; this.data.RemoveAt(Count - 1); return value; this.data.RemoveRange(startIndex, count); items.Reverse(); // is faster than remove range?? for (var i = this.Count - 1; i > startIndex - 1; i--) { this.data.RemoveAt(i); } return items.ToArray(); } public void Push(params T[] items) { this.data.AddRange(items); foreach (var item in items) { this.data.Add(item); } } { var index = Count - 1; if (this.data.Count > 0 && this.data[index].Equals(item)) if (this.Count > 0 && this.data[index].Equals(item)) { this.data.RemoveAt(index); public bool TryPop(out T item) { if (this.data.Count > 0) if (this.Count > 0) { item = this.Pop(); public override string ToString() { return string.Join(", ", this.data); if (this.Count == 0) { return string.Empty; } var sb = new StringBuilder(); for (var i = this.Count - 1; i > 0; i--) { sb.Append(this.data[i] + delimiter); } sb.Append(this.data[0]); return sb.ToString(); } }
• ## branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Tests/HeuristicLab.Tests.csproj

 r14323 HeuristicLab.TestsHeuristicLab.Testsv4.5.2v4.5512{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}FalseUnitTest prompt 4 5
Note: See TracChangeset for help on using the changeset viewer.