Changeset 14513 for branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/RandExpressions.cs
- Timestamp:
- 12/20/16 22:57:11 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/RandExpressions.cs
r14398 r14513 1 using HeuristicLab.Algorithms.PushGP.Generators; 2 using HeuristicLab.Algorithms.PushGP.Interpreter; 1 namespace HeuristicLab.Algorithms.PushGP.Expressions 2 { 3 using HeuristicLab.Algorithms.PushGP.Generators; 4 using HeuristicLab.Algorithms.PushGP.Interpreter; 3 5 4 namespace HeuristicLab.Algorithms.PushGP.Expressions 5 { 6 /// <summary>7 /// Pushes a random NAME.8 /// </summary>9 p ublic class NameRandExpression : StatelessExpression6 /// <summary> 7 /// Pushes a random NAME. 8 /// </summary> 9 public class NameRandExpression : StatelessExpression 10 { 11 protected override string InitStringRepresentation() 10 12 { 11 protected override string InitStringRepresentation() { return "NAME.RAND"; } 12 13 public override void Eval(IInterpreter interpreter) 14 { 15 var name = NameGenerator.RandomName(); 16 17 interpreter.NameStack.Push(name); 18 } 13 return "NAME.RAND"; 19 14 } 20 15 21 /// <summary> 22 /// Pushes a random integer. 23 /// </summary> 24 public class IntegerRandExpression : StatelessExpression 16 public override void Eval(IPushGpInterpreter interpreter) 25 17 { 26 protected override string InitStringRepresentation() { return "INTEGER.RAND"; }18 var name = NameGenerator.RandomName(); 27 19 28 public override void Eval(IInterpreter interpreter) 29 { 30 var value = IntegerGenerator.RandomInteger( 31 interpreter.Configuration.MinRandomInteger, 32 interpreter.Configuration.MaxRandomInteger); 20 interpreter.NameStack.Push(name); 21 } 22 } 33 23 34 interpreter.IntegerStack.Push(value); 35 } 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"; 36 32 } 37 33 38 /// <summary> 39 /// Pushes a random float. 40 /// </summary> 41 public class FloatRandExpression : StatelessExpression 34 public override void Eval(IPushGpInterpreter interpreter) 42 35 { 43 protected override string InitStringRepresentation() { return "FLOAT.RAND"; } 36 var value = IntegerGenerator.RandomInteger( 37 interpreter.Configuration.MinRandomInteger, 38 interpreter.Configuration.MaxRandomInteger); 44 39 45 public override void Eval(IInterpreter interpreter) 46 { 47 var value = FloatGenerator.RandomFloat( 48 interpreter.Configuration.MinRandomFloat, 49 interpreter.Configuration.MaxRandomFloat); 40 interpreter.IntegerStack.Push(value); 41 } 42 } 50 43 51 interpreter.FloatStack.Push(value); 52 } 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"; 53 52 } 54 53 55 /// <summary> 56 /// Pushes a random boolean. 57 /// </summary> 58 public class BooleanRandExpression : StatelessExpression 54 public override void Eval(IPushGpInterpreter interpreter) 59 55 { 60 protected override string InitStringRepresentation() { return "BOOLEAN.RAND"; } 56 var value = FloatGenerator.RandomFloat( 57 interpreter.Configuration.MinRandomFloat, 58 interpreter.Configuration.MaxRandomFloat); 61 59 62 public override void Eval(IInterpreter interpreter)63 {64 var value = BooleanGenerator.RandomBoolean();60 interpreter.FloatStack.Push(value); 61 } 62 } 65 63 66 interpreter.BooleanStack.Push(value); 67 } 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"; 68 72 } 69 73 70 /// <summary> 71 /// Pushes random expressions onto the code stack. 72 /// </summary> 73 public class CodeRandExpression : StatelessExpression 74 public override void Eval(IPushGpInterpreter interpreter) 74 75 { 75 protected override string InitStringRepresentation() { return "CODE.RAND"; }76 var value = BooleanGenerator.RandomBoolean(); 76 77 77 public override void Eval(IInterpreter interpreter) 78 { 79 if (interpreter.IntegerStack.Count == 0 || 80 interpreter.IntegerStack.Top < 1) 81 return; 78 interpreter.BooleanStack.Push(value); 79 } 80 } 82 81 83 var size = (int)(interpreter.IntegerStack.Pop() % interpreter.Configuration.MaxPointsInRandomExpression); 84 var expression = interpreter.CodeGenerator.RandomCode(size); 85 } 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"; 86 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 } 87 103 }
Note: See TracChangeset
for help on using the changeset viewer.