public override void Draw(Canvas canvas, RectangleF rectangle, Color color)
        {
            canvas.FillRect(rectangle, color * BackgroundTint);

            var padding = Padding.Calculate();

            var size = Math.Min(rectangle.Width, rectangle.Height) - padding * 2;

            var spacing = Spacing.Calculate();

            var rx = Rx.Calculate(size);
            var ry = Ry.Calculate(size);

            Vector2 step = Vector2.Zero;

            if (rectangle.Width > rectangle.Height)
            {
                step = new Vector2(size + spacing, 0);
            }
            else
            {
                step = new Vector2(0, size + spacing);
            }

            var startC = rectangle.Center - step * Count / 2f;
            var bounds = new RectangleF(startC.X - size / 2, startC.Y - size / 2, size, size);

            for (var idx = 0; idx < Count; ++idx)
            {
                canvas.FillRoundRect(bounds, new Vector2(rx, ry), color);
                bounds = bounds.Offset(step);
            }
        }
        public void SpacingTestSinglePoint()
        {
            double[] point = new double[2];
            point[0] = 0;
            point[1] = 0;
            double[][] front = { point };
            double     dist  = Spacing.Calculate(front);

            Assert.AreEqual(0, dist);
        }
        public void SpacingTestSamePoint()
        {
            double[] point = new double[2];
            point[0] = 0.5;
            point[1] = 0.5;

            double[] point1 = new double[2];
            point1[0] = 0.5;
            point1[1] = 0.5;
            double[][] front = { point, point1 };
            double     dist  = Spacing.Calculate(front);

            Assert.AreEqual(0, dist);
        }
Exemplo n.º 4
0
        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 SpacingTestRectangular()
        {
            double[] point = new double[2];
            point[0] = 0;
            point[1] = 0;
            double[] point1 = new double[2];
            point1[0] = 0;
            point1[1] = 1;

            double[] point2 = new double[2];
            point2[0] = 2;
            point2[1] = 0;
            double[] point3 = new double[2];
            point3[0] = 2;
            point3[1] = 1;
            double[][] front = { point, point1, point2, point3 };
            double     dist  = Spacing.Calculate(front);

            Assert.AreEqual(0, dist);
        }
        public void SpacingTestDeltoid()
        {
            double[] point = new double[2];
            point[0] = 0;
            point[1] = 0;
            double[] point1 = new double[2];
            point1[0] = 0;
            point1[1] = 1;

            double[] point2 = new double[2];
            point2[0] = 1;
            point2[1] = 0;
            double[] point3 = new double[2];
            point3[0] = 4;
            point3[1] = 4;
            double[][] front = { point, point1, point2, point3 };
            double     dist  = Spacing.Calculate(front);

            Assert.AreEqual(Math.Sqrt(3), dist);
        }
        public void SpacingTestEmptyFront()
        {
            double[][] front = { };

            Spacing.Calculate(front);
        }