Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/BooleanExpressions.cs @ 14744

Last change on this file since 14744 was 14744, checked in by pkimmesw, 7 years ago

#2665 Renamings due to typos, ManagedPool tests, Skip Noops in Debugger

File size: 2.3 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
3  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
4  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
5
6  /// <summary>
7  ///     Pushes the logical AND of the top two BOOLEANs.
8  /// </summary>
9  [PushExpression(StackType.Boolean, "BOOLEAN.AND")]
10  public class BooleanAndExpression : PushResultExpression<bool> {
11    public override bool Eval(IPushInterpreter interpreter) {
12      return Eval(interpreter.BooleanStack, 2, values => values[0] && values[1]);
13    }
14  }
15
16  /// <summary>
17  ///     Pushes the logical OR of the top two BOOLEANs.
18  /// </summary>
19  [PushExpression(StackType.Boolean, "BOOLEAN.OR")]
20  public class BooleanOrExpression : PushResultExpression<bool> {
21    public override bool Eval(IPushInterpreter interpreter) {
22      return Eval(interpreter.BooleanStack, 2, values => values[0] || values[1]);
23    }
24  }
25
26  /// <summary>
27  ///     Pushes the logical NOT of the top BOOLEAN.
28  /// </summary>
29  [PushExpression(StackType.Boolean, "BOOLEAN.NOT")]
30  public class BooleanNotExpression : PushResultExpression<bool> {
31    public override bool Eval(IPushInterpreter interpreter) {
32      return Eval(interpreter.BooleanStack, 1, values => !values[0]);
33    }
34  }
35
36  /// <summary>
37  ///     Pushes FALSE if the top FLOAT is 0.0, or TRUE otherwise.
38  /// </summary>
39  [PushExpression(StackType.Boolean, "BOOLEAN.FROMFLOAT")]
40  public class BooleanFromFloatExpression : StatelessExpression {
41    public override bool Eval(IPushInterpreter interpreter) {
42      if (interpreter.FloatStack.Count == 0) return false;
43
44      var value = interpreter.FloatStack.Pop() != 0.0;
45
46      interpreter.BooleanStack.Push(value);
47      return true;
48    }
49  }
50
51  /// <summary>
52  ///     Pushes FALSE if the top INTEGER is 0, or TRUE otherwise.
53  /// </summary>
54  [PushExpression(StackType.Boolean, "BOOLEAN.FROMINTEGER")]
55  public class BooleanFromIntegerExpression : StatelessExpression {
56    public override bool Eval(IPushInterpreter interpreter) {
57      if (interpreter.IntegerStack.Count == 0) return false;
58
59      var value = interpreter.IntegerStack.Pop() != 0;
60
61      interpreter.BooleanStack.Push(value);
62      return true;
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.