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

CglProbingTest.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 #include <cassert>
00014 
00015 #include "CoinPackedMatrix.hpp"
00016 #include "CglProbing.hpp"
00017 
00018 
00019 //--------------------------------------------------------------------------
00020 // test EKKsolution methods.
00021 void
00022 CglProbingUnitTest(
00023   const OsiSolverInterface * baseSiP,
00024   const std::string mpsDir )
00025 {
00026   CoinRelFltEq eq(0.000001);
00027 
00028   // Test default constructor
00029   {
00030     CglProbing aGenerator;
00031   }
00032   
00033   // Test copy & assignment
00034   {
00035     CglProbing rhs;
00036     {
00037       CglProbing bGenerator;
00038       CglProbing cGenerator(bGenerator);
00039       rhs=bGenerator;
00040     }
00041   }
00042 
00043   {
00044     OsiCuts osicuts;
00045     CglProbing test1;
00046     OsiSolverInterface  * siP = baseSiP->clone();
00047     int i;
00048     int nColCuts;
00049     int nRowCuts;
00050     
00051     std::string fn = mpsDir+"p0033";
00052     siP->readMps(fn.c_str(),"mps");
00053     siP->initialSolve();
00054     // just unsatisfied variables
00055     test1.generateCuts(*siP,osicuts);
00056     nColCuts = osicuts.sizeColCuts();
00057     nRowCuts = osicuts.sizeRowCuts();
00058     std::cout<<"There are "<<nRowCuts<<" probing cuts"<<std::endl;
00059     {
00060       std::cout<<"there are "<<nColCuts<<" probing column cuts"<<std::endl;
00061       const double * lo = siP->getColLower();
00062       const double * up = siP->getColUpper();
00063       for (i=0; i<nColCuts; i++){
00064         OsiColCut ccut;
00065         CoinPackedVector cpv;
00066         ccut = osicuts.colCut(i);
00067         cpv = ccut.lbs();
00068         int n = cpv.getNumElements();
00069         int j;
00070         const int * indices = cpv.getIndices();
00071         double* elements = cpv.getElements();
00072         for (j=0;j<n;j++) {
00073           int icol=indices[j];
00074           if (elements[j]>lo[icol])
00075             std::cout<<"Can increase lb on "<<icol<<" from "<<lo[icol]<<
00076               " to "<<elements[j]<<std::endl;
00077         }
00078         cpv = ccut.ubs();
00079         n = cpv.getNumElements();
00080         indices = cpv.getIndices();
00081         elements = cpv.getElements();
00082         for (j=0;j<n;j++) {
00083           int icol=indices[j];
00084           if (elements[j]<up[icol])
00085             std::cout<<"Can decrease ub on "<<icol<<" from "<<up[icol]<<
00086               " to "<<elements[j]<<std::endl;
00087         }
00088       }
00089     }
00090     for (i=0; i<nRowCuts; i++){
00091       OsiRowCut rcut;
00092       CoinPackedVector rpv;
00093       const double * colsol = siP->getColSolution();
00094       rcut = osicuts.rowCut(i);
00095       rpv = rcut.row();
00096       const int n = rpv.getNumElements();
00097       const int * indices = rpv.getIndices();
00098       double* elements = rpv.getElements();
00099       double sum2=0.0;
00100       int k=0;
00101       double lb=rcut.lb();
00102       double ub=rcut.ub();
00103       for (k=0; k<n; k++){
00104         int column=indices[k];
00105         sum2 += colsol[column]*elements[k];
00106       }
00107       if (sum2 >ub + 1.0e-7 ||sum2 < lb - 1.0e-7) {
00108         std::cout<<"Cut "<<i<<" lb "<<lb<<" solution "<<sum2<<" ub "<<ub<<std::endl;
00109         for (k=0; k<n; k++){
00110           int column=indices[k];
00111           std::cout<<"(col="<<column<<",el="<<elements[k]<<",sol="<<
00112             colsol[column]<<") ";
00113         }
00114         std::cout <<std::endl;
00115       }
00116     }
00117     CoinPackedVector check;
00118     int index[] = {6,32};
00119     double el[] = {1,1};
00120     check.setVector(2,index,el);
00121     assert (osicuts.sizeRowCuts()==2);
00122     // sort Elements in increasing order
00123     CoinPackedVector rpv=osicuts.rowCut(1).row();
00124     rpv.sortIncrIndex();
00125     assert (check==rpv);
00126     assert (osicuts.rowCut(1).lb()==1.0);
00127     // now all variables
00128     osicuts=OsiCuts();
00129     test1.setMode(2);
00130     test1.generateCuts(*siP,osicuts);
00131     nColCuts = osicuts.sizeColCuts();
00132     nRowCuts = osicuts.sizeRowCuts();
00133     std::cout<<"There are "<<nRowCuts<<" probing cuts"<<std::endl;
00134     {
00135       std::cout<<"there are "<<nColCuts<<" probing column cuts"<<std::endl;
00136       const double * lo = siP->getColLower();
00137       const double * up = siP->getColUpper();
00138       for (i=0; i<nColCuts; i++){
00139         OsiColCut ccut;
00140         CoinPackedVector cpv;
00141         ccut = osicuts.colCut(i);
00142         cpv = ccut.lbs();
00143         int n = cpv.getNumElements();
00144         int j;
00145         const int * indices = cpv.getIndices();
00146         double* elements = cpv.getElements();
00147         for (j=0;j<n;j++) {
00148           int icol=indices[j];
00149           if (elements[j]>lo[icol])
00150             std::cout<<"Can increase lb on "<<icol<<" from "<<lo[icol]<<
00151               " to "<<elements[j]<<std::endl;
00152         }
00153         cpv = ccut.ubs();
00154         n = cpv.getNumElements();
00155         indices = cpv.getIndices();
00156         elements = cpv.getElements();
00157         for (j=0;j<n;j++) {
00158           int icol=indices[j];
00159           if (elements[j]<up[icol])
00160             std::cout<<"Can decrease ub on "<<icol<<" from "<<up[icol]<<
00161               " to "<<elements[j]<<std::endl;
00162         }
00163       }
00164     }
00165     for (i=0; i<nRowCuts; i++){
00166       OsiRowCut rcut;
00167       CoinPackedVector rpv;
00168       const double * colsol = siP->getColSolution();
00169       rcut = osicuts.rowCut(i);
00170       rpv = rcut.row();
00171       const int n = rpv.getNumElements();
00172       const int * indices = rpv.getIndices();
00173       double* elements = rpv.getElements();
00174       double sum2=0.0;
00175       int k=0;
00176       double lb=rcut.lb();
00177       double ub=rcut.ub();
00178       for (k=0; k<n; k++){
00179         int column=indices[k];
00180         sum2 += colsol[column]*elements[k];
00181       }
00182       if (sum2 >ub + 1.0e-7 ||sum2 < lb - 1.0e-7) {
00183         std::cout<<"Cut "<<i<<" lb "<<lb<<" solution "<<sum2<<" ub "<<ub<<std::endl;
00184         for (k=0; k<n; k++){
00185           int column=indices[k];
00186           std::cout<<"(col="<<column<<",el="<<elements[k]<<",sol="<<
00187             colsol[column]<<") ";
00188         }
00189         std::cout <<std::endl;
00190       }
00191     }
00192     assert (osicuts.sizeRowCuts()==10);
00193     delete siP;
00194   }
00195 
00196 }
00197 

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