Subset sum problem where each number can be added or subtracted

不问归期 提交于 2019-12-04 20:42:51

You can solve it by using Boolean Integer Programming. There are several algorithms (e.g. Gomory or branch and bound) and free libraries (e.g. LP-Solve) available.

Calculate the sum of the list and call it s. Double the numbers in the list. Say the doubled numbers are a,b,c. Then you have the following equation system:

Boolean x,y,z 

a*x+b*y+c*z >= s

Minimize ax+by+cz!

The boolean variables indicate if the corresponding number should be added (when true) or subtracted (when false).

[Edit]

I should mention that the transformed problem can be seen as "knapsack problem" as well:

Boolean x,y,z 

-a*x-b*y-c*z <= -s

Maximize ax+by+cz!
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!