简体   繁体   English

这是什么算法?

[英]What kind of algorithm is this?

What kind of algorithm is this, I know pretty much nothing but this is what I'm trying to do in code... I have class 'Item', properties int A and int B -- I have multiple lists of List<Item> with a random amount of Item in each list, incosistent with any other List. 这是什么类型的算法,我几乎什么都不知道,但这是我在代码中尝试做的...我有类'Item',属性int Aint B - 我有多个List<Item>每个列表中包含随机数量的Item ,与任何其他列表无关。 I must choose 1 item from each list to get the highest possible value of the sum Item.A while conforming that the sum of Item.B must also be at minimum a certain number. 我必须从每个列表中选择1个项目拿到的总和最高可能值Item.A同时符合这总和Item.B还必须在最小的一定数量。 In the future there might also be another property Item.C to conform to that the sum must be equal to a certain number. 在将来可能还有另一个属性Item.C以符合总和必须等于某个数字。 I have no idea how to write this :( 我不知道怎么写这个:(

So to put it this way; 所以这样说吧;

class Item
  int A
  int B
  int C

I have a 10x different List<Item> each with a random number of Item inside 我有一个10x不同的List<Item>每个都有一个随机数的Item里面

We must find the exactly the best combination to have 我们必须找到最合适的组合

a) Highest sum of Item.A
b) Constraint that the sum of Item.B must be higher than X
c) Constraint that the sum of Item.C must be equal to X

I have no idea how to code this to be fast and efficient. 我不知道如何编写这个快速高效的代码。 :( :(

As mentionend in my comment, this is a Binary Programming problem, which can be cast as a multi-dimensional Knapsack problem . 正如我在评论中提到的,这是一个二进制编程问题,可以作为一个多维背包问题 I would first try to solve it with an off-the-shelf Mixed Integer Programming (MIP) solver like the one suggested by Lieven in one of his comments ( lpSolve ), given that you "only" have got some 100-200 binary variables. 我首先尝试使用现成的混合整数规划(MIP)求解器来解决它,就像Lieven在他的一条评论( lpSolve )中建议的那样 ,假设你“只”得到了100-200个二元变量。 You might have to play a little bit around with the parameters. 你可能需要玩一些参数。 Some MIP solvers allow you to add search heuristics, which might be helpful. 某些MIP求解器允许您添加搜索启发式,这可能会有所帮助。 Given your constraints, I must admit I don't have a feeling how long a standard MIP solver will take, but I wouldn't hold my breath. 考虑到你的限制,我必须承认我没有感觉标准MIP求解器需要多长时间,但我不会屏住呼吸。

If a mixed-integer programming solver is not fast enough for you, you want to look at some more specialised algorithms. 如果混合整数编程求解器不够快,您需要查看一些更专业的算法。 For your problem, the ones presented in Knapsack Problems , chapter 11.10 on the multiple-choice Knapsack problem (almost exactly your problem) and chapter 9 are relevant. 对于你的问题, 背包问题中提出的问题 ,第11.10章关于多选背包问题(几乎就是你的问题)和第9章是相关的。

Edit: based on your comments, the good news is that your data ranges are pretty good and the problem seems solvable in a reasonable time. 编辑:根据您的评论,好消息是您的数据范围非常好,问题在合理的时间内似乎是可以解决的。 This paper ( DOI in case the link vanishes) presents an algorithm that according to the authors solves problems of your size within seconds (see section 4.4 and 5.1). 本文DOI在链接消失的情况下)提出了一种算法,根据作者在几秒钟内解决了你的大小问题(见4.4和5.1节)。 The bad news is that it contains a lot of math... 坏消息是它包含了很多数学...

I posted this question as an unregistered user and after clicking register, it didn't associate my unregistered user with my registered user, nice =/ 我将此问题作为未注册的用户发布,在点击注册后,它没有将我的未注册用户与我的注册用户关联,很好= /

In regards to the comment by van: 关于范的评论:

Typically there will be about 14 lists or so Within each list there will be usually around 5-15 'Items' Each item has those 3 properties. 通常会有大约14个列表左右在每个列表中通常会有大约5-15个“项目”每个项目都有这3个属性。 We must exactly 1 item from each list. 我们每个列表中必须有1个项目。 We are looking for the maximum value of PropertyA when we calculate the sum of all PropertyA after choosing one item from each list The constraints are PropertyB and PropertyC which the chosen combination must confirm too, once again using the sum of the values across the combination. 我们在从每个列表中选择一个项目后计算所有PropertyA的总和时,我们正在寻找PropertyA的最大值。约束是PropertyB和PropertyC,所选组合也必须确认,再次使用组合中的值之和。

It must also be the most optimal solution, not an approximation. 它也必须是最佳解决方案,而不是近似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM