Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

binary LP vs. integer LP

I wonder why there is a difference between the following linear programs. They are written in the LP file format. I would assume that x=1 would be the optimal solution in both cases.

Program A:

min: x;
x >= 1;
bin x;

Output:

Value of objective function: 0

Actual values of the variables:
x                               0

Program B (simulates the binary constraint with the integer constrain and two additional constrains):

min: x;
x >= 1;
x <= 1;
x >= 0;
int x;

Output:

Value of objective function: 1.00000000

Actual values of the variables:
x                               1
like image 433
someonr Avatar asked Feb 17 '26 09:02

someonr


1 Answers

Yes, this is a small quirk of lpSove having to do with single variable constraints.

In your Problem A, setting 'bin x' ends up overriding the constraint 'x >=1.' That is why 0 is given as the optimal solution.

From the documentation:

Note that for bounds on variables, you should not put labels before them. This is because lp_solve then makes this an extra restriction. If you don't put a label before single variables then lp_solve doesn't have to create an extra row for bounds on variables, resulting in better performance.

So it is better to write:

 x1 >= 1;

than

 r_x1: x1 >= 1;

Note that this is only for single variables, so myrow: x1 + x2 >= 2;

performs as well as

x1 + x2 >= 2;

In your Problem A, you have a single variable constraint. When it is not explicitly named, the 'bin' declaration overrides that constraint. As you rightly point out, if you make the constraint explicit, by naming it, then lpSolve will create a new row for x1, thus honoring the constraint and the 'bin' cannot override it.

min: x;
a: x >= 1.0;
bin x;

will give you:

Value of objective function: 1.00000000

Actual values of the variables:
x                               1
like image 177
Ram Narasimhan Avatar answered Feb 20 '26 10:02

Ram Narasimhan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!