Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/21/16 15:52:53 (8 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/HypervolumeIndicator.cs

    r14269 r14404  
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
    28 using HeuristicLab.Data;
    2928using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3029using HeuristicLab.Problems.TestFunctions.MultiObjective;
     
    3231  [Item("HypervolumeIndicator", "Selection of Offspring based on contributing Hypervolume")]
    3332  [StorableClass]
    34   class HypervolumeIndicator : Item, IIndicator {
     33  internal class HypervolumeIndicator : Item, IIndicator {
    3534
    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       List<double[]> frontArr = front.Select(x => extractor.Invoke(x)).ToList<double[]>();
    41       double[] refPoint = buildReference(frontArr, problem.Maximization);
    42       refPoint = buildReference(refPoint, problem.TestFunction.ReferencePoint(problem.Objectives), problem.Maximization);
    43       double hv = Hypervolume.Calculate(frontArr, refPoint, problem.Maximization);
    44       for (int i = 0; i < frontArr.Count; i++) {
    45         var d = Contribution(frontArr, i, problem.Maximization, refPoint, hv);
    46         if (min > d) {
    47           mindex = i;
    48           min = d;
    49         }
    50       }
    51 
    52       return mindex;
     35    public int LeastContributer<TR>(IEnumerable<TR> front, Func<TR, double[]> extractor, MultiObjectiveTestFunctionProblem problem) {
     36      var frontArr = front.Select(extractor.Invoke).ToList();
     37      var refPoint = BuildReference(frontArr.Concat(new[] { problem.TestFunction.ReferencePoint(problem.Objectives) }), problem.Maximization);
     38      var hv = Hypervolume.Calculate(frontArr, refPoint, problem.Maximization);
     39      return Enumerable.Range(0, frontArr.Count).Select(i => Contribution(frontArr, i, problem.Maximization, refPoint, hv)).ArgMin();
    5340    }
    5441
    55     private double Contribution(List<double[]> front, int idx, bool[] maximization, double[] refPoint, double hv) {
     42    private static double Contribution(IList<double[]> front, int idx, bool[] maximization, double[] refPoint, double hv) {
    5643      var point = front[idx];
    5744      front.RemoveAt(idx);
     
    6047      return contribution;
    6148    }
    62 
    63     private double[] buildReference(IEnumerable<double[]> front, bool[] maximization) {
    64       double[] refPoint = new double[maximization.Length];
    65       foreach (double[] point in front) {
    66         for (int i = 0; i < maximization.Length; i++) {
     49    private static double[] BuildReference(IEnumerable<double[]> front, IReadOnlyList<bool> maximization) {
     50      var refPoint = new double[maximization.Count];
     51      foreach (var point in front)
     52        for (var i = 0; i < maximization.Count; i++)
    6753          refPoint[i] = maximization[i] ? Math.Min(refPoint[i], point[i]) : Math.Max(refPoint[i], point[i]);
    68         }
    69       }
    7054      return refPoint;
    71     }
    72     private double[] buildReference(double[] point1, double[] point2, bool[] maximization) {
    73       double[] refPoint = new double[maximization.Length];
    74 
    75       for (int i = 0; i < maximization.Length; i++) {
    76         refPoint[i] = maximization[i] ? Math.Min(point2[i], point1[i]) : Math.Max(point2[i], point1[i]);
    77       }
    78 
    79       return refPoint;
    80     }
    81 
    82     public override IDeepCloneable Clone(Cloner cloner) {
    83       return new HypervolumeIndicator(this, cloner);
    8455    }
    8556
    8657    [StorableConstructor]
    8758    protected HypervolumeIndicator(bool deserializing) : base(deserializing) { }
    88     protected HypervolumeIndicator(HypervolumeIndicator original, Cloner cloner)
    89       : base(original, cloner) {
    90     }
     59    protected HypervolumeIndicator(HypervolumeIndicator original, Cloner cloner) : base(original, cloner) { }
     60    public override IDeepCloneable Clone(Cloner cloner) { return new HypervolumeIndicator(this, cloner); }
    9161    public HypervolumeIndicator() { }
    9262  }
Note: See TracChangeset for help on using the changeset viewer.