Changeset 9495 for branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D
- Timestamp:
- 05/15/13 22:23:36 (12 years ago)
- Location:
- branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftFunctions.cs
r9440 r9495 5 5 using HeuristicLab.Collections; 6 6 using HeuristicLab.Core; 7 using HeuristicLab.Encodings.PackingEncoding.GroupingVector; 8 using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; 7 9 using HeuristicLab.Encodings.PackingEncoding.PackingSequence; 8 10 using HeuristicLab.Problems.BinPacking.Dimensions; … … 14 16 namespace HeuristicLab.Problems.BinPacking.Decoders { 15 17 public static class BottomLeftFunctions { 16 17 18 19 public static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures) { 18 19 20 public static ObservableDictionary<int, TwoDimensionalPacking> BottomLeftPacking( 21 MultiComponentVectorEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) { 22 int nrOfBins = solution.NrOfBins; 23 24 //Get all indexes of items for every bin according to grouping-vector 25 Dictionary<int, List<PackingInformation>> unpackedItemIndexesPerBin = new Dictionary<int, List<PackingInformation>>(); 26 27 for (int i = 0; i < nrOfBins; i++) { 28 unpackedItemIndexesPerBin[i] = new List<PackingInformation>(solution.PackingInformations[i]); 29 } 30 31 ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>(); 32 var remainingItems = new List<PackingInformation>(); 33 34 //Iterate over all bin-lists 35 for (int binNr = 0; binNr < nrOfBins; binNr++) { 36 //Iterate over the current bin-item-list and find feasible positions in the current bin for each item 37 var unpackedItems = unpackedItemIndexesPerBin[binNr]; 38 for (int i = 0; i < unpackedItems.Count; i++) { 39 var itemIndex = unpackedItems[i].ItemID; 40 var item = itemMeasures[itemIndex]; 41 TwoDimensionalPacking position = null; 42 43 position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated); 44 45 if (position == null) { 46 position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated); 47 } 48 if (position == null) { 49 remainingItems.Add(unpackedItems[i]); 50 } else { 51 packingPositions[itemIndex] = position; 52 solution.PackingInformations[binNr].Remove(unpackedItems[i]); 53 solution.PackingInformations[binNr].Find(pi => pi.ItemID == itemIndex).Rotated = position.Rotated; 54 } 55 } 56 } 57 58 //Packing of remaining items 59 //Iterate over all bin-lists 60 for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) { 61 var unpackedItems = new List<PackingInformation>(remainingItems); 62 for (int i = 0; i < unpackedItems.Count; i++) { 63 var itemIndex = unpackedItems[i].ItemID; 64 var item = itemMeasures[itemIndex]; 65 TwoDimensionalPacking position = null; 66 67 //Look for space in current bin 68 position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated); 69 70 if (position == null) { 71 position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated); 72 } 73 if (position != null) { 74 packingPositions[itemIndex] = position; 75 remainingItems.Remove(unpackedItems[i]); 76 solution.PackingInformations[binNr].Add(unpackedItems[i]); 77 solution.PackingInformations[binNr].Find(pi => pi.ItemID == itemIndex).Rotated = position.Rotated; 78 } 79 } 80 if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) { 81 solution.PackingInformations[nrOfBins] = new ItemList<PackingInformation>(); 82 nrOfBins++; 83 } 84 } 85 86 return packingPositions; 87 } 88 89 public static ObservableDictionary<int, TwoDimensionalPacking> BottomLeftPacking( 90 GroupingVectorEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) { 91 92 int nrOfBins = solution.GroupingVector.Max() + 1; 93 94 //Get all indexes of items for every bin according to grouping-vector 95 //It is assumed, that at this point the item-indexes are sorted according to their item-size! 96 Dictionary<int, List<int>> unpackedItemIndexesPerBin = new Dictionary<int, List<int>>(); 97 98 for (int i = 0; i < nrOfBins; i++) { 99 unpackedItemIndexesPerBin[i] = solution.GroupingVector 100 .Select((Value, Index) => new { Value, Index }) 101 .Where(temp => temp.Value == i) 102 .Select(temp => temp.Index).ToList(); 103 } 104 105 ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>(); 106 var remainingItems = new List<int>(); 107 108 //Iterate over all bin-lists 109 for (int binNr = 0; binNr < nrOfBins; binNr++) { 110 //Iterate over the current bin-item-list and find feasible positions in the current bin for each item 111 var unpackedItems = unpackedItemIndexesPerBin[binNr]; 112 for (int i = 0; i < unpackedItems.Count; i++) { 113 var itemIndex = unpackedItems[i]; 114 var item = itemMeasures[itemIndex]; 115 TwoDimensionalPacking position = null; 116 117 //Look for space in current bin 118 position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures); 119 120 //Did not find enough space in current bin 121 if (position == null) { 122 remainingItems.Add(itemIndex); 123 } else 124 packingPositions[itemIndex] = position; 125 } 126 } 127 128 //Packing of remaining items 129 //Iterate over all bin-lists 130 for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) { 131 var unpackedItems = new List<int>(remainingItems); 132 for (int i = 0; i < unpackedItems.Count; i++) { 133 var itemIndex = unpackedItems[i]; 134 var item = itemMeasures[itemIndex]; 135 TwoDimensionalPacking position = null; 136 137 //Look for space in current bin 138 position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures); 139 140 if (position != null) { 141 packingPositions[itemIndex] = position; 142 remainingItems.Remove(itemIndex); 143 solution.GroupingVector[itemIndex] = binNr; 144 } 145 } 146 if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) { 147 nrOfBins++; 148 } 149 } 150 151 return packingPositions; 152 } 153 154 public static ObservableDictionary<int, TwoDimensionalPacking> BottomLeftPacking( 155 PackingSequenceEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) { 156 157 ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>(); 158 int nrOfBins = 1; 159 for (int i = 0; i < solution.PackingSequence.Length; i++) { 160 var item = itemMeasures[solution.PackingSequence[i]]; 161 TwoDimensionalPacking position = null; 162 //Look for space in existing bins 163 for (int binNr = 0; binNr < nrOfBins; binNr++) { 164 position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures); 165 if (position != null) 166 break; 167 } 168 //Did not find enough space in any of the existing bins => create new bin 169 if (position == null) { 170 nrOfBins++; 171 position = BottomLeftFunctions.BottomLeftPosition(binMeasures, nrOfBins - 1, item, packingPositions, itemMeasures); 172 } 173 174 if (position == null) 175 position = new TwoDimensionalPacking(-1, 0, 0); 176 177 packingPositions[solution.PackingSequence[i]] = position; 178 } 179 180 return packingPositions; 181 } 182 183 private static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures) { 20 184 return BottomLeftPosition(binMeasures, binNr, currentItem, itemPositions, itemMeasures, false); 21 185 } 22 p ublicstatic TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures, bool rotated) {186 private static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures, bool rotated) { 23 187 TwoDimensionalPacking currentPosition = new TwoDimensionalPacking(binNr, 24 188 binMeasures.Width - (rotated ? currentItem.Height : currentItem.Width), -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftGroupingVectorDecoder.cs
r9440 r9495 41 41 [Item("Identical bin two dimensional grouping vector decoder", "<Description missing...>")] 42 42 [StorableClass] 43 public class BottomLeftGroupingVectorDecoder : IdenticalBinPackingSolutionDecoder<43 public class BottomLeftGroupingVectorDecoder : PackingSolutionDecoder< 44 44 TwoDimensionalPacking, 45 45 RectangularPackingBin, 46 RectangularPackingItem, 47 PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> { 46 RectangularPackingItem> { 48 47 49 48 public BottomLeftGroupingVectorDecoder() … … 61 60 62 61 63 p rotected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {62 public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) { 64 63 65 64 var solution = encodedSolution as GroupingVectorEncoding; … … 69 68 new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue); 70 69 71 int nrOfBins = solution.GroupingVector.Max() + 1; 72 73 //Get all indexes of items for every bin according to grouping-vector 74 //It is assumed, that at this point the item-indexes are sorted according to their item-size! 75 Dictionary<int, List<int>> unpackedItemIndexesPerBin = new Dictionary<int, List<int>>(); 76 77 for (int i = 0; i < nrOfBins; i++) { 78 unpackedItemIndexesPerBin[i] = solution.GroupingVector 79 .Select((Value, Index) => new { Value, Index }) 80 .Where(temp => temp.Value == i) 81 .Select(temp => temp.Index).ToList(); 82 } 83 84 ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>(); 85 var remainingItems = new List<int>(); 86 87 //Iterate over all bin-lists 88 for (int binNr = 0; binNr < nrOfBins; binNr++ ) { 89 //Iterate over the current bin-item-list and find feasible positions in the current bin for each item 90 var unpackedItems = unpackedItemIndexesPerBin [binNr]; 91 for (int i = 0; i < unpackedItems.Count; i++ ) { 92 var itemIndex = unpackedItems[i]; 93 var item = PackingItemMeasuresParameter.ActualValue[itemIndex]; 94 TwoDimensionalPacking position = null; 95 96 //Look for space in current bin 97 position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue); 98 99 //Did not find enough space in current bin 100 if (position == null) { 101 remainingItems.Add(itemIndex); 102 //if (binNr + 1 >= nrOfBins) { 103 // nrOfBins++; 104 // unpackedItemIndexesPerBin[binNr + 1] = new List<int>(); 105 // unpackedItemIndexesPerBin[binNr + 1].Add(itemIndex); 106 // unpackedItemIndexesPerBin[binNr].Remove(itemIndex); 107 //} else { 108 // unpackedItemIndexesPerBin[binNr + 1].Add(itemIndex); 109 // unpackedItemIndexesPerBin[binNr + 1].Sort(); 110 //} 111 //solution.GroupingVector[itemIndex] = binNr + 1; 112 } else 113 packingPositions[itemIndex] = position; 114 } 115 } 116 117 //Packing of remaining items 118 //Iterate over all bin-lists 119 for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) { 120 var unpackedItems = new List<int>(remainingItems); 121 for (int i = 0; i < unpackedItems.Count; i++) { 122 var itemIndex = unpackedItems[i]; 123 var item = PackingItemMeasuresParameter.ActualValue[itemIndex]; 124 TwoDimensionalPacking position = null; 125 126 //Look for space in current bin 127 position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue); 128 129 if (position != null) { 130 packingPositions[itemIndex] = position; 131 remainingItems.Remove(itemIndex); 132 solution.GroupingVector[itemIndex] = binNr; 133 } 134 } 135 if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) { 136 nrOfBins++; 137 } 138 } 139 140 result.PackingItemPositions = packingPositions; 141 142 70 result.PackingItemPositions = BottomLeftFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures); 143 71 return result; 144 72 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftMultiComponentVectorDecoder.cs
r9440 r9495 41 41 [Item("Identical bin two dimensional multi component vector decoder", "<Description missing...>")] 42 42 [StorableClass] 43 public class BottomLeftMultiComponentVectorDecoder : IdenticalBinPackingSolutionDecoder<43 public class BottomLeftMultiComponentVectorDecoder : PackingSolutionDecoder< 44 44 TwoDimensionalPacking, 45 45 RectangularPackingBin, 46 RectangularPackingItem, 47 PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> { 46 RectangularPackingItem> { 48 47 49 48 public BottomLeftMultiComponentVectorDecoder() … … 61 60 62 61 63 p rotected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {62 public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) { 64 63 65 64 var solution = encodedSolution as MultiComponentVectorEncoding; … … 68 67 PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> result = 69 68 new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(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, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>(); 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 TwoDimensionalPacking position = null; 92 93 position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, unpackedItems[i].Rotated); 94 95 if (position == null) { 96 position = BottomLeftFunctions.BottomLeftPosition(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 TwoDimensionalPacking position = null; 115 116 //Look for space in current bin 117 position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, unpackedItems[i].Rotated); 118 119 if (position == null) { 120 position = BottomLeftFunctions.BottomLeftPosition(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 = BottomLeftFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures); 135 71 136 72 return result; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftPackingSequenceDecoder.cs
r9440 r9495 40 40 [Item("Identical bin, two dimensional, direct permutation decoder", "<Description missing...>")] 41 41 [StorableClass] 42 public class BottomLeftPackingSequenceDecoder : IdenticalBinPackingSolutionDecoder<42 public class BottomLeftPackingSequenceDecoder : PackingSolutionDecoder< 43 43 TwoDimensionalPacking, 44 44 RectangularPackingBin, 45 RectangularPackingItem, 46 PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> { 45 RectangularPackingItem> { 47 46 48 47 public BottomLeftPackingSequenceDecoder() … … 60 59 61 60 62 p rotected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {61 public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) { 63 62 64 63 var solution = encodedSolution as PackingSequenceEncoding; … … 68 67 new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue); 69 68 70 ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>(); 71 int nrOfBins = 1; 72 for (int i = 0; i < solution.PackingSequence.Length; i++) { 73 var item = PackingItemMeasuresParameter.ActualValue[solution.PackingSequence[i]]; 74 TwoDimensionalPacking position = null; 75 //Look for space in existing bins 76 for (int binNr = 0; binNr < nrOfBins; binNr++) { 77 position = BottomLeftFunctions.BottomLeftPosition(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 = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, nrOfBins - 1, item, packingPositions, PackingItemMeasuresParameter.ActualValue); 85 } 86 87 if (position == null) 88 position = new TwoDimensionalPacking(-1, 0, 0); 89 90 packingPositions[solution.PackingSequence[i]] = position; 91 } 92 93 result.PackingItemPositions = packingPositions; 69 result.PackingItemPositions = BottomLeftFunctions.BottomLeftPacking (solution, binMeasures, itemMeasures); 94 70 95 71 return result; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointGroupingVectorDecoder2D.cs
r9440 r9495 41 41 [Item("Identical bin, two dimensional, extreme points based decoder for the GroupingVector encoding.", "<Description missing...>")] 42 42 [StorableClass] 43 public class ExtremePointGroupingVectorDecoder2D : IdenticalBinPackingSolutionDecoder<43 public class ExtremePointGroupingVectorDecoder2D : PackingSolutionDecoder< 44 44 TwoDimensionalPacking, 45 45 RectangularPackingBin, 46 RectangularPackingItem, 47 PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> { 46 RectangularPackingItem> { 48 47 49 48 public ExtremePointGroupingVectorDecoder2D () … … 68 67 } 69 68 70 p rotected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {69 public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) { 71 70 72 71 var solution = encodedSolution as GroupingVectorEncoding; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointMultiComponentVectorDecoder2D.cs
r9440 r9495 42 42 [Item("Identical bin, two dimensional, extreme points based decoder for the MultiComponentVector encoding.", "<Description missing...>")] 43 43 [StorableClass] 44 public class ExtremePointMultiComponentVectorDecoder2D : IdenticalBinPackingSolutionDecoder<44 public class ExtremePointMultiComponentVectorDecoder2D : PackingSolutionDecoder< 45 45 TwoDimensionalPacking, 46 46 RectangularPackingBin, 47 RectangularPackingItem, 48 PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> { 47 RectangularPackingItem> { 49 48 50 49 public ExtremePointMultiComponentVectorDecoder2D () … … 69 68 } 70 69 71 p rotected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {70 public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> 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/2D/EP/ExtremePointPackingSequenceDecoder2D.cs
r9440 r9495 40 40 [Item("Identical bin, two dimensional, extreme points based decoder for the PackingSequence encoding.", "<Description missing...>")] 41 41 [StorableClass] 42 public class ExtremePointPackingSequenceDecoder2D : IdenticalBinPackingSolutionDecoder<42 public class ExtremePointPackingSequenceDecoder2D : PackingSolutionDecoder< 43 43 TwoDimensionalPacking, 44 44 RectangularPackingBin, 45 RectangularPackingItem, 46 PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> { 45 RectangularPackingItem> { 47 46 48 47 public ExtremePointPackingSequenceDecoder2D () … … 59 58 60 59 61 p rotected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {60 public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) { 62 61 63 62 var solution = encodedSolution as PackingSequenceEncoding; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointsFunctions2D.cs
r9440 r9495 24 24 25 25 #region Preperations 26 int nrOfBins = solution.PackingInformations.Max(x => x.AssignedBin) + 1;26 int nrOfBins = solution.NrOfBins; 27 27 28 28 //Get all indexes of items for every bin according to grouping-vector … … 32 32 33 33 for (int i = 0; i < nrOfBins; i++) { 34 unpackedItemIndexesPerBin[i] = solution.PackingInformations 35 .Where(pi => pi.AssignedBin == i) 36 .ToList(); 34 unpackedItemIndexesPerBin[i] = new List<PackingInformation> (solution.PackingInformations[i]); 37 35 38 36 extremePointsForBin[i] = new HashSet<TwoDimensionalPacking>(); … … 52 50 var unpackedItems = unpackedItemIndexesPerBin[binNr]; 53 51 for (int i = 0; i < unpackedItems.Count; i++) { 54 var itemIndex = unpackedItems[i].ItemI ndex;52 var itemIndex = unpackedItems[i].ItemID; 55 53 var item = itemMeasures[itemIndex]; 56 54 57 extremePointsForBin[binNr] = new HashSet<TwoDimensionalPacking>(extremePointsForBin[binNr].OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));55 extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures); 58 56 var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions, unpackedItems[i].Rotated); 59 57 if (positionFound != null) { … … 62 60 occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex); 63 61 extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures); 64 } else 62 } else { 65 63 remainingItems.Add(unpackedItems[i]); 64 solution.PackingInformations[binNr].Remove(unpackedItems[i]); 65 } 66 66 } 67 67 } … … 74 74 //Iterate over all the remaining items 75 75 for (int i = 0; i < unpackedItems.Count; i++) { 76 var itemIndex = unpackedItems[i].ItemI ndex;76 var itemIndex = unpackedItems[i].ItemID; 77 77 var item = itemMeasures[itemIndex]; 78 78 79 extremePointsForBin[binNr] = new HashSet<TwoDimensionalPacking>(extremePointsForBin[binNr].OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));79 extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures); 80 80 var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions, unpackedItems[i].Rotated); 81 81 if (positionFound != null) { … … 85 85 extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures); 86 86 remainingItems.Remove(unpackedItems[i]); 87 solution.PackingInformations[binNr].Add(unpackedItems[i]); 87 88 } 88 89 } … … 91 92 extremePointsForBin[nrOfBins].Add(new TwoDimensionalPacking(nrOfBins, 0, 0, false)); 92 93 occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures); 94 solution.PackingInformations[nrOfBins] = new ItemList<PackingInformation>(); 93 95 nrOfBins++; 94 96 } … … 136 138 var item = itemMeasures[itemIndex]; 137 139 138 extremePointsForBin[binNr] = new HashSet<TwoDimensionalPacking>(extremePointsForBin[binNr].OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));140 extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures); 139 141 var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions); 140 142 if (positionFound != null) { … … 159 161 var item = itemMeasures[itemIndex]; 160 162 161 extremePointsForBin[binNr] = new HashSet<TwoDimensionalPacking>(extremePointsForBin[binNr].OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));163 extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures); 162 164 var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions); 163 165 if (positionFound != null) { … … 197 199 foreach (int itemIndex in solution.PackingSequence) { 198 200 var item = itemMeasures[itemIndex]; 199 extremePoints = new HashSet<TwoDimensionalPacking>(extremePoints.OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));201 extremePoints = OrderExtremePoints(extremePoints, occupiedPoints, binMeasures); 200 202 var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePoints, occupiedPoints, itemPositions); 201 203 if (positionFound != null) { … … 296 298 return extremePoints; 297 299 } 300 301 public static HashSet<TwoDimensionalPacking> OrderExtremePoints(HashSet<TwoDimensionalPacking> hashSet, List<int[,]> occupiedPoints, RectangularPackingBin binMeasures) { 302 return new HashSet<TwoDimensionalPacking>(hashSet.OrderBy(ep => ep.AssignedBin).ThenBy(ep => ep.X).ThenBy(ep => ep.Y).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures))); 303 } 298 304 private static int ShortestPossibleSideFromEP(TwoDimensionalPacking ep, List<int[,]> occupiedPoints, RectangularPackingBin binMeasures) { 299 305 int shortestSide = int.MaxValue;
Note: See TracChangeset
for help on using the changeset viewer.