Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/DuplicateExpressions.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  /// <summary>
7  ///     Duplicates the top item on the INTEGER stack. Does not pop its argument
8  ///     (which, if it did, would negate the effect of the duplication!).
9  /// </summary>
10  /// <typeparam name="T">Stacktype</typeparam>
11  public abstract class DuplicateExpression<T> : StatelessExpression
12  {
13    protected void Eval(IStack<T> stack)
14    {
15      if (stack.Count == 0) return;
16
17      stack.Push(stack.Top);
18    }
19
20    protected void Eval(IStack<Expression> stack)
21    {
22      if (stack.Count == 0) return;
23
24      var top = stack.Top;
25
26      stack.Push(top);
27    }
28  }
29
30  public class IntegerDuplicateExpression : DuplicateExpression<long>
31  {
32    protected override string InitStringRepresentation()
33    {
34      return "INTEGER.DUP";
35    }
36
37    public override void Eval(IPushGpInterpreter interpreter)
38    {
39      this.Eval(interpreter.IntegerStack);
40    }
41  }
42
43  public class FloatDuplicateExpression : DuplicateExpression<double>
44  {
45    protected override string InitStringRepresentation()
46    {
47      return "FLOAT.DUP";
48    }
49
50    public override void Eval(IPushGpInterpreter interpreter)
51    {
52      this.Eval(interpreter.FloatStack);
53    }
54  }
55
56  public class BooleanDuplicateExpression : DuplicateExpression<bool>
57  {
58    protected override string InitStringRepresentation()
59    {
60      return "BOOLEAN.DUP";
61    }
62
63    public override void Eval(IPushGpInterpreter interpreter)
64    {
65      this.Eval(interpreter.BooleanStack);
66    }
67  }
68
69  public class NameDuplicateExpression : DuplicateExpression<string>
70  {
71    protected override string InitStringRepresentation()
72    {
73      return "NAME.DUP";
74    }
75
76    public override void Eval(IPushGpInterpreter interpreter)
77    {
78      this.Eval(interpreter.NameStack);
79    }
80  }
81
82  public class ExecDuplicateExpression : DuplicateExpression<Expression>
83  {
84    protected override string InitStringRepresentation()
85    {
86      return "EXEC.DUP";
87    }
88
89    public override void Eval(IPushGpInterpreter interpreter)
90    {
91      this.Eval(interpreter.ExecStack);
92    }
93  }
94
95  public class CodeDuplicateExpression : DuplicateExpression<Expression>
96  {
97    protected override string InitStringRepresentation()
98    {
99      return "CODE.DUP";
100    }
101
102    public override void Eval(IPushGpInterpreter interpreter)
103    {
104      this.Eval(interpreter.CodeStack);
105    }
106  }
107}
Note: See TracBrowser for help on using the repository browser.