I am new to 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 = 200,000 (okay)
y = 735,800 (not 50,000!)
so I use the whole stock... instead of 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. And since you're telling it to minimize, the solver happily tries to maximize your original y
objective, instead of minimize.
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.