Debian Codegraph @

Osi/test/OsiCpxSolverInterfaceTest.cpp

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