<div dir="ltr"><div dir="ltr"><div>Hi List members,</div><div><br></div><div>I am learning coin OSI programming using the C++ interface (using CPLEX). I have the following example code that works for continuous variables and Linear Programming (LP) (based on online coin examples).</div><div><br></div><div>But I couldn't find instructions on how to use integer decision variables.</div><div><br></div><div>Could anyone help explain how to change the two decision variables x0 and x1 to integer and/or binary variables?</div><div><br></div><div>Also, I am currently use CPLEX and have clp installed. To use MILP with coin-or instead of CPLEX, what additional package do I need?<br></div><div><br></div><div>Thanks and regards,<br></div><div><br></div><div>// Example of using COIN-OR OSI, building the instance internally<br>// with sparse matrix object<br>#include <iostream><br>//#include <coin/OsiClpSolverInterface.hpp><br>#include <coin/OsiCpxSolverInterface.hpp><br>#include <coin/CoinPackedMatrix.hpp><br>#include <coin/CoinPackedVector.hpp><br><br>int<br>main(void)<br>{<br>  // Create a problem pointer. We use the base class here.<br>  OsiSolverInterface *si;<br>  // When we instantiate the object, we need a specific derived class.<br>  //si = new OsiClpSolverInterface;<br>  si = new OsiCpxSolverInterface;<br>  // Build our own instance from scratch<br>/*<br>* This section adapted from Matt Galati's example<br>* on thise COIN-OR Tutorial website.<br>*<br>* Problem from Bertsimas, Tsitsiklis page 21<br>*<br>* optimal solution: x* = (1,1)<br>*<br>* minimize -1 x0 - 1 x1<br>* s.t 1 x0 + 2 x1 <= 3<br>* 2 x0 + 1 x1 <= 3<br>* x0 >= 0<br>* x1 >= 0<br>*/<br>  int n_cols = 2;<br>  double * col_lb = new double[n_cols];//the column lower bounds<br>  double * col_ub = new double[n_cols];//the column upper bounds<br>  //Define the variable lower/upper bounds.<br>  // x0 >= 0 => 0 <= x0 <= infinity<br>  // x1 >= 0 => 0 <= x1 <= infinity<br>  col_lb[0] = 0.0;<br>  col_lb[1] = 0.0;<br>  col_ub[0] = si->getInfinity();<br>  col_ub[1] = si->getInfinity();<br><br>  //Define the objective coefficients.<br>  //minimize -1 x0 - 1 x1<br>//  double * objective = new double[n_cols];//the objective coefficients<br>  std::vector<double> objective(n_cols, 0.0); //the objective coefficients<br>  objective[0] = -1.0;<br>  objective[1] = -1.0;<br><br>  int n_rows = 2;<br>  double * row_lb = new double[n_rows]; //the row lower bounds<br>  double * row_ub = new double[n_rows]; //the row upper bounds<br>  //Define the constraint matrix.<br>  CoinPackedMatrix * matrix = new CoinPackedMatrix(false,0,0);<br>  matrix->setDimensions(0, n_cols);<br>  //1 x0 + 2 x1 <= 3 => -infinity <= 1 x0 + 2 x2 <= 3<br>  CoinPackedVector row1;<br>  row1.insert(0, 1.0);<br>  row1.insert(1, 2.0);<br>  row_lb[0] = -1.0 * si->getInfinity();<br>  row_ub[0] = 3.0;<br>   <br>  matrix->appendRow(row1);<br>  //2 x0 + 1 x1 <= 3 => -infinity <= 2 x0 + 1 x1 <= 3<br>  CoinPackedVector row2;<br>  row2.insert(0, 2.0);<br>  row2.insert(1, 1.0);<br>  row_lb[1] = -1.0 * si->getInfinity();<br>  row_ub[1] = 3.0;<br>  matrix->appendRow(row2);<br>  //load the problem to OSI<br>  si->loadProblem(*matrix, col_lb, col_ub, objective.data(), row_lb, row_ub);<br>  //write the MPS file to a file called example.mps<br>  si->writeMps("example");<br>  // Solve the (relaxation of the) problem<br>  si->initialSolve();<br>  // Check the solution<br>  if ( si->isProvenOptimal() )<br>  {<br>    std::cout << "Found optimal solution!" << std::endl;<br>    std::cout << "Objective value is " << si->getObjValue() << std::endl;<br>    int n = si->getNumCols();<br>    const double *solution;<br>    solution = si->getColSolution();<br>    // We could then print the solution or examine it.<br>  }<br>  else<br>  {<br>    std::cout << "Didn't find optimal solution." << std::endl;<br>    // Could then check other status functions.<br>  }<br>  return 0;<br>}<br><br></div></div></div>