Free cookie consent management tool by TermsFeed Policy Generator

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