Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/RotateExpressions.cs @ 14875

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

#2665 BenchmarkSuite, all examples, partially tested, VectorExpressions added

File size: 3.4 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using System.Collections.Generic;
3
4  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
5
6  using Interpreter;
7  using Stack;
8
9  public abstract class RotateExpression<T> : StatelessExpression {
10    public bool Eval(IPushStack<T> stack) {
11      if (stack.Count < 3) return false;
12
13      stack.Swap(3);
14      return true;
15    }
16  }
17
18
19  [PushExpression(StackTypes.Integer, "INTEGER.ROT")]
20  public class IntegerRotateExpression : RotateExpression<long> {
21    public override bool Eval(IInternalPushInterpreter interpreter) {
22      return Eval(interpreter.IntegerStack);
23    }
24  }
25
26  [PushExpression(StackTypes.Float, "FLOAT.ROT")]
27  public class FloatRotateExpression : RotateExpression<double> {
28    public override bool Eval(IInternalPushInterpreter interpreter) {
29      return Eval(interpreter.FloatStack);
30    }
31  }
32
33  [PushExpression(StackTypes.Boolean, "BOOLEAN.ROT")]
34  public class BooleanRotateExpression : RotateExpression<bool> {
35    public override bool Eval(IInternalPushInterpreter interpreter) {
36      return Eval(interpreter.BooleanStack);
37    }
38  }
39
40  [PushExpression(StackTypes.Name, "NAME.ROT")]
41  public class NameRotateExpression : RotateExpression<string> {
42    public override bool Eval(IInternalPushInterpreter interpreter) {
43      return Eval(interpreter.NameStack);
44    }
45  }
46
47  [PushExpression(StackTypes.Exec, "EXEC.ROT")]
48  public class ExecRotateExpression : RotateExpression<Expression> {
49    public override bool Eval(IInternalPushInterpreter interpreter) {
50      return Eval(interpreter.ExecStack);
51    }
52  }
53
54  [PushExpression(StackTypes.Code, "CODE.ROT")]
55  public class CodeRotateExpression : RotateExpression<Expression> {
56    public override bool Eval(IInternalPushInterpreter interpreter) {
57      return Eval(interpreter.CodeStack);
58    }
59  }
60
61  [PushExpression(StackTypes.Char, "CHAR.ROT")]
62  public class CharRotateExpression : RotateExpression<char> {
63    public override bool Eval(IInternalPushInterpreter interpreter) {
64      return Eval(interpreter.CharStack);
65    }
66  }
67
68  [PushExpression(StackTypes.String, "STRING.ROT")]
69  public class StringRotateExpression : RotateExpression<string> {
70    public override bool Eval(IInternalPushInterpreter interpreter) {
71      return Eval(interpreter.StringStack);
72    }
73  }
74
75  [PushExpression(StackTypes.IntegerVector, "INTEGER[].ROT")]
76  public class IntegerVectorRotateExpression : RotateExpression<List<long>> {
77    public override bool Eval(IInternalPushInterpreter interpreter) {
78      return Eval(interpreter.IntegerVectorStack);
79    }
80  }
81
82  [PushExpression(StackTypes.FloatVector, "FLOAT[].ROT")]
83  public class FloatVectorRotateExpression : RotateExpression<List<double>> {
84    public override bool Eval(IInternalPushInterpreter interpreter) {
85      return Eval(interpreter.FloatVectorStack);
86    }
87  }
88
89  [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].ROT")]
90  public class BooleanVectorRotateExpression : RotateExpression<List<bool>> {
91    public override bool Eval(IInternalPushInterpreter interpreter) {
92      return Eval(interpreter.BooleanVectorStack);
93    }
94  }
95
96  [PushExpression(StackTypes.StringVector, "STRING[].ROT")]
97  public class StringVectorRotateExpression : RotateExpression<List<string>> {
98    public override bool Eval(IInternalPushInterpreter interpreter) {
99      return Eval(interpreter.StringVectorStack);
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.