Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/21/16 15:52:53 (7 years ago)
Author:
bwerth
Message:

#2592 several fixes and cleanups to adapt a more HeuristicLab-Code-Style + renaming of folders and Plugin

Location:
branches
Files:
2 edited
2 copied
1 moved

Legend:

Unmodified
Added
Removed
  • branches

    • Property svn:global-ignores set to
      bin
  • branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/CrowdingIndicator.cs

    r14269 r14404  
    2020#endregion
    2121
    22 using HeuristicLab.Data;
    2322using System;
     23using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Common;
     26using HeuristicLab.Core;
    2527using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Core;
    27 using HeuristicLab.Common;
    2828using HeuristicLab.Problems.TestFunctions.MultiObjective;
    2929
     
    3131  [Item("CrowdingIndicator", "Selection of Offspring based on CrowdingDistance")]
    3232  [StorableClass]
    33   class CrowdingIndicator : Item, IIndicator {
     33  internal class CrowdingIndicator : Item, IIndicator {
    3434
     35    public int LeastContributer<TR>(IEnumerable<TR> front, Func<TR, double[]> extractor, MultiObjectiveTestFunctionProblem problem) {
     36      var bounds = problem.Bounds;
     37      var extracted = front.Select(extractor.Invoke).ToArray();
     38      var pointsums = new double[extracted.Length];
    3539
    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();
     40      for (var dim = 0; dim < problem.Objectives; dim++) {
     41        var arr = extracted.Select(x => x[dim]).ToArray();
    4442        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;
     43        var fmax = problem.Bounds[dim % bounds.Rows, 1];
     44        var fmin = bounds[dim % bounds.Rows, 0];
     45        var pointIdx = 0;
     46        foreach (var point in extracted) {
     47          var pos = Array.BinarySearch(arr, point[dim]);
     48          var d = pos != 0 && pos != arr.Length - 1 ? (arr[pos + 1] - arr[pos - 1]) / (fmax - fmin) : double.PositiveInfinity;
    5349          pointsums[pointIdx] += d;
    54 
    55 
    5650          pointIdx++;
    5751        }
    5852      }
    5953      //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);
     54      return pointsums.Where(x => !double.IsInfinity(x)).ArgMin();
    7555    }
    7656
    7757    [StorableConstructor]
    7858    protected CrowdingIndicator(bool deserializing) : base(deserializing) { }
    79     protected CrowdingIndicator(CrowdingIndicator original, Cloner cloner)
    80       : base(original, cloner) {
    81     }
     59    protected CrowdingIndicator(CrowdingIndicator original, Cloner cloner) : base(original, cloner) { }
     60    public override IDeepCloneable Clone(Cloner cloner) { return new CrowdingIndicator(this, cloner); }
    8261    public CrowdingIndicator() { }
    8362  }
Note: See TracChangeset for help on using the changeset viewer.