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