Changeset 9495 for branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D
- Timestamp:
- 05/15/13 22:23:36 (12 years ago)
- Location:
- branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/DBL/DeepestBottomLeftFunctions.cs
r9440 r9495 6 6 using HeuristicLab.Core; 7 7 using HeuristicLab.Encodings.PackingEncoding.GroupingVector; 8 using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; 8 9 using HeuristicLab.Encodings.PackingEncoding.PackingSequence; 9 10 using HeuristicLab.Problems.BinPacking.Dimensions; … … 16 17 public static class DeepestBottomLeftFunctions { 17 18 19 public static ObservableDictionary<int, ThreeDimensionalPacking> DeepestLeftBottomPacking(MultiComponentVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) { 20 int nrOfBins = solution.NrOfBins; 21 22 //Get all indexes of items for every bin according to grouping-vector 23 Dictionary<int, List<PackingInformation>> unpackedItemIndexesPerBin = new Dictionary<int, List<PackingInformation>>(); 24 25 for (int i = 0; i < nrOfBins; i++) { 26 unpackedItemIndexesPerBin[i] = new List<PackingInformation>(solution.PackingInformations[i]); 27 } 28 29 ObservableDictionary<int, ThreeDimensionalPacking> packingPositions = new ObservableDictionary<int, ThreeDimensionalPacking>(); 30 var remainingItems = new List<PackingInformation>(); 31 32 //Iterate over all bin-lists 33 for (int binNr = 0; binNr < nrOfBins; binNr++) { 34 //Iterate over the current bin-item-list and find feasible positions in the current bin for each item 35 var unpackedItems = unpackedItemIndexesPerBin[binNr]; 36 for (int i = 0; i < unpackedItems.Count; i++) { 37 var itemIndex = unpackedItems[i].ItemID; 38 var item = itemMeasures[itemIndex]; 39 ThreeDimensionalPacking position = null; 40 41 position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated); 42 43 if (position == null) { 44 position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated); 45 } 46 if (position == null) { 47 remainingItems.Add(unpackedItems[i]); 48 solution.PackingInformations[binNr].Remove(unpackedItems[i]); 49 } else { 50 packingPositions[itemIndex] = position; 51 solution.PackingInformations[binNr].Find(pi => pi.ItemID == itemIndex).Rotated = position.Rotated; 52 } 53 } 54 } 55 56 //Packing of remaining items 57 //Iterate over all bin-lists 58 for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) { 59 var unpackedItems = new List<PackingInformation>(remainingItems); 60 for (int i = 0; i < unpackedItems.Count; i++) { 61 var itemIndex = unpackedItems[i].ItemID; 62 var item = itemMeasures[itemIndex]; 63 ThreeDimensionalPacking position = null; 64 65 //Look for space in current bin 66 position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated); 67 68 if (position == null) { 69 position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated); 70 } 71 if (position != null) { 72 packingPositions[itemIndex] = position; 73 remainingItems.Remove(unpackedItems[i]); 74 solution.PackingInformations[binNr].Add(unpackedItems[i]); 75 solution.PackingInformations[binNr].Find(pi => pi.ItemID == itemIndex).Rotated = position.Rotated; 76 } 77 } 78 if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) { 79 solution.PackingInformations[nrOfBins] = new ItemList<PackingInformation>(); 80 nrOfBins++; 81 } 82 } 83 84 return packingPositions; 85 } 86 18 87 public static ObservableDictionary<int, ThreeDimensionalPacking> DeepestLeftBottomPacking(GroupingVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) { 19 88 int nrOfBins = solution.GroupingVector.Max() + 1; … … 77 146 } 78 147 79 148 public static ObservableDictionary<int, ThreeDimensionalPacking> DeepestLeftBottomPacking(PackingSequenceEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) { 149 ObservableDictionary<int, ThreeDimensionalPacking> packingPositions = new ObservableDictionary<int, ThreeDimensionalPacking>(); 150 int nrOfBins = 1; 151 for (int i = 0; i < solution.PackingSequence.Length; i++) { 152 var item = itemMeasures[solution.PackingSequence[i]]; 153 ThreeDimensionalPacking position = null; 154 //Look for space in existing bins 155 for (int binNr = 0; binNr < nrOfBins; binNr++) { 156 position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures); 157 if (position != null) 158 break; 159 } 160 //Did not find enough space in any of the existing bins => create new bin 161 if (position == null) { 162 nrOfBins++; 163 position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, nrOfBins - 1, item, packingPositions, itemMeasures); 164 } 165 166 if (position == null) 167 position = new ThreeDimensionalPacking(-1, 0, 0, 0); 168 169 packingPositions[solution.PackingSequence[i]] = position; 170 } 171 172 return packingPositions; 173 } 80 174 81 175 public static ThreeDimensionalPacking DeepestLeftBottomPosition(CuboidPackingBin binMeasures, int binNr, CuboidPackingItem currentItem, ObservableDictionary<int, ThreeDimensionalPacking> itemPositions, ItemList<CuboidPackingItem> itemMeasures) { -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/DBL/DeepestBottomLeftGroupingVectorDecoder.cs
r9440 r9495 40 40 [Item("Identical bin three dimensional direct grouping vector decoder", "<Description missing...>")] 41 41 [StorableClass] 42 public class DeepestBottomLeftGroupingVectorDecoder : IdenticalBinPackingSolutionDecoder<42 public class DeepestBottomLeftGroupingVectorDecoder : PackingSolutionDecoder< 43 43 ThreeDimensionalPacking, 44 44 CuboidPackingBin, 45 CuboidPackingItem, 46 PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> { 45 CuboidPackingItem> { 47 46 48 47 public DeepestBottomLeftGroupingVectorDecoder() … … 60 59 61 60 62 p rotected override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {61 public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) { 63 62 64 63 var solution = encodedSolution as GroupingVectorEncoding; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/DBL/DeepestBottomLeftMultiComponentVectorDecoder.cs
r9440 r9495 41 41 [Item("Identical bin three dimensional multi component vector decoder", "<Description missing...>")] 42 42 [StorableClass] 43 public class DeepestBottomLeftMultiComponentVectorDecoder : IdenticalBinPackingSolutionDecoder<43 public class DeepestBottomLeftMultiComponentVectorDecoder : PackingSolutionDecoder< 44 44 ThreeDimensionalPacking, 45 45 CuboidPackingBin, 46 CuboidPackingItem, 47 PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> { 46 CuboidPackingItem> { 48 47 49 48 public DeepestBottomLeftMultiComponentVectorDecoder() … … 61 60 62 61 63 p rotected override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {62 public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) { 64 63 65 64 var solution = encodedSolution as MultiComponentVectorEncoding; … … 68 67 PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> result = 69 68 new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue); 70 int nrOfBins = solution.PackingInformations.Max(pi => pi.AssignedBin) + 1; 71 72 //Get all indexes of items for every bin according to grouping-vector 73 Dictionary<int, List<PackingInformation>> unpackedItemIndexesPerBin = new Dictionary<int, List<PackingInformation>>(); 74 75 for (int i = 0; i < nrOfBins; i++) { 76 unpackedItemIndexesPerBin[i] = solution.PackingInformations 77 .Where(pi => pi.AssignedBin == i) 78 .ToList(); 79 } 80 81 ObservableDictionary<int, ThreeDimensionalPacking> packingPositions = new ObservableDictionary<int, ThreeDimensionalPacking>(); 82 var remainingItems = new List<PackingInformation>(); 83 84 //Iterate over all bin-lists 85 for (int binNr = 0; binNr < nrOfBins; binNr++) { 86 //Iterate over the current bin-item-list and find feasible positions in the current bin for each item 87 var unpackedItems = unpackedItemIndexesPerBin[binNr]; 88 for (int i = 0; i < unpackedItems.Count; i++) { 89 var itemIndex = unpackedItems[i].ItemIndex; 90 var item = PackingItemMeasuresParameter.ActualValue[itemIndex]; 91 ThreeDimensionalPacking position = null; 92 93 position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, unpackedItems[i].Rotated); 94 95 if (position == null) { 96 position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, !unpackedItems[i].Rotated); 97 } 98 if (position == null) { 99 remainingItems.Add(unpackedItems[i]); 100 } else { 101 packingPositions[itemIndex] = position; 102 solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex).Rotated = position.Rotated; 103 } 104 } 105 } 106 107 //Packing of remaining items 108 //Iterate over all bin-lists 109 for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) { 110 var unpackedItems = new List<PackingInformation>(remainingItems); 111 for (int i = 0; i < unpackedItems.Count; i++) { 112 var itemIndex = unpackedItems[i].ItemIndex; 113 var item = PackingItemMeasuresParameter.ActualValue[itemIndex]; 114 ThreeDimensionalPacking position = null; 115 116 //Look for space in current bin 117 position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, unpackedItems[i].Rotated); 118 119 if (position == null) { 120 position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, !unpackedItems[i].Rotated); 121 } 122 if (position != null) { 123 packingPositions[itemIndex] = position; 124 remainingItems.Remove(unpackedItems[i]); 125 solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex).AssignedBin = binNr; 126 solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex).Rotated = position.Rotated; 127 } 128 } 129 if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) { 130 nrOfBins++; 131 } 132 } 133 134 result.PackingItemPositions = packingPositions; 69 70 result.PackingItemPositions = DeepestBottomLeftFunctions.DeepestLeftBottomPacking (solution, binMeasures, itemMeasures); 135 71 136 72 return result; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/DBL/DeepestBottomLeftPackingSequenceDecoder.cs
r9440 r9495 40 40 [Item("Identical bin, three dimensional, direct permutation decoder", "<Description missing...>")] 41 41 [StorableClass] 42 public class DeepestBottomLeftPackingSequenceDecoder : IdenticalBinPackingSolutionDecoder<42 public class DeepestBottomLeftPackingSequenceDecoder : PackingSolutionDecoder< 43 43 ThreeDimensionalPacking, 44 44 CuboidPackingBin, 45 CuboidPackingItem, 46 PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> { 45 CuboidPackingItem> { 47 46 48 47 public DeepestBottomLeftPackingSequenceDecoder() … … 60 59 61 60 62 p rotected override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {61 public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) { 63 62 64 63 var solution = encodedSolution as PackingSequenceEncoding; … … 68 67 new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue); 69 68 70 ObservableDictionary<int, ThreeDimensionalPacking> packingPositions = new ObservableDictionary<int, ThreeDimensionalPacking>(); 71 int nrOfBins = 1; 72 for (int i = 0; i < solution.PackingSequence.Length; i++) { 73 var item = PackingItemMeasuresParameter.ActualValue[solution.PackingSequence[i]]; 74 ThreeDimensionalPacking position = null; 75 //Look for space in existing bins 76 for (int binNr = 0; binNr < nrOfBins; binNr++) { 77 position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue); 78 if (position != null) 79 break; 80 } 81 //Did not find enough space in any of the existing bins => create new bin 82 if (position == null) { 83 nrOfBins++; 84 position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(PackingBinMeasuresParameter.ActualValue, nrOfBins - 1, item, packingPositions, PackingItemMeasuresParameter.ActualValue); 85 } 86 87 if (position == null) 88 position = new ThreeDimensionalPacking(-1, 0, 0, 0); 89 90 packingPositions[solution.PackingSequence[i]] = position; 91 } 92 93 result.PackingItemPositions = packingPositions; 69 result.PackingItemPositions = DeepestBottomLeftFunctions.DeepestLeftBottomPacking (solution, binMeasures, itemMeasures); 94 70 95 71 return result; -
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.