Changeset 9598 for branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans
- Timestamp:
- 06/07/13 15:35:12 (12 years ago)
- Location:
- branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking.cs
r9596 r9598 105 105 } 106 106 107 108 public int PointOccupation(D position) { 109 foreach (var ipEntry in ItemPositions) { 110 if (ItemMeasures[ipEntry.Key].EnclosesPoint(ipEntry.Value, position)) 111 return ipEntry.Key; 112 } 113 return -1; 114 } 107 115 public bool IsPointOccupied(D position) { 108 116 foreach (var ipEntry in ItemPositions) { … … 110 118 return true; 111 119 } 112 113 120 return false; 114 121 } 115 122 public bool IsPositionFeasible(I currentItem, D position) { 116 //In this case feasability is defined as following: 1. the item fits into the bin-borders; 2. the item does not collide with another already packed item123 //In this case feasability is defined as following: 1. the item fits into the bin-borders; 2. the point is supported by something; 3. the item does not collide with another already packed item 117 124 if (!BinMeasures.Encloses(position, currentItem)) 118 125 return false; … … 127 134 public abstract int ShortestPossibleSideFromPoint (D position); 128 135 public abstract bool IsStaticStable (I item, D position); 129 130 //public bool IsPositionFeasible1(I currentItem, D position) {131 // if (!BinMeasures.Encloses(position, currentItem))132 // return false;133 134 // return OccupiedPoints.IsPositionFeasible (currentItem, position);135 //}136 136 } 137 137 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking2D.cs
r9596 r9598 62 62 if (sourcePointX.X < BinMeasures.Width && sourcePointX.Y < BinMeasures.Height) { 63 63 //Traversing down the y-axis 64 while (sourcePointX.Y > 0 && !IsPointOccupied(new TwoDimensionalPacking(0, sourcePointX.X, sourcePointX.Y - 1))) {64 while (sourcePointX.Y > 0 && (-1).Equals(IsPointOccupied(new TwoDimensionalPacking(0, sourcePointX.X, sourcePointX.Y - 1)))) { 65 65 sourcePointX.Y--; 66 66 } … … 75 75 if (sourcePointY.X < BinMeasures.Width && sourcePointY.Y < BinMeasures.Height) { 76 76 //Traversing down the x-axis 77 while (sourcePointY.X > 0 && !IsPointOccupied(new TwoDimensionalPacking (0,sourcePointY.X - 1, sourcePointY.Y))) {77 while (sourcePointY.X > 0 && (-1).Equals(IsPointOccupied(new TwoDimensionalPacking (0,sourcePointY.X - 1, sourcePointY.Y)))) { 78 78 sourcePointY.X--; 79 79 } … … 166 166 } 167 167 168 169 168 public override int ShortestPossibleSideFromPoint(TwoDimensionalPacking position) { 170 169 int shortestSide = int.MaxValue; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking3D.cs
r9596 r9598 61 61 var sourcePointX = new ThreeDimensionalPacking(0, position.X + newWidth, position.Y, position.Z); 62 62 if (sourcePointX.X < BinMeasures.Width && sourcePointX.Y < BinMeasures.Height && sourcePointX.Z < BinMeasures.Depth) { 63 //Traversing down the y-axis 64 int currentYValue = sourcePointX.Y; 65 while (currentYValue > 0 && !IsPointOccupied(new ThreeDimensionalPacking (0, sourcePointX.X, currentYValue, sourcePointX.Z))) { 66 currentYValue--; 67 } 68 ExtremePoints.Add(new ThreeDimensionalPacking(0, sourcePointX.X, currentYValue, sourcePointX.Z)); 69 70 //Traversing down the z-axis 71 int currentZValue = sourcePointX.Z; 72 while (currentZValue > 0 && !IsPointOccupied(new ThreeDimensionalPacking (0, sourcePointX.X, sourcePointX.Y, currentZValue - 1))) { 73 currentZValue--; 74 } 75 ExtremePoints.Add(new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, currentZValue)); 63 //Traversing down the y-axis 64 ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z); 65 while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown (current))) { 66 current = ThreeDimensionalPacking.MoveDown(current); 67 } 68 ExtremePoints.Add((ThreeDimensionalPacking)current.Clone()); 69 while (current.X > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) { 70 current = ThreeDimensionalPacking.MoveLeft(current); 71 } 72 ExtremePoints.Add(current); 73 74 //Traversing down the z-axis 75 current = new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z); 76 while (current.Z > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveBack (current))) { 77 current = ThreeDimensionalPacking.MoveBack(current); 78 } 79 ExtremePoints.Add((ThreeDimensionalPacking)current.Clone()); 80 while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) { 81 current = ThreeDimensionalPacking.MoveDown(current); 82 } 83 ExtremePoints.Add(current); 76 84 } 77 85 … … 82 90 var sourcePointY = new ThreeDimensionalPacking(0, position.X, position.Y + newItem.Height, position.Z); 83 91 if (sourcePointY.X < BinMeasures.Width && sourcePointY.Y < BinMeasures.Height && sourcePointY.Z < BinMeasures.Depth) { 84 //Traversing down the x-axis 85 int currentXValue = sourcePointY.X; 86 while (currentXValue > 0 && !IsPointOccupied(new ThreeDimensionalPacking (0, currentXValue - 1, sourcePointY.Y, sourcePointY.Z))) { 87 currentXValue--; 88 } 89 ExtremePoints.Add(new ThreeDimensionalPacking(0, currentXValue, sourcePointY.Y, sourcePointY.Z)); 90 91 //Traversing down the z-axis 92 int currentZValue = sourcePointY.Z; 93 while (currentZValue > 0 && !IsPointOccupied(new ThreeDimensionalPacking (0, sourcePointY.X, sourcePointY.Y, currentZValue - 1))) { 94 currentZValue--; 95 } 96 ExtremePoints.Add(new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, currentZValue)); 92 //Traversing down the x-axis 93 ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z); 94 while (current.X > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) { 95 current = ThreeDimensionalPacking.MoveLeft(current); 96 } 97 ExtremePoints.Add((ThreeDimensionalPacking)current.Clone()); 98 while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) { 99 current = ThreeDimensionalPacking.MoveDown(current); 100 } 101 ExtremePoints.Add(current); 102 103 //Traversing down the z-axis 104 current = new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z); 105 while (current.Z > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveBack(current))) { 106 current = ThreeDimensionalPacking.MoveBack(current); 107 } 108 ExtremePoints.Add((ThreeDimensionalPacking)current.Clone()); 109 while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) { 110 current = ThreeDimensionalPacking.MoveDown(current); 111 } 112 ExtremePoints.Add(current); 97 113 } 98 114 … … 104 120 var sourcePointZ = new ThreeDimensionalPacking(0, position.X, position.Y, position.Z + newDepth); 105 121 if (sourcePointZ.X < BinMeasures.Width && sourcePointZ.Y < BinMeasures.Height && sourcePointZ.Z < BinMeasures.Depth) { 106 //Traversing down the x-axis 107 int currentXValue = sourcePointZ.X; 108 while (currentXValue > 0 && !IsPointOccupied(new ThreeDimensionalPacking (0, currentXValue - 1, sourcePointZ.Y, sourcePointZ.Z))) { 109 currentXValue--; 110 } 111 ExtremePoints.Add(new ThreeDimensionalPacking(0, currentXValue, sourcePointZ.Y, sourcePointZ.Z)); 112 113 //Traversing down the y-axis 114 int currentYValue = sourcePointZ.Y; 115 while (currentYValue > 0 && !IsPointOccupied(new ThreeDimensionalPacking (0, sourcePointZ.X, currentYValue, sourcePointZ.Z))) { 116 currentYValue--; 117 } 118 ExtremePoints.Add(new ThreeDimensionalPacking(0, sourcePointZ.X, currentYValue, sourcePointZ.Z)); 122 //Traversing down the x-axis 123 ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z); 124 while (current.X > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) { 125 current = ThreeDimensionalPacking.MoveLeft(current); 126 } 127 ExtremePoints.Add((ThreeDimensionalPacking)current.Clone()); 128 while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) { 129 current = ThreeDimensionalPacking.MoveDown(current); 130 } 131 ExtremePoints.Add(current); 132 133 //Traversing down the y-axis 134 current = new ThreeDimensionalPacking(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z); 135 while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) { 136 current = ThreeDimensionalPacking.MoveDown(current); 137 } 138 ExtremePoints.Add((ThreeDimensionalPacking)current.Clone()); 139 while (current.X > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) { 140 current = ThreeDimensionalPacking.MoveLeft(current); 141 } 142 ExtremePoints.Add(current); 119 143 } 120 144 … … 122 146 OrderBy(ep => ep.Z). 123 147 ThenBy(ep => ep.X). 124 ThenBy(ep => ep.Y) .125 ThenBy(ep => ShortestPossibleSideFromPoint(ep)));148 ThenBy(ep => ep.Y)//.ThenBy(ep => ShortestPossibleSideFromPoint(ep)) 149 ); 126 150 } 127 151 … … 136 160 int epIndex = 0; 137 161 while (epIndex < ExtremePoints.Count && ( 138 !IsPositionFeasible(item, ExtremePoints.ElementAt(epIndex)) || (stackingConstraints && !IsStaticStable(item, ExtremePoints.ElementAt(epIndex))) 162 !IsPositionFeasible(item, ExtremePoints.ElementAt(epIndex)) 163 || !IsSupportedByAtLeastOnePoint(item, ExtremePoints.ElementAt(epIndex)) 164 || (stackingConstraints && !IsStaticStable(item, ExtremePoints.ElementAt(epIndex))) 165 || (stackingConstraints && !IsWeightSupported(item, ExtremePoints.ElementAt(epIndex))) 139 166 )) { epIndex++; } 140 167 … … 146 173 return null; 147 174 } 175 148 176 public override ThreeDimensionalPacking FindPositionBySliding(CuboidPackingItem measures, bool rotated) { 149 177 //Starting-position at upper right corner (=left bottom point of item-rectangle is at position item.width,item.height) … … 217 245 } 218 246 } 219 220 221 [Storable] 222 private bool depthWasDoubled = false; 223 public void DoubleDepth() { 224 if (!depthWasDoubled) { 225 var oldDepth = BinMeasures.Depth; 226 BinMeasures.Depth = BinMeasures.Depth * 2; 227 //OccupiedPoints.ChangeBinMeasures(BinMeasures); 228 depthWasDoubled = true; 229 } 230 } 231 247 232 248 public override int ShortestPossibleSideFromPoint(ThreeDimensionalPacking position) { 233 249 … … 265 281 266 282 if (IsPointOccupied (new ThreeDimensionalPacking (0, position.X, position.Y - 1, position.Z)) 267 && IsPointOccupied (new ThreeDimensionalPacking (0, position.X + item.Width - 1, position.Y - 1, position.Z))268 && IsPointOccupied (new ThreeDimensionalPacking (0, position.X, position.Y - 1, position.Z + item.Depth - 1))269 && IsPointOccupied (new ThreeDimensionalPacking (0, position.X + item.Width - 1, position.Y - 1, position.Z + item.Depth - 1)))283 && IsPointOccupied (new ThreeDimensionalPacking (0, position.X + item.Width, position.Y - 1, position.Z)) 284 && IsPointOccupied (new ThreeDimensionalPacking (0, position.X, position.Y - 1, position.Z + item.Depth)) 285 && IsPointOccupied (new ThreeDimensionalPacking (0, position.X + item.Width, position.Y - 1, position.Z + item.Depth))) 270 286 return true; 271 287 … … 290 306 return false; 291 307 } 308 309 310 [Storable] 311 private bool depthWasDoubled = false; 312 public void DoubleDepth() { 313 if (!depthWasDoubled) { 314 var oldDepth = BinMeasures.Depth; 315 BinMeasures.Depth = BinMeasures.Depth * 2; 316 //OccupiedPoints.ChangeBinMeasures(BinMeasures); 317 depthWasDoubled = true; 318 } 319 } 320 321 public bool IsSupportedByAtLeastOnePoint(CuboidPackingItem item, ThreeDimensionalPacking position) { 322 if (position.Y == 0) 323 return true; 324 325 int y = position.Y - 1; 326 for (int x = position.X; x < position.X + item.Width; x++) 327 for (int z = position.Z; z < position.Z + item.Depth; z++) 328 if (IsPointOccupied(new ThreeDimensionalPacking(0, x, y, z))) 329 return true; 330 331 return false; 332 } 333 public bool IsWeightSupported(CuboidPackingItem item, ThreeDimensionalPacking ep) { 334 if (ep.Y == 0) 335 return true; 336 337 if (ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X, ep.Y - 1, ep.Z))].SupportsStacking(item) 338 && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X + item.Width, ep.Y - 1, ep.Z))].SupportsStacking(item) 339 && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X, ep.Y - 1, ep.Z + item.Depth))].SupportsStacking(item) 340 && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X + item.Width, ep.Y - 1, ep.Z + item.Depth))].SupportsStacking(item)) 341 return true; 342 343 return false; 344 } 292 345 } 293 346 }
Note: See TracChangeset
for help on using the changeset viewer.