/Users/kmartin/Documents/files/code/cpp/OScpp/COIN-OS/OS/examples/addCuts/OSAddCuts.cpp

Go to the documentation of this file.
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 // test OS code samples here
00052         FileUtil *fileUtil = NULL; 
00053         fileUtil = new FileUtil();
00054         const char dirsep =  CoinFindDirSeparator();
00055         // Set directory containing mps data files.
00056         std::string dataDir;
00057    dataDir = dirsep == '/' ? "../../data/" : "..\\..\\data\\";
00058         cout << "Start Building the Model" << endl;
00059         try{
00060                 // get the p0033 problem
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                 // done writing the model
00070                 cout << "Done writing the Model" << endl;
00071                 // now solve the model
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                 solver->osiSolver->initialSolve();
00079                 cout << endl << endl << endl;
00080                 cout << "Here is the p0033 objective value "  << solver->osiSolver->getObjValue()  << endl;
00081                 //
00082                 // done solving the model
00083                 // add Rounding and Cover cuts
00084                 //
00085             CglKnapsackCover cover;
00086             CglSimpleRounding round;  
00087             CoinRelFltEq eq(0.0001);
00088             OsiSolverInterface::ApplyCutsReturnCode acRc;    
00089             OsiCuts cuts;
00090             cover.generateCuts(*(solver->osiSolver), cuts);
00091             round.generateCuts(*(solver->osiSolver), cuts);
00092             acRc = solver->osiSolver->applyCuts(cuts,  0.0);
00093             // Print applyCuts return code
00094             cout <<  endl <<endl;
00095             cout << cuts.sizeCuts() <<" cuts were generated" <<endl;
00096             cout <<"  " <<acRc.getNumInconsistent() <<" were inconsistent" <<endl;
00097             cout <<"  " <<acRc.getNumInconsistentWrtIntegerModel() 
00098            <<" were inconsistent for this problem" <<endl;
00099             cout <<"  " <<acRc.getNumInfeasible() <<" were infeasible" <<endl;
00100             cout <<"  " <<acRc.getNumIneffective() <<" were ineffective" <<endl;
00101             cout <<"  " <<acRc.getNumApplied() <<" were applied" <<endl;
00102         cout <<endl <<endl;
00103         // Resolve
00104         solver->osiSolver->resolve();
00105         cout <<endl;
00106         cout <<"After applying cuts, objective value changed to: "
00107              <<   solver->osiSolver->getObjValue() <<endl <<endl;
00108         // do garbage collection
00109                 delete solver;
00110                 solver = NULL;
00111                 delete osilreader;
00112                 osilreader = NULL;
00113                 delete fileUtil;
00114                 fileUtil  = NULL;
00115                 cout << "Done with garbage collection" << endl;
00116                 return 0;
00117         }
00118         catch(const ErrorClass& eclass){
00119                 delete fileUtil;
00120                 std::cout << eclass.errormsg <<  std::endl;
00121                 return 0;
00122         } 
00123 }// end main
00124 

Generated on Sat Mar 29 22:38:01 2008 by  doxygen 1.5.3