这是整数规划吗?

发布于 2024-11-03 22:32:15 字数 129 浏览 3 评论 0原文

问题: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 技术交流群。

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

发布评论

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

评论(4

怪我闹别瞎闹 2024-11-10 22:32:15

是的,这是一个整数规划问题。您可以将其写为:

   minimize  |x1 - x2| + |x2 - x3| + ... + |xn-1 - xn|

   subject to  x1 + x2 + x3 + ... + xn == c,

               xi == Ai1*yi1 + Ai2*yi2 + ... + Aip*yip, i=1,...,n,

               yi1 + yi2 + ... + yip == 1, i=1,...,n,

               yij binary for i=1,...,n  j=1,...,p,

               xi integer for i=1,...,n,

这里 Aij 是已知的输入数据,描述 xi 的特定值可能采用哪些整数。下面是一个包含 3 个变量 (n=3) 的具体示例,其中每个 xi 可以采用两个整数值之一 (p=2)。也就是说,x1 可以是 1 或 3,x2 可以是 3 或 4,x3 可以是 2 或 3。

    minimize  |x1 - x2| + |x2 - x3| 

    subject to  x1 + x2 + x3 == 8, 

                x1 == 1*y11 + 3*y12, 
                x2 == 3*y21 + 4*y22,
                x3 == 2*y31 + 3*y32,

                y11 + y12 == 1, 
                y21 + y22 == 1,
                y31 + y32 == 1,

                yij binary i=1,2,3 j=1,2
                xi integer i=1,2,3

您可以通过创建将上述问题重新表述为 MIP(混合整数规划)
一组新的变量 u 来表示目标函数。

    minimize   u1 + u2 + ... + un 

   subject to  ui >= xi - xi+1, i=1,...,n-1,

               ui >= xi+1 - xi, i=1,...,n-1,

               x1 + x2 + x3 + ... + xn == c,

               xi == Ai1*yi1 + Ai2*yi2 + ... + Aip*yip, i=1,...,n,

               yi1 + yi2 + ... + yip == 1, i=1,...,n,

               yij binary for i=1,...,n  j=1,...,p,

               xi integer for i=1,...,n,
               ui real    for i=1,...,n-1,

您可以使用任何标准的 MIP 求解器来解决上述问题。

Yes this is an integer programming problem. You can write it as:

   minimize  |x1 - x2| + |x2 - x3| + ... + |xn-1 - xn|

   subject to  x1 + x2 + x3 + ... + xn == c,

               xi == Ai1*yi1 + Ai2*yi2 + ... + Aip*yip, i=1,...,n,

               yi1 + yi2 + ... + yip == 1, i=1,...,n,

               yij binary for i=1,...,n  j=1,...,p,

               xi integer for i=1,...,n,

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.

    minimize  |x1 - x2| + |x2 - x3| 

    subject to  x1 + x2 + x3 == 8, 

                x1 == 1*y11 + 3*y12, 
                x2 == 3*y21 + 4*y22,
                x3 == 2*y31 + 3*y32,

                y11 + y12 == 1, 
                y21 + y22 == 1,
                y31 + y32 == 1,

                yij binary i=1,2,3 j=1,2
                xi integer i=1,2,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.

    minimize   u1 + u2 + ... + un 

   subject to  ui >= xi - xi+1, i=1,...,n-1,

               ui >= xi+1 - xi, i=1,...,n-1,

               x1 + x2 + x3 + ... + xn == c,

               xi == Ai1*yi1 + Ai2*yi2 + ... + Aip*yip, i=1,...,n,

               yi1 + yi2 + ... + yip == 1, i=1,...,n,

               yij binary for i=1,...,n  j=1,...,p,

               xi integer for i=1,...,n,
               ui real    for i=1,...,n-1,

You can use any standard MIP solver to solve the above problem.

还在原地等你 2024-11-10 22:32:15

这似乎是 np 完全问题,实际上您需要搜索整个解决方案空间才能获得正确的分布。也许可以试试这个

I。贪婪算法

foreach x in xses
   if current_sum < desired_sum:
       take maximal p for x
   else take_minimal p for x

正如您所看到的,这不会给您带来正确的解决方案,可能您的 SUM 会大于 DESIRED_SUM,

但在此之后您可以开始优化您的分布:
现在我们已经有了一组贪婪选择的 xses,

foreach x:
   if current_sum > desired_sum
       change taken P to minimal P for x
   else
     break

这将使您结束解决方案

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

foreach x in xses
   if current_sum < desired_sum:
       take maximal p for x
   else take_minimal p for x

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

foreach x:
   if current_sum > desired_sum
       change taken P to minimal P for x
   else
     break

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

誰認得朕 2024-11-10 22:32:15

您对整数有任何限制(或额外信息)吗?如果它们不太大,则可以采用一种算法来遍历所有可能的总和(无需进行所有组合):(

function adds_up_to(xs, N):
    sums := {0}
    for i from 1 to n:
        new_sums := {}
        for sum in sums:
            for value in values:
               new_sums := new_sums U {sum + value}
        sums := new_sums
    return (N in sums)

这只是搜索令人满意的解决方案。需要加强该算法以处理差异-最小化,无论这意味着什么)

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):

function adds_up_to(xs, N):
    sums := {0}
    for i from 1 to n:
        new_sums := {}
        for sum in sums:
            for value in values:
               new_sums := new_sums U {sum + value}
        sums := new_sums
    return (N in sums)

(This just searches for a satisfying solution. The algorithm needs to be beefed up to handle the difference-minimizing, whatever that means)

红墙和绿瓦 2024-11-10 22:32:15

至于目标函数,当你想最小化集合之间的差异时,这是一个技巧。简单的形式可以是 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.

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