Exemplo n.º 1
0
        public int LeastContributer(IReadOnlyList <Individual> front, MultiObjectiveBasicProblem <RealVectorEncoding> problem)
        {
            var bounds    = problem.Encoding.Bounds;
            var extracted = front.Select(x => x.PenalizedFitness).ToArray();

            if (extracted.Length <= 2)
            {
                return(0);
            }
            var pointsums = new double[extracted.Length];

            for (var dim = 0; dim < problem.Maximization.Length; dim++)
            {
                var arr = extracted.Select(x => x[dim]).ToArray();
                Array.Sort(arr);
                var fmax     = problem.Encoding.Bounds[dim % bounds.Rows, 1];
                var fmin     = bounds[dim % bounds.Rows, 0];
                var pointIdx = 0;
                foreach (var point in extracted)
                {
                    var pos = Array.BinarySearch(arr, point[dim]);
                    var d   = pos != 0 && pos != arr.Length - 1 ? (arr[pos + 1] - arr[pos - 1]) / (fmax - fmin) : double.PositiveInfinity;
                    pointsums[pointIdx] += d;
                    pointIdx++;
                }
            }
            return(pointsums.Select((value, index) => new { value, index }).OrderBy(x => x.value).First().index);
        }
Exemplo n.º 2
0
        public int LeastContributer(IReadOnlyList <Individual> front, MultiObjectiveBasicProblem <RealVectorEncoding> problem)
        {
            var frontCopy = front.Select(x => x.PenalizedFitness).ToList();

            if (frontCopy.Count <= 1)
            {
                return(0);
            }
            var p             = problem as MultiObjectiveTestFunctionProblem;
            var refPoint      = BuildReferencePoint(p != null ? frontCopy.Concat(new[] { p.ReferencePoint.CloneAsArray() }) : frontCopy, problem.Maximization);
            var contributions = Enumerable.Range(0, frontCopy.Count).Select(i => Contribution(frontCopy, i, problem.Maximization, refPoint));

            return(contributions.Select((value, index) => new { value, index }).OrderBy(x => x.value).First().index);
        }
Exemplo n.º 3
0
        public int LeastContributer(IReadOnlyList <Individual> front, MultiObjectiveBasicProblem <RealVectorEncoding> problem)
        {
            var extracted = front.Select(x => x.PenalizedFitness).ToArray();

            if (extracted.Length <= 2)
            {
                return(0);
            }
            var distances = CalcDistances(extracted);
            var mindexI   = 0;
            var mindexJ   = 0;
            var min       = double.MaxValue;

            for (var i = 0; i < extracted.Length; i++)
            {
                var d    = double.MaxValue;
                var minj = 0;
                for (var j = 0; j < extracted.Length; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    var d1 = distances[i, j];
                    if (!(d1 < d))
                    {
                        continue;
                    }
                    minj = j;
                    d    = d1;
                }
                if (!(d < min))
                {
                    continue;
                }
                min     = d;
                mindexI = i;
                mindexJ = minj;
            }

            //break tie with distance to second nearest
            var minI = double.MaxValue;
            var minJ = double.MaxValue;

            for (var i = 0; i < extracted.Length; i++)
            {
                double d;
                if (mindexI != i)
                {
                    d = distances[mindexI, i];
                    if (!d.IsAlmost(min))
                    {
                        minI = Math.Min(minI, d);
                    }
                }
                if (mindexJ == i)
                {
                    continue;
                }
                d = distances[mindexJ, i];
                if (!d.IsAlmost(min))
                {
                    minJ = Math.Min(minJ, d);
                }
            }

            //find min
            return(minI < minJ ? mindexI : mindexJ);
        }