how to get basis matrix?

530 views
Skip to first unread message

Akhil

unread,
Feb 3, 2014, 4:58:52 PM2/3/14
to gur...@googlegroups.com
I am trying to obtain the list of basic variables and constraints (that form the basis matrix) after an LP solve.
However, Gurobi is not returning number of basic constraints to be equal to the number of basic variables. Basis matrix is supposed to be a square matrix.
 Here is the code I am using:

basicVars = []

for v in vars:
    if v.VBasis == 0:
      basicVars.append(v)
      
  
  #get the list of basic constraints
  basicConstrs = []
  for c in constrs:
    if c.CBasis == 0:
      basicConstrs.append(c)

Here are the lengths I am getting for the some of the LPs

print len(basicVars), basicConstrs
496 2750
232 748
217 717
193 548

Can someone please tell what is the right way of obtaining the basic variables and constraints?

T.

unread,
Feb 3, 2014, 5:38:07 PM2/3/14
to gur...@googlegroups.com
I think you misunderstood the meaning of a constraint being basic.

The final basis matrix contains (parts of) all constraints. If a constraint is basic, it means that the corrseponding slack/surplus/artificial variable of that constraint is basic (meaning something in a way like "the constraint is not tight").

So to obtain the final basis matrix, you have to find all variables and constraints (i.e. slack/surplus/artificial variables) that are basic. For the normal variables just take the whole corresponding column. For the slack/surplus/artificial variables take unit vector with "1" at the position of the corresponding row. Alltogether, these columns and unit vectors form the basis matrix.

My question is now: Do you really need this matrix. If you want to solve a system like, Bx=d or B'x=c, there are easier ways than to invert the basis matrix yourself.

Jakob Sch.

unread,
Feb 4, 2014, 4:50:00 AM2/4/14
to gur...@googlegroups.com
Hi Akhil,

Maybe you should take a look at the advanced simplex interface gurobi provides (http://www.gurobi.com/documentation/5.6/reference-manual/c_advanced_simplex_routine - unfortunately only available in C) that offers some of the functionalities that T mentioned above.

Best regards,
Jakob
Reply all
Reply to author
Forward
0 new messages