Changeset 14513 for branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/BooleanExpressions.cs
- Timestamp:
- 12/20/16 22:57:11 (7 years ago)
- 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; 1 namespace HeuristicLab.Algorithms.PushGP.Expressions { 2 using HeuristicLab.Algorithms.PushGP.Interpreter; 2 3 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"; 19 10 } 20 11 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 } 30 16 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"; 35 23 } 36 24 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 } 43 29 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"; 48 36 } 49 37 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 } 56 42 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"; 66 49 } 67 50 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; 74 53 75 public override void Eval(IInterpreter interpreter) 76 { 77 if (interpreter.IntegerStack.Count == 0) 78 return; 54 var value = interpreter.FloatStack.Pop() != 0.0; 79 55 80 var value = interpreter.IntegerStack.Pop() != 0; 56 interpreter.BooleanStack.Push(value); 57 } 58 } 81 59 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"; 84 66 } 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 } 85 76 }
Note: See TracChangeset
for help on using the changeset viewer.