Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/02/10 21:34:31 (14 years ago)
Author:
abeham
Message:

#1029

  • Added Bounds to SingleObjectiveTestFunctionSolution
  • This would break persistence, so I added a CompatibilityMethod (which can be removed again once moving to 3.4)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Analyzers/BestSingleObjectiveTestFunctionSolutionAnalyzer.cs

    r3797 r3894  
    6969      get { return (IValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>)Parameters["Evaluator"]; }
    7070    }
     71    public ILookupParameter<DoubleMatrix> BoundsParameter {
     72      get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
     73    }
    7174
     75    protected BestSingleObjectiveTestFunctionSolutionAnalyzer(bool deserializing) : base(deserializing) { }
    7276    public BestSingleObjectiveTestFunctionSolutionAnalyzer()
    7377      : base() {
     
    8084      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the SingleObjectiveTestFunction solution should be stored."));
    8185      Parameters.Add(new ValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>("Evaluator", "The evaluator with which the solution is evaluated."));
     86      Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The bounds of the function."));
     87    }
     88
     89    /// <summary>
     90    /// This method can simply be removed when the plugin version is > 3.3
     91    /// </summary>
     92    [StorableHook(HookType.AfterDeserialization)]
     93    private void CompatibilityMethod() {
     94      // Bounds are introduced in 3.3.0.3894
     95      if (!Parameters.ContainsKey("Bounds"))
     96        Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The bounds of the function."));
    8297    }
    8398
     
    85100      ItemArray<RealVector> realVectors = RealVectorParameter.ActualValue;
    86101      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    87       ResultCollection results = ResultsParameter.ActualValue;
    88       ISingleObjectiveTestFunctionProblemEvaluator evaluator = EvaluatorParameter.ActualValue;
    89102      bool max = MaximizationParameter.ActualValue.Value;
    90103      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
     104      SingleObjectiveTestFunctionSolution solution = BestSolutionParameter.ActualValue;
    91105
    92106      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     
    97111        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
    98112        BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone();
     113        if (solution != null)
     114          solution.BestKnownRealVector = BestKnownSolutionParameter.ActualValue;
    99115      }
    100116
    101       SingleObjectiveTestFunctionSolution solution = BestSolutionParameter.ActualValue;
    102117      if (solution == null) {
    103         solution = new SingleObjectiveTestFunctionSolution(realVectors[i], qualities[i], evaluator);
     118        ResultCollection results = ResultsParameter.ActualValue;
     119        solution = new SingleObjectiveTestFunctionSolution(realVectors[i], qualities[i], EvaluatorParameter.ActualValue);
    104120        solution.Population = realVectors;
    105121        solution.BestKnownRealVector = BestKnownSolutionParameter.ActualValue;
     122        solution.Bounds = BoundsParameter.ActualValue;
    106123        BestSolutionParameter.ActualValue = solution;
    107124        results.Add(new Result("Best Solution", solution));
Note: See TracChangeset for help on using the changeset viewer.