1 | namespace HeuristicLab.Algorithms.PushGP.Expressions
|
---|
2 | {
|
---|
3 | using HeuristicLab.Algorithms.PushGP.Generators;
|
---|
4 | using HeuristicLab.Algorithms.PushGP.Interpreter;
|
---|
5 |
|
---|
6 | /// <summary>
|
---|
7 | /// Pushes a random NAME.
|
---|
8 | /// </summary>
|
---|
9 | public class NameRandExpression : StatelessExpression
|
---|
10 | {
|
---|
11 | protected override string InitStringRepresentation()
|
---|
12 | {
|
---|
13 | return "NAME.RAND";
|
---|
14 | }
|
---|
15 |
|
---|
16 | public override void Eval(IPushGpInterpreter interpreter)
|
---|
17 | {
|
---|
18 | var name = NameGenerator.RandomName();
|
---|
19 |
|
---|
20 | interpreter.NameStack.Push(name);
|
---|
21 | }
|
---|
22 | }
|
---|
23 |
|
---|
24 | /// <summary>
|
---|
25 | /// Pushes a random integer.
|
---|
26 | /// </summary>
|
---|
27 | public class IntegerRandExpression : StatelessExpression
|
---|
28 | {
|
---|
29 | protected override string InitStringRepresentation()
|
---|
30 | {
|
---|
31 | return "INTEGER.RAND";
|
---|
32 | }
|
---|
33 |
|
---|
34 | public override void Eval(IPushGpInterpreter interpreter)
|
---|
35 | {
|
---|
36 | var value = IntegerGenerator.RandomInteger(
|
---|
37 | interpreter.Configuration.MinRandomInteger,
|
---|
38 | interpreter.Configuration.MaxRandomInteger);
|
---|
39 |
|
---|
40 | interpreter.IntegerStack.Push(value);
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | /// <summary>
|
---|
45 | /// Pushes a random float.
|
---|
46 | /// </summary>
|
---|
47 | public class FloatRandExpression : StatelessExpression
|
---|
48 | {
|
---|
49 | protected override string InitStringRepresentation()
|
---|
50 | {
|
---|
51 | return "FLOAT.RAND";
|
---|
52 | }
|
---|
53 |
|
---|
54 | public override void Eval(IPushGpInterpreter interpreter)
|
---|
55 | {
|
---|
56 | var value = FloatGenerator.RandomFloat(
|
---|
57 | interpreter.Configuration.MinRandomFloat,
|
---|
58 | interpreter.Configuration.MaxRandomFloat);
|
---|
59 |
|
---|
60 | interpreter.FloatStack.Push(value);
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | /// <summary>
|
---|
65 | /// Pushes a random boolean.
|
---|
66 | /// </summary>
|
---|
67 | public class BooleanRandExpression : StatelessExpression
|
---|
68 | {
|
---|
69 | protected override string InitStringRepresentation()
|
---|
70 | {
|
---|
71 | return "BOOLEAN.RAND";
|
---|
72 | }
|
---|
73 |
|
---|
74 | public override void Eval(IPushGpInterpreter interpreter)
|
---|
75 | {
|
---|
76 | var value = BooleanGenerator.RandomBoolean();
|
---|
77 |
|
---|
78 | interpreter.BooleanStack.Push(value);
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | /// <summary>
|
---|
83 | /// Pushes random expressions onto the code stack.
|
---|
84 | /// </summary>
|
---|
85 | public class CodeRandExpression : StatelessExpression
|
---|
86 | {
|
---|
87 | protected override string InitStringRepresentation()
|
---|
88 | {
|
---|
89 | return "CODE.RAND";
|
---|
90 | }
|
---|
91 |
|
---|
92 | public override void Eval(IPushGpInterpreter interpreter)
|
---|
93 | {
|
---|
94 | if ((interpreter.IntegerStack.Count == 0) || (interpreter.IntegerStack.Top < 1)) return;
|
---|
95 |
|
---|
96 | var size = (int)(interpreter.IntegerStack.Pop() % interpreter.Configuration.MaxPointsInRandomExpression);
|
---|
97 |
|
---|
98 | var expression = CodeGenerator.RandomProgram(size, interpreter.CustomExpressions);
|
---|
99 |
|
---|
100 | interpreter.CodeStack.Push(expression);
|
---|
101 | }
|
---|
102 | }
|
---|
103 | } |
---|