这是整数规划吗?
问题:n 个变量 (x) 加起来是一个常量。 x1+x2+..+xn = const,其中每个 x 只能取 p(比如 5)个正整数值。我们想要找到 x 之间的差异最小化的解决方案,即它们分布最均匀。这是整数规划问题吗?
dlm
The problem: n variables (x) add up to be a constent. x1+x2+..+xn = const, where each x can only take p (say 5) positive integer values. We want to find the solution where the difference between x's are minimized, i.e. they are most evenly distributed. Is this an integer programming problem?
dlm
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,这是一个整数规划问题。您可以将其写为:
这里 Aij 是已知的输入数据,描述 xi 的特定值可能采用哪些整数。下面是一个包含 3 个变量 (n=3) 的具体示例,其中每个 xi 可以采用两个整数值之一 (p=2)。也就是说,x1 可以是 1 或 3,x2 可以是 3 或 4,x3 可以是 2 或 3。
您可以通过创建将上述问题重新表述为 MIP(混合整数规划)
一组新的变量 u 来表示目标函数。
您可以使用任何标准的 MIP 求解器来解决上述问题。
Yes this is an integer programming problem. You can write it as:
here the Aij are known input data that describe what integers a particular value of xi may take on. Below is a concrete example with 3 variables (n=3), where each xi can take on one of two integer values (p=2). That is x1 can be 1 or 3, x2 can be 3 or 4, x3 can be 2 or 3.
You can reformulate the above problem as a MIP (a mixed integer program) by creating
a new set of variables u to represent the objective function.
You can use any standard MIP solver to solve the above problem.
这似乎是 np 完全问题,实际上您需要搜索整个解决方案空间才能获得正确的分布。也许可以试试这个
I。贪婪算法
正如您所看到的,这不会给您带来正确的解决方案,可能您的 SUM 会大于 DESIRED_SUM,
但在此之后您可以开始优化您的分布:
现在我们已经有了一组贪婪选择的 xses,
这将使您结束解决方案
II。进化算法
对问题的严格定义使您可以使用遗传算法。
总体将是 X=[x1,x2,x3,x4...xn] 的向量
适应度函数很明显(期望总和与 X 计算总和之间的差异)
只需对向量进行适当的进化操作,它应该在短时间内为您带来优化的解决方案
It seems to be np-complete problem, at real you need to search whole space of solutions to get proper distribution. Maybe try this
I. Greedy algorithm
As you see this will not bring you to proper solution, probably you will have some SUM greater than DESIRED_SUM
but after this you can start to optimize your distribution:
now we have set of greedy selected xses
this will bring you to close solution
II. Evolutionary algorithm
Strict definition of your problem brings you to genetic algorithms.
Populations will be vectors of X=[x1,x2,x3,x4...xn]
fitness function it's obvious (difference between desired sum and computed sum from X)
just do proper evolutionary operations on vectors and it should bring you to optimized solution in short time
您对整数有任何限制(或额外信息)吗?如果它们不太大,则可以采用一种算法来遍历所有可能的总和(无需进行所有组合):(
这只是搜索令人满意的解决方案。需要加强该算法以处理差异-最小化,无论这意味着什么)
Do you have any bounds (or extra info) on the integers? If they aren't too big, it can be feasible to do an algorithm that goes through all possible sums (without doing all the combinations):
(This just searches for a satisfying solution. The algorithm needs to be beefed up to handle the difference-minimizing, whatever that means)
至于目标函数,当你想最小化集合之间的差异时,这是一个技巧。简单的形式可以是 Sum(ABS(Xi-Xj)),其中 i>j。可以线性化。但是,如果您想使用示例变体,那么这将成为 QIP,并且需要花费更多时间来解决。
As for the obejctive function, it is trick when you want to minimize the difference among the set. The simple form could be the Sum(ABS(Xi-Xj)) where i>j. which can be linearized. However if you want to use sample variant, that would become a QIP and a bit more time consuming to solve.