Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/DuplicateExpressions.cs @ 16003

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

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

File size: 8.0 KB
RevLine 
[15771]1using System.Collections.Generic;
2using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
3
4namespace HeuristicLab.Problems.ProgramSynthesis {
[14834]5
[14727]6  /// <summary>
[15032]7  /// Duplicates the top item on the T stack. Does not pop its argument
8  /// (which, if it did, would negate the effect of the duplication!).
[14727]9  /// </summary>
10  /// <typeparam name="T">Stacktype</typeparam>
[14952]11  [StorableClass]
[14727]12  public abstract class DuplicateExpression<T> : StatelessExpression {
[14952]13    protected DuplicateExpression() { }
14    [StorableConstructor]
15    protected DuplicateExpression(bool deserializing) : base(deserializing) { }
[14727]16
[14952]17    protected void Eval(IPushStack<T> stack) {
[14727]18      stack.Push(stack.Top);
19    }
20  }
21
[14952]22  [StorableClass]
[15032]23  [PushExpression(StackTypes.Integer, "INTEGER.DUP", "Duplicates the top item on the INTEGER stack.")]
[14727]24  public class IntegerDuplicateExpression : DuplicateExpression<long> {
[14952]25    public IntegerDuplicateExpression() { }
26    [StorableConstructor]
27    protected IntegerDuplicateExpression(bool deserializing) : base(deserializing) { }
28
29    public override bool IsNoop(IInternalPushInterpreter interpreter) {
30      return interpreter.IntegerStack.IsEmpty;
[14727]31    }
[14952]32
33    public override void Eval(IInternalPushInterpreter interpreter) {
34      Eval(interpreter.IntegerStack);
35    }
[14727]36  }
37
[14952]38  [StorableClass]
[15032]39  [PushExpression(StackTypes.Float, "FLOAT.DUP", "Duplicates the top item on the FLOAT stack.")]
[14727]40  public class FloatDuplicateExpression : DuplicateExpression<double> {
[14952]41    public FloatDuplicateExpression() { }
42    [StorableConstructor]
43    protected FloatDuplicateExpression(bool deserializing) : base(deserializing) { }
44
45    public override bool IsNoop(IInternalPushInterpreter interpreter) {
46      return interpreter.FloatStack.IsEmpty;
[14727]47    }
[14952]48
49    public override void Eval(IInternalPushInterpreter interpreter) {
50      Eval(interpreter.FloatStack);
51    }
[14727]52  }
53
[14952]54  [StorableClass]
[15032]55  [PushExpression(StackTypes.Boolean, "BOOLEAN.DUP", "Duplicates the top item on the BOOLEAN stack.")]
[14727]56  public class BooleanDuplicateExpression : DuplicateExpression<bool> {
[14952]57    public BooleanDuplicateExpression() { }
58    [StorableConstructor]
59    protected BooleanDuplicateExpression(bool deserializing) : base(deserializing) { }
60
61    public override bool IsNoop(IInternalPushInterpreter interpreter) {
62      return interpreter.BooleanStack.IsEmpty;
[14727]63    }
[14952]64
65    public override void Eval(IInternalPushInterpreter interpreter) {
66      Eval(interpreter.BooleanStack);
67    }
[14727]68  }
69
[14952]70  [StorableClass]
[15032]71  [PushExpression(StackTypes.Name, "NAME.DUP", "Duplicates the top item on the NAME stack.")]
[14727]72  public class NameDuplicateExpression : DuplicateExpression<string> {
[14952]73    public NameDuplicateExpression() { }
74    [StorableConstructor]
75    protected NameDuplicateExpression(bool deserializing) : base(deserializing) { }
76
77    public override bool IsNoop(IInternalPushInterpreter interpreter) {
78      return interpreter.NameStack.IsEmpty;
[14727]79    }
[14952]80
81    public override void Eval(IInternalPushInterpreter interpreter) {
82      Eval(interpreter.NameStack);
83    }
[14727]84  }
85
[14952]86  [StorableClass]
[15771]87  [PushExpression(StackTypes.Exec, "EXEC.DUP", "Duplicates the top item on the EXEC stack.", requiredBlockCount: 1)]
[14727]88  public class ExecDuplicateExpression : DuplicateExpression<Expression> {
[14952]89    public ExecDuplicateExpression() { }
90    [StorableConstructor]
91    protected ExecDuplicateExpression(bool deserializing) : base(deserializing) { }
92
93    public override bool IsNoop(IInternalPushInterpreter interpreter) {
94      return interpreter.ExecStack.IsEmpty;
[14727]95    }
[14952]96
97    public override void Eval(IInternalPushInterpreter interpreter) {
98      Eval(interpreter.ExecStack);
99    }
[14727]100  }
101
[14952]102  [StorableClass]
[15032]103  [PushExpression(StackTypes.Code, "CODE.DUP", "Duplicates the top item on the CODE stack.")]
[14727]104  public class CodeDuplicateExpression : DuplicateExpression<Expression> {
[14952]105    public CodeDuplicateExpression() { }
106    [StorableConstructor]
107    protected CodeDuplicateExpression(bool deserializing) : base(deserializing) { }
108
109    public override bool IsNoop(IInternalPushInterpreter interpreter) {
110      return interpreter.CodeStack.IsEmpty;
[14727]111    }
[14952]112
113    public override void Eval(IInternalPushInterpreter interpreter) {
114      Eval(interpreter.CodeStack);
115    }
[14727]116  }
[14834]117
[14952]118  [StorableClass]
[15032]119  [PushExpression(StackTypes.Char, "CHAR.DUP", "Duplicates the top item on the CHAR stack.")]
[15017]120  public class CharDuplicateExpression : DuplicateExpression<char> {
121    public CharDuplicateExpression() { }
122    [StorableConstructor]
123    protected CharDuplicateExpression(bool deserializing) : base(deserializing) { }
124
125    public override bool IsNoop(IInternalPushInterpreter interpreter) {
126      return interpreter.CharStack.IsEmpty;
127    }
128
129    public override void Eval(IInternalPushInterpreter interpreter) {
130      Eval(interpreter.CharStack);
131    }
132  }
133
134  [StorableClass]
[15032]135  [PushExpression(StackTypes.String, "STRING.DUP", "Duplicates the top item on the STRING stack.")]
[15017]136  public class StringDuplicateExpression : DuplicateExpression<string> {
137    public StringDuplicateExpression() { }
138    [StorableConstructor]
139    protected StringDuplicateExpression(bool deserializing) : base(deserializing) { }
140
141    public override bool IsNoop(IInternalPushInterpreter interpreter) {
142      return interpreter.StringStack.IsEmpty;
143    }
144
145    public override void Eval(IInternalPushInterpreter interpreter) {
146      Eval(interpreter.StringStack);
147    }
148  }
149
150  [StorableClass]
[15032]151  [PushExpression(StackTypes.IntegerVector, "INTEGER[].DUP", "Duplicates the top item on the INTEGER[] stack.")]
[15017]152  public class IntegerVectorDuplicateExpression : DuplicateExpression<IReadOnlyList<long>> {
[14952]153    public IntegerVectorDuplicateExpression() { }
154    [StorableConstructor]
155    protected IntegerVectorDuplicateExpression(bool deserializing) : base(deserializing) { }
156
157    public override bool IsNoop(IInternalPushInterpreter interpreter) {
158      return interpreter.IntegerVectorStack.IsEmpty;
[14834]159    }
[14952]160
161    public override void Eval(IInternalPushInterpreter interpreter) {
162      Eval(interpreter.IntegerVectorStack);
163    }
[14834]164  }
[14875]165
[14952]166  [StorableClass]
[15032]167  [PushExpression(StackTypes.FloatVector, "FLOAT[].DUP", "Duplicates the top item on the FLOAT[] stack.")]
[15017]168  public class FloatVectorDuplicateExpression : DuplicateExpression<IReadOnlyList<double>> {
[14952]169    public FloatVectorDuplicateExpression() { }
170    [StorableConstructor]
171    protected FloatVectorDuplicateExpression(bool deserializing) : base(deserializing) { }
172
173    public override bool IsNoop(IInternalPushInterpreter interpreter) {
174      return interpreter.FloatVectorStack.IsEmpty;
[14875]175    }
[14952]176
177    public override void Eval(IInternalPushInterpreter interpreter) {
178      Eval(interpreter.FloatVectorStack);
179    }
[14875]180  }
181
[14952]182  [StorableClass]
[15032]183  [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].DUP", "Duplicates the top item on the BOOLEAN[] stack.")]
[15017]184  public class BooleanVectorDuplicateExpression : DuplicateExpression<IReadOnlyList<bool>> {
[14952]185    public BooleanVectorDuplicateExpression() { }
186    [StorableConstructor]
187    protected BooleanVectorDuplicateExpression(bool deserializing) : base(deserializing) { }
188
189    public override bool IsNoop(IInternalPushInterpreter interpreter) {
190      return interpreter.BooleanVectorStack.IsEmpty;
[14875]191    }
[14952]192
193    public override void Eval(IInternalPushInterpreter interpreter) {
194      Eval(interpreter.BooleanVectorStack);
195    }
[14875]196  }
197
[14952]198  [StorableClass]
[15032]199  [PushExpression(StackTypes.StringVector, "STRING[].DUP", "Duplicates the top item on the STRING[] stack.")]
[15017]200  public class StringVectorDuplicateExpression : DuplicateExpression<IReadOnlyList<string>> {
[14952]201    public StringVectorDuplicateExpression() { }
202    [StorableConstructor]
203    protected StringVectorDuplicateExpression(bool deserializing) : base(deserializing) { }
204
205    public override bool IsNoop(IInternalPushInterpreter interpreter) {
206      return interpreter.StringVectorStack.IsEmpty;
[14875]207    }
[14952]208
209    public override void Eval(IInternalPushInterpreter interpreter) {
210      Eval(interpreter.StringVectorStack);
211    }
[14875]212  }
[14727]213}
Note: See TracBrowser for help on using the repository browser.