Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorPushAllExpressions.cs @ 15692

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

#2665 Fixed small issues, testet benchmark suite, added INX Expressions

File size: 4.0 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
2  using System.Collections.Generic;
3  using System.Linq;
4
5  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
7  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
8  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
9
10  /// <summary>
11  /// Pushes every item from the first vector onto the appropriate stack in reversed order.
12  /// </summary>
13  /// <typeparam name="T"></typeparam>
14  [StorableClass]
15  public abstract class VectorPushAllExpression<T> : StatelessExpression {
16    protected VectorPushAllExpression() { }
17    [StorableConstructor]
18    protected VectorPushAllExpression(bool deserializing) : base(deserializing) { }
19
20    protected bool IsNoop(IPushStack<IReadOnlyList<T>> vectorStack) {
21      return vectorStack.IsEmpty;
22    }
23
24    protected void Eval(IPushStack<IReadOnlyList<T>> vectorStack, IPushStack<T> literalStack) {
25      var vector = vectorStack.Pop().Reverse().ToList();
26      literalStack.Push(vector);
27    }
28  }
29
30  [StorableClass]
31  [PushExpression(
32    StackTypes.IntegerVector,
33    "INTEGER[].PUSHALL",
34    "Pushes every item from the top INTEGER[] onto the INTEGER stack in reversed order.",
35    StackTypes.Integer)]
36  public class IntegerVectorPushAllExpression : VectorPushAllExpression<long> {
37    public IntegerVectorPushAllExpression() { }
38    [StorableConstructor]
39    protected IntegerVectorPushAllExpression(bool deserializing) : base(deserializing) { }
40
41    public override bool IsNoop(IInternalPushInterpreter interpreter) {
42      return IsNoop(interpreter.IntegerVectorStack);
43    }
44
45    public override void Eval(IInternalPushInterpreter interpreter) {
46      Eval(interpreter.IntegerVectorStack, interpreter.IntegerStack);
47    }
48  }
49
50  [StorableClass]
51  [PushExpression(
52    StackTypes.FloatVector,
53    "FLOAT[].PUSHALL",
54    "Pushes every item from the top FLOAT[] onto the FLOAT stack in reversed order.",
55    StackTypes.Float)]
56  public class FloatVectorPushAllExpression : VectorPushAllExpression<double> {
57    public FloatVectorPushAllExpression() { }
58    [StorableConstructor]
59    protected FloatVectorPushAllExpression(bool deserializing) : base(deserializing) { }
60
61    public override bool IsNoop(IInternalPushInterpreter interpreter) {
62      return IsNoop(interpreter.FloatVectorStack);
63    }
64
65    public override void Eval(IInternalPushInterpreter interpreter) {
66      Eval(interpreter.FloatVectorStack, interpreter.FloatStack);
67    }
68  }
69
70  [StorableClass]
71  [PushExpression(
72    StackTypes.BooleanVector,
73    "BOOLEAN[].PUSHALL",
74    "Pushes every item from the top BOOLEAN[] onto the BOOLEAN stack in reversed order.",
75    StackTypes.Boolean)]
76  public class BooleanVectorPushAllExpression : VectorPushAllExpression<bool> {
77    public BooleanVectorPushAllExpression() { }
78    [StorableConstructor]
79    protected BooleanVectorPushAllExpression(bool deserializing) : base(deserializing) { }
80
81    public override bool IsNoop(IInternalPushInterpreter interpreter) {
82      return IsNoop(interpreter.BooleanVectorStack);
83    }
84
85    public override void Eval(IInternalPushInterpreter interpreter) {
86      Eval(interpreter.BooleanVectorStack, interpreter.BooleanStack);
87    }
88  }
89
90  [StorableClass]
91  [PushExpression(
92    StackTypes.StringVector,
93    "STRING[].PUSHALL",
94    "Pushes every item from the top STRING[] onto the STRING stack in reversed order.",
95    StackTypes.String)]
96  public class StringVectorPushAllExpression : VectorPushAllExpression<string> {
97    public StringVectorPushAllExpression() { }
98    [StorableConstructor]
99    protected StringVectorPushAllExpression(bool deserializing) : base(deserializing) { }
100
101    public override bool IsNoop(IInternalPushInterpreter interpreter) {
102      return IsNoop(interpreter.StringVectorStack);
103    }
104
105    public override void Eval(IInternalPushInterpreter interpreter) {
106      Eval(interpreter.StringVectorStack, interpreter.StringStack);
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.