Changeset 9495 for branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP
- Timestamp:
- 05/15/13 22:23:36 (12 years ago)
- Location:
- branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ExtremePointGroupingVectorDecoder3D.cs
r9440 r9495 41 41 [Item("Identical bin, three dimensional, extreme points based decoder for the GroupingVector encoding.", "<Description missing...>")] 42 42 [StorableClass] 43 public class ExtremePointGroupingVectorDecoder3D : IdenticalBinPackingSolutionDecoder<43 public class ExtremePointGroupingVectorDecoder3D : PackingSolutionDecoder< 44 44 ThreeDimensionalPacking, 45 45 CuboidPackingBin, 46 CuboidPackingItem, 47 PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> { 46 CuboidPackingItem> { 48 47 49 48 public ExtremePointGroupingVectorDecoder3D () … … 68 67 } 69 68 70 p rotected override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {69 public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) { 71 70 72 71 var solution = encodedSolution as GroupingVectorEncoding; 73 72 if (solution == null) throw new InvalidOperationException("Encoding is not of type GroupingVector"); 74 73 75 return Decode(solution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);74 return Decode(solution, binMeasures, itemMeasures); 76 75 } 77 76 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ExtremePointMultiComponentVectorDecoder3D.cs
r9440 r9495 42 42 [Item("Identical bin, three dimensional, extreme points based decoder for the MultiComponentVector encoding.", "<Description missing...>")] 43 43 [StorableClass] 44 public class ExtremePointMultiComponentVectorDecoder3D : IdenticalBinPackingSolutionDecoder<44 public class ExtremePointMultiComponentVectorDecoder3D : PackingSolutionDecoder< 45 45 ThreeDimensionalPacking, 46 46 CuboidPackingBin, 47 CuboidPackingItem, 48 PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> { 47 CuboidPackingItem> { 49 48 50 49 public ExtremePointMultiComponentVectorDecoder3D () … … 69 68 } 70 69 71 p rotected override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {70 public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) { 72 71 73 72 var solution = encodedSolution as MultiComponentVectorEncoding; 74 73 if (solution == null) throw new InvalidOperationException("Encoding is not of type MultiComponentVector"); 75 74 76 return Decode(solution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);75 return Decode(solution, binMeasures, itemMeasures); 77 76 } 78 77 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ExtremePointPackingSequenceDecoder3D.cs
r9440 r9495 40 40 [Item("Identical bin, three dimensional, extreme points based decoder for the PackingSequence encoding.", "<Description missing...>")] 41 41 [StorableClass] 42 public class ExtremePointPackingSequenceDecoder3D : IdenticalBinPackingSolutionDecoder<42 public class ExtremePointPackingSequenceDecoder3D : PackingSolutionDecoder< 43 43 ThreeDimensionalPacking, 44 44 CuboidPackingBin, 45 CuboidPackingItem, 46 PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> { 45 CuboidPackingItem> { 47 46 48 47 public ExtremePointPackingSequenceDecoder3D () … … 59 58 60 59 61 p rotected override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {60 public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) { 62 61 63 62 var solution = encodedSolution as PackingSequenceEncoding; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ExtremePointsFunctions3D.cs
r9473 r9495 9 9 using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; 10 10 using HeuristicLab.Encodings.PackingEncoding.PackingSequence; 11 using HeuristicLab.Encodings.PackingEncoding.Potvin;12 11 using HeuristicLab.Problems.BinPacking.Dimensions; 13 12 using HeuristicLab.Problems.BinPacking.Interfaces; … … 20 19 21 20 22 23 public static ObservableDictionary<int, ThreeDimensionalPacking> ExtremePointBasedPacking(ref PotvinEncoding solution,24 ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures) {25 if (!solution.DelimiterInitialized) {26 #region Preperations27 var itemPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();28 int nrOfBins = 1;29 30 var occupiedPoints = new List<int[, ,]>();31 occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures);32 33 HashSet<ThreeDimensionalPacking> extremePoints = new HashSet<ThreeDimensionalPacking>();34 extremePoints.Add(new ThreeDimensionalPacking(0, 0, 0, 0, false));35 #endregion36 37 Dictionary<int, List<int>> itemIndexesForBin = new Dictionary<int, List<int>>();38 itemIndexesForBin[0] = new List<int>();39 40 foreach (int itemIndex in solution.IntVector) {41 var item = itemMeasures[itemIndex];42 extremePoints = OrderExtremePoints(extremePoints, occupiedPoints, binMeasures);43 var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePoints, occupiedPoints, itemPositions);44 if (positionFound != null) {45 extremePoints.Remove(positionFound);46 } else {47 positionFound = new ThreeDimensionalPacking(nrOfBins, 0, 0, 0);48 occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures);49 itemIndexesForBin[nrOfBins] = new List<int>();50 nrOfBins++;51 }52 itemPositions[itemIndex] = positionFound;53 itemIndexesForBin[positionFound.AssignedBin].Add(itemIndex);54 occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex);55 extremePoints = GenerateNewExtremePointsForNewItem(extremePoints, occupiedPoints, item, positionFound, binMeasures);56 }57 List<int> intVector = new List<int>();58 foreach (var indexes in itemIndexesForBin) {59 foreach (var index in indexes.Value) {60 intVector.Add(index);61 }62 intVector.Add(-1);63 }64 intVector.RemoveAt(intVector.Count - 1);65 solution.IntVector = new IntegerVector (intVector.ToArray());66 67 return itemPositions;68 } else {69 #region Preperations70 int nrOfBins = solution.IntVector.Count(i => i.Equals (-1)) + 1;71 72 //Get all indexes of items for every bin according to int vector73 Dictionary<int, List<int>> unpackedItemIndexesPerBin = new Dictionary<int, List<int>>();74 Dictionary<int, HashSet<ThreeDimensionalPacking>> extremePointsForBin = new Dictionary<int, HashSet<ThreeDimensionalPacking>>();75 var occupiedPoints = new List<int[, ,]>();76 77 int binCounter = 0;78 unpackedItemIndexesPerBin[binCounter] = new List<int>();79 for (int i = 0; i < solution.IntVector.Length; i++) {80 if (solution.IntVector[i].Equals(-1)) {81 unpackedItemIndexesPerBin[binCounter++] = new List<int>();82 extremePointsForBin[i] = new HashSet<ThreeDimensionalPacking>();83 extremePointsForBin[i].Add(new ThreeDimensionalPacking(i, 0, 0, 0, false));84 occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures);85 } else {86 unpackedItemIndexesPerBin[binCounter].Add(solution.IntVector[i]);87 }88 89 }90 91 92 ObservableDictionary<int, ThreeDimensionalPacking> itemPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();93 var remainingItems = new List<int>();94 95 #endregion Preperations96 97 98 99 //Iterate over all bin-lists100 for (int binNr = 0; binNr < nrOfBins; binNr++) {101 //Iterate over the current bin-item-list and find feasible positions in the current bin for each item102 var unpackedItems = unpackedItemIndexesPerBin[binNr];103 for (int i = 0; i < unpackedItems.Count; i++) {104 var itemIndex = unpackedItems[i];105 var item = itemMeasures[itemIndex];106 107 extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);108 var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions);109 if (positionFound != null) {110 extremePointsForBin[binNr].Remove(positionFound);111 itemPositions[itemIndex] = positionFound;112 occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex);113 extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures);114 } else115 remainingItems.Add(itemIndex);116 }117 }118 119 120 121 //Packing of remaining items122 //Iterate over all bin-lists123 for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) {124 var unpackedItems = new List<int>(remainingItems);125 //Iterate over all the remaining items126 for (int i = 0; i < unpackedItems.Count; i++) {127 var itemIndex = unpackedItems[i];128 var item = itemMeasures[itemIndex];129 130 extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);131 var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions);132 if (positionFound != null) {133 extremePointsForBin[binNr].Remove(positionFound);134 InsertItemgeneAfterLastItemgeneOfUsedBin(ref solution, itemIndex, binNr);135 itemPositions[itemIndex] = positionFound;136 occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex);137 extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures);138 remainingItems.Remove(itemIndex);139 }140 }141 if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) {142 extremePointsForBin[nrOfBins] = new HashSet<ThreeDimensionalPacking>();143 extremePointsForBin[nrOfBins].Add(new ThreeDimensionalPacking(nrOfBins, 0, 0, 0, false));144 occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures);145 nrOfBins++;146 }147 }148 149 return itemPositions;150 }151 }152 private static void InsertItemgeneAfterLastItemgeneOfUsedBin(ref PotvinEncoding solution, int itemIndex, int binNr) {153 List<int> temp = new List<int> (solution.IntVector);154 temp.Remove(itemIndex);155 var delimiterIndexes = temp.Select((value, index) => value == -1).Select((value, index) => index);156 int insertionIndex = temp.Count;157 if (binNr < delimiterIndexes.Count()) {158 insertionIndex = delimiterIndexes.ElementAt(binNr);159 }160 temp.Insert(insertionIndex, itemIndex);161 solution.IntVector = new IntegerVector (temp.ToArray());162 }163 164 165 21 public static ObservableDictionary<int, ThreeDimensionalPacking> ExtremePointBasedPacking(ref MultiComponentVectorEncoding solution, 166 22 ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures) { 167 23 168 24 #region Preperations 169 int lowerBound = solution.PackingInformations.Max(x => x.AssignedBin); 170 int nrOfBins = lowerBound + 1; 25 int nrOfBins = solution.NrOfBins; 171 26 172 27 //Get all indexes of items for every bin according to grouping-vector … … 176 31 177 32 for (int i = 0; i < nrOfBins; i++) { 178 unpackedItemIndexesPerBin[i] = solution.PackingInformations 179 .Where(pi => pi.AssignedBin == i) 180 .ToList(); 33 unpackedItemIndexesPerBin[i] = new List<PackingInformation> (solution.PackingInformations[i]); 181 34 182 35 extremePointsForBin[i] = new HashSet<ThreeDimensionalPacking>(); … … 196 49 var unpackedItems = unpackedItemIndexesPerBin[binNr]; 197 50 for (int i = 0; i < unpackedItems.Count; i++) { 198 var itemIndex = unpackedItems[i].ItemI ndex;51 var itemIndex = unpackedItems[i].ItemID; 199 52 var item = itemMeasures[itemIndex]; 200 53 … … 206 59 occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex); 207 60 extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures); 208 } else 61 } else { 209 62 remainingItems.Add(unpackedItems[i]); 63 solution.PackingInformations[binNr].Remove(unpackedItems[i]); 64 } 210 65 } 211 66 } … … 218 73 //Iterate over all the remaining items 219 74 for (int i = 0; i < unpackedItems.Count; i++) { 220 var itemIndex = unpackedItems[i].ItemI ndex;75 var itemIndex = unpackedItems[i].ItemID; 221 76 var item = itemMeasures[itemIndex]; 222 77 … … 227 82 itemPositions[itemIndex] = positionFound; 228 83 occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex); 229 extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures); 84 extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures); 230 85 remainingItems.Remove(unpackedItems[i]); 231 if (binNr <= lowerBound) { 232 InsertItemgeneAfterLastItemgeneOfUsedBin(ref solution, itemIndex, binNr); 233 } 86 solution.PackingInformations[binNr].Add(unpackedItems[i]); 234 87 } 235 88 } … … 238 91 extremePointsForBin[nrOfBins].Add(new ThreeDimensionalPacking(nrOfBins, 0, 0, 0, false)); 239 92 occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures); 93 solution.PackingInformations[nrOfBins] = new ItemList<PackingInformation>(); 240 94 nrOfBins++; 241 95 } … … 243 97 244 98 return itemPositions; 245 }246 private static void InsertItemgeneAfterLastItemgeneOfUsedBin(ref MultiComponentVectorEncoding solution, int itemIndex, int binNr) {247 var itemgene = solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex);248 solution.PackingInformations.Remove (itemgene);249 itemgene.AssignedBin = binNr;250 int targetIndex = solution.PackingInformations.FindLastIndex(pi => pi.AssignedBin == binNr);251 solution.PackingInformations.Insert(targetIndex + 1, itemgene);252 99 } 253 100 … … 370 217 371 218 372 p rivatestatic ThreeDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures,219 public static ThreeDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures, 373 220 HashSet<ThreeDimensionalPacking> extremePoints, List<int[, ,]> occupiedPoints, ObservableDictionary<int, ThreeDimensionalPacking> itemPositions) { 374 221 return FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePoints, occupiedPoints, itemPositions, false); 375 222 } 376 p rivatestatic ThreeDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures,223 public static ThreeDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures, 377 224 HashSet<ThreeDimensionalPacking> extremePoints, List<int[,,]> occupiedPoints, ObservableDictionary<int, ThreeDimensionalPacking> itemPositions, bool rotated) { 378 225 … … 397 244 return null; 398 245 } 399 p rivatestatic List<int[, ,]> IncreaseBinCountForOccupiedPoints(List<int[, ,]> occupiedPoints, CuboidPackingBin binMeasures) {246 public static List<int[, ,]> IncreaseBinCountForOccupiedPoints(List<int[, ,]> occupiedPoints, CuboidPackingBin binMeasures) { 400 247 occupiedPoints.Add(new int[binMeasures.Width, binMeasures.Height, binMeasures.Depth]); 401 248 int lastIndex = occupiedPoints.Count - 1; … … 409 256 return occupiedPoints; 410 257 } 411 p rivatestatic bool IsStaticStable(int[, ,] occupiedPoints, CuboidPackingItem item, ThreeDimensionalPacking ep) {258 public static bool IsStaticStable(int[, ,] occupiedPoints, CuboidPackingItem item, ThreeDimensionalPacking ep) { 412 259 //Static stability is given, if item is placed on the ground 413 260 if (ep.Y == 0) … … 433 280 return false; 434 281 } 435 p rivatestatic List<int[, ,]> OccupyPointsForNewItem(List<int[, ,]> occupiedPoints, CuboidPackingItem newItem, ThreeDimensionalPacking position, int itemIndex) {282 public static List<int[, ,]> OccupyPointsForNewItem(List<int[, ,]> occupiedPoints, CuboidPackingItem newItem, ThreeDimensionalPacking position, int itemIndex) { 436 283 int width = position.Rotated ? newItem.Depth : newItem.Width; 437 284 int depth = position.Rotated ? newItem.Width : newItem.Depth; … … 445 292 return occupiedPoints; 446 293 } 447 p rivatestatic HashSet<ThreeDimensionalPacking> GenerateNewExtremePointsForNewItem(HashSet<ThreeDimensionalPacking> extremePoints, List<int[, ,]> occupiedPoints,294 public static HashSet<ThreeDimensionalPacking> GenerateNewExtremePointsForNewItem(HashSet<ThreeDimensionalPacking> extremePoints, List<int[, ,]> occupiedPoints, 448 295 CuboidPackingItem newItem, ThreeDimensionalPacking position, CuboidPackingBin binMeasures) { 449 296 int currentBin = position.AssignedBin; … … 518 365 519 366 520 p rivatestatic HashSet<ThreeDimensionalPacking> OrderExtremePoints(HashSet<ThreeDimensionalPacking> hashSet, List<int[, ,]> occupiedPoints, CuboidPackingBin binMeasures) {367 public static HashSet<ThreeDimensionalPacking> OrderExtremePoints(HashSet<ThreeDimensionalPacking> hashSet, List<int[, ,]> occupiedPoints, CuboidPackingBin binMeasures) { 521 368 return new HashSet<ThreeDimensionalPacking>(hashSet.OrderBy(ep => ep.AssignedBin).ThenBy(ep => ep.Z).ThenBy(ep => ep.X).ThenBy(ep => ep.Y).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures))); 522 369 } 523 p rivatestatic int ShortestPossibleSideFromEP(ThreeDimensionalPacking ep, List<int[, ,]> occupiedPoints, CuboidPackingBin binMeasures) {370 public static int ShortestPossibleSideFromEP(ThreeDimensionalPacking ep, List<int[, ,]> occupiedPoints, CuboidPackingBin binMeasures) { 524 371 int shortestSide = int.MaxValue; 525 372
Note: See TracChangeset
for help on using the changeset viewer.