Changeset 17710 for branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestSolution
- Timestamp:
- 08/03/20 15:50:59 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestSolution/BestVRPSolutionAnalyzer.cs
r17709 r17710 27 27 using HeuristicLab.Optimization; 28 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; 29 30 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 30 31 … … 33 34 /// An operator for analyzing the best solution of Vehicle Routing Problems. 34 35 /// </summary> 36 //TODO: remove this operator -> part of VRP problem analyze 35 37 [Item("BestVRPSolutionAnalyzer", "An operator for analyzing the best solution of Vehicle Routing Problems.")] 36 38 [StorableType("3e1bb409-0b8f-4324-826c-2190aa5fb2b6")] 37 39 public sealed class BestVRPSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator { 40 41 [Storable] private ILookupParameter<IVRPProblemInstance> problemInstanceParameter; 42 public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter => problemInstanceParameter; 43 [Storable] private IScopeTreeLookupParameter<IVRPEncodedSolution> vrpToursParameter; 44 public IScopeTreeLookupParameter<IVRPEncodedSolution> VRPToursParameter => vrpToursParameter; 38 45 39 46 [Storable] private IScopeTreeLookupParameter<VRPEvaluation> evaluationParameter; … … 43 50 public ILookupParameter<VRPSolution> BestSolutionParameter => bestSolutionParameter; 44 51 45 [Storable] private IResultParameter<VRPEvaluation> bestEvaluationParameter; 46 public IResultParameter<VRPEvaluation> BestSolutionEvaluationParameter => bestEvaluationParameter; 52 [Storable] private ILookupParameter<VRPSolution> bestFeasibleSolutionParameter; 53 public ILookupParameter<VRPSolution> BestFeasibleSolutionParameter => bestFeasibleSolutionParameter; 54 55 [Storable] private IResultParameter<VRPEvaluation> bestEvaluationResult; 56 public IResultParameter<VRPEvaluation> BestSolutionEvaluationResult => bestEvaluationResult; 57 [Storable] private IResultParameter<VRPEvaluation> bestFeasibleEvaluationResult; 58 public IResultParameter<VRPEvaluation> BestFeasibleSolutionEvaluationResult => bestFeasibleEvaluationResult; 59 [Storable] private IResultParameter<VRPSolution> bestSolutionResult; 60 public IResultParameter<VRPSolution> BestSolutionResult => bestSolutionResult; 61 [Storable] private IResultParameter<VRPSolution> bestFeasibleSolutionResult; 62 public IResultParameter<VRPSolution> BestFeasibleSolutionResult => bestFeasibleSolutionResult; 47 63 48 64 public bool EnabledByDefault { … … 54 70 private BestVRPSolutionAnalyzer(BestVRPSolutionAnalyzer original, Cloner cloner) 55 71 : base(original, cloner) { 72 problemInstanceParameter = cloner.Clone(original.problemInstanceParameter); 73 vrpToursParameter = cloner.Clone(original.vrpToursParameter); 56 74 evaluationParameter = cloner.Clone(original.evaluationParameter); 57 75 bestSolutionParameter = cloner.Clone(original.bestSolutionParameter); 58 bestEvaluationParameter = cloner.Clone(original.bestEvaluationParameter); 76 bestFeasibleSolutionParameter = cloner.Clone(original.bestFeasibleSolutionParameter); 77 bestEvaluationResult = cloner.Clone(original.bestEvaluationResult); 78 bestFeasibleEvaluationResult = cloner.Clone(original.bestFeasibleEvaluationResult); 79 bestSolutionResult = cloner.Clone(original.bestSolutionResult); 80 bestFeasibleSolutionResult = cloner.Clone(original.bestFeasibleSolutionResult); 59 81 } 60 82 public BestVRPSolutionAnalyzer() 61 83 : base() { 84 Parameters.Add(problemInstanceParameter = new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance.")); 85 Parameters.Add(vrpToursParameter = new ScopeTreeLookupParameter<IVRPEncodedSolution>("VRPTours", "The VRP encoded solution.")); 62 86 Parameters.Add(evaluationParameter = new ScopeTreeLookupParameter<VRPEvaluation>("EvaluationResult", "The qualities of the VRP solutions which should be analyzed.")); 63 87 Parameters.Add(bestSolutionParameter = new LookupParameter<VRPSolution>("BestSolution", "The best-so-far solution.")); 64 Parameters.Add(bestEvaluationParameter = new ResultParameter<VRPEvaluation>("Best VRP Evaluation", "The best VRP evaluation.", "Results")); 88 Parameters.Add(bestFeasibleSolutionParameter = new LookupParameter<VRPSolution>("BestFeasibleSolution", "The best-so-far feasible solution.")); 89 Parameters.Add(bestEvaluationResult = new ResultParameter<VRPEvaluation>("Best VRP Solution Evaluation", "The best VRP evaluation.", "Results")); 90 Parameters.Add(bestFeasibleEvaluationResult = new ResultParameter<VRPEvaluation>("Best Feasible VRP Solution Evaluation", "The best feasible VRP evaluation.", "Results")); 91 Parameters.Add(bestSolutionResult = new ResultParameter<VRPSolution>("Best VRP Solution", "The best-so-far VRP solution.")); 92 Parameters.Add(bestFeasibleSolutionResult = new ResultParameter<VRPSolution>("Best feasible VRP Solution", "The best-so-far feasible VRP solution.")); 65 93 } 66 94 … … 72 100 var evaluations = EvaluationParameter.ActualValue; 73 101 74 int i = evaluations.Select((x, index) => new { index, Eval = x }).OrderBy(x => x.Eval.Quality).First().index; 102 var bestInPop = evaluations.Select((x, index) => new { index, Eval = x }).OrderBy(x => x.Eval.Quality).First(); 103 var bestFeasibleInPop = evaluations.Select((x, index) => new { index, Eval = x }).Where(x => x.Eval.IsFeasible).OrderBy(x => x.Eval.Quality).FirstOrDefault(); 75 104 76 var bestEvaluation = BestSolutionEvaluation Parameter.ActualValue;105 var bestEvaluation = BestSolutionEvaluationResult.ActualValue; 77 106 78 107 var bestSolution = BestSolutionParameter.ActualValue; 79 if (bestSolution == null || evaluations[i].Quality <= bestSolution.Quality.Value) { 80 BestSolutionEvaluationParameter.ActualValue = (VRPEvaluation)evaluations[i].Clone(); 108 if (bestSolution == null || bestInPop.Eval.Quality < bestSolution.Evaluation.Quality) { 109 var best = new VRPSolution(ProblemInstanceParameter.ActualValue, 110 VRPToursParameter.ActualValue[bestInPop.index], (VRPEvaluation)bestInPop.Eval.Clone()); 111 BestSolutionParameter.ActualValue = best; 112 BestSolutionResult.ActualValue = best; 113 BestSolutionEvaluationResult.ActualValue = (VRPEvaluation)bestInPop.Eval.Clone(); 114 }; 115 116 if (bestFeasibleInPop != null) { 117 var bestFeasibleSolution = BestFeasibleSolutionParameter.ActualValue; 118 if (bestFeasibleSolution == null || bestFeasibleInPop.Eval.Quality < bestFeasibleSolution.Evaluation.Quality) { 119 var bestFeasible = new VRPSolution(ProblemInstanceParameter.ActualValue, 120 VRPToursParameter.ActualValue[bestFeasibleInPop.index], (VRPEvaluation)bestFeasibleInPop.Eval.Clone()); 121 BestFeasibleSolutionParameter.ActualValue = bestFeasible; 122 bestFeasibleSolutionResult.ActualValue = bestFeasible; 123 BestFeasibleSolutionEvaluationResult.ActualValue = (VRPEvaluation)bestFeasibleInPop.Eval.Clone(); 124 } 81 125 } 82 126
Note: See TracChangeset
for help on using the changeset viewer.