简体   繁体   English

将两个计算与lp_solve结合(线性编程)

[英]Combine two calculations with lp_solve (linear programming)

I am new to lp_solve. 我是lp_solve的新手。 I would like to combine these two calculations, (because the raw materials are the same...) 我想将这两个计算结合起来,(​​因为原料相同...)

First Production: 首次生产:

    min: 13.21 x0 + 27.46 x1 + 35.66 x2 + 89.21 x3 + 60.69 x4;

    x0 + x1 + x2 + x3 + x4 >= 200000;

    x0 <= 69148;
    x1 <= 25460;
    x2 <= 34020;
    x3 <= 69873;
    x4 <= 737299;

    -0.425 x0 + 0.086 x3 + -0.003 x4 >= 0;
    /* 0.175*x0 + 0.60*x1 + 0.60*x2 + 0.686*x3 + 0.59745*x4 >= (x0 + x1 + x2 + x3 + x4)*0.6 */

Second Production: 第二次生产:

    min: 13.21 y0 + 27.46 y1 + 35.66 y2 + 89.21 y3 + 60.69 y4;

    y0 + y1 + y2 + y3 + y4 >= 50000;

    y0 <= 69148;
    y1 <= 25460;
    y2 <= 34020;
    y3 <= 69873;
    y4 <= 737299;

    -0.275 y0 + 0.15 y1 + 0.15 y2 + 0.236 y3 + 0.14745 y4 >= 0;
    /* 0.175*y0 + 0.60*y1 + 0.60*y2 + 0.686*y3 + 0.59745*y4 >= (y0 + y1 + y2 + y3 + y4)*0.45 */

My solutions: 我的解决方案:

    min: 13.21 x0 - 13.21 y0
       + 27.46 x1 - 27.46 y1
       + 35.66 x2 - 35.66 y2
       + 89.21 x3 - 89.21 y3
       + 60.69 x4 - 60.69 y4;

    x0 + x1 + x2 + x3 + x4 >= 200000;
    y0 + y1 + y2 + y3 + y4 >= 50000;

    x0 + y0 <= 69148;
    x1 + y1 <= 25460;
    x2 + y2 <= 34020;
    x3 + y3 <= 69873;
    x4 + y4<= 737299;

    -0.425 x0 + 0.086 x3 + -0.003 x4 >= 0;
    -0.275 y0 + 0.15 y1 + 0.15 y2 + 0.236 y3 + 0.14745 y4 >= 0;

returns a strange result: 返回一个奇怪的结果:

    x0 0
    y0 69148
    x1 25460
    y1 0
    x2 34020
    y2 0
    x3 4736.62921348315
    y3 65136.3707865169
    x4 135783.370786517
    y4 601515.629213483

when I sum x and y: 当我对x和y求和时:

    x = 200,000 (okay)
    y = 735,800 (not 50,000!)

so I use the whole stock... instead of 250.000... 所以我用全部库存...而不是250.000 ...

In your combined objective function: 在合并的目标函数中:

min: 13.21 x0 - 13.21 y0
   + 27.46 x1 - 27.46 y1
   + 35.66 x2 - 35.66 y2
   + 89.21 x3 - 89.21 y3
   + 60.69 x4 - 60.69 y4;

You're subtracting the y objective function from the x objective function, instead of adding them. 您是从x目标函数中减去y目标函数,而不是将它们相加。 And since you're telling it to minimize, the solver happily tries to maximize your original y objective, instead of minimize. 而且由于您要告诉它最小化,所以求解器会很乐意尝试使原始的y目标最大化,而不是最小化。

If instead you use: 如果改为使用:

min: 13.21 x0 + 13.21 y0
   + 27.46 x1 + 27.46 y1
   + 35.66 x2 + 35.66 y2
   + 89.21 x3 + 89.21 y3
   + 60.69 x4 + 60.69 y4;

You get results of: 您得到以下结果:

x0                              0
x1                          25460
x2                          34020
x3                        4736.63
x4                         135783
y0                        17451.8
y1                              0
y2                              0
y3                              0
y4                        32548.2

So x is basically 200000 and y is 50000, as you hoped. 因此,正如您所希望的, x基本上是200000, y是50000。

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

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