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