Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^12: Tricky chemicals optimization problem

by BrowserUk (Patriarch)
on Jan 11, 2017 at 23:02 UTC ( [id://1179428]=note: print w/replies, xml ) Need Help??


in reply to Re^11: Tricky chemicals optimization problem
in thread Tricky chemicals optimization problem

I can answer these two questions tonight, the others will have to wait until Friday.

Which array is this in the code you provided?

If you look at the second block of output (100,000 nearest to your 85,000 machine limit) in Re^6: Tricky chemicals optimization problem, and I reformat the first line for machine E001 thus:

E001 => { " total" => 99982.9104, C015 => [24504.1632, 14837.91, 13323.6396, 12250.6656, 6234.5772, +5720.64, 5255.838, 4380.3252, 3468.138, 2386.0308, 1716.192, 1501.668 +, 1436.2488, 1430.16, 791.19, 703.4688], C064 => [42.0552] },

You can see that although the machine has 17 flows from the original dataset, they are made up of just two chemicals. So, by your latest description, that machine only requires two nozzles.

I hear what you are saying but I'm failing to see what the gap might be if we made minimizing the lines higher precedence... I.e., is the fact that your code is doing a good job of minimizing the nozzles a side effect of the operation , or are you purposefully designing it to do that -if so can you point out the line that provides that effect?

The fact that the loops of code attempt to fill each machine from flows of Cnnn first (largest first due to the sorting), and only switches to other chemicals when there are either no flows for this chemical left; or there are no flows of the current chemical that will fit in the remaining space, means that the very act of attempting to use the minimal number of machines will also ensure that each chemical is spread to as few machines as possible (within the limitations of the greedy algorithm).

The upshot of that is that is all the flows of particular chemical on any given machine can be combined into one nozzle; and thus minimizing the number of machines also tends to minimize the number of nozzles. (Again, within the limitations of the greedy algorithm.

Those greedy algorithm limitations mean that it may be possible to reduce the nozzle count a little by juggling the smaller components around; but it will only be a very small percentage.

If that was actually necessary; then you move into the realms of either:

  • Genetic programming:

    Try swapping a few things around in a few random combinations and then discard the some of the least good ones. Rinse and repeat until either no further improvement has been seen for some number of iterations; or until some time limit is reached.

  • A full brute force, exhaustive search.

    This method is guaranteed to find the absolute optimum solution. Eventually! But even for the relatively small number of thing you are dealing with, it is apt to take many days or even weeks to run.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice.
div

Replies are listed 'Best First'.
Re^13: Tricky chemicals optimization problem
by Anonymous Monk on Jan 16, 2017 at 01:55 UTC

    Hey UK, Is there any chance you can suggest which parts of the code I need to focus on to accomplish the change to minimizing nozzles before minimizing number of machines? Even if it's simpler to minimize nozzles and not worry about machines I can probably take it further from that point - I'm a bit stuck at the moment

    thanks again for the help /thoughts
      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.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Ok I think I am following..... - I will also try to code it and see how far I can get. Just to make it easier problem don't even worry about minimizing number of machines at all. I can go back and tinker later. And thanks again.... I realize how much time you're already given to this post, and it's very appreciated.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1179428]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found