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

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

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

File size: 2.1 KB
Line 
1using System.Collections.Generic;
2
3namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
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  /// Removes all occurrences of the first lit-type item in the top type vector.
10  /// </summary>
11  /// <typeparam name="T"></typeparam>
12  public abstract class VectorRemoveExpression<T> : StatelessExpression {
13    protected bool Eval(IPushStack<List<T>> vectorStack, IPushStack<T> literalStack) {
14      if (vectorStack.IsEmpty ||
15          literalStack.IsEmpty)
16        return false;
17
18      var literal = literalStack.Pop();
19      vectorStack.Top.RemoveAll(x => x.Equals(literal));
20      return true;
21    }
22  }
23
24  [PushExpression(StackTypes.IntegerVector, "INTEGER[].REMOVE", StackTypes.Integer)]
25  public class IntegerVectorRemoveExpression : VectorRemoveExpression<long> {
26    public override bool Eval(IInternalPushInterpreter interpreter) {
27      return Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack);
28    }
29  }
30
31  [PushExpression(StackTypes.FloatVector, "FLOAT[].REMOVE", StackTypes.Float)]
32  public class FloatVectorRemoveExpression : VectorRemoveExpression<double> {
33    public override bool Eval(IInternalPushInterpreter interpreter) {
34      return Eval(interpreter.FloatVectorStack, interpreter.FloatStack);
35    }
36  }
37
38  [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].REMOVE", StackTypes.Boolean)]
39  public class BooleanVectorRemoveExpression : VectorRemoveExpression<bool> {
40    public override bool Eval(IInternalPushInterpreter interpreter) {
41      return Eval(interpreter.BooleanVectorStack, interpreter.BooleanStack);
42    }
43  }
44
45  [PushExpression(StackTypes.StringVector, "STRING[].REMOVE", StackTypes.String)]
46  public class StringVectorRemoveExpression : VectorRemoveExpression<string> {
47    public override bool Eval(IInternalPushInterpreter interpreter) {
48      return Eval(interpreter.StringVectorStack, interpreter.StringStack);
49    }
50  }
51}
Note: See TracBrowser for help on using the repository browser.