Exemplo n.º 1
0
 /**
  * Returns the inverted generational distance of solution set
  * @param solutionSet Solution set
  * @return The value of the hypervolume indicator
  */
 public double GetIgd(SolutionSet solutionSet)
 {
     return new InvertedGenerationalDistance().Compute(
         solutionSet.WriteObjectivesToMatrix(),
         _trueParetoFront.WriteObjectivesToMatrix(),
         _problem.NumberOfObjectives);
 }
Exemplo n.º 2
0
 public QualityIndicator(Problem problem, String paretoFrontFile)
 {
     _problem = problem;
     _trueParetoFront = MetricsUtil.ReadNonDominatedSolutionSet(paretoFrontFile);
     _trueParetoFrontHypervolume = new Hypervolume().HypervolumeValue(
         _trueParetoFront.WriteObjectivesToMatrix(),
         _trueParetoFront.WriteObjectivesToMatrix(),
         _problem.NumberOfObjectives);
 }
 /**
  * Computes the feasibility ratio
  * Return the ratio of feasible solutions
  */
 public double MeanOveralViolation(SolutionSet solutionSet)
 {
     double aux = 0.0;
     for (int i = 0; i < solutionSet.Size(); i++)
     {
         aux += Math.Abs(solutionSet[i].NumberOfViolatedConstraints*
                         solutionSet[i].OverallConstraintViolation);
     }
     return aux/solutionSet.Size();
 }
Exemplo n.º 4
0
        /** Assigns crowding distances to all solutions in a <code>SolutionSet</code>.
           * @param solutionSet The <code>SolutionSet</code>.
           * @param nObjs Number of objectives.
           */
        public static void CrowdingDistanceAssignment(SolutionSet solutionSet, int nObjs)
        {
            int size = solutionSet.Size();

            if (size == 0)
            {
                return;
            }

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

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

            //Use a new SolutionSet to evite alter original solutionSet
            SolutionSet front = new SolutionSet(size);
            for (int i = 0; i < size; i++)
            {
                front.Add(solutionSet[i]);
            }

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

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

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

                for (int j = 1; j < size - 1; j++)
                {
                    double distance = front[j + 1].Objective[i] - front[j - 1].Objective[i];
                    distance = distance/(objetiveMaxn - objetiveMinn);
                    distance += front[j].CrowdingDistance;
                    front[j].CrowdingDistance = (distance);
                } // for
            } // for
        }
 /**
    * Computes the feasibility ratio
    * Return the ratio of feasible solutions
    */
 public double FeasibilityRatio(SolutionSet solutionSet)
 {
     double aux = 0.0;
     for (int i = 0; i < solutionSet.Size(); i++)
     {
         if (solutionSet[i].OverallConstraintViolation < 0)
         {
             aux = aux + 1.0;
         }
     }
     return aux/solutionSet.Size();
 }
        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[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[k]);
                }
            }

            return result;
        }
