Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/10/17 11:23:05 (8 years ago)
Author:
pkimmesw
Message:

#2665 Added IsNoop to Expression, Made Expressions storable, Fixed Debugger, Fixed and improved problem data and result visualisation, Added custom ErcOption view, Added problem difficulty to problem data name

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/RandExpressions.cs

    r14897 r14952  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
     2  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    23  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
    34  using HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator;
     
    910  /// </summary>
    1011  [PushExpression(StackTypes.Name, "NAME.RAND")]
     12  [StorableClass]
    1113  public class NameRandExpression : StatelessExpression {
    12     public override bool Eval(IInternalPushInterpreter interpreter) {
    13       if (!interpreter.Configuration.ErcOptions.NameErcOptions.IsEnabled)
    14         return false;
     14    public NameRandExpression() { }
     15    [StorableConstructor]
     16    protected NameRandExpression(bool deserializing) : base(deserializing) { }
    1517
     18    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     19      return !interpreter.Configuration.ErcOptions.NameErcOptions.IsEnabled;
     20    }
     21
     22    public override void Eval(IInternalPushInterpreter interpreter) {
    1623      var name = interpreter.Configuration.ErcOptions.NameErcOptions.GetErcValue(interpreter.Random);
    1724      interpreter.NameStack.Push(name);
    18       return true;
    1925    }
    2026  }
     
    2430  /// </summary>
    2531  [PushExpression(StackTypes.Integer, "INTEGER.RAND")]
     32  [StorableClass]
    2633  public class IntegerRandExpression : StatelessExpression {
    27     public override bool Eval(IInternalPushInterpreter interpreter) {
    28       if (!interpreter.Configuration.ErcOptions.IntegerErcOptions.IsEnabled)
    29         return false;
     34    public IntegerRandExpression() { }
     35    [StorableConstructor]
     36    protected IntegerRandExpression(bool deserializing) : base(deserializing) { }
    3037
     38    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     39      return !interpreter.Configuration.ErcOptions.IntegerErcOptions.IsEnabled;
     40    }
     41
     42    public override void Eval(IInternalPushInterpreter interpreter) {
    3143      var value = interpreter.Configuration.ErcOptions.IntegerErcOptions.GetErcValue(interpreter.Random);
    3244      interpreter.IntegerStack.Push(value);
    33       return true;
    3445    }
    3546  }
     
    3950  /// </summary>
    4051  [PushExpression(StackTypes.Float, "FLOAT.RAND")]
     52  [StorableClass]
    4153  public class FloatRandExpression : StatelessExpression {
    42     public override bool Eval(IInternalPushInterpreter interpreter) {
    43       if (!interpreter.Configuration.ErcOptions.FloatErcOptions.IsEnabled)
    44         return false;
     54    public FloatRandExpression() { }
     55    [StorableConstructor]
     56    protected FloatRandExpression(bool deserializing) : base(deserializing) { }
    4557
     58    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     59      return !interpreter.Configuration.ErcOptions.FloatErcOptions.IsEnabled;
     60    }
     61
     62    public override void Eval(IInternalPushInterpreter interpreter) {
    4663      var value = interpreter.Configuration.ErcOptions.FloatErcOptions.GetErcValue(interpreter.Random);
    4764      interpreter.FloatStack.Push(value);
    48       return true;
    4965    }
    5066  }
     
    5470  /// </summary>
    5571  [PushExpression(StackTypes.Boolean, "BOOLEAN.RAND")]
     72  [StorableClass]
    5673  public class BooleanRandExpression : StatelessExpression {
    57     public override bool Eval(IInternalPushInterpreter interpreter) {
    58       if (!interpreter.Configuration.ErcOptions.BooleanErcOptions.IsEnabled)
    59         return false;
     74    public BooleanRandExpression() { }
     75    [StorableConstructor]
     76    protected BooleanRandExpression(bool deserializing) : base(deserializing) { }
    6077
     78    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     79      return !interpreter.Configuration.ErcOptions.BooleanErcOptions.IsEnabled;
     80    }
     81
     82    public override void Eval(IInternalPushInterpreter interpreter) {
    6183      var value = interpreter.Configuration.ErcOptions.BooleanErcOptions.GetErcValue(interpreter.Random);
    6284      interpreter.BooleanStack.Push(value);
    63       return true;
    6485    }
    6586  }
     
    6990  /// </summary>
    7091  [PushExpression(StackTypes.Code, "CODE.RAND")]
     92  [StorableClass]
    7193  public class CodeRandExpression : StatelessExpression {
    72     public override bool Eval(IInternalPushInterpreter interpreter) {
    73       if (interpreter.IntegerStack.Count == 0 ||
    74           interpreter.IntegerStack.Top < 1) return false;
     94    public CodeRandExpression() { }
     95    [StorableConstructor]
     96    protected CodeRandExpression(bool deserializing) : base(deserializing) { }
    7597
     98    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     99      return interpreter.IntegerStack.Count == 0 || interpreter.IntegerStack.Top < 1;
     100    }
     101
     102    public override void Eval(IInternalPushInterpreter interpreter) {
    76103      var size = (int)(interpreter.IntegerStack.Pop() % interpreter.Configuration.MaxPointsInRandomExpression);
    77104      var program = LinearCodeGenerator.RandomProgram(
     
    84111
    85112      interpreter.CodeStack.Push(program);
    86       return true;
    87113    }
    88114  }
Note: See TracChangeset for help on using the changeset viewer.