Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

File size: 7.9 KB
RevLine 
[15771]1using System.Collections.Generic;
2using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
3
4namespace HeuristicLab.Problems.ProgramSynthesis {
[14952]5  [StorableClass]
[14727]6  public abstract class RotateExpression<T> : StatelessExpression {
[14952]7    protected RotateExpression() { }
8    [StorableConstructor]
9    protected RotateExpression(bool deserializing) : base(deserializing) { }
[14727]10
[14952]11    protected void Eval(IPushStack<T> stack) {
[14727]12      stack.Swap(3);
13    }
14  }
15
16
[15032]17  [PushExpression(
18    StackTypes.Integer,
19    "INTEGER.ROT",
20    "Rotates the top 3 items of the INTEGER stack clockwise.")]
[14952]21  [StorableClass]
[14727]22  public class IntegerRotateExpression : RotateExpression<long> {
[14952]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;
[14727]29    }
[14952]30
31    public override void Eval(IInternalPushInterpreter interpreter) {
32      Eval(interpreter.IntegerStack);
33    }
[14727]34  }
35
[15032]36  [PushExpression(
37    StackTypes.Float,
38    "FLOAT.ROT",
39    "Rotates the top 3 items of the FLOAT stack clockwise.")]
[14952]40  [StorableClass]
[14727]41  public class FloatRotateExpression : RotateExpression<double> {
[14952]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;
[14727]48    }
[14952]49
50    public override void Eval(IInternalPushInterpreter interpreter) {
51      Eval(interpreter.FloatStack);
52    }
[14727]53  }
54
[15032]55  [PushExpression(
56    StackTypes.Boolean,
57    "BOOLEAN.ROT",
58    "Rotates the top 3 items of the BOOLEAN stack clockwise.")]
[14952]59  [StorableClass]
[14727]60  public class BooleanRotateExpression : RotateExpression<bool> {
[14952]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;
[14727]67    }
[14952]68
69    public override void Eval(IInternalPushInterpreter interpreter) {
70      Eval(interpreter.BooleanStack);
71    }
[14727]72  }
73
[15032]74  [PushExpression(
75    StackTypes.Name,
76    "NAME.ROT",
77    "Rotates the top 3 items of the NAME stack clockwise.")]
[14952]78  [StorableClass]
[14727]79  public class NameRotateExpression : RotateExpression<string> {
[14952]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;
[14727]86    }
[14952]87
88    public override void Eval(IInternalPushInterpreter interpreter) {
89      Eval(interpreter.NameStack);
90    }
[14727]91  }
92
[15032]93  [PushExpression(
94    StackTypes.Exec,
95    "EXEC.ROT",
96    "Rotates the top 3 items of the EXEC stack clockwise.",
[15334]97    requiredBlockCount: 3)]
[14952]98  [StorableClass]
[14727]99  public class ExecRotateExpression : RotateExpression<Expression> {
[14952]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;
[14727]106    }
[14952]107
108    public override void Eval(IInternalPushInterpreter interpreter) {
109      Eval(interpreter.ExecStack);
110    }
[14727]111  }
112
[15032]113  [PushExpression(
114    StackTypes.Code,
115    "CODE.ROT",
116    "Rotates the top 3 items of the CODE stack clockwise.")]
[14952]117  [StorableClass]
[14727]118  public class CodeRotateExpression : RotateExpression<Expression> {
[14952]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;
[14727]125    }
[14952]126
127    public override void Eval(IInternalPushInterpreter interpreter) {
128      Eval(interpreter.CodeStack);
129    }
[14727]130  }
[14777]131
[15032]132  [PushExpression(
133    StackTypes.Char,
134    "CHAR.ROT",
135    "Rotates the top 3 items of the CHAR stack clockwise.")]
[14952]136  [StorableClass]
[14777]137  public class CharRotateExpression : RotateExpression<char> {
[14952]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;
[14777]144    }
[14952]145
146    public override void Eval(IInternalPushInterpreter interpreter) {
147      Eval(interpreter.CharStack);
148    }
[14777]149  }
150
[15032]151  [PushExpression(
152    StackTypes.String,
153    "STRING.ROT",
154    "Rotates the top 3 items of the STRING stack clockwise.")]
[14952]155  [StorableClass]
[14777]156  public class StringRotateExpression : RotateExpression<string> {
[14952]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;
[14777]163    }
[14952]164
165    public override void Eval(IInternalPushInterpreter interpreter) {
166      Eval(interpreter.StringStack);
167    }
[14777]168  }
[14834]169
[15032]170  [PushExpression(
171    StackTypes.IntegerVector,
172    "INTEGER[].ROT",
173    "Rotates the top 3 items of the INTEGER[] stack clockwise.")]
[14952]174  [StorableClass]
[15017]175  public class IntegerVectorRotateExpression : RotateExpression<IReadOnlyList<long>> {
[14952]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;
[14834]182    }
[14952]183
184    public override void Eval(IInternalPushInterpreter interpreter) {
185      Eval(interpreter.IntegerVectorStack);
186    }
[14834]187  }
[14875]188
[15032]189  [PushExpression(
190    StackTypes.FloatVector,
191    "FLOAT[].ROT",
192    "Rotates the top 3 items of the FLOAT[] stack clockwise.")]
[14952]193  [StorableClass]
[15017]194  public class FloatVectorRotateExpression : RotateExpression<IReadOnlyList<double>> {
[14952]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;
[14875]201    }
[14952]202
203    public override void Eval(IInternalPushInterpreter interpreter) {
204      Eval(interpreter.FloatVectorStack);
205    }
[14875]206  }
207
[15032]208  [PushExpression(
209    StackTypes.BooleanVector,
210    "BOOLEAN[].ROT",
211    "Rotates the top 3 items of the BOOLEAN[] stack clockwise.")]
[14952]212  [StorableClass]
[15017]213  public class BooleanVectorRotateExpression : RotateExpression<IReadOnlyList<bool>> {
[14952]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;
[14875]220    }
[14952]221
222    public override void Eval(IInternalPushInterpreter interpreter) {
223      Eval(interpreter.BooleanVectorStack);
224    }
[14875]225  }
226
[15032]227  [PushExpression(
228    StackTypes.StringVector,
229    "STRING[].ROT",
230    "Rotates the top 3 items of the STRING[] stack clockwise.")]
[14952]231  [StorableClass]
[15017]232  public class StringVectorRotateExpression : RotateExpression<IReadOnlyList<string>> {
[14952]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;
[14875]239    }
[14952]240
241    public override void Eval(IInternalPushInterpreter interpreter) {
242      Eval(interpreter.StringVectorStack);
243    }
[14875]244  }
[14727]245}
Note: See TracBrowser for help on using the repository browser.