Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorEmptyExpressions.cs @ 16958

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

#2665 Fixed bias 0 issue, PushExpressionFrequencyAnalyzer, Fixed probability for ERC settings, Fixed enable/disable instructions, Added expression descriptions

File size: 3.9 KB
Line 
1using System.Collections.Generic;
2
3namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
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  /// Pushes a boolean of whether the top vector is empty.
11  /// </summary>
12  /// <typeparam name="T"></typeparam>
13  [StorableClass]
14  public abstract class VectorEmptyVectorExpression<T> : StatelessExpression {
15    protected VectorEmptyVectorExpression() { }
16    [StorableConstructor]
17    protected VectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
18
19    protected bool IsNoop(IPushStack<IReadOnlyList<T>> vectorStack) {
20      return vectorStack.IsEmpty;
21    }
22
23    protected void Eval(IInternalPushInterpreter interpreter, IPushStack<IReadOnlyList<T>> vectorStack) {
24      var vector = vectorStack.Pop();
25      interpreter.BooleanStack.Push(vector.Count == 0);
26    }
27  }
28
29  [StorableClass]
30  [PushExpression(
31    StackTypes.IntegerVector,
32    "INTEGER[].EMPTYVECTOR",
33    "Pushes a BOOLEAN of whether the top INTEGER[] is empty.",
34    StackTypes.Boolean)]
35  public class IntegerVectorEmptyVectorExpression : VectorEmptyVectorExpression<long> {
36    public IntegerVectorEmptyVectorExpression() { }
37    [StorableConstructor]
38    protected IntegerVectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
39
40    public override bool IsNoop(IInternalPushInterpreter interpreter) {
41      return IsNoop(interpreter.IntegerVectorStack);
42    }
43
44    public override void Eval(IInternalPushInterpreter interpreter) {
45      Eval(interpreter, interpreter.IntegerVectorStack);
46    }
47  }
48
49  [StorableClass]
50  [PushExpression(
51    StackTypes.FloatVector,
52    "FLOAT[].EMPTYVECTOR",
53    "Pushes a BOOLEAN of whether the top FLOAT[] is empty.",
54    StackTypes.Boolean)]
55  public class FloatVectorEmptyVectorExpression : VectorEmptyVectorExpression<double> {
56    public FloatVectorEmptyVectorExpression() { }
57    [StorableConstructor]
58    protected FloatVectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
59
60    public override bool IsNoop(IInternalPushInterpreter interpreter) {
61      return IsNoop(interpreter.FloatVectorStack);
62    }
63
64    public override void Eval(IInternalPushInterpreter interpreter) {
65      Eval(interpreter, interpreter.FloatVectorStack);
66    }
67  }
68
69  [StorableClass]
70  [PushExpression(
71    StackTypes.BooleanVector,
72    "BOOLEAN[].EMPTYVECTOR",
73    "Pushes a BOOLEAN of whether the top BOOLEAN[] is empty.",
74    StackTypes.Boolean)]
75  public class BooleanVectorEmptyVectorExpression : VectorEmptyVectorExpression<bool> {
76    public BooleanVectorEmptyVectorExpression() { }
77    [StorableConstructor]
78    protected BooleanVectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
79
80    public override bool IsNoop(IInternalPushInterpreter interpreter) {
81      return IsNoop(interpreter.BooleanVectorStack);
82    }
83
84    public override void Eval(IInternalPushInterpreter interpreter) {
85      Eval(interpreter, interpreter.BooleanVectorStack);
86    }
87  }
88
89  [StorableClass]
90  [PushExpression(
91    StackTypes.StringVector,
92    "STRING[].EMPTYVECTOR",
93    "Pushes a BOOLEAN of whether the top STRING[] is empty.",
94    StackTypes.Boolean)]
95  public class StringVectorEmptyVectorExpression : VectorEmptyVectorExpression<string> {
96    public StringVectorEmptyVectorExpression() { }
97    [StorableConstructor]
98    protected StringVectorEmptyVectorExpression(bool deserializing) : base(deserializing) { }
99
100    public override bool IsNoop(IInternalPushInterpreter interpreter) {
101      return IsNoop(interpreter.StringVectorStack);
102    }
103
104    public override void Eval(IInternalPushInterpreter interpreter) {
105      Eval(interpreter, interpreter.StringVectorStack);
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.