- Timestamp:
- 08/04/17 23:45:08 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/BinPacking3D.cs
r15306 r15307 125 125 sourcePoint = new Vector3D(position.X, position.Y, position.Z + newDepth); 126 126 if (sourcePoint.X < BinShape.Width && sourcePoint.Y < BinShape.Height && sourcePoint.Z < BinShape.Depth) { 127 // Projecting onto the XZ-plane 128 var below = ProjectDown(sourcePoint); 129 var residualSpace = CalculateResidualSpace(below); 130 if (!IsWithinResidualSpaceOfAnotherExtremePoint(below, residualSpace)) { 131 // add only if the projected point's residual space is not a sub-space 132 // of another extreme point's residual space 133 var belowPoint = new PackingPosition(position.AssignedBin, below.X, below.Y, below.Z); 134 AddExtremePoint(belowPoint); 135 } 127 136 // Projecting onto the YZ-plane 128 137 var left = ProjectLeft(sourcePoint); 129 varresidualSpace = CalculateResidualSpace(left);138 residualSpace = CalculateResidualSpace(left); 130 139 if (!IsWithinResidualSpaceOfAnotherExtremePoint(left, residualSpace)) { 131 140 // add only if the projected point's residual space is not a sub-space … … 134 143 AddExtremePoint(leftPoint); 135 144 } 136 // Projecting onto the XZ-plane137 var below = ProjectDown(sourcePoint);138 residualSpace = CalculateResidualSpace(below);139 if (!IsWithinResidualSpaceOfAnotherExtremePoint(below, residualSpace)) {140 // add only if the projected point's residual space is not a sub-space141 // of another extreme point's residual space142 var belowPoint = new PackingPosition(position.AssignedBin, below.X, below.Y, below.Z);143 AddExtremePoint(belowPoint);144 }145 145 } 146 146 } … … 148 148 private bool IsWithinResidualSpaceOfAnotherExtremePoint(Vector3D pos, Tuple<int, int, int> residualSpace) { 149 149 var eps = ExtremePoints.Where(x => pos.IsInside(x, ResidualSpace[x])); 150 return eps.Any(x => ResidualSpace[x].Item1 >= pos.X - x.X + residualSpace.Item1 151 && ResidualSpace[x].Item2 >= pos.Y - x.Y + residualSpace.Item2 152 && ResidualSpace[x].Item3 >= pos.Z - x.Z + residualSpace.Item3); 150 return eps.Any(x => IsWithinResidualSpaceOfAnotherExtremePoint(pos, residualSpace, x, ResidualSpace[x])); 151 } 152 private bool IsWithinResidualSpaceOfAnotherExtremePoint(Vector3D pos, Tuple<int, int, int> rsPos, PackingPosition ep, Tuple<int, int, int> rsEp) { 153 return rsEp.Item1 >= pos.X - ep.X + rsPos.Item1 154 && rsEp.Item2 >= pos.Y - ep.Y + rsPos.Item2 155 && rsEp.Item3 >= pos.Z - ep.Z + rsPos.Item3; 153 156 } 154 157 155 158 private bool AddExtremePoint(PackingPosition pos) { 156 159 if (ExtremePoints.Add(pos)) { 157 ResidualSpace.Add(pos, Tuple.Create(BinShape.Width - pos.X, BinShape.Height - pos.Y, BinShape.Depth - pos.Z)); 160 var rs = Tuple.Create(BinShape.Width - pos.X, BinShape.Height - pos.Y, BinShape.Depth - pos.Z); 161 ResidualSpace.Add(pos, rs); 162 // Check if existing extreme points are shadowed by the new point 163 // That is, their residual space fit entirely into the residual space of the new point 164 foreach (var ep in ExtremePoints.Where(x => x != pos && new Vector3D(x).IsInside(pos, rs)).ToList()) { 165 if (IsWithinResidualSpaceOfAnotherExtremePoint(new Vector3D(ep), ResidualSpace[ep], pos, rs)) { 166 ExtremePoints.Remove(ep); 167 ResidualSpace.Remove(ep); 168 } 169 } 158 170 return true; 159 171 }
Note: See TracChangeset
for help on using the changeset viewer.