Changeset 15520 for branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointCreation/PointProjectionBasedEPCreator.cs
- Timestamp:
- 12/13/17 09:47:49 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointCreation/PointProjectionBasedEPCreator.cs
r15488 r15520 15 15 /// </summary> 16 16 public class PointProjectionBasedEPCreator : ExtremePointCreator { 17 p ublicoverride void UpdateExtremePoints(BinPacking3D binPacking, PackingItem item, PackingPosition position) {18 GenerateNewExtremePointsFor NewItem(binPacking, item, position);17 protected override void UpdateExtremePoints(BinPacking3D binPacking, PackingItem item, PackingPosition position) { 18 GenerateNewExtremePointsForItem(binPacking, item, position); 19 19 20 20 // if an item is fit in below, before, or left of another its extreme points have to be regenerated 21 21 foreach (var above in GetItemsAbove(binPacking, position)) { 22 GenerateNewExtremePointsFor NewItem(binPacking, above.Item2, above.Item1);22 GenerateNewExtremePointsForItem(binPacking, above.Item2, above.Item1); 23 23 } 24 24 foreach (var front in GetItemsInfront(binPacking, position)) { 25 GenerateNewExtremePointsFor NewItem(binPacking, front.Item2, front.Item1);25 GenerateNewExtremePointsForItem(binPacking, front.Item2, front.Item1); 26 26 } 27 27 foreach (var right in GetItemsOnRight(binPacking, position)) { 28 GenerateNewExtremePointsFor NewItem(binPacking, right.Item2, right.Item1);28 GenerateNewExtremePointsForItem(binPacking, right.Item2, right.Item1); 29 29 } 30 30 } 31 31 32 p ublicoverride void UpdateResidualSpace(BinPacking3D binPacking, PackingItem item, PackingPosition position) {32 protected override void UpdateResidualSpace(BinPacking3D binPacking, PackingItem item, PackingPosition position) { 33 33 foreach (var ep in binPacking.ExtremePoints.ToList()) { 34 var rs = binPacking.ResidualSpace [ep];34 var rs = binPacking.ResidualSpaces[ep]; 35 35 var depth = position.Rotated ? item.Width : item.Depth; 36 36 var width = position.Rotated ? item.Depth : item.Width; … … 39 39 if (ep.X <= position.X && ep.Y >= position.Y && ep.Y < position.Y + item.Height) { 40 40 var diff = position.X - ep.X; 41 var newRSX = Math.Min(rs. Item1, diff);42 rs = Tuple.Create(newRSX, rs.Item2, rs.Item3);41 var newRSX = Math.Min(rs.Width, diff); 42 rs = ResidualSpace.Create(newRSX, rs.Height, rs.Depth); 43 43 changed = true; 44 44 } 45 45 if (ep.Y <= position.Y && ep.X >= position.X && ep.X < position.X + width) { 46 46 var diff = position.Y - ep.Y; 47 var newRSY = Math.Min(rs. Item2, diff);48 rs = Tuple.Create(rs.Item1, newRSY, rs.Item3);47 var newRSY = Math.Min(rs.Height, diff); 48 rs = ResidualSpace.Create(rs.Width, newRSY, rs.Depth); 49 49 changed = true; 50 50 } … … 55 55 ep.X >= position.X && ep.X < position.X + width) { 56 56 var diff = position.Z - ep.Z; 57 var newRSZ = Math.Min(rs. Item3, diff);58 rs = Tuple.Create(rs.Item1, rs.Item2, newRSZ);57 var newRSZ = Math.Min(rs.Depth, diff); 58 rs = ResidualSpace.Create(rs.Width, rs.Height, newRSZ); 59 59 changed = true; 60 60 } 61 61 62 62 if (changed) { 63 if ( IsNonZero(rs) && !IsWithinResidualSpaceOfAnotherExtremePoint(binPacking, new Vector3D(ep), rs)) {64 binPacking.ResidualSpace [ep] = rs;63 if (!rs.IsZero() && !IsWithinResidualSpaceOfAnotherExtremePoint(binPacking, new Vector3D(ep), rs)) { 64 binPacking.ResidualSpaces[ep] = rs; 65 65 } else { 66 66 binPacking.ExtremePoints.Remove(ep); 67 binPacking.ResidualSpace .Remove(ep);67 binPacking.ResidualSpaces.Remove(ep); 68 68 } 69 69 } … … 83 83 if (binPacking.ExtremePoints.Add(position)) { 84 84 var rs = CalculateResidualSpace(binPacking, new Vector3D(position)); 85 binPacking.ResidualSpace .Add(position, rs);85 binPacking.ResidualSpaces.Add(position, rs); 86 86 // Check if the existing extreme points are shadowed by the new point 87 87 // This is, their residual space fit entirely into the residual space of the new point 88 88 foreach (var ep in binPacking.ExtremePoints.Where(x => x != position && new Vector3D(x).IsInside(position, rs)).ToList()) { 89 if (IsWithinResidualSpaceOfAnotherExtremePoint(new Vector3D(ep), binPacking.ResidualSpace [ep], position, rs)) {89 if (IsWithinResidualSpaceOfAnotherExtremePoint(new Vector3D(ep), binPacking.ResidualSpaces[ep], position, rs)) { 90 90 binPacking.ExtremePoints.Remove(ep); 91 binPacking.ResidualSpace .Remove(ep);91 binPacking.ResidualSpaces.Remove(ep); 92 92 } 93 93 }
Note: See TracChangeset
for help on using the changeset viewer.