Question

I am wondering whether any one here uses lpsolve to solve linear programming problem.

I have defined a integer linear programming problem in a file where there is a constraint x45=0(there are also other integer variables). After the problem is solved by lpsolve, the result reported strangely is x45=1. However, if I put a label before the constraint, for example, c1:x45=0, then the constraint will be met. Anyone here know what's going on?

So the problem I defined in my LP file is like:

max: 0 x0 262 x1 262 x2 262 x3 262 x4 262 x5 262 x6 262 x7 270 x8 0 x9 270 x10 270 x11 270 x12 270 x13 270 x14 270 x15;
549 x16 549 x17 0 x18 549 x19 549 x20 549 x21 549 x22 549 x23 >= 1; 
603 x24 603 x25 603 x26 0 x27 603 x28 603 x29 603 x30 603 x31 >= 1;
x0=0;
x9=0;
x18=0;
x27=0;
x36=0;
x45=0;
x54=0;
x63=0;
x0=x0; x1=x8; x2=x16; x3=x24; x4=x32; x5=x40; x6=x48; x7=x56; x8=x1; x9=x9; x10=x17; x11=x25; x12=x33; x13=x41; x14=x49; x15=x57; x16=x2; x17=x10; x18=x18; x19=x26; x20=x34; x21=x42; x22=x50; x23=x58; x24=x3; x25=x11; x26=x19; x27=x27; x28=x35; x29=x43; x30=x51; x31=x59; x32=x4; x33=x12; x34=x20; x35=x28; x36=x36; x37=x44; x38=x52; x39=x60; x40=x5; x41=x13; x42=x21; x43=x29; x44=x37; x45=x45; x46=x53; x47=x61; x48=x6; x49=x14; x50=x22; x51=x30; x52=x38; x53=x46; x54=x54; x55=x62; x56=x7; x57=x15; x58=x23; x59=x31; x60=x39; x61=x47; x62=x55; x63=x63; x0 x1 x2 x3 x4 x5 x6 x7=1; x8 x9 x10 x11 x12 x13 x14 x15=1; x16 x17 x18 x19 x20 x21 x22 x23=1; x24 x25 x26 x27 x28 x29 x30 x31=1; x32 x33 x34 x35 x36 x37 x38 x39=1; x40 x41 x42 x43 x44 x45 x46 x47=1; x48 x49 x50 x51 x52 x53 x54 x55=1; x56 x57 x58 x59 x60 x61 x62 x63=1;

bin x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23,x24,x25,x26,x27,x28,x29,x30,x31,x32,x33,x34,x35,x36,x37,x38,x39,x40,x41,x42,x43,x44,x45,x46,x47,x48,x49,x50,x51,x52,x53,x54,x55,x56,x57,x58,x59,x60,x61,x62,x63;

By solving it, the result is:

Value of objective function: 532.00000000

Actual values of the variables:
x0                              0
x1                              0
x2                              0
x3                              0
x4                              0
x5                              0
x6                              0
x7                              1
x8                              0
x9                              0
x10                             1
x11                             0
x12                             0
x13                             0
x14                             0
x15                             0
x16                             0
x17                             1
x18                             0
x19                             0
x20                             0
x21                             0
x22                             0
x23                             0
x24                             0
x25                             0
x26                             0
x27                             0
x28                             1
x29                             0
x30                             0
x31                             0
x36                             0
x45                             1
x54                             1
x63                             0
x32                             0
x40                             0
x48                             0
x56                             1
x33                             0
x41                             0
x49                             0
x57                             0
x34                             0
x42                             0
x50                             0
x58                             0
x35                             1
x43                             0
x51                             0
x59                             0
x37                             0
x44                             0
x38                             0
x52                             0
x39                             0
x60                             0
x46                             0
x53                             0
x47                             0
x61                             0
x55                             0
x62                             0

As you can see. x45 and x54 are both 1 while other constraints are all met. If I put a lable before the constraint such as :

c1: x45=0;

Then it will be met. I am not sure why this makes a difference

Was it helpful?

Solution

Updated response based on OP's clarifications

Something interesting is going on. When I solve the exact same IP that you posted above, all the constraints are being met.

Value of objective function: 532.00000000

Actual values of the variables:
x0                              0
x1                              0
x2                              0
x3                              0
x45                             0
x54                             0
x63                             0
x32                             0
x40                             0
x48                             1
x56                             0
x33                             0
x41                             0
x49                             0
x57                             1

The good news is that the Obj function value is the same. Here's what you can try and you will catch what's going on. Your problem is highly degenerate.

Somehow lp_solve is not seeing your x45=0 constraint.

Diagnose using the -stat option

Here's how can see what's going on: create two LP files.

  1. The original lp (say original.lp)
  2. Another file with the c1: added. (say namedconstraint.lp)

Now try this: From the command line mode

 lp_solve -stat original.lp
 lp_solve -stat namedconstraint.lp

If you compare the two outputs, you will see what is going on.

In my case, when I run lp_solve -stat I get

Constraints: 74
Variables  : 64
Integers   : 64
Semi-cont  : 0
SOS        : 0
Non-zeros  : 190    density=4.011824%

Then you can keep tweaking the original.lp file until you see why this is happening.

Further things to try:

Based on your additional remarks below, lp_solve is not seeing the constraint, unless you give the constraint a name. Try this next: 1. Move that constraint to be the very first, or the very last constraint in your model. Does that change anything? 2. I suspect that there are some strange characters in the line (or constraint) prior to the line where you have type x45=0. See if it helps if you delete that line.

Unfortunately, I am unable to replicate the problem, so I cannot debug it myself. Hence these suggestions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top