The constant combinator set the amount of ressource desired in the steel chest (or in any readable container), the + arithmetic combinator just transforms the signal into a control signal (C) since the signal to control stack size has to be specific
For several ressource, the simplest solution is probably to put one inserter per ressource.
However, my question arise as I plan to make a train supply station which would send train to outpost sending them not only regular supply when needed (eg repair pack), but also building material, so that I don't have to carry it (or even to assist the build). So I may need significant diversity (> 12 diff items, 12 being the max number of inserters per wagon), and a significant quantity of materials, hence my need of speed, although probably less than 40 stacks (so only one wagon needed). Also, on the unloading side, some items might be needed in small quantities (eg construction bots, belt splitters), and I would like to avoid overkill hence my need of precision.
Here is what I produced :
The wooden chest represents the input (should have been a constant combinator), and the stack filter inserter the output (has to be a filter inserter, stack or not, set to "set filter" and "set stack size"). Each line represent a threshold (1,2,5,12) : if any input is 1 or bigger, the top comparator outputs 1 in the control signal C. If any input is 2 or bigger, the second top comparator outputs 1 in the control signal C, and the multiplier multiplies it by 1, so that the signal C is at 2 (when we add the one outputted by the comparator of the first line). And so on. The top right comparator takes the input as well as C as input and cuts off signals lower than C (in particular C passes), so that, when C controls the stack size, only inputs big enough will be able to set the filter.
If you have the maximum stack size available (12) and have to load 20 copper plates and 2 iron plates, it will first load 12 copper plates, then 5 copper plates, then the 2 iron plates (because the iron plate appears before in the object list, as seen in the inventory! the fact that there are more copper plate left does not matter), then 2 copper plates then the last 1. So it is not optimal but close enough. We can optimise by adding up to 12 thresholds, but it saves at most two insertions per item type. Take note I have chosen the thresholds evenly spaced between 1 and 12, geometrically speaking.
blueprintI guess one could also have used the binary decomposition, but I'm not sure it is worth it for so small number, and I'm also afraid it is not as paralellizable as my solution, and may have a significant delay.
I'm eager to know if anyone has a better or different way to achieve the same task or a similar one, especially how to deal with several inserters (a simple fix is to count what inserters hold as already in the inventory you have to load, but you need to desync the inserters to avoid overload, I don't know how to efficiently do that).