Changeset 15471 for branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/BinPacking3D.cs
- Timestamp:
- 11/14/17 15:31:22 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/BinPacking3D.cs
r15462 r15471 67 67 #region New methods for bin packer class 68 68 69 /// <summary> 70 /// Puts a given item into the bin packing at the given position. 71 /// </summary> 72 /// <param name="itemID">Offset in the internal item array</param> 73 /// <param name="item">Item</param> 74 /// <param name="position">Position of the item in the bin packing</param> 69 75 public override void PackItem(int itemID, PackingItem item, PackingPosition position) { 70 76 Items[itemID] = item; … … 107 113 AddExtremePoint(ep2); 108 114 AddExtremePoint(ep3); 109 110 /* 111 ExtremePoints.Add(ep1); 112 ExtremePoints.Add(ep2); 113 ExtremePoints.Add(ep3); 114 115 var rs1 = CalculateResidualSpace(CreateRs(ep1)); 116 var rs2 = CalculateResidualSpace(CreateRs(ep2)); 117 var rs3 = CalculateResidualSpace(CreateRs(ep3)); 118 ResidualSpace.Add(ep1, rs1); 119 ResidualSpace.Add(ep2, rs2); 120 ResidualSpace.Add(ep3, rs3);*/ 121 } 122 123 124 /*private bool AddExtremePoint(PackingPosition position) { 125 if () 126 127 return true; 128 } 129 130 131 private bool AddExtremePoint(PackingPosition pos) { 132 if (ExtremePoints.Add(pos)) { 133 var rs = CalculateResidualSpace(new Vector3D(pos)); 134 ResidualSpace.Add(pos, rs); 135 // Check if existing extreme points are shadowed by the new point 136 // That is, their residual space fit entirely into the residual space of the new point 137 foreach (var ep in ExtremePoints.Where(x => x != pos && new Vector3D(x).IsInside(pos, rs)).ToList()) { 138 if (IsWithinResidualSpaceOfAnotherExtremePoint(new Vector3D(ep), ResidualSpace[ep], pos, rs)) { 139 ExtremePoints.Remove(ep); 140 ResidualSpace.Remove(ep); 141 } 142 } 143 return true; 144 } 145 return false; 146 }*/ 147 148 115 } 116 149 117 private Tuple<int, int, int> CalculateResidualSpace(Vector3D pos) { 150 118 var itemPos = Items.Select(x => new { Item = x.Value, Position = Positions[x.Key] }); … … 164 132 } 165 133 } 166 167 168 134 169 135 if (limit.X - pos.X <= 0 || limit.Y - pos.Y <= 0 || limit.Z - pos.Z <= 0) { 170 136 return Tuple.Create(0, 0, 0); 171 } 172 173 137 } 174 138 return Tuple.Create(limit.X - pos.X, limit.Y - pos.Y, limit.Z - pos.Z); 175 139 } … … 491 455 } 492 456 457 /// <summary> 458 /// Returns true if all values of a given tuple are not zero 459 /// </summary> 460 /// <param name="rs">Tuple with three integer values which represents a residual space</param> 461 /// <returns></returns> 493 462 private bool IsNonZero(Tuple<int, int, int> rs) { 494 463 return rs.Item1 > 0 && rs.Item2 > 0 && rs.Item3 > 0; 495 464 } 496 465 466 /// <summary> 467 /// 468 /// </summary> 469 /// <param name="pos"></param> 470 /// <param name="residualSpace"></param> 471 /// <returns></returns> 497 472 private bool IsWithinResidualSpaceOfAnotherExtremePoint(Vector3D pos, Tuple<int, int, int> residualSpace) { 498 473 var eps = ExtremePoints.Where(x => !pos.Equals(x) && pos.IsInside(x, ResidualSpace[x])); … … 505 480 } 506 481 482 /// <summary> 483 /// Adds an extrem point to the extreme point collection of the bin packing. 484 /// </summary> 485 /// <param name="pos">Position of the new extreme point</param> 486 /// <returns>Retruns true if the extreme point could be added</returns> 507 487 private bool AddExtremePoint(PackingPosition pos) { 508 488 if (ExtremePoints.Add(pos)) { 509 489 var rs = CalculateResidualSpace(new Vector3D(pos)); 510 490 ResidualSpace.Add(pos, rs); 511 // Check if existing extreme points are shadowed by the new point512 // Th atis, their residual space fit entirely into the residual space of the new point491 // Check if the existing extreme points are shadowed by the new point 492 // This is, their residual space fit entirely into the residual space of the new point 513 493 foreach (var ep in ExtremePoints.Where(x => x != pos && new Vector3D(x).IsInside(pos, rs)).ToList()) { 514 494 if (IsWithinResidualSpaceOfAnotherExtremePoint(new Vector3D(ep), ResidualSpace[ep], pos, rs)) { … … 521 501 return false; 522 502 } 523 524 private Tuple<int, int, int> CalculateResidualSpace1(Vector3D pos) { 525 var itemPos = Items.Select(x => new { Item = x.Value, Position = Positions[x.Key] }); 526 var rightLimit = ProjectRight(pos); 527 var upLimit = ProjectUp(pos); 528 var forwardLimit = ProjectForward(pos); 529 return Tuple.Create(rightLimit.X - pos.X, upLimit.Y - pos.Y, forwardLimit.Z - pos.Z); 530 } 531 503 532 504 #region Projections 533 505 … … 719 691 720 692 693 /// <summary> 694 /// Updates the resiual space for a packing item. 695 /// </summary> 696 /// <param name="item"></param> 697 /// <param name="pos"></param> 721 698 public void UpdateResidualSpace(PackingItem item, PackingPosition pos) { 722 699 foreach (var ep in ExtremePoints.ToList()) {
Note: See TracChangeset
for help on using the changeset viewer.