[14398] | 1 | using System;
|
---|
| 2 | using HeuristicLab.Algorithms.PushGP.Generators;
|
---|
[14392] | 3 | using HeuristicLab.Algorithms.PushGP.Interpreter;
|
---|
| 4 | using HeuristicLab.Algorithms.PushGP.Stack;
|
---|
[14398] | 5 | using HeuristicLab.Common;
|
---|
[14392] | 6 | using HeuristicLab.Core;
|
---|
| 7 | using HeuristicLab.Random;
|
---|
| 8 |
|
---|
| 9 | namespace HeuristicLab.Algorithms.PushGP.Expressions
|
---|
| 10 | {
|
---|
| 11 | public abstract class ERCExpression<T> : Expression
|
---|
| 12 | {
|
---|
| 13 | private readonly T value;
|
---|
[14398] | 14 |
|
---|
| 15 | public ERCExpression(T value)
|
---|
[14392] | 16 | {
|
---|
| 17 | this.value = value;
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | protected void Eval(IStack<T> stack)
|
---|
| 21 | {
|
---|
[14398] | 22 | stack.Push(value);
|
---|
[14392] | 23 | }
|
---|
[14398] | 24 |
|
---|
| 25 | /// <summary>
|
---|
| 26 | /// Does not make sense
|
---|
| 27 | /// </summary>
|
---|
| 28 | /// <returns></returns>
|
---|
| 29 | protected override string InitStringRepresentation()
|
---|
| 30 | {
|
---|
| 31 | throw new NotImplementedException();
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | /// <summary>
|
---|
| 35 | /// Does not make sense
|
---|
| 36 | /// </summary>
|
---|
| 37 | /// <returns></returns>
|
---|
| 38 | protected override int InitId()
|
---|
| 39 | {
|
---|
| 40 | throw new NotImplementedException();
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | /// <summary>
|
---|
| 44 | /// Does not make sense
|
---|
| 45 | /// </summary>
|
---|
| 46 | /// <returns></returns>
|
---|
| 47 | public override IDeepCloneable Clone(Cloner cloner)
|
---|
| 48 | {
|
---|
| 49 | throw new NotImplementedException();
|
---|
| 50 | }
|
---|
[14392] | 51 | }
|
---|
| 52 |
|
---|
| 53 | public class IntegerERCExpression : ERCExpression<long>
|
---|
| 54 | {
|
---|
[14398] | 55 | public IntegerERCExpression() : base(IntegerGenerator.RandomInteger())
|
---|
[14392] | 56 | {
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | public override void Eval(IInterpreter interpreter)
|
---|
| 60 | {
|
---|
[14398] | 61 | Eval(interpreter.IntegerStack);
|
---|
[14392] | 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | public class FloatERCExpression : ERCExpression<double>
|
---|
| 66 | {
|
---|
| 67 | protected bool isInitialized = false;
|
---|
| 68 |
|
---|
[14398] | 69 | public FloatERCExpression() : base(FloatGenerator.RandomFloat())
|
---|
[14392] | 70 | {
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | public override void Eval(IInterpreter interpreter)
|
---|
| 74 | {
|
---|
[14398] | 75 | Eval(interpreter.FloatStack);
|
---|
[14392] | 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | public class BooleanERCExpression : ERCExpression<bool>
|
---|
| 80 | {
|
---|
[14398] | 81 | public BooleanERCExpression() : base(BooleanGenerator.RandomBoolean())
|
---|
[14392] | 82 | {
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | public override void Eval(IInterpreter interpreter)
|
---|
| 86 | {
|
---|
[14398] | 87 | Eval(interpreter.BooleanStack);
|
---|
[14392] | 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | public class NameERCExpression : ERCExpression<string>
|
---|
| 92 | {
|
---|
| 93 | private static IRandom random = new FastRandom();
|
---|
| 94 |
|
---|
[14398] | 95 | public NameERCExpression() : base(NameGenerator.RandomName())
|
---|
[14392] | 96 | {
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | public override void Eval(IInterpreter interpreter)
|
---|
| 100 | {
|
---|
[14398] | 101 | Eval(interpreter.NameStack);
|
---|
[14392] | 102 | }
|
---|
| 103 | }
|
---|
| 104 | }
|
---|