Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/EmptyExpression.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: 6.9 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  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
7
8  using Stack;
9
10  /// <summary>
11  /// Tells whether that stack is empty.
12  /// </summary>
13  [StorableClass]
14  public abstract class EmptyExpression<T> : StatelessExpression {
15    protected EmptyExpression() { }
16    [StorableConstructor]
17    protected EmptyExpression(bool deserializing) : base(deserializing) { }
18
19    public override bool IsNoop(IInternalPushInterpreter interpreter) {
20      return false;
21    }
22
23    public void Eval(IPushStack<T> stack, IPushStack<bool> booleanStack) {
24      booleanStack.Push(stack.IsEmpty);
25    }
26  }
27
28  [StorableClass]
29  [PushExpression(
30    StackTypes.Exec,
31    "EXEC.EMPTY",
32    "Pushes TRUE onto the BOOLEAN stack if the EXEC stack is empty, otherwise FALSE.",
33    StackTypes.Boolean)]
34  public class ExecEmptyExpression : EmptyExpression<Expression> {
35    public ExecEmptyExpression() { }
36    [StorableConstructor]
37    protected ExecEmptyExpression(bool deserializing) : base(deserializing) { }
38
39    public override void Eval(IInternalPushInterpreter interpreter) {
40      Eval(interpreter.ExecStack, interpreter.BooleanStack);
41    }
42  }
43
44  [StorableClass]
45  [PushExpression(
46    StackTypes.Code,
47    "CODE.EMPTY",
48    "Pushes TRUE onto the BOOLEAN stack if the CODE stack is empty, otherwise FALSE.",
49    StackTypes.Boolean)]
50  public class CodeEmptyExpression : EmptyExpression<Expression> {
51    public CodeEmptyExpression() { }
52    [StorableConstructor]
53    protected CodeEmptyExpression(bool deserializing) : base(deserializing) { }
54    public override void Eval(IInternalPushInterpreter interpreter) {
55      Eval(interpreter.CodeStack, interpreter.BooleanStack);
56    }
57  }
58
59  [StorableClass]
60  [PushExpression(
61    StackTypes.Integer,
62    "INTEGER.EMPTY",
63    "Pushes TRUE onto the BOOLEAN stack if the INTEGER stack is empty, otherwise FALSE.",
64    StackTypes.Boolean)]
65  public class IntegerEmptyExpression : EmptyExpression<long> {
66    public IntegerEmptyExpression() { }
67    [StorableConstructor]
68    protected IntegerEmptyExpression(bool deserializing) : base(deserializing) { }
69    public override void Eval(IInternalPushInterpreter interpreter) {
70      Eval(interpreter.IntegerStack, interpreter.BooleanStack);
71    }
72  }
73
74  [PushExpression(
75    StackTypes.Float,
76    "FLOAT.EMPTY", "Pushes TRUE onto the BOOLEAN stack if the FLOAT stack is empty, otherwise FALSE.",
77    StackTypes.Boolean)]
78  public class FloatEmptyExpression : EmptyExpression<double> {
79    public FloatEmptyExpression() { }
80    [StorableConstructor]
81    protected FloatEmptyExpression(bool deserializing) : base(deserializing) { }
82    public override void Eval(IInternalPushInterpreter interpreter) {
83      Eval(interpreter.FloatStack, interpreter.BooleanStack);
84    }
85  }
86
87  [PushExpression(
88    StackTypes.Boolean,
89    "BOOLEAN.EMPTY",
90    "Pushes TRUE onto the BOOLEAN stack if the BOOLEAN stack is empty, otherwise FALSE.",
91    StackTypes.Boolean)]
92  public class BooleanEmptyExpression : EmptyExpression<bool> {
93    public BooleanEmptyExpression() { }
94    [StorableConstructor]
95    protected BooleanEmptyExpression(bool deserializing) : base(deserializing) { }
96    public override void Eval(IInternalPushInterpreter interpreter) {
97      Eval(interpreter.BooleanStack, interpreter.BooleanStack);
98    }
99  }
100
101  [PushExpression(
102    StackTypes.Char,
103    "CHAR.EMPTY",
104    "Pushes TRUE onto the BOOLEAN stack if the CHAR stack is empty, otherwise FALSE.",
105    StackTypes.Boolean)]
106  public class CharEmptyExpression : EmptyExpression<char> {
107    public CharEmptyExpression() { }
108    [StorableConstructor]
109    protected CharEmptyExpression(bool deserializing) : base(deserializing) { }
110    public override void Eval(IInternalPushInterpreter interpreter) {
111      Eval(interpreter.CharStack, interpreter.BooleanStack);
112    }
113  }
114
115  [PushExpression(
116    StackTypes.String,
117    "STRING.EMPTY",
118    "Pushes TRUE onto the BOOLEAN stack if the STRING stack is empty, otherwise FALSE.",
119    StackTypes.Boolean)]
120  public class StringEmptyExpression : EmptyExpression<string> {
121    public StringEmptyExpression() { }
122    [StorableConstructor]
123    protected StringEmptyExpression(bool deserializing) : base(deserializing) { }
124    public override void Eval(IInternalPushInterpreter interpreter) {
125      Eval(interpreter.StringStack, interpreter.BooleanStack);
126    }
127  }
128
129  [PushExpression(
130    StackTypes.IntegerVector,
131    "INTEGER[].EMPTY",
132    "Pushes TRUE onto the BOOLEAN stack if the INTEGER[] stack is empty, otherwise FALSE.",
133    StackTypes.Boolean)]
134  public class IntegerVectorEmptyExpression : EmptyExpression<IReadOnlyList<long>> {
135    public IntegerVectorEmptyExpression() { }
136    [StorableConstructor]
137    protected IntegerVectorEmptyExpression(bool deserializing) : base(deserializing) { }
138    public override void Eval(IInternalPushInterpreter interpreter) {
139      Eval(interpreter.IntegerVectorStack, interpreter.BooleanStack);
140    }
141  }
142
143  [PushExpression(
144    StackTypes.FloatVector,
145    "FLOAT[].EMPTY",
146    "Pushes TRUE onto the BOOLEAN stack if the FLOAT[] stack is empty, otherwise FALSE.",
147    StackTypes.Boolean)]
148  public class FloatVectorEmptyExpression : EmptyExpression<IReadOnlyList<double>> {
149    public FloatVectorEmptyExpression() { }
150    [StorableConstructor]
151    protected FloatVectorEmptyExpression(bool deserializing) : base(deserializing) { }
152    public override void Eval(IInternalPushInterpreter interpreter) {
153      Eval(interpreter.FloatVectorStack, interpreter.BooleanStack);
154    }
155  }
156
157  [PushExpression(
158    StackTypes.BooleanVector,
159    "BOOLEAN[].EMPTY",
160    "Pushes TRUE onto the BOOLEAN stack if the BOOLEAN[] stack is empty, otherwise FALSE.",
161    StackTypes.Boolean)]
162  public class BooleanVectorEmptyExpression : EmptyExpression<IReadOnlyList<bool>> {
163    public BooleanVectorEmptyExpression() { }
164    [StorableConstructor]
165    protected BooleanVectorEmptyExpression(bool deserializing) : base(deserializing) { }
166    public override void Eval(IInternalPushInterpreter interpreter) {
167      Eval(interpreter.BooleanVectorStack, interpreter.BooleanStack);
168    }
169  }
170
171  [PushExpression(
172    StackTypes.StringVector,
173    "STRING[].EMPTY",
174    "Pushes TRUE onto the BOOLEAN stack if the STRING[] stack is empty, otherwise FALSE.",
175    StackTypes.Boolean)]
176  public class StringVectorEmptyExpression : EmptyExpression<IReadOnlyList<string>> {
177    public StringVectorEmptyExpression() { }
178    [StorableConstructor]
179    protected StringVectorEmptyExpression(bool deserializing) : base(deserializing) { }
180    public override void Eval(IInternalPushInterpreter interpreter) {
181      Eval(interpreter.StringVectorStack, interpreter.BooleanStack);
182    }
183  }
184}
Note: See TracBrowser for help on using the repository browser.