Changeset 14513 for branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/SwapExpressions.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/SwapExpressions.cs
r14398 r14513 1 using HeuristicLab.Algorithms.PushGP.Interpreter; 2 using HeuristicLab.Algorithms.PushGP.Stack; 1 namespace HeuristicLab.Algorithms.PushGP.Expressions 2 { 3 using HeuristicLab.Algorithms.PushGP.Interpreter; 4 using HeuristicLab.Algorithms.PushGP.Stack; 3 5 4 namespace HeuristicLab.Algorithms.PushGP.Expressions 5 { 6 /// <summary>7 /// Swaps the top two values.8 /// </summary>9 /// <typeparam name="T">Stacktype</typeparam>10 public abstract class SwapExpression<T> : StatelessExpression6 /// <summary> 7 /// Swaps the top two values. 8 /// </summary> 9 /// <typeparam name="T">Stacktype</typeparam> 10 public abstract class SwapExpression<T> : StatelessExpression 11 { 12 public void Eval(IStack<T> stack) 11 13 { 12 public void Eval(IStack<T> stack) 13 { 14 if (stack.Count < 2) 15 return; 14 if (stack.Count < 2) return; 16 15 17 stack.Swap(2); 18 } 16 stack.Swap(2); 17 } 18 } 19 20 public class IntegerSwapExpression : SwapExpression<long> 21 { 22 protected override string InitStringRepresentation() 23 { 24 return "INTEGER.SWAP"; 19 25 } 20 26 21 public class IntegerSwapExpression : SwapExpression<long>27 public override void Eval(IPushGpInterpreter interpreter) 22 28 { 23 protected override string InitStringRepresentation() { return "INTEGER.SWAP"; } 29 this.Eval(interpreter.IntegerStack); 30 } 31 } 24 32 25 public override void Eval(IInterpreter interpreter) 26 { 27 Eval(interpreter.IntegerStack); 28 } 33 public class FloatSwapExpression : SwapExpression<double> 34 { 35 protected override string InitStringRepresentation() 36 { 37 return "FLOAT.SWAP"; 29 38 } 30 39 31 public class FloatSwapExpression : SwapExpression<double>40 public override void Eval(IPushGpInterpreter interpreter) 32 41 { 33 protected override string InitStringRepresentation() { return "FLOAT.SWAP"; } 42 this.Eval(interpreter.FloatStack); 43 } 44 } 34 45 35 public override void Eval(IInterpreter interpreter) 36 { 37 Eval(interpreter.FloatStack); 38 } 46 public class BooleanSwapExpression : SwapExpression<bool> 47 { 48 protected override string InitStringRepresentation() 49 { 50 return "BOOLEAN.SWAP"; 39 51 } 40 52 41 public class BooleanSwapExpression : SwapExpression<bool>53 public override void Eval(IPushGpInterpreter interpreter) 42 54 { 43 protected override string InitStringRepresentation() { return "BOOLEAN.SWAP"; } 55 this.Eval(interpreter.BooleanStack); 56 } 57 } 44 58 45 public override void Eval(IInterpreter interpreter) 46 { 47 Eval(interpreter.BooleanStack); 48 } 59 public class NameSwapExpression : SwapExpression<string> 60 { 61 protected override string InitStringRepresentation() 62 { 63 return "NAME.SWAP"; 49 64 } 50 65 51 public class NameSwapExpression : SwapExpression<string>66 public override void Eval(IPushGpInterpreter interpreter) 52 67 { 53 protected override string InitStringRepresentation() { return "NAME.SWAP"; } 68 this.Eval(interpreter.NameStack); 69 } 70 } 54 71 55 public override void Eval(IInterpreter interpreter) 56 { 57 Eval(interpreter.NameStack); 58 } 72 public class ExecSwapExpression : SwapExpression<Expression> 73 { 74 protected override string InitStringRepresentation() 75 { 76 return "EXEC.SWAP"; 59 77 } 60 78 61 public class ExecSwapExpression : SwapExpression<Expression>79 public override void Eval(IPushGpInterpreter interpreter) 62 80 { 63 protected override string InitStringRepresentation() { return "EXEC.SWAP"; } 81 this.Eval(interpreter.ExecStack); 82 } 83 } 64 84 65 public override void Eval(IInterpreter interpreter) 66 { 67 Eval(interpreter.ExecStack); 68 } 85 public class CodeSwapExpression : SwapExpression<Expression> 86 { 87 protected override string InitStringRepresentation() 88 { 89 return "CODE.SWAP"; 69 90 } 70 91 71 public class CodeSwapExpression : SwapExpression<Expression>92 public override void Eval(IPushGpInterpreter interpreter) 72 93 { 73 protected override string InitStringRepresentation() { return "CODE.SWAP"; } 74 75 public override void Eval(IInterpreter interpreter) 76 { 77 Eval(interpreter.CodeStack); 78 } 94 this.Eval(interpreter.CodeStack); 79 95 } 96 } 80 97 }
Note: See TracChangeset
for help on using the changeset viewer.