Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

File size: 1.9 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using System.Collections.Generic;
3
4  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
5  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
6  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
7
8  /// <summary>
9  /// Takes the rest of the top item on the type stack.
10  /// </summary>
11  /// <typeparam name="T"></typeparam>
12  public abstract class VectorRestExpression<T> : StatelessExpression {
13    protected bool Eval(IPushStack<List<T>> vectorStack) {
14      if (vectorStack.IsEmpty || vectorStack.Top.Count < 2)
15        return false;
16
17      var result = vectorStack.Top.GetRange(1, vectorStack.Top.Count - 1);
18      vectorStack.SetTop(result);
19      return true;
20    }
21  }
22
23  [PushExpression(StackTypes.IntegerVector, "INTEGER[].REST")]
24  public class IntegerVectorRestExpression : VectorRestExpression<long> {
25    public override bool Eval(IInternalPushInterpreter interpreter) {
26      return Eval(interpreter.IntegerVectorStack);
27    }
28  }
29
30  [PushExpression(StackTypes.FloatVector, "FLOAT[].REST")]
31  public class FloatVectorRestExpression : VectorRestExpression<double> {
32    public override bool Eval(IInternalPushInterpreter interpreter) {
33      return Eval(interpreter.FloatVectorStack);
34    }
35  }
36
37  [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].REST")]
38  public class BooleanVectorRestExpression : VectorRestExpression<bool> {
39    public override bool Eval(IInternalPushInterpreter interpreter) {
40      return Eval(interpreter.BooleanVectorStack);
41    }
42  }
43
44  [PushExpression(StackTypes.StringVector, "STRING[].REST")]
45  public class StringVectorRestExpression : VectorRestExpression<string> {
46    public override bool Eval(IInternalPushInterpreter interpreter) {
47      return Eval(interpreter.StringVectorStack);
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.