Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/10/17 11:23:05 (8 years ago)
Author:
pkimmesw
Message:

#2665 Added IsNoop to Expression, Made Expressions storable, Fixed Debugger, Fixed and improved problem data and result visualisation, Added custom ErcOption view, Added problem difficulty to problem data name

File:
1 edited

Legend:

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

    r14834 r14952  
    22
    33namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
     4  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    45  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
    56  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
     
    1011  /// </summary>
    1112  /// <typeparam name="T"></typeparam>
     13  [StorableClass]
    1214  public abstract class VectorIndexOfExpression<T> : StatelessExpression {
    13     protected bool Eval(
     15    protected VectorIndexOfExpression() { }
     16    [StorableConstructor]
     17    protected VectorIndexOfExpression(bool deserializing) : base(deserializing) { }
     18
     19    protected bool IsNoop(IPushStack<List<T>> vectorStack, IPushStack<T> literalStack) {
     20      return vectorStack.IsEmpty || literalStack.IsEmpty;
     21    }
     22
     23    protected void Eval(
    1424      IInternalPushInterpreter interpreter,
    1525      IPushStack<List<T>> vectorStack,
    1626      IPushStack<T> literalStack,
    1727      bool canOverride = false) {
    18       if (vectorStack.IsEmpty || literalStack.IsEmpty)
    19         return false;
    20 
    2128      var vector = vectorStack.Pop();
    2229      var literal = canOverride ? literalStack.Top : literalStack.Pop();
     
    2532      if (canOverride) interpreter.IntegerStack.SetTop(result);
    2633      else interpreter.IntegerStack.Push(result);
    27       return true;
    2834    }
    2935  }
    3036
     37  [StorableClass]
    3138  [PushExpression(StackTypes.IntegerVector, "INTEGER[].INDEXOF", StackTypes.Integer)]
    3239  public class IntegerVectorIndexOfExpression : VectorIndexOfExpression<long> {
    33     public override bool Eval(IInternalPushInterpreter interpreter) {
    34       return Eval(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack, true);
     40    public IntegerVectorIndexOfExpression() { }
     41    [StorableConstructor]
     42    protected IntegerVectorIndexOfExpression(bool deserializing) : base(deserializing) { }
     43
     44    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     45      return IsNoop(interpreter.IntegerVectorStack, interpreter.IntegerStack);
     46    }
     47
     48    public override void Eval(IInternalPushInterpreter interpreter) {
     49      Eval(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack, true);
    3550    }
    3651  }
    3752
     53  [StorableClass]
    3854  [PushExpression(StackTypes.FloatVector, "FLOAT[].INDEXOF", StackTypes.Float | StackTypes.Integer)]
    3955  public class FloatVectorIndexOfExpression : VectorIndexOfExpression<double> {
    40     public override bool Eval(IInternalPushInterpreter interpreter) {
    41       return Eval(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack);
     56    public FloatVectorIndexOfExpression() { }
     57    [StorableConstructor]
     58    protected FloatVectorIndexOfExpression(bool deserializing) : base(deserializing) { }
     59
     60    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     61      return IsNoop(interpreter.FloatVectorStack, interpreter.FloatStack);
     62    }
     63
     64    public override void Eval(IInternalPushInterpreter interpreter) {
     65      Eval(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack);
    4266    }
    4367  }
    4468
     69  [StorableClass]
    4570  [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].INDEXOF", StackTypes.Boolean | StackTypes.Integer)]
    4671  public class BooleanVectorIndexOfExpression : VectorIndexOfExpression<bool> {
    47     public override bool Eval(IInternalPushInterpreter interpreter) {
    48       return Eval(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack);
     72    public BooleanVectorIndexOfExpression() { }
     73    [StorableConstructor]
     74    protected BooleanVectorIndexOfExpression(bool deserializing) : base(deserializing) { }
     75
     76    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     77      return IsNoop(interpreter.BooleanVectorStack, interpreter.BooleanStack);
     78    }
     79
     80    public override void Eval(IInternalPushInterpreter interpreter) {
     81      Eval(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack);
    4982    }
    5083  }
    5184
     85  [StorableClass]
    5286  [PushExpression(StackTypes.StringVector, "STRING[].INDEXOF", StackTypes.String | StackTypes.String)]
    5387  public class StringVectorIndexOfExpression : VectorIndexOfExpression<string> {
    54     public override bool Eval(IInternalPushInterpreter interpreter) {
    55       return Eval(interpreter, interpreter.StringVectorStack, interpreter.StringStack);
     88    public StringVectorIndexOfExpression() { }
     89    [StorableConstructor]
     90    protected StringVectorIndexOfExpression(bool deserializing) : base(deserializing) { }
     91
     92    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     93      return IsNoop(interpreter.StringVectorStack, interpreter.StringStack);
     94    }
     95
     96    public override void Eval(IInternalPushInterpreter interpreter) {
     97      Eval(interpreter, interpreter.StringVectorStack, interpreter.StringStack);
    5698    }
    5799  }
Note: See TracChangeset for help on using the changeset viewer.