/// <summary> /// Constructor. /// </summary> /// <param name="problem">Problem to solve</param> public AbYSS(Problem problem) : base(problem) { //Initialize the fields this.solutionSet = null; this.archive = null; this.refSet1 = null; this.refSet2 = null; this.subSet = null; }
/// <summary> /// Reads the parameter from the parameter list using the /// <code>getInputParameter</code> method. /// </summary> public void InitParam() { //Read the parameters JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "populationSize", ref solutionSetSize); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "refSet1Size", ref refSet1Size); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "refSet2Size", ref refSet2Size); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "archiveSize", ref archiveSize); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "maxEvaluations", ref maxEvaluations); //Initialize the variables solutionSet = new SolutionSet(solutionSetSize); archive = new CrowdingArchive(archiveSize, this.Problem.NumberOfObjectives); refSet1 = new SolutionSet(refSet1Size); refSet2 = new SolutionSet(refSet2Size); subSet = new SolutionSet(solutionSetSize * 1000); evaluations = 0; numberOfSubranges = 4; dominance = new DominanceComparator(); equal = new EqualSolutions(); fitness = new FitnessComparator(); crowdingDistance = new CrowdingDistanceComparator(); distance = new Distance(); sumOfFrequencyValues = new int[this.Problem.NumberOfVariables]; sumOfReverseFrequencyValues = new int[this.Problem.NumberOfVariables]; frequency = new int[numberOfSubranges][]; reverseFrequency = new int[numberOfSubranges][]; for (int i = 0; i < numberOfSubranges; i++) { frequency[i] = new int[this.Problem.NumberOfVariables]; reverseFrequency[i] = new int[this.Problem.NumberOfVariables]; } // Read the operators of crossover and improvement crossoverOperator = this.Operators["crossover"]; improvementOperator = (LocalSearch)this.Operators["improvement"]; improvementOperator.SetParameter("archive", archive); }
/// <summary> /// Initialize all parameter of the algorithm /// </summary> public void InitParams() { JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "swarmSize", ref swarmSize); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "archiveSize", ref archiveSize); JMetalCSharp.Utils.Utils.GetIntValueFromParameter(this.InputParameters, "maxIterations", ref maxIterations); JMetalCSharp.Utils.Utils.GetIndicatorsFromParameters(this.InputParameters, "indicators", ref indicators); polynomialMutation = this.Operators["mutation"]; parallelEvaluator.StartParallelRunner(this.Problem);; iteration = 1; particles = new SolutionSet(swarmSize); best = new Solution[swarmSize]; Leaders = new CrowdingArchive(archiveSize, this.Problem.NumberOfObjectives); // Create comparators for dominance and crowding distance dominance = new DominanceComparator(); crowdingDistanceComparator = new CrowdingDistanceComparator(); distance = new Distance(); // Create the speed_ vector speed = new double[swarmSize][]; for (var i = 0; i < swarmSize; i++) { speed[i] = new double[this.Problem.NumberOfVariables]; } deltaMax = new double[this.Problem.NumberOfVariables]; deltaMin = new double[this.Problem.NumberOfVariables]; for (int i = 0; i < this.Problem.NumberOfVariables; i++) { deltaMax[i] = (this.Problem.UpperLimit[i] - this.Problem.LowerLimit[i]) / 2.0; deltaMin[i] = -deltaMax[i]; } }
/// <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> /// 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); }