1 | using System.Collections.Generic;
|
---|
2 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; |
---|
3 | |
---|
4 | namespace HeuristicLab.Problems.ProgramSynthesis { |
---|
5 | /// <summary>
|
---|
6 | /// Concatinates two vectors on the type stack.
|
---|
7 | /// </summary>
|
---|
8 | [StorableClass]
|
---|
9 | public abstract class VectorConcatExpression<T> : StatelessExpression {
|
---|
10 | protected VectorConcatExpression() { }
|
---|
11 | [StorableConstructor]
|
---|
12 | protected VectorConcatExpression(bool deserializing) : base(deserializing) { }
|
---|
13 |
|
---|
14 | protected bool IsNoop(IInternalPushInterpreter interpreter, IPushStack<IReadOnlyList<T>> vectorStack) {
|
---|
15 | return vectorStack.Count < 2 ||
|
---|
16 | vectorStack.Top.Count + vectorStack[1].Count > interpreter.Configuration.MaxVectorLength;
|
---|
17 | }
|
---|
18 |
|
---|
19 | protected void Eval(IInternalPushInterpreter interpter, IPushStack<IReadOnlyList<T>> vectorStack) {
|
---|
20 | var first = vectorStack.Pop();
|
---|
21 | var second = vectorStack.Top;
|
---|
22 | var result = new List<T>(second.Count + first.Count);
|
---|
23 | result.AddRange(second);
|
---|
24 | result.AddRange(first);
|
---|
25 |
|
---|
26 | vectorStack.Top = result;
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | [StorableClass]
|
---|
31 | [PushExpression(
|
---|
32 | StackTypes.IntegerVector,
|
---|
33 | "INTEGER[].CONCAT",
|
---|
34 | "Concatenates the top two vectors on the INTEGER[] stack.")]
|
---|
35 | public class IntegerVectorConcatExpression : VectorConcatExpression<long> {
|
---|
36 | public IntegerVectorConcatExpression() { }
|
---|
37 | [StorableConstructor]
|
---|
38 | protected IntegerVectorConcatExpression(bool deserializing) : base(deserializing) { }
|
---|
39 |
|
---|
40 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
41 | return IsNoop(interpreter, 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[].CONCAT",
|
---|
53 | "Concatenates the top two vectors on the FLOAT[] stack.")]
|
---|
54 | public class FloatVectorConcatExpression : VectorConcatExpression<double> {
|
---|
55 | public FloatVectorConcatExpression() { }
|
---|
56 | [StorableConstructor]
|
---|
57 | protected FloatVectorConcatExpression(bool deserializing) : base(deserializing) { }
|
---|
58 |
|
---|
59 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
60 | return IsNoop(interpreter, interpreter.FloatVectorStack);
|
---|
61 | }
|
---|
62 |
|
---|
63 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
64 | Eval(interpreter, interpreter.FloatVectorStack);
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | [StorableClass]
|
---|
69 | [PushExpression(
|
---|
70 | StackTypes.BooleanVector,
|
---|
71 | "BOOLEAN[].CONCAT",
|
---|
72 | "Concatenates the top two vectors on the BOOLEAN[] stack.")]
|
---|
73 | public class BooleanVectorConcatExpression : VectorConcatExpression<bool> {
|
---|
74 | public BooleanVectorConcatExpression() { }
|
---|
75 | [StorableConstructor]
|
---|
76 | protected BooleanVectorConcatExpression(bool deserializing) : base(deserializing) { }
|
---|
77 |
|
---|
78 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
79 | return IsNoop(interpreter, interpreter.BooleanVectorStack);
|
---|
80 | }
|
---|
81 |
|
---|
82 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
83 | Eval(interpreter, interpreter.BooleanVectorStack);
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | [StorableClass]
|
---|
88 | [PushExpression(
|
---|
89 | StackTypes.StringVector,
|
---|
90 | "STRING[].CONCAT",
|
---|
91 | "Concatenates the top two vectors on the STRING[] stack.")]
|
---|
92 | public class StringVectorConcatExpression : VectorConcatExpression<string> {
|
---|
93 | public StringVectorConcatExpression() { }
|
---|
94 | [StorableConstructor]
|
---|
95 | protected StringVectorConcatExpression(bool deserializing) : base(deserializing) { }
|
---|
96 |
|
---|
97 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
98 | return IsNoop(interpreter, interpreter.StringVectorStack);
|
---|
99 | }
|
---|
100 |
|
---|
101 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
102 | Eval(interpreter, interpreter.StringVectorStack);
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|