Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/ShoveExpressions.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{
3  using HeuristicLab.Algorithms.PushGP.Interpreter;
4  using HeuristicLab.Algorithms.PushGP.Stack;
5
6  public abstract class ShoveExpression<T> : StatelessExpression
7  {
8    public void Eval(IStack<T> stack, IStack<long> integerStack, int count = 1)
9    {
10      if (integerStack.Count == 0) return;
11
12      if ((integerStack.Top > stack.Count - count) || (integerStack.Top < 0) || (stack.Count < 2)) return;
13
14      var index = (int)integerStack.Pop();
15      var item = stack.Pop();
16
17      stack.Insert(index, item);
18    }
19  }
20
21  public class IntegerShoveExpression : ShoveExpression<long>
22  {
23    protected override string InitStringRepresentation()
24    {
25      return "INTEGER.SHOVE";
26    }
27
28    public override void Eval(IPushGpInterpreter interpreter)
29    {
30      this.Eval(interpreter.IntegerStack, interpreter.IntegerStack, 2);
31    }
32  }
33
34  public class FloatShoveExpression : ShoveExpression<double>
35  {
36    protected override string InitStringRepresentation()
37    {
38      return "FLOAT.SHOVE";
39    }
40
41    public override void Eval(IPushGpInterpreter interpreter)
42    {
43      this.Eval(interpreter.FloatStack, interpreter.IntegerStack);
44    }
45  }
46
47  public class BooleanShoveExpression : ShoveExpression<bool>
48  {
49    protected override string InitStringRepresentation()
50    {
51      return "BOOLEAN.SHOVE";
52    }
53
54    public override void Eval(IPushGpInterpreter interpreter)
55    {
56      this.Eval(interpreter.BooleanStack, interpreter.IntegerStack);
57    }
58  }
59
60  public class NameShoveExpression : ShoveExpression<string>
61  {
62    protected override string InitStringRepresentation()
63    {
64      return "NAME.SHOVE";
65    }
66
67    public override void Eval(IPushGpInterpreter interpreter)
68    {
69      this.Eval(interpreter.NameStack, interpreter.IntegerStack);
70    }
71  }
72
73  public class ExecShoveExpression : ShoveExpression<Expression>
74  {
75    protected override string InitStringRepresentation()
76    {
77      return "EXEC.SHOVE";
78    }
79
80    public override void Eval(IPushGpInterpreter interpreter)
81    {
82      this.Eval(interpreter.ExecStack, interpreter.IntegerStack);
83    }
84  }
85
86  public class CodeShoveExpression : ShoveExpression<Expression>
87  {
88    protected override string InitStringRepresentation()
89    {
90      return "CODE.SHOVE";
91    }
92
93    public override void Eval(IPushGpInterpreter interpreter)
94    {
95      this.Eval(interpreter.CodeStack, interpreter.IntegerStack);
96    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.