Example: displaying solutions with increased precision from the Python API

Illustrates how to format output from a Python session using CPLEX.

This example shows how to read a problem from a file, myprob.lp, in LP format. (For more information about LP, the linear programming format, see that topic in the reference manual, File formats supported by CPLEX.) The example prints the solution in double precision. It also displays nonzero reduced costs with the names of the associated variables.

>>> c = cplex.Cplex("myprob.lp")
>>> c.solve()
[. . . CPLEX log . . .]
>>> # print the solution vector in double precision
>>> for val in c.solution.get_values():
...   print " %+18.16e" % val
...
+2.5000000000000000e+000
+1.7865900324417692e+002
+1.9999999999999999e-001
>>> # print the nonzero reduced costs and their variable names
>>> for i, dj in enumerate(c.solution.get_reduced_costs()):
...   if dj != 0.:
...     print "red. cost of ", c.variables.get_names(i), " is ", dj
...
red. cost of x1 is 3.04