Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorConjExpressions.cs @ 16752

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

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

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