Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorPushAllExpressions.cs @ 17189

Last change on this file since 17189 was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

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