/// <summary>
        /// Returns a <code>SolutionSet</code> with the North, Sout, East and West
        /// neighbors solutions of ratio 0 of a given location into a given
        /// <code>SolutionSet</code>.
        /// </summary>
        /// <param name="solutionSet">The <code>SolutionSet</code>.</param>
        /// <param name="location">The location.</param>
        /// <returns>A <code>SolutionSet</code> with the neighbors.</returns>
        public SolutionSet GetFourNeighbors(SolutionSet solutionSet, int location)
        {
            //SolutionSet that contains the neighbors (to return)
            SolutionSet neighbors;

            //instance the solutionSet to a non dominated li of individuals
            neighbors = new SolutionSet(24);

            //Gets the neighboords N, S, E, W
            int index;

            //North
            index = structure[location][0][(int)Row.N];
            neighbors.Add(solutionSet.Get(index));

            //South
            index = structure[location][0][(int)Row.S];
            neighbors.Add(solutionSet.Get(index));

            //East
            index = structure[location][0][(int)Row.E];
            neighbors.Add(solutionSet.Get(index));

            //West
            index = structure[location][0][(int)Row.W];
            neighbors.Add(solutionSet.Get(index));

            //Return the list of non-dominated individuals
            return(neighbors);
        }
        /// <summary>
        /// Executes the operation
        /// </summary>
        /// <param name="obj">An object containing the population and the position (index) of the current individual</param>
        /// <returns>An object containing the three selected parents</returns>
        public override object Execute(object obj)
        {
            object[]    parameters = (object[])obj;
            SolutionSet population = (SolutionSet)parameters[0];
            int         index      = (int)parameters[1];

            Solution[] parents = new Solution[3];
            int        r1, r2, r3;

            if (population.Size() < 4)
            {
                throw new Exception("DifferentialEvolutionSelection: the population has less than four solutions");
            }

            do
            {
                r1 = (int)(JMetalRandom.Next(0, population.Size() - 1));
            } while (r1 == index);
            do
            {
                r2 = (int)(JMetalRandom.Next(0, population.Size() - 1));
            } while (r2 == index || r2 == r1);
            do
            {
                r3 = (int)(JMetalRandom.Next(0, population.Size() - 1));
            } while (r3 == index || r3 == r1 || r3 == r2);

            parents[0] = population.Get(r1);
            parents[1] = population.Get(r2);
            parents[2] = population.Get(r3);

            return(parents);
        }
Beispiel #3
0
        public void LoadFront(SolutionSet solutionSet, int notLoadingIndex)
        {
            if (notLoadingIndex >= 0 && notLoadingIndex < solutionSet.Size())
            {
                NumberOfPoints = solutionSet.Size() - 1;
            }
            else
            {
                NumberOfPoints = solutionSet.Size();
            }

            NPoints   = NumberOfPoints;
            dimension = solutionSet.Get(0).NumberOfObjectives;

            Points = new Point[NumberOfPoints];

            int index = 0;

            for (int i = 0; i < solutionSet.Size(); i++)
            {
                if (i != notLoadingIndex)
                {
                    double[] vector = new double[dimension];
                    for (int j = 0; j < dimension; j++)
                    {
                        vector[j] = solutionSet.Get(i).Objective[j];
                    }
                    Points[index++] = new Point(vector);
                }
            }
        }
        public override Solution GetOffspring(SolutionSet solutionSet, int index)
        {
            Solution[] parents   = new Solution[3];
            Solution   offSpring = null;

            try
            {
                int r1, r2;
                do
                {
                    r1 = JMetalRandom.Next(0, solutionSet.Size() - 1);
                } while (r1 == index);
                do
                {
                    r2 = JMetalRandom.Next(0, solutionSet.Size() - 1);
                } while (r2 == index || r2 == r1);

                parents[0] = solutionSet.Get(r1);
                parents[1] = solutionSet.Get(r2);
                parents[2] = solutionSet.Get(index);

                offSpring = (Solution)crossover.Execute(new object[] { solutionSet.Get(index), parents });
            }
            catch (Exception ex)
            {
                Logger.Log.Error("Exception in " + this.GetType().FullName + ".GetOffSpring()", ex);
                Console.Error.WriteLine("Exception in " + this.GetType().FullName + ".GetOffSpring()");
            }

            //Create a new solution, using DE
            return(offSpring);
        }
