Example: examining the simplex tableau in the Python API¶
Illustrates how to examine a typical simplex tableau.
This example reads a problem from a file, myprob.mps, formatted in MPS. (For more information about the math programming standard format MPS, see that topic in the reference manual, File formats supported by CPLEX.) After setting a limit on the number of iterations, and selecting primal simplex as the optimizer, it then loops through the simplex iterations as CPLEX solves the problem, printing rows (constraints).
>>> c = cplex.Cplex("myprob.mps")
>>> c.parameters.simplex.limits.iterations.set(1)
>>> c.parameters.lpmethod.set(c.parameters.lpmethod.values.primal)
>>> # this while loop will print the tableau after each
>>> # simplex iteration
>>> while c.solution.get_status() != c.solution.status.optimal:
... c.solve()
... print " CURRENT TABLEAU "
... for tableau_row in c.solution.advanced.binvarow():
... print tableau_row
... print
...
You can print only selected rows of the tableau by passing the names of rows or the indices of rows to the method binvarow. Another method, binvacol, returns columns of a tableau. The methods binvrow and binvcol return the inverted basis matrix.