Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ShoveExpressions.cs @ 15820

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

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

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