C++ version of the example
With BCL C++, the implementation of the cut example is similar to what we have seen in the previous section since the same Xpress Optimizer functions are used.
#include <iostream>
#include "xprb_cpp.h"
#include "xprs.h"
using namespace std;
using namespace ::dashoptimization;
...
XPRBvar start[NJ];
XPRBprob p("Jobs"); // Initialize BCL and a new problem
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
bprob->beginCB(oprob); // Coordinate BCL and Optimizer
XPRSgetintattrib(oprob, XPRS_NODES, &num);
if(num == 2) // Only generate cuts at node 2
{
ca[0] = bprob->newCut(start[1]+2 <= start[0], 2);
ca[1] = bprob->newCut(4*start[2] - 5.3*start[3] <= -17, 2);
cout << "Adding constraints:" << endl;
for(i=0;i<2;i++) ca[i].print();
if(bprob->addCuts(ca,2)) cout << "Problem with adding cuts." << endl;
}
bprob->endCB(); // Reset BCL to main problem
return 0; // Call this function once per node
}
int main(int argc, char **argv)
{
XPRSprob oprob;
for(j=0;j<4;j++) start[j] = p.newVar("start");
... // Define constraints and an objective function
oprob = p.getXPRSprob(); // Get Optimizer problem
p.setCutMode(1); // Enable the cut mode
XPRSsetcbcutmgr(oprob,usrcme,&p); // Def. the cut manager callback
p.mipOptimize(); // Solve the problem as MIP
... // Solution output
return 0;
}