Beispiel #5
0
        public int GetLessContributorHV(SolutionSet set)
        {
            Front wholeFront = new Front();

            wholeFront.LoadFront(set, -1);

            int    index        = 0;
            double contribution = double.PositiveInfinity;

            for (int i = 0; i < set.Size(); i++)
            {
                double[] v = new double[set.Get(i).NumberOfObjectives];
                for (int j = 0; j < v.Length; j++)
                {
                    v[j] = set.Get(i).Objective[j];
                }
                Point  p   = new Point(v);
                double aux = this.GetExclusiveHV(wholeFront, i);
                if ((aux) < contribution)
                {
                    index        = i;
                    contribution = aux;
                }
                set.Get(i).CrowdingDistance = aux;
            }

            return(index);
        }
Beispiel #6
0
        /// <summary>
        /// Returns a matrix with distances between solutions in a <code>SolutionSet</code>.
        /// </summary>
        /// <param name="solutionSet">The <code>SolutionSet</code>.</param>
        /// <returns>a matrix with distances.</returns>
        public double[][] DistanceMatrix(SolutionSet solutionSet)
        {
            Solution solutionI, solutionJ;

            //The matrix of distances
            double[][] distance = new double[solutionSet.Size()][];

            for (int i = 0; i < solutionSet.Size(); i++)
            {
                distance[i] = new double[solutionSet.Size()];
            }

            //-> Calculate the distances
            for (int i = 0; i < solutionSet.Size(); i++)
            {
                distance[i][i] = 0.0;
                solutionI      = solutionSet.Get(i);
                for (int j = i + 1; j < solutionSet.Size(); j++)
                {
                    solutionJ      = solutionSet.Get(j);
                    distance[i][j] = this.DistanceBetweenObjectives(solutionI, solutionJ);
                    distance[j][i] = distance[i][j];
                }
            }

            //->Return the matrix of distances
            return(distance);
        }
        /// <summary>
        /// Computes the HV contribution of the solutions
        /// </summary>
        /// <param name="solutionSet"></param>
        public void ComputeHVContributions(SolutionSet solutionSet)
        {
            double[] contributions = new double[solutionSet.Size()];
            double   solutionSetHV = 0;

            solutionSetHV = ComputeHypervolume(solutionSet);

            for (int i = 0; i < solutionSet.Size(); i++)
            {
                Solution currentPoint = solutionSet.Get(i);
                solutionSet.Remove(i);

                if (numberOfObjectives == 2)
                {
                    contributions[i] = solutionSetHV - Get2DHV(solutionSet);
                }
                else
                {
                    Front  front = new Front(solutionSet.Size(), numberOfObjectives, solutionSet);
                    double hv    = new WFGHV(numberOfObjectives, solutionSet.Size(), referencePoint).GetHV(front);
                    contributions[i] = solutionSetHV - hv;
                }
                solutionSet.Add(i, currentPoint);
            }

            for (int i = 0; i < solutionSet.Size(); i++)
            {
                solutionSet.Get(i).CrowdingDistance = contributions[i];
            }
        }
