using HeuristicLab.Algorithms.PushGP.Generators;
using HeuristicLab.Algorithms.PushGP.Interpreter;
namespace HeuristicLab.Algorithms.PushGP.Expressions
{
///
/// Pushes a random NAME.
///
public class NameRandExpression : Expression
{
public NameRandExpression() : base("NAME.RAND")
{
}
public override void Eval(IInterpreter interpreter)
{
var name = NameGenerator.RandomName();
interpreter.NameStack.Push(name);
}
}
///
/// Pushes a random integer.
///
public class IntegerRandExpression : Expression
{
public IntegerRandExpression() : base("INTEGER.RAND")
{
}
public override void Eval(IInterpreter interpreter)
{
var value = IntegerGenerator.RandomInteger(
interpreter.Configuration.MinRandomInteger,
interpreter.Configuration.MaxRandomInteger);
interpreter.IntegerStack.Push(value);
}
}
///
/// Pushes a random float.
///
public class FloatRandExpression : Expression
{
public FloatRandExpression() : base("FLOAT.RAND")
{
}
public override void Eval(IInterpreter interpreter)
{
var value = FloatGenerator.RandomFloat(
interpreter.Configuration.MinRandomFloat,
interpreter.Configuration.MaxRandomFloat);
interpreter.FloatStack.Push(value);
}
}
///
/// Pushes a random boolean.
///
public class BooleanRandExpression : Expression
{
public BooleanRandExpression() : base("BOOLEAN.RAND")
{
}
public override void Eval(IInterpreter interpreter)
{
var value = BooleanGenerator.RandomBoolean();
interpreter.BooleanStack.Push(value);
}
}
///
/// Pushes random expressions onto the code stack.
///
public class CodeRandExpression : Expression
{
public CodeRandExpression() : base("CODE.RAND")
{
}
public override void Eval(IInterpreter interpreter)
{
if (interpreter.IntegerStack.Count == 0 ||
interpreter.IntegerStack.Top < 1)
return;
var size = (int)(interpreter.IntegerStack.Pop() % interpreter.Configuration.MaxPointsInRandomExpression);
var expression = interpreter.CodeGenerator.RandomCode(size);
}
}
}