/// <summary> /// Performs the operation /// </summary> /// <param name="obj">Object representing a SolutionSet. This solution set must be an instancen <code>AdaptiveGridArchive</code></param> /// <returns>the selected solution</returns> public override object Execute(object obj) { try { AdaptiveGridArchive archive = (AdaptiveGridArchive)obj; int selected; int hypercube1 = archive.Grid.RandomOccupiedHypercube(); int hypercube2 = archive.Grid.RandomOccupiedHypercube(); if (hypercube1 != hypercube2) { if (archive.Grid.GetLocationDensity(hypercube1) < archive.Grid.GetLocationDensity(hypercube2)) { selected = hypercube1; } else if (archive.Grid.GetLocationDensity(hypercube2) < archive.Grid.GetLocationDensity(hypercube1)) { selected = hypercube2; } else { if (JMetalRandom.NextDouble() < 0.5) { selected = hypercube2; } else { selected = hypercube1; } } } else { selected = hypercube1; } int bas = JMetalRandom.Next(0, archive.Size() - 1); int cnt = 0; while (cnt < archive.Size()) { Solution individual = archive.Get((bas + cnt) % archive.Size()); if (archive.Grid.Location(individual) != selected) { cnt++; } else { return(individual); } } return(archive.Get((bas + cnt) % archive.Size())); } catch (InvalidCastException ex) { Logger.Log.Error("Exception in " + this.GetType().FullName + ".Execute()", ex); throw new Exception("Exception in " + this.GetType().FullName + ".Execute()"); } }
/// <summary> /// Tests two solutions to determine which one becomes be the guide of PAES algorithm /// </summary> /// <param name="solution"> The actual guide of PAES</param> /// <param name="mutatedSolution">A candidate guide</param> /// <param name="archive"></param> /// <returns></returns> private Solution Test(Solution solution, Solution mutatedSolution, AdaptiveGridArchive archive) { int originalLocation = archive.Grid.Location(solution); int mutatedLocation = archive.Grid.Location(mutatedSolution); if (originalLocation == -1) { return(new Solution(mutatedSolution)); } if (mutatedLocation == -1) { return(new Solution(solution)); } if (archive.Grid.GetLocationDensity(mutatedLocation) < archive.Grid.GetLocationDensity(originalLocation)) { return(new Solution(mutatedSolution)); } return(new Solution(solution)); }
/// <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); }