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