Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there C/C++ API for MibS #77

Open
kaba40 opened this issue Apr 10, 2020 · 3 comments
Open

Is there C/C++ API for MibS #77

kaba40 opened this issue Apr 10, 2020 · 3 comments

Comments

@kaba40
Copy link

kaba40 commented Apr 10, 2020

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

@tkralphs
Copy link
Member

tkralphs commented Apr 10, 2020

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.

@tkralphs
Copy link
Member

I guess we could pretty easily just make a solve() function that would make everything more transparent. I will look at that.

@kaba40
Copy link
Author

kaba40 commented Apr 10, 2020

OK. Thank you very much Ted for your quickly reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants