I am having balancing trouble. I feel like I'm missing something here..
This problem equates to the following situation:
My best attempt at maximizing point gain so far is:
My problem is: This works, but it is slow. I get skipped frames on Android 4.4.4 with only 7 weights selected, on a Galaxy Note 4.
I feel like I'm missing some crucial time-saver in the problem domain, but for the life of me I feel blind to it. So, how would you solve this particular puzzle?
Thanks!
This problem is a variation of the bin-packing problem.
Bin packing problem in a nutshell:
Given a set of items, each with weight
wi, a bin capacityT, and a (natural) numberk- find out if you can use at mostkbins, where each contains elements with weight sumT, such that all elements are covered.
Your problem is a very close variation of it, and somewhat a generalization of it:
Your problem is definetly NP-Complete, and a reduction is simple from binpacking or even from subset-sum-problem.
Moreover, since the binpacking problem is Strongly NP-Complete problem, and the similarity of the two problems is too large to ignore, I believe this problem is also Strongly-Np-Complete, which means there is no known pseudo-polynomial solution to it as well.
This is a bad news, and it means a brute force solution, similar to what you have done, is the way to go.
You can also try to solve it with linear programming, and follow the optimization equations:
maximize:
sum {y_i * T_i}
s.t.:
sum { x_i,j * w_j | sum over all j's} = y_i * T_i for all i
sum { x_i,j | sum over all i's } <= 1 for all j
x_i,j =0,1
y_i =0,1
Unfortuntaely, finding optimal solution to integer linear programming equations is also done in exponential time in worst case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With