/// <summary> /// Runs of the aMOCell2 algorithm. /// </summary> /// <returns>a <code>SolutionSet</code> that is a set of non dominated solutions /// as a result of the algorithm execution</returns> public override SolutionSet Execute() { //Init the param int populationSize = -1, archiveSize = -1, maxEvaluations = -1, evaluations = -1; Operator mutationOperator, crossoverOperator, selectionOperator; SolutionSet currentSolutionSet; CrowdingArchive archive; SolutionSet[] neighbors; Neighborhood neighborhood; IComparer <Solution> dominance = new DominanceComparator(), crowding = new CrowdingComparator(); Distance distance = new Distance(); //Read the params JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "populationSize", ref populationSize); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "archiveSize", ref archiveSize); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "maxEvaluations", ref maxEvaluations); //Read the operators mutationOperator = Operators["mutation"]; crossoverOperator = Operators["crossover"]; selectionOperator = Operators["selection"]; //Initialize the variables currentSolutionSet = new SolutionSet(populationSize); archive = new CrowdingArchive(archiveSize, this.Problem.NumberOfObjectives); evaluations = 0; neighborhood = new Neighborhood(populationSize); neighbors = new SolutionSet[populationSize]; //Create the initial population for (int i = 0; i < populationSize; i++) { Solution solution = new Solution(this.Problem); this.Problem.Evaluate(solution); this.Problem.EvaluateConstraints(solution); currentSolutionSet.Add(solution); solution.Location = i; evaluations++; } while (evaluations < maxEvaluations) { for (int ind = 0; ind < currentSolutionSet.Size(); ind++) { Solution individual = new Solution(currentSolutionSet.Get(ind)); Solution[] parents = new Solution[2]; Solution[] offSpring; neighbors[ind] = neighborhood.GetEightNeighbors(currentSolutionSet, ind); neighbors[ind].Add(individual); //parents parents[0] = (Solution)selectionOperator.Execute(neighbors[ind]); if (archive.Size() > 0) { parents[1] = (Solution)selectionOperator.Execute(archive); } else { parents[1] = (Solution)selectionOperator.Execute(neighbors[ind]); } //Create a new solution, using genetic operators mutation and crossover offSpring = (Solution[])crossoverOperator.Execute(parents); mutationOperator.Execute(offSpring[0]); //->Evaluate solution and constraints this.Problem.Evaluate(offSpring[0]); this.Problem.EvaluateConstraints(offSpring[0]); evaluations++; int flag = dominance.Compare(individual, offSpring[0]); if (flag == 1) { // OffSpring[0] dominates offSpring[0].Location = individual.Location; currentSolutionSet.Replace(offSpring[0].Location, offSpring[0]); archive.Add(new Solution(offSpring[0])); } else if (flag == 0) { //Both two are non-dominated neighbors[ind].Add(offSpring[0]); Ranking rank = new Ranking(neighbors[ind]); for (int j = 0; j < rank.GetNumberOfSubfronts(); j++) { distance.CrowdingDistanceAssignment(rank.GetSubfront(j), this.Problem.NumberOfObjectives); } bool deleteMutant = true; int compareResult = crowding.Compare(individual, offSpring[0]); if (compareResult == 1) { //The offSpring[0] is better deleteMutant = false; } if (!deleteMutant) { offSpring[0].Location = individual.Location; currentSolutionSet.Replace(offSpring[0].Location, offSpring[0]); archive.Add(new Solution(offSpring[0])); } else { archive.Add(new Solution(offSpring[0])); } } } } Result = archive; return(archive); }
/// <summary> /// Runs of the Paes algorithm. /// </summary> /// <returns>a <code>SolutionSet</code> that is a set of non dominated solutions /// as a result of the algorithm execution </returns> public override SolutionSet Execute() { int bisections = -1, archiveSize = -1, maxEvaluations = -1, evaluations; AdaptiveGridArchive archive; Operator mutationOperator; IComparer <Solution> dominance; //Read the params JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "biSections", ref bisections); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "archiveSize", ref archiveSize); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "maxEvaluations", ref maxEvaluations); //Read the operators mutationOperator = this.Operators["mutation"]; //Initialize the variables evaluations = 0; archive = new AdaptiveGridArchive(archiveSize, bisections, this.Problem.NumberOfObjectives); dominance = new DominanceComparator(); //-> Create the initial solution and evaluate it and his constraints Solution solution = new Solution(this.Problem); this.Problem.Evaluate(solution); this.Problem.EvaluateConstraints(solution); evaluations++; // Add it to the archive archive.Add(new Solution(solution)); //Iterations.... do { // Create the mutate one Solution mutatedIndividual = new Solution(solution); mutationOperator.Execute(mutatedIndividual); this.Problem.Evaluate(mutatedIndividual); this.Problem.EvaluateConstraints(mutatedIndividual); evaluations++; // Check dominance int flag = dominance.Compare(solution, mutatedIndividual); if (flag == 1) { //If mutate solution dominate solution = new Solution(mutatedIndividual); archive.Add(mutatedIndividual); } else if (flag == 0) { //If none dominate the other if (archive.Add(mutatedIndividual)) { solution = Test(solution, mutatedIndividual, archive); } } } while (evaluations < maxEvaluations); Result = archive; return(archive); }
/// <summary> /// Execute the algorithm /// </summary> /// <returns></returns> public override SolutionSet Execute() { int populationSize = -1, archiveSize = -1, maxEvaluations = -1, evaluations = -1, feedBack = -1; Operator mutationOperator, crossoverOperator, selectionOperator; SolutionSet currentPopulation; CrowdingArchive archive; SolutionSet[] neighbors; Neighborhood neighborhood; IComparer <Solution> dominance = new DominanceComparator(); IComparer <Solution> crowdingComparator = new CrowdingComparator(); Distance distance = new Distance(); //Read the parameters JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "populationSize", ref populationSize); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "archiveSize", ref archiveSize); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "maxEvaluations", ref maxEvaluations); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "feedBack", ref feedBack); //Read the operators mutationOperator = Operators["mutation"]; crossoverOperator = Operators["crossover"]; selectionOperator = Operators["selection"]; //Initialize the variables //Initialize the population and the archive currentPopulation = new SolutionSet(populationSize); archive = new CrowdingArchive(archiveSize, this.Problem.NumberOfObjectives); evaluations = 0; neighborhood = new Neighborhood(populationSize); neighbors = new SolutionSet[populationSize]; //Create the comparator for check dominance dominance = new DominanceComparator(); //Create the initial population for (int i = 0; i < populationSize; i++) { Solution individual = new Solution(this.Problem); this.Problem.Evaluate(individual); this.Problem.EvaluateConstraints(individual); currentPopulation.Add(individual); individual.Location = i; evaluations++; } while (evaluations < maxEvaluations) { for (int ind = 0; ind < currentPopulation.Size(); ind++) { Solution individual = new Solution(currentPopulation.Get(ind)); Solution[] parents = new Solution[2]; Solution[] offSpring; neighbors[ind] = neighborhood.GetEightNeighbors(currentPopulation, ind); neighbors[ind].Add(individual); //parents parents[0] = (Solution)selectionOperator.Execute(neighbors[ind]); parents[1] = (Solution)selectionOperator.Execute(neighbors[ind]); //Create a new individual, using genetic operators mutation and crossover offSpring = (Solution[])crossoverOperator.Execute(parents); mutationOperator.Execute(offSpring[0]); //->Evaluate individual an his constraints this.Problem.Evaluate(offSpring[0]); this.Problem.EvaluateConstraints(offSpring[0]); evaluations++; //<-Individual evaluated int flag = dominance.Compare(individual, offSpring[0]); if (flag == 1) { //The new individuals dominate offSpring[0].Location = individual.Location; currentPopulation.Replace(offSpring[0].Location, offSpring[0]); archive.Add(new Solution(offSpring[0])); } else if (flag == 0) { //The individuals are non-dominates neighbors[ind].Add(offSpring[0]); offSpring[0].Location = -1; Ranking rank = new Ranking(neighbors[ind]); for (int j = 0; j < rank.GetNumberOfSubfronts(); j++) { distance.CrowdingDistanceAssignment(rank.GetSubfront(j), this.Problem.NumberOfObjectives); } Solution worst = neighbors[ind].Worst(crowdingComparator); if (worst.Location == -1) { //The worst is the offspring archive.Add(new Solution(offSpring[0])); } else { offSpring[0].Location = worst.Location; currentPopulation.Replace(offSpring[0].Location, offSpring[0]); archive.Add(new Solution(offSpring[0])); } } } //Store a portion of the archive into the population distance.CrowdingDistanceAssignment(archive, this.Problem.NumberOfObjectives); for (int j = 0; j < feedBack; j++) { if (archive.Size() > j) { int r = JMetalRandom.Next(0, currentPopulation.Size() - 1); if (r < currentPopulation.Size()) { Solution individual = archive.Get(j); individual.Location = r; currentPopulation.Replace(r, new Solution(individual)); } } } } Result = archive; return(archive); }
/** * Runs of the GDE3 algorithm. * @return a <code>SolutionSet</code> that is a set of non dominated solutions * as a result of the algorithm execution * @throws JMException */ public override SolutionSet Execute() { int populationSize = -1; int maxIterations = -1; int evaluations; int iterations; SolutionSet population; SolutionSet offspringPopulation; Distance distance; IComparer <Solution> dominance; Operator selectionOperator; Operator crossoverOperator; distance = new Distance(); dominance = new DominanceComparator(); Solution[] parent; //Read the parameters JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "populationSize", ref populationSize); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "maxIterations", ref maxIterations); selectionOperator = this.Operators["selection"]; crossoverOperator = this.Operators["crossover"]; //Initialize the variables population = new SolutionSet(populationSize); evaluations = 0; iterations = 0; // Create the initial solutionSet Solution newSolution; for (int i = 0; i < populationSize; i++) { newSolution = new Solution(this.Problem); this.Problem.Evaluate(newSolution); this.Problem.EvaluateConstraints(newSolution); evaluations++; population.Add(newSolution); } // Generations ... while (iterations < maxIterations) { // Create the offSpring solutionSet offspringPopulation = new SolutionSet(populationSize * 2); for (int i = 0; i < populationSize; i++) { // Obtain parents. Two parameters are required: the population and the // index of the current individual parent = (Solution[])selectionOperator.Execute(new object[] { population, i }); Solution child; // Crossover. Two parameters are required: the current individual and the // array of parents child = (Solution)crossoverOperator.Execute(new object[] { population.Get(i), parent }); this.Problem.Evaluate(child); this.Problem.EvaluateConstraints(child); evaluations++; // Dominance test int result; result = dominance.Compare(population.Get(i), child); if (result == -1) { // Solution i dominates child offspringPopulation.Add(population.Get(i)); } else if (result == 1) { // child dominates offspringPopulation.Add(child); } else { // the two solutions are non-dominated offspringPopulation.Add(child); offspringPopulation.Add(population.Get(i)); } } // Ranking the offspring population Ranking ranking = new Ranking(offspringPopulation); 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())) { //Assign crowding distance to individuals distance.CrowdingDistanceAssignment(front, this.Problem.NumberOfObjectives); //Add the individuals of this front for (int k = 0; k < front.Size(); k++) { population.Add(front.Get(k)); } // for //Decrement remain 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 contains individuals to insert while (front.Size() > remain) { distance.CrowdingDistanceAssignment(front, this.Problem.NumberOfObjectives); front.Remove(front.IndexWorst(new CrowdingComparator())); } for (int k = 0; k < front.Size(); k++) { population.Add(front.Get(k)); } remain = 0; } iterations++; } // Return the first non-dominated front Ranking rnk = new Ranking(population); this.Result = rnk.GetSubfront(0); return(this.Result); }