1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
5 | using HeuristicLab.Problems.MultiObjectiveTestFunctions.Comparators;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Problems.MultiObjectiveTestFunctions {
|
---|
8 |
|
---|
9 |
|
---|
10 | /// <summary>
|
---|
11 | /// Spacing is defined as the standarddeviation of all d[i]
|
---|
12 | /// where d[i] is the minimum eukildean distance any point has
|
---|
13 | /// to all OTHER points in the same front
|
---|
14 | /// </summary>
|
---|
15 | public class Spacing : IMultiObjectiveDistance {
|
---|
16 |
|
---|
17 | public Spacing() { }
|
---|
18 |
|
---|
19 |
|
---|
20 | public static double GetSpacing(IEnumerable<double[]> front) {
|
---|
21 | return new Spacing().Get(front);
|
---|
22 | }
|
---|
23 | public static double GetDistance(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront) {
|
---|
24 | return new Spacing().Get(front);
|
---|
25 | }
|
---|
26 |
|
---|
27 | public double Compare(IEnumerable<double[]> front, IEnumerable<double[]> optimalFront) {
|
---|
28 | return GetSpacing(front) - GetSpacing(optimalFront);
|
---|
29 | }
|
---|
30 |
|
---|
31 | public double Get(IEnumerable<double[]> front) {
|
---|
32 | //TODO build a kd-tree, sort the array, do someting intelligent here
|
---|
33 | if (front == null) throw new ArgumentException("Fronts must not be null");
|
---|
34 | List<double> d = new List<double>();
|
---|
35 | foreach (double[] r in front) {
|
---|
36 | double dist = Utilities.minDistance(r, front, false);
|
---|
37 | d.Add(dist>=0?dist:0);
|
---|
38 | }
|
---|
39 | int n = d.Count;
|
---|
40 | if (n == 0) throw new ArgumentException("Fronts must not be empty");
|
---|
41 | return Math.Sqrt(d.Variance()*(n-1)/n);
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 | }
|
---|
46 | }
|
---|