Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StackdepthExpressions.cs @ 16958

Last change on this file since 16958 was 15032, checked in by pkimmesw, 8 years ago

#2665 Fixed bias 0 issue, PushExpressionFrequencyAnalyzer, Fixed probability for ERC settings, Fixed enable/disable instructions, Added expression descriptions

File size: 7.7 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
7  using Interpreter;
8  using Stack;
9
10  /// <summary>
11  ///     Pushes the stack depth onto the INTEGER stack (thereby increasing it!).
12  /// </summary>
13  /// <typeparam name="T">Stacktype</typeparam>
14  [StorableClass]
15  public abstract class StackdepthExpression<T> : StatelessExpression {
16    protected StackdepthExpression() { }
17    [StorableConstructor]
18    protected StackdepthExpression(bool deserializing) : base(deserializing) { }
19
20    public override bool IsNoop(IInternalPushInterpreter interpreter) {
21      return false;
22    }
23
24    protected void Eval(IPushStack<T> stack, IPushStack<long> integerStack, bool incremental = false) {
25      var count = stack.Count;
26      if (incremental) count += 1;
27      integerStack.Push(count);
28    }
29  }
30
31  [StorableClass]
32  [PushExpression(
33    StackTypes.Integer,
34    "INTEGER.STACKDEPTH",
35    "Pushes the stack depth onto the INTEGER stack.")]
36  public class IntegerStackdepthExpression : StackdepthExpression<long> {
37    public IntegerStackdepthExpression() { }
38    [StorableConstructor]
39    protected IntegerStackdepthExpression(bool deserializing) : base(deserializing) { }
40
41    public override void Eval(IInternalPushInterpreter interpreter) {
42      Eval(interpreter.IntegerStack, interpreter.IntegerStack, true);
43    }
44  }
45
46  [StorableClass]
47  [PushExpression(
48    StackTypes.Float,
49    "FLOAT.STACKDEPTH",
50    "Pushes the stack depth onto the INTEGER stack.",
51    StackTypes.Integer)]
52  public class FloatStackdepthExpression : StackdepthExpression<double> {
53    public FloatStackdepthExpression() { }
54    [StorableConstructor]
55    protected FloatStackdepthExpression(bool deserializing) : base(deserializing) { }
56
57    public override void Eval(IInternalPushInterpreter interpreter) {
58      Eval(interpreter.FloatStack, interpreter.IntegerStack);
59    }
60  }
61
62  [StorableClass]
63  [PushExpression(
64    StackTypes.Boolean,
65    "BOOLEAN.STACKDEPTH",
66    "Pushes the stack depth onto the INTEGER stack.",
67    StackTypes.Integer)]
68  public class BooleanStackdepthExpression : StackdepthExpression<bool> {
69    public BooleanStackdepthExpression() { }
70    [StorableConstructor]
71    protected BooleanStackdepthExpression(bool deserializing) : base(deserializing) { }
72
73    public override void Eval(IInternalPushInterpreter interpreter) {
74      Eval(interpreter.BooleanStack, interpreter.IntegerStack);
75    }
76  }
77
78  [StorableClass]
79  [PushExpression(
80    StackTypes.Name,
81    "NAME.STACKDEPTH",
82    "Pushes the stack depth onto the INTEGER stack.",
83    StackTypes.Integer)]
84  public class NameStackdepthExpression : StackdepthExpression<string> {
85    public NameStackdepthExpression() { }
86    [StorableConstructor]
87    protected NameStackdepthExpression(bool deserializing) : base(deserializing) { }
88
89    public override void Eval(IInternalPushInterpreter interpreter) {
90      Eval(interpreter.NameStack, interpreter.IntegerStack);
91    }
92  }
93
94  [StorableClass]
95  [PushExpression(
96    StackTypes.Exec,
97    "EXEC.STACKDEPTH",
98    "Pushes the stack depth onto the INTEGER stack.",
99    StackTypes.Integer)]
100  public class ExecStackdepthExpression : StackdepthExpression<Expression> {
101    public ExecStackdepthExpression() { }
102    [StorableConstructor]
103    protected ExecStackdepthExpression(bool deserializing) : base(deserializing) { }
104
105    public override void Eval(IInternalPushInterpreter interpreter) {
106      Eval(interpreter.ExecStack, interpreter.IntegerStack);
107    }
108  }
109
110  [StorableClass]
111  [PushExpression(
112    StackTypes.Code,
113    "CODE.STACKDEPTH",
114    "Pushes the stack depth onto the INTEGER stack.",
115    StackTypes.Integer)]
116  public class CodeStackdepthExpression : StackdepthExpression<Expression> {
117    public CodeStackdepthExpression() { }
118    [StorableConstructor]
119    protected CodeStackdepthExpression(bool deserializing) : base(deserializing) { }
120
121    public override void Eval(IInternalPushInterpreter interpreter) {
122      Eval(interpreter.CodeStack, interpreter.IntegerStack);
123    }
124  }
125
126  [StorableClass]
127  [PushExpression(
128    StackTypes.Char,
129    "CHAR.STACKDEPTH",
130    "Pushes the stack depth onto the INTEGER stack.",
131    StackTypes.Integer)]
132  public class CharStackdepthExpression : StackdepthExpression<char> {
133    public CharStackdepthExpression() { }
134    [StorableConstructor]
135    protected CharStackdepthExpression(bool deserializing) : base(deserializing) { }
136
137    public override void Eval(IInternalPushInterpreter interpreter) {
138      Eval(interpreter.CharStack, interpreter.IntegerStack);
139    }
140  }
141
142  [StorableClass]
143  [PushExpression(
144    StackTypes.String,
145    "STRING.STACKDEPTH",
146    "Pushes the stack depth onto the INTEGER stack.",
147    StackTypes.Integer)]
148  public class StringStackdepthExpression : StackdepthExpression<string> {
149    public StringStackdepthExpression() { }
150    [StorableConstructor]
151    protected StringStackdepthExpression(bool deserializing) : base(deserializing) { }
152
153    public override void Eval(IInternalPushInterpreter interpreter) {
154      Eval(interpreter.StringStack, interpreter.IntegerStack);
155    }
156  }
157
158  [StorableClass]
159  [PushExpression(
160    StackTypes.IntegerVector,
161    "INTEGER[].STACKDEPTH",
162    "Pushes the stack depth onto the INTEGER stack.",
163    StackTypes.Integer)]
164  public class IntegerVectorStackdepthExpression : StackdepthExpression<IReadOnlyList<long>> {
165    public IntegerVectorStackdepthExpression() { }
166    [StorableConstructor]
167    protected IntegerVectorStackdepthExpression(bool deserializing) : base(deserializing) { }
168
169    public override void Eval(IInternalPushInterpreter interpreter) {
170      Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack);
171    }
172  }
173
174  [StorableClass]
175  [PushExpression(
176    StackTypes.FloatVector,
177    "FLOAT[].STACKDEPTH",
178    "Pushes the stack depth onto the INTEGER stack.",
179    StackTypes.Integer)]
180  public class FloatVectorStackdepthExpression : StackdepthExpression<IReadOnlyList<double>> {
181    public FloatVectorStackdepthExpression() { }
182    [StorableConstructor]
183    protected FloatVectorStackdepthExpression(bool deserializing) : base(deserializing) { }
184    public override void Eval(IInternalPushInterpreter interpreter) {
185      Eval(interpreter.FloatVectorStack, interpreter.IntegerStack);
186    }
187  }
188
189  [StorableClass]
190  [PushExpression(
191    StackTypes.BooleanVector,
192    "BOOLEAN[].STACKDEPTH",
193    "Pushes the stack depth onto the INTEGER stack.",
194    StackTypes.Integer)]
195  public class BooleanVectorStackdepthExpression : StackdepthExpression<IReadOnlyList<bool>> {
196    public BooleanVectorStackdepthExpression() { }
197    [StorableConstructor]
198    protected BooleanVectorStackdepthExpression(bool deserializing) : base(deserializing) { }
199
200    public override void Eval(IInternalPushInterpreter interpreter) {
201      Eval(interpreter.BooleanVectorStack, interpreter.IntegerStack);
202    }
203  }
204
205  [StorableClass]
206  [PushExpression(
207    StackTypes.StringVector,
208    "STRING[].STACKDEPTH",
209    "Pushes the stack depth onto the INTEGER stack.",
210    StackTypes.Integer)]
211  public class StringVectorStackdepthExpression : StackdepthExpression<IReadOnlyList<string>> {
212    public StringVectorStackdepthExpression() { }
213    [StorableConstructor]
214    protected StringVectorStackdepthExpression(bool deserializing) : base(deserializing) { }
215
216    public override void Eval(IInternalPushInterpreter interpreter) {
217      Eval(interpreter.StringVectorStack, interpreter.IntegerStack);
218    }
219  }
220}
Note: See TracBrowser for help on using the repository browser.