[15771] | 1 | using System.Collections.Generic;
|
---|
| 2 | using System.Linq;
|
---|
| 3 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; |
---|
| 4 | |
---|
| 5 | namespace HeuristicLab.Problems.ProgramSynthesis { |
---|
[15017] | 6 |
|
---|
[14727] | 7 | /// <summary>
|
---|
[15032] | 8 | /// Pushes a random already defined name or a new one onto the NAME stack.
|
---|
[14727] | 9 | /// </summary>
|
---|
[15032] | 10 | [PushExpression(
|
---|
| 11 | StackTypes.Name,
|
---|
| 12 | "NAME.RAND",
|
---|
| 13 | "Pushes a random already defined name or a new one based on the Name-ERC-Options onto the NAME stack.")]
|
---|
[14952] | 14 | [StorableClass]
|
---|
[14727] | 15 | public class NameRandExpression : StatelessExpression {
|
---|
[14952] | 16 | public NameRandExpression() { }
|
---|
| 17 | [StorableConstructor]
|
---|
| 18 | protected NameRandExpression(bool deserializing) : base(deserializing) { }
|
---|
[14727] | 19 |
|
---|
[14952] | 20 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 21 | return !interpreter.Configuration.ErcOptions.NameErcOptions.IsEnabled;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
[14897] | 25 | var name = interpreter.Configuration.ErcOptions.NameErcOptions.GetErcValue(interpreter.Random);
|
---|
[14727] | 26 | interpreter.NameStack.Push(name);
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | /// <summary>
|
---|
[15032] | 31 | /// Pushes a random integer.
|
---|
[14727] | 32 | /// </summary>
|
---|
[15032] | 33 | [PushExpression(
|
---|
| 34 | StackTypes.Integer,
|
---|
| 35 | "INTEGER.RAND",
|
---|
| 36 | "Pushes a random integer based on the Integer-ERC-Options onto the INTEGER stack.")]
|
---|
[14952] | 37 | [StorableClass]
|
---|
[14727] | 38 | public class IntegerRandExpression : StatelessExpression {
|
---|
[14952] | 39 | public IntegerRandExpression() { }
|
---|
| 40 | [StorableConstructor]
|
---|
| 41 | protected IntegerRandExpression(bool deserializing) : base(deserializing) { }
|
---|
[14727] | 42 |
|
---|
[14952] | 43 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 44 | return !interpreter.Configuration.ErcOptions.IntegerErcOptions.IsEnabled;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
[14897] | 48 | var value = interpreter.Configuration.ErcOptions.IntegerErcOptions.GetErcValue(interpreter.Random);
|
---|
[14727] | 49 | interpreter.IntegerStack.Push(value);
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | /// <summary>
|
---|
[15032] | 54 | /// Pushes a random float.
|
---|
[14727] | 55 | /// </summary>
|
---|
[15032] | 56 | [PushExpression(
|
---|
| 57 | StackTypes.Float,
|
---|
| 58 | "FLOAT.RAND",
|
---|
| 59 | "Pushes a random float based on the Float-ERC-Options onto the FLOAT stack.")]
|
---|
[14952] | 60 | [StorableClass]
|
---|
[14727] | 61 | public class FloatRandExpression : StatelessExpression {
|
---|
[14952] | 62 | public FloatRandExpression() { }
|
---|
| 63 | [StorableConstructor]
|
---|
| 64 | protected FloatRandExpression(bool deserializing) : base(deserializing) { }
|
---|
[14727] | 65 |
|
---|
[14952] | 66 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 67 | return !interpreter.Configuration.ErcOptions.FloatErcOptions.IsEnabled;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
[14897] | 71 | var value = interpreter.Configuration.ErcOptions.FloatErcOptions.GetErcValue(interpreter.Random);
|
---|
[14727] | 72 | interpreter.FloatStack.Push(value);
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | /// <summary>
|
---|
| 77 | /// Pushes a random boolean.
|
---|
| 78 | /// </summary>
|
---|
[15032] | 79 | [PushExpression(
|
---|
| 80 | StackTypes.Boolean,
|
---|
| 81 | "BOOLEAN.RAND",
|
---|
| 82 | "Pushes a random boolean based on the Boolean-ERC-Options onto the BOOLEAN stack.")]
|
---|
[14952] | 83 | [StorableClass]
|
---|
[14727] | 84 | public class BooleanRandExpression : StatelessExpression {
|
---|
[14952] | 85 | public BooleanRandExpression() { }
|
---|
| 86 | [StorableConstructor]
|
---|
| 87 | protected BooleanRandExpression(bool deserializing) : base(deserializing) { }
|
---|
[14727] | 88 |
|
---|
[14952] | 89 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 90 | return !interpreter.Configuration.ErcOptions.BooleanErcOptions.IsEnabled;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
[14897] | 94 | var value = interpreter.Configuration.ErcOptions.BooleanErcOptions.GetErcValue(interpreter.Random);
|
---|
[14727] | 95 | interpreter.BooleanStack.Push(value);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /// <summary>
|
---|
| 100 | /// Pushes random expressions onto the code stack.
|
---|
| 101 | /// </summary>
|
---|
[15032] | 102 | [PushExpression(
|
---|
| 103 | StackTypes.Code,
|
---|
| 104 | "CODE.RAND",
|
---|
| 105 | "Pushes a random code onto the CODE stack.")]
|
---|
[14952] | 106 | [StorableClass]
|
---|
[14727] | 107 | public class CodeRandExpression : StatelessExpression {
|
---|
[14952] | 108 | public CodeRandExpression() { }
|
---|
| 109 | [StorableConstructor]
|
---|
| 110 | protected CodeRandExpression(bool deserializing) : base(deserializing) { }
|
---|
[14727] | 111 |
|
---|
[14952] | 112 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 113 | return interpreter.IntegerStack.Count == 0 || interpreter.IntegerStack.Top < 1;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
[15017] | 117 | var size = interpreter.IntegerStack.Pop().AsInt(interpreter.Configuration.MaxPointsInRandomExpression);
|
---|
[14777] | 118 | var program = LinearCodeGenerator.RandomProgram(
|
---|
| 119 | interpreter.PoolContainer.PushProgramPool,
|
---|
| 120 | interpreter.PoolContainer.ExpressionListPool,
|
---|
[14744] | 121 | size,
|
---|
| 122 | interpreter.Random,
|
---|
| 123 | interpreter.Configuration,
|
---|
| 124 | interpreter.CustomExpressions);
|
---|
[14727] | 125 |
|
---|
| 126 | interpreter.CodeStack.Push(program);
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
[15017] | 129 |
|
---|
| 130 | /// <summary>
|
---|
| 131 | /// Pushes a random char.
|
---|
| 132 | /// </summary>
|
---|
[15032] | 133 | [PushExpression(
|
---|
| 134 | StackTypes.Char,
|
---|
| 135 | "CHAR.RAND",
|
---|
| 136 | "Pushes a random char based on the Char-ERC-Options onto the CHAR stack.")]
|
---|
[15017] | 137 | [StorableClass]
|
---|
| 138 | public class CharRandExpression : StatelessExpression {
|
---|
| 139 | public CharRandExpression() { }
|
---|
| 140 | [StorableConstructor]
|
---|
| 141 | protected CharRandExpression(bool deserializing) : base(deserializing) { }
|
---|
| 142 |
|
---|
| 143 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 144 | return !interpreter.Configuration.ErcOptions.CharErcOptions.IsEnabled;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 148 | var value = interpreter.Configuration.ErcOptions.CharErcOptions.GetErcValue(interpreter.Random);
|
---|
| 149 | interpreter.CharStack.Push(value);
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | /// <summary>
|
---|
| 153 | /// Pushes a random string.
|
---|
| 154 | /// </summary>
|
---|
[15032] | 155 | [PushExpression(
|
---|
| 156 | StackTypes.String,
|
---|
| 157 | "STRING.RAND",
|
---|
| 158 | "Pushes a random string based on the String-ERC-Options onto the STRING stack.")]
|
---|
[15017] | 159 | [StorableClass]
|
---|
| 160 | public class StringRandExpression : StatelessExpression {
|
---|
| 161 | public StringRandExpression() { }
|
---|
| 162 | [StorableConstructor]
|
---|
| 163 | protected StringRandExpression(bool deserializing) : base(deserializing) { }
|
---|
| 164 |
|
---|
| 165 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 166 | return !interpreter.Configuration.ErcOptions.StringErcOptions.IsEnabled;
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 170 | var value = interpreter.Configuration.ErcOptions.StringErcOptions.GetErcValue(interpreter.Random);
|
---|
| 171 | interpreter.StringStack.Push(value);
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | /// <summary>
|
---|
| 175 | /// Pushes a random interger vector.
|
---|
| 176 | /// </summary>
|
---|
[15032] | 177 | [PushExpression(
|
---|
| 178 | StackTypes.IntegerVector,
|
---|
| 179 | "INTEGER[].RAND",
|
---|
| 180 | "Pushes a random integer vector based on the Integer-Vector-ERC-Options onto the INTEGER[] stack.")]
|
---|
[15017] | 181 | [StorableClass]
|
---|
| 182 | public class IntegerVectorRandExpression : StatelessExpression {
|
---|
| 183 | public IntegerVectorRandExpression() { }
|
---|
| 184 | [StorableConstructor]
|
---|
| 185 | protected IntegerVectorRandExpression(bool deserializing) : base(deserializing) { }
|
---|
| 186 |
|
---|
| 187 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 188 | return !interpreter.Configuration.ErcOptions.IntegerVectorErcOptions.IsEnabled;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 192 | var value = interpreter.Configuration.ErcOptions.IntegerVectorErcOptions.GetErcValue(interpreter.Random);
|
---|
| 193 | interpreter.IntegerVectorStack.Push(new List<long>(value.Select(i => (long)i)));
|
---|
| 194 | }
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | /// <summary>
|
---|
| 198 | /// Pushes a random float vector.
|
---|
| 199 | /// </summary>
|
---|
[15032] | 200 | [PushExpression(
|
---|
| 201 | StackTypes.FloatVector,
|
---|
| 202 | "FLOAT[].RAND",
|
---|
| 203 | "Pushes a random float vector based on the Float-Vector-ERC-Options onto the FLOAT[] stack.")]
|
---|
[15017] | 204 | [StorableClass]
|
---|
| 205 | public class FloatVectorRandExpression : StatelessExpression {
|
---|
| 206 | public FloatVectorRandExpression() { }
|
---|
| 207 | [StorableConstructor]
|
---|
| 208 | protected FloatVectorRandExpression(bool deserializing) : base(deserializing) { }
|
---|
| 209 |
|
---|
| 210 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 211 | return !interpreter.Configuration.ErcOptions.FloatVectorErcOptions.IsEnabled;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 215 | var value = interpreter.Configuration.ErcOptions.FloatVectorErcOptions.GetErcValue(interpreter.Random);
|
---|
| 216 | interpreter.FloatVectorStack.Push(value);
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | /// <summary>
|
---|
| 221 | /// Pushes a random boolean vector.
|
---|
| 222 | /// </summary>
|
---|
[15032] | 223 | [PushExpression(
|
---|
| 224 | StackTypes.StringVector,
|
---|
| 225 | "STRING[].RAND",
|
---|
| 226 | "Pushes a random string vector based on the String-Vector-ERC-Options onto the STRING[] stack.")]
|
---|
[15017] | 227 | [StorableClass]
|
---|
| 228 | public class StringVectorRandExpression : StatelessExpression {
|
---|
| 229 | public StringVectorRandExpression() { }
|
---|
| 230 | [StorableConstructor]
|
---|
| 231 | protected StringVectorRandExpression(bool deserializing) : base(deserializing) { }
|
---|
| 232 |
|
---|
| 233 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 234 | return !interpreter.Configuration.ErcOptions.StringVectorErcOptions.IsEnabled;
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
| 238 | var value = interpreter.Configuration.ErcOptions.StringVectorErcOptions.GetErcValue(interpreter.Random);
|
---|
| 239 | interpreter.StringVectorStack.Push(value);
|
---|
| 240 | }
|
---|
| 241 | }
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
[14727] | 244 | } |
---|