Changeset 14952 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorSetExpressions.cs
- Timestamp:
- 05/10/17 11:23:05 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/VectorSetExpressions.cs
r14909 r14952 2 2 3 3 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 4 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 4 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 5 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter; … … 10 11 /// </summary> 11 12 /// <typeparam name="T"></typeparam> 13 [StorableClass] 12 14 public abstract class VectorSetExpression<T> : StatelessExpression { 13 protected bool Eval( 15 protected VectorSetExpression() { } 16 [StorableConstructor] 17 protected VectorSetExpression(bool deserializing) : base(deserializing) { } 18 19 protected bool IsNoop(IInternalPushInterpreter interpreter, IPushStack<List<T>> vectorStack, IPushStack<T> literalStack, bool isLiteralTypeInteger = false) { 20 return vectorStack.IsEmpty || 21 vectorStack.Top.Count == 0 || 22 literalStack.IsEmpty || 23 (isLiteralTypeInteger && interpreter.IntegerStack.Count < 2) || 24 (!isLiteralTypeInteger && interpreter.IntegerStack.IsEmpty); 25 } 26 27 protected void Eval( 14 28 IInternalPushInterpreter interpreter, 15 29 IPushStack<List<T>> vectorStack, 16 30 IPushStack<T> literalStack, 17 31 bool isLiteralTypeInteger = false) { 18 if (vectorStack.IsEmpty ||19 vectorStack.Top.Count == 0 ||20 literalStack.IsEmpty ||21 (isLiteralTypeInteger && interpreter.IntegerStack.Count < 2) ||22 (!isLiteralTypeInteger && interpreter.IntegerStack.IsEmpty))23 return false;24 25 32 T literal; 26 33 int index; … … 42 49 43 50 vector[index] = literal; 44 return true;45 51 } 46 52 } 47 53 54 [StorableClass] 48 55 [PushExpression(StackTypes.IntegerVector, "INTEGER[].SET", StackTypes.Integer)] 49 56 public class IntegerVectorSetExpression : VectorSetExpression<long> { 50 public override bool Eval(IInternalPushInterpreter interpreter) { 51 return Eval(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack, true); 57 public IntegerVectorSetExpression() { } 58 [StorableConstructor] 59 protected IntegerVectorSetExpression(bool deserializing) : base(deserializing) { } 60 61 public override bool IsNoop(IInternalPushInterpreter interpreter) { 62 return IsNoop(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack, true); 63 } 64 65 public override void Eval(IInternalPushInterpreter interpreter) { 66 Eval(interpreter, interpreter.IntegerVectorStack, interpreter.IntegerStack, true); 52 67 } 53 68 } 54 69 70 [StorableClass] 55 71 [PushExpression(StackTypes.FloatVector, "FLOAT[].SET", StackTypes.Float | StackTypes.Integer)] 56 72 public class FloatVectorSetExpression : VectorSetExpression<double> { 57 public override bool Eval(IInternalPushInterpreter interpreter) { 58 return Eval(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack); 73 public FloatVectorSetExpression() { } 74 [StorableConstructor] 75 protected FloatVectorSetExpression(bool deserializing) : base(deserializing) { } 76 77 public override bool IsNoop(IInternalPushInterpreter interpreter) { 78 return IsNoop(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack); 79 } 80 81 public override void Eval(IInternalPushInterpreter interpreter) { 82 Eval(interpreter, interpreter.FloatVectorStack, interpreter.FloatStack); 59 83 } 60 84 } 61 85 86 [StorableClass] 62 87 [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].SET", StackTypes.Boolean | StackTypes.Integer)] 63 88 public class BooleanVectorSetExpression : VectorSetExpression<bool> { 64 public override bool Eval(IInternalPushInterpreter interpreter) { 65 return Eval(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack); 89 public BooleanVectorSetExpression() { } 90 [StorableConstructor] 91 protected BooleanVectorSetExpression(bool deserializing) : base(deserializing) { } 92 93 public override bool IsNoop(IInternalPushInterpreter interpreter) { 94 return IsNoop(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack); 95 } 96 97 public override void Eval(IInternalPushInterpreter interpreter) { 98 Eval(interpreter, interpreter.BooleanVectorStack, interpreter.BooleanStack); 66 99 } 67 100 } 68 101 102 [StorableClass] 69 103 [PushExpression(StackTypes.StringVector, "STRING[].SET", StackTypes.String | StackTypes.Integer)] 70 104 public class StringVectorSetExpression : VectorSetExpression<string> { 71 public override bool Eval(IInternalPushInterpreter interpreter) { 72 return Eval(interpreter, interpreter.StringVectorStack, interpreter.StringStack); 105 public StringVectorSetExpression() { } 106 [StorableConstructor] 107 protected StringVectorSetExpression(bool deserializing) : base(deserializing) { } 108 109 public override bool IsNoop(IInternalPushInterpreter interpreter) { 110 return IsNoop(interpreter, interpreter.StringVectorStack, interpreter.StringStack); 111 } 112 113 public override void Eval(IInternalPushInterpreter interpreter) { 114 Eval(interpreter, interpreter.StringVectorStack, interpreter.StringStack); 73 115 } 74 116 }
Note: See TracChangeset
for help on using the changeset viewer.