Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/01/17 09:28:34 (7 years ago)
Author:
pkimmesw
Message:

#2665 Fixed Benchmark Problem Definition, Converted LoopExpressions to stateless expressions, Added several unit test to ensure funcionality, Fixed UI bugs

File:
1 edited

Legend:

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

    r14952 r15017  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions {
    22  using System;
     3  using System.Globalization;
     4
    35  using Common;
    46
     
    3032      if (double.IsNegativeInfinity(result)) result = double.MinValue;
    3133
    32       interpreter.FloatStack.SetTop(result);
     34      interpreter.FloatStack.Top = result;
    3335    }
    3436  }
     
    5658      if (double.IsNegativeInfinity(result)) result = double.MinValue;
    5759
    58       interpreter.FloatStack.SetTop(result);
     60      interpreter.FloatStack.Top = result;
    5961    }
    6062  }
     
    8284      if (double.IsNegativeInfinity(result)) result = double.MinValue;
    8385
    84       interpreter.FloatStack.SetTop(result);
     86      interpreter.FloatStack.Top = result;
    8587    }
    8688  }
     
    109111      if (double.IsNegativeInfinity(result)) result = double.MinValue;
    110112
    111       interpreter.FloatStack.SetTop(result);
     113      interpreter.FloatStack.Top = result;
    112114    }
    113115  }
     
    136138      var result = second % first;
    137139
    138       interpreter.FloatStack.SetTop(result);
     140      interpreter.FloatStack.Top = result;
    139141    }
    140142  }
     
    159161      var result = Math.Min(second, first);
    160162
    161       interpreter.FloatStack.SetTop(result);
     163      interpreter.FloatStack.Top = result;
    162164    }
    163165  }
     
    182184      var result = Math.Max(second, first);
    183185
    184       interpreter.FloatStack.SetTop(result);
     186      interpreter.FloatStack.Top = result;
    185187    }
    186188  }
     
    298300    public override void Eval(IInternalPushInterpreter interpreter) {
    299301      var result = Math.Sin(interpreter.FloatStack.Top);
    300       interpreter.FloatStack.SetTop(result);
     302      interpreter.FloatStack.Top = result;
    301303    }
    302304  }
     
    317319    public override void Eval(IInternalPushInterpreter interpreter) {
    318320      var result = Math.Cos(interpreter.FloatStack.Top);
    319       interpreter.FloatStack.SetTop(result);
     321      interpreter.FloatStack.Top = result;
    320322    }
    321323  }
     
    362364    }
    363365  }
     366
     367  /// <summary>
     368  ///     Pushes the result of truncating the top CHAR.
     369  /// </summary>
     370  [PushExpression(StackTypes.Float, "FLOAT.FROMCHAR", StackTypes.Char)]
     371  [StorableClass]
     372  public class FloatFromCharExpression : StatelessExpression {
     373    public FloatFromCharExpression() { }
     374    [StorableConstructor]
     375    protected FloatFromCharExpression(bool deserializing) : base(deserializing) { }
     376
     377    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     378      return interpreter.CharStack.IsEmpty;
     379    }
     380
     381    public override void Eval(IInternalPushInterpreter interpreter) {
     382      var value = interpreter.CharStack.Pop();
     383      interpreter.FloatStack.Push(value);
     384    }
     385  }
     386
     387  /// <summary>
     388  ///     Pushes the result of parsing the top STRING.
     389  /// </summary>
     390  [PushExpression(StackTypes.Float, "FLOAT.FROMSTRING", StackTypes.String)]
     391  [StorableClass]
     392  public class FloatFromStringExpression : StatelessExpression {
     393    public FloatFromStringExpression() { }
     394    [StorableConstructor]
     395    protected FloatFromStringExpression(bool deserializing) : base(deserializing) { }
     396
     397    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     398      double tmp;
     399      return interpreter.StringStack.IsEmpty ||
     400             interpreter.StringStack.Top.Length == 0 ||
     401             !double.TryParse(interpreter.StringStack.Top, out tmp);
     402    }
     403
     404    public override void Eval(IInternalPushInterpreter interpreter) {
     405      var str = interpreter.StringStack.Pop();
     406      var value = double.Parse(str, CultureInfo.InvariantCulture);
     407
     408      interpreter.FloatStack.Push(value);
     409    }
     410  }
     411
     412  /// <summary>
     413  ///     Pushes the result of increasing the top INTEGER by 1.
     414  /// </summary>
     415  [PushExpression(StackTypes.Float, "FLOAT.INC")]
     416  [StorableClass]
     417  public class FloatIncExpression : StatelessExpression {
     418    public FloatIncExpression() { }
     419    [StorableConstructor]
     420    protected FloatIncExpression(bool deserializing) : base(deserializing) { }
     421
     422    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     423      return interpreter.FloatStack.IsEmpty;
     424    }
     425
     426    public override void Eval(IInternalPushInterpreter interpreter) {
     427      interpreter.FloatStack.Top += 1;
     428    }
     429  }
     430
     431  /// <summary>
     432  ///     Pushes the result of decreasing the top INTEGER by 1.
     433  /// </summary>
     434  [PushExpression(StackTypes.Float, "FLOAT.DEC")]
     435  [StorableClass]
     436  public class FloatDecExpression : StatelessExpression {
     437    public FloatDecExpression() { }
     438    [StorableConstructor]
     439    protected FloatDecExpression(bool deserializing) : base(deserializing) { }
     440
     441    public override bool IsNoop(IInternalPushInterpreter interpreter) {
     442      return interpreter.FloatStack.IsEmpty;
     443    }
     444
     445    public override void Eval(IInternalPushInterpreter interpreter) {
     446      interpreter.FloatStack.Top -= 1;
     447    }
     448  }
    364449}
Note: See TracChangeset for help on using the changeset viewer.