Is there C/C++ API for MibS
Dears,
When I installed MibS, I realized that to solve a mixed integer bilevel linear optimization problem, we must provide both an MPS file and an auxiliary information file that specifies which variables and constraints are associated with the each level.
I would like to know if there is an API (C, C++, Java, etc.) for MibS. If not, how to generate the two files (mps and txt) when we deal with an instance of a problem with thousands or even millions of variables and constraints ?
Best regards, Kaba Innovation and Technology Transfer engineer Inria Lille INOCS
Yes, there is an API, though it is not very well-documented. The command-line tool essentially just reads the MPS file and then passes the data in through the API. To load problem data directly, you would use MibSModel::loadProblemData and MibSModel::loadProblemData.
It's admittedly a little bit hard to see the logic because MibS is built on top of the Alps tree search framework, but if you just more or less follow the logic of the main function of MibS, but loading the data yourself, it should work. Here's an example of a working code snippet.
model->loadAuxiliaryData(lowerColNum, lowerRowNum, lowerColInd,
lowerRowInd, 1.0, lObjCoeff,
upperColNum, upperRowNum, upperColInd,
upperRowInd, structRowNum, structRowInd,
0, NULL, lColLbInLProb, lColUbInLProb);
model->loadProblemData(*newMatrix, varLB, varUB, objCoef, conLB,
conUB, colType, 1, mps->getInfinity(), rowSense);
int argc = 1;
char** argv = new char* [1];
argv[0] = "mibs";
AlpsKnowledgeBrokerSerial broker(argc, argv, model);
broker.search(model);
if(model->getNumSolutions() == 0){
std::cout << "MibS could not find any bilevel feasible solutions. " << std::endl;
abort();
}
MibSSolution *solution = dynamic_cast<MibSSolution* >
(broker.getBestKnowledge(AlpsKnowledgeTypeSolution).first);
double *y = new double[upperColNum];
for (j = lowerColNum; j < numTotalCols; j++){
y[j - lowerColNum] = floor(solution->getValues()[j] + 0.5);
}
Guess I should add this to the README at least. Alternatively you could also just generate your MPS file using a modeling front-end, like PuLP. I have on my long-term TODO list to give MibS a real front-end by perhaps hooking up PuLP to it directly, but I guess that won't happen anytime very soon.
I guess we could pretty easily just make a solve() function that would make everything more transparent. I will look at that.
OK. Thank you very much Ted for your quickly reply!