int main (int argc, const char *argv[]) { OsiClpSolverInterface solver1; //#define USE_OSI_NAMES #ifdef USE_OSI_NAMES // Say we are keeping names (a bit slower this way) solver1.setIntParam(OsiNameDiscipline,1); #endif // Read in model using argv[1] // and assert that it is a clean model std::string mpsFileName; #if defined(SAMPLEDIR) mpsFileName = SAMPLEDIR "/p0033.mps"; #else if (argc < 2) { fprintf(stderr, "Do not know where to find sample MPS files.\n"); exit(1); } #endif if (argc>=2) mpsFileName = argv[1]; int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),""); if( numMpsReadErrors != 0 ) { printf("%d errors reading MPS file\n", numMpsReadErrors); return numMpsReadErrors; } // Tell solver to return fast if presolve or initial solve infeasible solver1.getModelPtr()->setMoreSpecialOptions(3); // Pass to Cbc initialize defaults CbcModel modelA(solver1); CbcModel * model = &modelA; CbcMain0(modelA); // Event handler MyEventHandler3 eventHandler; model->passInEventHandler(&eventHandler); /* Now go into code for standalone solver Could copy arguments and add -quit at end to be safe but this will do */ if (argc>2) { CbcMain1(argc-1,argv+1,modelA,callBack); } else { const char * argv2[]={"driver6","-solve","-quit"}; CbcMain1(3,argv2,modelA,callBack); } // Solver was cloned so get current copy OsiSolverInterface * solver = model->solver(); // Print solution if finished (could get from model->bestSolution() as well if (model->bestSolution()) { const double * solution = solver->getColSolution(); int iColumn; int numberColumns = solver->getNumCols(); std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14); std::cout<<"--------------------------------------"<<std::endl; #ifdef USE_OSI_NAMES for (iColumn=0;iColumn<numberColumns;iColumn++) { double value=solution[iColumn]; if (fabs(value)>1.0e-7&&solver->isInteger(iColumn)) std::cout<<std::setw(6)<<iColumn<<" "<<std::setw(8)<<setiosflags(std::ios::left)<<solver->getColName(iColumn) <<resetiosflags(std::ios::adjustfield)<<std::setw(14)<<" "<<value<<std::endl; } #else // names may not be in current solver - use original for (iColumn=0;iColumn<numberColumns;iColumn++) { double value=solution[iColumn]; if (fabs(value)>1.0e-7&&solver->isInteger(iColumn)) std::cout<<std::setw(6)<<iColumn<<" "<<std::setw(8)<<setiosflags(std::ios::left)<<solver1.getModelPtr()->columnName(iColumn) <<resetiosflags(std::ios::adjustfield)<<std::setw(14)<<" "<<value<<std::endl; } #endif std::cout<<"--------------------------------------"<<std::endl; std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific); } else { std::cout<<" No solution!"<<std::endl; } return 0; }