Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorRestExpressions.cs @ 14952

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

#2665 Added IsNoop to Expression, Made Expressions storable, Fixed Debugger, Fixed and improved problem data and result visualisation, Added custom ErcOption view, Added problem difficulty to problem data name

File size: 3.3 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using System.Collections.Generic;
3
4  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
5  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
6  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
7  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
8
9  /// <summary>
10  /// Takes the rest of the top item on the type stack.
11  /// </summary>
12  /// <typeparam name="T"></typeparam>
13  [StorableClass]
14  public abstract class VectorRestExpression<T> : StatelessExpression {
15    protected VectorRestExpression() { }
16    [StorableConstructor]
17    protected VectorRestExpression(bool deserializing) : base(deserializing) { }
18
19    protected bool IsNoop(IPushStack<List<T>> vectorStack) {
20      return vectorStack.IsEmpty || vectorStack.Top.Count < 2;
21    }
22
23    protected void Eval(IPushStack<List<T>> vectorStack) {
24      var result = vectorStack.Top.GetRange(1, vectorStack.Top.Count - 1);
25      vectorStack.SetTop(result);
26    }
27  }
28
29  [StorableClass]
30  [PushExpression(StackTypes.IntegerVector, "INTEGER[].REST")]
31  public class IntegerVectorRestExpression : VectorRestExpression<long> {
32    public IntegerVectorRestExpression() { }
33    [StorableConstructor]
34    protected IntegerVectorRestExpression(bool deserializing) : base(deserializing) { }
35
36    public override bool IsNoop(IInternalPushInterpreter interpreter) {
37      return IsNoop(interpreter.IntegerVectorStack);
38    }
39
40    public override void Eval(IInternalPushInterpreter interpreter) {
41      Eval(interpreter.IntegerVectorStack);
42    }
43  }
44
45  [StorableClass]
46  [PushExpression(StackTypes.FloatVector, "FLOAT[].REST")]
47  public class FloatVectorRestExpression : VectorRestExpression<double> {
48    public FloatVectorRestExpression() { }
49    [StorableConstructor]
50    protected FloatVectorRestExpression(bool deserializing) : base(deserializing) { }
51
52    public override bool IsNoop(IInternalPushInterpreter interpreter) {
53      return IsNoop(interpreter.FloatVectorStack);
54    }
55
56    public override void Eval(IInternalPushInterpreter interpreter) {
57      Eval(interpreter.FloatVectorStack);
58    }
59  }
60
61  [StorableClass]
62  [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].REST")]
63  public class BooleanVectorRestExpression : VectorRestExpression<bool> {
64    public BooleanVectorRestExpression() { }
65    [StorableConstructor]
66    protected BooleanVectorRestExpression(bool deserializing) : base(deserializing) { }
67
68    public override bool IsNoop(IInternalPushInterpreter interpreter) {
69      return IsNoop(interpreter.BooleanVectorStack);
70    }
71
72    public override void Eval(IInternalPushInterpreter interpreter) {
73      Eval(interpreter.BooleanVectorStack);
74    }
75  }
76
77  [StorableClass]
78  [PushExpression(StackTypes.StringVector, "STRING[].REST")]
79  public class StringVectorRestExpression : VectorRestExpression<string> {
80    public StringVectorRestExpression() { }
81    [StorableConstructor]
82    protected StringVectorRestExpression(bool deserializing) : base(deserializing) { }
83
84    public override bool IsNoop(IInternalPushInterpreter interpreter) {
85      return IsNoop(interpreter.StringVectorStack);
86    }
87
88    public override void Eval(IInternalPushInterpreter interpreter) {
89      Eval(interpreter.StringVectorStack);
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.