1 | using System;
|
---|
2 | using HeuristicLab.Algorithms.PushGP.Generators;
|
---|
3 | using HeuristicLab.Algorithms.PushGP.Interpreter;
|
---|
4 | using HeuristicLab.Algorithms.PushGP.Stack;
|
---|
5 | using HeuristicLab.Common;
|
---|
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;
|
---|
14 |
|
---|
15 | public ERCExpression(T value)
|
---|
16 | {
|
---|
17 | this.value = value;
|
---|
18 | }
|
---|
19 |
|
---|
20 | protected void Eval(IStack<T> stack)
|
---|
21 | {
|
---|
22 | stack.Push(value);
|
---|
23 | }
|
---|
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 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | public class IntegerERCExpression : ERCExpression<long>
|
---|
54 | {
|
---|
55 | public IntegerERCExpression() : base(IntegerGenerator.RandomInteger())
|
---|
56 | {
|
---|
57 | }
|
---|
58 |
|
---|
59 | public override void Eval(IInterpreter interpreter)
|
---|
60 | {
|
---|
61 | Eval(interpreter.IntegerStack);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | public class FloatERCExpression : ERCExpression<double>
|
---|
66 | {
|
---|
67 | protected bool isInitialized = false;
|
---|
68 |
|
---|
69 | public FloatERCExpression() : base(FloatGenerator.RandomFloat())
|
---|
70 | {
|
---|
71 | }
|
---|
72 |
|
---|
73 | public override void Eval(IInterpreter interpreter)
|
---|
74 | {
|
---|
75 | Eval(interpreter.FloatStack);
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | public class BooleanERCExpression : ERCExpression<bool>
|
---|
80 | {
|
---|
81 | public BooleanERCExpression() : base(BooleanGenerator.RandomBoolean())
|
---|
82 | {
|
---|
83 | }
|
---|
84 |
|
---|
85 | public override void Eval(IInterpreter interpreter)
|
---|
86 | {
|
---|
87 | Eval(interpreter.BooleanStack);
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | public class NameERCExpression : ERCExpression<string>
|
---|
92 | {
|
---|
93 | private static IRandom random = new FastRandom();
|
---|
94 |
|
---|
95 | public NameERCExpression() : base(NameGenerator.RandomName())
|
---|
96 | {
|
---|
97 | }
|
---|
98 |
|
---|
99 | public override void Eval(IInterpreter interpreter)
|
---|
100 | {
|
---|
101 | Eval(interpreter.NameStack);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|