Click here to Skip to main content
16,016,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
This is difficult one to explain but here goes. I have a list of numbers which are to be set over a set number of column (Pre-determined by another calulation). The task it to move the number around till the shortest column height (Numbers are additionalised in each column to give height).

I told you it was not going to be easy to explain.

What is the best way to process this to get the column lists?

Ex:- Numbers (232,277,432,200,200,220,500,490,286,478) & Column Count is 4 (Note:- Not always are they evenly balanced by quantity).

Think of it as you can move the numbers from column to column but the aim to to get the lowest average of the sum of the column across all columns.

Ideal would (Not as per example):- Col=200,300,300 Col2=200, 400, 100, 50 Col3= 200, 300, 200 Col4=300, 200, 50, 200

Column sum
Col1=800
Col2=750
Col3=700
Col4= 750

i.e. move the lengths around to make the shortest column.



Thanks in advance.

OK, Realtime numbers
432
432
432
305
205
205
205
205
205
205
150
150
150

4 columns/pots (making an target 820 per each pot)

I hope this helps

What I have tried:

Sorry I have no trys to show as I must confess I don't realy know where to start (Any pointer are welcome).

New Try,
1) Order list to larger -> Smaller
2) Workout the Best average.
3) Add to each column (In order) largest
4) when all have first run add smallest to largest but not if largest is greater or equal to Best average.

I'm unsure if this is the best approach but it is best way I can visualise the process. Turning it into code is another issue.

Hi, Sorry for the delay in writting this up.
I have worked out a solution from the input here & thought it good to pass it on where I got to (If someone has a simular issue it may come in handy)

Steps:-
1) Sort coins with larger first.
2) Add one coin to each pot (From larger to Smaller) i.e. only one coin per pot at this stage.
3) Put the largest coin in the smallest pot till all coins have gone.

This worked for me & I hope it works for others.
Posted
Updated 17-Jan-24 8:37am
v9
Comments
Richard MacCutchan 28-Dec-23 9:16am    
The first thing I would do is to sort the numbers into ascending order. It is then a few simle calculations to find the lowest or highest set. But it is not exactly clear what actual result you are trying to find.
Knight school 28-Dec-23 10:01am    
Hi,
Thanks for the reply, As I said it is difficult to explain. I Have updated the question. Hopefully helps
Richard MacCutchan 28-Dec-23 10:20am    
Well I still don't understand what the rules are for moving the numbers, or how many numbers are required (or limited to) in each column. For example, why is one column not just [ 50 ]?
0x01AA 28-Dec-23 10:07am    
I think it is necessary you make a (better two) consistent example.
Also please explain among other why Col2 results in 700 (and not what I would assume in 750)
Knight school 28-Dec-23 10:21am    
My mistake. Col2 corrected.
I will look at the examples but I'm unsure of the output as it is optermisation (Not realy something I can workout). Thanks again.

1 solution

I think what you have is a "multiple" knapsacks problem. (Find a link that works for you if not this one).

Solving a Multiple Knapsacks Problem  |  OR-Tools  |  Google for Developers[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900