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