Search code examples
pythoncallbackcplex

CPLEX: Accessing strong branching values via python API


I am working on some advanced branching heuristics for mixed integer programming using CPLEX (12.9) by its Python (3.6) API. Part of the branching decisions should be based on the strong branching (SB) score of variables. While I can query the pseudo cost score of variables directly via the API [1], there seems to be no easy way to get calculated SB scores. Therefore I want to implement the calculation on my own. I found an old forum post, describing how to implement strong branching calculations as efficient as possible [2] by using the C-API. Unfortunately the described mehtod uses library calls (like CPXgetcallbacknodelp()) for which I can't find corresponding python methods.

This leaves me with three questions:

  1. Is there an API call to get SB scores I missed?
  2. Did I overlook the python wrapper for CPXgetcallbacknodelp() etc.?
  3. Is there an easy way to add wrappers to unsupported C-API calls to the cplex python wrapper (maybe by extending the SWIG generated python files)?

[1] https://www.ibm.com/support/knowledgecenter/SSSA5P_12.9.0/ilog.odms.cplex.help/refpythoncplex/html/cplex.callbacks.ControlCallback-class.html

[2] https://www.ibm.com/developerworks/community/forums/html/threadTopic?id=77777777-0000-0000-0000-000014479565&ps=25


Solution

  • There is no way to get direct access to the nodelp via the CPLEX Python API. If you use one of the callbacks that inherit from HSCallback, you can call solve() on it, etc.

    What you can do (although, this may not be efficient) is clone the original problem, pass it to the callback when you create it, and then at each node call Cplex.advanced.strong_branching().