Example
The following example shows how the Xpress Optimizer node cut manager callback may be defined to add cuts during the branch and bound search. Function XPRBaddcuts that adds the cuts to the problem in Xpress Optimizer may only be called from one of the cut manager callback functions. Nevertheless, cuts may be defined at any place in the program after BCL has been initialized and the relevant variables have been defined. In order to keep the present example simple, we only create and add cuts at a single node, they are therefore created in the cut manager callback immediately before they are added to the problem. More realistically, cuts may be generated subject to a certain search tree depth or depending on the solution values of certain variables in the current LP-relaxation.
#include <stdio.h> #include "xprb.h" #include "xprs.h" ... XPRBvar start[4]; int XPRS_CC usrcme(XPRSprob oprob, void* vd) { XPRBcut ca[2]; int num; int i=0; XPRBprob bprob; bprob = (XPRBprob)vd; /* Get the BCL problem */ XPRBbegincb(bprob, oprob); /* Coordinate BCL and Optimizer */ XPRSgetintattrib(oprob, XPRS_NODES, &num); if(num == 2) /* Only generate cuts at node 2 */ { /* ca0: s_1+2 <= s_0 */ ca[0] = XPRBnewcutprec(bprob, start[1], 2, start[0], 2); ca[1] = XPRBnewcut(bprob, XPRB_L, 2); /* ca1: 4*s_2 - 5.3*s_3 <= -17 */ XPRBaddcutterm(ca[1], start[2], 4); XPRBaddcutterm(ca[1], start[3], -5.3); XPRBaddcutterm(ca[1], NULL, -17); printf("Adding constraints:\n"); for(i=0;i<2;i++) XPRBprintcut(ca[i]); if(XPRBaddcuts(bprob, ca, 2)) printf("Problem with adding cuts.\n"); } XPRBendcb(bprob); /* Reset BCL to main problem */ return 0; /* Call this func. once per node */ } int main(int argc, char **argv) { XPRBprob prob; XPRSprob oprob; prob=XPRBnewprob("CutExpl"); /* Initialization */ for(j=0;j<4;j++) start[j] = XPRBnewvar(prob, XPRB_PL, "start", 0, 500); ... /* Define constraints and an objective function */ XPRBsetcutmode(prob, 1); /* Enable the cut mode */ oprob = XPRBgetXPRSprob(prob); /* Get the Optimizer problem */ XPRSsetcbcutmgr(oprob, usrcme, prob); /* Def. the cut manager callback */ XPRBmipoptimize(prob, ""); /* Solve the MIP problem */ ... /* Solution output */ return 0; }
When using the default multi-threaded MIP search it is important to coordinate BCL with the local Optimizer subproblem by surrounding the calls to BCL functions in the cut manager callback by calls to XPRBbegincb and XPRBendcb. Alternatively, you may choose to disable parallelism by setting the XPRS_MIPTHREADS control to 1.
© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.