Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/RotateExpressions.cs @ 17432

Last change on this file since 17432 was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

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