Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/08/16 15:30:46 (8 years ago)
Author:
bwerth
Message:

#1087 several fixes according to the reviev comments in comment 31

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Calculators/HyperVolume.cs

    r14018 r14030  
    5252    /// </summary>
    5353    ///
    54     public static double Calculate(IEnumerable<double[]> points, double[] referencePoint, bool[] maximization) {
    55       var front = NonDominatedSelect.removeNonReferenceDominatingVectors(points, referencePoint, maximization, false);
     54    public static double Calculate(IEnumerable<double[]> front, double[] referencePoint, bool[] maximization) {
     55      front = NonDominatedSelect.removeNonReferenceDominatingVectors(front, referencePoint, maximization, false);
    5656      if (maximization.Length == 2)
    5757        return Calculate2D(front, referencePoint, maximization);
    5858
    5959      if (Array.TrueForAll(maximization, x => !x))
    60         return CalculateMD(front, referencePoint);
     60        return CalculateMulitDimensional(front, referencePoint);
    6161      else throw new NotImplementedException("Hypervolume calculation for more than two dimensions is supported only with minimization problems.");
    6262    }
     
    7070      if (referencePoint.Length != 2) throw new ArgumentException("ReferencePoint must have exactly two dimensions.");
    7171
    72       double[][] set = front.ToArray();   //Still no Good
     72      double[][] set = front.ToArray();
    7373      if (set.Any(s => s.Length != 2)) throw new ArgumentException("Points in front must have exactly two dimensions.");
    7474
     
    7777      double sum = 0;
    7878      for (int i = 0; i < set.Length - 1; i++) {
    79         if (NonDominatedSelect.Dominates(referencePoint, set[i], maximization, true) == NonDominatedSelect.DominationResult.Dominates)
    80           throw new ArgumentException("Reference Point must be dominated by all points of the front");
    8179        sum += Math.Abs((set[i][0] - set[i + 1][0])) * Math.Abs((set[i][1] - referencePoint[1]));
    8280      }
    8381
    8482      double[] lastPoint = set[set.Length - 1];
    85       if (NonDominatedSelect.Dominates(referencePoint, lastPoint, maximization, true) == NonDominatedSelect.DominationResult.Dominates)
    86         throw new ArgumentException("Reference Point must be dominated by all points of the front");
    8783      sum += Math.Abs(lastPoint[0] - referencePoint[0]) * Math.Abs(lastPoint[1] - referencePoint[1]);
    8884
     
    9288
    9389
    94     private static double CalculateMD(IEnumerable<double[]> points, double[] referencePoint) {
     90    private static double CalculateMulitDimensional(IEnumerable<double[]> front, double[] referencePoint) {
    9591      if (referencePoint == null || referencePoint.Length < 3) throw new ArgumentException("ReferencePoint unfit for complex Hypervolume calculation");
    96       if (!IsDominated(referencePoint, points)) {
    97         throw new ArgumentException("ReferencePoint unfit for complex Hypervolume calculation");
    98       }
    9992
    10093      int objectives = referencePoint.Length;
    101       var front = points.ToList();
    102       front.StableSort(new Utilities.DimensionComparer(objectives - 1, false));
     94      var fronList = front.ToList();
     95      fronList.StableSort(new Utilities.DimensionComparer(objectives - 1, false));
    10396
    10497      double[] regLow = Enumerable.Repeat(1E15, objectives).ToArray();
    105       foreach (double[] p in front) {
     98      foreach (double[] p in fronList) {
    10699        for (int i = 0; i < regLow.Length; i++) {
    107100          if (p[i] < regLow[i]) regLow[i] = p[i];
     
    109102      }
    110103
    111       return Stream(regLow, referencePoint, front, 0, referencePoint[objectives - 1], (int)Math.Sqrt(front.Count), objectives);
    112     }
    113 
    114     private static bool IsDominated(double[] referencePoint, IEnumerable<double[]> points) {
    115       foreach (double[] point in points) {
    116         for (int i = 0; i < referencePoint.Length; i++) {
    117           if (referencePoint[i] < point[i]) {
    118             return false;
    119           }
    120         }
    121       }
    122       return true;
    123     }
    124 
    125     private static double Stream(double[] regionLow, double[] regionUp, List<double[]> points, int split, double cover, int sqrtNoPoints, int objectives) {
     104      return Stream(regLow, referencePoint, fronList, 0, referencePoint[objectives - 1], (int)Math.Sqrt(fronList.Count), objectives);
     105    }
     106
     107    private static double Stream(double[] regionLow, double[] regionUp, List<double[]> front, int split, double cover, int sqrtNoPoints, int objectives) {
    126108      double coverOld = cover;
    127109      int coverIndex = 0;
     
    131113
    132114      double dMeasure = GetMeasure(regionLow, regionUp, objectives);
    133       while (cover == coverOld && coverIndex < points.Count()) {
     115      while (cover == coverOld && coverIndex < front.Count()) {
    134116        if (coverIndexOld == coverIndex) break;
    135117        coverIndexOld = coverIndex;
    136         if (Covers(points[coverIndex], regionLow, objectives)) {
    137           cover = points[coverIndex][objectives - 1];
     118        if (Covers(front[coverIndex], regionLow, objectives)) {
     119          cover = front[coverIndex][objectives - 1];
    138120          result += dMeasure * (coverOld - cover);
    139121        } else coverIndex++;
     
    141123      }
    142124
    143       for (c = coverIndex; c > 0; c--) if (points[c - 1][objectives - 1] == cover) coverIndex--;
     125      for (c = coverIndex; c > 0; c--) if (front[c - 1][objectives - 1] == cover) coverIndex--;
    144126      if (coverIndex == 0) return result;
    145127
     
    147129      int[] piles = new int[coverIndex];
    148130      for (int i = 0; i < coverIndex; i++) {
    149         piles[i] = IsPile(points[i], regionLow, regionUp, objectives);
     131        piles[i] = IsPile(front[i], regionLow, regionUp, objectives);
    150132        if (piles[i] == -1) {
    151133          allPiles = false;
     
    161143        int i = 0;
    162144        do {
    163           current = points[i][objectives - 1];
     145          current = front[i][objectives - 1];
    164146          do {
    165             if (points[i][piles[i]] < trellis[piles[i]]) trellis[piles[i]] = points[i][piles[i]];
     147            if (front[i][piles[i]] < trellis[piles[i]]) trellis[piles[i]] = front[i][piles[i]];
    166148            i++;
    167             if (i < coverIndex) next = points[i][objectives - 1];
     149            if (i < coverIndex) next = front[i][objectives - 1];
    168150            else { next = cover; break; }
    169151          } while (next == current);
     
    179161        do {
    180162          for (int i = 0; i < coverIndex; i++) {
    181             int contained = ContainesBoundary(points[i], regionLow, split);
    182             if (contained == 0) boundaries[boundIdx++] = points[i][split];
    183             else if (contained == 1) noBoundaries[noBoundIdx++] = points[i][split];
     163            int contained = ContainesBoundary(front[i], regionLow, split);
     164            if (contained == 0) boundaries[boundIdx++] = front[i][split];
     165            else if (contained == 1) noBoundaries[noBoundIdx++] = front[i][split];
    184166          }
    185167          if (boundIdx > 0) bound = GetMedian(boundaries, boundIdx);
     
    197179
    198180        for (int i = 0; i < coverIndex; i++) {
    199           if (PartCovers(points[i], regionUpC, objectives)) pointsChildUp.Add(points[i]);
    200           if (PartCovers(points[i], regionUp, objectives)) pointsChildLow.Add(points[i]);
     181          if (PartCovers(front[i], regionUpC, objectives)) pointsChildUp.Add(front[i]);
     182          if (PartCovers(front[i], regionUp, objectives)) pointsChildLow.Add(front[i]);
    201183        }
    202184        //this could/should be done in Parallel
Note: See TracChangeset for help on using the changeset viewer.