Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/SwapExpressions.cs @ 14875

Last change on this file since 14875 was 14875, checked in by pkimmesw, 8 years ago

#2665 BenchmarkSuite, all examples, partially tested, VectorExpressions added

File size: 3.5 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using System.Collections.Generic;
3
4  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
5
6  using Interpreter;
7  using Stack;
8
9  /// <summary>
10  ///     Swaps the top two values.
11  /// </summary>
12  /// <typeparam name="T">Stacktype</typeparam>
13  public abstract class SwapExpression<T> : StatelessExpression {
14    public bool Eval(IPushStack<T> stack) {
15      if (stack.Count < 2)
16        return false;
17
18      stack.Swap(2);
19      return true;
20    }
21  }
22
23  [PushExpression(StackTypes.Integer, "INTEGER.SWAP")]
24  public class IntegerSwapExpression : SwapExpression<long> {
25    public override bool Eval(IInternalPushInterpreter interpreter) {
26      return Eval(interpreter.IntegerStack);
27    }
28  }
29
30  [PushExpression(StackTypes.Float, "FLOAT.SWAP")]
31  public class FloatSwapExpression : SwapExpression<double> {
32    public override bool Eval(IInternalPushInterpreter interpreter) {
33      return Eval(interpreter.FloatStack);
34    }
35  }
36
37  [PushExpression(StackTypes.Boolean, "BOOLEAN.SWAP")]
38  public class BooleanSwapExpression : SwapExpression<bool> {
39    public override bool Eval(IInternalPushInterpreter interpreter) {
40      return Eval(interpreter.BooleanStack);
41    }
42  }
43
44  [PushExpression(StackTypes.Name, "NAME.SWAP")]
45  public class NameSwapExpression : SwapExpression<string> {
46    public override bool Eval(IInternalPushInterpreter interpreter) {
47      return Eval(interpreter.NameStack);
48    }
49  }
50
51  [PushExpression(StackTypes.Exec, "EXEC.SWAP")]
52  public class ExecSwapExpression : SwapExpression<Expression> {
53    public override bool Eval(IInternalPushInterpreter interpreter) {
54      return Eval(interpreter.ExecStack);
55    }
56  }
57
58  [PushExpression(StackTypes.Code, "CODE.SWAP")]
59  public class CodeSwapExpression : SwapExpression<Expression> {
60    public override bool Eval(IInternalPushInterpreter interpreter) {
61      return Eval(interpreter.CodeStack);
62    }
63  }
64
65  [PushExpression(StackTypes.Char, "CHAR.SWAP")]
66  public class CharSwapExpression : SwapExpression<char> {
67    public override bool Eval(IInternalPushInterpreter interpreter) {
68      return Eval(interpreter.CharStack);
69    }
70  }
71
72  [PushExpression(StackTypes.String, "STRING.SWAP")]
73  public class StringSwapExpression : SwapExpression<string> {
74    public override bool Eval(IInternalPushInterpreter interpreter) {
75      return Eval(interpreter.StringStack);
76    }
77  }
78
79  [PushExpression(StackTypes.IntegerVector, "INTEGER[].SWAP")]
80  public class IntegerVectorSwapExpression : SwapExpression<List<long>> {
81    public override bool Eval(IInternalPushInterpreter interpreter) {
82      return Eval(interpreter.IntegerVectorStack);
83    }
84  }
85
86  [PushExpression(StackTypes.FloatVector, "FLOAT[].SWAP")]
87  public class FloatVectorSwapExpression : SwapExpression<List<double>> {
88    public override bool Eval(IInternalPushInterpreter interpreter) {
89      return Eval(interpreter.FloatVectorStack);
90    }
91  }
92
93  [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].SWAP")]
94  public class BooleanVectorSwapExpression : SwapExpression<List<bool>> {
95    public override bool Eval(IInternalPushInterpreter interpreter) {
96      return Eval(interpreter.BooleanVectorStack);
97    }
98  }
99
100  [PushExpression(StackTypes.StringVector, "STRING[].SWAP")]
101  public class StringVectorSwapExpression : SwapExpression<List<string>> {
102    public override bool Eval(IInternalPushInterpreter interpreter) {
103      return Eval(interpreter.StringVectorStack);
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.