Querying solution information in the Python API
Introduces methods to query the quality of solutions in the Python API.
To query the quality of a solution in a Python session
or from a Python application, use a method of the solution object
(such as get_integer quality or get_float_quality)
and supply the identifier of the quality of interest, like this:
c.solution.get_integer_quality(quality_ID)
c.solution.get_float_quality(quality_ID)
The argument you supply to those methods may be the identifier of a single quality or it may be a list of identifiers of qualities.
The same approach works for querying the quality of a solution in the solution pool, but of course you invoke methods of the solution pool object in that case, like this:
c.solution.pool.get_integer_quality(soln, quality_ID)
c.solution.pool.get_float_quality(soln, quality_ID)
Rather than retrieving information about the quality
of a solution one metric at a time, you can extract the most commonly
used metrics with a single line of code. To do so, use the methods Cplex.solution.get_quality_metrics or Cplex.solution.pool.get_quality_metrics.
You can display the objects returned by these methods interactively,
or you can use those returned objects to query individual solution
metrics.
For example, to report information about the incumbent solution in a Python session, adapt this approach to your specific problem:
>>> c = cplex.Cplex("problem.lp")
>>> c.solve()
>>> print c.solution.get_quality_metrics()
For information about the quality of a solution in the solution pool, you specify the solution of interest either by its index or by its name in the solution pool, like this:
>>> print c.solution.pool.get_quality_metrics(soln)
The object returned by this method get_quality_metrics has
many data members that you can inspect individually. For the names
and the conditions under which they are defined, see the documentation
of the class QualityMetrics in the reference
manual of the Python API.