Exemplo n.º 7
0
        public Ranking(SolutionSet solutionSet)
        {
            _solutionSet = solutionSet;

            // dominateMe[i] contains the number of solutions dominating i
            int[] dominateMe = new int[_solutionSet.Size()];

            // iDominate[k] contains the list of solutions dominated by k
            List<int>[] iDominate = new List<int>[_solutionSet.Size()];

            // front[i] contains the list of individuals belonging to the front i
            List<int>[] front = new List<int>[_solutionSet.Size() + 1];

            // flagDominate is an auxiliar encodings.variable
            int flagDominate;

            // Initialize the fronts
            for (int k = 0; k < front.Length; k++)
            {
                front[k] = new List<int>();
            }

            //-> Fast non dominated sorting algorithm
            // Contribution of Guillaume Jacquenot
            for (int p = 0; p < _solutionSet.Size(); p++)
            {
                // Initialize the list of individuals that i dominate and the number
                // of individuals that dominate me
                iDominate[p] = new List<int>();
                dominateMe[p] = 0;
            }
            for (int p = 0; p < (_solutionSet.Size() - 1); p++)
            {
                // For all q individuals , calculate if p dominates q or vice versa
                for (int q = p + 1; q < _solutionSet.Size(); q++)
                {
                    flagDominate = Constraint.Compare(solutionSet[p], solutionSet[q]);
                    if (flagDominate == 0)
                    {
                        flagDominate = Dominance.Compare(solutionSet[p], solutionSet[q]);
                    }
                    if (flagDominate == -1)
                    {
                        iDominate[p].Add(q);
                        dominateMe[q]++;
                    }
                    else if (flagDominate == 1)
                    {
                        iDominate[q].Add(p);
                        dominateMe[p]++;
                    }
                }
                // If nobody dominates p, p belongs to the first front
            }
            for (int p = 0; p < _solutionSet.Size(); p++)
            {
                if (dominateMe[p] == 0)
                {
                    front[0].Add(p);
                    solutionSet[p].Rank = 0;
                }
            }

            //Obtain the rest of fronts
            int i = 0;
            IEnumerator<int> it1; // Iterators
            while (front[i].Count != 0)
            {
                i++;
                it1 = front[i - 1].GetEnumerator();
                while (it1.MoveNext())
                {
                    IEnumerator<int> it2 = iDominate[it1.Current].GetEnumerator(); // Iterators
                    while (it2.MoveNext())
                    {
                        int index = it2.Current;
                        dominateMe[index]--;
                        if (dominateMe[index] == 0)
                        {
                            front[i].Add(index);
                            _solutionSet[index].Rank = i;
                        }
                    }
                }
            }
            //<-

            _ranking = new SolutionSet[i];
            //0,1,2,....,i-1 are front, then i fronts
            for (int j = 0; j < i; j++)
            {
                _ranking[j] = new SolutionSet(front[j].Count);
                it1 = front[j].GetEnumerator();
                while (it1.MoveNext())
                {
                    _ranking[j].Add(solutionSet[it1.Current]);
                }
            }
        }
 /**
  * Updates the threshold value using the population
  */
 public void UpdateThreshold(SolutionSet set)
 {
     _threshold = FeasibilityRatio(set)*MeanOveralViolation(set);
 }
Exemplo n.º 9
0
        /**
         * Updates the grid limits and the grid content adding the solutions contained
         * in a specific <code>SolutionSet</code>.
         * @param solutionSet The <code>SolutionSet</code>.
         */
        public void updateGrid(SolutionSet solutionSet)
        {
            //Update lower and upper limits
            UpdateLimits(solutionSet);

            //Calculate the division Size
            for (int obj = 0; obj < _objectives; obj++)
            {
                _divisionSize[obj] = _upperLimits[obj] - _lowerLimits[obj];
            }

            //Clean the hypercubes
            for (int i = 0; i < Hypercubes.Length; i++)
            {
                Hypercubes[i] = 0;
            }

            //Add the population
            AddSolutionSet(solutionSet);
        }
Exemplo n.º 10
0
        /**
           * Return the index of the nearest solution in the solution set to a given solution
           * @param solution
           * @param solutionSet
           * @return  The index of the nearest solution; -1 if the solutionSet is empty
           */
        public static int IndexToNearestSolutionInSolutionSpace(Solution solution, SolutionSet solutionSet)
        {
            int index = -1;
            double minimumDistance = double.MaxValue;
            for (int i = 0; i < solutionSet.Size(); i++)
            {
                double distance = DistanceBetweenSolutions(solution, solutionSet[i]);
                if (distance < minimumDistance)
                {
                    minimumDistance = distance;
                    index = i;
                }
            }

            return index;
        }
Exemplo n.º 11
0
        /**
         * Updates the grid limits and the grid content adding a new
         * <code>Solution</code>.
         * If the solution falls out of the grid bounds, the limits and content of the
         * grid must be re-calculated.
         * @param solution <code>Solution</code> considered to update the grid.
         * @param solutionSet <code>SolutionSet</code> used to update the grid.
         */
        public void updateGrid(Solution solution, SolutionSet solutionSet)
        {
            int location = Location(solution);
            if (location == -1)
            {
            //Re-build the Adaptative-Grid
                //Update lower and upper limits
                UpdateLimits(solutionSet);

                //Actualize the lower and upper limits whit the individual
                for (int obj = 0; obj < _objectives; obj++)
                {
                    double solutionObjective = solution.Objective[obj];

                    if (solutionObjective < _lowerLimits[obj])
                    {
                        _lowerLimits[obj] = solutionObjective;
                    }
                    if (solutionObjective > _upperLimits[obj])
                    {
                        _upperLimits[obj] = solutionObjective;
                    }
                }

                //Calculate the division Size
                for (int obj = 0; obj < _objectives; obj++)
                {
                    _divisionSize[obj] = _upperLimits[obj] - _lowerLimits[obj];
                }

                //Clean the hypercube
                for (int i = 0; i < Hypercubes.Length; i++)
                {
                    Hypercubes[i] = 0;
                }

                //add the population
                AddSolutionSet(solutionSet);
            }
        }
