Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/RotateExpressions.cs @ 16958

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

#2665 Testet Problems, Testet error functions, Small fixes, Created HL files

File size: 8.1 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using System.Collections.Generic;
3
4  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
5  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
6
7  using Interpreter;
8  using Stack;
9
10  [StorableClass]
11  public abstract class RotateExpression<T> : StatelessExpression {
12    protected RotateExpression() { }
13    [StorableConstructor]
14    protected RotateExpression(bool deserializing) : base(deserializing) { }
15
16    protected void Eval(IPushStack<T> stack) {
17      stack.Swap(3);
18    }
19  }
20
21
22  [PushExpression(
23    StackTypes.Integer,
24    "INTEGER.ROT",
25    "Rotates the top 3 items of the INTEGER stack clockwise.")]
26  [StorableClass]
27  public class IntegerRotateExpression : RotateExpression<long> {
28    public IntegerRotateExpression() { }
29    [StorableConstructor]
30    protected IntegerRotateExpression(bool deserializing) : base(deserializing) { }
31
32    public override bool IsNoop(IInternalPushInterpreter interpreter) {
33      return interpreter.IntegerStack.Count < 3;
34    }
35
36    public override void Eval(IInternalPushInterpreter interpreter) {
37      Eval(interpreter.IntegerStack);
38    }
39  }
40
41  [PushExpression(
42    StackTypes.Float,
43    "FLOAT.ROT",
44    "Rotates the top 3 items of the FLOAT stack clockwise.")]
45  [StorableClass]
46  public class FloatRotateExpression : RotateExpression<double> {
47    public FloatRotateExpression() { }
48    [StorableConstructor]
49    protected FloatRotateExpression(bool deserializing) : base(deserializing) { }
50
51    public override bool IsNoop(IInternalPushInterpreter interpreter) {
52      return interpreter.FloatStack.Count < 3;
53    }
54
55    public override void Eval(IInternalPushInterpreter interpreter) {
56      Eval(interpreter.FloatStack);
57    }
58  }
59
60  [PushExpression(
61    StackTypes.Boolean,
62    "BOOLEAN.ROT",
63    "Rotates the top 3 items of the BOOLEAN stack clockwise.")]
64  [StorableClass]
65  public class BooleanRotateExpression : RotateExpression<bool> {
66    public BooleanRotateExpression() { }
67    [StorableConstructor]
68    protected BooleanRotateExpression(bool deserializing) : base(deserializing) { }
69
70    public override bool IsNoop(IInternalPushInterpreter interpreter) {
71      return interpreter.BooleanStack.Count < 3;
72    }
73
74    public override void Eval(IInternalPushInterpreter interpreter) {
75      Eval(interpreter.BooleanStack);
76    }
77  }
78
79  [PushExpression(
80    StackTypes.Name,
81    "NAME.ROT",
82    "Rotates the top 3 items of the NAME stack clockwise.")]
83  [StorableClass]
84  public class NameRotateExpression : RotateExpression<string> {
85    public NameRotateExpression() { }
86    [StorableConstructor]
87    protected NameRotateExpression(bool deserializing) : base(deserializing) { }
88
89    public override bool IsNoop(IInternalPushInterpreter interpreter) {
90      return interpreter.NameStack.Count < 3;
91    }
92
93    public override void Eval(IInternalPushInterpreter interpreter) {
94      Eval(interpreter.NameStack);
95    }
96  }
97
98  [PushExpression(
99    StackTypes.Exec,
100    "EXEC.ROT",
101    "Rotates the top 3 items of the EXEC stack clockwise.",
102    requiredBlockCount: 3)]
103  [StorableClass]
104  public class ExecRotateExpression : RotateExpression<Expression> {
105    public ExecRotateExpression() { }
106    [StorableConstructor]
107    protected ExecRotateExpression(bool deserializing) : base(deserializing) { }
108
109    public override bool IsNoop(IInternalPushInterpreter interpreter) {
110      return interpreter.ExecStack.Count < 3;
111    }
112
113    public override void Eval(IInternalPushInterpreter interpreter) {
114      Eval(interpreter.ExecStack);
115    }
116  }
117
118  [PushExpression(
119    StackTypes.Code,
120    "CODE.ROT",
121    "Rotates the top 3 items of the CODE stack clockwise.")]
122  [StorableClass]
123  public class CodeRotateExpression : RotateExpression<Expression> {
124    public CodeRotateExpression() { }
125    [StorableConstructor]
126    protected CodeRotateExpression(bool deserializing) : base(deserializing) { }
127
128    public override bool IsNoop(IInternalPushInterpreter interpreter) {
129      return interpreter.CodeStack.Count < 3;
130    }
131
132    public override void Eval(IInternalPushInterpreter interpreter) {
133      Eval(interpreter.CodeStack);
134    }
135  }
136
137  [PushExpression(
138    StackTypes.Char,
139    "CHAR.ROT",
140    "Rotates the top 3 items of the CHAR stack clockwise.")]
141  [StorableClass]
142  public class CharRotateExpression : RotateExpression<char> {
143    public CharRotateExpression() { }
144    [StorableConstructor]
145    protected CharRotateExpression(bool deserializing) : base(deserializing) { }
146
147    public override bool IsNoop(IInternalPushInterpreter interpreter) {
148      return interpreter.CharStack.Count < 3;
149    }
150
151    public override void Eval(IInternalPushInterpreter interpreter) {
152      Eval(interpreter.CharStack);
153    }
154  }
155
156  [PushExpression(
157    StackTypes.String,
158    "STRING.ROT",
159    "Rotates the top 3 items of the STRING stack clockwise.")]
160  [StorableClass]
161  public class StringRotateExpression : RotateExpression<string> {
162    public StringRotateExpression() { }
163    [StorableConstructor]
164    protected StringRotateExpression(bool deserializing) : base(deserializing) { }
165
166    public override bool IsNoop(IInternalPushInterpreter interpreter) {
167      return interpreter.StringStack.Count < 3;
168    }
169
170    public override void Eval(IInternalPushInterpreter interpreter) {
171      Eval(interpreter.StringStack);
172    }
173  }
174
175  [PushExpression(
176    StackTypes.IntegerVector,
177    "INTEGER[].ROT",
178    "Rotates the top 3 items of the INTEGER[] stack clockwise.")]
179  [StorableClass]
180  public class IntegerVectorRotateExpression : RotateExpression<IReadOnlyList<long>> {
181    public IntegerVectorRotateExpression() { }
182    [StorableConstructor]
183    protected IntegerVectorRotateExpression(bool deserializing) : base(deserializing) { }
184
185    public override bool IsNoop(IInternalPushInterpreter interpreter) {
186      return interpreter.IntegerVectorStack.Count < 3;
187    }
188
189    public override void Eval(IInternalPushInterpreter interpreter) {
190      Eval(interpreter.IntegerVectorStack);
191    }
192  }
193
194  [PushExpression(
195    StackTypes.FloatVector,
196    "FLOAT[].ROT",
197    "Rotates the top 3 items of the FLOAT[] stack clockwise.")]
198  [StorableClass]
199  public class FloatVectorRotateExpression : RotateExpression<IReadOnlyList<double>> {
200    public FloatVectorRotateExpression() { }
201    [StorableConstructor]
202    protected FloatVectorRotateExpression(bool deserializing) : base(deserializing) { }
203
204    public override bool IsNoop(IInternalPushInterpreter interpreter) {
205      return interpreter.FloatVectorStack.Count < 3;
206    }
207
208    public override void Eval(IInternalPushInterpreter interpreter) {
209      Eval(interpreter.FloatVectorStack);
210    }
211  }
212
213  [PushExpression(
214    StackTypes.BooleanVector,
215    "BOOLEAN[].ROT",
216    "Rotates the top 3 items of the BOOLEAN[] stack clockwise.")]
217  [StorableClass]
218  public class BooleanVectorRotateExpression : RotateExpression<IReadOnlyList<bool>> {
219    public BooleanVectorRotateExpression() { }
220    [StorableConstructor]
221    protected BooleanVectorRotateExpression(bool deserializing) : base(deserializing) { }
222
223    public override bool IsNoop(IInternalPushInterpreter interpreter) {
224      return interpreter.BooleanVectorStack.Count < 3;
225    }
226
227    public override void Eval(IInternalPushInterpreter interpreter) {
228      Eval(interpreter.BooleanVectorStack);
229    }
230  }
231
232  [PushExpression(
233    StackTypes.StringVector,
234    "STRING[].ROT",
235    "Rotates the top 3 items of the STRING[] stack clockwise.")]
236  [StorableClass]
237  public class StringVectorRotateExpression : RotateExpression<IReadOnlyList<string>> {
238    public StringVectorRotateExpression() { }
239    [StorableConstructor]
240    protected StringVectorRotateExpression(bool deserializing) : base(deserializing) { }
241
242    public override bool IsNoop(IInternalPushInterpreter interpreter) {
243      return interpreter.StringVectorStack.Count < 3;
244    }
245
246    public override void Eval(IInternalPushInterpreter interpreter) {
247      Eval(interpreter.StringVectorStack);
248    }
249  }
250}
Note: See TracBrowser for help on using the repository browser.