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/VectorSetExpressions.cs

    r14909 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 VectorSetExpression<T> : StatelessExpression {
    13     protected bool Eval(
     15    protected VectorSetExpression() { }
     16    [StorableConstructor]
     17    protected VectorSetExpression(bool deserializing) : base(deserializing) { }
     18
     19    protected bool IsNoop(IInternalPushInterpreter interpreter, IPushStack<List<T>> vectorStack, IPushStack<T> literalStack, bool isLiteralTypeInteger = false) {
     20      return vectorStack.IsEmpty ||
     21             vectorStack.Top.Count == 0 ||
     22             literalStack.IsEmpty ||
     23             (isLiteralTypeInteger && interpreter.IntegerStack.Count < 2) ||
     24             (!isLiteralTypeInteger && interpreter.IntegerStack.IsEmpty);
     25    }
     26
     27    protected void Eval(
    1428      IInternalPushInterpreter interpreter,
    1529      IPushStack<List<T>> vectorStack,
    1630      IPushStack<T> literalStack,
    1731      bool isLiteralTypeInteger = false) {
    18       if (vectorStack.IsEmpty ||
    19           vectorStack.Top.Count == 0 ||
    20           literalStack.IsEmpty ||
    21           (isLiteralTypeInteger && interpreter.IntegerStack.Count < 2) ||
    22           (!isLiteralTypeInteger && interpreter.IntegerStack.IsEmpty))
    23         return false;
    24 
    2532      T literal;
    2633      int index;
     
    4249
    4350      vector[index] = literal;
    44       return true;
    4551    }
    4652  }
    4753
     54  [StorableClass]
    4855  [PushExpression(StackTypes.IntegerVector, "INTEGER[].SET", StackTypes.Integer)]
    4956  public class IntegerVectorSetExpression : VectorSetExpression<long> {
    50     public override bool Eval(IInternalPushInterpreter interpreter) {
    51       return Eval(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack, true);
     57    public IntegerVectorSetExpression() { }
     58    [StorableConstructor]
     59    protected IntegerVectorSetExpression(bool deserializing) : base(deserializing) { }
     60
     61    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     62      return IsNoop(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack, true);
     63    }
     64
     65    public override void Eval(IInternalPushInterpreter interpreter) {
     66      Eval(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack, true);
    5267    }
    5368  }
    5469
     70  [StorableClass]
    5571  [PushExpression(StackTypes.FloatVector, "FLOAT[].SET", StackTypes.Float | StackTypes.Integer)]
    5672  public class FloatVectorSetExpression : VectorSetExpression<double> {
    57     public override bool Eval(IInternalPushInterpreter interpreter) {
    58       return Eval(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack);
     73    public FloatVectorSetExpression() { }
     74    [StorableConstructor]
     75    protected FloatVectorSetExpression(bool deserializing) : base(deserializing) { }
     76
     77    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     78      return IsNoop(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack);
     79    }
     80
     81    public override void Eval(IInternalPushInterpreter interpreter) {
     82      Eval(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack);
    5983    }
    6084  }
    6185
     86  [StorableClass]
    6287  [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].SET", StackTypes.Boolean | StackTypes.Integer)]
    6388  public class BooleanVectorSetExpression : VectorSetExpression<bool> {
    64     public override bool Eval(IInternalPushInterpreter interpreter) {
    65       return Eval(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack);
     89    public BooleanVectorSetExpression() { }
     90    [StorableConstructor]
     91    protected BooleanVectorSetExpression(bool deserializing) : base(deserializing) { }
     92
     93    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     94      return IsNoop(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack);
     95    }
     96
     97    public override void Eval(IInternalPushInterpreter interpreter) {
     98      Eval(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack);
    6699    }
    67100  }
    68101
     102  [StorableClass]
    69103  [PushExpression(StackTypes.StringVector, "STRING[].SET", StackTypes.String | StackTypes.Integer)]
    70104  public class StringVectorSetExpression : VectorSetExpression<string> {
    71     public override bool Eval(IInternalPushInterpreter interpreter) {
    72       return Eval(interpreter, interpreter.StringVectorStack, interpreter.StringStack);
     105    public StringVectorSetExpression() { }
     106    [StorableConstructor]
     107    protected StringVectorSetExpression(bool deserializing) : base(deserializing) { }
     108
     109    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     110      return IsNoop(interpreter, interpreter.StringVectorStack, interpreter.StringStack);
     111    }
     112
     113    public override void Eval(IInternalPushInterpreter interpreter) {
     114      Eval(interpreter, interpreter.StringVectorStack, interpreter.StringStack);
    73115    }
    74116  }
Note: See TracChangeset for help on using the changeset viewer.