- Timestamp:
- 11/14/17 15:31:22 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Sorting/PackingItemSorter.cs
r15463 r15471 8 8 9 9 namespace HeuristicLab.Problems.BinPacking3D.Sorting { 10 11 /// <summary> 12 /// This is a extension class for sorting a permutation. 13 /// </summary> 10 14 public static class PackingItemSorter { 15 16 /// <summary> 17 /// Sorts a given permutation first by the volume and secoundly by the height. 18 /// </summary> 19 /// <param name="items">Permuation which should be sorted</param> 20 /// <returns>A new sorted permutation</returns> 11 21 public static Permutation SortByVolumeHeight(this IList<PackingItem> items) { 12 22 return new Permutation(PermutationTypes.Absolute, … … 17 27 } 18 28 29 /// <summary> 30 /// Sorts a given permutation first by the heigth and secoundly by the volume. 31 /// </summary> 32 /// <param name="items">Permuation which should be sorted</param> 33 /// <returns>A new sorted permutation</returns> 19 34 public static Permutation SortByHeightVolume(this IList<PackingItem> items) { 20 35 return new Permutation(PermutationTypes.Absolute, … … 25 40 } 26 41 42 /// <summary> 43 /// Sorts a given permutation first by the area and secondly by the height. 44 /// </summary> 45 /// <param name="items">Permuation which should be sorted</param> 46 /// <returns>A new sorted permutation</returns> 27 47 public static Permutation SortByAreaHeight(this IList<PackingItem> items) { 28 48 return new Permutation(PermutationTypes.Absolute, … … 33 53 } 34 54 55 /// <summary> 56 /// Sorts a given permuation first by the height and secoundly by the area. 57 /// </summary> 58 /// <param name="items">Permuation which should be sorted</param> 59 /// <returns>A new sorted permutation</returns> 35 60 public static Permutation SortByHeightArea(this IList<PackingItem> items) { 36 61 return new Permutation(PermutationTypes.Absolute, … … 41 66 } 42 67 68 /// <summary> 69 /// Sorts a given permutation. The items are being grouped by the cluster id. 70 /// The cluster id is calulated as followed: clusterId = Ceiling( (width * depth) / (width * depth * delta)) 71 /// The permutation is first being sorted by the area and secoundly by the height. 72 /// </summary> 73 /// <param name="items">Permuation which should be sorted</param> 74 /// <param name="bin">The bin is needed for building the cluster</param> 75 /// <param name="delta">The delta is needed for building the cluster</param> 76 /// <returns>A new sorted permutation</returns> 43 77 public static Permutation SortByClusteredAreaHeight(this IList<PackingItem> items, PackingShape bin, double delta) { 44 78 double clusterRange = bin.Width * bin.Depth * delta; … … 52 86 } 53 87 88 /// <summary> 89 /// Sorts a given permutation. The items are being grouped by the cluster id. 90 /// The cluster id is calulated as followed: clusterId = Ceiling( (height) / (height * delta)) 91 /// The permutation is first being sorted by the height and secoundly by the area. 92 /// </summary> 93 /// <param name="items">Permuation which should be sorted</param> 94 /// <param name="bin">The bin is needed for building the cluster</param> 95 /// <param name="delta">The delta is needed for building the cluster</param> 96 /// <returns>A new sorted permutation</returns> 54 97 public static Permutation SortByClusteredHeightArea(this IList<PackingItem> items, PackingShape bin, double delta) { 55 98 double clusterRange2 = bin.Height * delta; … … 63 106 } 64 107 108 /// <summary> 109 /// Sorts a given permutation first by the material, secoundly by the volume and finally by the height. 110 /// </summary> 111 /// <param name="items">Permuation which should be sorted</param> 112 /// <returns>A new sorted permutation</returns> 65 113 public static Permutation SortByMaterialVolumeHeight(this IList<PackingItem> items) { 66 114 return new Permutation(PermutationTypes.Absolute, … … 72 120 } 73 121 122 /// <summary> 123 /// Sorts a given permutation first by the material, secoundly by the heigth and finally by the volume. 124 /// </summary> 125 /// <param name="items">Permuation which should be sorted</param> 126 /// <returns>A new sorted permutation</returns> 74 127 public static Permutation SortByMaterialHeightVolume(this IList<PackingItem> items) { 75 128 return new Permutation(PermutationTypes.Absolute, … … 81 134 } 82 135 136 /// <summary> 137 /// Sorts a given permutation first by the material, secoundly by the area and finally by the height. 138 /// </summary> 139 /// <param name="items">Permuation which should be sorted</param> 140 /// <returns>A new sorted permutation</returns> 83 141 public static Permutation SortByMaterialAreaHeight(this IList<PackingItem> items) { 84 142 return new Permutation(PermutationTypes.Absolute, … … 90 148 } 91 149 150 /// <summary> 151 /// Sorts a given permuation first by the material, secoundly by the height and finally by the area. 152 /// </summary> 153 /// <param name="items">Permuation which should be sorted</param> 154 /// <returns>A new sorted permutation</returns> 92 155 public static Permutation SortByMaterialHeightArea(this IList<PackingItem> items) { 93 156 return new Permutation(PermutationTypes.Absolute, … … 99 162 } 100 163 164 /// <summary> 165 /// Sorts a given permutation. The items are being grouped by the cluster id. 166 /// The cluster id is calulated as followed: clusterId = Ceiling( (width * depth) / (width * depth * delta)) 167 /// The permutation is being clusterd by the area, first sorted by the material, secoundly by the height. 168 /// </summary> 169 /// <param name="items">Permuation which should be sorted</param> 170 /// <param name="bin">The bin is needed for building the cluster</param> 171 /// <param name="delta">The delta is needed for building the cluster</param> 172 /// <returns>A new sorted permutation</returns> 101 173 public static Permutation SortByMaterialClusteredAreaHeight(this IList<PackingItem> items, PackingShape bin, double delta) { 102 174 double clusterRange = bin.Width * bin.Depth * delta; … … 104 176 items.Select((v, i) => new { Index = i, Item = v, ClusterId = (int)(Math.Ceiling(v.Width * v.Depth / clusterRange)) }) 105 177 .GroupBy(x => x.ClusterId) 106 .Select(x => new { Cluster = x.Key, Items = x.OrderByDescending(y => y.Item.Height).ToList() }) 107 .OrderByDescending(x => x.Cluster) 108 .SelectMany(x => x.Items) 109 .Select(x => x.Index).ToArray()); 110 } 111 178 .Select(x => new { Cluster = x.Key, Items = x.OrderByDescending(z => z.Item.Material).ThenByDescending(y => y.Item.Height).ToList() }) 179 .OrderByDescending(x => x.Cluster) 180 .SelectMany(x => x.Items) 181 .Select(x => x.Index).ToArray()); 182 } 183 184 /// <summary> 185 /// Sorts a given permutation. The items are being grouped by the cluster id. 186 /// The cluster id is calulated as followed: clusterId = Ceiling( (height) / (height * delta)) 187 /// The permutation is being clusterd by the height, first sorted by the material, secoundly by the area. 188 /// </summary> 189 /// <param name="items">Permuation which should be sorted</param> 190 /// <param name="bin">The bin is needed for building the cluster</param> 191 /// <param name="delta">The delta is needed for building the cluster</param> 192 /// <returns>A new sorted permutation</returns> 112 193 public static Permutation SortByMaterialClusteredHeightArea(this IList<PackingItem> items, PackingShape bin, double delta) { 113 194 double clusterRange2 = bin.Height * delta; … … 115 196 items.Select((v, i) => new { Index = i, Item = v, ClusterId = (int)(Math.Ceiling(v.Height / clusterRange2)) }) 116 197 .GroupBy(x => x.ClusterId) 117 .Select(x => new { Cluster = x.Key, Items = x.OrderByDescending( y => y.Item.Depth * y.Item.Width).ToList() })198 .Select(x => new { Cluster = x.Key, Items = x.OrderByDescending(z => z.Item.Material).ThenByDescending(y => y.Item.Depth * y.Item.Width).ToList() }) 118 199 .OrderByDescending(x => x.Cluster) 119 200 .SelectMany(x => x.Items)
Note: See TracChangeset
for help on using the changeset viewer.