Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/17 01:15:25 (8 years ago)
Author:
pkimmesw
Message:

#2665 BenchmarkSuite, all examples, partially tested, VectorExpressions added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ShoveExpressions.cs

    r14834 r14875  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
     2  using System;
    23  using System.Collections.Generic;
    34
    4   using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
    5 
     5  using Attributes;
    66  using Interpreter;
    77  using Stack;
    88
    99  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)))
    1513        return false;
    1614
    17       var index = (int)integerStack.Pop();
     15      var index = (int)Math.Abs(integerStack.Pop() % stack.Count);
    1816      var item = stack.Pop();
    19 
    2017      stack.Insert(index, item);
    2118      return true;
     
    2623  public class IntegerShoveExpression : ShoveExpression<long> {
    2724    public override bool Eval(IInternalPushInterpreter interpreter) {
    28       return Eval(interpreter.IntegerStack, interpreter.IntegerStack, 2);
     25      return Eval(interpreter.IntegerStack, interpreter.IntegerStack);
    2926    }
    3027  }
     
    8582    }
    8683  }
     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  }
    87105}
Note: See TracChangeset for help on using the changeset viewer.