Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/FlushExpressions.cs @ 15032

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

#2665 Fixed bias 0 issue, PushExpressionFrequencyAnalyzer, Fixed probability for ERC settings, Fixed enable/disable instructions, Added expression descriptions

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