1 | using System.Collections.Generic;
|
---|
2 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
3 |
|
---|
4 | namespace HeuristicLab.Problems.ProgramSynthesis { |
---|
5 | /// <summary>
|
---|
6 | /// Pushes a boolean of whether the top vector is empty.
|
---|
7 | /// </summary>
|
---|
8 | /// <typeparam name="T"></typeparam>
|
---|
9 | [StorableClass]
|
---|
10 | public abstract class VectorEmptyVectorExpression<T> : StatelessExpression {
|
---|
11 | protected VectorEmptyVectorExpression() { }
|
---|
12 | [StorableConstructor]
|
---|
13 | protected VectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
|
---|
14 |
|
---|
15 | protected bool IsNoop(IPushStack<IReadOnlyList<T>> vectorStack) {
|
---|
16 | return vectorStack.IsEmpty;
|
---|
17 | }
|
---|
18 |
|
---|
19 | protected void Eval(IInternalPushInterpreter interpreter, IPushStack<IReadOnlyList<T>> vectorStack) {
|
---|
20 | var vector = vectorStack.Pop();
|
---|
21 | interpreter.BooleanStack.Push(vector.Count == 0);
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | [StorableClass]
|
---|
26 | [PushExpression(
|
---|
27 | StackTypes.IntegerVector,
|
---|
28 | "INTEGER[].EMPTYVECTOR",
|
---|
29 | "Pushes a BOOLEAN of whether the top INTEGER[] is empty.",
|
---|
30 | StackTypes.Boolean)]
|
---|
31 | public class IntegerVectorEmptyVectorExpression : VectorEmptyVectorExpression<long> {
|
---|
32 | public IntegerVectorEmptyVectorExpression() { }
|
---|
33 | [StorableConstructor]
|
---|
34 | protected IntegerVectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
|
---|
35 |
|
---|
36 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
37 | return IsNoop(interpreter.IntegerVectorStack);
|
---|
38 | }
|
---|
39 |
|
---|
40 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
41 | Eval(interpreter, interpreter.IntegerVectorStack);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | [StorableClass]
|
---|
46 | [PushExpression(
|
---|
47 | StackTypes.FloatVector,
|
---|
48 | "FLOAT[].EMPTYVECTOR",
|
---|
49 | "Pushes a BOOLEAN of whether the top FLOAT[] is empty.",
|
---|
50 | StackTypes.Boolean)]
|
---|
51 | public class FloatVectorEmptyVectorExpression : VectorEmptyVectorExpression<double> {
|
---|
52 | public FloatVectorEmptyVectorExpression() { }
|
---|
53 | [StorableConstructor]
|
---|
54 | protected FloatVectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
|
---|
55 |
|
---|
56 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
57 | return IsNoop(interpreter.FloatVectorStack);
|
---|
58 | }
|
---|
59 |
|
---|
60 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
61 | Eval(interpreter, interpreter.FloatVectorStack);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | [StorableClass]
|
---|
66 | [PushExpression(
|
---|
67 | StackTypes.BooleanVector,
|
---|
68 | "BOOLEAN[].EMPTYVECTOR",
|
---|
69 | "Pushes a BOOLEAN of whether the top BOOLEAN[] is empty.",
|
---|
70 | StackTypes.Boolean)]
|
---|
71 | public class BooleanVectorEmptyVectorExpression : VectorEmptyVectorExpression<bool> {
|
---|
72 | public BooleanVectorEmptyVectorExpression() { }
|
---|
73 | [StorableConstructor]
|
---|
74 | protected BooleanVectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
|
---|
75 |
|
---|
76 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
77 | return IsNoop(interpreter.BooleanVectorStack);
|
---|
78 | }
|
---|
79 |
|
---|
80 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
81 | Eval(interpreter, interpreter.BooleanVectorStack);
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | [StorableClass]
|
---|
86 | [PushExpression(
|
---|
87 | StackTypes.StringVector,
|
---|
88 | "STRING[].EMPTYVECTOR",
|
---|
89 | "Pushes a BOOLEAN of whether the top STRING[] is empty.",
|
---|
90 | StackTypes.Boolean)]
|
---|
91 | public class StringVectorEmptyVectorExpression : VectorEmptyVectorExpression<string> {
|
---|
92 | public StringVectorEmptyVectorExpression() { }
|
---|
93 | [StorableConstructor]
|
---|
94 | protected StringVectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
|
---|
95 |
|
---|
96 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
97 | return IsNoop(interpreter.StringVectorStack);
|
---|
98 | }
|
---|
99 |
|
---|
100 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
101 | Eval(interpreter, interpreter.StringVectorStack);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|