Debian Codegraph @

CoinMP/test/unitTest.cpp

raw
1
2 /* unitTest.cpp */
3
4 // $Id: unitTest.cpp 583 2013-11-30 21:48:48Z bjarni $
5
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <assert.h>
10 #include <math.h>
11
12 #include "CoinMP.h"
13
14
15 int SOLVCALL MsgLogCallback(const char* messageStr, void *userParam)
16 {
17 fprintf(stdout, "*** MsgCB: %s\n", messageStr);
18 return 0;
19 }
20
21
22 int SOLVCALL IterCallback(int iterCount,
23 double objectValue,
24 int isFeasible,
25 double infeasValue,
26 void *userParam)
27 {
28 fprintf(stdout, "*** IterCB: iter=%d, obj=%.12g, feas=%d, infeas=%.12g\n",
29 iterCount, objectValue, isFeasible, infeasValue);
30 return 0;
31 }
32
33
34 int SOLVCALL MipNodeCallback(int iterCount,
35 int nodeCount,
36 double bestBound,
37 double bestInteger,
38 int isImproved,
39 void *userParam)
40 {
41 fprintf(stdout, "*** NodeCB: iter=%d, node=%d, bound=%.12g, best=%.12g %s\n",
42 iterCount, nodeCount, bestBound, bestInteger, isImproved ? "*" : "");
43 return 0;
44 }
45
46
47 void GetAndCheckSolution(double optimalValue, HPROB hProb)
48 {
49 int solutionStatus;
50 const char* solutionText;
51 double objectValue;
52 int i;
53 int colCount;
54 double* xValues;
55 const char* ColName;
56 const char* problemName;
57
58 problemName = CoinGetProblemName(hProb);
59 solutionStatus = CoinGetSolutionStatus(hProb);
60 solutionText = CoinGetSolutionText(hProb);
61 objectValue = CoinGetObjectValue(hProb);
62
63 fprintf(stdout, "\n---------------------------------------\n");
64 fprintf(stdout, "Problem Name: %s\n", problemName);
65 fprintf(stdout, "Solution Result: %s\n", solutionText );
66 fprintf(stdout, "Solution Status: %d\n", solutionStatus);
67 fprintf(stdout, "Optimal Value: %.12g\n", objectValue);
68 fprintf(stdout, "---------------------------------------\n");
69
70 colCount = CoinGetColCount(hProb);
71 xValues = (double* )malloc(colCount * sizeof(double));
72 CoinGetSolutionValues(hProb, xValues, NULL, NULL, NULL);
73 for (i = 0; i < colCount; i++) {
74 if (xValues[i] != 0.0) {
75 ColName = CoinGetColName(hProb, i);
76 fprintf(stdout, "%s = %.12g\n", ColName, xValues[i]);
77 }
78 }
79 fprintf(stdout, "---------------------------------------\n\n");
80 assert(solutionStatus==0);
81 assert(strcmp(solutionText,"Optimal solution found")==0);
82 if (optimalValue != 0.0) {
83 assert( fabs(objectValue-optimalValue) < 0.001 );
84 }
85 }
86
87
88
89 void RunTestProblem(const char* problemName, double optimalValue, int colCount, int rowCount,
90 int nonZeroCount, int rangeCount, int objectSense, double objectConst, double* objectCoeffs,
91 double* lowerBounds, double* upperBounds, const char* rowType, double* rhsValues, double* rangeValues,
92 int* matrixBegin, int* matrixCount, int* matrixIndex, double* matrixValues, char** colNames,
93 char** rowNames, const char* objectName, double* initValues, const char* columnType)
94 {
95 HPROB hProb;
96 int result;
97 char filename[260];
98 const char *userParam = "ProblemData";
99
100 fprintf(stdout, "Solve Problem: %s (obj=%.12g)\n", problemName, optimalValue);
101 hProb = CoinCreateProblem(problemName);
102 result = CoinLoadMatrix(hProb, colCount, rowCount, nonZeroCount, rangeCount,
103 objectSense, objectConst, objectCoeffs, lowerBounds, upperBounds,
104 rowType, rhsValues, rangeValues, matrixBegin, matrixCount,
105 matrixIndex, matrixValues);
106 result = CoinLoadNames(hProb, colNames, rowNames, objectName);
107 if (columnType) {
108 result = CoinLoadInteger(hProb, columnType);
109 }
110 result = CoinCheckProblem(hProb);
111 if (result != SOLV_CALL_SUCCESS) {
112 fprintf(stdout, "Check Problem failed (result = %d)\n", result);
113 }
114 result = CoinRegisterMsgLogCallback(hProb, &MsgLogCallback, (void*)userParam);
115 if (columnType == NULL)
116 result = CoinRegisterLPIterCallback(hProb, &IterCallback, (void*)userParam);
117 else {
118 result = CoinRegisterMipNodeCallback(hProb, &MipNodeCallback, (void*)userParam);
119 }
120 result = CoinOptimizeProblem(hProb, 0);
121 strcpy(filename, problemName);
122 strcat(filename, ".mps");
123 result = CoinWriteFile(hProb, SOLV_FILE_MPS, filename);
124 GetAndCheckSolution(optimalValue, hProb);
125 CoinUnloadProblem(hProb);
126 }
127
128
129 void RunTestProblemBuf(const char* problemName, double optimalValue, int colCount, int rowCount,
130 int nonZeroCount, int rangeCount, int objectSense, double objectConst, double* objectCoeffs,
131 double* lowerBounds, double* upperBounds, const char* rowType, double* rhsValues, double* rangeValues,
132 int* matrixBegin, int* matrixCount, int* matrixIndex, double* matrixValues, const char* colNamesBuf,
133 const char* rowNamesBuf, const char* objectName, double* initValues, const char* columnType)
134 {
135 HPROB hProb;
136 int result;
137 char filename[260];
138 const char *userParam = "ProblemData";
139
140 fprintf(stdout, "Solve Problem: %s (obj=%.12g)\n", problemName, optimalValue);
141 hProb = CoinCreateProblem(problemName);
142 result = CoinLoadMatrix(hProb, colCount, rowCount, nonZeroCount, rangeCount,
143 objectSense, objectConst, objectCoeffs, lowerBounds, upperBounds,
144 rowType, rhsValues, rangeValues, matrixBegin, matrixCount,
145 matrixIndex, matrixValues);
146 result = CoinLoadNamesBuf(hProb, colNamesBuf, rowNamesBuf, objectName);
147 if (columnType) {
148 result = CoinLoadInteger(hProb, columnType);
149 }
150 result = CoinCheckProblem(hProb);
151 if (result != SOLV_CALL_SUCCESS) {
152 fprintf(stdout, "Check Problem failed (result = %d)\n", result);
153 }
154 result = CoinRegisterMsgLogCallback(hProb, &MsgLogCallback, (void*)userParam);
155 if (columnType == NULL)
156 result = CoinRegisterLPIterCallback(hProb, &IterCallback, (void*)userParam);
157 else {
158 result = CoinRegisterMipNodeCallback(hProb, &MipNodeCallback, (void*)userParam);
159 }
160 result = CoinOptimizeProblem(hProb, 0);
161 strcpy(filename, problemName);
162 strcat(filename, ".mps");
163 result = CoinWriteFile(hProb, SOLV_FILE_MPS, filename);
164 GetAndCheckSolution(optimalValue, hProb);
165 CoinUnloadProblem(hProb);
166 }
167
168
169 void RunTestProblemMip(const char* problemName, double optimalValue, int colCount, int rowCount,
170 int nonZeroCount, int rangeCount, int objectSense, double objectConst, double* objectCoeffs,
171 double* lowerBounds, double* upperBounds, const char* rowType, double* rhsValues, double* rangeValues,
172 int* matrixBegin, int* matrixCount, int* matrixIndex, double* matrixValues, char** colNames,
173 char** rowNames, const char* objectName, double* initValues, const char* columnType, int sosCount,
174 int sosNZCount, int* sosType, int* sosPrior, int* sosBegin, int* sosIndex, double* sosRef,
175 int semiCount, int* semiIndex, int priorCount, int* priorIndex, int* priorValues, int* priorBranch)
176 {
177 HPROB hProb;
178 int result;
179 char filename[260];
180 const char *userParam = "ProblemData";
181
182 fprintf(stdout, "Solve Problem: %s (obj=%.12g)\n", problemName, optimalValue);
183 hProb = CoinCreateProblem(problemName);
184 result = CoinLoadMatrix(hProb, colCount, rowCount, nonZeroCount, rangeCount,
185 objectSense, objectConst, objectCoeffs, lowerBounds, upperBounds,
186 rowType, rhsValues, rangeValues, matrixBegin, matrixCount,
187 matrixIndex, matrixValues);
188 result = CoinLoadNames(hProb, colNames, rowNames, objectName);
189 if (columnType) {
190 result = CoinLoadInteger(hProb, columnType);
191 }
192 if (priorCount > 0) {
193 result = CoinLoadPriority(hProb, priorCount, priorIndex, priorValues, priorBranch);
194 }
195 if (sosCount > 0) {
196 result = CoinLoadSos(hProb, sosCount, sosNZCount, sosType, sosPrior, sosBegin, sosIndex, sosRef);
197 }
198 if (semiCount > 0) {
199 result = CoinLoadSemiCont(hProb, semiCount, semiIndex);
200 }
201 result = CoinCheckProblem(hProb);
202 if (result != SOLV_CALL_SUCCESS) {
203 fprintf(stdout, "Check Problem failed (result = %d)\n", result);
204 }
205 result = CoinRegisterMsgLogCallback(hProb, &MsgLogCallback, (void*)userParam);
206 if ((columnType == NULL) && (sosCount == 0) && (semiCount == 0))
207 result = CoinRegisterLPIterCallback(hProb, &IterCallback, (void*)userParam);
208 else {
209 result = CoinRegisterMipNodeCallback(hProb, &MipNodeCallback, (void*)userParam);
210 }
211 strcpy(filename, problemName);
212 strcat(filename, ".mps");
213 result = CoinWriteFile(hProb, SOLV_FILE_MPS, filename);
214 result = CoinOptimizeProblem(hProb, 0);
215 GetAndCheckSolution(optimalValue, hProb);
216 CoinUnloadProblem(hProb);
217 }
218
219
220
221 /*************************************************************************
222 * This problem is copied from coinutils\test\CoinPackedMatrixTest
223 *
224 * 3x1 + x2 - 2x4 - x5 - x8
225 * 2x2 + 1.1x3
226 * x3 + x6
227 * 2.8x4 -1.2x7
228 * 5.6x1 + x5 + 1.9x8
229 *
230 *************************************************************************/
231
232 void SolveProblemCoinTest(void)
233 {
234 const char* problemName = "CoinTest";
235 int colCount=8;
236 int rowCount=5;
237 int nonZeroCount=14;
238 int rangeCount = 0;
239
240 const char* objectName = "obj";
241 int objectSense = SOLV_OBJSENS_MAX;
242 double objectConst = 0.0;
243 double objectCoeffs[8] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
244
245 double lowerBounds[8] = { 0., 0., 0., 0., 0., 0., 0. };
246 double upperBounds[8] = { 1000000., 1000000., 1000000., 1000000., 1000000., 1000000., 1000000., 1000000. };
247
248 char rowType[5] = { 'L', 'L', 'L', 'L', 'L' };
249 double rhsValues[5] = { 14., 80., 50., 50., 50. };
250
251 int matrixBegin[8+1]={0,2,4,6,8,10,11,12,14};
252 int matrixCount[8]={2,2,2,2,2,1,1,2};
253 int matrixIndex[14]={0,4,0,1,1,2,0,3,0,4,2,3,0,4};
254 double matrixValues[14]={3., 5.6, 1., 2., 1.1, 1., -2., 2.8, -1., 1., 1., -1.2, -1., 1.9};
255
256 const char* colNames[8] = {"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8"};
257 const char* rowNames[5] = {"r1", "r2", "r3", "r4", "r5"};
258
259 double initValues[8] = { 0., 0., 0., 0., 0., 0., 0., 0. };
260
261 double optimalValue = 1428729.2857143;
262
263 RunTestProblem(problemName, optimalValue, colCount, rowCount,
264 nonZeroCount, rangeCount, objectSense, objectConst, objectCoeffs,
265 lowerBounds, upperBounds, rowType, rhsValues, NULL,
266 matrixBegin, matrixCount, matrixIndex, matrixValues,
267 const_cast<char**>(colNames), const_cast<char**>(rowNames), objectName, initValues, NULL);
268 }
269
270
271 void SolveProblemBakery(void)
272 {
273 const char* problemName = "Bakery";
274 int colCount = 2;
275 int rowCount = 3;
276 int nonZeroCount = 4 ;
277 int rangeCount = 0;
278
279 const char* objectName = "Profit";
280 int objectSense = SOLV_OBJSENS_MAX;
281 double objectConst = - 4000.0 / 30.0;
282 double objectCoeffs[2] = { 0.05 , 0.08 };
283
284 double lowerBounds[2] = { 0, 0 };
285 double upperBounds[2] = { 1000000, 1000000 };
286
287 char rowType[3] = { 'L', 'L' , 'L' };
288 double rhsValues[3] = { 1400 , 8000 , 5000 };
289
290 int matrixBegin[2+1] = { 0 , 2, 4 };
291 int matrixCount[2] = { 2 , 2 };
292 int matrixIndex[4] = { 0, 1, 0, 2};
293 double matrixValues[4] = { 0.1, 1, 0.2, 1};
294
295 const char* colNames[2] = {"Sun", "Moon"};
296 const char* rowNames[3] = {"c1", "c2", "c3"};
297
298 double optimalValue = 506.66666667;
299
300 RunTestProblem(problemName, optimalValue, colCount, rowCount,
301 nonZeroCount, rangeCount, objectSense, objectConst, objectCoeffs,
302 lowerBounds, upperBounds, rowType, rhsValues, NULL,
303 matrixBegin, matrixCount, matrixIndex, matrixValues,
304 const_cast<char**>(colNames), const_cast<char**>(rowNames), objectName, NULL, NULL);
305 }
306
307
308 void SolveProblemAfiro(void)
309 {
310 const char* probname = "Afiro";
311 int ncol = 32;
312 int nrow = 27;
313 int nels = 83;
314 int nrng = 0;
315
316 const char* objectname = "Cost";
317 int objsens = SOLV_OBJSENS_MIN;
318 double objconst = 0.0;
319
320 double dobj[32]={0, -0.4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.32, 0, 0, 0, -0.6,
321 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.48, 0, 0, 10};
322
323 double dclo[32]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
324 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
325
326 double dcup[32]={1e+037, 1e+037, 1e+037, 1e+037, 1e+037, 1e+037, 1e+037,
327 1e+037, 1e+037, 1e+037, 1e+037, 1e+037, 1e+037, 1e+037, 1e+037, 1e+037,
328 1e+037, 1e+037, 1e+037, 1e+037, 1e+037, 1e+037, 1e+037, 1e+037, 1e+037,
329 1e+037, 1e+037, 1e+037, 1e+037, 1e+037, 1e+037, 1e+037};
330
331 char rtyp[27]= {'E', 'E', 'L', 'L', 'E', 'E', 'L', 'L', 'L', 'L', 'E', 'E', 'L',
332 'L', 'E', 'E', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'};
333
334 double drhs[27]={0, 0, 80, 0, 0, 0, 80, 0, 0, 0, 0, 0, 500, 0, 0, 44, 500, 0,
335 0, 0, 0, 0, 0, 0, 0, 310, 300};
336
337 int mbeg[32+1]={0, 4, 6, 8, 10, 14, 18, 22, 26, 28, 30, 32, 34, 36, 38, 40,
338 44, 46, 48, 50, 52, 56, 60, 64, 68, 70, 72, 74, 76, 78, 80, 82, 83};
339
340 int mcnt[32]={4, 2, 2, 2, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 4,
341 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 1};
342
343 int midx[83]={0, 1, 2, 23, 0, 3, 0, 21, 1, 25, 4, 5, 6, 24, 4, 5, 7, 24, 4, 5,
344 8, 24, 4, 5, 9, 24, 6, 20, 7, 20, 8, 20, 9, 20, 3, 4, 4, 22, 5, 26, 10, 11,
345 12, 21, 10, 13, 10, 23, 10, 20, 11, 25, 14, 15, 16, 22, 14, 15, 17, 22, 14,
346 15, 18, 22, 14, 15, 19, 22, 16, 20, 17, 20, 18, 20, 19, 20, 13, 15, 15, 24,
347 14, 26, 15};
348
349 double mval[83]={-1, -1.06, 1, 0.301, 1, -1, 1, -1, 1, 1, -1, -1.06, 1, 0.301,
350 -1, -1.06, 1, 0.313, -1, -0.96, 1, 0.313, -1, -0.86, 1, 0.326, -1, 2.364, -1,
351 2.386, -1, 2.408, -1, 2.429, 1.4, 1, 1, -1, 1, 1, -1, -0.43, 1, 0.109, 1, -1,
352 1, -1, 1, -1, 1, 1, -0.43, 1, 1, 0.109, -0.43, 1, 1, 0.108, -0.39, 1, 1,
353 0.108, -0.37, 1, 1, 0.107, -1, 2.191, -1, 2.219, -1, 2.249, -1, 2.279, 1.4,
354 -1, 1, -1, 1, 1, 1};
355
356 const char* colnames[32] = {"x01", "x02", "x03", "x04", "x06", "x07", "x08", "x09",
357 "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x22", "x23", "x24", "x25",
358 "x26", "x28", "x29", "x30", "x31", "x32", "x33", "x34", "x35", "x36", "x37",
359 "x38", "x39"};
360
361 const char* rownames[27] = {"r09", "r10", "x05", "x21", "r12", "r13", "x17", "x18",
362 "x19", "x20", "r19", "r20", "x27", "x44", "r22", "r23", "x40", "x41", "x42",
363 "x43", "x45", "x46", "x47", "x48", "x49", "x50", "x51"};
364
365 double optimalValue = -464.753142857;
366
367 RunTestProblem(probname, optimalValue, ncol, nrow, nels, nrng,
368 objsens, objconst, dobj, dclo, dcup, rtyp, drhs, NULL, mbeg,
369 mcnt, midx, mval, const_cast<char**>(colnames), const_cast<char**>(rownames), objectname, NULL, NULL);
370 }
371
372
373 void SolveProblemP0033(void)
374 {
375 const char* probname = "P0033";
376 int ncol = 33;
377 int nrow = 15;
378 int nels = 98;
379 int nrng = 0;
380
381 const char* objectname = "Obj";
382 int objsens = SOLV_OBJSENS_MIN;
383 double objconst = 0.0;
384
385 double dobj[33]={171, 171, 171, 171, 163, 162, 163, 69, 69, 183, 183, 183,
386 183, 49, 183, 258, 517, 250, 500, 250, 500, 159, 318, 159, 318, 159, 318, 159,
387 318, 114, 228, 159, 318};
388
389 double dclo[33]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
390 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
391
392 double dcup[33]={1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
393 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
394
395 char rtyp[15]= { 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L' };
396
397 double drhs[15]={1, 1, 1, 1, -5, 2700, -2600, -100, -900, -1656, -335, -1026,
398 -5, -500, -270};
399
400 int mbeg[33+1]={0, 3, 6, 10, 14, 19, 24, 26, 31, 36, 38, 41, 45, 49, 53, 54,
401 55, 56, 58, 60, 61, 62, 66, 70, 73, 76, 80, 84, 87, 90, 93, 96, 97, 98};
402
403 int mcnt[33]={3, 3, 4, 4, 5, 5, 2, 5, 5, 2, 3, 4, 4, 4, 1, 1, 1, 2, 2, 1, 1,
404 4, 4, 3, 3, 4, 4, 3, 3, 3, 3, 1, 1};
405
406 int midx[98]={0, 8, 9, 0, 12, 13, 0, 5, 6, 9, 0, 5, 6, 7, 1, 5, 6, 10, 11, 1,
407 5, 6, 8, 9, 1, 14, 2, 5, 6, 10, 11, 2, 5, 6, 8, 9, 3, 4, 3, 10, 11, 3, 5, 6,
408 11, 3, 5, 6, 9, 5, 6, 8, 9, 3, 4, 4, 12, 13, 12, 13, 13, 13, 5, 6, 10, 11, 5,
409 6, 10, 11, 5, 6, 11, 5, 6, 11, 5, 6, 8, 9, 5, 6, 8, 9, 5, 6, 9, 5, 6, 9, 5, 6,
410 7, 5, 6, 7, 14, 14};
411
412 double mval[98]={1, -300, -300, 1, -300, -300, 1, 300, -300, -300, 1, 300,
413 -300, -300, 1, 285, -285, -285, -285, 1, 285, -285, -285, -285, 1, -285, 1,
414 265, -265, -265, -265, 1, 265, -265, -265, -265, 1, -230, 1, -230, -230, 1,
415 230, -230, -230, 1, 230, -230, -230, 190, -190, -190, -190, 1, -200, -400,
416 -200, -200, -400, -400, -200, -400, 200, -200, -200, -200, 400, -400, -400,
417 -400, 200, -200, -200, 400, -400, -400, 200, -200, -200, -200, 400, -400,
418 -400, -400, 200, -200, -200, 400, -400, -400, 200, -200, -200, 400, -400,
419 -400, -200, -400};
420
421 const char* colnames[33] = {"c157", "c158", "c159", "c160", "c161", "c162", "c163",
422 "c164", "c165", "c166", "c167", "c168", "c169", "c170", "c171", "c172",
423 "c173", "c174", "c175", "c176", "c177", "c178", "c179", "c180", "c181",
424 "c182", "c183", "c184", "c185", "c186", "c187", "c188", "c189"};
425
426 const char* rownames[15] = {"r114", "r115", "r116", "r117", "r118", "r119", "r120",
427 "r121", "r122", "r123", "r124", "r125", "r126", "r127", "r128"};
428
429 char ctyp[33] = { 'B', 'B', 'B', 'B', 'B', 'B', 'B',
430 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B',
431 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B',
432 'B', 'B', 'B', 'B', 'B', 'B' };
433
434 double optimalValue = 3089.0;
435
436 RunTestProblem(probname, optimalValue, ncol, nrow, nels, nrng,
437 objsens, objconst, dobj, dclo, dcup, rtyp, drhs, NULL, mbeg,
438 mcnt, midx, mval, const_cast<char**>(colnames), const_cast<char**>(rownames), objectname, NULL, ctyp);
439 }
440
441
442 void SolveProblemExmip1(void)
443 {
444 const char* probname = "Exmip1";
445 int ncol = 8;
446 int nrow = 5;
447 int nels = 14;
448 int nrng = 2;
449
450 const char* objectname = "z";
451 int objsens = SOLV_OBJSENS_MIN;
452 double objconst = 0.0;
453 double dobj[8]={1, 0, 0, 0, 2, 0, 0, -1};
454
455 double dclo[8]={2.5, 0, 0, 0, 0.5, 0, 0, 0};
456 double dcup[8]={1e+037, 4.1, 1e+037, 1e+037, 4, 1e+037, 1e+037, 4.3};
457
458 char rtyp[5]= {'G', 'L', 'E', 'G', 'L'};
459 double drhs[5]={2.5, 2.1, 4, 1.8, 15};
460 double drng[5]={0, 0, 0, -3.2, 12};
461
462 int mbeg[8+1]={0, 2, 4, 6, 8, 10, 11, 12, 14};
463 int mcnt[8]={2, 2, 2, 2, 2, 1, 1, 2};
464 int midx[14]={0, 4, 0, 1, 1, 2, 0, 3, 0, 4, 2, 3, 0, 4};
465 double mval[14]={3, 5.6, 1, 2, 1.1, 1, -2, 2.8, -1, 1, 1, -1.2, -1, 1.9};
466
467 const char* colnames[8] = {"col01", "col02", "col03", "col04", "col05", "col06",
468 "col07", "col08"};
469 const char* rownames[5] = {"row01", "row02", "row03", "row04", "row05"};
470
471 char ctyp[8] = { 'C', 'C', 'B', 'B', 'C', 'C', 'C', 'C'};
472
473 double optimalValue = 3.23684210526;
474
475 RunTestProblem(probname, optimalValue, ncol, nrow, nels, nrng,
476 objsens, objconst, dobj, dclo, dcup, rtyp, drhs, drng, mbeg,
477 mcnt, midx, mval, const_cast<char**>(colnames), const_cast<char**>(rownames), objectname, NULL, ctyp);
478 }
479
480
481
482 void SolveProblemGamsSos1a(void)
483 {
484 const char* probname = "GamsSos1a";
485 int ncol = 3;
486 int nrow = 1;
487 int nels = 3;
488 int nrng = 0;
489
490 const char* objectname = "z";
491 int objsens = SOLV_OBJSENS_MAX;
492 double objconst = 0.0;
493 double dobj[3]={0.9, 1.0, 1.1};
494
495 double dclo[3]={0, 0, 0};
496 double dcup[3]={0.8, 0.6, 0.6};
497
498 double drlo[1]={-1e+37};
499 double drup[1]={1.0};
500
501 int mbeg[3+1]={0, 1, 2, 3};
502 int mcnt[3]={1, 1, 1};
503 int midx[3]={0, 0, 0};
504 double mval[3]={1, 1, 1};
505
506 const char* colnames[3] = {"x1", "x2", "x3"};
507 const char* rownames[1] = {"xsum"};
508
509 int sosCount = 1;
510 int sosNZCount = 3;
511 int sosType[1] = {1};
512 int sosBegin[1+1] = {0, 3};
513 int sosIndex[3] = {0, 1, 2};
514
515 double optimalValue = 0.72;
516
517 RunTestProblemMip(probname, optimalValue, ncol, nrow, nels, nrng,
518 objsens, objconst, dobj, dclo, dcup, NULL, drlo, drup, mbeg,
519 mcnt, midx, mval, const_cast<char**>(colnames), const_cast<char**>(rownames), objectname, NULL, NULL,
520 sosCount, sosNZCount, sosType, NULL, sosBegin, sosIndex, NULL,
521 0, NULL, 0, NULL, NULL, NULL);
522 }
523
524
525 void SolveProblemGamsSos2a(void)
526 {
527 const char* probname = "GamsSos2a";
528 int ncol = 7;
529 int nrow = 5;
530 int nels = 15;
531 int nrng = 0;
532
533 const char* objectname = "z";
534 int objsens = SOLV_OBJSENS_MIN;
535 double objconst = 0.0;
536 double dobj[7]={0, 0, 0, 0, 0, 1, 1};
537
538 double dclo[7]={0.0, 0, 0, -1e+37, -1e+37, 0, 0};
539 double dcup[7]={1e+37, 1e+37, 1e+37, 1e+37, 1e+37, 1e+37, 1e+37};
540
541 char rtyp[5]= {'E', 'E', 'E', 'G', 'G'};
542 double drhs[5]={1, 0, 0, -1.3, 1.3};
543
544 int mbeg[7+1]={0, 3, 6, 9, 10, 13, 14, 15};
545 int mcnt[7]={3, 3, 3, 1, 3, 1, 1};
546 int midx[15]={0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 2, 3, 4, 3, 4};
547 double mval[15]={1, 1, 1, 1, 2, 2, 1, 3, 3, -1, -1, -1, 1, 1, 1};
548
549 const char* colnames[7] = {"w1", "w2", "w3", "x", "fx", "fplus", "fminus"};
550 const char* rownames[5] = {"wsum", "xdef", "fxdef", "gapplus", "gapminus"};
551
552 int sosCount = 1;
553 int sosNZCount = 3;
554 int sosType[1] = {2};
555 int sosBegin[1+1] = {0, 3};
556 int sosIndex[3] = {0, 1, 2};
557
558 double optimalValue = 0.0;
559
560 RunTestProblemMip(probname, optimalValue, ncol, nrow, nels, nrng,
561 objsens, objconst, dobj, dclo, dcup, rtyp, drhs, NULL, mbeg,
562 mcnt, midx, mval, const_cast<char**>(colnames), const_cast<char**>(rownames), objectname, NULL, NULL,
563 sosCount, sosNZCount, sosType, NULL, sosBegin, sosIndex, NULL,
564 0, NULL, 0, NULL, NULL, NULL);
565 }
566
567
568 void SolveProblemSemiCont(void)
569 {
570 const char* probname = "SemiCont";
571 int ncol = 4;
572 int nrow = 3;
573 int nels = 6;
574 int nrng = 0;
575
576 const char* objectname = "z";
577 int objsens = SOLV_OBJSENS_MIN;
578 double objconst = 0.0;
579 double dobj[4]={0.0, 1.0, 1.0, 0.0};
580
581 double dclo[4]={2.8, 0.0, 0.0, 0.0};
582 double dcup[4]={10.0, 1e+37, 1e+37, 1e+37};
583
584 char rtyp[3]= {'L', 'G', 'E'};
585 double drhs[3]={8.9, 8.9, 10.0};
586
587 int mbeg[4+1]={0, 1, 2, 3, 6};
588 int mcnt[4]={1, 1, 1, 3};
589 int midx[6]={2, 0, 1, 0, 1, 2};
590 double mval[6]={1, -1, 1, 1, 1, 1};
591
592 const char* colnames[4] = {"s", "pup", "plo", "x"};
593 const char* rownames[3] = {"bigx", "smallx", "f"};
594
595 int semiCount = 1;
596 int semiIndex[1] = {0};
597
598 double optimalValue = 1.1;
599
600 RunTestProblemMip(probname, optimalValue, ncol, nrow, nels, nrng,
601 objsens, objconst, dobj, dclo, dcup, rtyp, drhs, NULL, mbeg,
602 mcnt, midx, mval, const_cast<char**>(colnames), const_cast<char**>(rownames), objectname, NULL, NULL,
603 0, 0, NULL, NULL, NULL, NULL, NULL, semiCount, semiIndex,
604 0, NULL, NULL, NULL);
605 }
606
607
608 int main (int argc, char* argv[])
609 {
610 const char* SolverName;
611 double CoinVersion;
612
613 CoinInitSolver("");
614 SolverName = CoinGetSolverName();
615 CoinVersion = CoinGetVersion();
616 fprintf(stdout, "UnitTest: %s version %.20g\n\n", SolverName, CoinVersion);
617 SolveProblemCoinTest();
618 SolveProblemBakery();
619 SolveProblemAfiro();
620 SolveProblemP0033();
621 SolveProblemExmip1();
622 SolveProblemGamsSos1a();
623 SolveProblemGamsSos2a();
624 SolveProblemSemiCont();
625 fprintf(stdout, "All unit tests completed successfully\n" );
626 CoinFreeSolver();
627 return 0;
628 }