Exemplo n.º 12
0
        // NSGAII
        public override SolutionSet Execute()
        {
            int populationSize;
            int maxEvaluations;
            QualityIndicator indicators;

            Operator mutationOperator;
            Operator crossoverOperator;
            Operator selectionOperator;

            object parameter;
            if (InputParameters.TryGetValue("populationSize", out parameter))
            {
                populationSize = (int) parameter;
            }
            else
            {
                throw new Exception("populationSize does not exist");
            }

            if (InputParameters.TryGetValue("maxEvaluations", out parameter))
            {
                maxEvaluations = (int) parameter;
            }
            else
            {
                throw new Exception("maxEvaluations does not exist");
            }

            if (InputParameters.TryGetValue("indicators", out parameter))
            {
                indicators = (QualityIndicator) parameter;
            }
            else
            {
                throw new Exception("maxEvaluations does not exist");
            }

            // Initializing variables
            var population = new SolutionSet(populationSize);
            var evaluations = 0;

            int requiredEvaluations = 0;

            Operator unknownIOperator;
            //Read the operators
            if (UsedOperators.TryGetValue("mutation", out unknownIOperator))
            {
                mutationOperator = unknownIOperator;
            }
            else
            {
                throw new Exception("mutation does not exist");
            }
            if (UsedOperators.TryGetValue("crossover", out unknownIOperator))
            {
                crossoverOperator = unknownIOperator;
            }
            else
            {
                throw new Exception("crossover does not exist");
            }
            if (UsedOperators.TryGetValue("selection", out unknownIOperator))
            {
                selectionOperator = unknownIOperator;
            }
            else
            {
                throw new Exception("selection does not exist");
            }

            // Create the initial solutionSet
            for (int i = 0; i < populationSize; i++)
            {
                var newSolution = new Solution(Problema);
                Problema.Evaluate(newSolution);
                Problema.EvaluateConstraints(newSolution);
                evaluations++;
                population.Add(newSolution);
            } //for

            // Generations
            while (evaluations < maxEvaluations)
            {
                // Create the offSpring solutionSet
                var offspringPopulation = new SolutionSet(populationSize);
                Solution[] parents = new Solution[2];
                for (int i = 0; i < (populationSize/2); i++)
                {
                    if (evaluations < maxEvaluations)
                    {
                        //obtain parents
                        parents[0] = (Solution) selectionOperator.Execute(population);
                        parents[1] = (Solution) selectionOperator.Execute(population);
                        Solution[] offSpring = (Solution[]) crossoverOperator.Execute(parents);
                        mutationOperator.Execute(offSpring[0]);
                        mutationOperator.Execute(offSpring[1]);
                        Problema.Evaluate(offSpring[0]);
                        Problema.EvaluateConstraints(offSpring[0]);
                        Problema.Evaluate(offSpring[1]);
                        Problema.EvaluateConstraints(offSpring[1]);
                        offspringPopulation.Add(offSpring[0]);
                        offspringPopulation.Add(offSpring[1]);
                        evaluations += 2;
                    } // if
                } // for

                System.Console.WriteLine("evaluation #: " + evaluations);

                // Create the solutionSet union of solutionSet and offSpring
                SolutionSet union = population.Union(offspringPopulation);

                // Ranking the union
                Ranking localRanking = new Ranking(union);

                int remain = populationSize;
                int index = 0;
                SolutionSet front = null;
                population.Clear();

                // Obtain the next front
                front = localRanking.GetSubfront(index);

                while ((remain > 0) && (remain >= front.Size()))
                {
                    //Assign crowding distance to individuals
                    Distance.CrowdingDistanceAssignment(front, Problema.NumberOfObjectives);
                    //Add the individuals of this front
                    for (int k = 0; k < front.Size(); k++)
                    {
                        population.Add(front[k]);
                    } // for

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

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

                // Remain is less than front(index).size, insert only the best one
                if (remain > 0)
                {
                    // front contains individuals to insert
                    Distance.CrowdingDistanceAssignment(front, Problema.NumberOfObjectives);
                    front.Sort(new CrowdingComparator());
                    for (int k = 0; k < remain; k++)
                    {
                        population.Add(front[k]);
                    } // for

                    remain = 0;
                } // if

                // This piece of code shows how to use the indicator object into the code
                // of NSGA-II. In particular, it finds the number of evaluations required
                // by the algorithm to obtain a Pareto front with a hypervolume higher
                // than the hypervolume of the true Pareto front.
                if ((indicators != null) &&
                    (requiredEvaluations == 0))
                {
                    double hv = indicators.GetHypervolume(population);
                    if (hv >= (0.98*indicators.GetTrueParetoFrontHypervolume()))
                    {
                        requiredEvaluations = evaluations;
                    } // if
                } // if
            } // while

            // Return as output parameter the required evaluations
            OutputParameters["evaluations"] = requiredEvaluations;

            // Return the first non-dominated front
            Ranking ranking = new Ranking(population);
            ranking.GetSubfront(0).PrintFeasibleFUN("FUN_NSGAII");

            return ranking.GetSubfront(0);
        }
Exemplo n.º 13
0
        /** Returns the minimum distance from a <code>Solution</code> to a
           * <code>SolutionSet according to the encodings.variable values</code>.
           * @param solution The <code>Solution</code>.
           * @param solutionSet The <code>SolutionSet</code>.
           * @return The minimum distance between solution and the set.
           * @throws JMException
           */
        public static 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 = DistanceBetweenSolutions(solution, solutionSet[i]);
                if (aux < distance)
                {
                    distance = aux;
                }
            } // for

            //->Return the best distance
            return distance;
        }
