Integer Programming entities in BCL
The BCL code extracts in this document are formulated for the BCL C++ interface. The other BCL interfaces (C, Java, C#) work similarly, please refer to the Xpress BCL documentation for further detail.
Definition: Integer Programming types are specified when creating decision variables (type XPRBvar); types may be changed with setType.
XPRBprob prob("test"); XPRBvar d, ifmake[NP][NL], x; int p,l; d = prob.newVar("d", XPRB_BV); // Single binary variable for (p = 0; p < NP; p++) // An array of binaries for (l = 0; l < NL; l++) ifmake[p][l] = prob.newVar("ifmake", XPRB_BV); x = prob.newVar("x", XPRB_UI, MINVAL, MAXVAL); // An integer variable // MINVAL,MAXVAL: reals between -XPRB_INFINITY and XPRB_INFINITY ... x.setType(XPRB_PI); // Change type to partial integer x.setLim(10); ... x.setType(XPRB_PL); // Change type to continuous
Solving: use mipOptimize, possibly preceded by setSense (the default optimization direction is minimization), to solve a problem as a MIP problem. To solve just the LP relaxation use option "l" (if following up with MIP search) or lpOptimize (ignore all MIP information).
prob.setSense(XPRB_MINIM);
prob.mipOptimize("");
Accessing the solution: for obtaining solution values of decision variables and linear expressions use getSol; the MIP problem status is returned by getMIPstatus.
int mipstatus = prob.getMIPStat(); switch (mipstatus) { case XPRB_MIP_NOT_LOADED: case XPRB_MIP_LP_NOT_OPTIMAL: cout << "Solving not started" << endl; break; case XPRB_MIP_LP_OPTIMAL: cout << "Root LP solved" << endl; break; case XPRB_MIP_UNBOUNDED: cout << "LP unbounded" << endl; break; case XPRB_MIP_NO_SOL_FOUND: case XPRB_MIP_INFEAS: cout << "MIP search started, no solution" << endl; break; case XPRB_MIP_SOLUTION: case XPRB_MIP_OPTIMAL: cout << "MIP solution: " << prob.getObjVal() << endl; break; } cout << x.getName() << ": " << x.getSol() << endl;