#include #include #include "OsiRowCut.hpp" #include "CoinFloatEqual.hpp" #include "OsiCuts.hpp" #include "OsiRowCut.hpp" #include "OsiColCut.hpp" #include "OsiCuts.hpp" #include "CoinPackedMatrix.hpp" #include "CoinHelperFunctions.hpp" #include "CoinSort.hpp" #include "OsiSolverInterface.hpp" #include "OsiSimplexInterface.hpp" #include "OsiRowCutDebugger.hpp" #ifdef COIN_USE_OSL #include "OsiOslSolverInterface.hpp" #define MyOsiSolverInterface OsiOslSolverInterface #endif #ifdef COIN_USE_XPR #include "OsiXprSolverInterface.hpp" #define MyOsiSolverInterface OsiXprSolverInterface #endif #ifdef COIN_USE_CPX #include "OsiCpxSolverInterface.hpp" #endif #ifdef COIN_USE_SPX #include "OsiSpxSolverInterface.hpp" #endif #ifdef COIN_USE_VOL #include "OsiVolSolverInterface.hpp" #endif #ifdef COIN_USE_DYLP #include "OsiDylpSolverInterface.hpp" #endif #ifdef COIN_USE_GLPK #include "OsiGlpkSolverInterface.hpp" #define MyOsiSolverInterface OsiGlpkSolverInterface #endif #ifdef COIN_USE_CLP #include "OsiClpSolverInterface.hpp" #define MyOsiSolverInterface OsiClpSolverInterface #endif void testingMessage( const char * const msg ); int main (int argc, const char *argv[]) { /* Constructs the system max 3x0 + x1 -inf <= 2x0 + x1 <= 10 -inf <= x0 + 3x1 <= 15 The optimal solution is unbounded. Objective is then changed to max x0 + x1 which has a bounded optimum at x0 = 3, x1 = 4. */ OsiSolverInterface * pl = new MyOsiSolverInterface; bool ret = true; CoinPackedMatrix m; double inf = pl->getInfinity(); pl->loadProblem (m,NULL,NULL,NULL,NULL,NULL); CoinPackedVector empty; pl->addCol(empty, -inf, inf, 3.0); // -inf <= x0 <= inf pl->addCol(empty, -inf, inf, 1.0); // -inf <= x1 <= inf /* inserting the first constraint */ CoinPackedVector r0; r0.insert(0, 2.0); /* 2.x0 */ r0.insert(1, 1.0); /* + 1.x1 */ pl->addRow(r0, -inf, 10.0);/* -inf <= <= 10 */ /* inserting the second constraint */ CoinPackedVector r1; r1.insert(0, 1.0); /* 1.x0 */ r1.insert(1, 3.0); /* + 3.x1 */ pl->addRow(r1, -inf, 15.0);/* -inf <= <= 15 */ pl->setObjSense(-1); /* maximize */ pl->writeMps("mytestlp"); pl->initialSolve(); if (pl->isProvenOptimal()) printf("optimal solution\n"); else printf("non optimal solution\n"); if (pl->isProvenPrimalInfeasible()) printf("solution is proven primal infeasible\n"); else printf("solution is not proven primal infeasible\n"); if (pl->isProvenDualInfeasible()) printf("solution is proven dual infeasible\n"); else printf("solution is not proven dual infeasible\n"); ret = ret && !pl->isProvenOptimal(); ret = ret && !pl->isProvenPrimalInfeasible(); ret = ret && pl->isProvenDualInfeasible(); printf("end of first test \n\n"); /* second test, changing obj. coef */ pl->setObjCoeff(0, 1.0); pl->setObjCoeff(1, 1.0); pl->resolve(); if (pl->isProvenOptimal()) printf("optimal solution\n"); else printf("non optimal solution\n"); if (pl->isProvenPrimalInfeasible()) printf("solution is proven primal infeasible\n"); else printf("solution is not proven primal infeasible\n"); if (pl->isProvenDualInfeasible()) printf("solution is proven dual infeasible\n"); else printf("solution is not proven dual infeasible\n"); ret = ret && pl->isProvenOptimal(); ret = ret && !pl->isProvenPrimalInfeasible(); ret = ret && !pl->isProvenDualInfeasible(); printf("The optimal solution is:\n"); for (int i=0;i<2;i++) { printf("x%d = %lf\n",i,pl->getColSolution()[i]); } /* third test, changing bounds */ printf("setting bounds on x1 -> [2,3]\n"); pl->setColBounds(1,2.0,3.0); pl->resolve(); if (pl->isProvenOptimal()) printf("optimal solution\n"); else printf("non optimal solution\n"); if (pl->isProvenPrimalInfeasible()) printf("solution is proven primal infeasible\n"); else printf("solution is not proven primal infeasible\n"); if (pl->isProvenDualInfeasible()) printf("solution is proven dual infeasible\n"); else printf("solution is not proven dual infeasible\n"); ret = ret && pl->isProvenOptimal(); ret = ret && !pl->isProvenPrimalInfeasible(); ret = ret && !pl->isProvenDualInfeasible(); printf("Printing the solution\n"); for (int i=0;i<2;i++) { printf("x%d = %lf\n",i,pl->getColSolution()[i]); } return ret; } // Display message on stdout and stderr void testingMessage( const char * const msg ) { std::cerr <