Changeset 15838 for branches/2817-BinPackingSpeedup
- Timestamp:
- 03/12/18 14:19:06 (7 years ago)
- Location:
- branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Algorithms/ExtremePointAlgorithm.cs
r15731 r15838 247 247 } 248 248 249 250 var x = Problem.SolutionEvaluator.Evaluate1(solution);251 252 /*253 if (double.IsNaN(result.Item2) || double.IsInfinity(result.Item2)) {254 continue;255 }256 257 if (double.IsNaN(best) || Problem.Maximization && result.Item2 > best || !Problem.Maximization && result.Item2 < best) {258 bestSolution = result.Item1;259 best = result.Item2;260 bestSorting = sort;261 bestFitting = fit;262 bestEPCreation = epCreation;263 }264 return true;*/265 266 249 if (token.IsCancellationRequested) { 267 250 return Tuple.Create(bestSolution, best, bestSorting, bestFitting, bestEPCreation); … … 277 260 278 261 /// <summary> 279 /// Returns a tuple with the solution and the packing ratiodepending on the given parameters262 /// Returns a solution depending on the given parameters 280 263 /// </summary> 281 264 /// <param name="parameters"></param> … … 284 267 285 268 var sol = parameters.Decoder.Decode(parameters.SortedItems, parameters.Bin, parameters.Items, parameters.StackingConstraints); 286 //var fit = parameters.Evaluator.Evaluate(sol); 287 288 return sol; //Tuple.Create(sol, fit); 269 270 return sol; 289 271 } 290 272 … … 298 280 public ExtremePointCreationMethod ExtremePointGeneration { get; set; } 299 281 } 300 301 282 302 283 /// <summary> 303 284 /// Returns a new permutation of the given items depending on the sorting method -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Encoding/ExtremePointPermutationDecoder.cs
r15652 r15838 69 69 : base(original, cloner) { 70 70 fittingMethodParameter = cloner.Clone(original.fittingMethodParameter); 71 //_binPacker = cloner.Clone(original._binPacker);72 71 } 73 72 public ExtremePointPermutationDecoder() { … … 86 85 return new ExtremePointPermutationDecoder(this, cloner); 87 86 } 88 89 /*[Storable] 90 BinPacker _binPacker; 91 */ 87 92 88 /// <summary> 93 89 /// Creates a solution for displaying it on the HEAL gui … … 108 104 } 109 105 return solution; 110 } 111 112 Permutation AddOffset(Permutation p, int offset) { 113 var s = p.ToArray(); 114 for (int i = 0; i < s.Length; i++) { 115 s[i] += offset; 116 } 117 118 return new Permutation(PermutationTypes.Absolute, s); 119 } 106 } 120 107 } 121 108 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Evaluators/BinUtilizationEvaluator.cs
r15731 r15838 81 81 } 82 82 83 public Tuple<int, double, int, int> Evaluate 1(Solution solution) {83 public Tuple<int, double, int, int> EvaluateBinPacking(Solution solution) { 84 84 85 85 -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Evaluators/IEvaluator.cs
r15731 r15838 41 41 /// <param name="solution"></param> 42 42 /// <returns></returns> 43 Tuple<int, double, int, int> Evaluate 1(Solution solution);43 Tuple<int, double, int, int> EvaluateBinPacking(Solution solution); 44 44 } 45 45 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Evaluators/PackingRatioEvaluator.cs
r15731 r15838 98 98 } 99 99 100 public Tuple<int, double, int, int> Evaluate 1(Solution solution) {100 public Tuple<int, double, int, int> EvaluateBinPacking(Solution solution) { 101 101 102 102 -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointCreation/ExtremePointCreator.cs
r15617 r15838 232 232 /// <returns></returns> 233 233 protected bool IsWithinResidualSpaceOfAnotherExtremePoint(BinPacking3D binPacking, Vector3D pos, IEnumerable<ResidualSpace> residualSpaces) { 234 foreach (var residualSpace in residualSpaces) { 235 if (IsWithinResidualSpaceOfAnotherExtremePoint(binPacking, pos, residualSpace)) { 236 return true; 237 } 238 } 239 return false; 234 return residualSpaces.Any(x => IsWithinResidualSpaceOfAnotherExtremePoint(binPacking, pos, x)); 240 235 } 241 236 … … 262 257 /// <returns></returns> 263 258 protected virtual bool IsWithinResidualSpaceOfAnotherExtremePoint(Vector3D pos, ResidualSpace rsPos, PackingPosition ep, ResidualSpace rsEp) { 264 /*old implementation265 return rsEp.Width >= pos.X - ep.X + rsPos.Width266 && rsEp.Height >= pos.Y - ep.Y + rsPos.Height267 && rsEp.Depth >= pos.Z - ep.Z + rsPos.Depth;*/268 269 259 var x = pos.X >= ep.X && pos.X + rsPos.Width <= ep.X + rsEp.Width; 270 260 var y = pos.Y >= ep.Y && pos.Y + rsPos.Height <= ep.Y + rsEp.Height; … … 294 284 .Select(x => x.Intersect(line)) 295 285 .Where(x => x != null && x.Z <= pos.Z); 296 if (m. Where(x => x != null).Any()) {297 return m.MaxItems(x => x. Y).First();286 if (m.Any(x => x != null)) { 287 return m.MaxItems(x => x.Z).FirstOrDefault(); 298 288 } 299 289 return null; … … 307 297 .Select(x => x.Intersect(line)) 308 298 .Where(x => x != null && x.X <= pos.X); 309 if (m. Where(x => x != null).Any()) {310 return m.MaxItems(x => x. Y).First();299 if (m.Any(x => x != null)) { 300 return m.MaxItems(x => x.X).FirstOrDefault(); 311 301 } 312 302 return null; … … 320 310 .Select(x => x.Intersect(line)) 321 311 .Where(x => x != null && x.Y <= pos.Y); 322 if (m. Where(x => x != null).Any()) {323 return m.MaxItems(x => x.Y).First ();312 if (m.Any(x => x != null)) { 313 return m.MaxItems(x => x.Y).FirstOrDefault(); 324 314 } 325 315 return null; … … 333 323 .Select(x => x.Intersect(line)) 334 324 .Where(x => x != null && x.Z >= pos.Z); 335 if (m. Where(x => x != null).Any()) {336 return m.M axItems(x => x.Y).First();325 if (m.Any(x => x != null)) { 326 return m.MinItems(x => x.Z).FirstOrDefault(); 337 327 } 338 328 return null; … … 346 336 .Select(x => x.Intersect(line)) 347 337 .Where(x => x != null && x.X >= pos.X); 348 if (m. Where(x => x != null).Any()) {349 return m.M axItems(x => x.Y).First();338 if (m.Any(x => x != null)) { 339 return m.MinItems(x => x.X).FirstOrDefault(); 350 340 } 351 341 return null; … … 359 349 .Select(x => x.Intersect(line)) 360 350 .Where(x => x != null && x.Y >= pos.Y); 361 if (m. Where(x => x != null).Any()) {362 return m.M axItems(x => x.Y).First();351 if (m.Any(x => x != null)) { 352 return m.MinItems(x => x.Y).FirstOrDefault(); 363 353 } 364 354 return null; -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointCreation/ExtremePointCreatorFactory.cs
r15617 r15838 28 28 namespace HeuristicLab.Problems.BinPacking3D.ExtremePointCreation { 29 29 public static class ExtremePointCreatorFactory { 30 public static IExtremePointCreator CreateExtremePointCreator(ExtremePointCreationMethod epGenerationMethod, bool useStackingConstraints) { 31 if (epGenerationMethod == ExtremePointCreationMethod.PointProjection) { 30 31 /// <summary> 32 /// Returns an extreme point creator depending on the given creation method. 33 /// </summary> 34 /// <param name="epCreationMethod"></param> 35 /// <param name="useStackingConstraints"></param> 36 /// <returns></returns> 37 public static IExtremePointCreator CreateExtremePointCreator(ExtremePointCreationMethod epCreationMethod, bool useStackingConstraints) { 38 if (epCreationMethod == ExtremePointCreationMethod.PointProjection) { 32 39 return new PointProjectionBasedEPCreator(); 33 } else if (ep GenerationMethod == ExtremePointCreationMethod.LineProjection) {40 } else if (epCreationMethod == ExtremePointCreationMethod.LineProjection) { 34 41 return new LineProjectionBasedEPCreator(); 35 42 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointCreation/PointProjectionBasedEPCreator.cs
r15822 r15838 56 56 GenerateNewExtremePointsForItem(binPacking, it, pos); 57 57 }); 58 58 59 59 // remove not needed extreme points. 60 60 foreach (var extremePoint in binPacking.ExtremePoints.ToList()) { -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPackerMinRSLeft.cs
r15822 r15838 245 245 packingItem.Rotated = rsd.Item.Rotated; 246 246 packingItem.Tilted = rsd.Item.Tilted; 247 247 248 return rsd.Position; 248 249 } … … 254 255 $"Item: ({packingItem.Width} {packingItem.Depth} {packingItem.Height})"); 255 256 } 256 257 var rsd = CalculateResidalSpaceDifferences(packingBin, packingItem, useStackingConstraints).Where(x => x != null).FirstOrDefault(); 257 258 var rsds = CalculateResidalSpaceDifferences(packingBin, packingItem, useStackingConstraints).Where(x => x != null); 259 var rsd = rsds.FirstOrDefault(); 260 258 261 259 262 if (rsd == null) { … … 263 266 packingItem.Rotated = rsd.Item.Rotated; 264 267 packingItem.Tilted = rsd.Item.Tilted; 268 265 269 return rsd.Position; 266 270 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Solution.cs
r15731 r15838 42 42 43 43 public bool IsBetterThan(Solution other, IEvaluator evaluator, bool problemMaximization = true) { 44 var evaluatedThis = evaluator.Evaluate 1(this);44 var evaluatedThis = evaluator.EvaluateBinPacking(this); 45 45 46 46 if (double.IsInfinity(evaluatedThis.Item2) || double.IsNaN(evaluatedThis.Item2)) { … … 52 52 } 53 53 54 var evaluatedOther = evaluator.Evaluate 1(other);54 var evaluatedOther = evaluator.EvaluateBinPacking(other); 55 55 if (evaluatedThis.Item1 < evaluatedOther.Item1) { 56 56 return true;
Note: See TracChangeset
for help on using the changeset viewer.