Changeset 14952 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/SwapExpressions.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/SwapExpressions.cs
r14875 r14952 2 2 using System.Collections.Generic; 3 3 4 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 4 5 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 5 6 … … 11 12 /// </summary> 12 13 /// <typeparam name="T">Stacktype</typeparam> 14 [StorableClass] 13 15 public abstract class SwapExpression<T> : StatelessExpression { 14 public bool Eval(IPushStack<T> stack) { 15 if (stack.Count < 2) 16 return false; 17 16 protected SwapExpression() { } 17 [StorableConstructor] 18 protected SwapExpression(bool deserializing) : base(deserializing) { } 19 20 protected void Eval(IPushStack<T> stack) { 18 21 stack.Swap(2); 19 return true;20 21 } 22 22 } 23 } 24 25 [StorableClass] 23 26 [PushExpression(StackTypes.Integer, "INTEGER.SWAP")] 24 27 public class IntegerSwapExpression : SwapExpression<long> { 25 public override bool Eval(IInternalPushInterpreter interpreter) { 26 return Eval(interpreter.IntegerStack); 27 } 28 } 29 28 public IntegerSwapExpression() { } 29 [StorableConstructor] 30 protected IntegerSwapExpression(bool deserializing) : base(deserializing) { } 31 32 public override bool IsNoop(IInternalPushInterpreter interpreter) { 33 return interpreter.IntegerStack.Count < 2; 34 } 35 36 public override void Eval(IInternalPushInterpreter interpreter) { 37 Eval(interpreter.IntegerStack); 38 } 39 } 40 41 [StorableClass] 30 42 [PushExpression(StackTypes.Float, "FLOAT.SWAP")] 31 43 public class FloatSwapExpression : SwapExpression<double> { 32 public override bool Eval(IInternalPushInterpreter interpreter) { 33 return Eval(interpreter.FloatStack); 34 } 35 } 36 44 public FloatSwapExpression() { } 45 [StorableConstructor] 46 protected FloatSwapExpression(bool deserializing) : base(deserializing) { } 47 48 public override bool IsNoop(IInternalPushInterpreter interpreter) { 49 return interpreter.FloatStack.Count < 2; 50 } 51 52 public override void Eval(IInternalPushInterpreter interpreter) { 53 Eval(interpreter.FloatStack); 54 } 55 } 56 57 [StorableClass] 37 58 [PushExpression(StackTypes.Boolean, "BOOLEAN.SWAP")] 38 59 public class BooleanSwapExpression : SwapExpression<bool> { 39 public override bool Eval(IInternalPushInterpreter interpreter) { 40 return Eval(interpreter.BooleanStack); 41 } 42 } 43 60 public BooleanSwapExpression() { } 61 [StorableConstructor] 62 protected BooleanSwapExpression(bool deserializing) : base(deserializing) { } 63 64 public override bool IsNoop(IInternalPushInterpreter interpreter) { 65 return interpreter.BooleanStack.Count < 2; 66 } 67 68 public override void Eval(IInternalPushInterpreter interpreter) { 69 Eval(interpreter.BooleanStack); 70 } 71 } 72 73 [StorableClass] 44 74 [PushExpression(StackTypes.Name, "NAME.SWAP")] 45 75 public class NameSwapExpression : SwapExpression<string> { 46 public override bool Eval(IInternalPushInterpreter interpreter) { 47 return Eval(interpreter.NameStack); 48 } 49 } 50 76 public NameSwapExpression() { } 77 [StorableConstructor] 78 protected NameSwapExpression(bool deserializing) : base(deserializing) { } 79 80 public override bool IsNoop(IInternalPushInterpreter interpreter) { 81 return interpreter.NameStack.Count < 2; 82 } 83 84 public override void Eval(IInternalPushInterpreter interpreter) { 85 Eval(interpreter.NameStack); 86 } 87 } 88 89 [StorableClass] 51 90 [PushExpression(StackTypes.Exec, "EXEC.SWAP")] 52 91 public class ExecSwapExpression : SwapExpression<Expression> { 53 public override bool Eval(IInternalPushInterpreter interpreter) { 54 return Eval(interpreter.ExecStack); 55 } 56 } 57 92 public ExecSwapExpression() { } 93 [StorableConstructor] 94 protected ExecSwapExpression(bool deserializing) : base(deserializing) { } 95 96 public override bool IsNoop(IInternalPushInterpreter interpreter) { 97 return interpreter.ExecStack.Count < 2; 98 } 99 100 public override void Eval(IInternalPushInterpreter interpreter) { 101 Eval(interpreter.ExecStack); 102 } 103 } 104 105 [StorableClass] 58 106 [PushExpression(StackTypes.Code, "CODE.SWAP")] 59 107 public class CodeSwapExpression : SwapExpression<Expression> { 60 public override bool Eval(IInternalPushInterpreter interpreter) { 61 return Eval(interpreter.CodeStack); 62 } 63 } 64 108 public CodeSwapExpression() { } 109 [StorableConstructor] 110 protected CodeSwapExpression(bool deserializing) : base(deserializing) { } 111 112 public override bool IsNoop(IInternalPushInterpreter interpreter) { 113 return interpreter.CodeStack.Count < 2; 114 } 115 116 public override void Eval(IInternalPushInterpreter interpreter) { 117 Eval(interpreter.CodeStack); 118 } 119 } 120 121 [StorableClass] 65 122 [PushExpression(StackTypes.Char, "CHAR.SWAP")] 66 123 public class CharSwapExpression : SwapExpression<char> { 67 public override bool Eval(IInternalPushInterpreter interpreter) { 68 return Eval(interpreter.CharStack); 69 } 70 } 71 124 public CharSwapExpression() { } 125 [StorableConstructor] 126 protected CharSwapExpression(bool deserializing) : base(deserializing) { } 127 128 public override bool IsNoop(IInternalPushInterpreter interpreter) { 129 return interpreter.CharStack.Count < 2; 130 } 131 132 public override void Eval(IInternalPushInterpreter interpreter) { 133 Eval(interpreter.CharStack); 134 } 135 } 136 137 [StorableClass] 72 138 [PushExpression(StackTypes.String, "STRING.SWAP")] 73 139 public class StringSwapExpression : SwapExpression<string> { 74 public override bool Eval(IInternalPushInterpreter interpreter) { 75 return Eval(interpreter.StringStack); 76 } 77 } 78 140 public StringSwapExpression() { } 141 [StorableConstructor] 142 protected StringSwapExpression(bool deserializing) : base(deserializing) { } 143 144 public override bool IsNoop(IInternalPushInterpreter interpreter) { 145 return interpreter.StringStack.Count < 2; 146 } 147 148 public override void Eval(IInternalPushInterpreter interpreter) { 149 Eval(interpreter.StringStack); 150 } 151 } 152 153 [StorableClass] 79 154 [PushExpression(StackTypes.IntegerVector, "INTEGER[].SWAP")] 80 155 public class IntegerVectorSwapExpression : SwapExpression<List<long>> { 81 public override bool Eval(IInternalPushInterpreter interpreter) { 82 return Eval(interpreter.IntegerVectorStack); 83 } 84 } 85 156 public IntegerVectorSwapExpression() { } 157 [StorableConstructor] 158 protected IntegerVectorSwapExpression(bool deserializing) : base(deserializing) { } 159 160 public override bool IsNoop(IInternalPushInterpreter interpreter) { 161 return interpreter.IntegerVectorStack.Count < 2; 162 } 163 164 public override void Eval(IInternalPushInterpreter interpreter) { 165 Eval(interpreter.IntegerVectorStack); 166 } 167 } 168 169 [StorableClass] 86 170 [PushExpression(StackTypes.FloatVector, "FLOAT[].SWAP")] 87 171 public class FloatVectorSwapExpression : SwapExpression<List<double>> { 88 public override bool Eval(IInternalPushInterpreter interpreter) { 89 return Eval(interpreter.FloatVectorStack); 90 } 91 } 92 172 public FloatVectorSwapExpression() { } 173 [StorableConstructor] 174 protected FloatVectorSwapExpression(bool deserializing) : base(deserializing) { } 175 176 public override bool IsNoop(IInternalPushInterpreter interpreter) { 177 return interpreter.FloatVectorStack.Count < 2; 178 } 179 180 public override void Eval(IInternalPushInterpreter interpreter) { 181 Eval(interpreter.FloatVectorStack); 182 } 183 } 184 185 [StorableClass] 93 186 [PushExpression(StackTypes.BooleanVector, "BOOLEAN[].SWAP")] 94 187 public class BooleanVectorSwapExpression : SwapExpression<List<bool>> { 95 public override bool Eval(IInternalPushInterpreter interpreter) { 96 return Eval(interpreter.BooleanVectorStack); 97 } 98 } 99 188 public BooleanVectorSwapExpression() { } 189 [StorableConstructor] 190 protected BooleanVectorSwapExpression(bool deserializing) : base(deserializing) { } 191 192 public override bool IsNoop(IInternalPushInterpreter interpreter) { 193 return interpreter.BooleanVectorStack.Count < 2; 194 } 195 196 public override void Eval(IInternalPushInterpreter interpreter) { 197 Eval(interpreter.BooleanVectorStack); 198 } 199 } 200 201 [StorableClass] 100 202 [PushExpression(StackTypes.StringVector, "STRING[].SWAP")] 101 203 public class StringVectorSwapExpression : SwapExpression<List<string>> { 102 public override bool Eval(IInternalPushInterpreter interpreter) { 103 return Eval(interpreter.StringVectorStack); 204 public StringVectorSwapExpression() { } 205 [StorableConstructor] 206 protected StringVectorSwapExpression(bool deserializing) : base(deserializing) { } 207 208 public override bool IsNoop(IInternalPushInterpreter interpreter) { 209 return interpreter.StringVectorStack.Count < 2; 210 } 211 212 public override void Eval(IInternalPushInterpreter interpreter) { 213 Eval(interpreter.StringVectorStack); 104 214 } 105 215 }
Note: See TracChangeset
for help on using the changeset viewer.