Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/18/16 15:50:10 (6 years ago)
Author:
bwerth
Message:

#1087 refactored Analyzers to use ResultParameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs

    r14092 r14097  
    3838      get { return (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"]; }
    3939    }
     40    public IResultParameter<DoubleValue> HypervolumeResultParameter {
     41      get { return (IResultParameter<DoubleValue>)Parameters["Hypervolume"]; }
     42    }
     43    public IResultParameter<DoubleValue> BestKnownHypervolumeResultParameter {
     44      get { return (IResultParameter<DoubleValue>)Parameters["Best known hypervolume"]; }
     45    }
     46    public IResultParameter<DoubleValue> HypervolumeDistanceResultParameter {
     47      get { return (IResultParameter<DoubleValue>)Parameters["Absolute Distance to BestKnownHypervolume"]; }
     48    }
     49
    4050
    4151    [StorableConstructor]
     
    5262    public HypervolumeAnalyzer() {
    5363      Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation"));
     64      Parameters.Add(new ResultParameter<DoubleValue>("Hypervolume", "The hypervolume of the current generation"));
     65      Parameters.Add(new ResultParameter<DoubleValue>("Best known hypervolume", "The optimal hypervolume"));
     66      Parameters.Add(new ResultParameter<DoubleValue>("Absolute Distance to BestKnownHypervolume", "The difference between the best known and the current hypervolume"));
     67      HypervolumeResultParameter.DefaultValue = new DoubleValue(0);
     68      BestKnownHypervolumeResultParameter.DefaultValue = new DoubleValue(0);
     69      HypervolumeDistanceResultParameter.DefaultValue = new DoubleValue(0);
     70
     71
    5472    }
    5573
    5674    public override IOperation Apply() {
    57       var results = ResultsParameter.ActualValue;
    5875      var qualities = QualitiesParameter.ActualValue;
    5976      var testFunction = TestFunctionParameter.ActualValue;
     
    6178      var referencePoint = ReferencePointParameter.ActualValue;
    6279
    63       if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", new DoubleValue(0)));
    64       if (!results.ContainsKey("Absolute Distance to BestKnownHypervolume")) results.Add(new Result("Absolute Distance to BestKnownHypervolume", new DoubleValue(0)));
    65 
    66       double best = testFunction.OptimalHypervolume(objectives);
    67       if (!results.ContainsKey("BestKnownHypervolume")) {
    68         results.Add(new Result("BestKnownHypervolume", new DoubleValue(0)));
    69       } else {
    70         best = Math.Max(best, ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value);
     80      double best = BestKnownHypervolumeResultParameter.ActualValue.Value;
     81      if (referencePoint.SequenceEqual(testFunction.ReferencePoint(objectives))) {
     82        best = Math.Max(best, testFunction.OptimalHypervolume(objectives));
    7183      }
    72 
    7384
    7485      IEnumerable<double[]> front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true);
     
    7687      double hv = Hypervolume.Calculate(front, referencePoint.ToArray(), testFunction.Maximization(objectives));
    7788
    78       if (double.IsNaN(best) || best < hv) {
     89      if (!double.IsNaN(hv) || best < hv) {
    7990        best = hv;
    80         BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities.Select(q => q.ToArray()).ToArray()));
    8191      }
    8292
    83       ((DoubleValue)(results["Hypervolume"].Value)).Value = hv;
    84       ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value = best;
    85       ((DoubleValue)(results["Absolute Distance to BestKnownHypervolume"].Value)).Value = best - hv;
     93      HypervolumeResultParameter.ActualValue.Value = hv;
     94      BestKnownHypervolumeResultParameter.ActualValue.Value = best;
     95      HypervolumeDistanceResultParameter.ActualValue.Value = best - hv;
    8696
    8797      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.