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

CglOddHoleTest.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 <cstdio>
00009 
00010 #ifdef NDEBUG
00011 #undef NDEBUG
00012 #endif
00013 
00014 #include <cassert>
00015 
00016 #include "CoinPackedMatrix.hpp"
00017 #include "CglOddHole.hpp"
00018 
00019 
00020 //--------------------------------------------------------------------------
00021 // test EKKsolution methods.
00022 void
00023 CglOddHoleUnitTest(
00024   const OsiSolverInterface * baseSiP,
00025   const std::string mpsDir )
00026 {
00027   CoinRelFltEq eq(0.000001);
00028 
00029   // Test default constructor
00030   {
00031     CglOddHole aGenerator;
00032   }
00033   
00034   // Test copy & assignment
00035   {
00036     CglOddHole rhs;
00037     {
00038       CglOddHole bGenerator;
00039       CglOddHole cGenerator(bGenerator);
00040       rhs=bGenerator;
00041     }
00042   }
00043 
00044 
00045   // test on simple case
00046   {  
00047     const int nRows=3;
00048     const int nCols=3;
00049     const int nEls=6;
00050     const double elem[]={1.0,1.0,1.0,1.0,1.0,1.0};
00051     const int row[]={0,1,0,2,1,2};
00052     const int start[]={0,2,4};
00053     const int len[]={2,2,2};
00054     CoinPackedMatrix matrix(true,nRows,nCols,nEls,elem,row,start,len);
00055     const double sol[]={0.5,0.5,0.5};
00056     const double dj[]={0,0,0};
00057     const int which[]={1,1,1};
00058     const int fixed[]={0,0,0};
00059     OsiCuts cs;
00060     CglOddHole test1;
00061     test1.generateCuts(NULL,matrix,sol,dj,cs,which,fixed,true);
00062     CoinPackedVector check;
00063     int index[] = {0,1,2};
00064     double el[] = {1,1,1};
00065     check.setVector(3,index,el);
00066     //assert (cs.sizeRowCuts()==2);
00067     assert (cs.sizeRowCuts()==1);
00068     // sort Elements in increasing order
00069     CoinPackedVector rpv=cs.rowCut(0).row();
00070     rpv.sortIncrIndex();
00071     assert (check==rpv);
00072   }
00073   
00074   // Testcase /u/rlh/osl2/mps/scOneInt.mps
00075   // Model has 3 continous, 2 binary, and 1 general
00076   // integer variable.
00077   {
00078     OsiSolverInterface  * siP = baseSiP->clone();
00079     
00080     std::string fn = mpsDir+"scOneInt";
00081     siP->readMps(fn.c_str(),"mps");
00082 #if 0
00083     CglOddHole cg;
00084     int nCols=siP->getNumCols();
00085     
00086     // Test the siP methods for detecting
00087     // variable type
00088     int numCont=0, numBinary=0, numIntNonBinary=0, numInt=0;
00089     for (int thisCol=0; thisCol<nCols; thisCol++) {
00090       if ( siP->isContinuous(thisCol) ) numCont++;
00091       if ( siP->isBinary(thisCol) ) numBinary++;
00092       if ( siP->isIntegerNonBinary(thisCol) ) numIntNonBinary++;
00093       if ( siP->isInteger(thisCol) ) numInt++;
00094     }
00095     assert(numCont==3);
00096     assert(numBinary==2);
00097     assert(numIntNonBinary==1);
00098     assert(numInt==3);
00099     
00100     
00101     // Test initializeCutGenerator
00102     siP->initialSolve();
00103     assert(xstar !=NULL);
00104     for (i=0; i<nCols; i++){
00105       assert(complement[i]==0);
00106     }
00107     int nRows=siP->getNumRows();
00108     for (i=0; i<nRows; i++){
00109     int vectorsize = siP->getMatrixByRow()->getVectorSize(i);
00110     assert(vectorsize==2);
00111     }
00112     
00113     kccg.cleanUpCutGenerator(complement,xstar);
00114 #endif  
00115     delete siP;
00116   }
00117 
00118 }
00119 

Generated on Wed Dec 3 14:34:55 2003 for Cgl by doxygen 1.3.5