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