Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/20/16 22:57:11 (7 years ago)
Author:
pkimmesw
Message:

#2665 Added Problem.ProgramSynthesis Project, Fixed Expression Issues, Fixed Code Generation

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;
     1namespace HeuristicLab.Algorithms.PushGP.Expressions
     2{
     3  using HeuristicLab.Algorithms.PushGP.Generators;
     4  using HeuristicLab.Algorithms.PushGP.Interpreter;
    35
    4 namespace HeuristicLab.Algorithms.PushGP.Expressions
    5 {
    6     /// <summary>
    7     /// Pushes a random NAME.
    8     /// </summary>
    9     public class NameRandExpression : StatelessExpression
     6  /// <summary>
     7  ///     Pushes a random NAME.
     8  /// </summary>
     9  public class NameRandExpression : StatelessExpression
     10  {
     11    protected override string InitStringRepresentation()
    1012    {
    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";
    1914    }
    2015
    21     /// <summary>
    22     /// Pushes a random integer.
    23     /// </summary>
    24     public class IntegerRandExpression : StatelessExpression
     16    public override void Eval(IPushGpInterpreter interpreter)
    2517    {
    26         protected override string InitStringRepresentation() { return "INTEGER.RAND"; }
     18      var name = NameGenerator.RandomName();
    2719
    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  }
    3323
    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";
    3632    }
    3733
    38     /// <summary>
    39     /// Pushes a random float.
    40     /// </summary>
    41     public class FloatRandExpression : StatelessExpression
     34    public override void Eval(IPushGpInterpreter interpreter)
    4235    {
    43         protected override string InitStringRepresentation() { return "FLOAT.RAND"; }
     36      var value = IntegerGenerator.RandomInteger(
     37        interpreter.Configuration.MinRandomInteger,
     38        interpreter.Configuration.MaxRandomInteger);
    4439
    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  }
    5043
    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";
    5352    }
    5453
    55     /// <summary>
    56     /// Pushes a random boolean.
    57     /// </summary>
    58     public class BooleanRandExpression : StatelessExpression
     54    public override void Eval(IPushGpInterpreter interpreter)
    5955    {
    60         protected override string InitStringRepresentation() { return "BOOLEAN.RAND"; }
     56      var value = FloatGenerator.RandomFloat(
     57        interpreter.Configuration.MinRandomFloat,
     58        interpreter.Configuration.MaxRandomFloat);
    6159
    62         public override void Eval(IInterpreter interpreter)
    63         {
    64             var value = BooleanGenerator.RandomBoolean();
     60      interpreter.FloatStack.Push(value);
     61    }
     62  }
    6563
    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";
    6872    }
    6973
    70     /// <summary>
    71     /// Pushes random expressions onto the code stack.
    72     /// </summary>
    73     public class CodeRandExpression : StatelessExpression
     74    public override void Eval(IPushGpInterpreter interpreter)
    7475    {
    75         protected override string InitStringRepresentation() { return "CODE.RAND"; }
     76      var value = BooleanGenerator.RandomBoolean();
    7677
    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  }
    8281
    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";
    8690    }
     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  }
    87103}
Note: See TracChangeset for help on using the changeset viewer.