Changeset 1666 for trunk/Cbc/test
 Timestamp:
 Jun 13, 2011 9:45:24 AM (8 years ago)
 Location:
 trunk/Cbc/test
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Cbc/test/OsiCbcSolverInterfaceTest.cpp
r1574 r1666 4 4 // This code is licensed under the terms of the Eclipse Public License (EPL). 5 5 6 #if defined(_MSC_VER) 7 // Turn off compiler warning about long names 8 # pragma warning(disable:4786) 9 #endif 10 11 #ifdef NDEBUG 12 #undef NDEBUG 13 #endif 14 15 #include "OsiConfig.h" 16 17 #include <cassert> 6 #include "CoinPragma.hpp" 7 8 //#include <cassert> 18 9 //#include <cstdlib> 19 10 //#include <cstdio> … … 24 15 #include "OsiRowCut.hpp" 25 16 #include "OsiColCut.hpp" 17 #include "OsiUnitTests.hpp" 26 18 #include "CoinMessage.hpp" 27 19 #include "CoinModel.hpp" 28 #ifdef COIN_HAS_OSL29 #include "OsiOslSolverInterface.hpp"30 #endif31 20 32 21 //############################################################################# … … 70 59 OsiCbcSolverInterfaceUnitTest(const std::string & mpsDir, const std::string & netlibDir) 71 60 { 72 73 74 61 { 75 62 CoinRelFltEq eq; … … 80 67 { 81 68 OsiCbcSolverInterface im; 82 83 assert( im.getNumCols() == 0 ); 84 85 assert( im.getModelPtr()!=NULL ); 69 OSIUNITTEST_ASSERT_ERROR(im.getNumCols() == 0, {}, "cbc", "default constructor"); 70 OSIUNITTEST_ASSERT_ERROR(im.getModelPtr() != NULL, {}, "cbc", "default constructor"); 86 71 } 87 72 … … 93 78 94 79 OsiCbcSolverInterface imC1(im); 95 assert( imC1.getModelPtr()!=im.getModelPtr());96 assert( imC1.getNumCols() == im.getNumCols());97 assert( imC1.getNumRows() == im.getNumRows() );80 OSIUNITTEST_ASSERT_ERROR(imC1.getModelPtr() != im.getModelPtr(), {}, "cbc", "copy constructor"); 81 OSIUNITTEST_ASSERT_ERROR(imC1.getNumCols() == im.getNumCols(), {}, "cbc", "copy constructor"); 82 OSIUNITTEST_ASSERT_ERROR(imC1.getNumRows() == im.getNumRows(), {}, "cbc", "copy constructor"); 98 83 99 84 OsiCbcSolverInterface imC2(im); 100 assert( imC2.getModelPtr()!=im.getModelPtr() ); 101 assert( imC2.getNumCols() == im.getNumCols() ); 102 assert( imC2.getNumRows() == im.getNumRows() ); 85 OSIUNITTEST_ASSERT_ERROR(imC2.getModelPtr() != im.getModelPtr(), {}, "cbc", "copy constructor"); 86 OSIUNITTEST_ASSERT_ERROR(imC2.getNumCols() == im.getNumCols(), {}, "cbc", "copy constructor"); 87 OSIUNITTEST_ASSERT_ERROR(imC2.getNumRows() == im.getNumRows(), {}, "cbc", "copy constructor"); 88 89 OSIUNITTEST_ASSERT_ERROR(imC1.getModelPtr() != imC2.getModelPtr(), {}, "cbc", "copy constructor"); 103 90 104 assert( imC2.getModelPtr()!=imC1.getModelPtr() ); 105 106 lhs=imC2; 107 } 91 lhs = imC2; 92 } 93 108 94 // Test that lhs has correct values even though rhs has gone out of scope 109 110 assert( lhs.getModelPtr() != m.getModelPtr());111 assert( lhs.getNumCols() == m.getNumCols());112 assert( lhs.getNumRows() == m.getNumRows() );113 } 95 OSIUNITTEST_ASSERT_ERROR(lhs.getModelPtr() != m.getModelPtr(), {}, "cbc", "assignment operator"); 96 OSIUNITTEST_ASSERT_ERROR(lhs.getNumCols() == m.getNumCols(), {}, "cbc", "copy constructor"); 97 OSIUNITTEST_ASSERT_ERROR(lhs.getNumRows() == m.getNumRows(), {}, "cbc", "copy constructor"); 98 } 99 114 100 // Test clone 115 101 { 116 OsiCbcSolverInterface oslSi(m);117 OsiSolverInterface * siPtr = & oslSi;102 OsiCbcSolverInterface cbcSi(m); 103 OsiSolverInterface * siPtr = &cbcSi; 118 104 OsiSolverInterface * siClone = siPtr>clone(); 119 OsiCbcSolverInterface * oslClone = dynamic_cast<OsiCbcSolverInterface*>(siClone); 120 assert( oslClone != NULL ); 121 assert( oslClone>getModelPtr() != oslSi.getModelPtr() ); 122 assert( oslClone>getNumRows() == oslSi.getNumRows() ); 123 assert( oslClone>getNumCols() == m.getNumCols() ); 105 OsiCbcSolverInterface * cbcClone = dynamic_cast<OsiCbcSolverInterface*>(siClone); 106 107 OSIUNITTEST_ASSERT_ERROR(cbcClone != NULL, {}, "cbc", "clone"); 108 OSIUNITTEST_ASSERT_ERROR(cbcClone>getModelPtr() != cbcSi.getModelPtr(), {}, "cbc", "clone"); 109 OSIUNITTEST_ASSERT_ERROR(cbcClone>getNumRows() == cbcSi.getNumRows(), {}, "cbc", "clone"); 110 OSIUNITTEST_ASSERT_ERROR(cbcClone>getNumCols() == m.getNumCols(), {}, "cbc", "clone"); 124 111 125 112 delete siClone; … … 129 116 { 130 117 OsiCbcSolverInterface si; 131 assert( eq(si.getInfinity(),OsiCbcInfinity));118 OSIUNITTEST_ASSERT_ERROR(si.getInfinity() == OsiCbcInfinity, {}, "cbc", "infinity"); 132 119 } 133 120 134 // Test setting solution 121 // Test some catches 122 if (!OsiCbcHasNDEBUG()) 135 123 { 136 OsiCbcSolverInterface m1(m);137 int i;138 139 double * cs = new double[m1.getNumCols()];140 for ( i = 0; i < m1.getNumCols(); i++ )141 cs[i] = i + .5;142 m1.setColSolution(cs);143 for ( i = 0; i < m1.getNumCols(); i++ )144 assert(m1.getColSolution()[i] == i + .5);145 146 double * rs = new double[m1.getNumRows()];147 for ( i = 0; i < m1.getNumRows(); i++ )148 rs[i] = i  .5;149 m1.setRowPrice(rs);150 for ( i = 0; i < m1.getNumRows(); i++ )151 assert(m1.getRowPrice()[i] == i  .5);152 153 delete [] cs;154 delete [] rs;155 }156 157 158 // Test fraction Indices159 {160 OsiCbcSolverInterface fim;161 std::string fn = mpsDir+"exmip1";162 fim.readMps(fn.c_str(),"mps");163 // exmip1.mps has 2 integer variables with index 2 & 3164 assert( fim.isContinuous(0) );165 assert( fim.isContinuous(1) );166 assert( !fim.isContinuous(2) );167 assert( !fim.isContinuous(3) );168 assert( fim.isContinuous(4) );169 170 assert( !fim.isInteger(0) );171 assert( !fim.isInteger(1) );172 assert( fim.isInteger(2) );173 assert( fim.isInteger(3) );174 assert( !fim.isInteger(4) );175 176 assert( !fim.isBinary(0) );177 assert( !fim.isBinary(1) );178 assert( fim.isBinary(2) );179 assert( fim.isBinary(3) );180 assert( !fim.isBinary(4) );181 182 assert( !fim.isIntegerNonBinary(0) );183 assert( !fim.isIntegerNonBinary(1) );184 assert( !fim.isIntegerNonBinary(2) );185 assert( !fim.isIntegerNonBinary(3) );186 assert( !fim.isIntegerNonBinary(4) );187 188 }189 // Test some catches190 if (!OsiCbcHasNDEBUG())191 { bool thrown ;192 193 thrown = false ;194 124 OsiCbcSolverInterface solver; 195 125 try { 196 126 solver.setObjCoeff(0,0.0); 127 OSIUNITTEST_ADD_OUTCOME("cbc", "setObjCoeff on empty model", "should throw exception", OsiUnitTest::TestOutcome::ERROR, false); 197 128 } 198 129 catch (CoinError e) { 199 std::cout<<"Correct throw"<<std::endl; 200 thrown = true ; 201 } 202 assert( thrown == true ) ; 130 if (OsiUnitTest::verbosity >= 1) 131 std::cout<<"Correct throw from setObjCoeff on empty model"<<std::endl; 132 } 203 133 204 134 std::string fn = mpsDir+"exmip1"; 205 135 solver.readMps(fn.c_str(),"mps"); 206 try { 207 solver.setObjCoeff(0,0.0); 208 } 209 catch (CoinError e) { 210 std::cout<<"** Incorrect throw"<<std::endl; 211 abort(); 212 } 213 214 thrown = false ; 136 OSIUNITTEST_CATCH_ERROR(solver.setObjCoeff(0,0.0), {}, "cbc", "setObjCoeff on nonempty model"); 137 215 138 try { 216 139 int index[]={0,20}; 217 140 double value[]={0.0,0.0,0.0,0.0}; 218 141 solver.setColSetBounds(index,index+2,value); 142 OSIUNITTEST_ADD_OUTCOME("cbc", "setColSetBounds on cols not in model", "should throw exception", OsiUnitTest::TestOutcome::ERROR, false); 219 143 } 220 144 catch (CoinError e) { 221 std::cout<<"Correct throw"<<std::endl; 222 thrown = true ; 223 } 224 assert( thrown == true ) ; 225 } 226 // Test apply cuts method 227 { 228 OsiCbcSolverInterface im(m); 229 OsiCuts cuts; 230 231 // Generate some cuts 232 { 233 // Get number of rows and columns in model 234 int nr=im.getNumRows(); 235 int nc=im.getNumCols(); 236 assert( nr == 5 ); 237 assert( nc == 8 ); 238 239 // Generate a valid row cut from thin air 240 int c; 241 { 242 int *inx = new int[nc]; 243 for (c=0;c<nc;c++) inx[c]=c; 244 double *el = new double[nc]; 245 for (c=0;c<nc;c++) el[c]=((double)c)*((double)c); 246 247 OsiRowCut rc; 248 rc.setRow(nc,inx,el); 249 rc.setLb(100.); 250 rc.setUb(100.); 251 rc.setEffectiveness(22); 252 253 cuts.insert(rc); 254 delete[]el; 255 delete[]inx; 256 } 257 258 // Generate valid col cut from thin air 259 { 260 const double * oslColLB = im.getColLower(); 261 const double * oslColUB = im.getColUpper(); 262 int *inx = new int[nc]; 263 for (c=0;c<nc;c++) inx[c]=c; 264 double *lb = new double[nc]; 265 double *ub = new double[nc]; 266 for (c=0;c<nc;c++) lb[c]=oslColLB[c]+0.001; 267 for (c=0;c<nc;c++) ub[c]=oslColUB[c]0.001; 268 269 OsiColCut cc; 270 cc.setLbs(nc,inx,lb); 271 cc.setUbs(nc,inx,ub); 272 273 cuts.insert(cc); 274 delete [] ub; 275 delete [] lb; 276 delete [] inx; 277 } 278 279 { 280 // Generate a row and column cut which are ineffective 281 OsiRowCut * rcP= new OsiRowCut; 282 rcP>setEffectiveness(1.); 283 cuts.insert(rcP); 284 assert(rcP==NULL); 285 286 OsiColCut * ccP= new OsiColCut; 287 ccP>setEffectiveness(12.); 288 cuts.insert(ccP); 289 assert(ccP==NULL); 290 } 291 { 292 //Generate inconsistent Row cut 293 OsiRowCut rc; 294 const int ne=1; 295 int inx[ne]={10}; 296 double el[ne]={2.5}; 297 rc.setRow(ne,inx,el); 298 rc.setLb(3.); 299 rc.setUb(4.); 300 assert(!rc.consistent()); 301 cuts.insert(rc); 302 } 303 { 304 //Generate inconsistent col cut 305 OsiColCut cc; 306 const int ne=1; 307 int inx[ne]={10}; 308 double el[ne]={2.5}; 309 cc.setUbs(ne,inx,el); 310 assert(!cc.consistent()); 311 cuts.insert(cc); 312 } 313 { 314 // Generate row cut which is inconsistent for model m 315 OsiRowCut rc; 316 const int ne=1; 317 int inx[ne]={10}; 318 double el[ne]={2.5}; 319 rc.setRow(ne,inx,el); 320 assert(rc.consistent()); 321 assert(!rc.consistent(im)); 322 cuts.insert(rc); 323 } 324 { 325 // Generate col cut which is inconsistent for model m 326 OsiColCut cc; 327 const int ne=1; 328 int inx[ne]={30}; 329 double el[ne]={2.0}; 330 cc.setLbs(ne,inx,el); 331 assert(cc.consistent()); 332 assert(!cc.consistent(im)); 333 cuts.insert(cc); 334 } 335 { 336 // Generate col cut which is infeasible 337 OsiColCut cc; 338 const int ne=1; 339 int inx[ne]={0}; 340 double el[ne]={2.0}; 341 cc.setUbs(ne,inx,el); 342 cc.setEffectiveness(1000.); 343 assert(cc.consistent()); 344 assert(cc.consistent(im)); 345 assert(cc.infeasible(im)); 346 cuts.insert(cc); 347 } 348 } 349 assert(cuts.sizeRowCuts()==4); 350 assert(cuts.sizeColCuts()==5); 351 352 OsiSolverInterface::ApplyCutsReturnCode rc = im.applyCuts(cuts); 353 assert( rc.getNumIneffective() == 2 ); 354 assert( rc.getNumApplied() == 2 ); 355 assert( rc.getNumInfeasible() == 1 ); 356 assert( rc.getNumInconsistentWrtIntegerModel() == 2 ); 357 assert( rc.getNumInconsistent() == 2 ); 358 assert( cuts.sizeCuts() == rc.getNumIneffective() + 359 rc.getNumApplied() + 360 rc.getNumInfeasible() + 361 rc.getNumInconsistentWrtIntegerModel() + 362 rc.getNumInconsistent() ); 145 if (OsiUnitTest::verbosity >= 1) 146 std::cout<<"Correct throw from setObjCoeff on empty model"<<std::endl; 147 } 363 148 } 364 149 365 150 { 366 OsiCbcSolverInterface oslSi(m);367 int nc = oslSi.getNumCols();368 int nr = oslSi.getNumRows();369 const double * cl = oslSi.getColLower();370 const double * cu = oslSi.getColUpper();371 const double * rl = oslSi.getRowLower();372 const double * ru = oslSi.getRowUpper();373 assert( nc == 8);374 assert( nr == 5);375 assert( eq(cl[0],2.5));376 assert( eq(cl[1],0.0));377 assert( eq(cu[1],4.1));378 assert( eq(cu[2],1.0));379 assert( eq(rl[0],2.5));380 assert( eq(rl[4],3.0));381 assert( eq(ru[1],2.1));382 assert( eq(ru[4],15.0));383 384 const double * cs = oslSi.getColSolution();385 assert( eq(cs[0],2.5));386 assert( eq(cs[7],0.0));387 388 assert( !eq(cl[3],1.2345));389 oslSi.setColLower( 3, 1.2345 );390 assert( eq(oslSi.getColLower()[3],1.2345));391 392 assert( !eq(cu[4],10.2345));393 oslSi.setColUpper( 4, 10.2345 );394 assert( eq(oslSi.getColUpper()[4],10.2345));395 // LH: Objective will depend on how underlying solver constructs and 396 // LH: maintains initial solution.397 double objValue = oslSi.getObjValue();398 assert( eq(objValue,3.5)  eq(objValue,10.5));399 400 assert( eq( oslSi.getObjCoefficients()[0], 1.0));401 assert( eq( oslSi.getObjCoefficients()[1], 0.0));402 assert( eq( oslSi.getObjCoefficients()[2], 0.0));403 assert( eq( oslSi.getObjCoefficients()[3], 0.0));404 assert( eq( oslSi.getObjCoefficients()[4], 2.0));405 assert( eq( oslSi.getObjCoefficients()[5], 0.0));406 assert( eq( oslSi.getObjCoefficients()[6], 0.0));407 assert( eq( oslSi.getObjCoefficients()[7], 1.0));151 OsiCbcSolverInterface cbcSi(m); 152 int nc = cbcSi.getNumCols(); 153 int nr = cbcSi.getNumRows(); 154 const double * cl = cbcSi.getColLower(); 155 const double * cu = cbcSi.getColUpper(); 156 const double * rl = cbcSi.getRowLower(); 157 const double * ru = cbcSi.getRowUpper(); 158 OSIUNITTEST_ASSERT_ERROR(nc == 8, return 1, "cbc", "read and copy exmip1"); 159 OSIUNITTEST_ASSERT_ERROR(nr == 5, return 1, "cbc", "read and copy exmip1"); 160 OSIUNITTEST_ASSERT_ERROR(eq(cl[0],2.5), {}, "cbc", "read and copy exmip1"); 161 OSIUNITTEST_ASSERT_ERROR(eq(cl[1],0.0), {}, "cbc", "read and copy exmip1"); 162 OSIUNITTEST_ASSERT_ERROR(eq(cu[1],4.1), {}, "cbc", "read and copy exmip1"); 163 OSIUNITTEST_ASSERT_ERROR(eq(cu[2],1.0), {}, "cbc", "read and copy exmip1"); 164 OSIUNITTEST_ASSERT_ERROR(eq(rl[0],2.5), {}, "cbc", "read and copy exmip1"); 165 OSIUNITTEST_ASSERT_ERROR(eq(rl[4],3.0), {}, "cbc", "read and copy exmip1"); 166 OSIUNITTEST_ASSERT_ERROR(eq(ru[1],2.1), {}, "cbc", "read and copy exmip1"); 167 OSIUNITTEST_ASSERT_ERROR(eq(ru[4],15.), {}, "cbc", "read and copy exmip1"); 168 169 const double * cs = cbcSi.getColSolution(); 170 OSIUNITTEST_ASSERT_ERROR(eq(cs[0],2.5), {}, "cbc", "read and copy exmip1"); 171 OSIUNITTEST_ASSERT_ERROR(eq(cs[7],0.0), {}, "cbc", "read and copy exmip1"); 172 173 OSIUNITTEST_ASSERT_ERROR(!eq(cl[3],1.2345), {}, "cbc", "set col lower"); 174 cbcSi.setColLower( 3, 1.2345 ); 175 OSIUNITTEST_ASSERT_ERROR( eq(cbcSi.getColLower()[3],1.2345), {}, "cbc", "set col lower"); 176 177 OSIUNITTEST_ASSERT_ERROR(!eq(cbcSi.getColUpper()[4],10.2345), {}, "cbc", "set col upper"); 178 cbcSi.setColUpper( 4, 10.2345 ); 179 OSIUNITTEST_ASSERT_ERROR( eq(cbcSi.getColUpper()[4],10.2345), {}, "cbc", "set col upper"); 180 181 // LH: Objective will depend on how underlying solver constructs and maintains initial solution 182 double objValue = cbcSi.getObjValue(); 183 OSIUNITTEST_ASSERT_ERROR(eq(objValue,3.5)  eq(objValue,10.5), {}, "cbc", "getObjValue() before solve"); 184 185 OSIUNITTEST_ASSERT_ERROR(eq(cbcSi.getObjCoefficients()[0], 1.0), {}, "cbc", "read and copy exmip1"); 186 OSIUNITTEST_ASSERT_ERROR(eq(cbcSi.getObjCoefficients()[1], 0.0), {}, "cbc", "read and copy exmip1"); 187 OSIUNITTEST_ASSERT_ERROR(eq(cbcSi.getObjCoefficients()[2], 0.0), {}, "cbc", "read and copy exmip1"); 188 OSIUNITTEST_ASSERT_ERROR(eq(cbcSi.getObjCoefficients()[3], 0.0), {}, "cbc", "read and copy exmip1"); 189 OSIUNITTEST_ASSERT_ERROR(eq(cbcSi.getObjCoefficients()[4], 2.0), {}, "cbc", "read and copy exmip1"); 190 OSIUNITTEST_ASSERT_ERROR(eq(cbcSi.getObjCoefficients()[5], 0.0), {}, "cbc", "read and copy exmip1"); 191 OSIUNITTEST_ASSERT_ERROR(eq(cbcSi.getObjCoefficients()[6], 0.0), {}, "cbc", "read and copy exmip1"); 192 OSIUNITTEST_ASSERT_ERROR(eq(cbcSi.getObjCoefficients()[7],1.0), {}, "cbc", "read and copy exmip1"); 408 193 } 409 194 … … 412 197 const OsiCbcSolverInterface si(m); 413 198 const CoinPackedMatrix * smP = si.getMatrixByRow(); 414 // LL: const OsiCbcPackedMatrix * osmP = dynamic_cast<const OsiCbcPackedMatrix*>(smP); 415 // LL: assert( osmP!=NULL ); 199 200 OSIUNITTEST_ASSERT_ERROR(smP>getMajorDim() == 5, return 1, "cbc", "getMatrixByRow: major dim"); 201 OSIUNITTEST_ASSERT_ERROR(smP>getMinorDim() == 8, return 1, "cbc", "getMatrixByRow: major dim"); 202 OSIUNITTEST_ASSERT_ERROR(smP>getNumElements() == 14, return 1, "cbc", "getMatrixByRow: num elements"); 203 OSIUNITTEST_ASSERT_ERROR(smP>getSizeVectorStarts() == 6, return 1, "cbc", "getMatrixByRow: num elements"); 416 204 417 205 #ifdef OSICBC_TEST_MTX_STRUCTURE 418 419 206 CoinRelFltEq eq; 420 207 const double * ev = smP>getElements(); 421 assert( eq(ev[0], 3.0));422 assert( eq(ev[1], 1.0));423 assert( eq(ev[2], 2.0));424 assert( eq(ev[3], 1.0));425 assert( eq(ev[4], 1.0));426 assert( eq(ev[5], 2.0));427 assert( eq(ev[6], 1.1));428 assert( eq(ev[7], 1.0));429 assert( eq(ev[8], 1.0));430 assert( eq(ev[9], 2.8));431 assert( eq(ev[10], 1.2));432 assert( eq(ev[11], 5.6));433 assert( eq(ev[12], 1.0));434 assert( eq(ev[13], 1.9));435 436 const CoinBigIndex* mi = smP>getVectorStarts();437 assert( mi[0]==0);438 assert( mi[1]==5);439 assert( mi[2]==7);440 assert( mi[3]==9);441 assert( mi[4]==11);442 assert( mi[5]==14);208 OSIUNITTEST_ASSERT_ERROR(eq(ev[0], 3.0), {}, "cbc", "getMatrixByRow: elements"); 209 OSIUNITTEST_ASSERT_ERROR(eq(ev[1], 1.0), {}, "cbc", "getMatrixByRow: elements"); 210 OSIUNITTEST_ASSERT_ERROR(eq(ev[2], 2.0), {}, "cbc", "getMatrixByRow: elements"); 211 OSIUNITTEST_ASSERT_ERROR(eq(ev[3], 1.0), {}, "cbc", "getMatrixByRow: elements"); 212 OSIUNITTEST_ASSERT_ERROR(eq(ev[4], 1.0), {}, "cbc", "getMatrixByRow: elements"); 213 OSIUNITTEST_ASSERT_ERROR(eq(ev[5], 2.0), {}, "cbc", "getMatrixByRow: elements"); 214 OSIUNITTEST_ASSERT_ERROR(eq(ev[6], 1.1), {}, "cbc", "getMatrixByRow: elements"); 215 OSIUNITTEST_ASSERT_ERROR(eq(ev[7], 1.0), {}, "cbc", "getMatrixByRow: elements"); 216 OSIUNITTEST_ASSERT_ERROR(eq(ev[8], 1.0), {}, "cbc", "getMatrixByRow: elements"); 217 OSIUNITTEST_ASSERT_ERROR(eq(ev[9], 2.8), {}, "cbc", "getMatrixByRow: elements"); 218 OSIUNITTEST_ASSERT_ERROR(eq(ev[10], 1.2), {}, "cbc", "getMatrixByRow: elements"); 219 OSIUNITTEST_ASSERT_ERROR(eq(ev[11], 5.6), {}, "cbc", "getMatrixByRow: elements"); 220 OSIUNITTEST_ASSERT_ERROR(eq(ev[12], 1.0), {}, "cbc", "getMatrixByRow: elements"); 221 OSIUNITTEST_ASSERT_ERROR(eq(ev[13], 1.9), {}, "cbc", "getMatrixByRow: elements"); 222 223 const int * mi = smP>getVectorStarts(); 224 OSIUNITTEST_ASSERT_ERROR(mi[0] == 0, {}, "cbc", "getMatrixByRow: vector starts"); 225 OSIUNITTEST_ASSERT_ERROR(mi[1] == 5, {}, "cbc", "getMatrixByRow: vector starts"); 226 OSIUNITTEST_ASSERT_ERROR(mi[2] == 7, {}, "cbc", "getMatrixByRow: vector starts"); 227 OSIUNITTEST_ASSERT_ERROR(mi[3] == 9, {}, "cbc", "getMatrixByRow: vector starts"); 228 OSIUNITTEST_ASSERT_ERROR(mi[4] == 11, {}, "cbc", "getMatrixByRow: vector starts"); 229 OSIUNITTEST_ASSERT_ERROR(mi[5] == 14, {}, "cbc", "getMatrixByRow: vector starts"); 443 230 444 231 const int * ei = smP>getIndices(); 445 assert( ei[0] == 0 ); 446 assert( ei[1] == 1 ); 447 assert( ei[2] == 3 ); 448 assert( ei[3] == 4 ); 449 assert( ei[4] == 7 ); 450 assert( ei[5] == 1 ); 451 assert( ei[6] == 2 ); 452 assert( ei[7] == 2 ); 453 assert( ei[8] == 5 ); 454 assert( ei[9] == 3 ); 455 assert( ei[10] == 6 ); 456 assert( ei[11] == 0 ); 457 assert( ei[12] == 4 ); 458 assert( ei[13] == 7 ); 459 232 OSIUNITTEST_ASSERT_ERROR(ei[ 0] == 0, {}, "cbc", "getMatrixByRow: indices"); 233 OSIUNITTEST_ASSERT_ERROR(ei[ 1] == 1, {}, "cbc", "getMatrixByRow: indices"); 234 OSIUNITTEST_ASSERT_ERROR(ei[ 2] == 3, {}, "cbc", "getMatrixByRow: indices"); 235 OSIUNITTEST_ASSERT_ERROR(ei[ 3] == 4, {}, "cbc", "getMatrixByRow: indices"); 236 OSIUNITTEST_ASSERT_ERROR(ei[ 4] == 7, {}, "cbc", "getMatrixByRow: indices"); 237 OSIUNITTEST_ASSERT_ERROR(ei[ 5] == 1, {}, "cbc", "getMatrixByRow: indices"); 238 OSIUNITTEST_ASSERT_ERROR(ei[ 6] == 2, {}, "cbc", "getMatrixByRow: indices"); 239 OSIUNITTEST_ASSERT_ERROR(ei[ 7] == 2, {}, "cbc", "getMatrixByRow: indices"); 240 OSIUNITTEST_ASSERT_ERROR(ei[ 8] == 5, {}, "cbc", "getMatrixByRow: indices"); 241 OSIUNITTEST_ASSERT_ERROR(ei[ 9] == 3, {}, "cbc", "getMatrixByRow: indices"); 242 OSIUNITTEST_ASSERT_ERROR(ei[10] == 6, {}, "cbc", "getMatrixByRow: indices"); 243 OSIUNITTEST_ASSERT_ERROR(ei[11] == 0, {}, "cbc", "getMatrixByRow: indices"); 244 OSIUNITTEST_ASSERT_ERROR(ei[12] == 4, {}, "cbc", "getMatrixByRow: indices"); 245 OSIUNITTEST_ASSERT_ERROR(ei[13] == 7, {}, "cbc", "getMatrixByRow: indices"); 460 246 #else // OSICBC_TEST_MTX_STRUCTURE 461 247 462 248 CoinPackedMatrix exmip1Mtx ; 463 249 exmip1Mtx.reverseOrderedCopyOf(BuildExmip1Mtx()) ; 464 assert( exmip1Mtx.isEquivalent(*smP) ) ; 465 250 OSIUNITTEST_ASSERT_ERROR(exmip1Mtx.isEquivalent(*smP), {}, "cbc", "getMatrixByRow") ; 466 251 #endif // OSICBC_TEST_MTX_STRUCTURE 467 468 assert( smP>getMajorDim() == 5 );469 assert( smP>getMinorDim() == 8 );470 assert( smP>getNumElements() == 14 );471 assert( smP>getSizeVectorStarts() == 6 );472 252 } 473 253 … … 514 294 const double * cs = fim.getColSolution(); 515 295 CoinRelFltEq eq; 516 assert( eq(cs[2], 1.0));517 assert( eq(cs[3], 1.0));296 OSIUNITTEST_ASSERT_ERROR(eq(cs[2], 1.0), {}, "cbc", "add cuts"); 297 OSIUNITTEST_ASSERT_ERROR(eq(cs[3], 1.0), {}, "cbc", "add cuts"); 518 298 // check will find invalid matrix 519 299 el[0]=1.0/el[4]; … … 526 306 // resolve  should get message about zero elements 527 307 fim.resolve(); 528 assert (fim.isAbandoned());308 OSIUNITTEST_ASSERT_WARNING(fim.isAbandoned(), {}, "cbc", "add cuts"); 529 309 delete[]el; 530 310 delete[]inx; 531 311 } 532 312 533 313 // Test matrixByCol method 534 314 { 535 536 315 const OsiCbcSolverInterface si(m); 537 316 const CoinPackedMatrix * smP = si.getMatrixByCol(); 538 // LL: const OsiCbcPackedMatrix * osmP = dynamic_cast<const OsiCbcPackedMatrix*>(smP); 539 // LL: assert( osmP!=NULL ); 540 317 318 OSIUNITTEST_ASSERT_ERROR(smP>getMajorDim() == 8, return 1, "cbc", "getMatrixByCol: major dim"); 319 OSIUNITTEST_ASSERT_ERROR(smP>getMinorDim() == 5, return 1, "cbc", "getMatrixByCol: minor dim"); 320 OSIUNITTEST_ASSERT_ERROR(smP>getNumElements() == 14, return 1, "cbc", "getMatrixByCol: number of elements"); 321 OSIUNITTEST_ASSERT_ERROR(smP>getSizeVectorStarts() == 9, return 1, "cbc", "getMatrixByCol: vector starts size"); 322 541 323 #ifdef OSICBC_TEST_MTX_STRUCTURE 542 543 324 CoinRelFltEq eq; 544 325 const double * ev = smP>getElements(); 545 assert( eq(ev[0], 3.0));546 assert( eq(ev[1], 5.6));547 assert( eq(ev[2], 1.0));548 assert( eq(ev[3], 2.0));549 assert( eq(ev[4], 1.1));550 assert( eq(ev[5], 1.0));551 assert( eq(ev[6], 2.0));552 assert( eq(ev[7], 2.8));553 assert( eq(ev[8], 1.0));554 assert( eq(ev[9], 1.0));555 assert( eq(ev[10], 1.0));556 assert( eq(ev[11], 1.2));557 assert( eq(ev[12], 1.0));558 assert( eq(ev[13], 1.9));326 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 0], 3.0), {}, "cbc", "getMatrixByCol: elements"); 327 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 1], 5.6), {}, "cbc", "getMatrixByCol: elements"); 328 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 2], 1.0), {}, "cbc", "getMatrixByCol: elements"); 329 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 3], 2.0), {}, "cbc", "getMatrixByCol: elements"); 330 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 4], 1.1), {}, "cbc", "getMatrixByCol: elements"); 331 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 5], 1.0), {}, "cbc", "getMatrixByCol: elements"); 332 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 6],2.0), {}, "cbc", "getMatrixByCol: elements"); 333 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 7], 2.8), {}, "cbc", "getMatrixByCol: elements"); 334 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 8],1.0), {}, "cbc", "getMatrixByCol: elements"); 335 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 9], 1.0), {}, "cbc", "getMatrixByCol: elements"); 336 OSIUNITTEST_ASSERT_ERROR(eq(ev[10], 1.0), {}, "cbc", "getMatrixByCol: elements"); 337 OSIUNITTEST_ASSERT_ERROR(eq(ev[11],1.2), {}, "cbc", "getMatrixByCol: elements"); 338 OSIUNITTEST_ASSERT_ERROR(eq(ev[12],1.0), {}, "cbc", "getMatrixByCol: elements"); 339 OSIUNITTEST_ASSERT_ERROR(eq(ev[13], 1.9), {}, "cbc", "getMatrixByCol: elements"); 559 340 560 341 const CoinBigIndex * mi = smP>getVectorStarts(); 561 assert( mi[0]==0);562 assert( mi[1]==2);563 assert( mi[2]==4);564 assert( mi[3]==6);565 assert( mi[4]==8);566 assert( mi[5]==10);567 assert( mi[6]==11);568 assert( mi[7]==12);569 assert( mi[8]==14);342 OSIUNITTEST_ASSERT_ERROR(mi[0] == 0, {}, "cbc", "getMatrixByCol: vector starts"); 343 OSIUNITTEST_ASSERT_ERROR(mi[1] == 2, {}, "cbc", "getMatrixByCol: vector starts"); 344 OSIUNITTEST_ASSERT_ERROR(mi[2] == 4, {}, "cbc", "getMatrixByCol: vector starts"); 345 OSIUNITTEST_ASSERT_ERROR(mi[3] == 6, {}, "cbc", "getMatrixByCol: vector starts"); 346 OSIUNITTEST_ASSERT_ERROR(mi[4] == 8, {}, "cbc", "getMatrixByCol: vector starts"); 347 OSIUNITTEST_ASSERT_ERROR(mi[5] == 10, {}, "cbc", "getMatrixByCol: vector starts"); 348 OSIUNITTEST_ASSERT_ERROR(mi[6] == 11, {}, "cbc", "getMatrixByCol: vector starts"); 349 OSIUNITTEST_ASSERT_ERROR(mi[7] == 12, {}, "cbc", "getMatrixByCol: vector starts"); 350 OSIUNITTEST_ASSERT_ERROR(mi[8] == 14, {}, "cbc", "getMatrixByCol: vector starts"); 570 351 571 352 const int * ei = smP>getIndices(); 572 assert( ei[0] == 0 ); 573 assert( ei[1] == 4 ); 574 assert( ei[2] == 0 ); 575 assert( ei[3] == 1 ); 576 assert( ei[4] == 1 ); 577 assert( ei[5] == 2 ); 578 assert( ei[6] == 0 ); 579 assert( ei[7] == 3 ); 580 assert( ei[8] == 0 ); 581 assert( ei[9] == 4 ); 582 assert( ei[10] == 2 ); 583 assert( ei[11] == 3 ); 584 assert( ei[12] == 0 ); 585 assert( ei[13] == 4 ); 586 353 OSIUNITTEST_ASSERT_ERROR(ei[ 0] == 0, {}, "cbc", "getMatrixByCol: indices"); 354 OSIUNITTEST_ASSERT_ERROR(ei[ 1] == 4, {}, "cbc", "getMatrixByCol: indices"); 355 OSIUNITTEST_ASSERT_ERROR(ei[ 2] == 0, {}, "cbc", "getMatrixByCol: indices"); 356 OSIUNITTEST_ASSERT_ERROR(ei[ 3] == 1, {}, "cbc", "getMatrixByCol: indices"); 357 OSIUNITTEST_ASSERT_ERROR(ei[ 4] == 1, {}, "cbc", "getMatrixByCol: indices"); 358 OSIUNITTEST_ASSERT_ERROR(ei[ 5] == 2, {}, "cbc", "getMatrixByCol: indices"); 359 OSIUNITTEST_ASSERT_ERROR(ei[ 6] == 0, {}, "cbc", "getMatrixByCol: indices"); 360 OSIUNITTEST_ASSERT_ERROR(ei[ 7] == 3, {}, "cbc", "getMatrixByCol: indices"); 361 OSIUNITTEST_ASSERT_ERROR(ei[ 8] == 0, {}, "cbc", "getMatrixByCol: indices"); 362 OSIUNITTEST_ASSERT_ERROR(ei[ 9] == 4, {}, "cbc", "getMatrixByCol: indices"); 363 OSIUNITTEST_ASSERT_ERROR(ei[10] == 2, {}, "cbc", "getMatrixByCol: indices"); 364 OSIUNITTEST_ASSERT_ERROR(ei[11] == 3, {}, "cbc", "getMatrixByCol: indices"); 365 OSIUNITTEST_ASSERT_ERROR(ei[12] == 0, {}, "cbc", "getMatrixByCol: indices"); 366 OSIUNITTEST_ASSERT_ERROR(ei[13] == 4, {}, "cbc", "getMatrixByCol: indices"); 587 367 #else // OSICBC_TEST_MTX_STRUCTURE 588 368 589 369 CoinPackedMatrix &exmip1Mtx = BuildExmip1Mtx() ; 590 assert( exmip1Mtx.isEquivalent(*smP) ) ; 591 370 OSIUNITTEST_ASSERT_ERROR(exmip1Mtx.isEquivalent(*smP), {}, "cbc", "getMatrixByCol"); 592 371 #endif // OSICBC_TEST_MTX_STRUCTURE 593 594 assert( smP>getMajorDim() == 8 );595 assert( smP>getMinorDim() == 5 );596 assert( smP>getNumElements() == 14 );597 assert( smP>getSizeVectorStarts() == 9 );598 372 } 599 373 … … 602 376 { 603 377 OsiCbcSolverInterface lhs; 604 { 605 606 OsiCbcSolverInterface siC1(m); 378 { 379 OsiCbcSolverInterface siC1(m); 380 607 381 const char * siC1rs = siC1.getRowSense(); 608 assert( siC1rs[0]=='G');609 assert( siC1rs[1]=='L');610 assert( siC1rs[2]=='E');611 assert( siC1rs[3]=='R');612 assert( siC1rs[4]=='R');613 382 OSIUNITTEST_ASSERT_ERROR(siC1rs[0] == 'G', {}, "cbc", "row sense"); 383 OSIUNITTEST_ASSERT_ERROR(siC1rs[1] == 'L', {}, "cbc", "row sense"); 384 OSIUNITTEST_ASSERT_ERROR(siC1rs[2] == 'E', {}, "cbc", "row sense"); 385 OSIUNITTEST_ASSERT_ERROR(siC1rs[3] == 'R', {}, "cbc", "row sense"); 386 OSIUNITTEST_ASSERT_ERROR(siC1rs[4] == 'R', {}, "cbc", "row sense"); 387 614 388 const double * siC1rhs = siC1.getRightHandSide(); 615 assert( eq(siC1rhs[0],2.5));616 assert( eq(siC1rhs[1],2.1));617 assert( eq(siC1rhs[2],4.0));618 assert( eq(siC1rhs[3],5.0));619 assert( eq(siC1rhs[4],15.) );620 389 OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[0],2.5), {}, "cbc", "right hand side"); 390 OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[1],2.1), {}, "cbc", "right hand side"); 391 OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[2],4.0), {}, "cbc", "right hand side"); 392 OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[3],5.0), {}, "cbc", "right hand side"); 393 OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[4],15.), {}, "cbc", "right hand side"); 394 621 395 const double * siC1rr = siC1.getRowRange(); 622 assert( eq(siC1rr[0],0.0));623 assert( eq(siC1rr[1],0.0));624 assert( eq(siC1rr[2],0.0));625 assert( eq(siC1rr[3],5.01.8));626 assert( eq(siC1rr[4],15.03.0));396 OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[0],0.0), {}, "cbc", "row range"); 397 OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[1],0.0), {}, "cbc", "row range"); 398 OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[2],0.0), {}, "cbc", "row range"); 399 OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[3],5.01.8), {}, "cbc", "row range"); 400 OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[4],15.03.0), {}, "cbc", "row range"); 627 401 628 402 const CoinPackedMatrix * siC1mbr = siC1.getMatrixByRow(); 629 assert( siC1mbr != NULL ); 403 OSIUNITTEST_ASSERT_ERROR(siC1mbr != NULL, {}, "cbc", "matrix by row"); 404 OSIUNITTEST_ASSERT_ERROR(siC1mbr>getMajorDim() == 5, return 1, "cbc", "matrix by row: major dim"); 405 OSIUNITTEST_ASSERT_ERROR(siC1mbr>getMinorDim() == 8, return 1, "cbc", "matrix by row: major dim"); 406 OSIUNITTEST_ASSERT_ERROR(siC1mbr>getNumElements() == 14, return 1, "cbc", "matrix by row: num elements"); 407 OSIUNITTEST_ASSERT_ERROR(siC1mbr>getSizeVectorStarts() == 6, return 1, "cbc", "matrix by row: num elements"); 630 408 631 409 #ifdef OSICBC_TEST_MTX_STRUCTURE 632 633 410 const double * ev = siC1mbr>getElements(); 634 assert( eq(ev[0], 3.0));635 assert( eq(ev[1], 1.0));636 assert( eq(ev[2], 2.0));637 assert( eq(ev[3], 1.0));638 assert( eq(ev[4], 1.0));639 assert( eq(ev[5], 2.0));640 assert( eq(ev[6], 1.1));641 assert( eq(ev[7], 1.0));642 assert( eq(ev[8], 1.0));643 assert( eq(ev[9], 2.8));644 assert( eq(ev[10], 1.2));645 assert( eq(ev[11], 5.6));646 assert( eq(ev[12], 1.0));647 assert( eq(ev[13], 1.9));648 411 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 0], 3.0), {}, "cbc", "matrix by row: elements"); 412 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 1], 1.0), {}, "cbc", "matrix by row: elements"); 413 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 2],2.0), {}, "cbc", "matrix by row: elements"); 414 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 3],1.0), {}, "cbc", "matrix by row: elements"); 415 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 4],1.0), {}, "cbc", "matrix by row: elements"); 416 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 5], 2.0), {}, "cbc", "matrix by row: elements"); 417 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 6], 1.1), {}, "cbc", "matrix by row: elements"); 418 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 7], 1.0), {}, "cbc", "matrix by row: elements"); 419 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 8], 1.0), {}, "cbc", "matrix by row: elements"); 420 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 9], 2.8), {}, "cbc", "matrix by row: elements"); 421 OSIUNITTEST_ASSERT_ERROR(eq(ev[10],1.2), {}, "cbc", "matrix by row: elements"); 422 OSIUNITTEST_ASSERT_ERROR(eq(ev[11], 5.6), {}, "cbc", "matrix by row: elements"); 423 OSIUNITTEST_ASSERT_ERROR(eq(ev[12], 1.0), {}, "cbc", "matrix by row: elements"); 424 OSIUNITTEST_ASSERT_ERROR(eq(ev[13], 1.9), {}, "cbc", "matrix by row: elements"); 425 649 426 const CoinBigIndex * mi = siC1mbr>getVectorStarts(); 650 assert( mi[0]==0);651 assert( mi[1]==5);652 assert( mi[2]==7);653 assert( mi[3]==9);654 assert( mi[4]==11);655 assert( mi[5]==14);656 427 OSIUNITTEST_ASSERT_ERROR(mi[0] == 0, {}, "cbc", "matrix by row: vector starts"); 428 OSIUNITTEST_ASSERT_ERROR(mi[1] == 5, {}, "cbc", "matrix by row: vector starts"); 429 OSIUNITTEST_ASSERT_ERROR(mi[2] == 7, {}, "cbc", "matrix by row: vector starts"); 430 OSIUNITTEST_ASSERT_ERROR(mi[3] == 9, {}, "cbc", "matrix by row: vector starts"); 431 OSIUNITTEST_ASSERT_ERROR(mi[4] == 11, {}, "cbc", "matrix by row: vector starts"); 432 OSIUNITTEST_ASSERT_ERROR(mi[5] == 14, {}, "cbc", "matrix by row: vector starts"); 433 657 434 const int * ei = siC1mbr>getIndices(); 658 assert( ei[0] == 0 ); 659 assert( ei[1] == 1 ); 660 assert( ei[2] == 3 ); 661 assert( ei[3] == 4 ); 662 assert( ei[4] == 7 ); 663 assert( ei[5] == 1 ); 664 assert( ei[6] == 2 ); 665 assert( ei[7] == 2 ); 666 assert( ei[8] == 5 ); 667 assert( ei[9] == 3 ); 668 assert( ei[10] == 6 ); 669 assert( ei[11] == 0 ); 670 assert( ei[12] == 4 ); 671 assert( ei[13] == 7 ); 672 435 OSIUNITTEST_ASSERT_ERROR(ei[ 0] == 0, {}, "cbc", "matrix by row: indices"); 436 OSIUNITTEST_ASSERT_ERROR(ei[ 1] == 1, {}, "cbc", "matrix by row: indices"); 437 OSIUNITTEST_ASSERT_ERROR(ei[ 2] == 3, {}, "cbc", "matrix by row: indices"); 438 OSIUNITTEST_ASSERT_ERROR(ei[ 3] == 4, {}, "cbc", "matrix by row: indices"); 439 OSIUNITTEST_ASSERT_ERROR(ei[ 4] == 7, {}, "cbc", "matrix by row: indices"); 440 OSIUNITTEST_ASSERT_ERROR(ei[ 5] == 1, {}, "cbc", "matrix by row: indices"); 441 OSIUNITTEST_ASSERT_ERROR(ei[ 6] == 2, {}, "cbc", "matrix by row: indices"); 442 OSIUNITTEST_ASSERT_ERROR(ei[ 7] == 2, {}, "cbc", "matrix by row: indices"); 443 OSIUNITTEST_ASSERT_ERROR(ei[ 8] == 5, {}, "cbc", "matrix by row: indices"); 444 OSIUNITTEST_ASSERT_ERROR(ei[ 9] == 3, {}, "cbc", "matrix by row: indices"); 445 OSIUNITTEST_ASSERT_ERROR(ei[10] == 6, {}, "cbc", "matrix by row: indices"); 446 OSIUNITTEST_ASSERT_ERROR(ei[11] == 0, {}, "cbc", "matrix by row: indices"); 447 OSIUNITTEST_ASSERT_ERROR(ei[12] == 4, {}, "cbc", "matrix by row: indices"); 448 OSIUNITTEST_ASSERT_ERROR(ei[13] == 7, {}, "cbc", "matrix by row: indices"); 673 449 #else // OSICBC_TEST_MTX_STRUCTURE 674 450 675 CoinPackedMatrix exmip1Mtx ; 676 exmip1Mtx.reverseOrderedCopyOf(BuildExmip1Mtx()) ; 677 assert( exmip1Mtx.isEquivalent(*siC1mbr) ) ; 678 451 CoinPackedMatrix exmip1Mtx ; 452 exmip1Mtx.reverseOrderedCopyOf(BuildExmip1Mtx()) ; 453 OSIUNITTEST_ASSERT_ERROR(exmip1Mtx.isEquivalent(*siC1mbr), {}, "cbc", "matrix by row"); 679 454 #endif // OSICBC_TEST_MTX_STRUCTURE 680 455 681 assert( siC1mbr>getMajorDim() == 5 ); 682 assert( siC1mbr>getMinorDim() == 8 ); 683 assert( siC1mbr>getNumElements() == 14 ); 684 assert( siC1mbr>getSizeVectorStarts()==6 ); 685 686 assert( siC1rs == siC1.getRowSense() ); 687 assert( siC1rhs == siC1.getRightHandSide() ); 688 assert( siC1rr == siC1.getRowRange() ); 689 690 // Change OSL Model by adding free row 456 OSIUNITTEST_ASSERT_WARNING(siC1rs == siC1.getRowSense(), {}, "cbc", "row sense"); 457 OSIUNITTEST_ASSERT_WARNING(siC1rhs == siC1.getRightHandSide(), {}, "cbc", "right hand side"); 458 OSIUNITTEST_ASSERT_WARNING(siC1rr == siC1.getRowRange(), {}, "cbc", "row range"); 459 460 // Change CBC Model by adding free row 691 461 OsiRowCut rc; 692 rc.setLb( DBL_MAX);693 rc.setUb( DBL_MAX);462 rc.setLb(COIN_DBL_MAX); 463 rc.setUb( COIN_DBL_MAX); 694 464 OsiCuts cuts; 695 465 cuts.insert(rc); 696 466 siC1.applyCuts(cuts); 697 698 467 699 468 siC1rs = siC1.getRowSense(); 700 assert( siC1rs[0]=='G');701 assert( siC1rs[1]=='L');702 assert( siC1rs[2]=='E');703 assert( siC1rs[3]=='R');704 assert( siC1rs[4]=='R');705 assert( siC1rs[5]=='N');469 OSIUNITTEST_ASSERT_ERROR(siC1rs[0] == 'G', {}, "cbc", "row sense after adding row"); 470 OSIUNITTEST_ASSERT_ERROR(siC1rs[1] == 'L', {}, "cbc", "row sense after adding row"); 471 OSIUNITTEST_ASSERT_ERROR(siC1rs[2] == 'E', {}, "cbc", "row sense after adding row"); 472 OSIUNITTEST_ASSERT_ERROR(siC1rs[3] == 'R', {}, "cbc", "row sense after adding row"); 473 OSIUNITTEST_ASSERT_ERROR(siC1rs[4] == 'R', {}, "cbc", "row sense after adding row"); 474 OSIUNITTEST_ASSERT_ERROR(siC1rs[5] == 'N', {}, "cbc", "row sense after adding row"); 706 475 707 476 siC1rhs = siC1.getRightHandSide(); 708 assert( eq(siC1rhs[0],2.5));709 assert( eq(siC1rhs[1],2.1));710 assert( eq(siC1rhs[2],4.0));711 assert( eq(siC1rhs[3],5.0));712 assert( eq(siC1rhs[4],15.) );713 assert( eq(siC1rhs[5],0.0 ) );477 OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[0],2.5), {}, "cbc", "right hand side after adding row"); 478 OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[1],2.1), {}, "cbc", "right hand side after adding row"); 479 OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[2],4.0), {}, "cbc", "right hand side after adding row"); 480 OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[3],5.0), {}, "cbc", "right hand side after adding row"); 481 OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[4],15.), {}, "cbc", "right hand side after adding row"); 482 OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[5],0.0), {}, "cbc", "right hand side after adding row"); 714 483 715 484 siC1rr = siC1.getRowRange(); 716 assert( eq(siC1rr[0],0.0) ); 717 assert( eq(siC1rr[1],0.0) ); 718 assert( eq(siC1rr[2],0.0) ); 719 assert( eq(siC1rr[3],5.01.8) ); 720 assert( eq(siC1rr[4],15.03.0) ); 721 assert( eq(siC1rr[5],0.0) ); 722 723 lhs=siC1; 724 } 485 OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[0],0.0), {}, "cbc", "row range after adding row"); 486 OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[1],0.0), {}, "cbc", "row range after adding row"); 487 OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[2],0.0), {}, "cbc", "row range after adding row"); 488 OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[3],5.01.8), {}, "cbc", "row range after adding row"); 489 OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[4],15.03.0), {}, "cbc", "row range after adding row"); 490 OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[5],0.0), {}, "cbc", "row range after adding row"); 491 492 lhs = siC1; 493 } 494 725 495 // Test that lhs has correct values even though siC1 has gone out of scope 726 727 496 const char * lhsrs = lhs.getRowSense(); 728 assert( lhsrs[0]=='G');729 assert( lhsrs[1]=='L');730 assert( lhsrs[2]=='E');731 assert( lhsrs[3]=='R');732 assert( lhsrs[4]=='R');733 assert( lhsrs[5]=='N');497 OSIUNITTEST_ASSERT_ERROR(lhsrs[0] == 'G', {}, "cbc", "row sense after assignment"); 498 OSIUNITTEST_ASSERT_ERROR(lhsrs[1] == 'L', {}, "cbc", "row sense after assignment"); 499 OSIUNITTEST_ASSERT_ERROR(lhsrs[2] == 'E', {}, "cbc", "row sense after assignment"); 500 OSIUNITTEST_ASSERT_ERROR(lhsrs[3] == 'R', {}, "cbc", "row sense after assignment"); 501 OSIUNITTEST_ASSERT_ERROR(lhsrs[4] == 'R', {}, "cbc", "row sense after assignment"); 502 OSIUNITTEST_ASSERT_ERROR(lhsrs[5] == 'N', {}, "cbc", "row sense after assignment"); 734 503 735 504 const double * lhsrhs = lhs.getRightHandSide(); 736 assert( eq(lhsrhs[0],2.5));737 assert( eq(lhsrhs[1],2.1));738 assert( eq(lhsrhs[2],4.0));739 assert( eq(lhsrhs[3],5.0));740 assert( eq(lhsrhs[4],15.) );741 assert( eq(lhsrhs[5],0.0) );742 743 const double *lhsrr 744 assert( eq(lhsrr[0],0.0));745 assert( eq(lhsrr[1],0.0));746 assert( eq(lhsrr[2],0.0));747 assert( eq(lhsrr[3],5.01.8));748 assert( eq(lhsrr[4],15.03.0));749 assert( eq(lhsrr[5],0.0) );505 OSIUNITTEST_ASSERT_ERROR(eq(lhsrhs[0],2.5), {}, "cbc", "right hand side after assignment"); 506 OSIUNITTEST_ASSERT_ERROR(eq(lhsrhs[1],2.1), {}, "cbc", "right hand side after assignment"); 507 OSIUNITTEST_ASSERT_ERROR(eq(lhsrhs[2],4.0), {}, "cbc", "right hand side after assignment"); 508 OSIUNITTEST_ASSERT_ERROR(eq(lhsrhs[3],5.0), {}, "cbc", "right hand side after assignment"); 509 OSIUNITTEST_ASSERT_ERROR(eq(lhsrhs[4],15.), {}, "cbc", "right hand side after assignment"); 510 OSIUNITTEST_ASSERT_ERROR(eq(lhsrhs[5],0.0), {}, "cbc", "right hand side after assignment"); 511 512 const double *lhsrr = lhs.getRowRange(); 513 OSIUNITTEST_ASSERT_ERROR(eq(lhsrr[0],0.0), {}, "cbc", "row range after assignment"); 514 OSIUNITTEST_ASSERT_ERROR(eq(lhsrr[1],0.0), {}, "cbc", "row range after assignment"); 515 OSIUNITTEST_ASSERT_ERROR(eq(lhsrr[2],0.0), {}, "cbc", "row range after assignment"); 516 OSIUNITTEST_ASSERT_ERROR(eq(lhsrr[3],5.01.8), {}, "cbc", "row range after assignment"); 517 OSIUNITTEST_ASSERT_ERROR(eq(lhsrr[4],15.03.0), {}, "cbc", "row range after assignment"); 518 OSIUNITTEST_ASSERT_ERROR(eq(lhsrr[5],0.0), {}, "cbc", "row range after assignment"); 750 519 751 520 const CoinPackedMatrix * lhsmbr = lhs.getMatrixByRow(); 752 assert( lhsmbr != NULL ); 521 OSIUNITTEST_ASSERT_ERROR(lhsmbr != NULL, {}, "cbc", "matrix by row after assignment"); 522 OSIUNITTEST_ASSERT_ERROR(lhsmbr>getMajorDim() == 6, return 1, "cbc", "matrix by row after assignment: major dim"); 523 OSIUNITTEST_ASSERT_ERROR(lhsmbr>getNumElements() == 14, return 1, "cbc", "matrix by row after assignment: num elements"); 524 753 525 754 526 #ifdef OSICBC_TEST_MTX_STRUCTURE 755 756 527 const double * ev = lhsmbr>getElements(); 757 assert( eq(ev[0], 3.0));758 assert( eq(ev[1], 1.0));759 assert( eq(ev[2], 2.0));760 assert( eq(ev[3], 1.0));761 assert( eq(ev[4], 1.0));762 assert( eq(ev[5], 2.0));763 assert( eq(ev[6], 1.1));764 assert( eq(ev[7], 1.0));765 assert( eq(ev[8], 1.0));766 assert( eq(ev[9], 2.8));767 assert( eq(ev[10], 1.2));768 assert( eq(ev[11], 5.6));769 assert( eq(ev[12], 1.0));770 assert( eq(ev[13], 1.9));528 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 0], 3.0), {}, "cbc", "matrix by row after assignment: elements"); 529 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 1], 1.0), {}, "cbc", "matrix by row after assignment: elements"); 530 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 2],2.0), {}, "cbc", "matrix by row after assignment: elements"); 531 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 3],1.0), {}, "cbc", "matrix by row after assignment: elements"); 532 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 4],1.0), {}, "cbc", "matrix by row after assignment: elements"); 533 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 5], 2.0), {}, "cbc", "matrix by row after assignment: elements"); 534 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 6], 1.1), {}, "cbc", "matrix by row after assignment: elements"); 535 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 7], 1.0), {}, "cbc", "matrix by row after assignment: elements"); 536 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 8], 1.0), {}, "cbc", "matrix by row after assignment: elements"); 537 OSIUNITTEST_ASSERT_ERROR(eq(ev[ 9], 2.8), {}, "cbc", "matrix by row after assignment: elements"); 538 OSIUNITTEST_ASSERT_ERROR(eq(ev[10],1.2), {}, "cbc", "matrix by row after assignment: elements"); 539 OSIUNITTEST_ASSERT_ERROR(eq(ev[11], 5.6), {}, "cbc", "matrix by row after assignment: elements"); 540 OSIUNITTEST_ASSERT_ERROR(eq(ev[12], 1.0), {}, "cbc", "matrix by row after assignment: elements"); 541 OSIUNITTEST_ASSERT_ERROR(eq(ev[13], 1.9), {}, "cbc", "matrix by row after assignment: elements"); 771 542 772 543 const CoinBigIndex * mi = lhsmbr>getVectorStarts(); 773 assert( mi[0]==0);774 assert( mi[1]==5);775 assert( mi[2]==7);776 assert( mi[3]==9);777 assert( mi[4]==11);778 assert( mi[5]==14);544 OSIUNITTEST_ASSERT_ERROR(mi[0] == 0, {}, "cbc", "matrix by row after assignment: vector starts"); 545 OSIUNITTEST_ASSERT_ERROR(mi[1] == 5, {}, "cbc", "matrix by row after assignment: vector starts"); 546 OSIUNITTEST_ASSERT_ERROR(mi[2] == 7, {}, "cbc", "matrix by row after assignment: vector starts"); 547 OSIUNITTEST_ASSERT_ERROR(mi[3] == 9, {}, "cbc", "matrix by row after assignment: vector starts"); 548 OSIUNITTEST_ASSERT_ERROR(mi[4] == 11, {}, "cbc", "matrix by row after assignment: vector starts"); 549 OSIUNITTEST_ASSERT_ERROR(mi[5] == 14, {}, "cbc", "matrix by row after assignment: vector starts"); 779 550 780 551 const int * ei = lhsmbr>getIndices(); 781 assert( ei[0] == 0 ); 782 assert( ei[1] == 1 ); 783 assert( ei[2] == 3 ); 784 assert( ei[3] == 4 ); 785 assert( ei[4] == 7 ); 786 assert( ei[5] == 1 ); 787 assert( ei[6] == 2 ); 788 assert( ei[7] == 2 ); 789 assert( ei[8] == 5 ); 790 assert( ei[9] == 3 ); 791 assert( ei[10] == 6 ); 792 assert( ei[11] == 0 ); 793 assert( ei[12] == 4 ); 794 assert( ei[13] == 7 ); 795 552 OSIUNITTEST_ASSERT_ERROR(ei[ 0] == 0, {}, "cbc", "matrix by row after assignment: indices"); 553 OSIUNITTEST_ASSERT_ERROR(ei[ 1] == 1, {}, "cbc", "matrix by row after assignment: indices"); 554 OSIUNITTEST_ASSERT_ERROR(ei[ 2] == 3, {}, "cbc", "matrix by row after assignment: indices"); 555 OSIUNITTEST_ASSERT_ERROR(ei[ 3] == 4, {}, "cbc", "matrix by row after assignment: indices"); 556 OSIUNITTEST_ASSERT_ERROR(ei[ 4] == 7, {}, "cbc", "matrix by row after assignment: indices"); 557 OSIUNITTEST_ASSERT_ERROR(ei[ 5] == 1, {}, "cbc", "matrix by row after assignment: indices"); 558 OSIUNITTEST_ASSERT_ERROR(ei[ 6] == 2, {}, "cbc", "matrix by row after assignment: indices"); 559 OSIUNITTEST_ASSERT_ERROR(ei[ 7] == 2, {}, "cbc", "matrix by row after assignment: indices"); 560 OSIUNITTEST_ASSERT_ERROR(ei[ 8] == 5, {}, "cbc", "matrix by row after assignment: indices"); 561 OSIUNITTEST_ASSERT_ERROR(ei[ 9] == 3, {}, "cbc", "matrix by row after assignment: indices"); 562 OSIUNITTEST_ASSERT_ERROR(ei[10] == 6, {}, "cbc", "matrix by row after assignment: indices"); 563 OSIUNITTEST_ASSERT_ERROR(ei[11] == 0, {}, "cbc", "matrix by row after assignment: indices"); 564 OSIUNITTEST_ASSERT_ERROR(ei[12] == 4, {}, "cbc", "matrix by row after assignment: indices"); 565 OSIUNITTEST_ASSERT_ERROR(ei[13] == 7, {}, "cbc", "matrix by row after assignment: indices"); 796 566 #else // OSICBC_TEST_MTX_STRUCTURE 797 567 … … 805 575 CoinPackedVector freeRow ; 806 576 exmip1Mtx.appendRow(freeRow) ; 807 assert( exmip1Mtx.isEquivalent(*lhsmbr) ) ; 808 577 OSIUNITTEST_ASSERT_ERROR(exmip1Mtx.isEquivalent(*lhsmbr), {}, "cbc", "matrix by row after assignment"); 809 578 #endif // OSICBC_TEST_MTX_STRUCTURE 810 811 int md = lhsmbr>getMajorDim(); 812 assert( md == 6 ); 813 assert( lhsmbr>getNumElements() == 14 ); 814 } 815 579 } 816 580 } 817 581 … … 830 594 double objValue = m.getObjValue(); 831 595 CoinRelFltEq eq(1.0e2); 832 assert( eq(objValue,2520.57) ); 596 OSIUNITTEST_ASSERT_ERROR(eq(objValue,2520.57), {}, "cbc", "objvalue after adding col"); 597 833 598 // Try deleting first column that's nonbasic at lower bound (0). 834 599 int * d = new int[1]; 835 CoinWarmStartBasis *cwsb = 836 dynamic_cast<CoinWarmStartBasis *>(m.getWarmStart()) ; 837 assert(cwsb) ; 600 CoinWarmStartBasis *cwsb = dynamic_cast<CoinWarmStartBasis *>(m.getWarmStart()) ; 601 OSIUNITTEST_ASSERT_ERROR(cwsb != NULL, {}, "cbc", "get warmstart basis"); 838 602 CoinWarmStartBasis::Status stati ; 839 603 int iCol ; … … 848 612 m.resolve(); 849 613 objValue = m.getObjValue(); 850 assert( eq(objValue,2520.57) ); 614 OSIUNITTEST_ASSERT_ERROR(eq(objValue,2520.57), {}, "clp", "objvalue after deleting first col"); 615 851 616 // Try deleting column we added. If basic, go to initialSolve as deleting 852 617 // basic variable trashes basis required for warm start. … … 861 626 { m.resolve(); } 862 627 objValue = m.getObjValue(); 863 assert( eq(objValue,2520.57) ); 864 865 } 866 // Test matt 867 if (fopen("../Cbc/matt.mps","r")) { 868 OsiCbcSolverInterface m; 869 m.readMps("../Cbc/matt","mps"); 870 m.setHintParam(OsiDoPresolveInResolve, true, OsiHintDo); 871 m.resolve(); 872 873 std::vector<double *> rays = m.getDualRays(1); 874 std::cout << "Dual Ray: " << std::endl; 875 for(int i = 0; i < m.getNumRows(); i++){ 876 if(fabs(rays[0][i]) > 0.00001) 877 std::cout << i << " : " << rays[0][i] << std::endl; 878 } 879 880 std::cout << "isProvenOptimal = " << m.isProvenOptimal() << std::endl; 881 std::cout << "isProvenPrimalInfeasible = " << m.isProvenPrimalInfeasible() 882 << std::endl; 883 884 delete [] rays[0]; 885 628 OSIUNITTEST_ASSERT_ERROR(eq(objValue,2520.57), {}, "clp", "objvalue after deleting added col"); 886 629 } 887 630 … … 997 740 if (numberColumns<50) 998 741 build.setLogLevel(1); 999 int numberErrors=model2.loadFromCoinModel(build);1000 742 // should fail as we never set multiplier 1001 assert (numberErrors);743 OSIUNITTEST_ASSERT_ERROR(model2.loadFromCoinModel(build) != 0, {}, "cbc", "build model with missing multipliers"); 1002 744 build.associateElement("multiplier",0.0); 1003 numberErrors=model2.loadFromCoinModel(build); 1004 assert (!numberErrors); 745 OSIUNITTEST_ASSERT_ERROR(model2.loadFromCoinModel(build) == 0, {}, "cbc", "build model"); 1005 746 model2.initialSolve(); 1006 747 // It then loops with multiplier going from 0.0 to 2.0 in increments of 0.1 1007 748 for (double multiplier=0.0;multiplier<2.0;multiplier+= 0.1) { 1008 749 build.associateElement("multiplier",multiplier); 1009 numberErrors=model2.loadFromCoinModel(build,true); 1010 assert (!numberErrors); 750 OSIUNITTEST_ASSERT_ERROR(model2.loadFromCoinModel(build,true) == 0, {}, "cbc", "build model with increasing multiplier"); 1011 751 model2.resolve(); 1012 752 } 1013 753 } 754 1014 755 // branch and bound 1015 756 { … … 1022 763 m.branchAndBound(); 1023 764 } 765 1024 766 // branch and bound using CbcModel!!!!!!! 1025 767 { … … 1031 773 m.branchAndBound(); 1032 774 } 1033 #ifdef COIN_HAS_OSL 1034 // branch and bound using OSL 1035 { 1036 OsiOslSolverInterface mmm; 1037 OsiCbcSolverInterface mm(&mmm); 1038 CbcStrategyNull strategy; 1039 OsiCbcSolverInterface m(&mm,&strategy); 1040 std::string fn = mpsDir+"p0033"; 1041 m.readMps(fn.c_str(),"mps"); 1042 //m.initialSolve(); 1043 m.branchAndBound(); 1044 } 1045 #endif 1046 int errCnt = 0; 775 1047 776 // Do common solverInterface testing 1048 777 { 1049 778 OsiCbcSolverInterface m; 1050 errCnt +=OsiSolverInterfaceCommonUnitTest(&m, mpsDir,netlibDir);779 OsiSolverInterfaceCommonUnitTest(&m, mpsDir,netlibDir); 1051 780 } 1052 781 { 1053 782 OsiCbcSolverInterface mm; 1054 783 OsiCbcSolverInterface m(&mm); 1055 errCnt +=OsiSolverInterfaceCommonUnitTest(&m, mpsDir,netlibDir);784 OsiSolverInterfaceCommonUnitTest(&m, mpsDir,netlibDir); 1056 785 } 1057 #ifdef COIN_HAS_OSL 1058 { 1059 OsiOslSolverInterface mm; 1060 OsiCbcSolverInterface m(&mm); 1061 errCnt += OsiSolverInterfaceCommonUnitTest(&m, mpsDir,netlibDir); 1062 } 1063 #endif 1064 return errCnt; 786 787 return 0; 1065 788 } 
trunk/Cbc/test/osiUnitTest.cpp
r1620 r1666 1 // $Id$2 1 // Copyright (C) 2000, International Business Machines 3 2 // Corporation and others. All Rights Reserved. 4 3 // This code is licensed under the terms of the Eclipse Public License (EPL). 4 // $Id$ 5 5 6 6 #include "CoinPragma.hpp" 7 7 8 #include "OsiConfig.h"9 10 #ifdef NDEBUG11 #undef NDEBUG12 #endif13 14 #include <cassert>15 8 #include <cstdio> 16 9 #include <iostream> 17 #include <map>18 10 19 11 #include "OsiUnitTests.hpp" 20 12 #include "OsiRowCutDebugger.hpp" 13 #include "OsiRowCut.hpp" 14 #include "OsiColCut.hpp" 21 15 22 16 #include "CoinError.hpp" … … 24 18 #include "OsiCbcSolverInterface.hpp" 25 19 26 namespace { 27 28 // Display message on stdout and stderr. Flush cout buffer before printing the 29 // message, so that output comes out in order in spite of buffered cout. 30 31 void testingMessage( const char * const msg ) 32 { 33 std::cout.flush() ; 34 std::cerr <<msg; 35 //cout <<endl <<"*****************************************" 36 // <<endl <<msg <<endl; 37 } 38 39 40 /* 41 Utility routine to process command line parameters. An unrecognised parameter 42 will trigger the help message and a return value of false. 43 44 This should be replaced with the one of the standard CoinUtils parameter 45 mechanisms. 46 */ 47 bool processParameters (int argc, const char **argv, 48 std::map<std::string,std::string> &parms) 49 50 { 51 assert(argc >= 1); 52 assert(argv != NULL); 53 /* 54 Initialise the parameter keywords. 55 */ 56 std::set<std::string> definedKeyWords; 57 definedKeyWords.insert("cerr2cout"); 58 definedKeyWords.insert("mpsDir"); 59 definedKeyWords.insert("netlibDir"); 60 definedKeyWords.insert("testOsiSolverInterface"); 61 definedKeyWords.insert("nobuf"); 62 /* 63 Set default values for data directories. 64 */ 65 std::string dirsep(1,CoinFindDirSeparator()) ; 66 std::string upOne = ".."+dirsep ; 67 std::string pathTmp ; 68 /* 69 Establish likely defaults for the Sample and Miplib directories. 70 */ 71 # ifdef SAMPLEDIR 72 pathTmp = SAMPLEDIR ; 73 # else 74 pathTmp = upOne+upOne+"Data"+dirsep+"Sample" ; 75 # endif 76 parms["mpsDir"] = pathTmp ; 77 # ifdef NETLIBDIR 78 pathTmp = NETLIBDIR ; 79 # else 80 pathTmp = upOne+upOne+"Data"+dirsep+"Netlib" ; 81 # endif 82 parms["netlibDir"] = pathTmp ; 83 /* 84 Read the command line parameters and fill a map of parameter keys and 85 associated data. The parser allows for parameters which are only a keyword, 86 or parameters of the form keyword=value (no spaces). 87 */ 88 for (int i = 1 ; i < argc ; i++) 89 { std::string parm(argv[i]) ; 90 std::string key,value ; 91 std::string::size_type eqPos = parm.find('='); 92 93 if (eqPos == std::string::npos) 94 { key = parm ; } 95 else 96 { key = parm.substr(0,eqPos) ; 97 value = parm.substr(eqPos+1) ; } 98 /* 99 Is the specifed key valid? 100 */ 101 if (definedKeyWords.find(key) == definedKeyWords.end()) 102 { std::cerr << "Undefined parameter \"" << key << "\"." << std::endl ; 103 std::cerr 104 << "Usage: " << argv[0] 105 << " [nobuf] [mpsDir=V1] [netlibDir=V2] " 106 << "[testOsiSolverInterface] " << std::endl ; 107 std::cerr << " where:" << std::endl ; 108 std::cerr 109 << " " 110 << "cerr2cout: redirect cerr to cout; sometimes useful." << std::endl 111 << "\t" << "to synchronise cout & cerr." << std::endl ; 112 std::cerr 113 << " " 114 << "mpsDir: directory containing mps test files." << std::endl 115 << "\t" << "Default value V1=\"../../Data/Sample\"" << std::endl ; 116 std::cerr 117 << " " 118 << "netlibDir: directory containing netlib files." << std::endl 119 << "\t" << "Default value V2=\"../../Data/Netlib\"" << std::endl ; 120 std::cerr 121 << " " 122 << "testOsiSolverInterface: " 123 << "run each OSI on the netlib problem set." << std::endl 124 << "\t" 125 << "Default is to not run the netlib problem set." << std::endl ; 126 std::cerr 127 << " " 128 << "nobuf: use unbuffered output." << std::endl 129 << "\t" << "Default is buffered output." << std::endl ; 130 131 return (false) ; } 132 /* 133 Valid keyword; stash the value for later reference. 134 */ 135 parms[key]=value ; } 136 /* 137 Tack the directory separator onto the data directories so we don't have to 138 worry about it later. 139 */ 140 parms["mpsDir"] += dirsep ; 141 parms["netlibDir"] += dirsep ; 142 /* 143 Did the user request unbuffered i/o? It seems we need to go after this 144 through stdio  using pubsetbuf(0,0) on the C++ streams has no 145 discernible affect. Nor, for that matter, did setting the unitbuf flag on 146 the streams. Why? At a guess, sync_with_stdio connects the streams to the 147 stdio buffers, and the C++ side isn't programmed to change them? 148 */ 149 if (parms.find("nobuf") != parms.end()) 150 { // std::streambuf *coutBuf, *cerrBuf ; 151 // coutBuf = std::cout.rdbuf() ; 152 // coutBuf>pubsetbuf(0,0) ; 153 // cerrBuf = std::cerr.rdbuf() ; 154 // cerrBuf>pubsetbuf(0,0) ; 155 setbuf(stderr,0) ; 156 setbuf(stdout,0) ; } 157 /* 158 Did the user request a redirect for cerr? This must occur before any i/o is 159 performed. 160 */ 161 if (parms.find("cerr2cout") != parms.end()) 162 { std::cerr.rdbuf(std::cout.rdbuf()) ; } 163 164 return (true) ; } 165 166 167 } // end filelocal namespace 168 169 20 using namespace OsiUnitTest; 170 21 171 22 // 172 // unitTest [nobuf] [mpsDir=V1] [netlibDir=V2] [testOsiSolverInterface] 173 // 174 // where: 175 // nobuf: remove buffering on cout (stdout); useful to keep cout and cerr 176 // messages synchronised when redirecting output to a file or pipe. 177 // mpsDir: directory containing mps test files 178 // Default value V1="../../Data/Sample" 179 // netlibDir: directory containing netlib files 180 // Default value V2="../../Data/Netlib" 181 // testOsiSolverInterface 182 // If specified, then OsiSolveInterface::unitTest 183 // is skipped over and not run. 184 // 185 // All parameters are optional. 23 // to see parameter list, call unitTest usage 186 24 // 187 25 188 26 int main (int argc, const char *argv[]) 189 190 { int totalErrCnt = 0; 191 27 { 192 28 /* 193 29 Start off with various bits of initialisation that don't really belong 194 30 anywhere else. 195 196 First off, synchronise C++ stream i/o with C stdio. This makes debugging 31 */ 32 outcomes.clear(); 33 /* 34 Synchronise C++ stream i/o with C stdio. This makes debugging 197 35 output a bit more comprehensible. It still suffers from interleave of cout 198 36 (stdout) and cerr (stderr), but nobuf deals with that. 199 */37 */ 200 38 std::ios::sync_with_stdio() ; 201 39 /* 202 40 Suppress an popup window that Windows shows in response to a crash. See 203 41 note at head of file. 204 */42 */ 205 43 WindowsErrorPopupBlocker(); 44 206 45 /* 207 46 Process command line parameters. 208 */ 209 std::map<std::string,std::string> parms ; 210 47 */ 48 std::map<std::string,std::string> parms; 211 49 if (processParameters(argc,argv,parms) == false) 212 { return (1) ; }50 return 1; 213 51 214 52 std::string mpsDir = parms["mpsDir"] ; 215 53 std::string netlibDir = parms["netlibDir"] ; 216 54 217 try { 218 /* 219 Test Osi{Row,Col}Cut routines. 220 */ 55 /* 56 Test Osi{Row,Col}Cut routines. 57 */ 221 58 { 222 59 OsiCbcSolverInterface cbcSi; 223 60 testingMessage( "Testing OsiRowCut with OsiCbcSolverInterface\n" ); 224 O siRowCutUnitTest(&cbcSi,mpsDir);61 OSIUNITTEST_CATCH_ERROR(OsiRowCutUnitTest(&cbcSi,mpsDir), {}, cbcSi, "rowcut unittest"); 225 62 } 226 63 { 227 64 OsiCbcSolverInterface cbcSi; 228 65 testingMessage( "Testing OsiColCut with OsiCbcSolverInterface\n" ); 229 O siColCutUnitTest(&cbcSi,mpsDir);66 OSIUNITTEST_CATCH_ERROR(OsiColCutUnitTest(&cbcSi,mpsDir), {}, cbcSi, "colcut unittest"); 230 67 } 231 68 { 232 69 OsiCbcSolverInterface cbcSi; 233 70 testingMessage( "Testing OsiRowCutDebugger with OsiCbcSolverInterface\n" ); 234 O siRowCutDebuggerUnitTest(&cbcSi,mpsDir);71 OSIUNITTEST_CATCH_ERROR(OsiRowCutDebuggerUnitTest(&cbcSi,mpsDir), {}, cbcSi, "rowcut debugger unittest"); 235 72 } 236 73 237 /* 238 Run the OsiXXX class test. It's up to the OsiCbc implementor 239 to decide whether or not to run OsiSolverInterfaceCommonUnitTest. Arguably 240 this should be required. 241 */ 74 /* 75 Run the OsiCbc class test. This will also call OsiSolverInterfaceCommonUnitTest. 76 */ 242 77 testingMessage( "Testing OsiCbcSolverInterface\n" ); 243 O siCbcSolverInterfaceUnitTest(mpsDir,netlibDir);78 OSIUNITTEST_CATCH_ERROR(OsiCbcSolverInterfaceUnitTest(mpsDir,netlibDir), {}, "cbc", "osicbc unittest"); 244 79 245 /*246 We have run the specialised unit test. Check now to see if we need to247 run through the Netlib problems.248 */80 /* 81 We have run the specialised unit test. 82 Check now to see if we need to run through the Netlib problems. 83 */ 249 84 if (parms.find("testOsiSolverInterface") != parms.end()) 250 85 { … … 253 88 254 89 testingMessage( "Testing OsiSolverInterface on Netlib problems.\n" ); 255 O siSolverInterfaceMpsUnitTest(vecSi,netlibDir);90 OSIUNITTEST_CATCH_ERROR(OsiSolverInterfaceMpsUnitTest(vecSi,netlibDir), {}, "cbc", "netlib unittest"); 256 91 257 92 delete vecSi[0]; 258 93 } 259 else { 260 testingMessage( "***Skipped Testing of OsiCbcSolverInterface on Netlib problems***\n" ); 261 testingMessage( "***use testOsiSolverInterface to run them.***\n" ); 262 } 263 } catch (CoinError& error) { 94 else 95 testingMessage( "***Skipped Testing of OsiCbcSolverInterface on Netlib problems, use testOsiSolverInterface to run them.***\n" ); 96 97 /* 98 We're done. Report on the results. 99 */ 264 100 std::cout.flush(); 265 std::cerr << "Caught CoinError exception: "; 266 error.print(true); 267 totalErrCnt += 1; 101 outcomes.print(); 102 103 int nerrors; 104 int nerrors_expected; 105 outcomes.getCountBySeverity(TestOutcome::ERROR, nerrors, nerrors_expected); 106 107 if (nerrors > nerrors_expected) 108 std::cerr << "Tests completed with " << nerrors  nerrors_expected << " unexpected errors." << std::endl ; 109 else 110 std::cerr << "All tests completed successfully\n"; 111 112 return nerrors  nerrors_expected; 268 113 } 269 /*270 We're done. Report on the results.271 */272 if (totalErrCnt)273 { std::cout.flush() ;274 std::cerr275 << "Tests completed with " << totalErrCnt << " errors." << std::endl ;276 } else277 { testingMessage("All tests completed successfully\n") ; }278 return totalErrCnt;279 }
Note: See TracChangeset
for help on using the changeset viewer.