确定最佳组合的算法 - Bin Packing

发布于 2024-09-18 20:05:37 字数 414 浏览 3 评论 0原文

给定一组项目,每个项目都有一个值,确定要包含在集合中的每个项目的数量,使总价值小于或等于给定限制,并且总价值尽可能大。

示例:

Product A = 4
Product B = 3
Product C = 2
Product D = 5

If Total Capacity = 10.5 , then the combination of B,C,D will be selected.
If Total Capacity = 12.5 , then the combination of A,B,D will be selected.
If Total Capacity = 17 , then the combination of A,B,C,D will be selected.

我正在寻找一种算法(如背包或装箱)来确定组合。任何帮助表示赞赏。

Given a set of items, each with a value, determine the number of each item to include in a collection so that the total value is less than or equal to given limit and the total value is as large as possible.

Example:

Product A = 4
Product B = 3
Product C = 2
Product D = 5

If Total Capacity = 10.5 , then the combination of B,C,D will be selected.
If Total Capacity = 12.5 , then the combination of A,B,D will be selected.
If Total Capacity = 17 , then the combination of A,B,C,D will be selected.

I am looking for an algorithm (like knapsack or bin packing) to determine the combination. Any help appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2024-09-25 20:05:37

你说这是“像背包”。据我所知,这是有界背包问题的特殊情况,称为0-1背包问题。

它是 NP 完全的。

您可以尝试多种方法来解决该问题。请参阅此相关问题了解一种方法:

如果您只有四个项目,那么对于大多数用途来说,仅测试所有可能性就足够快了。

You say that this is "like knapsack". As far as I can see it is a special case of bounded knapsack problem called the 0-1 knapsack problem.

It is NP-complete.

There are lots of ways you could attempt to solve it. See this related question for one approach:

If you only have four items then just testing all possibilities should be fast enough for most purposes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文