Exemplo n.º 14
0
        private void NormalizePopulation(SolutionSet pop)
        {
            Solution z = new Solution(Problema);
            for (var i = 0; i < Problema.NumberOfObjectives; i++)
            {
                z.Objective[i] = double.NegativeInfinity;
            }

            foreach (var x in pop.SolutionList)
            {
                for (var i = 0; i < Problema.NumberOfObjectives; i++)
                {
                    if (x.Objective[i] > z.Objective[i])
                    {
                        z.Objective[i] = x.Objective[i];
                    }
                }
            }

            foreach (var x in pop.SolutionList)
            {
                for (var i = 0; i < Problema.NumberOfObjectives; i++)
                {
                    x.Objective[i] = (x.Objective[i] - IdealPoint.Objective[i])/
                                     (z.Objective[i] - IdealPoint.Objective[i]);
                }
            }
        }
Exemplo n.º 15
0
        public override SolutionSet Execute()
        {
            int populationSize;
            int maxEvaluations;
            QualityIndicator indicators;

            Operator mutationOperator;
            Operator crossoverOperator;
            Operator selectionOperator;

            object parameter;
            if (InputParameters.TryGetValue("populationSize", out parameter))
            {
                populationSize = (int) parameter;
            }
            else
            {
                throw new Exception("populationSize does not exist");
            }

            if (InputParameters.TryGetValue("maxEvaluations", out parameter))
            {
                maxEvaluations = (int) parameter;
            }
            else
            {
                throw new Exception("maxEvaluations does not exist");
            }

            if (InputParameters.TryGetValue("indicators", out parameter))
            {
                indicators = (QualityIndicator) parameter;
            }
            else
            {
                throw new Exception("maxEvaluations does not exist");
            }

            if (InputParameters.TryGetValue("theta", out parameter))
            {
                Theta = (int) parameter;
            }
            else
            {
                throw new Exception("Theta does not exist");
            }

            if (InputParameters.TryGetValue("H", out parameter))
            {
                K = MetalMath.BinomialCoeff(Problema.NumberOfObjectives - 1,
                                            ((int) parameter) + Problema.NumberOfObjectives - 1);
            }
            else
            {
                throw new Exception("H does not exist");
            }

            // Initializing variables
            var population = new SolutionSet(populationSize);
            var evaluations = 0;

            int requiredEvaluations = 0;

            Operator unknownIOperator;
            //Read the operators
            if (UsedOperators.TryGetValue("mutation", out unknownIOperator))
            {
                mutationOperator = unknownIOperator;
            }
            else
            {
                throw new Exception("mutation does not exist");
            }
            if (UsedOperators.TryGetValue("crossover", out unknownIOperator))
            {
                crossoverOperator = unknownIOperator;
            }
            else
            {
                throw new Exception("crossover does not exist");
            }
            if (UsedOperators.TryGetValue("selection", out unknownIOperator))
            {
                selectionOperator = unknownIOperator;
            }
            else
            {
                throw new Exception("selection does not exist");
            }

            K = populationSize;
            ReferencePoints = new Solution[K];

            //Create references points
            GenerateReferencePoint();

            // Create the initial solutionSet
            for (int i = 0; i < populationSize; i++)
            {
                var newSolution = new Solution(Problema);
                Problema.Evaluate(newSolution);
                Problema.EvaluateConstraints(newSolution);
                evaluations++;
                population.Add(newSolution);
            }

            IdealPoint = new Solution(Problema);
            for (var i = 0; i < Problema.NumberOfObjectives; i++)
            {
                IdealPoint.Objective[i] = double.PositiveInfinity;
            }

            ComputeIdealPoint(population);

            ThetaNonDominatedSort ranking = null;

            // Generations
            SolutionSet union = null;

            while (evaluations < maxEvaluations)
            {
                // Create the offSpring solutionSet
                var offspringPopulation = new SolutionSet(populationSize);
                Solution[] parents = new Solution[2];

                for (int i = 0; i < (populationSize/2); i++)
                {
                    if (evaluations < maxEvaluations)
                    {
                        //obtain parents
                        parents[0] = (Solution) selectionOperator.Execute(population);
                        parents[1] = (Solution) selectionOperator.Execute(population);
                        Solution[] offSpring = (Solution[]) crossoverOperator.Execute(parents);
                        mutationOperator.Execute(offSpring[0]);
                        mutationOperator.Execute(offSpring[1]);
                        Problema.Evaluate(offSpring[0]);
                        Problema.EvaluateConstraints(offSpring[0]);
                        Problema.Evaluate(offSpring[1]);
                        Problema.EvaluateConstraints(offSpring[1]);
                        offspringPopulation.Add(offSpring[0]);
                        offspringPopulation.Add(offSpring[1]);
                        evaluations += 2;
                    }
                }

                //Update ideal point

                // Create the solutionSet union of solutionSet and offSpring
                union = population.Union(offspringPopulation);
                ComputeIdealPoint(offspringPopulation);

                //Normalize
                NormalizePopulation(union);

                //Clustering and non dominated sort
                ranking = new ThetaNonDominatedSort(union, Clustering(union), Theta);

                //Generate next pop
                population = new SolutionSet(populationSize);
                int front = 0;
                while (population.Size() + ranking.GetSubfront(front).Size() <= populationSize)
                {
                    var frontResult = ranking.GetSubfront(front);
                    foreach (var r in frontResult.SolutionList)
                    {
                        population.Add(r);
                    }
                    front++;
                }

                //Generate new pop
                var localList =
                    ranking.GetSubfront(front).SolutionList.OrderBy(item => PseudoRandom.Instance().Next()).ToList();
                int localSizePt1 = population.Size();
                for (int i = 0; i < populationSize - localSizePt1; i++)
                {
                    population.Add(localList[i]);
                }

                if ((indicators != null) && (requiredEvaluations == 0))
                {
                    /*
                    double hv = indicators.GetHypervolume(population);
                    if (hv >= (0.98 * indicators.GetTrueParetoFrontHypervolume()))
                    {
                        requiredEvaluations = evaluations;
                    }*/

                    double gd = indicators.GetGd(ranking.GetSubfront(0));
                    Console.WriteLine(gd);
                }
            }

            OutputParameters["evaluations"] = requiredEvaluations;
            ranking.GetSubfront(0).PrintFeasibleFUN("FUN_THETA_NSGAIII");
            Console.WriteLine("before quitting");
            Console.WriteLine(indicators.GetGd(ranking.GetSubfront(0)));
            Console.WriteLine("before quitting");
            return ranking.GetSubfront(0);
        }
