Changeset 15229 for branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/2D/BinPacking2D.cs
- Timestamp:
- 07/13/17 15:22:59 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/2D/BinPacking2D.cs
r15182 r15229 88 88 }; 89 89 90 int epIndex = 0; 91 while (epIndex < ExtremePoints.Count && (!IsPositionFeasible(rotatedItem, ExtremePoints.ElementAt(epIndex)))) { epIndex++; } 92 93 if (epIndex < ExtremePoints.Count) { 94 var currentPoint = ExtremePoints.ElementAt(epIndex); 95 96 var result = new PackingPosition(currentPoint.AssignedBin, currentPoint.X, currentPoint.Y, rotated); 90 var ep = ExtremePoints.Where(x => IsPositionFeasible(rotatedItem, x, stackingConstraints)).FirstOrDefault(); 91 if (ep != null) { 92 var result = new PackingPosition(ep.AssignedBin, ep.X, ep.Y, rotated); 97 93 return result; 98 94 } 99 95 return null; 100 96 } 101 public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated ) {97 public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated, bool stackingConstraints) { 102 98 PackingPosition currentPosition = new PackingPosition(0, 103 99 BinShape.Width - (rotated ? item.Height : item.Width), 104 100 BinShape.Height - (rotated ? item.Width : item.Height), rotated); 105 101 //Slide the item as far as possible to the left 106 while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition) )107 || IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition) )) {102 while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition), stackingConstraints) 103 || IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition), stackingConstraints)) { 108 104 //Slide the item as far as possible to the bottom 109 while (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition) )) {105 while (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition), stackingConstraints)) { 110 106 currentPosition = PackingPosition.MoveDown(currentPosition); 111 107 } 112 if (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition) ))108 if (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition), stackingConstraints)) 113 109 currentPosition = PackingPosition.MoveLeft(currentPosition); 114 110 } 115 111 116 return IsPositionFeasible(item, currentPosition ) ? currentPosition : null;117 } 118 119 public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items ) {112 return IsPositionFeasible(item, currentPosition, stackingConstraints) ? currentPosition : null; 113 } 114 115 public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints) { 120 116 var temp = new List<int>(sequence); 121 117 for (int i = 0; i < temp.Count; i++) { 122 118 var item = items[temp[i]]; 123 var position = FindPositionBySliding(item, false );119 var position = FindPositionBySliding(item, false, stackingConstraints); 124 120 if (position != null) { 125 121 PackItem(temp[i], item, position); … … 128 124 } 129 125 } 130 public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, Dictionary<int, bool> rotationArray ) {126 public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, Dictionary<int, bool> rotationArray, bool stackingConstraints) { 131 127 var temp = new List<int>(sequence); 132 128 for (int i = 0; i < temp.Count; i++) { 133 129 var item = items[temp[i]]; 134 var position = FindPositionBySliding(item, rotationArray[temp[i]] );130 var position = FindPositionBySliding(item, rotationArray[temp[i]], stackingConstraints); 135 131 if (position != null) { 136 132 PackItem(temp[i], item, position); … … 150 146 } 151 147 } 152 public override bool ExtremePointBasedPacking(int itemID, IList<PackingItem> items, bool stackingConstraints) {153 var item = items[itemID];154 var positionFound = FindExtremePointForItem(item, false, stackingConstraints);155 if (positionFound != null) {156 PackItem(itemID, item, positionFound);157 return true;158 }159 return false;160 }161 148 162 149 public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints, Dictionary<int, bool> rotationArray) {
Note: See TracChangeset
for help on using the changeset viewer.