给出具有价格和价值的大项目清单,选择10个项目中最便宜的组合,其平均值大于或等于固定值

时间:2016-01-23 23:33:16

标签: algorithm math language-agnostic combinations

我不是计算机科学专业,所以我对算法知之甚少。最近我在考虑某种类型的市场机器人,我有一个关键问题,我无法用蛮力处理。

Question: Let there be a list of items, where number of items are greater
than 10000. Each item has a value in between 0 and 1, and a price. Value and
price are independent of each other. You must choose the cheapest 10 items
where their average (or total) value is greater or equal than a given value.

我想到了几种算法,例如:

-Sort the list by price
-Divide the list in 5 item chunks, reducing the brute
force steps from 10000nCr10 to 2000nCr2.

显然它不会给出真正最便宜的组合,但希望足够接近?我感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

您可以使用整数线性编程来解决它。设项i的值为v [i],其成本为c [i]。设x [i]是您购买的每个项目的编号(可以取值0或1),V是可接受的最小总值。 x [i]上的0/1约束使得这是一个整数线性程序而不是更简单的线性程序。

那么你想要最小化和(c [i] * x [i])使得和(v [i] * x [i])> = V和sum(x [i])= 10,其中是一个正确形式的问题,作为ILP解决。

这是一个很好的开源解算器:https://www.gnu.org/software/glpk/