Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/StackdepthExpressions.cs @ 16003

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

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

File size: 7.5 KB
RevLine 
[15771]1using System.Collections.Generic;
2using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
3
4namespace HeuristicLab.Problems.ProgramSynthesis {
[14727]5  /// <summary>
6  ///     Pushes the stack depth onto the INTEGER stack (thereby increasing it!).
7  /// </summary>
8  /// <typeparam name="T">Stacktype</typeparam>
[14952]9  [StorableClass]
[14727]10  public abstract class StackdepthExpression<T> : StatelessExpression {
[14952]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) {
[14727]20      var count = stack.Count;
21      if (incremental) count += 1;
22      integerStack.Push(count);
23    }
24  }
25
[14952]26  [StorableClass]
[15032]27  [PushExpression(
28    StackTypes.Integer,
29    "INTEGER.STACKDEPTH",
30    "Pushes the stack depth onto the INTEGER stack.")]
[14727]31  public class IntegerStackdepthExpression : StackdepthExpression<long> {
[14952]32    public IntegerStackdepthExpression() { }
33    [StorableConstructor]
34    protected IntegerStackdepthExpression(bool deserializing) : base(deserializing) { }
[14727]35
[14952]36    public override void Eval(IInternalPushInterpreter interpreter) {
37      Eval(interpreter.IntegerStack, interpreter.IntegerStack, true);
[14727]38    }
39  }
40
[14952]41  [StorableClass]
[15032]42  [PushExpression(
43    StackTypes.Float,
44    "FLOAT.STACKDEPTH",
45    "Pushes the stack depth onto the INTEGER stack.",
46    StackTypes.Integer)]
[14727]47  public class FloatStackdepthExpression : StackdepthExpression<double> {
[14952]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);
[14727]54    }
55  }
56
[14952]57  [StorableClass]
[15032]58  [PushExpression(
59    StackTypes.Boolean,
60    "BOOLEAN.STACKDEPTH",
61    "Pushes the stack depth onto the INTEGER stack.",
62    StackTypes.Integer)]
[14727]63  public class BooleanStackdepthExpression : StackdepthExpression<bool> {
[14952]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);
[14727]70    }
71  }
72
[14952]73  [StorableClass]
[15032]74  [PushExpression(
75    StackTypes.Name,
76    "NAME.STACKDEPTH",
77    "Pushes the stack depth onto the INTEGER stack.",
78    StackTypes.Integer)]
[14727]79  public class NameStackdepthExpression : StackdepthExpression<string> {
[14952]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);
[14727]86    }
87  }
88
[14952]89  [StorableClass]
[15032]90  [PushExpression(
91    StackTypes.Exec,
92    "EXEC.STACKDEPTH",
93    "Pushes the stack depth onto the INTEGER stack.",
94    StackTypes.Integer)]
[14727]95  public class ExecStackdepthExpression : StackdepthExpression<Expression> {
[14952]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);
[14727]102    }
103  }
104
[14952]105  [StorableClass]
[15032]106  [PushExpression(
107    StackTypes.Code,
108    "CODE.STACKDEPTH",
109    "Pushes the stack depth onto the INTEGER stack.",
110    StackTypes.Integer)]
[14727]111  public class CodeStackdepthExpression : StackdepthExpression<Expression> {
[14952]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);
[14727]118    }
119  }
[14777]120
[14952]121  [StorableClass]
[15032]122  [PushExpression(
123    StackTypes.Char,
124    "CHAR.STACKDEPTH",
125    "Pushes the stack depth onto the INTEGER stack.",
126    StackTypes.Integer)]
[14777]127  public class CharStackdepthExpression : StackdepthExpression<char> {
[14952]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);
[14777]134    }
135  }
136
[14952]137  [StorableClass]
[15032]138  [PushExpression(
139    StackTypes.String,
140    "STRING.STACKDEPTH",
141    "Pushes the stack depth onto the INTEGER stack.",
142    StackTypes.Integer)]
[14777]143  public class StringStackdepthExpression : StackdepthExpression<string> {
[14952]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);
[14777]150    }
151  }
[14834]152
[14952]153  [StorableClass]
[15032]154  [PushExpression(
155    StackTypes.IntegerVector,
156    "INTEGER[].STACKDEPTH",
157    "Pushes the stack depth onto the INTEGER stack.",
158    StackTypes.Integer)]
[15017]159  public class IntegerVectorStackdepthExpression : StackdepthExpression<IReadOnlyList<long>> {
[14952]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);
[14834]166    }
167  }
[14875]168
[14952]169  [StorableClass]
[15032]170  [PushExpression(
171    StackTypes.FloatVector,
172    "FLOAT[].STACKDEPTH",
173    "Pushes the stack depth onto the INTEGER stack.",
174    StackTypes.Integer)]
[15017]175  public class FloatVectorStackdepthExpression : StackdepthExpression<IReadOnlyList<double>> {
[14952]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);
[14875]181    }
182  }
183
[14952]184  [StorableClass]
[15032]185  [PushExpression(
186    StackTypes.BooleanVector,
187    "BOOLEAN[].STACKDEPTH",
188    "Pushes the stack depth onto the INTEGER stack.",
189    StackTypes.Integer)]
[15017]190  public class BooleanVectorStackdepthExpression : StackdepthExpression<IReadOnlyList<bool>> {
[14952]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);
[14875]197    }
198  }
199
[14952]200  [StorableClass]
[15032]201  [PushExpression(
202    StackTypes.StringVector,
203    "STRING[].STACKDEPTH",
204    "Pushes the stack depth onto the INTEGER stack.",
205    StackTypes.Integer)]
[15017]206  public class StringVectorStackdepthExpression : StackdepthExpression<IReadOnlyList<string>> {
[14952]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);
[14875]213    }
214  }
[14727]215}
Note: See TracBrowser for help on using the repository browser.