| 1 | /* |
| 2 | Unit test for OsiMsk. |
| 3 | |
| 4 | This file is licensed under the terms of Eclipse Public License (EPL). |
| 5 | */ |
| 6 | |
| 7 | #include "CoinPragma.hpp" |
| 8 | #include "OsiConfig.h" |
| 9 | |
| 10 | //#include <cassert> |
| 11 | //#include <iostream> |
| 12 | |
| 13 | #include "OsiUnitTests.hpp" |
| 14 | #include "OsiMskSolverInterface.hpp" |
| 15 | #include "OsiCuts.hpp" |
| 16 | #include "OsiRowCut.hpp" |
| 17 | #include "OsiColCut.hpp" |
| 18 | #include "CoinPackedMatrix.hpp" |
| 19 | |
| 20 | // Added so build windows build with dsp files works, |
| 21 | // when not building with gurobi. |
| 22 | #ifdef COIN_HAS_MSK |
| 23 | #include "mosek.h" |
| 24 | |
| 25 | //-------------------------------------------------------------------------- |
| 26 | void OsiMskSolverInterfaceUnitTest( const std::string & mpsDir, const std::string & netlibDir ) |
| 27 | { |
| 28 | unsigned int numInstancesStart = OsiMskSolverInterface::getNumInstances(); |
| 29 | // Test default constructor |
| 30 | { |
| 31 | OsiMskSolverInterface m; |
| 32 | OSIUNITTEST_ASSERT_ERROR(m.obj_ == NULL, {}, "mosek", "default constructor"); |
| 33 | OSIUNITTEST_ASSERT_ERROR(m.collower_ == NULL, {}, "mosek", "default constructor"); |
| 34 | OSIUNITTEST_ASSERT_ERROR(m.colupper_ == NULL, {}, "mosek", "default constructor"); |
| 35 | OSIUNITTEST_ASSERT_ERROR(m.coltype_ == NULL, {}, "mosek", "default constructor"); |
| 36 | OSIUNITTEST_ASSERT_ERROR(m.coltypesize_ == 0, {}, "mosek", "default constructor"); |
| 37 | OSIUNITTEST_ASSERT_ERROR(m.rowsense_ == NULL, {}, "mosek", "default constructor"); |
| 38 | OSIUNITTEST_ASSERT_ERROR(m.rhs_ == NULL, {}, "mosek", "default constructor"); |
| 39 | OSIUNITTEST_ASSERT_ERROR(m.rowrange_ == NULL, {}, "mosek", "default constructor"); |
| 40 | OSIUNITTEST_ASSERT_ERROR(m.rowlower_ == NULL, {}, "mosek", "default constructor"); |
| 41 | OSIUNITTEST_ASSERT_ERROR(m.rowupper_ == NULL, {}, "mosek", "default constructor"); |
| 42 | OSIUNITTEST_ASSERT_ERROR(m.colsol_ == NULL, {}, "mosek", "default constructor"); |
| 43 | OSIUNITTEST_ASSERT_ERROR(m.rowsol_ == NULL, {}, "mosek", "default constructor"); |
| 44 | OSIUNITTEST_ASSERT_ERROR(m.matrixByRow_ == NULL, {}, "mosek", "default constructor"); |
| 45 | OSIUNITTEST_ASSERT_ERROR(m.matrixByCol_ == NULL, {}, "mosek", "default constructor"); |
| 46 | OSIUNITTEST_ASSERT_ERROR(m.getNumCols() == 0, {}, "mosek", "default constructor"); |
| 47 | OSIUNITTEST_ASSERT_ERROR(m.getApplicationData() == NULL, {}, "mosek", "default constructor"); |
| 48 | OSIUNITTEST_ASSERT_ERROR(OsiMskSolverInterface::getNumInstances() == numInstancesStart+1, {}, "mosek", "number of instances during first test"); |
| 49 | int i=2346; |
| 50 | m.setApplicationData(&i); |
| 51 | OSIUNITTEST_ASSERT_ERROR(*((int *)(m.getApplicationData())) == i, {}, "mosek", "default constructor"); |
| 52 | } |
| 53 | OSIUNITTEST_ASSERT_ERROR(OsiMskSolverInterface::getNumInstances() == numInstancesStart, {}, "mosek", "number of instances after first test"); |
| 54 | |
| 55 | { |
| 56 | CoinRelFltEq eq; |
| 57 | OsiMskSolverInterface m; |
| 58 | OSIUNITTEST_ASSERT_ERROR(OsiMskSolverInterface::getNumInstances() == numInstancesStart+1, {}, "mosek", "number of instances"); |
| 59 | std::string fn = mpsDir+"exmip1"; |
| 60 | m.readMps(fn.c_str(),"mps"); |
| 61 | |
| 62 | { |
| 63 | OSIUNITTEST_ASSERT_ERROR(m.getNumCols() == 8, {}, "mosek", "exmip1 read"); |
| 64 | const CoinPackedMatrix * colCopy = m.getMatrixByCol(); |
| 65 | OSIUNITTEST_ASSERT_ERROR(colCopy->getNumCols() == 8, {}, "mosek", "exmip1 matrix"); |
| 66 | OSIUNITTEST_ASSERT_ERROR(colCopy->getMajorDim() == 8, {}, "mosek", "exmip1 matrix"); |
| 67 | OSIUNITTEST_ASSERT_ERROR(colCopy->getNumRows() == 5, {}, "mosek", "exmip1 matrix"); |
| 68 | OSIUNITTEST_ASSERT_ERROR(colCopy->getMinorDim() == 5, {}, "mosek", "exmip1 matrix"); |
| 69 | OSIUNITTEST_ASSERT_ERROR(colCopy->getVectorLengths()[7] == 2, {}, "mosek", "exmip1 matrix"); |
| 70 | CoinPackedMatrix revColCopy; |
| 71 | revColCopy.reverseOrderedCopyOf(*colCopy); |
| 72 | CoinPackedMatrix rev2ColCopy; |
| 73 | rev2ColCopy.reverseOrderedCopyOf(revColCopy); |
| 74 | OSIUNITTEST_ASSERT_ERROR(rev2ColCopy.getNumCols() == 8, {}, "mosek", "twice reverse matrix copy"); |
| 75 | OSIUNITTEST_ASSERT_ERROR(rev2ColCopy.getMajorDim() == 8, {}, "mosek", "twice reverse matrix copy"); |
| 76 | OSIUNITTEST_ASSERT_ERROR(rev2ColCopy.getNumRows() == 5, {}, "mosek", "twice reverse matrix copy"); |
| 77 | OSIUNITTEST_ASSERT_ERROR(rev2ColCopy.getMinorDim() == 5, {}, "mosek", "twice reverse matrix copy"); |
| 78 | OSIUNITTEST_ASSERT_ERROR(rev2ColCopy.getVectorLengths()[7] == 2, {}, "mosek", "twice reverse matrix copy"); |
| 79 | } |
| 80 | |
| 81 | // Test copy constructor and assignment operator |
| 82 | { |
| 83 | OsiMskSolverInterface lhs; |
| 84 | { |
| 85 | OsiMskSolverInterface im(m); |
| 86 | |
| 87 | OsiMskSolverInterface imC1(im); |
| 88 | OSIUNITTEST_ASSERT_ERROR(imC1.getNumCols() == im.getNumCols(), {}, "mosek", "copy constructor"); |
| 89 | OSIUNITTEST_ASSERT_ERROR(imC1.getNumRows() == im.getNumRows(), {}, "mosek", "copy constructor"); |
| 90 | |
| 91 | OsiMskSolverInterface imC2(im); |
| 92 | OSIUNITTEST_ASSERT_ERROR(imC2.getNumCols() == im.getNumCols(), {}, "mosek", "copy constructor"); |
| 93 | OSIUNITTEST_ASSERT_ERROR(imC2.getNumRows() == im.getNumRows(), {}, "mosek", "copy constructor"); |
| 94 | |
| 95 | lhs = imC2; |
| 96 | } |
| 97 | |
| 98 | // Test that lhs has correct values even though rhs has gone out of scope |
| 99 | OSIUNITTEST_ASSERT_ERROR(lhs.getNumCols() == m.getNumCols(), {}, "mosek", "copy constructor"); |
| 100 | OSIUNITTEST_ASSERT_ERROR(lhs.getNumRows() == m.getNumRows(), {}, "mosek", "copy constructor"); |
| 101 | } |
| 102 | |
| 103 | // Test clone |
| 104 | { |
| 105 | OsiMskSolverInterface mosekSi(m); |
| 106 | OsiSolverInterface * siPtr = &mosekSi; |
| 107 | OsiSolverInterface * siClone = siPtr->clone(); |
| 108 | OsiMskSolverInterface * mosekClone = dynamic_cast<OsiMskSolverInterface*>(siClone); |
| 109 | OSIUNITTEST_ASSERT_ERROR(mosekClone != NULL, {}, "mosek", "clone"); |
| 110 | OSIUNITTEST_ASSERT_ERROR(mosekClone->getNumRows() == mosekSi.getNumRows(), {}, "mosek", "clone"); |
| 111 | OSIUNITTEST_ASSERT_ERROR(mosekClone->getNumCols() == m.getNumCols(), {}, "mosek", "clone"); |
| 112 | |
| 113 | delete siClone; |
| 114 | } |
| 115 | |
| 116 | // test infinity |
| 117 | { |
| 118 | OsiMskSolverInterface si; |
| 119 | OSIUNITTEST_ASSERT_ERROR(si.getInfinity() == MSK_INFINITY, {}, "mosek", "value for infinity"); |
| 120 | } |
| 121 | |
| 122 | { |
| 123 | OsiMskSolverInterface mosekSi(m); |
| 124 | int nc = mosekSi.getNumCols(); |
| 125 | int nr = mosekSi.getNumRows(); |
| 126 | const double * cl = mosekSi.getColLower(); |
| 127 | const double * cu = mosekSi.getColUpper(); |
| 128 | const double * rl = mosekSi.getRowLower(); |
| 129 | const double * ru = mosekSi.getRowUpper(); |
| 130 | |
| 131 | OSIUNITTEST_ASSERT_ERROR(nc == 8, return, "mosek", "read and copy exmip1"); |
| 132 | OSIUNITTEST_ASSERT_ERROR(nr == 5, return, "mosek", "read and copy exmip1"); |
| 133 | OSIUNITTEST_ASSERT_ERROR(eq(cl[0],2.5), {}, "mosek", "read and copy exmip1"); |
| 134 | OSIUNITTEST_ASSERT_ERROR(eq(cl[1],0.0), {}, "mosek", "read and copy exmip1"); |
| 135 | OSIUNITTEST_ASSERT_ERROR(eq(cu[1],4.1), {}, "mosek", "read and copy exmip1"); |
| 136 | OSIUNITTEST_ASSERT_ERROR(eq(cu[2],1.0), {}, "mosek", "read and copy exmip1"); |
| 137 | OSIUNITTEST_ASSERT_ERROR(eq(rl[0],2.5), {}, "mosek", "read and copy exmip1"); |
| 138 | OSIUNITTEST_ASSERT_ERROR(eq(rl[4],3.0), {}, "mosek", "read and copy exmip1"); |
| 139 | OSIUNITTEST_ASSERT_ERROR(eq(ru[1],2.1), {}, "mosek", "read and copy exmip1"); |
| 140 | OSIUNITTEST_ASSERT_ERROR(eq(ru[4],15.), {}, "mosek", "read and copy exmip1"); |
| 141 | |
| 142 | double newCs[8] = {1., 2., 3., 4., 5., 6., 7., 8.}; |
| 143 | mosekSi.setColSolution(newCs); |
| 144 | const double * cs = mosekSi.getColSolution(); |
| 145 | OSIUNITTEST_ASSERT_ERROR(eq(cs[0],1.0), {}, "mosek", "set col solution"); |
| 146 | OSIUNITTEST_ASSERT_ERROR(eq(cs[7],8.0), {}, "mosek", "set col solution"); |
| 147 | { |
| 148 | OsiMskSolverInterface solnSi(mosekSi); |
| 149 | const double * cs = solnSi.getColSolution(); |
| 150 | OSIUNITTEST_ASSERT_ERROR(eq(cs[0],1.0), {}, "mosek", "set col solution and copy"); |
| 151 | OSIUNITTEST_ASSERT_ERROR(eq(cs[7],8.0), {}, "mosek", "set col solution and copy"); |
| 152 | } |
| 153 | |
| 154 | OSIUNITTEST_ASSERT_ERROR(!eq(cl[3],1.2345), {}, "mosek", "set col lower"); |
| 155 | mosekSi.setColLower( 3, 1.2345 ); |
| 156 | OSIUNITTEST_ASSERT_ERROR( eq(cl[3],1.2345), {}, "mosek", "set col lower"); |
| 157 | |
| 158 | OSIUNITTEST_ASSERT_ERROR(!eq(cu[4],10.2345), {}, "mosek", "set col upper"); |
| 159 | mosekSi.setColUpper( 4, 10.2345 ); |
| 160 | OSIUNITTEST_ASSERT_ERROR( eq(cu[4],10.2345), {}, "mosek", "set col upper"); |
| 161 | |
| 162 | OSIUNITTEST_ASSERT_ERROR(eq(mosekSi.getObjCoefficients()[0], 1.0), {}, "mosek", "read and copy exmip1"); |
| 163 | OSIUNITTEST_ASSERT_ERROR(eq(mosekSi.getObjCoefficients()[1], 0.0), {}, "mosek", "read and copy exmip1"); |
| 164 | OSIUNITTEST_ASSERT_ERROR(eq(mosekSi.getObjCoefficients()[2], 0.0), {}, "mosek", "read and copy exmip1"); |
| 165 | OSIUNITTEST_ASSERT_ERROR(eq(mosekSi.getObjCoefficients()[3], 0.0), {}, "mosek", "read and copy exmip1"); |
| 166 | OSIUNITTEST_ASSERT_ERROR(eq(mosekSi.getObjCoefficients()[4], 2.0), {}, "mosek", "read and copy exmip1"); |
| 167 | OSIUNITTEST_ASSERT_ERROR(eq(mosekSi.getObjCoefficients()[5], 0.0), {}, "mosek", "read and copy exmip1"); |
| 168 | OSIUNITTEST_ASSERT_ERROR(eq(mosekSi.getObjCoefficients()[6], 0.0), {}, "mosek", "read and copy exmip1"); |
| 169 | OSIUNITTEST_ASSERT_ERROR(eq(mosekSi.getObjCoefficients()[7],-1.0), {}, "mosek", "read and copy exmip1"); |
| 170 | } |
| 171 | |
| 172 | // Test getMatrixByRow method |
| 173 | { |
| 174 | const OsiMskSolverInterface si(m); |
| 175 | const CoinPackedMatrix * smP = si.getMatrixByRow(); |
| 176 | |
| 177 | OSIUNITTEST_ASSERT_ERROR(smP->getMajorDim() == 5, return, "mosek", "getMatrixByRow: major dim"); |
| 178 | OSIUNITTEST_ASSERT_ERROR(smP->getNumElements() == 14, return, "mosek", "getMatrixByRow: num elements"); |
| 179 | |
| 180 | CoinRelFltEq eq; |
| 181 | const double * ev = smP->getElements(); |
| 182 | OSIUNITTEST_ASSERT_ERROR(eq(ev[0], 3.0), {}, "mosek", "getMatrixByRow: elements"); |
| 183 | OSIUNITTEST_ASSERT_ERROR(eq(ev[1], 1.0), {}, "mosek", "getMatrixByRow: elements"); |
| 184 | OSIUNITTEST_ASSERT_ERROR(eq(ev[2], -2.0), {}, "mosek", "getMatrixByRow: elements"); |
| 185 | OSIUNITTEST_ASSERT_ERROR(eq(ev[3], -1.0), {}, "mosek", "getMatrixByRow: elements"); |
| 186 | OSIUNITTEST_ASSERT_ERROR(eq(ev[4], -1.0), {}, "mosek", "getMatrixByRow: elements"); |
| 187 | OSIUNITTEST_ASSERT_ERROR(eq(ev[5], 2.0), {}, "mosek", "getMatrixByRow: elements"); |
| 188 | OSIUNITTEST_ASSERT_ERROR(eq(ev[6], 1.1), {}, "mosek", "getMatrixByRow: elements"); |
| 189 | OSIUNITTEST_ASSERT_ERROR(eq(ev[7], 1.0), {}, "mosek", "getMatrixByRow: elements"); |
| 190 | OSIUNITTEST_ASSERT_ERROR(eq(ev[8], 1.0), {}, "mosek", "getMatrixByRow: elements"); |
| 191 | OSIUNITTEST_ASSERT_ERROR(eq(ev[9], 2.8), {}, "mosek", "getMatrixByRow: elements"); |
| 192 | OSIUNITTEST_ASSERT_ERROR(eq(ev[10], -1.2), {}, "mosek", "getMatrixByRow: elements"); |
| 193 | OSIUNITTEST_ASSERT_ERROR(eq(ev[11], 5.6), {}, "mosek", "getMatrixByRow: elements"); |
| 194 | OSIUNITTEST_ASSERT_ERROR(eq(ev[12], 1.0), {}, "mosek", "getMatrixByRow: elements"); |
| 195 | OSIUNITTEST_ASSERT_ERROR(eq(ev[13], 1.9), {}, "mosek", "getMatrixByRow: elements"); |
| 196 | |
| 197 | const int * mi = smP->getVectorStarts(); |
| 198 | OSIUNITTEST_ASSERT_ERROR(mi[0] == 0, {}, "mosek", "getMatrixByRow: vector starts"); |
| 199 | OSIUNITTEST_ASSERT_ERROR(mi[1] == 5, {}, "mosek", "getMatrixByRow: vector starts"); |
| 200 | OSIUNITTEST_ASSERT_ERROR(mi[2] == 7, {}, "mosek", "getMatrixByRow: vector starts"); |
| 201 | OSIUNITTEST_ASSERT_ERROR(mi[3] == 9, {}, "mosek", "getMatrixByRow: vector starts"); |
| 202 | OSIUNITTEST_ASSERT_ERROR(mi[4] == 11, {}, "mosek", "getMatrixByRow: vector starts"); |
| 203 | OSIUNITTEST_ASSERT_ERROR(mi[5] == 14, {}, "mosek", "getMatrixByRow: vector starts"); |
| 204 | |
| 205 | const int * ei = smP->getIndices(); |
| 206 | OSIUNITTEST_ASSERT_ERROR(ei[ 0] == 0, {}, "mosek", "getMatrixByRow: indices"); |
| 207 | OSIUNITTEST_ASSERT_ERROR(ei[ 1] == 1, {}, "mosek", "getMatrixByRow: indices"); |
| 208 | OSIUNITTEST_ASSERT_ERROR(ei[ 2] == 3, {}, "mosek", "getMatrixByRow: indices"); |
| 209 | OSIUNITTEST_ASSERT_ERROR(ei[ 3] == 4, {}, "mosek", "getMatrixByRow: indices"); |
| 210 | OSIUNITTEST_ASSERT_ERROR(ei[ 4] == 7, {}, "mosek", "getMatrixByRow: indices"); |
| 211 | OSIUNITTEST_ASSERT_ERROR(ei[ 5] == 1, {}, "mosek", "getMatrixByRow: indices"); |
| 212 | OSIUNITTEST_ASSERT_ERROR(ei[ 6] == 2, {}, "mosek", "getMatrixByRow: indices"); |
| 213 | OSIUNITTEST_ASSERT_ERROR(ei[ 7] == 2, {}, "mosek", "getMatrixByRow: indices"); |
| 214 | OSIUNITTEST_ASSERT_ERROR(ei[ 8] == 5, {}, "mosek", "getMatrixByRow: indices"); |
| 215 | OSIUNITTEST_ASSERT_ERROR(ei[ 9] == 3, {}, "mosek", "getMatrixByRow: indices"); |
| 216 | OSIUNITTEST_ASSERT_ERROR(ei[10] == 6, {}, "mosek", "getMatrixByRow: indices"); |
| 217 | OSIUNITTEST_ASSERT_ERROR(ei[11] == 0, {}, "mosek", "getMatrixByRow: indices"); |
| 218 | OSIUNITTEST_ASSERT_ERROR(ei[12] == 4, {}, "mosek", "getMatrixByRow: indices"); |
| 219 | OSIUNITTEST_ASSERT_ERROR(ei[13] == 7, {}, "mosek", "getMatrixByRow: indices"); |
| 220 | } |
| 221 | //-------------- |
| 222 | // Test rowsense, rhs, rowrange, getMatrixByRow |
| 223 | { |
| 224 | OsiMskSolverInterface lhs; |
| 225 | { |
| 226 | OsiMskSolverInterface siC1(m); |
| 227 | OSIUNITTEST_ASSERT_WARNING(siC1.obj_ == NULL, {}, "mosek", "objective"); |
| 228 | OSIUNITTEST_ASSERT_WARNING(siC1.collower_ == NULL, {}, "mosek", "col lower"); |
| 229 | OSIUNITTEST_ASSERT_WARNING(siC1.colupper_ == NULL, {}, "mosek", "col upper"); |
| 230 | OSIUNITTEST_ASSERT_WARNING(siC1.rowrange_ == NULL, {}, "mosek", "row range"); |
| 231 | OSIUNITTEST_ASSERT_WARNING(siC1.rowsense_ == NULL, {}, "mosek", "row sense"); |
| 232 | OSIUNITTEST_ASSERT_WARNING(siC1.rowlower_ == NULL, {}, "mosek", "row lower"); |
| 233 | OSIUNITTEST_ASSERT_WARNING(siC1.rowupper_ == NULL, {}, "mosek", "row upper"); |
| 234 | OSIUNITTEST_ASSERT_WARNING(siC1.rhs_ == NULL, {}, "mosek", "right hand side"); |
| 235 | OSIUNITTEST_ASSERT_WARNING(siC1.matrixByRow_ == NULL, {}, "mosek", "matrix by row"); |
| 236 | OSIUNITTEST_ASSERT_WARNING(siC1.colsol_ == NULL, {}, "mosek", "col solution"); |
| 237 | OSIUNITTEST_ASSERT_WARNING(siC1.rowsol_ == NULL, {}, "mosek", "row solution"); |
| 238 | |
| 239 | const char * siC1rs = siC1.getRowSense(); |
| 240 | OSIUNITTEST_ASSERT_ERROR(siC1rs[0] == 'G', {}, "mosek", "row sense"); |
| 241 | OSIUNITTEST_ASSERT_ERROR(siC1rs[1] == 'L', {}, "mosek", "row sense"); |
| 242 | OSIUNITTEST_ASSERT_ERROR(siC1rs[2] == 'E', {}, "mosek", "row sense"); |
| 243 | OSIUNITTEST_ASSERT_ERROR(siC1rs[3] == 'R', {}, "mosek", "row sense"); |
| 244 | OSIUNITTEST_ASSERT_ERROR(siC1rs[4] == 'R', {}, "mosek", "row sense"); |
| 245 | |
| 246 | const double * siC1rhs = siC1.getRightHandSide(); |
| 247 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[0],2.5), {}, "mosek", "right hand side"); |
| 248 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[1],2.1), {}, "mosek", "right hand side"); |
| 249 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[2],4.0), {}, "mosek", "right hand side"); |
| 250 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[3],5.0), {}, "mosek", "right hand side"); |
| 251 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[4],15.), {}, "mosek", "right hand side"); |
| 252 | |
| 253 | const double * siC1rr = siC1.getRowRange(); |
| 254 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[0],0.0), {}, "mosek", "row range"); |
| 255 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[1],0.0), {}, "mosek", "row range"); |
| 256 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[2],0.0), {}, "mosek", "row range"); |
| 257 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[3],5.0-1.8), {}, "mosek", "row range"); |
| 258 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[4],15.0-3.0), {}, "mosek", "row range"); |
| 259 | |
| 260 | const CoinPackedMatrix * siC1mbr = siC1.getMatrixByRow(); |
| 261 | OSIUNITTEST_ASSERT_ERROR(siC1mbr != NULL, {}, "mosek", "matrix by row"); |
| 262 | OSIUNITTEST_ASSERT_ERROR(siC1mbr->getMajorDim() == 5, return, "mosek", "matrix by row: major dim"); |
| 263 | OSIUNITTEST_ASSERT_ERROR(siC1mbr->getNumElements() == 14, return, "mosek", "matrix by row: num elements"); |
| 264 | |
| 265 | const double * ev = siC1mbr->getElements(); |
| 266 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 0], 3.0), {}, "mosek", "matrix by row: elements"); |
| 267 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 1], 1.0), {}, "mosek", "matrix by row: elements"); |
| 268 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 2],-2.0), {}, "mosek", "matrix by row: elements"); |
| 269 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 3],-1.0), {}, "mosek", "matrix by row: elements"); |
| 270 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 4],-1.0), {}, "mosek", "matrix by row: elements"); |
| 271 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 5], 2.0), {}, "mosek", "matrix by row: elements"); |
| 272 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 6], 1.1), {}, "mosek", "matrix by row: elements"); |
| 273 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 7], 1.0), {}, "mosek", "matrix by row: elements"); |
| 274 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 8], 1.0), {}, "mosek", "matrix by row: elements"); |
| 275 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 9], 2.8), {}, "mosek", "matrix by row: elements"); |
| 276 | OSIUNITTEST_ASSERT_ERROR(eq(ev[10],-1.2), {}, "mosek", "matrix by row: elements"); |
| 277 | OSIUNITTEST_ASSERT_ERROR(eq(ev[11], 5.6), {}, "mosek", "matrix by row: elements"); |
| 278 | OSIUNITTEST_ASSERT_ERROR(eq(ev[12], 1.0), {}, "mosek", "matrix by row: elements"); |
| 279 | OSIUNITTEST_ASSERT_ERROR(eq(ev[13], 1.9), {}, "mosek", "matrix by row: elements"); |
| 280 | |
| 281 | const CoinBigIndex * mi = siC1mbr->getVectorStarts(); |
| 282 | OSIUNITTEST_ASSERT_ERROR(mi[0] == 0, {}, "mosek", "matrix by row: vector starts"); |
| 283 | OSIUNITTEST_ASSERT_ERROR(mi[1] == 5, {}, "mosek", "matrix by row: vector starts"); |
| 284 | OSIUNITTEST_ASSERT_ERROR(mi[2] == 7, {}, "mosek", "matrix by row: vector starts"); |
| 285 | OSIUNITTEST_ASSERT_ERROR(mi[3] == 9, {}, "mosek", "matrix by row: vector starts"); |
| 286 | OSIUNITTEST_ASSERT_ERROR(mi[4] == 11, {}, "mosek", "matrix by row: vector starts"); |
| 287 | OSIUNITTEST_ASSERT_ERROR(mi[5] == 14, {}, "mosek", "matrix by row: vector starts"); |
| 288 | |
| 289 | const int * ei = siC1mbr->getIndices(); |
| 290 | OSIUNITTEST_ASSERT_ERROR(ei[ 0] == 0, {}, "mosek", "matrix by row: indices"); |
| 291 | OSIUNITTEST_ASSERT_ERROR(ei[ 1] == 1, {}, "mosek", "matrix by row: indices"); |
| 292 | OSIUNITTEST_ASSERT_ERROR(ei[ 2] == 3, {}, "mosek", "matrix by row: indices"); |
| 293 | OSIUNITTEST_ASSERT_ERROR(ei[ 3] == 4, {}, "mosek", "matrix by row: indices"); |
| 294 | OSIUNITTEST_ASSERT_ERROR(ei[ 4] == 7, {}, "mosek", "matrix by row: indices"); |
| 295 | OSIUNITTEST_ASSERT_ERROR(ei[ 5] == 1, {}, "mosek", "matrix by row: indices"); |
| 296 | OSIUNITTEST_ASSERT_ERROR(ei[ 6] == 2, {}, "mosek", "matrix by row: indices"); |
| 297 | OSIUNITTEST_ASSERT_ERROR(ei[ 7] == 2, {}, "mosek", "matrix by row: indices"); |
| 298 | OSIUNITTEST_ASSERT_ERROR(ei[ 8] == 5, {}, "mosek", "matrix by row: indices"); |
| 299 | OSIUNITTEST_ASSERT_ERROR(ei[ 9] == 3, {}, "mosek", "matrix by row: indices"); |
| 300 | OSIUNITTEST_ASSERT_ERROR(ei[10] == 6, {}, "mosek", "matrix by row: indices"); |
| 301 | OSIUNITTEST_ASSERT_ERROR(ei[11] == 0, {}, "mosek", "matrix by row: indices"); |
| 302 | OSIUNITTEST_ASSERT_ERROR(ei[12] == 4, {}, "mosek", "matrix by row: indices"); |
| 303 | OSIUNITTEST_ASSERT_ERROR(ei[13] == 7, {}, "mosek", "matrix by row: indices"); |
| 304 | |
| 305 | OSIUNITTEST_ASSERT_WARNING(siC1rs == siC1.getRowSense(), {}, "mosek", "row sense"); |
| 306 | OSIUNITTEST_ASSERT_WARNING(siC1rhs == siC1.getRightHandSide(), {}, "mosek", "right hand side"); |
| 307 | OSIUNITTEST_ASSERT_WARNING(siC1rr == siC1.getRowRange(), {}, "mosek", "row range"); |
| 308 | |
| 309 | // Change MOSEK Model by adding free row |
| 310 | OsiRowCut rc; |
| 311 | rc.setLb(-COIN_DBL_MAX); |
| 312 | rc.setUb( COIN_DBL_MAX); |
| 313 | OsiCuts cuts; |
| 314 | cuts.insert(rc); |
| 315 | siC1.applyCuts(cuts); |
| 316 | |
| 317 | // Since model was changed, test that cached data is now freed. |
| 318 | OSIUNITTEST_ASSERT_ERROR(siC1.obj_ == NULL, {}, "mosek", "objective"); |
| 319 | OSIUNITTEST_ASSERT_ERROR(siC1.collower_ == NULL, {}, "mosek", "col lower"); |
| 320 | OSIUNITTEST_ASSERT_ERROR(siC1.colupper_ == NULL, {}, "mosek", "col upper"); |
| 321 | OSIUNITTEST_ASSERT_ERROR(siC1.rowrange_ == NULL, {}, "mosek", "free cached data after adding row"); |
| 322 | OSIUNITTEST_ASSERT_ERROR(siC1.rowsense_ == NULL, {}, "mosek", "free cached data after adding row"); |
| 323 | OSIUNITTEST_ASSERT_ERROR(siC1.rowlower_ == NULL, {}, "mosek", "row lower"); |
| 324 | OSIUNITTEST_ASSERT_ERROR(siC1.rowupper_ == NULL, {}, "mosek", "row upper"); |
| 325 | OSIUNITTEST_ASSERT_ERROR(siC1.rhs_ == NULL, {}, "mosek", "free cached data after adding row"); |
| 326 | OSIUNITTEST_ASSERT_ERROR(siC1.matrixByRow_ == NULL, {}, "mosek", "free cached data after adding row"); |
| 327 | OSIUNITTEST_ASSERT_ERROR(siC1.matrixByCol_ == NULL, {}, "mosek", "free cached data after adding row"); |
| 328 | OSIUNITTEST_ASSERT_ERROR(siC1.colsol_ == NULL, {}, "mosek", "free cached data after adding row"); |
| 329 | OSIUNITTEST_ASSERT_ERROR(siC1.rowsol_ == NULL, {}, "mosek", "free cached data after adding row"); |
| 330 | |
| 331 | siC1rs = siC1.getRowSense(); |
| 332 | OSIUNITTEST_ASSERT_ERROR(siC1rs[0] == 'G', {}, "mosek", "row sense after adding row"); |
| 333 | OSIUNITTEST_ASSERT_ERROR(siC1rs[1] == 'L', {}, "mosek", "row sense after adding row"); |
| 334 | OSIUNITTEST_ASSERT_ERROR(siC1rs[2] == 'E', {}, "mosek", "row sense after adding row"); |
| 335 | OSIUNITTEST_ASSERT_ERROR(siC1rs[3] == 'R', {}, "mosek", "row sense after adding row"); |
| 336 | OSIUNITTEST_ASSERT_ERROR(siC1rs[4] == 'R', {}, "mosek", "row sense after adding row"); |
| 337 | OSIUNITTEST_ASSERT_ERROR(siC1rs[5] == 'N', {}, "mosek", "row sense after adding row"); |
| 338 | |
| 339 | siC1rhs = siC1.getRightHandSide(); |
| 340 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[0],2.5), {}, "mosek", "right hand side after adding row"); |
| 341 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[1],2.1), {}, "mosek", "right hand side after adding row"); |
| 342 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[2],4.0), {}, "mosek", "right hand side after adding row"); |
| 343 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[3],5.0), {}, "mosek", "right hand side after adding row"); |
| 344 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[4],15.), {}, "mosek", "right hand side after adding row"); |
| 345 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rhs[5],0.0), {}, "mosek", "right hand side after adding row"); |
| 346 | |
| 347 | siC1rr = siC1.getRowRange(); |
| 348 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[0],0.0), {}, "mosek", "row range after adding row"); |
| 349 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[1],0.0), {}, "mosek", "row range after adding row"); |
| 350 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[2],0.0), {}, "mosek", "row range after adding row"); |
| 351 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[3],5.0-1.8), {}, "mosek", "row range after adding row"); |
| 352 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[4],15.0-3.0), {}, "mosek", "row range after adding row"); |
| 353 | OSIUNITTEST_ASSERT_ERROR(eq(siC1rr[5],0.0), {}, "mosek", "row range after adding row"); |
| 354 | |
| 355 | lhs = siC1; |
| 356 | } |
| 357 | // Test that lhs has correct values even though siC1 has gone out of scope |
| 358 | OSIUNITTEST_ASSERT_ERROR(lhs.obj_ == NULL, {}, "mosek", "freed origin after assignment"); |
| 359 | OSIUNITTEST_ASSERT_ERROR(lhs.collower_ == NULL, {}, "mosek", "freed origin after assignment"); |
| 360 | OSIUNITTEST_ASSERT_ERROR(lhs.colupper_ == NULL, {}, "mosek", "freed origin after assignment"); |
| 361 | OSIUNITTEST_ASSERT_ERROR(lhs.rowrange_ == NULL, {}, "mosek", "freed origin after assignment"); |
| 362 | OSIUNITTEST_ASSERT_ERROR(lhs.rowsense_ == NULL, {}, "mosek", "freed origin after assignment"); |
| 363 | OSIUNITTEST_ASSERT_ERROR(lhs.rowlower_ == NULL, {}, "mosek", "freed origin after assignment"); |
| 364 | OSIUNITTEST_ASSERT_ERROR(lhs.rowupper_ == NULL, {}, "mosek", "freed origin after assignment"); |
| 365 | OSIUNITTEST_ASSERT_ERROR(lhs.rhs_ == NULL, {}, "mosek", "freed origin after assignment"); |
| 366 | OSIUNITTEST_ASSERT_ERROR(lhs.matrixByRow_ == NULL, {}, "mosek", "freed origin after assignment"); |
| 367 | OSIUNITTEST_ASSERT_ERROR(lhs.matrixByCol_ == NULL, {}, "mosek", "freed origin after assignment"); |
| 368 | OSIUNITTEST_ASSERT_ERROR(lhs.colsol_ == NULL, {}, "mosek", "freed origin after assignment"); |
| 369 | OSIUNITTEST_ASSERT_ERROR(lhs.rowsol_ == NULL, {}, "mosek", "freed origin after assignment"); |
| 370 | |
| 371 | const char * lhsrs = lhs.getRowSense(); |
| 372 | OSIUNITTEST_ASSERT_ERROR(lhsrs[0] == 'G', {}, "mosek", "row sense after assignment"); |
| 373 | OSIUNITTEST_ASSERT_ERROR(lhsrs[1] == 'L', {}, "mosek", "row sense after assignment"); |
| 374 | OSIUNITTEST_ASSERT_ERROR(lhsrs[2] == 'E', {}, "mosek", "row sense after assignment"); |
| 375 | OSIUNITTEST_ASSERT_ERROR(lhsrs[3] == 'R', {}, "mosek", "row sense after assignment"); |
| 376 | OSIUNITTEST_ASSERT_ERROR(lhsrs[4] == 'R', {}, "mosek", "row sense after assignment"); |
| 377 | OSIUNITTEST_ASSERT_ERROR(lhsrs[5] == 'N', {}, "mosek", "row sense after assignment"); |
| 378 | |
| 379 | const double * lhsrhs = lhs.getRightHandSide(); |
| 380 | OSIUNITTEST_ASSERT_ERROR(eq(lhsrhs[0],2.5), {}, "mosek", "right hand side after assignment"); |
| 381 | OSIUNITTEST_ASSERT_ERROR(eq(lhsrhs[1],2.1), {}, "mosek", "right hand side after assignment"); |
| 382 | OSIUNITTEST_ASSERT_ERROR(eq(lhsrhs[2],4.0), {}, "mosek", "right hand side after assignment"); |
| 383 | OSIUNITTEST_ASSERT_ERROR(eq(lhsrhs[3],5.0), {}, "mosek", "right hand side after assignment"); |
| 384 | OSIUNITTEST_ASSERT_ERROR(eq(lhsrhs[4],15.), {}, "mosek", "right hand side after assignment"); |
| 385 | OSIUNITTEST_ASSERT_ERROR(eq(lhsrhs[5],0.0), {}, "mosek", "right hand side after assignment"); |
| 386 | |
| 387 | const double *lhsrr = lhs.getRowRange(); |
| 388 | OSIUNITTEST_ASSERT_ERROR(eq(lhsrr[0],0.0), {}, "mosek", "row range after assignment"); |
| 389 | OSIUNITTEST_ASSERT_ERROR(eq(lhsrr[1],0.0), {}, "mosek", "row range after assignment"); |
| 390 | OSIUNITTEST_ASSERT_ERROR(eq(lhsrr[2],0.0), {}, "mosek", "row range after assignment"); |
| 391 | OSIUNITTEST_ASSERT_ERROR(eq(lhsrr[3],5.0-1.8), {}, "mosek", "row range after assignment"); |
| 392 | OSIUNITTEST_ASSERT_ERROR(eq(lhsrr[4],15.0-3.0), {}, "mosek", "row range after assignment"); |
| 393 | OSIUNITTEST_ASSERT_ERROR(eq(lhsrr[5],0.0), {}, "mosek", "row range after assignment"); |
| 394 | |
| 395 | const CoinPackedMatrix * lhsmbr = lhs.getMatrixByRow(); |
| 396 | OSIUNITTEST_ASSERT_ERROR(lhsmbr != NULL, {}, "mosek", "matrix by row after assignment"); |
| 397 | OSIUNITTEST_ASSERT_ERROR(lhsmbr->getMajorDim() == 6, return, "mosek", "matrix by row after assignment: major dim"); |
| 398 | OSIUNITTEST_ASSERT_ERROR(lhsmbr->getNumElements() == 14, return, "mosek", "matrix by row after assignment: num elements"); |
| 399 | |
| 400 | const double * ev = lhsmbr->getElements(); |
| 401 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 0], 3.0), {}, "mosek", "matrix by row after assignment: elements"); |
| 402 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 1], 1.0), {}, "mosek", "matrix by row after assignment: elements"); |
| 403 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 2],-2.0), {}, "mosek", "matrix by row after assignment: elements"); |
| 404 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 3],-1.0), {}, "mosek", "matrix by row after assignment: elements"); |
| 405 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 4],-1.0), {}, "mosek", "matrix by row after assignment: elements"); |
| 406 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 5], 2.0), {}, "mosek", "matrix by row after assignment: elements"); |
| 407 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 6], 1.1), {}, "mosek", "matrix by row after assignment: elements"); |
| 408 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 7], 1.0), {}, "mosek", "matrix by row after assignment: elements"); |
| 409 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 8], 1.0), {}, "mosek", "matrix by row after assignment: elements"); |
| 410 | OSIUNITTEST_ASSERT_ERROR(eq(ev[ 9], 2.8), {}, "mosek", "matrix by row after assignment: elements"); |
| 411 | OSIUNITTEST_ASSERT_ERROR(eq(ev[10],-1.2), {}, "mosek", "matrix by row after assignment: elements"); |
| 412 | OSIUNITTEST_ASSERT_ERROR(eq(ev[11], 5.6), {}, "mosek", "matrix by row after assignment: elements"); |
| 413 | OSIUNITTEST_ASSERT_ERROR(eq(ev[12], 1.0), {}, "mosek", "matrix by row after assignment: elements"); |
| 414 | OSIUNITTEST_ASSERT_ERROR(eq(ev[13], 1.9), {}, "mosek", "matrix by row after assignment: elements"); |
| 415 | |
| 416 | const CoinBigIndex * mi = lhsmbr->getVectorStarts(); |
| 417 | OSIUNITTEST_ASSERT_ERROR(mi[0] == 0, {}, "mosek", "matrix by row after assignment: vector starts"); |
| 418 | OSIUNITTEST_ASSERT_ERROR(mi[1] == 5, {}, "mosek", "matrix by row after assignment: vector starts"); |
| 419 | OSIUNITTEST_ASSERT_ERROR(mi[2] == 7, {}, "mosek", "matrix by row after assignment: vector starts"); |
| 420 | OSIUNITTEST_ASSERT_ERROR(mi[3] == 9, {}, "mosek", "matrix by row after assignment: vector starts"); |
| 421 | OSIUNITTEST_ASSERT_ERROR(mi[4] == 11, {}, "mosek", "matrix by row after assignment: vector starts"); |
| 422 | OSIUNITTEST_ASSERT_ERROR(mi[5] == 14, {}, "mosek", "matrix by row after assignment: vector starts"); |
| 423 | |
| 424 | const int * ei = lhsmbr->getIndices(); |
| 425 | OSIUNITTEST_ASSERT_ERROR(ei[ 0] == 0, {}, "mosek", "matrix by row after assignment: indices"); |
| 426 | OSIUNITTEST_ASSERT_ERROR(ei[ 1] == 1, {}, "mosek", "matrix by row after assignment: indices"); |
| 427 | OSIUNITTEST_ASSERT_ERROR(ei[ 2] == 3, {}, "mosek", "matrix by row after assignment: indices"); |
| 428 | OSIUNITTEST_ASSERT_ERROR(ei[ 3] == 4, {}, "mosek", "matrix by row after assignment: indices"); |
| 429 | OSIUNITTEST_ASSERT_ERROR(ei[ 4] == 7, {}, "mosek", "matrix by row after assignment: indices"); |
| 430 | OSIUNITTEST_ASSERT_ERROR(ei[ 5] == 1, {}, "mosek", "matrix by row after assignment: indices"); |
| 431 | OSIUNITTEST_ASSERT_ERROR(ei[ 6] == 2, {}, "mosek", "matrix by row after assignment: indices"); |
| 432 | OSIUNITTEST_ASSERT_ERROR(ei[ 7] == 2, {}, "mosek", "matrix by row after assignment: indices"); |
| 433 | OSIUNITTEST_ASSERT_ERROR(ei[ 8] == 5, {}, "mosek", "matrix by row after assignment: indices"); |
| 434 | OSIUNITTEST_ASSERT_ERROR(ei[ 9] == 3, {}, "mosek", "matrix by row after assignment: indices"); |
| 435 | OSIUNITTEST_ASSERT_ERROR(ei[10] == 6, {}, "mosek", "matrix by row after assignment: indices"); |
| 436 | OSIUNITTEST_ASSERT_ERROR(ei[11] == 0, {}, "mosek", "matrix by row after assignment: indices"); |
| 437 | OSIUNITTEST_ASSERT_ERROR(ei[12] == 4, {}, "mosek", "matrix by row after assignment: indices"); |
| 438 | OSIUNITTEST_ASSERT_ERROR(ei[13] == 7, {}, "mosek", "matrix by row after assignment: indices"); |
| 439 | } |
| 440 | OSIUNITTEST_ASSERT_ERROR(OsiMskSolverInterface::getNumInstances() == numInstancesStart+1, {}, "mosek", "number of instances"); |
| 441 | } |
| 442 | OSIUNITTEST_ASSERT_ERROR(OsiMskSolverInterface::getNumInstances() == numInstancesStart, {}, "mosek", "number of instances at finish"); |
| 443 | |
| 444 | // Do common solverInterface testing by calling the |
| 445 | // base class testing method. |
| 446 | { |
| 447 | OsiMskSolverInterface m; |
| 448 | OsiSolverInterfaceCommonUnitTest(&m, mpsDir, netlibDir); |
| 449 | } |
| 450 | } |
| 451 | #endif |