00001
00002
00003 #if defined(_MSC_VER)
00004
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
00018 void
00019 OsiRowCutDebuggerUnitTest(const OsiSolverInterface * baseSiP,
00020 const std::string & mpsDir )
00021 {
00022
00023 CoinRelFltEq eq;
00024
00025
00026 {
00027 OsiRowCutDebugger r;
00028 assert( r.integerVariable_==NULL );
00029 assert( r.optimalSolution_==NULL );
00030 assert( r.numberColumns_==0);
00031 }
00032
00033 {
00034
00035 OsiSolverInterface * imP = baseSiP->clone();
00036 std::string fn = mpsDir+"exmip1";
00037 imP->readMps(fn.c_str(),"mps");
00038
00039 assert( imP->getNumRows() == 5);
00040
00041
00042 imP->activateRowCutDebugger("ab cd /x/ /exmip1.asc");
00043
00044 int i;
00045
00046
00047 const OsiRowCutDebugger * debugger = imP->getRowCutDebugger();
00048
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
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
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 }