Exemplo n.º 16
0
        private List<Cluster> Clustering(SolutionSet normalizedPop)
        {
            List<Cluster> clusters = new List<Cluster>(K);

            for (var c = 0; c < K; c++)
            {
                clusters.Add(new Cluster(ReferencePoints[c], normalizedPop.Size()));
            }

            for (var x = 0; x < normalizedPop.Size(); x++)
            {
                var k = 0;
                var min = Distance(normalizedPop.SolutionList[x], ReferencePoints[k]);
                for (var j = 1; j < K; j++)
                {
                    var d2 = Distance(normalizedPop.SolutionList[x], ReferencePoints[j]);
                    if (d2.Item2 < min.Item2)
                    {
                        min = d2;
                        k = j;
                    }
                }
                clusters[k].Add(normalizedPop.SolutionList[x], min);
            }

            return clusters;
        }
Exemplo n.º 17
0
 /**
  * Returns the spread of solution set
  * @param solutionSet Solution set
  * @return The value of the hypervolume indicator
  */
 public double GetSpread(SolutionSet solutionSet)
 {
     return new Spread().Compute(solutionSet.WriteObjectivesToMatrix(),
                                 _trueParetoFront.WriteObjectivesToMatrix(),
                                 _problem.NumberOfObjectives);
 }
