public void GenerationalDistanceTestEmptyFront()
 {
     double[] point = new double[2];
     point[0] = 0.5;
     point[1] = 0.5;
     double[][] front          = { };
     double[][] referencefront = { point };
     GenerationalDistance.Calculate(front, referencefront, 1);
 }
        public void GenerationalDistanceTestSinglePoint()
        {
            double[] point = new double[2];
            point[0] = 0;
            point[1] = 0;
            double[][] front  = { point };
            double[]   point2 = new double[2];
            point2[0] = 1;
            point2[1] = 1;
            double[][] referencefront = { point2 };
            double     dist           = GenerationalDistance.Calculate(front, referencefront, 1);

            Assert.AreEqual(Math.Sqrt(2), dist);
        }
        public void GenerationalDistanceTestSamePoint()
        {
            double[] point = new double[2];
            point[0] = 0.5;
            point[1] = 0.5;
            double[][] front  = { point };
            double[]   point1 = new double[2];
            point1[0] = 0.5;
            point1[1] = 0.5;
            double[][] referencefront = { point1 };
            double     dist           = GenerationalDistance.Calculate(front, referencefront, 1);

            Assert.AreEqual(0, dist);
        }
        private void Analyze()
        {
            ResultsScatterPlot = new ParetoFrontScatterPlot(solutions.Select(x => x.Fitness).ToArray(), solutions.Select(x => x.Mean.ToArray()).ToArray(), ResultsScatterPlot.ParetoFront, ResultsScatterPlot.Objectives, ResultsScatterPlot.ProblemSize);
            ResultsSolutions   = solutions.Select(x => x.Mean.ToArray()).ToMatrix();

            var problem = Problem as MultiObjectiveTestFunctionProblem;

            if (problem == null)
            {
                return;
            }

            var front = NonDominatedSelect.GetDominatingVectors(solutions.Select(x => x.Fitness), problem.ReferencePoint.CloneAsArray(), Problem.Maximization, true).ToArray();

            if (front.Length == 0)
            {
                return;
            }
            var bounds = problem.Bounds.CloneAsMatrix();

            ResultsCrowding             = Crowding.Calculate(front, bounds);
            ResultsSpacing              = Spacing.Calculate(front);
            ResultsGenerationalDistance = problem.BestKnownFront != null?GenerationalDistance.Calculate(front, problem.BestKnownFront.ToJaggedArray(), 1) : double.NaN;

            ResultsInvertedGenerationalDistance = problem.BestKnownFront != null?InvertedGenerationalDistance.Calculate(front, problem.BestKnownFront.ToJaggedArray(), 1) : double.NaN;

            ResultsHypervolume     = Hypervolume.Calculate(front, problem.ReferencePoint.CloneAsArray(), Problem.Maximization);
            ResultsBestHypervolume = Math.Max(ResultsHypervolume, ResultsBestHypervolume);
            ResultsDifferenceBestKnownHypervolume = ResultsBestKnownHypervolume - ResultsBestHypervolume;

            ResultsBestHypervolumeDataLine.Values.Add(ResultsBestHypervolume);
            ResultsHypervolumeDataLine.Values.Add(ResultsHypervolume);
            ResultsCrowdingDataLine.Values.Add(ResultsCrowding);
            ResultsGenerationalDistanceDataLine.Values.Add(ResultsGenerationalDistance);
            ResultsInvertedGenerationalDistanceDataLine.Values.Add(ResultsInvertedGenerationalDistance);
            ResultsSpacingDataLine.Values.Add(ResultsSpacing);
            ResultsHypervolumeDifferenceDataLine.Values.Add(ResultsDifferenceBestKnownHypervolume);

            Problem.Analyze(
                solutions.Select(x => (Optimization.Individual) new SingleEncodingIndividual(Problem.Encoding, new Scope {
                Variables = { new Variable(Problem.Encoding.Name, x.Mean) }
            })).ToArray(),
                solutions.Select(x => x.Fitness).ToArray(),
                Results,
                random);
        }
        public void GenerationalDistanceTestDifferentSizes()
        {
            double[] point = new double[2];
            point[0] = 0;
            point[1] = 0;
            double[] point1 = new double[2];
            point1[0] = 1;
            point1[1] = 0.5;
            double[][] front  = { point, point1 };
            double[]   point2 = new double[2];
            point2[0] = 1;
            point2[1] = 0;
            double[][] referencefront = { point2 };
            double     dist           = GenerationalDistance.Calculate(front, referencefront, 1);

            Assert.AreEqual(0.75, dist);
        }
        public void GenerationalDistanceTestQuadratic()
        {
            double[] point = new double[2];
            point[0] = 0;
            point[1] = 0;
            double[] point1 = new double[2];
            point1[0] = 0;
            point1[1] = 1;
            double[][] front  = { point, point1 };
            double[]   point2 = new double[2];
            point2[0] = 1;
            point2[1] = 0;
            double[] point3 = new double[2];
            point3[0] = 1;
            point3[1] = 1;
            double[][] referencefront = { point2, point3 };
            double     dist           = GenerationalDistance.Calculate(front, referencefront, 1);

            Assert.AreEqual(1, dist);
        }