Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorConjExpressions.cs @ 15032

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

#2665 Fixed bias 0 issue, PushExpressionFrequencyAnalyzer, Fixed probability for ERC settings, Fixed enable/disable instructions, Added expression descriptions

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