Exemplo n.º 18
0
        /**
         * Updates the grid adding solutions contained in a specific
         * <code>SolutionSet</code>.
         * <b>REQUIRE</b> The grid limits must have been previously calculated.
         * @param solutionSet The <code>SolutionSet</code> considered.
         */
        private void AddSolutionSet(SolutionSet solutionSet)
        {
            //Calculate the location of all individuals and update the grid
            MostPopulated = 0;

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

            //The grid has been updated, so also update ocuppied's hypercubes
            CalculateOccupied();
        }
Exemplo n.º 19
0
 /**
  * Returns the hypervolume of solution set
  * @param solutionSet Solution set
  * @return The value of the hypervolume indicator
  */
 public double GetHypervolume(SolutionSet solutionSet)
 {
     return new Hypervolume().HypervolumeValue(solutionSet.WriteObjectivesToMatrix(),
                                               _trueParetoFront.WriteObjectivesToMatrix(),
                                               _problem.NumberOfObjectives);
 }
Exemplo n.º 20
0
        /**
        *  Updates the grid limits considering the solutions contained in a
        *  <code>SolutionSet</code>.
        *  @param solutionSet The <code>SolutionSet</code> considered.
        */
        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[ind];
                for (int obj = 0; obj < _objectives; obj++)
                {
                    double tmpIndividualObjective = tmpIndividual.Objective[obj];
                    if (tmpIndividualObjective < _lowerLimits[obj])
                    {
                        _lowerLimits[obj] = tmpIndividualObjective;
                    }
                    if (tmpIndividualObjective > _upperLimits[obj])
                    {
                        _upperLimits[obj] = tmpIndividualObjective;
                    }
                }
            }
        }
Exemplo n.º 21
0
        private void ComputeIdealPoint(SolutionSet pop)
        {
            if (pop.Size() <= 0)
            {
                throw new Exception("Empty pop");
            }

            pop.SolutionList.ForEach(sol =>
                                     {
                                         for (var i = 0; i < sol.NumberOfObjectives; i++)
                                         {
                                             if (sol.Objective[i] < IdealPoint.Objective[i])
                                             {
                                                 IdealPoint.Objective[i] = sol.Objective[i];
                                             }
                                         }
                                     });
        }
Exemplo n.º 22
0
 public Cluster(Solution referencePoint, int populationSize)
 {
     Solutions = new SolutionSet(populationSize);
     Distances = new List<Tuple<double, double>>();
     ReferencePoint = referencePoint.Clone();
 }
Exemplo n.º 23
0
        private void printObjectives(string filename, SolutionSet pop)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            TextWriter tw = new StreamWriter(filename);

            pop.SolutionList.ForEach(sol => { tw.WriteLine(string.Join(",", sol.Objective)); });
            tw.Close();
        }
Exemplo n.º 24
0
        /**
           * Returns a matrix with distances between solutions in a
           * <code>SolutionSet</code>.
           * @param solutionSet The <code>SolutionSet</code>.
           * @return a matrix with distances.
           */
        public static double[][] DistanceMatrix(SolutionSet solutionSet)
        {
            //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;
                Solution solutionI = solutionSet[i];
                for (int j = i + 1; j < solutionSet.Size(); j++)
                {
                    Solution solutionJ = solutionSet[j];
                    distance[i][j] = DistanceBetweenObjectives(solutionI, solutionJ);
                    distance[j][i] = distance[i][j];
                } // for
            } // for

            //->Return the matrix of distances
            return distance;
        }
