I have a number of chunks of data.
For arguments sake we'll say they are
File 1 - 150Kb
File 2 - 50Kb
File 3 - 70Kb
File 4 - 60Kb
File 5 - 70Kb
File 6 - 100Kb
File 7 - 90Kb
For transmission, I can package these up into a max payload of 300Kb.
If you just iterate through them in order you'd get
TRANS1: 150Kb + 50Kb + 70Kb = 270Kb - the next file puts you over the limit of 300Kb
TRANS2: 60Kb + 70Kb + 100Kb = 230Kb - the next file puts you over the limit of 300Kb
TRANS3: 90Kb
So three seperate transmissions.
But if you re-organise them, you can send
Files 1,2,6 together = 300Kb
Files 3,4,5,7 together = 290Kb
So you cut the number of separate transmissions needs. Since there's a monetary cost associated with each transmission (these transmissions are actually API calls to a 3rd party system, where we're billed per API Call) we'd like to keep the number of separate payload sends to a minimum.
Is there any sorting algorithm out there around this kind of optimization, that will take a list of weighted objects, and sort/group them so you end up with fewest number of groups
For reference, I'd be coding this up in .NET but if you can provide and example in another language or psuedo-code implementation/description, that'd be great also.
Thanks, Eoin C