Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/10/17 21:36:03 (7 years ago)
Author:
pkimmesw
Message:

#2665 Fixed small issues, testet benchmark suite, added INX Expressions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Problem/BenchmarkSuite/PushBenchmarkSuiteEvaluator.cs

    r15017 r15189  
    22  using System;
    33  using System.Collections.Generic;
     4  using System.Globalization;
    45  using System.Linq;
    56
     
    130131      var example = Data.Examples[exampleIndex];
    131132
    132       interpreter.BooleanStack.Push(example.InputBoolean);
    133       interpreter.IntegerStack.Push(example.InputInteger);
    134       interpreter.FloatStack.Push(example.InputFloat);
    135       interpreter.CharStack.Push(example.InputChar);
    136       interpreter.StringStack.Push(example.InputString);
    137       interpreter.StringVectorStack.Push(example.InputStringVector);
    138       interpreter.IntegerVectorStack.Push(example.InputIntegerVector);
    139       interpreter.FloatVectorStack.Push(example.InputFloatVector);
     133      //interpreter.BooleanStack.Push(example.InputBoolean);
     134      //interpreter.IntegerStack.Push(example.InputInteger);
     135      //interpreter.FloatStack.Push(example.InputFloat);
     136      //interpreter.CharStack.Push(example.InputChar);
     137      //interpreter.StringStack.Push(example.InputString);
     138      //interpreter.StringVectorStack.Push(example.InputStringVector);
     139      //interpreter.IntegerVectorStack.Push(example.InputIntegerVector);
     140      //interpreter.FloatVectorStack.Push(example.InputFloatVector);
     141
     142      interpreter.SetInput(
     143        integers: example.InputInteger,
     144        floats: example.InputFloat,
     145        booleans: example.InputBoolean,
     146        chars: example.InputChar,
     147        strings: example.InputString,
     148        integerVectors: example.InputIntegerVector,
     149        floatVectors: example.InputFloatVector,
     150        stringVectors: example.InputStringVector);
    140151
    141152      interpreter.Run(program);
    142153
    143154      switch (Data.ProblemType) {
    144         //case ProblemType.NumberIO:
    145         //  if (interpreter.PrintStack.IsEmpty)
    146         //    return Data.WorstResult;
    147 
    148         //  double value;
    149         //  var levenshteinDistance = GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, example.OutputPrintLineCount, Data.WorstResult);
    150         //  return levenshteinDistance + (double.TryParse(interpreter.PrintStack.Top, out value)
    151         //    ? FloatDiffer(value, example.OutputFloat[0], example.OutputFloatPrecision)
    152         //    : Data.WorstResult / 2);
    153 
    154         case ProblemType.Median: return interpreter.PrintStack.IsEmpty ? 1 : interpreter.PrintStack.Top.Equals(example.OutputPrint) ? 0 : 1;
    155       }
    156 
     155        case ProblemType.NumberIO: return NumberIo(interpreter, example);
     156        case ProblemType.Median: return Median(interpreter, example);
     157      }
     158
     159      return Default(interpreter, example);
     160    }
     161
     162    private double Default(IPushInterpreter interpreter, Example example) {
    157163      var result = GetDiff(example.OutputInteger, interpreter.IntegerStack, Data.WorstResult, IntegerDiffer)
    158                  + GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision))
    159                  + GetDiff(example.OutputBoolean, interpreter.BooleanStack, Data.WorstResult, BooleanDiffer)
    160                  + GetDiff(example.OutputString, interpreter.StringStack, Data.WorstResult, StringDiffer)
    161                  + GetDiff(example.OutputChar, interpreter.CharStack, Data.WorstResult, CharDiffer)
    162                  + GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, example.OutputPrintLineCount, Data.WorstResult)
    163                  + GetVectorDiff(example.OutputIntegerVector, interpreter.IntegerVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, IntegerDiffer))
    164                  + GetVectorDiff(example.OutputFloatVector, interpreter.FloatVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, (x, y) => FloatDiffer(x, y, example.OutputFloatVectorPrecision)))
    165                  + GetVectorDiff(example.OutputStringVector, interpreter.StringVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, StringDiffer));
     164             + GetDiff(example.OutputFloat, interpreter.FloatStack, Data.WorstResult, (a, b) => FloatDiffer(a, b, example.OutputFloatPrecision))
     165             + GetDiff(example.OutputBoolean, interpreter.BooleanStack, Data.WorstResult, BooleanDiffer)
     166             + GetDiff(example.OutputString, interpreter.StringStack, Data.WorstResult, StringDiffer)
     167             + GetDiff(example.OutputChar, interpreter.CharStack, Data.WorstResult, CharDiffer)
     168             + GetPrintDiffer(example.OutputPrint, interpreter.PrintStack, example.OutputPrintLineCount, Data.WorstResult)
     169             + GetVectorDiff(example.OutputIntegerVector, interpreter.IntegerVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, IntegerDiffer))
     170             + GetVectorDiff(example.OutputFloatVector, interpreter.FloatVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, (x, y) => FloatDiffer(x, y, example.OutputFloatVectorPrecision)))
     171             + GetVectorDiff(example.OutputStringVector, interpreter.StringVectorStack, Data.WorstResult, (a, b) => VectorDiffer(a, b, StringDiffer));
    166172
    167173      return result;
     174    }
     175
     176    private double Median(IPushInterpreter interpreter, Example example) {
     177      return interpreter.PrintStack.IsEmpty || !interpreter.PrintStack.Top.Equals(example.OutputPrint) ? 1 : 0;
     178    }
     179
     180    private double NumberIo(IPushInterpreter interpreter, Example example) {
     181      if (interpreter.PrintStack.IsEmpty)
     182        return Data.WorstResult;
     183
     184      double value;
     185      if (double.TryParse(interpreter.PrintStack.Top, NumberStyles.Number | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out value)) {
     186        var diff = Math.Abs(example.OutputFloat[0] - value);
     187        var result = Math.Min(diff, Data.WorstResult);
     188
     189        return result;
     190      }
     191
     192      var penaltyError = Data.WorstResult / 4.0d;
     193      var levenshteinDistance = GetPrintDiffer(
     194        example.OutputPrint,
     195        interpreter.PrintStack.Top,
     196        Data.WorstResult);
     197
     198      return levenshteinDistance + penaltyError;
    168199    }
    169200
     
    217248    }
    218249
     250    private static double GetPrintDiffer(string estimated, string printResult, double worstResult) {
     251      var distance = LevenshteinDistance(estimated, printResult);
     252
     253      return Math.Min(distance, worstResult);
     254    }
     255
    219256    private static double GetPrintDiffer(string estimated, IPushStack<string> printStack, int estimatedCount, double worstResult) {
    220       var printResult = string.Join(PushEnvironment.NewLine, printStack.Take(estimatedCount));
     257      var printResult = string.Join(PushEnvironment.NewLine, printStack.AsStrings().Take(estimatedCount));
    221258      var distance = LevenshteinDistance(estimated, printResult);
    222259
     
    234271        var count = Math.Min(estimated.Count, resultStack.Count);
    235272        var result = resultStack.Peek(count);
    236         comparableLength = Math.Min(estimated.Count, result.Length);
     273        comparableLength = Math.Min(estimated.Count, result.Count);
    237274
    238275        for (var i = 0; i < comparableLength; i++) {
     
    259296        var count = Math.Min(estimated.Count, resultStack.Count);
    260297        var result = resultStack.Peek(count);
    261         comparableLength = Math.Min(estimated.Count, result.Length);
     298        comparableLength = Math.Min(estimated.Count, result.Count);
    262299
    263300        for (var i = 0; i < comparableLength; i++) {
Note: See TracChangeset for help on using the changeset viewer.