Changeset 17382
- Timestamp:
- 12/18/19 16:11:21 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessCovarianceOptimizationProblem.cs
r17320 r17382 198 198 private readonly object syncRoot = new object(); 199 199 // Does not produce the same result for the same seed when using parallel engine (see below)! 200 public override doubleEvaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {200 public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 201 201 var meanFunction = new MeanConst(); 202 202 var problemData = ProblemData; … … 260 260 UpdateBestSoFar(bestObjValue[0], bestHyperParameters, meanFunction, covarianceFunction); 261 261 262 return bestObjValue[0]; 262 var quality = bestObjValue[0]; 263 return new SingleObjectiveEvaluationResult(quality); 263 264 } 264 265 -
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); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IEvaluationResult.cs
r17357 r17382 26 26 [StorableType("406EB24F-A59C-440C-8B83-49FC05F48855")] 27 27 public interface IEvaluationResult : IItem { 28 29 //TODO: make methods generic for get/set additional data 28 30 void SetAdditionalData(string identifier, object o); 29 31 object GetAdditionalData(string identifier); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveProblemDefinition.cs
r17363 r17382 37 37 where TEncodedSolution : class, IEncodedSolution { 38 38 39 double Evaluate(TEncodedSolution solution, IRandom random); 40 double Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 39 ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random); 40 ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 41 41 42 void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random); 42 43 void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISolutionContext.cs
r17363 r17382 33 33 IEvaluationResult EvaluationResult { get; } 34 34 35 36 //TODO: make methods generic for get/set additional data 35 37 void SetAdditionalData(string identifier, object o); 36 38 object GetAdditionalData(string identifier); -
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs
r17366 r17382 113 113 } 114 114 115 public doubleEvaluate(TEncodedSolution solution, IRandom random) {115 public ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random) { 116 116 return Evaluate(solution, random, CancellationToken.None); 117 117 } 118 public abstract doubleEvaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);118 public abstract ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 119 119 120 120 public void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) { … … 122 122 } 123 123 public virtual void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken) { 124 double quality= Evaluate(solutionContext.EncodedSolution, random, cancellationToken);125 solutionContext.EvaluationResult = new SingleObjectiveEvaluationResult(quality);124 var evaluationResult = Evaluate(solutionContext.EncodedSolution, random, cancellationToken); 125 solutionContext.EvaluationResult = evaluationResult; 126 126 } 127 127 … … 139 139 return GetNeighbors(solutionContext.EncodedSolution, random).Select(n => new SingleObjectiveSolutionContext<TEncodedSolution>(n)); 140 140 } 141 142 143 141 144 142 public static bool IsBetter(bool maximization, double quality, double bestQuality) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveTrapProblem.cs
r17320 r17382 29 29 using HeuristicLab.Data; 30 30 using HeuristicLab.Encodings.BinaryVectorEncoding; 31 using HeuristicLab.Optimization; 31 32 using HeuristicLab.Parameters; 32 33 … … 81 82 } 82 83 83 public override doubleEvaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) {84 public override ISingleObjectiveEvaluationResult Evaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) { 84 85 if (individual.Length != Length) throw new ArgumentException("The individual has not the correct length."); 85 86 int total = 0; … … 88 89 total += Score(individual, i, trapSize); 89 90 } 90 return (double)(total * trapSize) / (TrapMaximum * individual.Length); 91 var quality = (double)(total * trapSize) / (TrapMaximum * individual.Length); 92 return new SingleObjectiveEvaluationResult(quality); 91 93 } 92 94 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/HIFFProblem.cs
r17320 r17382 28 28 using HeuristicLab.Core; 29 29 using HeuristicLab.Encodings.BinaryVectorEncoding; 30 using HeuristicLab.Optimization; 30 31 31 32 namespace HeuristicLab.Problems.Binary { … … 48 49 } 49 50 // In the GECCO paper, Section 4.1 50 public override doubleEvaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) {51 public override ISingleObjectiveEvaluationResult Evaluate(BinaryVector individual, IRandom random, CancellationToken cancellationToken) { 51 52 int[] level = new int[individual.Length]; 52 53 int levelLength = individual.Length; … … 83 84 84 85 // Convert to percentage of total 85 return (double)total / maximum; 86 var quality = (double)total / maximum; 87 return new SingleObjectiveEvaluationResult(quality); 86 88 } 87 89 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/OneMaxProblem.cs
r17320 r17382 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Encodings.BinaryVectorEncoding; 29 using HeuristicLab.Optimization; 29 30 30 31 namespace HeuristicLab.Problems.Binary { … … 48 49 } 49 50 50 public override double Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) { 51 return vector.Count(b => b); 51 public override ISingleObjectiveEvaluationResult Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) { 52 var quality = vector.Count(b => b); 53 return new SingleObjectiveEvaluationResult(quality); 52 54 } 53 55 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/SingleObjectiveExternalEvaluationProblem.cs
r17363 r17382 105 105 106 106 #region Single Objective Problem Overrides 107 public override doubleEvaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) {107 public override ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) { 108 108 var qualityMessage = Evaluate(BuildSolutionMessage(solution), cancellationToken); 109 109 if (!qualityMessage.HasExtension(SingleObjectiveQualityMessage.QualityMessage_)) 110 110 throw new InvalidOperationException("The received message is not a SingleObjectiveQualityMessage."); 111 return qualityMessage.GetExtension(SingleObjectiveQualityMessage.QualityMessage_).Quality; 111 var quality = qualityMessage.GetExtension(SingleObjectiveQualityMessage.QualityMessage_).Quality; 112 return new SingleObjectiveEvaluationResult(quality); 113 112 114 } 113 115 public virtual QualityMessage Evaluate(SolutionMessage solutionMessage, CancellationToken cancellationToken) { -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/ArtificialAnt/Problem.cs
r17320 r17382 135 135 136 136 137 public override doubleEvaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {137 public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 138 138 var interpreter = new Interpreter(tree, World, MaxTimeSteps); 139 139 interpreter.Run(); 140 return interpreter.FoodEaten; 140 var quality = interpreter.FoodEaten; 141 return new SingleObjectiveEvaluationResult(quality); 141 142 } 142 143 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/BasicSymbolicRegression/Problem.cs
r17320 r17382 28 28 using HeuristicLab.Core; 29 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 using HeuristicLab.Optimization; 30 31 using HeuristicLab.Parameters; 31 32 using HeuristicLab.Problems.DataAnalysis; … … 90 91 91 92 92 public override doubleEvaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {93 public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 93 94 // Doesn't use classes from HeuristicLab.Problems.DataAnalysis.Symbolic to make sure that the implementation can be fully understood easily. 94 95 // HeuristicLab.Problems.DataAnalysis.Symbolic would already provide all the necessary functionality (esp. interpreter) but at a much higher complexity. … … 103 104 var r = OnlinePearsonsRCalculator.Calculate(target, predicted, out errorState); 104 105 if (errorState != OnlineCalculatorError.None) r = 0; 105 return r * r; 106 var quality = r * r; 107 108 return new SingleObjectiveEvaluationResult(quality); 106 109 } 107 110 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs
r17320 r17382 29 29 using HeuristicLab.Data; 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 31 using HeuristicLab.Optimization; 31 32 using HeuristicLab.Parameters; 32 33 … … 104 105 105 106 106 public override doubleEvaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {107 public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 107 108 if (NumberOfBits <= 0) throw new NotSupportedException("Number of bits must be larger than zero."); 108 109 if (NumberOfBits > 10) throw new NotSupportedException("Even parity does not support problems with number of bits > 10."); … … 110 111 var targets = bs.Select(b => CalcTarget(b, NumberOfBits)); 111 112 var pred = Interpret(tree, bs); 112 return targets.Zip(pred, (t, p) => t == p ? 1 : 0).Sum(); // count number of correct predictions 113 var quality = targets.Zip(pred, (t, p) => t == p ? 1 : 0).Sum(); // count number of correct predictions 114 115 return new SingleObjectiveEvaluationResult(quality); 113 116 } 114 117 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs
r17320 r17382 30 30 using HeuristicLab.Data; 31 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 32 using HeuristicLab.Optimization; 32 33 using HeuristicLab.Parameters; 33 34 … … 118 119 119 120 120 public override doubleEvaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {121 public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 121 122 if (NumberOfBits <= 0) throw new NotSupportedException("Number of bits must be larger than zero."); 122 123 if (NumberOfBits > 37) throw new NotSupportedException("Multiplexer does not support problems with number of bits > 37."); … … 126 127 var targets = bs.Select(b => CalcTarget(b, addrBits, inputBits)); 127 128 var pred = Interpret(tree, bs, (byte)addrBits); 128 return targets.Zip(pred, (t, p) => t == p ? 1 : 0).Sum(); // count number of correct predictions 129 var quality = targets.Zip(pred, (t, p) => t == p ? 1 : 0).Sum(); // count number of correct predictions 130 131 return new SingleObjectiveEvaluationResult(quality); 129 132 } 130 133 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/LawnMower/Problem.cs
r17320 r17382 93 93 } 94 94 95 public override doubleEvaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) {95 public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 96 96 var length = LawnLengthParameter.Value.Value; 97 97 var width = LawnWidthParameter.Value.Value; … … 105 105 numberOfMowedCells++; 106 106 } 107 return numberOfMowedCells; 107 var quality = numberOfMowedCells; 108 return new SingleObjectiveEvaluationResult(quality); 108 109 } 109 110 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/robocode/Problem.cs
r17320 r17382 99 99 private void AfterDeserialization() { RegisterEventHandlers(); } 100 100 101 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 102 return Interpreter.EvaluateTankProgram(tree, RobocodePath, Enemies, null, false, NrOfRounds); 101 public override ISingleObjectiveEvaluationResult Evaluate(ISymbolicExpressionTree tree, IRandom random, CancellationToken cancellationToken) { 102 var quality = Interpreter.EvaluateTankProgram(tree, RobocodePath, Enemies, null, false, NrOfRounds); 103 return new SingleObjectiveEvaluationResult(quality); 103 104 } 104 105 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GrammaticalEvolution/3.4/ArtificialAnt/GEArtificialAntProblem.cs
r17320 r17382 96 96 97 97 private readonly object syncRoot = new object(); 98 public override doubleEvaluate(IntegerVector solution, IRandom random, CancellationToken cancellationToken) {98 public override ISingleObjectiveEvaluationResult Evaluate(IntegerVector solution, IRandom random, CancellationToken cancellationToken) { 99 99 var bounds = Encoding.Bounds; 100 100 var len = Encoding.Length; … … 113 113 interpreter.Run(); 114 114 115 return interpreter.FoodEaten; 115 var quality = interpreter.FoodEaten; 116 return new SingleObjectiveEvaluationResult(quality); 116 117 } 117 118 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GraphColoring/3.3/GraphColoringProblem.cs
r17320 r17382 129 129 } 130 130 131 public override doubleEvaluate(LinearLinkage lle, IRandom random, CancellationToken cancellationToken) {131 public override ISingleObjectiveEvaluationResult Evaluate(LinearLinkage lle, IRandom random, CancellationToken cancellationToken) { 132 132 var adjList = adjacencyListParameter.Value; 133 133 var llee = lle.ToEndLinks(); // LLE-e encoding uses the highest indexed member as group number 134 135 double quality = double.NaN; 134 136 135 137 switch (FitnessFunction) { … … 142 144 var mag = Math.Pow(10, -(int)Math.Ceiling(Math.Log10(llee.Length))); 143 145 // the value is e.g. 4.03 for 4 conflicts with 3 colors (and less than 100 nodes) 144 return conflicts + colors * mag; 146 quality = conflicts + colors * mag; 147 break; 145 148 } 146 149 case FitnessFunction.Penalized: { … … 157 160 if (color1 == color2) colors[color1].ConflictCount++; 158 161 } 159 return 2 * colors.Sum(x => x.Value.ColorCount * x.Value.ConflictCount) - colors.Sum(x => x.Value.ColorCount * x.Value.ColorCount); 162 quality = 2 * colors.Sum(x => x.Value.ColorCount * x.Value.ConflictCount) - colors.Sum(x => x.Value.ColorCount * x.Value.ColorCount); 163 break; 160 164 } 161 165 default: throw new InvalidOperationException(string.Format("Unknown fitness function {0}.", FitnessFunction)); 162 166 } 167 168 return new SingleObjectiveEvaluationResult(quality); 163 169 } 164 170 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r17356 r17382 97 97 } 98 98 99 public override doubleEvaluate(BinaryVector solution, IRandom random, CancellationToken cancellationToken) {99 public override ISingleObjectiveEvaluationResult Evaluate(BinaryVector solution, IRandom random, CancellationToken cancellationToken) { 100 100 var totalWeight = 0.0; 101 101 var totalValue = 0.0; … … 105 105 totalValue += Values[i]; 106 106 } 107 return totalWeight > KnapsackCapacity ? KnapsackCapacity - totalWeight : totalValue; 107 var quality = totalWeight > KnapsackCapacity ? KnapsackCapacity - totalWeight : totalValue; 108 return new SingleObjectiveEvaluationResult(quality); 108 109 } 109 110 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.NK/3.3/NKLandscape.cs
r17320 r17382 29 29 using HeuristicLab.Data; 30 30 using HeuristicLab.Encodings.BinaryVectorEncoding; 31 using HeuristicLab.Optimization; 31 32 using HeuristicLab.Parameters; 32 33 using HeuristicLab.PluginInfrastructure; … … 335 336 } 336 337 337 public override doubleEvaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) {338 public override ISingleObjectiveEvaluationResult Evaluate(BinaryVector vector, IRandom random, CancellationToken cancellationToken) { 338 339 double[] f_i; //useful for debugging 339 340 double quality = Evaluate(vector, GeneInteractions, Weights, InteractionSeed.Value, out f_i, Q, P); 340 return quality;341 return new SingleObjectiveEvaluationResult(quality); 341 342 } 342 343 #endregion -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/AnalyticalPTSP.cs
r17335 r17382 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Encodings.PermutationEncoding; 27 using HeuristicLab.Optimization; 27 28 28 29 namespace HeuristicLab.Problems.PTSP { … … 60 61 } 61 62 62 public override double Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) { 63 return Evaluate(tour, ProbabilisticTSPData, cancellationToken); 63 public override ISingleObjectiveEvaluationResult Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) { 64 var quality = Evaluate(tour, ProbabilisticTSPData, cancellationToken); 65 return new SingleObjectiveEvaluationResult(quality); 64 66 } 65 67 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/EstimatedPTSP.cs
r17335 r17382 29 29 using HeuristicLab.Data; 30 30 using HeuristicLab.Encodings.PermutationEncoding; 31 using HeuristicLab.Optimization; 31 32 using HeuristicLab.Parameters; 32 33 using HeuristicLab.Problems.Instances; … … 56 57 set { RealizationsParameter.Value.Value = value; } 57 58 } 58 59 59 60 private ReadOnlyItemList<BoolArray> RealizationData { 60 61 get { return RealizationDataParameter.Value; } … … 102 103 } 103 104 104 public override double Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) { 105 return Evaluate(tour, ProbabilisticTSPData, RealizationData, cancellationToken); 105 public override ISingleObjectiveEvaluationResult Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) { 106 var quality = Evaluate(tour, ProbabilisticTSPData, RealizationData, cancellationToken); 107 return new SingleObjectiveEvaluationResult(quality); 106 108 } 107 109 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/ProbabilisticTSP.cs
r17363 r17382 124 124 try { 125 125 var tour = new Permutation(PermutationTypes.RelativeUndirected, data.BestKnownTour); 126 var tourLength = Evaluate(tour, new MersenneTwister(1)) ;126 var tourLength = Evaluate(tour, new MersenneTwister(1)).Quality; 127 127 BestKnownSolution = ProbabilisticTSPData.GetSolution(tour, tourLength); 128 128 BestKnownQuality = tourLength; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/CompiledProblemDefinition.cs
r17381 r17382 61 61 public abstract bool Maximization { get; } 62 62 63 public virtual doubleEvaluate(TEncodedSolution solution, IRandom random) {63 public virtual ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random) { 64 64 return Evaluate(solution, random, CancellationToken.None); 65 65 } 66 public abstract doubleEvaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken);66 public abstract ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken); 67 67 68 68 public virtual void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random) { … … 70 70 } 71 71 public virtual void Evaluate(ISingleObjectiveSolutionContext<TEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken) { 72 double quality= Evaluate(solutionContext.EncodedSolution, random, cancellationToken);73 solutionContext.EvaluationResult = new SingleObjectiveEvaluationResult(quality);72 var evaluationResult = Evaluate(solutionContext.EncodedSolution, random, cancellationToken); 73 solutionContext.EvaluationResult = evaluationResult; 74 74 } 75 75 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs
r17366 r17382 51 51 public bool Maximization => CompiledProblemDefinition.Maximization; 52 52 53 doubleISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution solution, IRandom random) {53 ISingleObjectiveEvaluationResult ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution solution, IRandom random) { 54 54 return CompiledProblemDefinition.Evaluate(solution, random); 55 55 } 56 56 57 doubleISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) {57 ISingleObjectiveEvaluationResult ISingleObjectiveProblemDefinition<TEncoding, TEncodedSolution>.Evaluate(TEncodedSolution solution, IRandom random, CancellationToken cancellationToken) { 58 58 return CompiledProblemDefinition.Evaluate(solution, random, cancellationToken); 59 59 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r17363 r17382 111 111 ProblemDefinition.Evaluate(solutionContext, random, cancellationToken); 112 112 } 113 public override doubleEvaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) {113 public override ISingleObjectiveEvaluationResult Evaluate(TEncodedSolution individual, IRandom random, CancellationToken cancellationToken) { 114 114 return ProblemDefinition.Evaluate(individual, random, cancellationToken); 115 115 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/SingleObjectiveProblem_Template.cs
r17381 r17382 23 23 //TODO add other methods 24 24 25 public override void Evaluate(ISingleObjectiveSolutionContext<SOLUTION_CLASS> solutionContext, IRandom random, CancellationToken cancellationToken) { 26 var quality = Evaluate(solutionContext.EncodedSolution, random, cancellationToken); 25 public override ISingleObjectiveEvaluationResult Evaluate(SOLUTION_CLASS solution, IRandom random, CancellationToken cancellationToken) { 26 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 27 var quality = 0.0; 27 28 var evaluationResult = new SingleObjectiveEvaluationResult(quality); 28 solutionContext.EvaluationResult =evaluationResult;29 return evaluationResult; 29 30 } 30 31 31 public override double Evaluate(SOLUTION_CLASS solution, IRandom random, CancellationToken cancellationToken) { 32 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 33 var quality = 0.0; 34 return quality; 35 } 36 37 public override void Analyze(ISingleObjectiveSolutionContext<TEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) { 32 public override void Analyze(ISingleObjectiveSolutionContext<SOLUTION_CLASS>[] solutionContexts, ResultCollection results, IRandom random) { 38 33 var solutions = solutionContexts.Select(c => c.EncodedSolution).ToArray(); 39 34 var qualities = solutionContexts.Select(c => c.EvaluationResult.Quality).ToArray(); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r17320 r17382 136 136 } 137 137 138 public override double Evaluate(Permutation assignment, IRandom random, CancellationToken cancellationToken) { 139 return Evaluate(assignment, cancellationToken); 138 public override ISingleObjectiveEvaluationResult Evaluate(Permutation assignment, IRandom random, CancellationToken cancellationToken) { 139 var quality = Evaluate(assignment, cancellationToken); 140 return new SingleObjectiveEvaluationResult(quality); 140 141 } 141 142 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs
r17320 r17382 109 109 } 110 110 111 public override double Evaluate(RealVector individual, IRandom random, CancellationToken cancellationToken) { 112 return TestFunction.Evaluate(individual); 111 public override ISingleObjectiveEvaluationResult Evaluate(RealVector individual, IRandom random, CancellationToken cancellationToken) { 112 var quality = TestFunction.Evaluate(individual); 113 return new SingleObjectiveEvaluationResult(quality); 113 114 } 114 115 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSP.cs
r17335 r17382 83 83 } 84 84 85 public override double Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) { 86 return Evaluate(tour); 85 public override ISingleObjectiveEvaluationResult Evaluate(Permutation tour, IRandom random, CancellationToken cancellationToken) { 86 var quality = Evaluate(tour); 87 return new SingleObjectiveEvaluationResult(quality); 87 88 } 88 89
Note: See TracChangeset
for help on using the changeset viewer.