1 | using HeuristicLab.Algorithms.PushGP.Interpreter;
|
---|
2 |
|
---|
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 | }
|
---|
19 | }
|
---|
20 |
|
---|
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 | }
|
---|
30 |
|
---|
31 | public override void Eval(IInterpreter interpreter)
|
---|
32 | {
|
---|
33 | Eval(interpreter.BooleanStack, 2, values => values[0] || values[1]);
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
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"; }
|
---|
43 |
|
---|
44 | public override void Eval(IInterpreter interpreter)
|
---|
45 | {
|
---|
46 | Eval(interpreter.BooleanStack, 1, values => !values[0]);
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
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"; }
|
---|
56 |
|
---|
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 | }
|
---|
66 | }
|
---|
67 |
|
---|
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"; }
|
---|
74 |
|
---|
75 | public override void Eval(IInterpreter interpreter)
|
---|
76 | {
|
---|
77 | if (interpreter.IntegerStack.Count == 0)
|
---|
78 | return;
|
---|
79 |
|
---|
80 | var value = interpreter.IntegerStack.Pop() != 0;
|
---|
81 |
|
---|
82 | interpreter.BooleanStack.Push(value);
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|