Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/StackdepthExpressions.cs @ 14513

Last change on this file since 14513 was 14513, checked in by pkimmesw, 7 years ago

#2665 Added Problem.ProgramSynthesis Project, Fixed Expression Issues, Fixed Code Generation

File size: 2.5 KB
Line 
1namespace HeuristicLab.Algorithms.PushGP.Expressions {
2  using HeuristicLab.Algorithms.PushGP.Interpreter;
3  using HeuristicLab.Algorithms.PushGP.Stack;
4
5  /// <summary>
6  ///     Pushes the stack depth onto the INTEGER stack (thereby increasing it!).
7  /// </summary>
8  /// <typeparam name="T">Stacktype</typeparam>
9  public abstract class StackdepthExpression<T> : StatelessExpression {
10    public void Eval(IStack<T> stack, IStack<long> integerStack, bool incremental = false) {
11      var count = stack.Count;
12
13      if (incremental) count += 1;
14
15      integerStack.Push(count);
16    }
17  }
18
19  public class IntegerStackdepthExpression : StackdepthExpression<long> {
20    protected override string InitStringRepresentation() {
21      return "INTEGER.STACKDEPTH";
22    }
23
24    public override void Eval(IPushGpInterpreter interpreter) {
25      this.Eval(interpreter.IntegerStack, interpreter.IntegerStack, true);
26    }
27  }
28
29  public class FloatStackdepthExpression : StackdepthExpression<double> {
30    protected override string InitStringRepresentation() {
31      return "FLOAT.STACKDEPTH";
32    }
33
34    public override void Eval(IPushGpInterpreter interpreter) {
35      this.Eval(interpreter.FloatStack, interpreter.IntegerStack);
36    }
37  }
38
39  public class BooleanStackdepthExpression : StackdepthExpression<bool> {
40    protected override string InitStringRepresentation() {
41      return "BOOLEAN.STACKDEPTH";
42    }
43
44    public override void Eval(IPushGpInterpreter interpreter) {
45      this.Eval(interpreter.BooleanStack, interpreter.IntegerStack);
46    }
47  }
48
49  public class NameStackdepthExpression : StackdepthExpression<string> {
50    protected override string InitStringRepresentation() {
51      return "NAME.STACKDEPTH";
52    }
53
54    public override void Eval(IPushGpInterpreter interpreter) {
55      this.Eval(interpreter.NameStack, interpreter.IntegerStack);
56    }
57  }
58
59  public class ExecStackdepthExpression : StackdepthExpression<Expression> {
60    protected override string InitStringRepresentation() {
61      return "EXEC.STACKDEPTH";
62    }
63
64    public override void Eval(IPushGpInterpreter interpreter) {
65      this.Eval(interpreter.ExecStack, interpreter.IntegerStack);
66    }
67  }
68
69  public class CodeStackdepthExpression : StackdepthExpression<Expression> {
70    protected override string InitStringRepresentation() {
71      return "CODE.STACKDEPTH";
72    }
73
74    public override void Eval(IPushGpInterpreter interpreter) {
75      this.Eval(interpreter.CodeStack, interpreter.IntegerStack);
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.