Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Indicators/CrowdingIndicator.cs @ 17398

Last change on this file since 17398 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Encodings.RealVectorEncoding;
28using HeuristicLab.Optimization;
29using HEAL.Attic;
30
31namespace HeuristicLab.Algorithms.MOCMAEvolutionStrategy {
32  [Item("CrowdingIndicator", "Selection of Offspring based on CrowdingDistance")]
33  [StorableType("FEC5F17A-C720-4411-8AD6-42BA0F392AE9")]
34  internal class CrowdingIndicator : Item, IIndicator {
35    #region Constructors and Cloning
36    [StorableConstructor]
37    protected CrowdingIndicator(StorableConstructorFlag _) : base(_) { }
38    protected CrowdingIndicator(CrowdingIndicator original, Cloner cloner) : base(original, cloner) { }
39    public override IDeepCloneable Clone(Cloner cloner) { return new CrowdingIndicator(this, cloner); }
40    public CrowdingIndicator() { }
41    #endregion
42
43    public int LeastContributer(IReadOnlyList<Individual> front, MultiObjectiveBasicProblem<RealVectorEncoding> problem) {
44      var bounds = problem.Encoding.Bounds;
45      var extracted = front.Select(x => x.PenalizedFitness).ToArray();
46      if (extracted.Length <= 2) return 0;
47      var pointsums = new double[extracted.Length];
48
49      for (var dim = 0; dim < problem.Maximization.Length; dim++) {
50        var arr = extracted.Select(x => x[dim]).ToArray();
51        Array.Sort(arr);
52        var fmax = problem.Encoding.Bounds[dim % bounds.Rows, 1];
53        var fmin = bounds[dim % bounds.Rows, 0];
54        var pointIdx = 0;
55        foreach (var point in extracted) {
56          var pos = Array.BinarySearch(arr, point[dim]);
57          var d = pos != 0 && pos != arr.Length - 1 ? (arr[pos + 1] - arr[pos - 1]) / (fmax - fmin) : double.PositiveInfinity;
58          pointsums[pointIdx] += d;
59          pointIdx++;
60        }
61      }
62      return pointsums.Select((value, index) => new { value, index }).OrderBy(x => x.value).First().index;
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.