Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 Storable problem data, Renamings due to typos, Removed GP from class names

File size: 2.2 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 void Eval(IPushInterpreter interpreter) {
12      this.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 void Eval(IPushInterpreter interpreter) {
22      this.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 void Eval(IPushInterpreter interpreter) {
32      this.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 void Eval(IPushInterpreter interpreter) {
42      if (interpreter.FloatStack.Count == 0) return;
43
44      var value = interpreter.FloatStack.Pop() != 0.0;
45
46      interpreter.BooleanStack.Push(value);
47    }
48  }
49
50  /// <summary>
51  ///     Pushes FALSE if the top INTEGER is 0, or TRUE otherwise.
52  /// </summary>
53  [PushExpression(StackType.Boolean, "BOOLEAN.FROMINTEGER")]
54  public class BooleanFromIntegerExpression : StatelessExpression {
55    public override void Eval(IPushInterpreter interpreter) {
56      if (interpreter.IntegerStack.Count == 0) return;
57
58      var value = interpreter.IntegerStack.Pop() != 0;
59
60      interpreter.BooleanStack.Push(value);
61    }
62  }
63}
Note: See TracBrowser for help on using the repository browser.