Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

File size: 2.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
7  using Stack;
8
9  /// <summary>
10  /// Tells whether that stack is empty.
11  /// </summary>
12  public abstract class EmptyExpresssion<T> : StatelessExpression {
13    public bool Eval(IPushStack<T> stack, IPushStack<bool> booleanStack) {
14      booleanStack.Push(stack.IsEmpty);
15
16      return true;
17    }
18  }
19
20  [PushExpression(StackTypes.Exec, "EXEC.EMPTY", StackTypes.Boolean)]
21  public class ExecEmptyExpression : EmptyExpresssion<Expression> {
22    public override bool Eval(IInternalPushInterpreter interpreter) {
23      return Eval(interpreter.ExecStack, interpreter.BooleanStack);
24    }
25  }
26
27  [PushExpression(StackTypes.Code, "CODE.EMPTY", StackTypes.Boolean)]
28  public class CodeEmptyExpression : EmptyExpresssion<Expression> {
29    public override bool Eval(IInternalPushInterpreter interpreter) {
30      return Eval(interpreter.CodeStack, interpreter.BooleanStack);
31    }
32  }
33
34  [PushExpression(StackTypes.Integer, "INTEGER.EMPTY", StackTypes.Boolean)]
35  public class IntegerEmptyExpression : EmptyExpresssion<long> {
36    public override bool Eval(IInternalPushInterpreter interpreter) {
37      return Eval(interpreter.IntegerStack, interpreter.BooleanStack);
38    }
39  }
40
41  [PushExpression(StackTypes.Float, "FLOAT.EMPTY", StackTypes.Boolean)]
42  public class FloatEmptyExpression : EmptyExpresssion<double> {
43    public override bool Eval(IInternalPushInterpreter interpreter) {
44      return Eval(interpreter.FloatStack, interpreter.BooleanStack);
45    }
46  }
47
48  [PushExpression(StackTypes.Boolean, "BOOLEAN.EMPTY", StackTypes.Boolean)]
49  public class BooleanEmptyExpression : EmptyExpresssion<bool> {
50    public override bool Eval(IInternalPushInterpreter interpreter) {
51      return Eval(interpreter.BooleanStack, interpreter.BooleanStack);
52    }
53  }
54
55  [PushExpression(StackTypes.Char, "CHAR.EMPTY", StackTypes.Boolean)]
56  public class CharEmptyExpression : EmptyExpresssion<char> {
57    public override bool Eval(IInternalPushInterpreter interpreter) {
58      return Eval(interpreter.CharStack, interpreter.BooleanStack);
59    }
60  }
61
62  [PushExpression(StackTypes.String, "STRING.EMPTY", StackTypes.Boolean)]
63  public class StringEmptyExpression : EmptyExpresssion<string> {
64    public override bool Eval(IInternalPushInterpreter interpreter) {
65      return Eval(interpreter.StringStack, interpreter.BooleanStack);
66    }
67  }
68
69  [PushExpression(StackTypes.IntegerVector, "INTEGER[].EMPTY", StackTypes.Boolean)]
70  public class IntegerVectorEmptyExpression : EmptyExpresssion<List<long>> {
71    public override bool Eval(IInternalPushInterpreter interpreter) {
72      return Eval(interpreter.IntegerVectorStack, interpreter.BooleanStack);
73    }
74  }
75}
Note: See TracBrowser for help on using the repository browser.