Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/20/16 22:57:11 (7 years ago)
Author:
pkimmesw
Message:

#2665 Added Problem.ProgramSynthesis Project, Fixed Expression Issues, Fixed Code Generation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/BooleanExpressions.cs

    r14398 r14513  
    1 using HeuristicLab.Algorithms.PushGP.Interpreter;
     1namespace HeuristicLab.Algorithms.PushGP.Expressions {
     2  using HeuristicLab.Algorithms.PushGP.Interpreter;
    23
    3 namespace HeuristicLab.Algorithms.PushGP.Expressions
    4 {
    5     /// <summary>
    6     /// Pushes the logical AND of the top two BOOLEANs.
    7     /// </summary>
    8     public class BooleanAndExpression : PushResultExpression<bool>
    9     {
    10         protected override string InitStringRepresentation()
    11         {
    12             return "BOOLEAN.AND";
    13         }
    14 
    15         public override void Eval(IInterpreter interpreter)
    16         {
    17             Eval(interpreter.BooleanStack, 2, values => values[0] && values[1]);
    18         }
     4  /// <summary>
     5  ///     Pushes the logical AND of the top two BOOLEANs.
     6  /// </summary>
     7  public class BooleanAndExpression : PushResultExpression<bool> {
     8    protected override string InitStringRepresentation() {
     9      return "BOOLEAN.AND";
    1910    }
    2011
    21     /// <summary>
    22     /// Pushes the logical OR of the top two BOOLEANs.
    23     /// </summary>
    24     public class BooleanOrExpression : PushResultExpression<bool>
    25     {
    26         protected override string InitStringRepresentation()
    27         {
    28             return "BOOLEAN.OR";
    29         }
     12    public override void Eval(IPushGpInterpreter interpreter) {
     13      this.Eval(interpreter.BooleanStack, 2, values => values[0] && values[1]);
     14    }
     15  }
    3016
    31         public override void Eval(IInterpreter interpreter)
    32         {
    33             Eval(interpreter.BooleanStack, 2, values => values[0] || values[1]);
    34         }
     17  /// <summary>
     18  ///     Pushes the logical OR of the top two BOOLEANs.
     19  /// </summary>
     20  public class BooleanOrExpression : PushResultExpression<bool> {
     21    protected override string InitStringRepresentation() {
     22      return "BOOLEAN.OR";
    3523    }
    3624
    37     /// <summary>
    38     /// Pushes the logical NOT of the top BOOLEAN.
    39     /// </summary>
    40     public class BooleanNotExpression : PushResultExpression<bool>
    41     {
    42         protected override string InitStringRepresentation() { return "BOOLEAN.NOT"; }
     25    public override void Eval(IPushGpInterpreter interpreter) {
     26      this.Eval(interpreter.BooleanStack, 2, values => values[0] || values[1]);
     27    }
     28  }
    4329
    44         public override void Eval(IInterpreter interpreter)
    45         {
    46             Eval(interpreter.BooleanStack, 1, values => !values[0]);
    47         }
     30  /// <summary>
     31  ///     Pushes the logical NOT of the top BOOLEAN.
     32  /// </summary>
     33  public class BooleanNotExpression : PushResultExpression<bool> {
     34    protected override string InitStringRepresentation() {
     35      return "BOOLEAN.NOT";
    4836    }
    4937
    50     /// <summary>
    51     /// Pushes FALSE if the top FLOAT is 0.0, or TRUE otherwise.
    52     /// </summary>
    53     public class BooleanFromFloatExpression : StatelessExpression
    54     {
    55         protected override string InitStringRepresentation() { return "BOOLEAN.FROMFLOAT"; }
     38    public override void Eval(IPushGpInterpreter interpreter) {
     39      this.Eval(interpreter.BooleanStack, 1, values => !values[0]);
     40    }
     41  }
    5642
    57         public override void Eval(IInterpreter interpreter)
    58         {
    59             if (interpreter.FloatStack.Count == 0)
    60                 return;
    61 
    62             var value = interpreter.FloatStack.Pop() != 0.0;
    63 
    64             interpreter.BooleanStack.Push(value);
    65         }
     43  /// <summary>
     44  ///     Pushes FALSE if the top FLOAT is 0.0, or TRUE otherwise.
     45  /// </summary>
     46  public class BooleanFromFloatExpression : StatelessExpression {
     47    protected override string InitStringRepresentation() {
     48      return "BOOLEAN.FROMFLOAT";
    6649    }
    6750
    68     /// <summary>
    69     /// Pushes FALSE if the top INTEGER is 0, or TRUE otherwise.
    70     /// </summary>
    71     public class BooleanFromIntegerExpression : StatelessExpression
    72     {
    73         protected override string InitStringRepresentation() { return "BOOLEAN.FROMINTEGER"; }
     51    public override void Eval(IPushGpInterpreter interpreter) {
     52      if (interpreter.FloatStack.Count == 0) return;
    7453
    75         public override void Eval(IInterpreter interpreter)
    76         {
    77             if (interpreter.IntegerStack.Count == 0)
    78                 return;
     54      var value = interpreter.FloatStack.Pop() != 0.0;
    7955
    80             var value = interpreter.IntegerStack.Pop() != 0;
     56      interpreter.BooleanStack.Push(value);
     57    }
     58  }
    8159
    82             interpreter.BooleanStack.Push(value);
    83         }
     60  /// <summary>
     61  ///     Pushes FALSE if the top INTEGER is 0, or TRUE otherwise.
     62  /// </summary>
     63  public class BooleanFromIntegerExpression : StatelessExpression {
     64    protected override string InitStringRepresentation() {
     65      return "BOOLEAN.FROMINTEGER";
    8466    }
     67
     68    public override void Eval(IPushGpInterpreter interpreter) {
     69      if (interpreter.IntegerStack.Count == 0) return;
     70
     71      var value = interpreter.IntegerStack.Pop() != 0;
     72
     73      interpreter.BooleanStack.Push(value);
     74    }
     75  }
    8576}
Note: See TracChangeset for help on using the changeset viewer.