1 | namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
|
---|
2 | using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
|
---|
3 | using HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator;
|
---|
4 | using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
|
---|
5 | using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
|
---|
6 |
|
---|
7 | /// <summary>
|
---|
8 | /// Pushes a random NAME.
|
---|
9 | /// </summary>
|
---|
10 | [PushExpression(StackTypes.Name, "NAME.RAND")]
|
---|
11 | public class NameRandExpression : StatelessExpression {
|
---|
12 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
13 | if (!interpreter.Configuration.ErcOptions.NameErcOptions.IsEnabled)
|
---|
14 | return false;
|
---|
15 |
|
---|
16 | var name = interpreter.Configuration.ErcOptions.NameErcOptions.GetErcValue(interpreter.Random);
|
---|
17 | interpreter.NameStack.Push(name);
|
---|
18 | return true;
|
---|
19 | }
|
---|
20 | }
|
---|
21 |
|
---|
22 | /// <summary>
|
---|
23 | /// Pushes a random integer.
|
---|
24 | /// </summary>
|
---|
25 | [PushExpression(StackTypes.Integer, "INTEGER.RAND")]
|
---|
26 | public class IntegerRandExpression : StatelessExpression {
|
---|
27 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
28 | if (!interpreter.Configuration.ErcOptions.IntegerErcOptions.IsEnabled)
|
---|
29 | return false;
|
---|
30 |
|
---|
31 | var value = interpreter.Configuration.ErcOptions.IntegerErcOptions.GetErcValue(interpreter.Random);
|
---|
32 | interpreter.IntegerStack.Push(value);
|
---|
33 | return true;
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | /// <summary>
|
---|
38 | /// Pushes a random float.
|
---|
39 | /// </summary>
|
---|
40 | [PushExpression(StackTypes.Float, "FLOAT.RAND")]
|
---|
41 | public class FloatRandExpression : StatelessExpression {
|
---|
42 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
43 | if (!interpreter.Configuration.ErcOptions.FloatErcOptions.IsEnabled)
|
---|
44 | return false;
|
---|
45 |
|
---|
46 | var value = interpreter.Configuration.ErcOptions.FloatErcOptions.GetErcValue(interpreter.Random);
|
---|
47 | interpreter.FloatStack.Push(value);
|
---|
48 | return true;
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | /// <summary>
|
---|
53 | /// Pushes a random boolean.
|
---|
54 | /// </summary>
|
---|
55 | [PushExpression(StackTypes.Boolean, "BOOLEAN.RAND")]
|
---|
56 | public class BooleanRandExpression : StatelessExpression {
|
---|
57 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
58 | if (!interpreter.Configuration.ErcOptions.BooleanErcOptions.IsEnabled)
|
---|
59 | return false;
|
---|
60 |
|
---|
61 | var value = interpreter.Configuration.ErcOptions.BooleanErcOptions.GetErcValue(interpreter.Random);
|
---|
62 | interpreter.BooleanStack.Push(value);
|
---|
63 | return true;
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | /// <summary>
|
---|
68 | /// Pushes random expressions onto the code stack.
|
---|
69 | /// </summary>
|
---|
70 | [PushExpression(StackTypes.Code, "CODE.RAND")]
|
---|
71 | public class CodeRandExpression : StatelessExpression {
|
---|
72 | public override bool Eval(IInternalPushInterpreter interpreter) {
|
---|
73 | if (interpreter.IntegerStack.Count == 0 ||
|
---|
74 | interpreter.IntegerStack.Top < 1) return false;
|
---|
75 |
|
---|
76 | var size = (int)(interpreter.IntegerStack.Pop() % interpreter.Configuration.MaxPointsInRandomExpression);
|
---|
77 | var program = LinearCodeGenerator.RandomProgram(
|
---|
78 | interpreter.PoolContainer.PushProgramPool,
|
---|
79 | interpreter.PoolContainer.ExpressionListPool,
|
---|
80 | size,
|
---|
81 | interpreter.Random,
|
---|
82 | interpreter.Configuration,
|
---|
83 | interpreter.CustomExpressions);
|
---|
84 |
|
---|
85 | interpreter.CodeStack.Push(program);
|
---|
86 | return true;
|
---|
87 | }
|
---|
88 | }
|
---|
89 | } |
---|