00001
00022 #include <cppad/cppad.hpp>
00023 #include "OSConfig.h"
00024 #include "OSCoinSolver.h"
00025 #include "OSResult.h"
00026 #include "OSiLReader.h"
00027 #include "OSiLWriter.h"
00028 #include "OSrLReader.h"
00029 #include "OSrLWriter.h"
00030 #include "OSInstance.h"
00031 #include "OSFileUtil.h"
00032 #include "OSDefaultSolver.h"
00033 #include "OSWSUtil.h"
00034 #include "OSSolverAgent.h"
00035 #include "OShL.h"
00036 #include "OSErrorClass.h"
00037 #include "OSmps2osil.h"
00038 #include "OSBase64.h"
00039 #include "OSCommonUtil.h"
00040 #include "OSErrorClass.h"
00041 #include "CglGomory.hpp"
00042 #include "CglSimpleRounding.hpp"
00043 #include "CglKnapsackCover.hpp"
00044 #include "OSMathUtil.h"
00045
00046 #include<iostream>
00047 using std::cout;
00048 using std::endl;
00049
00050 int main( ){
00051
00052 FileUtil *fileUtil = NULL;
00053 fileUtil = new FileUtil();
00054 const char dirsep = CoinFindDirSeparator();
00055
00056 std::string dataDir;
00057 dataDir = dirsep == '/' ? "../../data/" : "..\\..\\data\\";
00058 cout << "Start Building the Model" << endl;
00059 try{
00060
00061 std::string osilFileName;
00062 osilFileName = dataDir + "osilFiles" + dirsep + "p0033.osil";
00063 std::cout << "Try to read a sample file" << std::endl;
00064 std::cout << "The file is: " ;
00065 std::cout << osilFileName << std::endl;
00066 std::string osil = fileUtil->getFileAsString( osilFileName.c_str() );
00067 OSiLReader *osilreader = NULL;
00068 osilreader = new OSiLReader();
00069
00070 cout << "Done writing the Model" << endl;
00071
00072 CoinSolver *solver = NULL;
00073 solver = new CoinSolver();
00074 solver->sSolverName ="clp";
00075 solver->osinstance = osilreader->readOSiL( osil);;
00076 cout << "call the COIN - Clp Solver" << endl;
00077 solver->buildSolverInstance();
00078
00079 solver->osiSolver->setHintParam(OsiDoReducePrint, true, OsiHintTry);
00080 solver->osiSolver->initialSolve();
00081 cout << endl << endl << endl;
00082 cout << "Here is the p0033 objective value " << solver->osiSolver->getObjValue() << endl;
00083
00084
00085
00086
00087 CglKnapsackCover cover;
00088 CglSimpleRounding round;
00089 CoinRelFltEq eq(0.0001);
00090 OsiSolverInterface::ApplyCutsReturnCode acRc;
00091 OsiCuts cuts;
00092 cover.generateCuts(*(solver->osiSolver), cuts);
00093 round.generateCuts(*(solver->osiSolver), cuts);
00094 acRc = solver->osiSolver->applyCuts(cuts, 0.0);
00095
00096 cout << endl <<endl;
00097 cout << cuts.sizeCuts() <<" cuts were generated" <<endl;
00098 cout <<" " <<acRc.getNumInconsistent() <<" were inconsistent" <<endl;
00099 cout <<" " <<acRc.getNumInconsistentWrtIntegerModel()
00100 <<" were inconsistent for this problem" <<endl;
00101 cout <<" " <<acRc.getNumInfeasible() <<" were infeasible" <<endl;
00102 cout <<" " <<acRc.getNumIneffective() <<" were ineffective" <<endl;
00103 cout <<" " <<acRc.getNumApplied() <<" were applied" <<endl;
00104 cout <<endl <<endl;
00105
00106 solver->osiSolver->resolve();
00107 cout <<endl;
00108 cout <<"After applying cuts, objective value changed to: "
00109 << solver->osiSolver->getObjValue() <<endl <<endl;
00110
00111 delete solver;
00112 solver = NULL;
00113 delete osilreader;
00114 osilreader = NULL;
00115 delete fileUtil;
00116 fileUtil = NULL;
00117 cout << "Done with garbage collection" << endl;
00118 return 0;
00119 }
00120 catch(const ErrorClass& eclass){
00121 delete fileUtil;
00122 std::cout << eclass.errormsg << std::endl;
00123 return 0;
00124 }
00125 }
00126