Hi, TIMTOWTDI.
This approach uses two phases:
Phase-1: Find a combination of bins with at maximum two capacity classes.
Ideally use minimum number of bins with maximum capacity. If that doesn't work,
find greatest number of bins with maximum capacity and the rest of the bins will
have minimum capacity (choose min-capacity as big as possible - by configuration).
E.g., 31 bins: 31 bins a 6 capacity = 186 elements. 32 bins: 26 bins a 6 + 6 bins a 5 = 186 elements.
(I understand that it is the OP's intention to keep the bin capacity
maximised and homogeneous.)
After this phase the bin geometry is fixed (e.g. use bins with capacity 5-6) and the bins
will be filled naively - without respecting the second constraint. That will be optimised in ...
Phase-2: Compute an error measure that identifies how good the current solution is.
Now select groups of bins that have a sum that is too big or too small. Pick random elements from
these groups and cross-exchange items iff the error measure will decrease. Fall back to any
group if there is no group that satisfies the constraint (i.e. sum too big/small). Stop if all restrictions
are satisfied. Periodically, check how far we are. Stop, if the solution has not improved. Instead of stopping the simulation, one could introduce a little mutation and increase the error by randomly swapping elements. However, I noticed that it is sufficient to restart the simulation with a new set of
freshly shuffled items...
Concerning the target value to optimse for (e.g. sum of a bin shall be 852), I used something along
bin-size * mean value. When there are two capacity classes, the mean capacity is used. This leads to an evenly distributed sum per bin even when two bin-capacities are in use
(e.g. smaller bins get less but bigger items).
I hope, these assumptions were made in the OP's intention...
Here's a sample output:
partitions: 31x6 0x6
mean-cap. : 6.000
sum : 26403
target-sum: 852
mean : 141.951612903226
inital error: 67.0183766996175
=== SOLUTION FOUND ===
runtime : 0s, loops:144, improv.:57
ranges : low: 840, target: 852, high: 900
capacity: min: 6, meancap: 6, max: 6
error. : 0.593394689997349 bins: 31
1) 858 OK (sz=6, trgt= 852.0, [840-900]) 123, 131, 132, 137
+, 137, 198
2) 856 OK (sz=6, trgt= 852.0, [840-900]) 121, 123, 127, 133
+, 157, 195
3) 842 OK (sz=6, trgt= 852.0, [840-900]) 107, 109, 134, 157
+, 164, 171
4) 855 OK (sz=6, trgt= 852.0, [840-900]) 126, 128, 136, 141
+, 147, 177
5) 848 OK (sz=6, trgt= 852.0, [840-900]) 98, 121, 122, 147
+, 173, 187
6) 844 OK (sz=6, trgt= 852.0, [840-900]) 112, 129, 129, 152
+, 154, 168
7) 849 OK (sz=6, trgt= 852.0, [840-900]) 117, 129, 139, 144
+, 160, 160
8) 858 OK (sz=6, trgt= 852.0, [840-900]) 88, 91, 99, 141
+, 143, 296
9) 845 OK (sz=6, trgt= 852.0, [840-900]) 95, 117, 136, 139
+, 142, 216
10) 844 OK (sz=6, trgt= 852.0, [840-900]) 105, 121, 133, 148
+, 154, 183
11) 845 OK (sz=6, trgt= 852.0, [840-900]) 113, 114, 132, 151
+, 153, 182
12) 848 OK (sz=6, trgt= 852.0, [840-900]) 99, 122, 124, 157
+, 158, 188
13) 855 OK (sz=6, trgt= 852.0, [840-900]) 105, 116, 150, 151
+, 161, 172
14) 876 OK (sz=6, trgt= 852.0, [840-900]) 130, 135, 138, 143
+, 149, 181
15) 856 OK (sz=6, trgt= 852.0, [840-900]) 92, 126, 139, 140
+, 167, 192
16) 843 OK (sz=6, trgt= 852.0, [840-900]) 99, 111, 112, 116
+, 144, 261
17) 871 OK (sz=6, trgt= 852.0, [840-900]) 103, 109, 113, 131
+, 158, 257
18) 857 OK (sz=6, trgt= 852.0, [840-900]) 120, 122, 143, 152
+, 154, 166
19) 851 OK (sz=6, trgt= 852.0, [840-900]) 103, 105, 124, 166
+, 173, 180
20) 852 OK (sz=6, trgt= 852.0, [840-900]) 113, 122, 131, 135
+, 141, 210
21) 850 OK (sz=6, trgt= 852.0, [840-900]) 103, 116, 126, 161
+, 167, 177
22) 858 OK (sz=6, trgt= 852.0, [840-900]) 96, 132, 134, 160
+, 162, 174
23) 850 OK (sz=6, trgt= 852.0, [840-900]) 98, 130, 145, 150
+, 150, 177
24) 844 OK (sz=6, trgt= 852.0, [840-900]) 112, 121, 124, 145
+, 146, 196
25) 841 OK (sz=6, trgt= 852.0, [840-900]) 115, 118, 122, 124
+, 165, 197
26) 841 OK (sz=6, trgt= 852.0, [840-900]) 114, 130, 135, 144
+, 156, 162
27) 840 OK (sz=6, trgt= 852.0, [840-900]) 97, 111, 118, 126
+, 193, 195
28) 852 OK (sz=6, trgt= 852.0, [840-900]) 99, 122, 126, 160
+, 163, 182
29) 844 OK (sz=6, trgt= 852.0, [840-900]) 86, 105, 115, 141
+, 198, 199
30) 872 OK (sz=6, trgt= 852.0, [840-900]) 103, 120, 135, 155
+, 156, 203
31) 858 OK (sz=6, trgt= 852.0, [840-900]) 89, 111, 114, 115
+, 118, 311
|