Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Algorithms.CMAEvolutionStrategy/sources/MOCMAES/CrowdingIndicator.cs @ 14269

Last change on this file since 14269 was 14269, checked in by bwerth, 8 years ago

#2592 code cleanup + project reactored

File size: 2.9 KB
Line 
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
22using HeuristicLab.Data;
23using System;
24using System.Linq;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26using HeuristicLab.Core;
27using HeuristicLab.Common;
28using HeuristicLab.Problems.TestFunctions.MultiObjective;
29
30namespace HeuristicLab.Algorithms.MOCMAEvolutionStrategy {
31  [Item("CrowdingIndicator", "Selection of Offspring based on CrowdingDistance")]
32  [StorableClass]
33  class CrowdingIndicator : Item, IIndicator {
34
35
36    public int LeastContributer<R>(R[] front, Func<R, double[]> extractor, MultiObjectiveTestFunctionProblem problem) {
37      DoubleMatrix bounds = problem.Bounds;
38      int mindex = 1;
39      double min = Double.MaxValue;
40      double[] pointsums = new double[front.Count()];
41
42      for (int dim = 0; dim < problem.Objectives; dim++) {
43        double[] arr = front.Select(x => extractor.Invoke(x)[dim]).ToArray();
44        Array.Sort(arr);
45        double fmax = problem.Bounds[dim % bounds.Rows, 1];
46        double fmin = bounds[dim % bounds.Rows, 0];
47        int pointIdx = 0;
48        foreach (R point in front) {
49          double d = 0;
50          int pos = Array.BinarySearch(arr, extractor.Invoke(point)[dim]);
51
52          d = pos != 0 && pos != arr.Count() - 1 ? (arr[pos + 1] - arr[pos - 1]) / (fmax - fmin) : Double.PositiveInfinity;
53          pointsums[pointIdx] += d;
54
55
56          pointIdx++;
57        }
58      }
59      //find min
60      for (int pointIdx = 0; pointIdx < pointsums.Length; pointIdx++) {
61        double d = pointsums[pointIdx];
62        if (!Double.IsInfinity(d) && min > d) {
63          mindex = pointIdx;
64          min = d;
65        }
66      }
67
68      return mindex;
69    }
70
71
72
73    public override IDeepCloneable Clone(Cloner cloner) {
74      return new CrowdingIndicator(this, cloner);
75    }
76
77    [StorableConstructor]
78    protected CrowdingIndicator(bool deserializing) : base(deserializing) { }
79    protected CrowdingIndicator(CrowdingIndicator original, Cloner cloner)
80      : base(original, cloner) {
81    }
82    public CrowdingIndicator() { }
83  }
84}
Note: See TracBrowser for help on using the repository browser.