Beispiel #8
0
        /// <summary>
        /// Assigns crowding distances to all solutions in a <code>SolutionSet</code>.
        /// </summary>
        /// <param name="solutionSet">The <code>SolutionSet</code>.</param>
        /// <param name="nObjs">Number of objectives.</param>
        public void CrowdingDistanceAssignment(SolutionSet solutionSet, int nObjs)
        {
            int size = solutionSet.Size();

            if (size == 0)
            {
                return;
            }

            if (size == 1)
            {
                solutionSet.Get(0).CrowdingDistance = double.PositiveInfinity;
                return;
            }

            if (size == 2)
            {
                solutionSet.Get(0).CrowdingDistance = double.PositiveInfinity;
                solutionSet.Get(1).CrowdingDistance = double.PositiveInfinity;
                return;
            }

            //Use a new SolutionSet to evite alter original solutionSet
            SolutionSet front = new SolutionSet(size);

            for (int i = 0; i < size; i++)
            {
                front.Add(solutionSet.Get(i));
            }

            for (int i = 0; i < size; i++)
            {
                front.Get(i).CrowdingDistance = 0.0;
            }

            double objetiveMaxn;
            double objetiveMinn;
            double distance;

            for (int i = 0; i < nObjs; i++)
            {
                // Sort the population by Obj n
                front.Sort(new ObjectiveComparator(i));
                objetiveMinn = front.Get(0).Objective[i];
                objetiveMaxn = front.Get(front.Size() - 1).Objective[i];

                //Set de crowding distance
                front.Get(0).CrowdingDistance        = double.PositiveInfinity;
                front.Get(size - 1).CrowdingDistance = double.PositiveInfinity;

                for (int j = 1; j < size - 1; j++)
                {
                    distance  = front.Get(j + 1).Objective[i] - front.Get(j - 1).Objective[i];
                    distance  = distance / (objetiveMaxn - objetiveMinn);
                    distance += front.Get(j).CrowdingDistance;
                    front.Get(j).CrowdingDistance = distance;
                }
            }
        }
        /// <summary>
        /// Computes the feasibility ratio
        /// </summary>
        /// <param name="solutionSet"></param>
        /// <returns>The ratio of feasible solutions</returns>
        private double MeanOveralViolation(SolutionSet solutionSet)
        {
            double aux = 0.0;

            for (int i = 0; i < solutionSet.Size(); i++)
            {
                aux += Math.Abs(solutionSet.Get(i).NumberOfViolatedConstraints *solutionSet.Get(i).OverallConstraintViolation);
            }
            return(aux / (double)solutionSet.Size());
        }
        /// <summary>
        /// Performs the operation
        /// </summary>
        /// <param name="obj">Object representing a SolutionSet.</param>
        /// <returns>An object representing a <code>SolutionSet<code> with the selected parents</returns>
        public override object Execute(object obj)
        {
            SolutionSet population     = (SolutionSet)obj;
            int         populationSize = (int)Parameters["populationSize"];
            SolutionSet result         = new SolutionSet(populationSize);

            //->Ranking the union
            Ranking ranking = new Ranking(population);

            int         remain = populationSize;
            int         index  = 0;
            SolutionSet front  = null;

            population.Clear();

            //-> Obtain the next front
            front = ranking.GetSubfront(index);

            while ((remain > 0) && (remain >= front.Size()))
            {
                //Asign crowding distance to individuals
                distance.CrowdingDistanceAssignment(front, problem.NumberOfObjectives);
                //Add the individuals of this front
                for (int k = 0; k < front.Size(); k++)
                {
                    result.Add(front.Get(k));
                }

                //Decrement remaint
                remain = remain - front.Size();

                //Obtain the next front
                index++;
                if (remain > 0)
                {
                    front = ranking.GetSubfront(index);
                }
            }

            //-> remain is less than front(index).size, insert only the best one
            if (remain > 0)
            {              // front containt individuals to insert
                distance.CrowdingDistanceAssignment(front, problem.NumberOfObjectives);
                front.Sort(crowdingComparator);
                for (int k = 0; k < remain; k++)
                {
                    result.Add(front.Get(k));
                }

                remain = 0;
            }

            return(result);
        }
        private void InitIdealPoint()
        {
            for (int i = 0; i < Problem.NumberOfObjectives; i++)
            {
                z[i]        = 1.0e+30;
                indArray[i] = new Solution(Problem);
                Problem.Evaluate(indArray[i]);
                evaluations++;
            }             // for

            for (int i = 0; i < populationSize; i++)
            {
                UpdateReference(population.Get(i));
            }
        }
