4

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

CharJ
  • 67
  • 5
  • There is a related question on the IBM Developer Answers forum [here](https://developer.ibm.com/answers/questions/502218/branching-strategy-in-cplex-python-api.html?childToView=502267#answer-502267). – rkersh Apr 29 '19 at 20:11
  • My Question is about calculating/retrieving the SB scores efficiently. I do know how to implement callbacks in general. – CharJ Apr 29 '19 at 21:18
  • I am looking to retrieve strong branching values as well! Do you have a publicly available version of your implementation? Thank you! – Elena Mar 16 '22 at 12:03
  • Actually I switched to SCIP [1] as a MIP-solver, which makes it way easier to access additional information like the sb score. [1]: https://www.scipopt.org/ – CharJ Mar 17 '22 at 15:40
  • OK, looks like I will need to do the same. A colleague from Operations Research also mentioned me SCIP. Could you still share your solution using SCIP? – Elena Mar 17 '22 at 16:39
  • As SCIP is open source, you can just copy their full strong branching heuristic and modify it. The file "branch_vanillafullstrong.c" should be the perfect starting point. – CharJ Mar 21 '22 at 09:53

1 Answers1

3

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().

rkersh
  • 4,447
  • 2
  • 22
  • 31
  • Thanks for your helpful answer. To use advanced.strong_branching on every node the clone of my problem needs to know which variables were already used for branching above the current node (doesn't it?). – CharJ Apr 30 '19 at 07:15
  • I think you don't need to know which variables were branched on, per se. On the other hand, you need to know which ones are fixed in the current node, which you can get by looking at the bounds. This will include the variables that have been branched on, as well as those that were deduced via other means. – Xavier Nodet Apr 30 '19 at 08:59
  • Good point. So basically I could do the following (cuts and presolve turned of for now): - Keep a copy of the problem in a seperate variable. - At each node query the current bounds on the variables and add them to the copy. - Use strong_branching on copy and collect results Seems reasonable. I will do some research on how warmstarts coudl be used to speed up the process. – CharJ Apr 30 '19 at 09:40
  • I also came up with a different strategy that might be faster. Use nodecallback and branchcallback. In the branchcallback add branches for every variable I want to calculate the SB score for (sb-nodes) and one pseudo branch that consists of the same problem as the current node (pseudo-node). In the nodecallback always select sb-nodes first and solve them by setting the simplex iteration limit to some value. Collect the information generated by the sb-nodes and feed it to the pseudo-node to make the real branching decision. – CharJ Apr 30 '19 at 10:15