Exemplo n.º 25
0
        public ThetaNonDominatedSort(SolutionSet population, List<Cluster> clusters, double theta)
        {
            Dominance = new ThetaComparator(theta);
            _solutionSet = population;
            _ranking = new List<SolutionSet>();
            // dominateMe[i] contains the number of solutions dominating i
            int[] dominateMe = new int[_solutionSet.Size()];

            // iDominate[k] contains the list of solutions dominated by k
            List<int>[] iDominate = new List<int>[_solutionSet.Size()];

            // front[i] contains the list of individuals belonging to the front i
            List<int>[] front = new List<int>[_solutionSet.Size() + 1];

            // flagDominate is an auxiliar encodings.variable
            int flagDominate;

            for (int p = 0; p < (clusters.Count - 1); p++)
            {
                // Initialize the fronts
                for (int k = 0; k < front.Length; k++)
                {
                    front[k] = new List<int>();
                }
                for (int q = 0; q < clusters[p].Count; q++)
                {
                    // Initialize the list of individuals that i dominate and the number
                    // of individuals that dominate me
                    iDominate[q] = new List<int>();
                    dominateMe[q] = 0;
                }

                for (int q = 0; q < (clusters[p].Count - 1); q++)
                {
                    for (int r = q + 1; r < (clusters[p].Count - 1); r++)
                    {
                        flagDominate = Dominance.Compare(clusters[p][q].Item2, clusters[p][r].Item2);
                        //flagDominate = Constraint.Compare(clusters[p][q].Item1, clusters[p][r].Item1);
                        if (flagDominate == 0)
                        {
                            flagDominate = Dominance.Compare(clusters[p][q].Item2, clusters[p][r].Item2);
                        }
                        if (flagDominate == -1)
                        {
                            iDominate[q].Add(r);
                            dominateMe[r]++;
                        }
                        else if (flagDominate == 1)
                        {
                            iDominate[r].Add(q);
                            dominateMe[q]++;
                        }
                    }
                }

                //Fill front
                if (_ranking.Count == 0)
                {
                    _ranking.Add(new SolutionSet(population.Size()));
                }
                for (int q = 0; q < clusters[p].Count; q++)
                {
                    if (dominateMe[q] == 0)
                    {
                        front[0].Add(q);
                        _ranking[0].Add(clusters[p][q].Item1);
                        clusters[p][q].Item1.Rank = 0;
                    }
                }

                //Obtain the rest of fronts
                int i = 0;
                IEnumerator<int> it1; // Iterators
                while (front[i].Count != 0)
                {
                    i++;
                    if (i >= _ranking.Count)
                    {
                        _ranking.Add(new SolutionSet(population.Size()));
                    }
                    it1 = front[i - 1].GetEnumerator();
                    while (it1.MoveNext())
                    {
                        IEnumerator<int> it2 = iDominate[it1.Current].GetEnumerator(); // Iterators
                        while (it2.MoveNext())
                        {
                            int index = it2.Current;
                            dominateMe[index]--;
                            if (dominateMe[index] == 0)
                            {
                                front[i].Add(index);
                                _ranking[i].Add(clusters[p][index].Item1);
                                clusters[p][index].Item1.Rank = i;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        ///     Joins two solution sets: the current one and the one passed as argument
        /// </summary>
        /// <param name="solutionSet">
        ///     A <see cref="SolutionSet" />
        /// </param>
        /// <returns>
        ///     A new solution set
        ///     A <see cref="SolutionSet" />
        /// </returns>
        public SolutionSet Union(SolutionSet solutionSet)
        {
            if (solutionSet == null)
            {
                throw new ArgumentNullException("solutionSet");
            }
            //Check the correct size
            int newSize = Size() + solutionSet.Size();
            if (newSize < Capacity)
            {
                newSize = Capacity;
            }

            //Create a new population
            var union = new SolutionSet(newSize);
            foreach (Solution solution in SolutionList)
            {
                union.Add(solution);
            }

            for (int i = Size(); i < (Size() + solutionSet.Size()); i++)
            {
                union.Add(solutionSet.SolutionList[i - Size()]);
            }

            return union;
        }