Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/15/16 17:19:34 (8 years ago)
Author:
bwerth
Message:

#1087 regorganized testfunctions, added view for qualities

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Comparators/GenerationalDistance.cs

    r13562 r13620  
    11using System;
     2using System.Collections.Generic;
    23using HeuristicLab.Encodings.RealVectorEncoding;
     4using HeuristicLab.Problems.MultiObjectiveTestFunctions.Comparators;
    35
    46namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
     
    1517    }
    1618
    17 
    18     public static double GetDistance(RealVector[] front, RealVector[] optimalFront, double p) {
     19    public static double GetDistance(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront, double p) {
    1920     return new GenerationalDistance(p).Compare(front,optimalFront);
    2021    }
    2122
    22     public double Compare(RealVector[] front, RealVector[] optimalFront) {
    23      //TODO build a kd-tree, sort the array, do someting intelligent here
    24      double sum = 0;
    25       if (front.Length == 0 || optimalFront.Length == 0) throw new Exception("Both Fronts need to contain at least one point");
    26      foreach(RealVector r in front) {
    27         sum += minDistance(r, optimalFront);
     23    public double Compare(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront) {
     24      //TODO build a kd-tree, sort the array, do someting intelligent here
     25      if (front == null || optimalFront == null) throw new ArgumentException("Fronts must not be null");
     26      double sum = 0;
     27      int c = 0;
     28     foreach(double[] r in front) {
     29        sum += Utilities.minDistance(r, optimalFront,true);
     30        c++;
    2831      }
    29       return Math.Pow(sum, p) /front.Length;
     32      if (c == 0) throw new ArgumentException("Fronts must not be empty");
     33      return Math.Pow(sum, p) /c;
    3034    }
    3135
    32     private double minDistance(RealVector point, RealVector[] list) {
    33       //TODO inefficient
    34       double min = Double.MaxValue;
    35       foreach (RealVector r in list) {
    36         if (r == point) continue;
    37         double d = 0;
    38         for (int i = 0; i < r.Length; i++) {
    39           d += (point[i] - r[i]) * (point[i] - r[i]);
    40         }
    41         min = Math.Min(d, min);
    42       }
    43       return Math.Sqrt(min);
    44     }
     36   
    4537
    4638  }
Note: See TracChangeset for help on using the changeset viewer.