1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Optimization;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
|
---|
29 | class HypervolumeAnalyzer : MOTFAnalyzer {
|
---|
30 | public HypervolumeAnalyzer() {
|
---|
31 | }
|
---|
32 |
|
---|
33 | protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
34 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
35 | return new HypervolumeAnalyzer(this, cloner);
|
---|
36 | }
|
---|
37 |
|
---|
38 | protected override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) {
|
---|
39 | if (qualities == null || qualities.Length < 2) return;
|
---|
40 | int objectives = qualities[0].Length;
|
---|
41 | double best = TestFunction.BestKnownHypervolume(objectives);
|
---|
42 |
|
---|
43 | double diff;
|
---|
44 |
|
---|
45 | if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", typeof(DoubleValue)));
|
---|
46 | IEnumerable<double[]> front = NonDominatedSelect.selectNonDominatedVectors(qualities, TestFunction.Maximization(objectives), true);
|
---|
47 | if (!results.ContainsKey("BestKnownHypervolume")) results.Add(new Result("BestKnownHypervolume", typeof(DoubleValue)));
|
---|
48 | else {
|
---|
49 | DoubleValue dv = (DoubleValue)(results["BestKnownHypervolume"].Value);
|
---|
50 | best = dv.Value;
|
---|
51 | }
|
---|
52 | if (!results.ContainsKey("Absolute Distance to BestKnownHypervolume")) results.Add(new Result("Absolute Distance to BestKnownHypervolume", typeof(DoubleValue)));
|
---|
53 |
|
---|
54 | double hv = Double.NaN;
|
---|
55 | try {
|
---|
56 | if (objectives == 2) { //Hypervolume analysis only with 2 objectives for now
|
---|
57 | hv = Hypervolume.Calculate(front, TestFunction.ReferencePoint(objectives), TestFunction.Maximization(objectives));
|
---|
58 | } else if (Array.TrueForAll(TestFunction.Maximization(objectives), x => !x)) {
|
---|
59 | hv = FastHV2.Calculate(front, TestFunction.ReferencePoint(objectives));
|
---|
60 | }
|
---|
61 | }
|
---|
62 | catch (ArgumentException) {
|
---|
63 | //TODO
|
---|
64 | }
|
---|
65 |
|
---|
66 | if (best < 0) {
|
---|
67 | best = hv;
|
---|
68 | }
|
---|
69 | diff = best - hv;
|
---|
70 | if (!Double.IsNaN(hv) && (diff < 0 || best < 0)) {
|
---|
71 | best = hv;
|
---|
72 | diff = 0;
|
---|
73 | }
|
---|
74 |
|
---|
75 | results["Hypervolume"].Value = new DoubleValue(hv);
|
---|
76 | results["Absolute Distance to BestKnownHypervolume"].Value = new DoubleValue(diff);
|
---|
77 | results["BestKnownHypervolume"].Value = new DoubleValue(best);
|
---|
78 |
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|