Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/FlushExpressions.cs @ 18242

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

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

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