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

    r14834 r14875  
    1010  /// </summary>
    1111  [PushExpression(StackTypes.Boolean, "BOOLEAN.AND")]
    12   public class BooleanAndExpression : PushResultExpression<bool> {
     12  public class BooleanAndExpression : StatelessExpression {
    1313    public override bool Eval(IInternalPushInterpreter interpreter) {
    14       return Eval(interpreter.BooleanStack, 2, values => values[0] && values[1]);
     14      if (interpreter.BooleanStack.Count < 2)
     15        return false;
     16
     17      var first = interpreter.BooleanStack.Pop();
     18      var second = interpreter.BooleanStack.Top;
     19      var result = second && first;
     20
     21      interpreter.BooleanStack.SetTop(result);
     22      return true;
    1523    }
    1624  }
     
    2028  /// </summary>
    2129  [PushExpression(StackTypes.Boolean, "BOOLEAN.OR")]
    22   public class BooleanOrExpression : PushResultExpression<bool> {
     30  public class BooleanOrExpression : StatelessExpression {
    2331    public override bool Eval(IInternalPushInterpreter interpreter) {
    24       return Eval(interpreter.BooleanStack, 2, values => values[0] || values[1]);
     32      if (interpreter.BooleanStack.Count < 2)
     33        return false;
     34
     35      var first = interpreter.BooleanStack.Pop();
     36      var second = interpreter.BooleanStack.Top;
     37      var result = second || first;
     38
     39      interpreter.BooleanStack.SetTop(result);
     40      return true;
    2541    }
    2642  }
     
    3046  /// </summary>
    3147  [PushExpression(StackTypes.Boolean, "BOOLEAN.NOT")]
    32   public class BooleanNotExpression : PushResultExpression<bool> {
     48  public class BooleanNotExpression : StatelessExpression {
    3349    public override bool Eval(IInternalPushInterpreter interpreter) {
    34       return Eval(interpreter.BooleanStack, 1, values => !values[0]);
     50      if (interpreter.BooleanStack.IsEmpty)
     51        return false;
     52
     53      interpreter.BooleanStack.SetTop(!interpreter.BooleanStack.Top);
     54      return true;
    3555    }
    3656  }
     
    7090  /// </summary>
    7191  [PushExpression(StackTypes.Boolean, "BOOLEAN.INVERT_FIRST_THEN_AND")]
    72   public class BooleanInvertFirstThenAnd : PushResultExpression<bool> {
     92  public class BooleanInvertFirstThenAnd : StatelessExpression {
    7393    public override bool Eval(IInternalPushInterpreter interpreter) {
    74       return Eval(interpreter.BooleanStack, 2, values => !values[0] && values[1]);
     94      if (interpreter.BooleanStack.Count < 2)
     95        return false;
     96
     97      var first = interpreter.BooleanStack.Pop();
     98      var second = interpreter.BooleanStack.Top;
     99      var result = second && !first;
     100
     101      interpreter.BooleanStack.SetTop(result);
     102      return true;
    75103    }
    76104  }
     
    80108  /// </summary>
    81109  [PushExpression(StackTypes.Boolean, "BOOLEAN.INVERT_SECOND_THEN_AND")]
    82   public class BooleanInvertSecondThenAnd : PushResultExpression<bool> {
     110  public class BooleanInvertSecondThenAnd : StatelessExpression {
    83111    public override bool Eval(IInternalPushInterpreter interpreter) {
    84       return Eval(interpreter.BooleanStack, 2, values => values[0] && !values[1]);
     112      if (interpreter.BooleanStack.Count < 2)
     113        return false;
     114
     115      var first = interpreter.BooleanStack.Pop();
     116      var second = interpreter.BooleanStack.Top;
     117      var result = !second && first;
     118
     119      interpreter.BooleanStack.SetTop(result);
     120      return true;
    85121    }
    86122  }
     
    88124
    89125  /// <summary>
    90   ///     Pushes the logical AND of the top two BOOLEANs, whereby the second value is inverted first.
     126  ///     Pushes the xor of the top tow BOOLEANs
    91127  /// </summary>
    92128  [PushExpression(StackTypes.Boolean, "BOOLEAN.XOR")]
    93   public class BooleanXorExpression : PushResultExpression<bool> {
     129  public class BooleanXorExpression : StatelessExpression {
    94130    public override bool Eval(IInternalPushInterpreter interpreter) {
    95       return Eval(interpreter.BooleanStack, 2, values => values[0] ^ values[1]);
     131      if (interpreter.BooleanStack.Count < 2)
     132        return false;
     133
     134      var first = interpreter.BooleanStack.Pop();
     135      var second = interpreter.BooleanStack.Top;
     136      var result = second ^ first;
     137
     138      interpreter.BooleanStack.SetTop(result);
     139      return true;
    96140    }
    97141  }
Note: See TracChangeset for help on using the changeset viewer.