Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/08/13 18:57:53 (11 years ago)
Author:
jkarder
Message:

#2029:

  • added EvaluateFunction to ISingleObjectiveTestFunctionProblemEvaluator and adapted evaluators
  • fixed SingleObjectiveTestFunctionImprovementOperator
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Improvers/SingleObjectiveTestFunctionImprovementOperator.cs

    r8987 r9345  
    2121
    2222using System;
    23 using System.Reflection;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
     
    126125        throw new ArgumentException("Cannot improve solution because it has the wrong type.");
    127126
    128       MethodInfo evaluationMethod = Evaluator.GetType().GetMethod("EvaluateFunction",
    129                                                                   BindingFlags.Instance | BindingFlags.NonPublic,
    130                                                                   null,
    131                                                                   new[] { typeof(RealVector) },
    132                                                                   null);
    133       Func<RealVector, double> functionEvaluator = x => (double)evaluationMethod.Invoke(Evaluator, new object[] { x });
    134       double bestSolQuality = functionEvaluator(bestSol);
     127      double bestSolQuality = Evaluator.EvaluateFunction(bestSol);
    135128
    136129      // create perturbed solutions
     
    146139      for (int i = 0; i < ImprovementAttempts.Value; i++) {
    147140        // order according to their objective function value
    148         Array.Sort(simplex, (x, y) => functionEvaluator(x).CompareTo(functionEvaluator(y)));
     141        Array.Sort(simplex, (x, y) => Evaluator.EvaluateFunction(x).CompareTo(Evaluator.EvaluateFunction(y)));
    149142
    150143        // calculate centroid
     
    160153        for (int j = 0; j < reflectionPoint.Length; j++)
    161154          reflectionPoint[j] = centroid[j] + Alpha.Value * (centroid[j] - simplex[simplex.Length - 1][j]);
    162         double reflectionPointQuality = functionEvaluator(reflectionPoint);
    163         if (functionEvaluator(simplex[0]) <= reflectionPointQuality
    164             && reflectionPointQuality < functionEvaluator(simplex[simplex.Length - 2]))
     155        double reflectionPointQuality = Evaluator.EvaluateFunction(reflectionPoint);
     156        if (Evaluator.EvaluateFunction(simplex[0]) <= reflectionPointQuality
     157            && reflectionPointQuality < Evaluator.EvaluateFunction(simplex[simplex.Length - 2]))
    165158          simplex[simplex.Length - 1] = reflectionPoint;
    166159
    167160        // expansion
    168         if (reflectionPointQuality < functionEvaluator(simplex[0])) {
     161        if (reflectionPointQuality < Evaluator.EvaluateFunction(simplex[0])) {
    169162          RealVector expansionPoint = new RealVector(bestSol.Length);
    170163          for (int j = 0; j < expansionPoint.Length; j++)
    171164            expansionPoint[j] = centroid[j] + Beta.Value * (reflectionPoint[j] - centroid[j]);
    172           simplex[simplex.Length - 1] = functionEvaluator(expansionPoint) < reflectionPointQuality ? expansionPoint : reflectionPoint;
     165          simplex[simplex.Length - 1] = Evaluator.EvaluateFunction(expansionPoint) < reflectionPointQuality ? expansionPoint : reflectionPoint;
    173166        }
    174167
    175168        // contraction
    176         if (functionEvaluator(simplex[simplex.Length - 2]) <= reflectionPointQuality
    177             && reflectionPointQuality < functionEvaluator(simplex[simplex.Length - 1])) {
     169        if (Evaluator.EvaluateFunction(simplex[simplex.Length - 2]) <= reflectionPointQuality
     170            && reflectionPointQuality < Evaluator.EvaluateFunction(simplex[simplex.Length - 1])) {
    178171          RealVector outsideContractionPoint = new RealVector(bestSol.Length);
    179172          for (int j = 0; j < outsideContractionPoint.Length; j++)
    180173            outsideContractionPoint[j] = centroid[j] + Gamma.Value * (reflectionPoint[j] - centroid[j]);
    181           if (functionEvaluator(outsideContractionPoint) <= reflectionPointQuality) {
     174          if (Evaluator.EvaluateFunction(outsideContractionPoint) <= reflectionPointQuality) {
    182175            simplex[simplex.Length - 1] = outsideContractionPoint;
    183             if (functionEvaluator(reflectionPoint) >= functionEvaluator(simplex[simplex.Length - 1])) {
     176            if (Evaluator.EvaluateFunction(reflectionPoint) >= Evaluator.EvaluateFunction(simplex[simplex.Length - 1])) {
    184177              RealVector insideContractionPoint = new RealVector(bestSol.Length);
    185178              for (int j = 0; j < insideContractionPoint.Length; j++)
    186179                insideContractionPoint[j] = centroid[j] - Gamma.Value * (reflectionPoint[j] - centroid[j]);
    187               if (functionEvaluator(insideContractionPoint) < functionEvaluator(simplex[simplex.Length - 1])) simplex[simplex.Length - 1] = insideContractionPoint;
     180              if (Evaluator.EvaluateFunction(insideContractionPoint) < Evaluator.EvaluateFunction(simplex[simplex.Length - 1])) simplex[simplex.Length - 1] = insideContractionPoint;
    188181            }
    189182          }
Note: See TracChangeset for help on using the changeset viewer.