Changeset 15646 for branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Algorithms/ExtremePointAlgorithm.cs
- Timestamp:
- 01/24/18 13:17:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Algorithms/ExtremePointAlgorithm.cs
r15617 r15646 202 202 /// <param name="token"></param> 203 203 /// <returns></returns> 204 private Tuple<Solution, double, SortingMethod?, FittingMethod?, ExtremePointCreationMethod?> 205 GetBest(PackingShape bin, 206 IList<PackingItem> items, 207 SortingMethod[] sortings, 204 private Tuple<Solution, double, SortingMethod?, FittingMethod?, ExtremePointCreationMethod?> 205 GetBest(PackingShape bin, 206 IList<PackingItem> items, 207 SortingMethod[] sortings, 208 208 FittingMethod[] fittings, 209 209 ExtremePointCreationMethod[] epCreationMethods, … … 222 222 }; 223 223 Permutation sortedItems; 224 224 225 225 if (SortByMaterialParameter.Value.Value) { 226 226 sortedItems = SortItemsByMaterialAndSortingMethod(bin, items, sort, DeltaParameter.Value.Value); … … 229 229 } 230 230 231 var result= Optimize(new OptimaizationParamters() {231 var solution = Optimize(new OptimaizationParamters() { 232 232 SortedItems = sortedItems, 233 233 Bin = bin, … … 238 238 ExtremePointGeneration = epCreation 239 239 }); 240 240 241 if (solution.IsBetterThan(bestSolution, Problem.SolutionEvaluator, Problem.Maximization)) { 242 bestSolution = solution; 243 best = Problem.SolutionEvaluator.Evaluate(solution); 244 bestSorting = sort; 245 bestFitting = fit; 246 bestEPCreation = epCreation; 247 } 248 249 250 var x = Problem.SolutionEvaluator.Evaluate1(solution); 251 252 /* 241 253 if (double.IsNaN(result.Item2) || double.IsInfinity(result.Item2)) { 242 254 continue; … … 250 262 bestEPCreation = epCreation; 251 263 } 264 return true;*/ 265 252 266 if (token.IsCancellationRequested) { 253 267 return Tuple.Create(bestSolution, best, bestSorting, bestFitting, bestEPCreation); … … 267 281 /// <param name="parameters"></param> 268 282 /// <returns></returns> 269 private static Tuple<Solution, double> Optimize(OptimaizationParamters parameters) {270 283 private static Solution Optimize(OptimaizationParamters parameters) { 284 271 285 var sol = parameters.Decoder.Decode(parameters.SortedItems, parameters.Bin, parameters.Items, parameters.StackingConstraints); 272 var fit = parameters.Evaluator.Evaluate(sol);273 274 return Tuple.Create(sol, fit);286 //var fit = parameters.Evaluator.Evaluate(sol); 287 288 return sol; //Tuple.Create(sol, fit); 275 289 } 276 290 … … 284 298 public ExtremePointCreationMethod ExtremePointGeneration { get; set; } 285 299 } 286 300 287 301 288 302 /// <summary> 289 303 /// Returns a new permutation of the given items depending on the sorting method 304 /// </summary> 305 /// <param name="bin"></param> 306 /// <param name="items"></param> 307 /// <param name="sortingMethod"></param> 308 /// <param name="delta"></param> 309 /// <returns></returns> 310 private Permutation SortItemsByMaterialAndSortingMethod(PackingShape bin, IList<PackingItem> items, SortingMethod sortingMethod, double delta) { 311 Permutation sorted = null; 312 313 switch (sortingMethod) { 314 case SortingMethod.Given: 315 sorted = new Permutation(PermutationTypes.Absolute, Enumerable.Range(0, items.Count).ToArray()); 316 break; 317 case SortingMethod.VolumeHeight: 318 sorted = items.SortByVolumeHeight(); 319 break; 320 case SortingMethod.HeightVolume: 321 sorted = items.SortByMaterialHeightVolume(); 322 break; 323 case SortingMethod.AreaHeight: 324 sorted = items.SortByMaterialAreaHeight(); 325 break; 326 case SortingMethod.HeightArea: 327 sorted = items.SortByMaterialHeightArea(); 328 break; 329 case SortingMethod.ClusteredAreaHeight: 330 sorted = items.SortByMaterialClusteredAreaHeight(bin, delta); 331 break; 332 case SortingMethod.ClusteredHeightArea: 333 sorted = items.SortByMaterialClusteredHeightArea(bin, delta); 334 break; 335 default: 336 throw new ArgumentException("Unknown sorting method: " + sortingMethod); 337 } 338 return sorted; 339 } 340 341 /// <summary> 342 /// Returns a new permutation of the given items depending on the material and sorting method 290 343 /// </summary> 291 344 /// <param name="bin"></param> … … 296 349 private Permutation SortItemsBySortingMethod(PackingShape bin, IList<PackingItem> items, SortingMethod sortingMethod, double delta) { 297 350 Permutation sorted = null; 298 351 299 352 switch (sortingMethod) { 300 353 case SortingMethod.Given: … … 305 358 break; 306 359 case SortingMethod.HeightVolume: 307 sorted = items.SortBy MaterialHeightVolume();360 sorted = items.SortByHeightVolume(); 308 361 break; 309 362 case SortingMethod.AreaHeight: 310 sorted = items.SortBy MaterialAreaHeight();363 sorted = items.SortByAreaHeight(); 311 364 break; 312 365 case SortingMethod.HeightArea: 313 sorted = items.SortBy MaterialHeightArea();366 sorted = items.SortByHeightArea(); 314 367 break; 315 368 case SortingMethod.ClusteredAreaHeight: 316 sorted = items.SortBy MaterialClusteredAreaHeight(bin, delta);369 sorted = items.SortByClusteredAreaHeight(bin, delta); 317 370 break; 318 371 case SortingMethod.ClusteredHeightArea: 319 sorted = items.SortBy MaterialClusteredHeightArea(bin, delta);372 sorted = items.SortByClusteredHeightArea(bin, delta); 320 373 break; 321 374 default: … … 324 377 return sorted; 325 378 } 326 327 /// <summary>328 /// Returns a new permutation of the given items depending on the material and sorting method329 /// </summary>330 /// <param name="bin"></param>331 /// <param name="items"></param>332 /// <param name="sortingMethod"></param>333 /// <param name="delta"></param>334 /// <returns></returns>335 private Permutation SortItemsByMaterialAndSortingMethod(PackingShape bin, IList<PackingItem> items, SortingMethod sortingMethod, double delta) {336 Permutation sorted = null;337 338 switch (sortingMethod) {339 case SortingMethod.Given:340 sorted = new Permutation(PermutationTypes.Absolute, Enumerable.Range(0, items.Count).ToArray());341 break;342 case SortingMethod.VolumeHeight:343 sorted = items.SortByVolumeHeight();344 break;345 case SortingMethod.HeightVolume:346 sorted = items.SortByHeightVolume();347 break;348 case SortingMethod.AreaHeight:349 sorted = items.SortByAreaHeight();350 break;351 case SortingMethod.HeightArea:352 sorted = items.SortByHeightArea();353 break;354 case SortingMethod.ClusteredAreaHeight:355 sorted = items.SortByClusteredAreaHeight(bin, delta);356 break;357 case SortingMethod.ClusteredHeightArea:358 sorted = items.SortByClusteredHeightArea(bin, delta);359 break;360 default:361 throw new ArgumentException("Unknown sorting method: " + sortingMethod);362 }363 return sorted;364 }365 379 } 366 380 }
Note: See TracChangeset
for help on using the changeset viewer.