[13562] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[13562] | 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.Collections.Generic;
|
---|
| 23 |
|
---|
[14111] | 24 | namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
|
---|
[13562] | 25 |
|
---|
[14085] | 26 | public static class NonDominatedSelect {
|
---|
[14018] | 27 | public enum DominationResult { Dominates, IsDominated, IsNonDominated };
|
---|
[13562] | 28 |
|
---|
[14081] | 29 | public static IEnumerable<double[]> SelectNonDominatedVectors(IEnumerable<double[]> qualities, bool[] maximization, bool dominateOnEqualQualities) {
|
---|
[13562] | 30 |
|
---|
[13988] | 31 | List<double[]> front = new List<double[]>();
|
---|
| 32 | foreach (double[] row in qualities) {
|
---|
| 33 | bool insert = true;
|
---|
| 34 | for (int i = 0; i < front.Count; i++) {
|
---|
| 35 | DominationResult res = Dominates(front[i], row, maximization, dominateOnEqualQualities);
|
---|
| 36 | if (res == DominationResult.Dominates) { insert = false; break; } //Vector domiates Row
|
---|
| 37 | else if (res == DominationResult.IsDominated) { //Row dominates Vector
|
---|
[14081] | 38 | front.RemoveAt(i);
|
---|
[13988] | 39 | }
|
---|
[13562] | 40 | }
|
---|
[13988] | 41 | if (insert) {
|
---|
| 42 | front.Add(row);
|
---|
[13562] | 43 | }
|
---|
[13988] | 44 | }
|
---|
[13562] | 45 |
|
---|
[13988] | 46 | return front;
|
---|
| 47 | }
|
---|
[13562] | 48 |
|
---|
[14081] | 49 | public static IEnumerable<double[]> GetDominatingVectors(IEnumerable<double[]> qualities, double[] reference, bool[] maximization, bool dominateOnEqualQualities) {
|
---|
[13988] | 50 | List<double[]> front = new List<double[]>();
|
---|
| 51 | foreach (double[] vec in qualities) {
|
---|
| 52 | if (Dominates(vec, reference, maximization, dominateOnEqualQualities) == DominationResult.Dominates) {
|
---|
| 53 | front.Add(vec);
|
---|
[13562] | 54 | }
|
---|
[13988] | 55 | }
|
---|
| 56 | return front;
|
---|
| 57 | }
|
---|
[13562] | 58 |
|
---|
[14018] | 59 | public static DominationResult Dominates(double[] left, double[] right, bool[] maximizations, bool dominateOnEqualQualities) {
|
---|
[13988] | 60 | //mkommend Caution: do not use LINQ.SequenceEqual for comparing the two quality arrays (left and right) due to performance reasons
|
---|
| 61 | if (dominateOnEqualQualities) {
|
---|
| 62 | var equal = true;
|
---|
| 63 | for (int i = 0; i < left.Length; i++) {
|
---|
| 64 | if (left[i] != right[i]) {
|
---|
| 65 | equal = false;
|
---|
| 66 | break;
|
---|
| 67 | }
|
---|
[13936] | 68 | }
|
---|
[13988] | 69 | if (equal) return DominationResult.Dominates;
|
---|
| 70 | }
|
---|
[13562] | 71 |
|
---|
[13988] | 72 | bool leftIsBetter = false, rightIsBetter = false;
|
---|
| 73 | for (int i = 0; i < left.Length; i++) {
|
---|
| 74 | if (IsDominated(left[i], right[i], maximizations[i])) rightIsBetter = true;
|
---|
| 75 | else if (IsDominated(right[i], left[i], maximizations[i])) leftIsBetter = true;
|
---|
| 76 | if (leftIsBetter && rightIsBetter) break;
|
---|
| 77 | }
|
---|
[13562] | 78 |
|
---|
[13988] | 79 | if (leftIsBetter && !rightIsBetter) return DominationResult.Dominates;
|
---|
| 80 | if (!leftIsBetter && rightIsBetter) return DominationResult.IsDominated;
|
---|
| 81 | return DominationResult.IsNonDominated;
|
---|
[13562] | 82 | }
|
---|
[13988] | 83 |
|
---|
| 84 | private static bool IsDominated(double left, double right, bool maximization) {
|
---|
| 85 | return maximization && left < right
|
---|
| 86 | || !maximization && left > right;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | }
|
---|
[13562] | 90 | }
|
---|