Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

OsiRowCutDebuggerTest.cpp

00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #if defined(_MSC_VER)
00004 // Turn off compiler warning about long names
00005 #  pragma warning(disable:4786)
00006 #endif
00007 
00008 #include <cassert>
00009 
00010 #include "OsiRowCutDebugger.hpp"
00011 
00012 #ifdef NDEBUG
00013 #undef NDEBUG
00014 #endif
00015 
00016 //--------------------------------------------------------------------------
00017 // test cut debugger methods.
00018 void
00019 OsiRowCutDebuggerUnitTest(const OsiSolverInterface * baseSiP,
00020                           const std::string & mpsDir )
00021 {
00022   
00023   CoinRelFltEq eq;
00024   
00025   // Test default constructor
00026   {
00027     OsiRowCutDebugger r;
00028     assert( r.integerVariable_==NULL );
00029     assert( r.optimalSolution_==NULL );
00030     assert( r.numberColumns_==0);
00031   }
00032   
00033   {
00034     // Get non trivial instance
00035     OsiSolverInterface * imP = baseSiP->clone();
00036     std::string fn = mpsDir+"exmip1";
00037     imP->readMps(fn.c_str(),"mps");
00038     //std::cerr <<imP->getNumRows() <<std::endl;
00039     assert( imP->getNumRows() == 5);
00040     
00041     // activate debugger
00042     imP->activateRowCutDebugger("ab cd /x/ /exmip1.asc");
00043     
00044     int i;
00045     
00046     // return debugger
00047     const OsiRowCutDebugger * debugger = imP->getRowCutDebugger();
00048     // check 
00049     assert (debugger!=NULL);
00050     
00051     assert (debugger->numberColumns_==8);
00052     
00053     const bool type[]={0,0,1,1,0,0,0,0};
00054     const double values[]= {2.5, 0, 1, 1, 0.5, 3, 0, 0.26315789473684253};
00055     CoinPackedVector objCoefs(8,imP->getObjCoefficients());
00056    
00057 #if 0
00058     for (i=0;i<8;i++) {
00059       assert(type[i]==debugger->integerVariable_[i]);
00060       std::cerr <<i  <<" " <<values[i] <<" " <<debugger->optimalSolution_[i] <<std::endl;
00061     }
00062 #endif
00063     
00064     double objValue = objCoefs.dotProduct(values);
00065     double debuggerObjValue = objCoefs.dotProduct(debugger->optimalSolution_);
00066     //std::cerr <<objValue <<" " <<debuggerObjValue <<std::endl;
00067     assert( eq(objValue,debuggerObjValue) );
00068     
00069     OsiRowCutDebugger rhs;
00070     {
00071       OsiRowCutDebugger rC1(*debugger);
00072       
00073       assert (rC1.numberColumns_==8);
00074       for (i=0;i<8;i++) {
00075         assert(type[i]==rC1.integerVariable_[i]);
00076       }
00077       assert( eq(objValue,objCoefs.dotProduct(rC1.optimalSolution_)) );
00078       
00079       rhs=rC1;
00080       assert (rhs.numberColumns_==8);
00081       for (i=0;i<8;i++) {
00082         assert(type[i]==rhs.integerVariable_[i]);
00083       }
00084       assert( eq(objValue,objCoefs.dotProduct(rhs.optimalSolution_)) );
00085     }
00086     // Test that rhs has correct values even though lhs has gone out of scope
00087     assert (rhs.numberColumns_==8);
00088     for (i=0;i<8;i++) {
00089       assert(type[i]==rhs.integerVariable_[i]);
00090     }
00091     assert( eq(objValue,objCoefs.dotProduct(rhs.optimalSolution_)) );
00092     OsiRowCut cut[2];
00093     
00094     const int ne = 3;
00095     int inx[ne] = { 0, 2, 3 };
00096     double el[ne] = { 1., 1., 1. };
00097     cut[0].setRow(ne,inx,el);
00098     cut[0].setUb(5.);
00099     
00100     el[1]=5;
00101     cut[1].setRow(ne,inx,el);
00102     cut[1].setUb(5);
00103     OsiCuts cs; 
00104     cs.insert(cut[0]);
00105     cs.insert(cut[1]);
00106     assert(!debugger->invalidCut(cut[0]));
00107     assert( debugger->invalidCut(cut[1]));
00108     assert(debugger->validateCuts(cs,0,2)==1);
00109     assert(debugger->validateCuts(cs,0,1)==0);
00110     delete imP;
00111   }
00112 }

Generated on Wed Dec 3 14:35:33 2003 for Osi by doxygen 1.3.5