which parts of the code I need to focus on to accomplish the change to minimizing nozzles before minimizing number of machines?
Well, the minimum number of nozzles is simply the number of chemicals; plus that number required to ensure that no single nozzle is delivering more than your machine limit.
This code, simply reads your sample data, discards any 'zero flows' and accumulates all flows for each chemical.
The provisional result is that there are 406 non-zero flows for 61 chemicals. But, some of those chemicals have combined flows that are greater than the 85,000 seconds/machine you've stipulated. Those need to be split across 2 or more machines. Doing so results in a requirement for 71 machines to dispense the 61 chemicals:But now, some of the machines (eg.those running C057 & C039) are grossly under-utilised and those chemicals need to be combined into fewer machines.
The simplest approach to that is a variation of the greedy knapsack algorithm which I will call (because I haven't seen it described anywhere) and the max-min algorithm.
Basically you order the nozzles largest to smallest. You look at the largest and then track backward from the smallest until you find the largest (single chemical) nozzle that can be combined with that largest nozzle without breaking the machine limit. Combine them into a single machine and remove the small one from them from consideration. Rinse and repeat. When the smallest left is too big to be combined, remove the current largest from consideration also. Rinse and repeat until no nozzles are left.
This isn't guaranteed to produce the absolute optimal solution in terms of minimizing the number of machines, but it will always produce the minimum number of nozzles and very close to the minimal number of machines.
I don't have code for this approach this evening, but I'll try to post some tomorrow.
In reply to Re^14: Tricky chemicals optimization problem
by BrowserUk
in thread Tricky chemicals optimization problem
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |