Changeset 14875 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ShoveExpressions.cs
- Timestamp:
- 04/18/17 01:15:25 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ShoveExpressions.cs
r14834 r14875 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 using System; 2 3 using System.Collections.Generic; 3 4 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 5 5 using Attributes; 6 6 using Interpreter; 7 7 using Stack; 8 8 9 9 public abstract class ShoveExpression<T> : StatelessExpression { 10 protected bool Eval(IPushStack<T> stack, IPushStack<long> integerStack, int count = 1) { 11 if (integerStack.Count == 0 || 12 integerStack.Top > stack.Count - count || 13 integerStack.Top < 0 || 14 stack.Count < 2) 10 protected bool Eval(IPushStack<T> stack, IPushStack<long> integerStack) { 11 if ((stack == integerStack && integerStack.Count < 3) || 12 (stack != integerStack && (integerStack.IsEmpty || stack.Count < 2))) 15 13 return false; 16 14 17 var index = (int) integerStack.Pop();15 var index = (int)Math.Abs(integerStack.Pop() % stack.Count); 18 16 var item = stack.Pop(); 19 20 17 stack.Insert(index, item); 21 18 return true; … … 26 23 public class IntegerShoveExpression : ShoveExpression<long> { 27 24 public override bool Eval(IInternalPushInterpreter interpreter) { 28 return Eval(interpreter.IntegerStack, interpreter.IntegerStack , 2);25 return Eval(interpreter.IntegerStack, interpreter.IntegerStack); 29 26 } 30 27 } … … 85 82 } 86 83 } 84 85 [PushExpression(StackTypes.FloatVector, "FLOAT[].SHOVE", StackTypes.Integer)] 86 public class FloatVectorShoveExpression : ShoveExpression<List<double>> { 87 public override bool Eval(IInternalPushInterpreter interpreter) { 88 return Eval(interpreter.FloatVectorStack, interpreter.IntegerStack); 89 } 90 } 91 92 [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].SHOVE", StackTypes.Integer)] 93 public class BooleanVectorShoveExpression : ShoveExpression<List<bool>> { 94 public override bool Eval(IInternalPushInterpreter interpreter) { 95 return Eval(interpreter.BooleanVectorStack, interpreter.IntegerStack); 96 } 97 } 98 99 [PushExpression(StackTypes.StringVector, "STRING[].SHOVE", StackTypes.Integer)] 100 public class StringVectorShoveExpression : ShoveExpression<List<string>> { 101 public override bool Eval(IInternalPushInterpreter interpreter) { 102 return Eval(interpreter.StringVectorStack, interpreter.IntegerStack); 103 } 104 } 87 105 }
Note: See TracChangeset
for help on using the changeset viewer.