Beispiel #12
0
        /// <summary>
        /// Updates the grid limits considering the solutions contained in a <code>SolutionSet</code>.
        /// </summary>
        /// <param name="solutionSet">The <code>SolutionSet</code> considered.</param>
        private void UpdateLimits(SolutionSet solutionSet)
        {
            //Init the lower and upper limits
            for (int obj = 0; obj < objectives; obj++)
            {
                //Set the lower limits to the max real
                lowerLimits[obj] = double.MaxValue;
                //Set the upper limits to the min real
                upperLimits[obj] = double.MinValue;
            }

            //Find the max and min limits of objetives into the population
            for (int ind = 0; ind < solutionSet.Size(); ind++)
            {
                Solution tmpIndividual = solutionSet.Get(ind);
                for (int obj = 0; obj < objectives; obj++)
                {
                    if (tmpIndividual.Objective[obj] < lowerLimits[obj])
                    {
                        lowerLimits[obj] = tmpIndividual.Objective[obj];
                    }
                    if (tmpIndividual.Objective[obj] > upperLimits[obj])
                    {
                        upperLimits[obj] = tmpIndividual.Objective[obj];
                    }
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Return the index of the nearest solution in the solution set to a given solution
        /// </summary>
        /// <param name="solution"></param>
        /// <param name="solutionSet"></param>
        /// <returns>The index of the nearest solution; -1 if the solutionSet is empty</returns>
        public int IndexToNearestSolutionInSolutionSpace(Solution solution, SolutionSet solutionSet)
        {
            int    index           = -1;
            double minimumDistance = double.MaxValue;

            try
            {
                for (int i = 0; i < solutionSet.Size(); i++)
                {
                    double distance = 0;
                    distance = this.DistanceBetweenSolutions(solution, solutionSet.Get(i));
                    if (distance < minimumDistance)
                    {
                        minimumDistance = distance;
                        index           = i;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error("Exception in " + this.GetType().FullName + ".IndexToNearestSolutionInSolutionSpace()", ex);
                Console.WriteLine("Exception in " + this.GetType().FullName + ".IndexToNearestSolutionInSolutionSpace()");
            }
            return(index);
        }
        /// <summary>
        /// Computes the HV of a solution set.
        /// REQUIRES: The problem is bi-objective
        /// REQUIRES: The archive is ordered in descending order by the second objective
        /// </summary>
        /// <param name="solutionSet"></param>
        /// <returns></returns>
        public double Get2DHV(SolutionSet solutionSet)
        {
            double hv = 0.0;

            if (solutionSet.Size() > 0)
            {
                hv = Math.Abs((solutionSet.Get(0).Objective[0] - referencePoint.Objective[0]) * (solutionSet.Get(0).Objective[1] - referencePoint.Objective[1]));

                for (int i = 1; i < solutionSet.Size(); i++)
                {
                    double tmp = Math.Abs((solutionSet.Get(i).Objective[0] - referencePoint.Objective[0]) * (solutionSet.Get(i).Objective[1] - solutionSet.Get(i - 1).Objective[1]));
                    hv += tmp;
                }
            }
            return(hv);
        }
        public double ComputeHypervolume(SolutionSet solutionSet, Solution referencePoint)
        {
            double hv = 0.0;

            if (solutionSet.Size() == 0)
            {
                hv = 0.0;
            }
            else
            {
                this.numberOfObjectives = solutionSet.Get(0).NumberOfObjectives;
                this.referencePoint     = referencePoint;

                if (this.numberOfObjectives == 2)
                {
                    solutionSet.Sort(new ObjectiveComparator(this.numberOfObjectives - 1, true));

                    hv = Get2DHV(solutionSet);
                }
                else
                {
                    WFGHV wfg   = new WFGHV(this.numberOfObjectives, solutionSet.Size());
                    Front front = new Front(solutionSet.Size(), numberOfObjectives, solutionSet);
                    hv = wfg.GetHV(front, referencePoint);
                }
            }

            return(hv);
        }
        public double ComputeHypervolume(SolutionSet solutionSet)
        {
            double hv;

            if (solutionSet.Size() == 0)
            {
                hv = 0.0;
            }
            else
            {
                numberOfObjectives = solutionSet.Get(0).NumberOfObjectives;
                referencePoint     = new Solution(numberOfObjectives);
                UpdateReferencePoint(solutionSet);
                if (numberOfObjectives == 2)
                {
                    solutionSet.Sort(new ObjectiveComparator(numberOfObjectives - 1, true));
                    hv = Get2DHV(solutionSet);
                }
                else
                {
                    UpdateReferencePoint(solutionSet);
                    Front front = new Front(solutionSet.Size(), numberOfObjectives, solutionSet);
                    hv = new WFGHV(numberOfObjectives, solutionSet.Size(), referencePoint).GetHV(front);
                }
            }

            return(hv);
        }
        /// <summary>
        /// Tries to update the reference set one with a <code>Solution</code>.
        /// </summary>
        /// <param name="solution">The <code>Solution</code></param>
        /// <returns>true if the <code>Solution</code> has been inserted, false
        /// otherwise.</returns>
        public bool RefSet1Test(Solution solution)
        {
            bool dominated = false;
            int  flag;
            int  i = 0;

            while (i < refSet1.Size())
            {
                flag = dominance.Compare(solution, refSet1.Get(i));
                if (flag == -1)
                {                 //This is: solution dominates
                    refSet1.Remove(i);
                }
                else if (flag == 1)
                {
                    dominated = true;
                    i++;
                }
                else
                {
                    flag = equal.Compare(solution, refSet1.Get(i));
                    if (flag == 0)
                    {
                        return(true);
                    }
                    i++;
                }
            }

            if (!dominated)
            {
                solution.UnMarked();
                if (refSet1.Size() < refSet1Size)
                {                 //refSet1 isn't full
                    refSet1.Add(solution);
                }
                else
                {
                    archive.Add(solution);
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Performs the operation
        /// </summary>
        /// <param name="obj">Object representing a SolutionSet.</param>
        /// <returns>An object representing an array with the selected parents</returns>
        public override object Execute(object obj)
        {
            SolutionSet population = (SolutionSet)obj;
            int         pos1, pos2;

            pos1 = JMetalRandom.Next(0, population.Size() - 1);
            pos2 = JMetalRandom.Next(0, population.Size() - 1);
            while ((pos1 == pos2) && (population.Size() > 1))
            {
                pos2 = JMetalRandom.Next(0, population.Size() - 1);
            }

            Solution[] parents = new Solution[2];
            parents[0] = population.Get(pos1);
            parents[1] = population.Get(pos2);

            return(parents);
        }
Beispiel #19
0
 /// <summary>
 /// Constructor.
 /// Creates a new instance of Spea2Fitness for a given <code>SolutionSet</code>.
 /// </summary>
 /// <param name="solutionSet">The <code>SolutionSet</code></param>
 public Spea2Fitness(SolutionSet solutionSet)
 {
     this.distanceMatrix = distance.DistanceMatrix(solutionSet);
     this.solutionSet    = solutionSet;
     for (int i = 0; i < solutionSet.Size(); i++)
     {
         solutionSet.Get(i).Location = i;
     }
 }
        /// <summary>
        /// Performs the operation
        /// </summary>
        /// <param name="obj">Object representing a SolutionSet</param>
        /// <returns>The selected solution</returns>
        public override object Execute(object obj)
        {
            SolutionSet population = (SolutionSet)obj;

            if (index == 0)             //Create the permutation
            {
                a = (new PermutationUtility()).IntPermutation(population.Size());
            }

            Solution solution1, solution2;

            solution1 = population.Get(a[index]);
            solution2 = population.Get(a[index + 1]);

            index = (index + 2) % population.Size();

            int flag = dominance.Compare(solution1, solution2);

            if (flag == -1)
            {
                return(solution1);
            }
            else if (flag == 1)
            {
                return(solution2);
            }
            else if (solution1.CrowdingDistance > solution2.CrowdingDistance)
            {
                return(solution1);
            }
            else if (solution2.CrowdingDistance > solution1.CrowdingDistance)
            {
                return(solution2);
            }
            else if (JMetalRandom.NextDouble() < 0.5)
            {
                return(solution1);
            }
            else
            {
                return(solution2);
            }
        }
        /// <summary>
        /// Update the speed of each particle
        /// </summary>
        /// <param name="iter"></param>
        /// <param name="miter"></param>
        private void ComputeSpeed(int iter, int miter)
        {
            double r1, r2, W, C1, C2;
            double wmax, wmin;
            XReal  bestGlobal;

            for (int i = 0; i < swarmSize; i++)
            {
                XReal particle     = new XReal(particles.Get(i));
                XReal bestParticle = new XReal(best[i]);

                //Select a global best for calculate the speed of particle i, bestGlobal
                Solution one, two;
                int      pos1 = JMetalRandom.Next(0, Leaders.Size() - 1);
                int      pos2 = JMetalRandom.Next(0, Leaders.Size() - 1);
                one = Leaders.Get(pos1);
                two = Leaders.Get(pos2);

                if (crowdingDistanceComparator.Compare(one, two) < 1)
                {
                    bestGlobal = new XReal(one);
                }
                else
                {
                    bestGlobal = new XReal(two);
                    //Params for velocity equation
                }
                r1 = JMetalRandom.NextDouble(r1Min, r1Max);
                r2 = JMetalRandom.NextDouble(r2Min, r2Max);
                C1 = JMetalRandom.NextDouble(C1Min, C1Max);
                C2 = JMetalRandom.NextDouble(C2Min, C2Max);
                W  = JMetalRandom.NextDouble(WMin, WMax);

                wmax = WMax;
                wmin = WMin;

                for (int var = 0; var < particle.GetNumberOfDecisionVariables(); var++)
                {
                    //Computing the velocity of this particle
                    speed[i][var] = VelocityConstriction(ConstrictionCoefficient(C1, C2) * (InertiaWeight(iter, miter, wmax, wmin) *
                                                                                            speed[i][var] + C1 * r1 * (bestParticle.GetValue(var) - particle.GetValue(var)) + C2 * r2 * (bestGlobal.GetValue(var) - particle.GetValue(var))),
                                                         deltaMax,
                                                         deltaMin,
                                                         var,
                                                         i);
                }
            }
        }
        /// <summary>
        /// Computes the feasibility ratio
        /// </summary>
        /// <param name="solutionSet"></param>
        /// <returns>The ratio of feasible solutions</returns>
        private double FeasibilityRatio(SolutionSet solutionSet)
        {
            double aux = 0.0;

            for (int i = 0; i < solutionSet.Size(); i++)
            {
                if (solutionSet.Get(i).OverallConstraintViolation < 0)
                {
                    aux = aux + 1.0;
                }
            }
            return(aux / (double)solutionSet.Size());
        }
        /// <summary>
        /// Performs the operation
        /// </summary>
        /// <param name="obj">Object representing a SolutionSet.</param>
        /// <returns>the best solution found</returns>
        public override object Execute(object obj)
        {
            SolutionSet solutionSet = (SolutionSet)obj;

            if (solutionSet.Size() == 0)
            {
                return(null);
            }
            int bestSolution;

            bestSolution = 0;

            for (int i = 1; i < solutionSet.Size(); i++)
            {
                if (comparator.Compare(solutionSet.Get(i), solutionSet.Get(bestSolution)) < 0)
                {
                    bestSolution = i;
                }
            }

            return(bestSolution);
        }
Beispiel #24
0
        /// <summary>
        /// Assigns fitness for all the solutions.
        /// </summary>
        public void FitnessAssign()
        {
            double[] strength   = new double[solutionSet.Size()];
            double[] rawFitness = new double[solutionSet.Size()];
            double   kDistance;


            //Calculate the strength value
            // strength(i) = |{j | j <- SolutionSet and i dominate j}|
            for (int i = 0; i < solutionSet.Size(); i++)
            {
                for (int j = 0; j < solutionSet.Size(); j++)
                {
                    if (dominance.Compare(solutionSet.Get(i), solutionSet.Get(j)) == -1)
                    {
                        strength[i] += 1.0;
                    }
                }
            }


            //Calculate the raw fitness
            // rawFitness(i) = |{sum strenght(j) | j <- SolutionSet and j dominate i}|
            for (int i = 0; i < solutionSet.Size(); i++)
            {
                for (int j = 0; j < solutionSet.Size(); j++)
                {
                    if (dominance.Compare(solutionSet.Get(i), solutionSet.Get(j)) == 1)
                    {
                        rawFitness[i] += strength[j];
                    }
                }
            }


            // Add the distance to the k-th individual. In the reference paper of SPEA2,
            // k = sqrt(population.size()), but a value of k = 1 recommended. See
            // http://www.tik.ee.ethz.ch/pisa/selectors/spea2/spea2_documentation.txt
            int k = 1;

            for (int i = 0; i < distanceMatrix.Length; i++)
            {
                Array.Sort(distanceMatrix[i]);
                kDistance = 1.0 / (distanceMatrix[i][k] + 2.0);                 // Calcule de D(i) distance
                solutionSet.Get(i).Fitness = rawFitness[i] + kDistance;
            }
        }
        /// <summary>
        /// Performs the operation
        /// </summary>
        /// <param name="obj">Object representing a SolutionSet</param>
        /// <returns>The selected solution</returns>
        public override object Execute(object obj)
        {
            SolutionSet solutionSet = (SolutionSet)obj;
            Solution    solution1, solution2;

            solution1 = solutionSet.Get(JMetalRandom.Next(0, solutionSet.Size() - 1));
            solution2 = solutionSet.Get(JMetalRandom.Next(0, solutionSet.Size() - 1));

            if (solutionSet.Size() >= 2)
            {
                while (solution1 == solution2)
                {
                    solution2 = solutionSet.Get(JMetalRandom.Next(0, solutionSet.Size() - 1));
                }
            }

            int flag = comparator.Compare(solution1, solution2);

            if (flag == -1)
            {
                return(solution1);
            }
            else if (flag == 1)
            {
                return(solution2);
            }
            else
            if (JMetalRandom.NextDouble() < 0.5)
            {
                return(solution1);
            }
            else
            {
                return(solution2);
            }
        }
        /// <summary>
        /// Returns a <code>SolutionSet</code> with the North, Sout, East, West,
        /// North-West, South-West, North-East and South-East neighbors solutions of
        /// ratio 0 of a given location into a given <code>SolutionSet</code>.
        /// solutions of a given location into a given <code>SolutionSet</code>.
        /// </summary>
        /// <param name="population">The <code>SolutionSet</code>.</param>
        /// <param name="individual">The individual.</param>
        /// <returns>A <code>SolutionSet</code> with the neighbors.</returns>
        public SolutionSet GetEightNeighbors(SolutionSet population, int individual)
        {
            //SolutionSet that contains the neighbors (to return)
            SolutionSet neighbors;

            //instance the population to a non dominated li of individuals
            neighbors = new SolutionSet(24);

            //Gets the neighboords N, S, E, W
            int index;

            //N
            index = this.structure[individual][0][(int)Row.N];
            neighbors.Add(population.Get(index));

            //S
            index = this.structure[individual][0][(int)Row.S];
            neighbors.Add(population.Get(index));

            //E
            index = this.structure[individual][0][(int)Row.E];
            neighbors.Add(population.Get(index));

            //W
            index = this.structure[individual][0][(int)Row.W];
            neighbors.Add(population.Get(index));

            //NE
            index = this.structure[individual][0][(int)Row.NE];
            neighbors.Add(population.Get(index));

            //NW
            index = this.structure[individual][0][(int)Row.NW];
            neighbors.Add(population.Get(index));

            //SE
            index = this.structure[individual][0][(int)Row.SE];
            neighbors.Add(population.Get(index));

            //SW
            index = this.structure[individual][0][(int)Row.SW];
            neighbors.Add(population.Get(index));

            //Return the list of non-dominated individuals
            return(neighbors);
        }
        /// <summary>
        /// Updates the reference point
        /// </summary>
        /// <param name="solutionSet"></param>
        private void UpdateReferencePoint(SolutionSet solutionSet)
        {
            double[] maxObjectives = new double[numberOfObjectives];
            for (int i = 0; i < numberOfObjectives; i++)
            {
                maxObjectives[i] = 0;
            }

            for (int i = 0; i < solutionSet.Size(); i++)
            {
                for (int j = 0; j < numberOfObjectives; j++)
                {
                    if (maxObjectives[j] < solutionSet.Get(i).Objective[j])
                    {
                        maxObjectives[j] = solutionSet.Get(i).Objective[j];
                    }
                }
            }

            for (int i = 0; i < referencePoint.NumberOfObjectives; i++)
            {
                referencePoint.Objective[i] = maxObjectives[i] + offset;
            }
        }
Beispiel #28
0
        /// <summary>
        /// Returns the minimum distance from a <code>Solution</code> to a
        /// <code>SolutionSet according to the encodings.variable values</code>.
        /// </summary>
        /// <param name="solution">The <code>Solution</code></param>
        /// <param name="solutionSet">The <code>SolutionSet</code>.</param>
        /// <returns>The minimum distance between solution and the set.</returns>
        public double DistanceToSolutionSetInSolutionSpace(Solution solution, SolutionSet solutionSet)
        {
            //At start point the distance is the max
            double distance = double.MaxValue;

            // found the min distance respect to population
            for (int i = 0; i < solutionSet.Size(); i++)
            {
                double aux = this.DistanceBetweenSolutions(solution, solutionSet.Get(i));
                if (aux < distance)
                {
                    distance = aux;
                }
            }

            //->Return the best distance
            return(distance);
        }
Beispiel #29
0
        /// <summary>
        /// Updates the grid adding solutions contained in a specific
        /// <code>SolutionSet</code>.
        /// <b>REQUIRE</b> The grid limits must have been previously calculated.
        /// </summary>
        /// <param name="solutionSet">The <code>SolutionSet</code> considered.</param>
        private void AddSolutionSet(SolutionSet solutionSet)
        {
            //Calculate the location of all individuals and update the grid
            MostPopulated = 0;
            int location;

            for (int ind = 0; ind < solutionSet.Size(); ind++)
            {
                location = Location(solutionSet.Get(ind));
                hypercubes[location]++;
                if (hypercubes[location] > hypercubes[MostPopulated])
                {
                    MostPopulated = location;
                }
            }

            //The grid has been updated, so also update ocuppied's hypercubes
            CalculateOccupied();
        }
Beispiel #30
0
        public Front(int numberOfPoints, int dimension, SolutionSet solutionSet)
        {
            this.maximizing      = true;
            this.pointComparator = new PointComparator(maximizing);
            this.NumberOfPoints  = numberOfPoints;
            this.dimension       = dimension;
            this.NPoints         = numberOfPoints;

            this.Points = new Point[numberOfPoints];
            for (int i = 0; i < numberOfPoints; i++)
            {
                double[] p = new double[dimension];
                for (int j = 0; j < dimension; j++)
                {
                    p[j] = solutionSet.Get(i).Objective[j];
                }
                Points[i] = new Point(p);
            }
        }