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