Changeset 7854
- Timestamp:
- 05/21/12 14:12:32 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestSolution/BestVRPSolutionAnalyzer.cs
r7175 r7854 30 30 using HeuristicLab.Problems.VehicleRouting.Variants; 31 31 using HeuristicLab.Common; 32 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 32 33 33 34 namespace HeuristicLab.Problems.VehicleRouting { … … 126 127 127 128 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 128 129 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;130 131 129 IVRPEncoding best = solutions[i].Clone() as IVRPEncoding; 132 130 VRPSolution solution = BestSolutionParameter.ActualValue; … … 139 137 results.Add(new Result("Best VRP Solution VehicleUtilization", new DoubleValue(vehiclesUtilizations[i].Value))); 140 138 } else { 141 if (qualities[i].Value <= solution.Quality.Value) { 139 VRPEvaluation eval = problemInstance.Evaluate(solution.Solution); 140 if (qualities[i].Value <= eval.Quality) { 142 141 solution.ProblemInstance = problemInstance; 143 142 solution.Solution = best.Clone() as IVRPEncoding; … … 148 147 } 149 148 150 VRPSolution validSolution = BestValidSolutionParameter.ActualValue; 151 if (validSolution == null) { 152 if (ProblemInstanceParameter.ActualValue.Feasible(best)) { 153 validSolution = new VRPSolution(problemInstance, best.Clone() as IVRPEncoding, new DoubleValue(qualities[i].Value)); 154 BestValidSolutionParameter.ActualValue = validSolution; 155 if (results.ContainsKey("Best valid VRP Solution")) 156 results["Best valid VRP Solution"].Value = validSolution; 157 else 158 results.Add(new Result("Best valid VRP Solution", validSolution)); 149 var idx = qualities.Select((x, index) => new { index, x.Value }).Where(index => problemInstance.Feasible(solutions[index.index])).OrderBy(x => x.Value).FirstOrDefault(); 150 if (idx != null) { 151 int j = idx.index; 152 IVRPEncoding bestFeasible = solutions[j].Clone() as IVRPEncoding; 153 VRPSolution validSolution = BestValidSolutionParameter.ActualValue; 154 if (validSolution == null) { 155 if (ProblemInstanceParameter.ActualValue.Feasible(best)) { 156 validSolution = new VRPSolution(problemInstance, best.Clone() as IVRPEncoding, new DoubleValue(qualities[j].Value)); 157 BestValidSolutionParameter.ActualValue = validSolution; 158 if (results.ContainsKey("Best valid VRP Solution")) 159 results["Best valid VRP Solution"].Value = validSolution; 160 else 161 results.Add(new Result("Best valid VRP Solution", validSolution)); 159 162 160 results.Add(new Result("Best valid VRP Solution Distance", new DoubleValue(distances[i].Value))); 161 results.Add(new Result("Best valid VRP Solution VehicleUtilization", new DoubleValue(vehiclesUtilizations[i].Value))); 162 } 163 } else { 164 if (qualities[i].Value <= validSolution.Quality.Value) { 165 if (ProblemInstanceParameter.ActualValue.Feasible(best)) { 166 validSolution.ProblemInstance = problemInstance; 167 validSolution.Solution = best.Clone() as IVRPEncoding; 168 validSolution.Quality.Value = qualities[i].Value; 169 (results["Best valid VRP Solution Distance"].Value as DoubleValue).Value = distances[i].Value; 170 (results["Best valid VRP Solution VehicleUtilization"].Value as DoubleValue).Value = vehiclesUtilizations[i].Value; 163 results.Add(new Result("Best valid VRP Solution Distance", new DoubleValue(distances[j].Value))); 164 results.Add(new Result("Best valid VRP Solution VehicleUtilization", new DoubleValue(vehiclesUtilizations[j].Value))); 165 } 166 } else { 167 if (qualities[j].Value <= validSolution.Quality.Value) { 168 if (ProblemInstanceParameter.ActualValue.Feasible(best)) { 169 validSolution.ProblemInstance = problemInstance; 170 validSolution.Solution = best.Clone() as IVRPEncoding; 171 validSolution.Quality.Value = qualities[j].Value; 172 (results["Best valid VRP Solution Distance"].Value as DoubleValue).Value = distances[j].Value; 173 (results["Best valid VRP Solution VehicleUtilization"].Value as DoubleValue).Value = vehiclesUtilizations[j].Value; 174 } 171 175 } 172 176 } 173 }174 177 175 if (bestKnownQuality == null || 176 qualities[i].Value < bestKnownQuality.Value) { 177 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 178 BestKnownSolutionParameter.ActualValue = (VRPSolution)solution.Clone(); 178 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 179 if (bestKnownQuality == null || qualities[j].Value < bestKnownQuality.Value) { 180 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[j].Value); 181 BestKnownSolutionParameter.ActualValue = (VRPSolution)validSolution.Clone(); 182 } 179 183 } 180 184
Note: See TracChangeset
for help on using the changeset viewer.