I am still working on a solution for you. I don't think you appreciate how technically complicated this is to do. Essentially you need to find every possible sum combination that either equals the *capacity* or sum as close as possible to *capacity* without being greater than *capacity*. I am having to use a recursive procedure to do this which I have been able to do with the help of some code written by someone very clever. I attempted to use the Solver Add In however I could not get it to give me the results I need by using binary constraints method.

I will post something for you soon unless someone else picks this up. Your suggested solution while being a consideration will not give you the correct result.

As I say this is a very complex problem. The recursive solution is very fast however when finalised how large will the data set be?

As an example what you are asking is to test every combination of a set of numbers to see if it sums less than or equal to a number. To follow is a succinct VB.net example that does not take into consideration the constraints you are requesting - this simply calculates every sum possibility for an array - remember that the sum can be generated from 1 number or all numbers so coding for the conditions is a challenge. Just google **subset sum problem** and you will appreciate the complexity of your request.

This is certainly a challenge.

Remember to follow is a VB.net sample and certainly not the solution but is part of the solution

## Bookmarks