1 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
2 | using HeuristicLab.Problems.BinPacking2D;
|
---|
3 | using System;
|
---|
4 | using System.Collections.Generic;
|
---|
5 | using System.Linq;
|
---|
6 | using System.Text;
|
---|
7 | using System.Threading.Tasks;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Problems.BinPacking3D.Sorting {
|
---|
10 | public static class PackingItemSorter {
|
---|
11 | public static Permutation SortByVolumeHeight(this IList<PackingItem> items) {
|
---|
12 | return new Permutation(PermutationTypes.Absolute,
|
---|
13 | items.Select((v, i) => new { Index = i, Item = v })
|
---|
14 | .OrderByDescending(x => x.Item.Depth * x.Item.Width * x.Item.Height)
|
---|
15 | .ThenByDescending(x => x.Item.Height)
|
---|
16 | .Select(x => x.Index).ToArray());
|
---|
17 | }
|
---|
18 |
|
---|
19 | public static Permutation SortByHeightVolume(this IList<PackingItem> items) {
|
---|
20 | return new Permutation(PermutationTypes.Absolute,
|
---|
21 | items.Select((v, i) => new { Index = i, Item = v })
|
---|
22 | .OrderByDescending(x => x.Item.Height)
|
---|
23 | .ThenByDescending(x => x.Item.Depth * x.Item.Width * x.Item.Height)
|
---|
24 | .Select(x => x.Index).ToArray());
|
---|
25 | }
|
---|
26 |
|
---|
27 | public static Permutation SortByAreaHeight(this IList<PackingItem> items) {
|
---|
28 | return new Permutation(PermutationTypes.Absolute,
|
---|
29 | items.Select((v, i) => new { Index = i, Item = v })
|
---|
30 | .OrderByDescending(x => x.Item.Depth * x.Item.Width)
|
---|
31 | .ThenByDescending(x => x.Item.Height)
|
---|
32 | .Select(x => x.Index).ToArray());
|
---|
33 | }
|
---|
34 |
|
---|
35 | public static Permutation SortByHeightArea(this IList<PackingItem> items) {
|
---|
36 | return new Permutation(PermutationTypes.Absolute,
|
---|
37 | items.Select((v, i) => new { Index = i, Item = v })
|
---|
38 | .OrderByDescending(x => x.Item.Height)
|
---|
39 | .ThenByDescending(x => x.Item.Depth * x.Item.Width)
|
---|
40 | .Select(x => x.Index).ToArray());
|
---|
41 | }
|
---|
42 |
|
---|
43 | public static Permutation SortByClusteredAreaHeight(this IList<PackingItem> items, PackingShape bin, double delta) {
|
---|
44 | double clusterRange = bin.Width * bin.Depth * delta;
|
---|
45 | return new Permutation(PermutationTypes.Absolute,
|
---|
46 | items.Select((v, i) => new { Index = i, Item = v, ClusterId = (int)(Math.Ceiling(v.Width * v.Depth / clusterRange)) })
|
---|
47 | .GroupBy(x => x.ClusterId)
|
---|
48 | .Select(x => new { Cluster = x.Key, Items = x.OrderByDescending(y => y.Item.Height).ToList() })
|
---|
49 | .OrderByDescending(x => x.Cluster)
|
---|
50 | .SelectMany(x => x.Items)
|
---|
51 | .Select(x => x.Index).ToArray());
|
---|
52 | }
|
---|
53 |
|
---|
54 | public static Permutation SortByClusteredHeightArea(this IList<PackingItem> items, PackingShape bin, double delta) {
|
---|
55 | double clusterRange2 = bin.Height * delta;
|
---|
56 | return new Permutation(PermutationTypes.Absolute,
|
---|
57 | items.Select((v, i) => new { Index = i, Item = v, ClusterId = (int)(Math.Ceiling(v.Height / clusterRange2)) })
|
---|
58 | .GroupBy(x => x.ClusterId)
|
---|
59 | .Select(x => new { Cluster = x.Key, Items = x.OrderByDescending(y => y.Item.Depth * y.Item.Width).ToList() })
|
---|
60 | .OrderByDescending(x => x.Cluster)
|
---|
61 | .SelectMany(x => x.Items)
|
---|
62 | .Select(x => x.Index).ToArray());
|
---|
63 | }
|
---|
64 |
|
---|
65 | public static Permutation SortByMaterialVolumeHeight(this IList<PackingItem> items) {
|
---|
66 | return new Permutation(PermutationTypes.Absolute,
|
---|
67 | items.Select((v, i) => new { Index = i, Item = v })
|
---|
68 | .OrderByDescending(x => x.Item.Material)
|
---|
69 | .ThenByDescending(x => x.Item.Depth * x.Item.Width * x.Item.Height)
|
---|
70 | .ThenByDescending(x => x.Item.Height)
|
---|
71 | .Select(x => x.Index).ToArray());
|
---|
72 | }
|
---|
73 |
|
---|
74 | public static Permutation SortByMaterialHeightVolume(this IList<PackingItem> items) {
|
---|
75 | return new Permutation(PermutationTypes.Absolute,
|
---|
76 | items.Select((v, i) => new { Index = i, Item = v })
|
---|
77 | .OrderByDescending(x => x.Item.Material)
|
---|
78 | .ThenByDescending(x => x.Item.Height)
|
---|
79 | .ThenByDescending(x => x.Item.Depth * x.Item.Width * x.Item.Height)
|
---|
80 | .Select(x => x.Index).ToArray());
|
---|
81 | }
|
---|
82 |
|
---|
83 | public static Permutation SortByMaterialAreaHeight(this IList<PackingItem> items) {
|
---|
84 | return new Permutation(PermutationTypes.Absolute,
|
---|
85 | items.Select((v, i) => new { Index = i, Item = v })
|
---|
86 | .OrderByDescending(x => x.Item.Material)
|
---|
87 | .ThenByDescending(x => x.Item.Depth * x.Item.Width)
|
---|
88 | .ThenByDescending(x => x.Item.Height)
|
---|
89 | .Select(x => x.Index).ToArray());
|
---|
90 | }
|
---|
91 |
|
---|
92 | public static Permutation SortByMaterialHeightArea(this IList<PackingItem> items) {
|
---|
93 | return new Permutation(PermutationTypes.Absolute,
|
---|
94 | items.Select((v, i) => new { Index = i, Item = v })
|
---|
95 | .OrderByDescending(x => x.Item.Material)
|
---|
96 | .ThenByDescending(x => x.Item.Height)
|
---|
97 | .ThenByDescending(x => x.Item.Depth * x.Item.Width)
|
---|
98 | .Select(x => x.Index).ToArray());
|
---|
99 | }
|
---|
100 |
|
---|
101 | public static Permutation SortByMaterialClusteredAreaHeight(this IList<PackingItem> items, PackingShape bin, double delta) {
|
---|
102 | double clusterRange = bin.Width * bin.Depth * delta;
|
---|
103 | return new Permutation(PermutationTypes.Absolute,
|
---|
104 | items.Select((v, i) => new { Index = i, Item = v, ClusterId = (int)(Math.Ceiling(v.Width * v.Depth / clusterRange)) })
|
---|
105 | .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 |
|
---|
112 | public static Permutation SortByMaterialClusteredHeightArea(this IList<PackingItem> items, PackingShape bin, double delta) {
|
---|
113 | double clusterRange2 = bin.Height * delta;
|
---|
114 | return new Permutation(PermutationTypes.Absolute,
|
---|
115 | items.Select((v, i) => new { Index = i, Item = v, ClusterId = (int)(Math.Ceiling(v.Height / clusterRange2)) })
|
---|
116 | .GroupBy(x => x.ClusterId)
|
---|
117 | .Select(x => new { Cluster = x.Key, Items = x.OrderByDescending(y => y.Item.Depth * y.Item.Width).ToList() })
|
---|
118 | .OrderByDescending(x => x.Cluster)
|
---|
119 | .SelectMany(x => x.Items)
|
---|
120 | .Select(x => x.Index).ToArray());
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|