Changeset 14090 for branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs
- Timestamp:
- 07/15/16 19:27:12 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs
r14085 r14090 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 34 35 public class HypervolumeAnalyzer : MOTFAnalyzer { 35 36 36 public ILookupParameter<DoubleArray> ReferencePointParameter {37 get { return (ILookupParameter<DoubleArray>)Parameters["ReferencePoint"]; }38 }39 40 public IFixedValueParameter<DoubleValue> BestKnownHyperVolumeParameter {41 get { return (IFixedValueParameter<DoubleValue>)Parameters["BestKnownHyperVolume"]; }42 }43 44 public double BestKnownHyperVolume {45 get { return BestKnownHyperVolumeParameter.Value.Value; }46 set { BestKnownHyperVolumeParameter.Value.Value = value; }47 }48 49 37 [StorableConstructor] 50 38 protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) { } … … 57 45 } 58 46 59 public HypervolumeAnalyzer() { 60 Parameters.Add(new LookupParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation")); 61 Parameters.Add(new FixedValueParameter<DoubleValue>("BestKnownHyperVolume", "The currently best known hypervolume", new DoubleValue(0))); 62 } 47 public HypervolumeAnalyzer() { } 63 48 64 49 public override IOperation Apply() { … … 66 51 var qualities = QualitiesParameter.ActualValue; 67 52 var testFunction = TestFunctionParameter.ActualValue; 68 var referencePoint = ReferencePointParameter.ActualValue;69 53 int objectives = qualities[0].Length; 70 71 54 var referencePoint = testFunction.ReferencePoint(objectives); 72 55 73 56 if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", typeof(DoubleValue))); 74 57 if (!results.ContainsKey("Absolute Distance to BestKnownHypervolume")) results.Add(new Result("Absolute Distance to BestKnownHypervolume", typeof(DoubleValue))); 75 58 76 double best ;59 double best = testFunction.OptimalHypervolume(objectives); 77 60 if (!results.ContainsKey("BestKnownHypervolume")) { 78 61 results.Add(new Result("BestKnownHypervolume", typeof(DoubleValue))); 79 best = BestKnownHyperVolumeParameter.Value.Value;80 } else {81 best = ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value;82 62 } 83 63 best = Math.Max(best, ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value); 84 64 85 65 IEnumerable<double[]> front = NonDominatedSelect.SelectNonDominatedVectors(qualities.Select(q => q.ToArray()), testFunction.Maximization(objectives), true); 86 66 87 double hv = front.Any() ? Hypervolume.Calculate(front, referencePoint.CloneAsArray(), testFunction.Maximization(objectives)) : 0; 88 67 double hv = Hypervolume.Calculate(front, (double[])referencePoint.Clone(), testFunction.Maximization(objectives)); 89 68 90 69 if (double.IsNaN(best) || best < hv) { … … 93 72 } 94 73 95 results["Hypervolume"].Value = new DoubleValue(hv);96 results["BestKnownHypervolume"].Value = new DoubleValue(best);97 results["Absolute Distance to BestKnownHypervolume"].Value = new DoubleValue(best - hv);74 ((DoubleValue)(results["Hypervolume"].Value)).Value = hv; 75 ((DoubleValue)(results["BestKnownHypervolume"].Value)).Value = best; 76 ((DoubleValue)(results["Absolute Distance to BestKnownHypervolume"].Value)).Value = best - hv; 98 77 99 78 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.