Changeset 17382 for branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid
- Timestamp:
- 12/18/19 16:11:21 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs
r17363 r17382 95 95 } 96 96 97 public doubleEvaluate(BinaryVector vector, IRandom random) {97 public ISingleObjectiveEvaluationResult Evaluate(BinaryVector vector, IRandom random) { 98 98 return Evaluate(vector, random, CancellationToken.None); 99 99 } 100 100 101 public doubleEvaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) {101 public ISingleObjectiveEvaluationResult Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) { 102 102 if (Evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached"); 103 103 Evaluations++; 104 double fitness = problem.Evaluate(vector, random); 104 105 var evaluationResult = problem.Evaluate(vector, random); 106 double fitness = evaluationResult.Quality; 105 107 if (double.IsNaN(BestQuality) || problem.IsBetter(fitness, BestQuality)) { 106 108 BestQuality = fitness; … … 108 110 BestFoundOnEvaluation = Evaluations; 109 111 } 110 return fitness;112 return evaluationResult; 111 113 } 112 114 … … 115 117 } 116 118 public void Evaluate(ISingleObjectiveSolutionContext<BinaryVector> solutionContext, IRandom random, CancellationToken cancellationToken) { 117 double quality= Evaluate(solutionContext.EncodedSolution, random, cancellationToken);118 solutionContext.EvaluationResult = new SingleObjectiveEvaluationResult(quality);119 var evaluationResult = Evaluate(solutionContext.EncodedSolution, random, cancellationToken); 120 solutionContext.EvaluationResult = evaluationResult; 119 121 } 120 122 -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r17226 r17382 25 25 using System.Linq; 26 26 using System.Threading; 27 using HEAL.Attic; 27 28 using HeuristicLab.Common; 28 29 using HeuristicLab.Core; … … 31 32 using HeuristicLab.Optimization; 32 33 using HeuristicLab.Parameters; 33 using HEAL.Attic;34 34 using HeuristicLab.Random; 35 35 … … 110 110 } 111 111 112 var fitness = Problem.Evaluate(solution, random); 112 var evaluationResult = Problem.Evaluate(solution, random); 113 var fitness = evaluationResult.Quality; 113 114 114 115 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); … … 128 129 if (tried.Contains(option)) continue; 129 130 solution[option] = !solution[option]; 130 double newFitness = problem.Evaluate(solution, rand); 131 var newEvaluationResult = problem.Evaluate(solution, rand); 132 double newFitness = newEvaluationResult.Quality; 131 133 if (problem.IsBetter(newFitness, fitness)) { 132 134 fitness = newFitness; -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageCrossover.cs
r17226 r17382 59 59 changed = flipped.Count > 0; 60 60 if (changed) { 61 double newFitness = problem.Evaluate(solution, rand) ;61 double newFitness = problem.Evaluate(solution, rand).Quality; 62 62 // if the original is strictly better, revert the change 63 63 if (problem.IsBetter(fitness, newFitness)) { -
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r17226 r17382 214 214 solution[i] = random.Next(2) == 1; 215 215 } 216 double fitness = tracker.Evaluate(solution, random) ;216 double fitness = tracker.Evaluate(solution, random).Quality; 217 217 fitness = HillClimber.ImproveToLocalOptimum(tracker, solution, fitness, random); 218 218 AddIfUnique(solution, 0); … … 271 271 ResultsIterations++; 272 272 cancellationToken.ThrowIfCancellationRequested(); 273 } 274 finally { 273 } finally { 275 274 ResultsEvaluations = tracker.Evaluations; 276 275 ResultsBestSolution = new BinaryVector(tracker.BestSolution);
Note: See TracChangeset
for help on using the changeset viewer.