Changeset 15325 for trunk/sources/HeuristicLab.Problems.BinPacking/3.3
- Timestamp:
- 08/13/17 12:25:57 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.BinPacking/3.3/3D/BinPacking3D.cs
r15276 r15325 64 64 } 65 65 66 public override void PackItem(int itemID, PackingItem item, PackingPosition position) { 66 public override void PackItem(int itemID, PackingItem item, PackingPosition position) {// base call is deliberately omitted, because UpdateResidualSpace needs to be fitted in before 67 // base call is deliberately omitted, because UpdateResidualSpace needs to be fitted in before 68 Items[itemID] = item; 69 Positions[itemID] = position; 70 ExtremePoints.Remove(position); 67 71 ResidualSpace.Remove(position); 68 base.PackItem(itemID, item, position); 72 UpdateResidualSpace(item, position); 73 foreach (int id in Items.Select(x => x.Key)) 74 GenerateNewExtremePointsForNewItem(Items[id], Positions[id]); 75 76 AddNewItemToOccupationLayers(itemID, item, position); 69 77 } 70 78 … … 237 245 if (positionFound != null) { 238 246 PackItem(itemID, item, positionFound); 239 if (Items.Count > 1)240 UpdateResidualSpace(item, positionFound);241 247 sequence.Remove(itemID); 242 248 } … … 350 356 public void UpdateResidualSpace(PackingItem item, PackingPosition pos) { 351 357 foreach (var ep in ExtremePoints) { 352 if (ep.Z >= pos.Z && ep.Z <= pos.Z + item.Depth) { 353 if (ep.X <= pos.X && ep.Y > pos.Y && ep.Y < pos.Y + item.Height) { 358 var rs = ResidualSpace[ep]; 359 var depth = pos.Rotated ? item.Width : item.Depth; 360 var width = pos.Rotated ? item.Depth : item.Width; 361 if (ep.Z >= pos.Z && ep.Z < pos.Z + depth) { 362 if (ep.X <= pos.X && ep.Y >= pos.Y && ep.Y < pos.Y + item.Height) { 354 363 var diff = pos.X - ep.X; 355 var newRSX = ResidualSpace[ep].Item1 < diff ? ResidualSpace[ep].Item1 : diff;356 ResidualSpace[ep] = Tuple.Create(newRSX, ResidualSpace[ep].Item2, ResidualSpace[ep].Item3);364 var newRSX = Math.Min(rs.Item1, diff); 365 ResidualSpace[ep] = Tuple.Create(newRSX, rs.Item2, rs.Item3); 357 366 } 358 if (ep.Y <= pos.Y && ep.X > pos.X && ep.X < pos.X + item.Width) {367 if (ep.Y <= pos.Y && ep.X >= pos.X && ep.X < pos.X + width) { 359 368 var diff = pos.Y - ep.Y; 360 var newRSY = ResidualSpace[ep].Item2 < diff ? ResidualSpace[ep].Item2 : diff;361 ResidualSpace[ep] = Tuple.Create( ResidualSpace[ep].Item1, newRSY, ResidualSpace[ep].Item3);369 var newRSY = Math.Min(rs.Item2, diff); 370 ResidualSpace[ep] = Tuple.Create(rs.Item1, newRSY, rs.Item3); 362 371 } 363 372 } 364 if (ep.Z <= pos.Z && 365 ep.Y > pos.Y && ep.Y < pos.Y + item.Height &&366 ep.X > pos.X && ep.X < pos.X + item.Width) {367 368 var newRSZ = ResidualSpace[ep].Item3 < diff ? ResidualSpace[ep].Item3 : diff;369 ResidualSpace[ep] = Tuple.Create(ResidualSpace[ep].Item1, ResidualSpace[ep].Item2, newRSZ);373 if (ep.Z <= pos.Z && 374 ep.Y >= pos.Y && ep.Y < pos.Y + item.Height && 375 ep.X >= pos.X && ep.X < pos.X + width) { 376 var diff = pos.Z - ep.Z; 377 var newRSZ = Math.Min(rs.Item3, diff); 378 ResidualSpace[ep] = Tuple.Create(rs.Item1, rs.Item2, newRSZ); 370 379 } 371 380 }
Note: See TracChangeset
for help on using the changeset viewer.