Debian Codegraph @

CoinMP/src/CoinMP.cpp

raw
1 /************************************************************************/
2 /* */
3 /* CoinMP Solver Maximal Software */
4 /* */
5 /* File : 'coinmp.cpp' */
6 /* */
7 /* Version : 1.8 */
8 /* */
9 /* Author : Bjarni Kristjansson, Maximal Software */
10 /* */
11 /* Copyright (c) 2002-2015 Bjarni Kristjansson */
12 /* */
13 /************************************************************************/
14
15 // $Id: CoinMP.cpp 674 2019-02-23 18:35:11Z stefan $
16
17 #include <stdlib.h>
18 #include <string.h>
19 #include <stdio.h>
20 #include <stdarg.h>
21 #include <memory.h>
22
23 #include "CoinProblem.h"
24 #include "CoinResult.h"
25 #include "CoinSolver.h"
26 #include "CoinOption.h"
27
28 #include "CoinCbc.h"
29
30 #include "config_coinmp_default.h"
31
32
33 #define SOLVER_EXPORT
34 #define SOLV_LINK_LIB
35 #include "CoinMP.h"
36
37
38 const char* COINMP_VERSIONSTR = "1.8.4";
39 const int COINMP_VERSIONINT = 184;
40 const double COINMP_VERSIONDBL = 1.84;
41
42 const char* COINMP_NAME = "CoinMP";
43
44
45 /************************************************************************/
46 /* Solver Initialization */
47 /************************************************************************/
48
49
50 SOLVAPI int SOLVCALL CoinInitSolver(const char* LicenseStr)
51 {
52 return SOLV_CALL_SUCCESS;
53 }
54
55
56 SOLVAPI int SOLVCALL CoinFreeSolver(void)
57 {
58 return SOLV_CALL_SUCCESS;
59 }
60
61 /************************************************************************/
62 /* Solver Queries */
63 /************************************************************************/
64
65
66 SOLVAPI const char* SOLVCALL CoinGetSolverName(void)
67 {
68 return COINMP_NAME;
69 }
70
71
72 SOLVAPI int SOLVCALL CoinGetSolverNameBuf(char* SolverName, int buflen)
73 {
74 strncpy(SolverName, CoinGetSolverName(), buflen-1);
75 SolverName[buflen-1] = '\0';
76 return (int)strlen(SolverName);
77 }
78
79
80 SOLVAPI const char* SOLVCALL CoinGetVersionStr(void)
81 {
82 return COINMP_VERSIONSTR;
83 }
84
85
86 SOLVAPI int SOLVCALL CoinGetVersionStrBuf(char* VersionStr, int buflen)
87 {
88 strncpy(VersionStr, CoinGetVersionStr(), buflen-1);
89 VersionStr[buflen-1] = '\0';
90 return (int)strlen(VersionStr);
91 }
92
93
94 SOLVAPI double SOLVCALL CoinGetVersion(void)
95 {
96 return COINMP_VERSIONDBL;
97 }
98
99
100 SOLVAPI int SOLVCALL CoinGetFeatures(void)
101 {
102 return SOLV_FEATURE_LP |
103 SOLV_FEATURE_MIP;
104 }
105
106
107 SOLVAPI int SOLVCALL CoinGetMethods(void)
108 {
109 return SOLV_METHOD_PRIMAL |
110 SOLV_METHOD_DUAL |
111 SOLV_METHOD_BARRIER;
112 }
113
114
115
116 SOLVAPI double SOLVCALL CoinGetInfinity(void)
117 {
118 return COIN_DBL_MAX;
119 }
120
121
122 /************************************************************************/
123 /* Coin Problem Info Structure */
124 /************************************************************************/
125
126
127 typedef struct {
128 PPROBLEM pProblem;
129 PRESULT pResult;
130 PSOLVER pSolver;
131 POPTION pOption;
132
133 } COININFO, *PCOIN;
134
135
136
137 /************************************************************************/
138 /* Create/Load Problem */
139 /************************************************************************/
140
141
142 SOLVAPI HPROB SOLVCALL CoinCreateProblem(const char* ProblemName)
143 {
144 PCOIN pCoin;
145
146 pCoin = (PCOIN) malloc(sizeof(COININFO));
147
148 pCoin->pProblem = coinCreateProblemObject();
149 pCoin->pResult = coinCreateResultObject();
150 pCoin->pSolver = coinCreateSolverObject();
151 pCoin->pOption = coinCreateOptionObject();
152
153 coinSetProblemName(pCoin->pProblem, ProblemName);
154 coinCopyOptionTable(pCoin->pOption, CbcGetOptionTable(), CbcGetOptionCount());
155
156 return (HPROB)pCoin;
157 }
158
159
160 SOLVAPI int SOLVCALL CoinUnloadProblem(HPROB hProb)
161 {
162 PCOIN pCoin = (PCOIN)hProb;
163
164 if (pCoin) {
165 coinClearProblemObject(pCoin->pProblem);
166 coinClearResultObject(pCoin->pResult);
167 coinClearSolverObject(pCoin->pSolver);
168 coinClearOptionObject(pCoin->pOption);
169 }
170 free(pCoin);
171 pCoin = NULL;
172 return SOLV_CALL_SUCCESS;
173 }
174
175
176
177 SOLVAPI int SOLVCALL CoinLoadMatrix(HPROB hProb,
178 int ColCount, int RowCount, int NZCount, int RangeCount,
179 int ObjectSense, double ObjectConst, double* ObjectCoeffs,
180 double* LowerBounds, double* UpperBounds, const char* RowType,
181 double* RHSValues, double* RangeValues, int* MatrixBegin,
182 int* MatrixCount, int* MatrixIndex, double* MatrixValues)
183 {
184 PCOIN pCoin = (PCOIN)hProb;
185 PPROBLEM pProblem = pCoin->pProblem;
186
187 if (!coinStoreMatrix(pProblem, ColCount, RowCount, NZCount, RangeCount, ObjectSense,
188 ObjectConst, ObjectCoeffs, LowerBounds, UpperBounds, RowType,
189 RHSValues, RangeValues, MatrixBegin, MatrixCount, MatrixIndex,
190 MatrixValues)) {
191 return SOLV_CALL_FAILED;
192 }
193 return SOLV_CALL_SUCCESS;
194 }
195
196
197 SOLVAPI int SOLVCALL CoinLoadNames(HPROB hProb, char** ColNamesList, char** RowNamesList, const char* ObjectName)
198 {
199 PCOIN pCoin = (PCOIN)hProb;
200
201 if (!coinStoreNamesList(pCoin->pProblem, ColNamesList, RowNamesList, ObjectName)) {
202 return SOLV_CALL_FAILED;
203 }
204 return SOLV_CALL_SUCCESS;
205 }
206
207
208
209 SOLVAPI int SOLVCALL CoinLoadNamesBuf(HPROB hProb, const char* ColNamesBuf, const char* RowNamesBuf, const char* ObjectName)
210 {
211 PCOIN pCoin = (PCOIN)hProb;
212
213 if (!coinStoreNamesBuf(pCoin->pProblem, ColNamesBuf, RowNamesBuf, ObjectName)) {
214 return SOLV_CALL_FAILED;
215 }
216 return SOLV_CALL_SUCCESS;
217 }
218
219
220
221 SOLVAPI int SOLVCALL CoinLoadProblem(HPROB hProb,
222 int ColCount, int RowCount, int NZCount, int RangeCount,
223 int ObjectSense, double ObjectConst, double* ObjectCoeffs,
224 double* LowerBounds, double* UpperBounds, const char* RowType,
225 double* RHSValues, double* RangeValues, int* MatrixBegin,
226 int* MatrixCount, int* MatrixIndex, double* MatrixValues,
227 char** ColNamesList, char** RowNamesList, const char* ObjectName)
228 {
229 PCOIN pCoin = (PCOIN)hProb;
230 PPROBLEM pProblem = pCoin->pProblem;
231
232 if (!coinStoreMatrix(pProblem, ColCount, RowCount, NZCount, RangeCount, ObjectSense,
233 ObjectConst, ObjectCoeffs, LowerBounds, UpperBounds, RowType,
234 RHSValues, RangeValues, MatrixBegin, MatrixCount, MatrixIndex,
235 MatrixValues)) {
236 return SOLV_CALL_FAILED;
237 }
238 if (!coinStoreNamesList(pProblem, ColNamesList, RowNamesList, ObjectName)) {
239 return SOLV_CALL_FAILED;
240 }
241 return SOLV_CALL_SUCCESS;
242 }
243
244 // CoinLoadProblemBuf accepts ColNamesBuf/RowNamesBuf as character buffer with \0 after each name
245
246 SOLVAPI int SOLVCALL CoinLoadProblemBuf(HPROB hProb,
247 int ColCount, int RowCount, int NZCount, int RangeCount,
248 int ObjectSense, double ObjectConst, double* ObjectCoeffs,
249 double* LowerBounds, double* UpperBounds, const char* RowType,
250 double* RHSValues, double* RangeValues, int* MatrixBegin,
251 int* MatrixCount, int* MatrixIndex, double* MatrixValues,
252 const char* ColNamesBuf, const char* RowNamesBuf, const char* ObjectName)
253 {
254 PCOIN pCoin = (PCOIN)hProb;
255 PPROBLEM pProblem = pCoin->pProblem;
256
257 if (!coinStoreMatrix(pProblem, ColCount, RowCount, NZCount, RangeCount, ObjectSense,
258 ObjectConst, ObjectCoeffs, LowerBounds, UpperBounds, RowType,
259 RHSValues, RangeValues, MatrixBegin, MatrixCount, MatrixIndex,
260 MatrixValues)) {
261 return SOLV_CALL_FAILED;
262 }
263 if (!coinStoreNamesBuf(pProblem, ColNamesBuf, RowNamesBuf, ObjectName)) {
264 return SOLV_CALL_FAILED;
265 }
266 return SOLV_CALL_SUCCESS;
267 }
268
269
270
271
272 SOLVAPI int SOLVCALL CoinLoadInitValues(HPROB hProb, double* InitValues)
273 {
274 PCOIN pCoin = (PCOIN)hProb;
275
276 if (!coinStoreInitValues(pCoin->pProblem, InitValues)) {
277 return SOLV_CALL_FAILED;
278 }
279 return SOLV_CALL_SUCCESS;
280 }
281
282
283 SOLVAPI int SOLVCALL CoinLoadInteger(HPROB hProb, const char* ColType)
284 {
285 PCOIN pCoin = (PCOIN)hProb;
286 PPROBLEM pProblem = pCoin->pProblem;
287
288 if (!coinStoreInteger(pProblem, ColType)) {
289 return SOLV_CALL_FAILED;
290 }
291 return SOLV_CALL_SUCCESS;
292 }
293
294
295
296 SOLVAPI int SOLVCALL CoinLoadPriority(HPROB hProb, int PriorCount, int* PriorIndex,
297 int* PriorValues, int* PriorBranch)
298 {
299 PCOIN pCoin = (PCOIN)hProb;
300
301 if (!coinStorePriority(pCoin->pProblem, PriorCount, PriorIndex, PriorValues, PriorBranch)) {
302 return SOLV_CALL_FAILED;
303 }
304 return SOLV_CALL_SUCCESS;
305 }
306
307
308 SOLVAPI int SOLVCALL CoinLoadSos(HPROB hProb, int SosCount, int SosNZCount,
309 int* SosType, int* SosPrior, int* SosBegin,
310 int* SosIndex, double* SosRef)
311 {
312 PCOIN pCoin = (PCOIN)hProb;
313
314 if (!coinStoreSos(pCoin->pProblem, SosCount, SosNZCount, SosType, SosPrior,
315 SosBegin, SosIndex, SosRef)) {
316 return SOLV_CALL_FAILED;
317 }
318 return SOLV_CALL_SUCCESS;
319 }
320
321
322
323 SOLVAPI int SOLVCALL CoinLoadSemiCont(HPROB hProb, int SemiCount, int* SemiIndex)
324 {
325 PCOIN pCoin = (PCOIN)hProb;
326
327 if (!coinStoreSemiCont(pCoin->pProblem, SemiCount, SemiIndex)) {
328 return SOLV_CALL_FAILED;
329 }
330 return SOLV_CALL_SUCCESS;
331 }
332
333
334 SOLVAPI int SOLVCALL CoinLoadQuadratic(HPROB hProb, int* QuadBegin, int* QuadCount,
335 int* QuadIndex, double* QuadValues)
336 {
337 return SOLV_CALL_FAILED;
338 }
339
340
341 SOLVAPI int SOLVCALL CoinLoadNonlinear(HPROB hProb, int NlpTreeCount, int NlpLineCount,
342 int* NlpBegin, int* NlpOper, int* NlpArg1,
343 int* NlpArg2, int* NlpIndex1, int* NlpIndex2,
344 double* NlpValue1, double* NlpValue2)
345 {
346 return SOLV_CALL_FAILED;
347 }
348
349
350
351
352 #define CHECK_MAXNAMELEN 100
353
354
355 SOLVAPI int SOLVCALL CoinCheckProblem(HPROB hProb)
356 {
357 PCOIN pCoin = (PCOIN)hProb;
358 PPROBLEM pProblem = pCoin->pProblem;
359 int i;
360
361 if (pProblem->ColCount == 0) {
362 return SOLV_CHECK_COLCOUNT;
363 }
364 if ((pProblem->RowCount < 0) ||
365 (pProblem->NZCount < 0) ||
366 (pProblem->RangeCount < 0)) {
367 return SOLV_CHECK_ROWCOUNT;
368 }
369 if ((pProblem->RangeCount > pProblem->RowCount)) {
370 return SOLV_CHECK_RANGECOUNT;
371 }
372 if ((pProblem->ObjectSense < -1) ||
373 (pProblem->ObjectSense > 1)) {
374 return SOLV_CHECK_OBJSENSE;
375 }
376 if (pProblem->RowType && (pProblem->RowCount > 0)) {
377 for (i = 0; i < pProblem->RowCount; i++) {
378 if ((pProblem->RowType[i] != 'L') &&
379 (pProblem->RowType[i] != 'E') &&
380 (pProblem->RowType[i] != 'G') &&
381 (pProblem->RowType[i] != 'R') &&
382 (pProblem->RowType[i] != 'N')) {
383 return SOLV_CHECK_ROWTYPE;
384 }
385 }
386 }
387 if (pProblem->NZCount > 0) {
388 for (i = 0; i < pProblem->ColCount; i++) {
389 if (pProblem->MatrixBegin[i] < 0) {
390 return SOLV_CHECK_MATBEGIN;
391 }
392 if (pProblem->MatrixCount[i] < 0) {
393 return SOLV_CHECK_MATCOUNT;
394 }
395 if (pProblem->MatrixBegin[i+1] - pProblem->MatrixBegin[i] != pProblem->MatrixCount[i]) {
396 return SOLV_CHECK_MATBEGCNT;
397 }
398 }
399 if (pProblem->MatrixBegin[pProblem->ColCount] != pProblem->NZCount) {
400 return 100 + pProblem->MatrixBegin[pProblem->ColCount];
401 }
402 for (i = 0; i < pProblem->NZCount; i++) {
403 if (pProblem->MatrixIndex[i] < 0) {
404 return SOLV_CHECK_MATINDEX;
405 }
406 if (pProblem->MatrixIndex[i] >= pProblem->RowCount) {
407 return SOLV_CHECK_MATINDEXROW;
408 }
409 }
410 }
411 if (pProblem->LowerBounds && pProblem->UpperBounds) {
412 for (i = 0; i < pProblem->ColCount; i++) {
413 if (pProblem->LowerBounds[i] > pProblem->UpperBounds[i]) {
414 return SOLV_CHECK_BOUNDS;
415 }
416 }
417 }
418 if (pProblem->ColType) {
419 for (i = 0; i < pProblem->ColCount; i++) {
420 if ((pProblem->ColType[i] != 'C') &&
421 (pProblem->ColType[i] != 'B') &&
422 (pProblem->ColType[i] != 'I')) {
423 return SOLV_CHECK_COLTYPE;
424 }
425 }
426 }
427 if (pProblem->ColNamesBuf) {
428 if (pProblem->lenColNamesBuf <= 0) {
429 return SOLV_CHECK_COLNAMES;
430 }
431 if (pProblem->lenColNamesBuf > pProblem->ColCount * CHECK_MAXNAMELEN) {
432 return SOLV_CHECK_COLNAMESLEN;
433 }
434 }
435 if (pProblem->RowNamesBuf) {
436 if (pProblem->lenRowNamesBuf <= 0) {
437 return SOLV_CHECK_ROWNAMES;
438 }
439 if (pProblem->lenRowNamesBuf > pProblem->RowCount * CHECK_MAXNAMELEN) {
440 return SOLV_CHECK_ROWNAMSLEN;
441 }
442 }
443 return SOLV_CALL_SUCCESS;
444 }
445
446
447
448 /************************************************************************/
449 /* Problem Queries */
450 /************************************************************************/
451
452
453 SOLVAPI const char* SOLVCALL CoinGetProblemName(HPROB hProb)
454 {
455 PCOIN pCoin = (PCOIN)hProb;
456
457 return pCoin->pProblem->ProblemName;
458 }
459
460
461 SOLVAPI int SOLVCALL CoinGetProblemNameBuf(HPROB hProb, char* ProbName, int buflen)
462 {
463 strncpy(ProbName, CoinGetProblemName(hProb), buflen-1);
464 ProbName[buflen-1] = '\0';
465 return (int)strlen(ProbName);
466 }
467
468
469
470 SOLVAPI int SOLVCALL CoinGetColCount(HPROB hProb)
471 {
472 PCOIN pCoin = (PCOIN)hProb;
473
474 return pCoin->pProblem->ColCount;
475 }
476
477
478 SOLVAPI int SOLVCALL CoinGetRowCount(HPROB hProb)
479 {
480 PCOIN pCoin = (PCOIN)hProb;
481
482 return pCoin->pProblem->RowCount;
483 }
484
485
486
487 SOLVAPI const char* SOLVCALL CoinGetColName(HPROB hProb, int col)
488 {
489 PCOIN pCoin = (PCOIN)hProb;
490
491 return pCoin->pProblem->ColNamesList[col];
492 }
493
494
495 SOLVAPI int SOLVCALL CoinGetColNameBuf(HPROB hProb, int col, char* ColName, int buflen)
496 {
497 strncpy(ColName, CoinGetColName(hProb, col), buflen-1);
498 ColName[buflen-1] = '\0';
499 return (int)strlen(ColName);
500 }
501
502
503 SOLVAPI const char* SOLVCALL CoinGetRowName(HPROB hProb, int row)
504 {
505 PCOIN pCoin = (PCOIN)hProb;
506
507 return pCoin->pProblem->RowNamesList[row];
508 }
509
510
511 SOLVAPI int SOLVCALL CoinGetRowNameBuf(HPROB hProb, int row, char* RowName, int buflen)
512 {
513 strncpy(RowName, CoinGetRowName(hProb, row), buflen-1);
514 RowName[buflen-1] = '\0';
515 return (int)strlen(RowName);
516 }
517
518
519
520 SOLVAPI int SOLVCALL CoinRegisterMsgLogCallback(HPROB hProb, COIN_MSGLOG_CB MsgLogCB, void *UserParam)
521 {
522 PCOIN pCoin = (PCOIN)hProb;
523
524 pCoin->pSolver->MsgLogCB = MsgLogCB;
525 pCoin->pSolver->MsgLogParam = UserParam;
526 return SOLV_CALL_SUCCESS;
527 }
528
529 SOLVAPI int SOLVCALL CoinRegisterLPIterCallback(HPROB hProb, COIN_LPITER_CB LPIterCB, void *UserParam)
530 {
531 PCOIN pCoin = (PCOIN)hProb;
532
533 pCoin->pSolver->LPIterCB = LPIterCB;
534 pCoin->pSolver->LPIterParam = UserParam;
535 return SOLV_CALL_SUCCESS;
536 }
537
538 SOLVAPI int SOLVCALL CoinRegisterMipNodeCallback(HPROB hProb, COIN_MIPNODE_CB MipNodeCB, void *UserParam)
539 {
540 PCOIN pCoin = (PCOIN)hProb;
541
542 pCoin->pSolver->MipNodeCB = MipNodeCB;
543 pCoin->pSolver->MipNodeParam = UserParam;
544 return SOLV_CALL_SUCCESS;
545 }
546
547
548 // Depreciated, use CoinRegisterMsgLogCallback instead
549 SOLVAPI int SOLVCALL CoinSetMsgLogCallback(HPROB hProb, MSGLOGCALLBACK MsgLogCallback)
550 {
551 PCOIN pCoin = (PCOIN)hProb;
552
553 pCoin->pSolver->MsgLogCallback = MsgLogCallback;
554 return SOLV_CALL_SUCCESS;
555 }
556
557 // Depreciated, use CoinRegisterLPIterCallback instead
558 SOLVAPI int SOLVCALL CoinSetIterCallback(HPROB hProb, ITERCALLBACK IterCallback)
559 {
560 PCOIN pCoin = (PCOIN)hProb;
561
562 pCoin->pSolver->IterCallback = IterCallback;
563 return SOLV_CALL_SUCCESS;
564 }
565
566 // Depreciated, use CoinRegisterMipNodeCallback instead
567 SOLVAPI int SOLVCALL CoinSetMipNodeCallback(HPROB hProb, MIPNODECALLBACK MipNodeCallback)
568 {
569 PCOIN pCoin = (PCOIN)hProb;
570
571 pCoin->pSolver->MipNodeCallback = MipNodeCallback;
572 return SOLV_CALL_SUCCESS;
573 }
574
575
576
577 /************************************************************************/
578 /* Optimization */
579 /************************************************************************/
580
581
582 SOLVAPI int SOLVCALL CoinOptimizeProblem(HPROB hProb, int Method)
583 {
584 PCOIN pCoin = (PCOIN)hProb;
585
586 return CbcOptimizeProblem(pCoin->pProblem, pCoin->pResult, pCoin->pSolver, pCoin->pOption, Method);
587 }
588
589
590
591 /************************************************************************/
592 /* Solution status */
593 /************************************************************************/
594
595
596 SOLVAPI int SOLVCALL CoinGetSolutionStatus(HPROB hProb)
597 {
598 PCOIN pCoin = (PCOIN)hProb;
599
600 return pCoin->pResult->SolutionStatus;
601 }
602
603
604
605
606 SOLVAPI const char* SOLVCALL CoinGetSolutionText(HPROB hProb)
607 {
608 PCOIN pCoin = (PCOIN)hProb;
609
610 return pCoin->pResult->SolutionText;
611 }
612
613
614 SOLVAPI int SOLVCALL CoinGetSolutionTextBuf(HPROB hProb, char* SolutionText, int buflen)
615 {
616 strncpy(SolutionText, CoinGetSolutionText(hProb), buflen-1);
617 SolutionText[buflen-1] = '\0';
618 return (int)strlen(SolutionText);
619 }
620
621
622
623 SOLVAPI double SOLVCALL CoinGetObjectValue(HPROB hProb)
624 {
625 PCOIN pCoin = (PCOIN)hProb;
626
627 return pCoin->pResult->ObjectValue + pCoin->pProblem->ObjectConst;
628 }
629
630
631 SOLVAPI double SOLVCALL CoinGetMipBestBound(HPROB hProb)
632 {
633 PCOIN pCoin = (PCOIN)hProb;
634
635 return pCoin->pResult->MipBestBound;
636 }
637
638
639
640 SOLVAPI int SOLVCALL CoinGetIterCount(HPROB hProb)
641 {
642 PCOIN pCoin = (PCOIN)hProb;
643
644 return pCoin->pResult->IterCount;
645 }
646
647
648 SOLVAPI int SOLVCALL CoinGetMipNodeCount(HPROB hProb)
649 {
650 PCOIN pCoin = (PCOIN)hProb;
651
652 return pCoin->pResult->MipNodeCount;
653 }
654
655
656
657 /************************************************************************/
658 /* Solution retrieval */
659 /************************************************************************/
660
661
662 SOLVAPI int SOLVCALL CoinGetSolutionValues(HPROB hProb, double* Activity, double* ReducedCost,
663 double* SlackValues, double* ShadowPrice)
664 {
665 PCOIN pCoin = (PCOIN)hProb;
666 PPROBLEM pProblem = pCoin->pProblem;
667 PRESULT pResult = pCoin->pResult;
668
669 if (Activity && pResult->ColActivity) {
670 memcpy(Activity, pResult->ColActivity, pProblem->ColCount * sizeof(double));
671 }
672 if (ReducedCost && pResult->ReducedCost) {
673 memcpy(ReducedCost, pResult->ReducedCost, pProblem->ColCount * sizeof(double));
674 }
675 if (SlackValues && pResult->SlackValues) {
676 memcpy(SlackValues, pResult->SlackValues, pProblem->RowCount * sizeof(double));
677 }
678 if (ShadowPrice && pResult->ShadowPrice) {
679 memcpy(ShadowPrice, pResult->ShadowPrice, pProblem->RowCount * sizeof(double));
680 }
681 return SOLV_CALL_SUCCESS;
682 }
683
684
685
686 SOLVAPI int SOLVCALL CoinGetSolutionRanges(HPROB hProb, double* ObjLoRange, double* ObjUpRange,
687 double* RhsLoRange, double* RhsUpRange)
688 {
689 PCOIN pCoin = (PCOIN)hProb;
690 PPROBLEM pProblem = pCoin->pProblem;
691 PRESULT pResult = pCoin->pResult;
692
693 if (ObjLoRange && pResult->ObjLoRange) {
694 memcpy(ObjLoRange, pResult->ObjLoRange, pProblem->ColCount * sizeof(double));
695 }
696 if (ObjUpRange && pResult->ObjUpRange) {
697 memcpy(ObjUpRange, pResult->ObjUpRange, pProblem->ColCount * sizeof(double));
698 }
699 if (RhsLoRange && pResult->RhsLoRange) {
700 memcpy(RhsLoRange, pResult->RhsLoRange, pProblem->RowCount * sizeof(double));
701 }
702 if (RhsUpRange && pResult->RhsUpRange) {
703 memcpy(RhsUpRange, pResult->RhsUpRange, pProblem->RowCount * sizeof(double));
704 }
705 return SOLV_CALL_SUCCESS;
706 }
707
708
709
710 SOLVAPI int SOLVCALL CoinGetSolutionBasis(HPROB hProb, int* ColStatus, int* RowStatus)
711 {
712 PCOIN pCoin = (PCOIN)hProb;
713 PPROBLEM pProblem = pCoin->pProblem;
714 PRESULT pResult = pCoin->pResult;
715
716 if (ColStatus && pResult->ColStatus) {
717 memcpy(ColStatus, pResult->ColStatus, pProblem->ColCount * sizeof(int));
718 }
719 if (RowStatus && pResult->RowStatus) {
720 memcpy(RowStatus, pResult->RowStatus, pProblem->RowCount * sizeof(int));
721 }
722 return SOLV_CALL_SUCCESS;
723 }
724
725
726
727 /************************************************************************/
728 /* File Handling */
729 /************************************************************************/
730
731
732 SOLVAPI int SOLVCALL CoinReadFile(HPROB hProb, int FileType, const char* ReadFilename)
733 {
734 PCOIN pCoin = (PCOIN)hProb;
735
736 switch (FileType) {
737 case SOLV_FILE_MPS:
738 return CbcReadMpsFile(pCoin->pProblem, ReadFilename);
739
740 case SOLV_FILE_LP:
741 case SOLV_FILE_BASIS:
742 case SOLV_FILE_IIS:
743
744 default:
745 return SOLV_CALL_FAILED;
746 }
747 return SOLV_CALL_SUCCESS;
748 }
749
750
751
752 SOLVAPI int SOLVCALL CoinWriteFile(HPROB hProb, int FileType, const char* WriteFilename)
753 {
754 PCOIN pCoin = (PCOIN)hProb;
755
756 switch (FileType) {
757 case SOLV_FILE_MPS:
758 return CbcWriteMpsFile(pCoin->pProblem, WriteFilename);
759
760 case SOLV_FILE_LP:
761 case SOLV_FILE_BASIS:
762 case SOLV_FILE_IIS:
763
764 default:
765 return SOLV_CALL_FAILED;
766
767 }
768 return SOLV_CALL_SUCCESS;
769 }
770
771
772
773 SOLVAPI int SOLVCALL CoinOpenLogFile(HPROB hProb, const char* logFilename)
774 {
775 PCOIN pCoin = (PCOIN)hProb;
776
777 strcpy(pCoin->pSolver->LogFilename, logFilename);
778 return SOLV_CALL_SUCCESS;
779 }
780
781
782 SOLVAPI int SOLVCALL CoinCloseLogFile(HPROB hProb)
783 {
784 return SOLV_CALL_SUCCESS;
785 }
786
787
788 /************************************************************************/
789 /* Option Handling */
790 /************************************************************************/
791
792
793 SOLVAPI int SOLVCALL CoinGetOptionCount(HPROB hProb)
794 {
795 PCOIN pCoin = (PCOIN)hProb;
796
797 return coinGetOptionCount(pCoin->pOption);
798 }
799
800 SOLVAPI int SOLVCALL CoinLocateOptionID(HPROB hProb, int OptionID)
801 {
802 PCOIN pCoin = (PCOIN)hProb;
803
804 return coinLocateOptionID(pCoin->pOption, OptionID);
805 }
806
807
808 SOLVAPI int SOLVCALL CoinLocateOptionName(HPROB hProb, const char* OptionName)
809 {
810 PCOIN pCoin = (PCOIN)hProb;
811
812 return coinLocateOptionName(pCoin->pOption, OptionName);
813 }
814
815
816
817 SOLVAPI int SOLVCALL CoinGetOptionID(HPROB hProb, int OptionNr)
818 {
819 PCOIN pCoin = (PCOIN)hProb;
820
821 return coinGetOptionID(pCoin->pOption, OptionNr);
822 }
823
824
825 SOLVAPI int SOLVCALL CoinGetOptionInfo(HPROB hProb, int OptionNr, int* OptionID, int* GroupType, int* OptionType)
826 {
827 PCOIN pCoin = (PCOIN)hProb;
828 int optionID;
829
830 optionID = coinGetOptionID(pCoin->pOption, OptionNr);
831 if (OptionID) *OptionID = optionID;
832 if (OptionType) *OptionType = coinGetOptionType(pCoin->pOption, optionID);
833 if (GroupType) *GroupType = coinGetOptionGroup(pCoin->pOption, optionID);
834 return SOLV_CALL_SUCCESS;
835 }
836
837
838 SOLVAPI int SOLVCALL CoinGetIntOptionMinMax(HPROB hProb, int OptionNr, int* MinValue, int* MaxValue)
839 {
840 PCOIN pCoin = (PCOIN)hProb;
841 int optionID;
842
843 optionID = coinGetOptionID(pCoin->pOption, OptionNr);
844 if (MinValue) *MinValue = coinGetIntOptionMinValue(pCoin->pOption, optionID);
845 if (MaxValue) *MaxValue = coinGetIntOptionMaxValue(pCoin->pOption, optionID);
846 return SOLV_CALL_SUCCESS;
847 }
848
849
850 SOLVAPI int SOLVCALL CoinGetRealOptionMinMax(HPROB hProb, int OptionNr, double* MinValue, double* MaxValue)
851 {
852 PCOIN pCoin = (PCOIN)hProb;
853 int optionID;
854
855 optionID = coinGetOptionID(pCoin->pOption, OptionNr);
856 if (MinValue) *MinValue = coinGetRealOptionMinValue(pCoin->pOption, optionID);
857 if (MaxValue) *MaxValue = coinGetRealOptionMaxValue(pCoin->pOption, optionID);
858 return SOLV_CALL_SUCCESS;
859 }
860
861
862 SOLVAPI int SOLVCALL CoinGetOptionNamesBuf(HPROB hProb, int OptionNr, char* OptionName,
863 char* ShortName, int buflen)
864 {
865 PCOIN pCoin = (PCOIN)hProb;
866 int optionID;
867
868 optionID = coinGetOptionID(pCoin->pOption, OptionNr);
869 if (OptionName) coinGetOptionNameBuf(pCoin->pOption, optionID, OptionName, buflen);
870 if (ShortName) coinGetOptionShortNameBuf(pCoin->pOption, optionID, ShortName, buflen);
871 return SOLV_CALL_SUCCESS;
872 }
873
874
875
876
877
878 SOLVAPI int SOLVCALL CoinGetOptionGroup(HPROB hProb, int OptionID)
879 {
880 PCOIN pCoin = (PCOIN)hProb;
881
882 return coinGetOptionGroup(pCoin->pOption, OptionID);
883 }
884
885
886 SOLVAPI int SOLVCALL CoinGetOptionType(HPROB hProb, int OptionID)
887 {
888 PCOIN pCoin = (PCOIN)hProb;
889
890 return coinGetOptionType(pCoin->pOption, OptionID);
891 }
892
893
894
895
896 SOLVAPI int SOLVCALL CoinGetIntOptionDefaultValue(HPROB hProb, int OptionID)
897 {
898 PCOIN pCoin = (PCOIN)hProb;
899
900 return coinGetIntOptionDefaultValue(pCoin->pOption, OptionID);
901 }
902
903
904 SOLVAPI int SOLVCALL CoinGetIntOptionMinValue(HPROB hProb, int OptionID)
905 {
906 PCOIN pCoin = (PCOIN)hProb;
907
908 return coinGetIntOptionMinValue(pCoin->pOption, OptionID);
909 }
910
911
912 SOLVAPI int SOLVCALL CoinGetIntOptionMaxValue(HPROB hProb, int OptionID)
913 {
914 PCOIN pCoin = (PCOIN)hProb;
915
916 return coinGetIntOptionMaxValue(pCoin->pOption, OptionID);
917 }
918
919
920
921 SOLVAPI double SOLVCALL CoinGetRealOptionDefaultValue(HPROB hProb, int OptionID)
922 {
923 PCOIN pCoin = (PCOIN)hProb;
924
925 return coinGetRealOptionDefaultValue(pCoin->pOption, OptionID);
926 }
927
928
929 SOLVAPI double SOLVCALL CoinGetRealOptionMinValue(HPROB hProb, int OptionID)
930 {
931 PCOIN pCoin = (PCOIN)hProb;
932
933 return coinGetRealOptionMinValue(pCoin->pOption, OptionID);
934 }
935
936
937 SOLVAPI double SOLVCALL CoinGetRealOptionMaxValue(HPROB hProb, int OptionID)
938 {
939 PCOIN pCoin = (PCOIN)hProb;
940
941 return coinGetRealOptionMaxValue(pCoin->pOption, OptionID);
942 }
943
944
945
946
947 SOLVAPI const char* SOLVCALL CoinGetOptionName(HPROB hProb, int OptionID)
948 {
949 PCOIN pCoin = (PCOIN)hProb;
950
951 return coinGetOptionName(pCoin->pOption, OptionID);
952 }
953
954
955 SOLVAPI int SOLVCALL CoinGetOptionNameBuf(HPROB hProb, int OptionID, char* OptionName, int buflen)
956 {
957 PCOIN pCoin = (PCOIN)hProb;
958
959 return coinGetOptionNameBuf(pCoin->pOption, OptionID, OptionName, buflen);
960 }
961
962
963 SOLVAPI const char* SOLVCALL CoinGetOptionShortName(HPROB hProb, int OptionID)
964 {
965 PCOIN pCoin = (PCOIN)hProb;
966
967 return coinGetOptionShortName(pCoin->pOption, OptionID);
968 }
969
970
971 SOLVAPI int SOLVCALL CoinGetOptionShortNameBuf(HPROB hProb, int OptionID, char* ShortName, int buflen)
972 {
973 PCOIN pCoin = (PCOIN)hProb;
974
975 return coinGetOptionShortNameBuf(pCoin->pOption, OptionID, ShortName, buflen);
976 }
977
978
979
980
981 SOLVAPI int SOLVCALL CoinGetOptionChanged(HPROB hProb, int OptionID)
982 {
983 PCOIN pCoin = (PCOIN)hProb;
984
985 return coinGetOptionChanged(pCoin->pOption, OptionID);
986 }
987
988
989 SOLVAPI int SOLVCALL CoinGetIntOption(HPROB hProb, int OptionID)
990 {
991 PCOIN pCoin = (PCOIN)hProb;
992
993 return coinGetIntOption(pCoin->pOption, OptionID);
994 }
995
996
997
998 SOLVAPI int SOLVCALL CoinSetIntOption(HPROB hProb, int OptionID, int IntValue)
999 {
1000 PCOIN pCoin = (PCOIN)hProb;
1001
1002 return coinSetIntOption(pCoin->pOption, OptionID, IntValue);
1003 }
1004
1005
1006
1007 SOLVAPI double SOLVCALL CoinGetRealOption(HPROB hProb, int OptionID)
1008 {
1009 PCOIN pCoin = (PCOIN)hProb;
1010
1011 return coinGetRealOption(pCoin->pOption, OptionID);
1012 }
1013
1014
1015
1016 SOLVAPI int SOLVCALL CoinSetRealOption(HPROB hProb, int OptionID, double RealValue)
1017 {
1018 PCOIN pCoin = (PCOIN)hProb;
1019
1020 return coinSetRealOption(pCoin->pOption, OptionID, RealValue);
1021 }
1022
1023
1024 SOLVAPI const char* SOLVCALL CoinGetStringOption(HPROB hProb, int OptionID)
1025 {
1026 return "";
1027 }
1028
1029
1030 SOLVAPI int SOLVCALL CoinGetStringOptionBuf(HPROB hProb, int OptionID, char* StringValue, int buflen)
1031 {
1032 return SOLV_CALL_FAILED;
1033 }
1034
1035
1036 SOLVAPI int SOLVCALL CoinSetStringOption(HPROB hProb, int OptionID, const char* StringValue)
1037 {
1038 return SOLV_CALL_FAILED;
1039 }
1040
1041
1042
1043 /************************************************************************/
1044 /* DLL Handling */
1045 /************************************************************************/
1046
1047
1048 #if defined(_MSC_VER)
1049 #define WIN32_LEAN_AND_MEAN
1050 #include <windows.h>
1051
1052
1053 static HINSTANCE g_hInstance;
1054
1055
1056 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
1057 {
1058 switch (dwReason) {
1059
1060 case DLL_PROCESS_ATTACH:
1061 g_hInstance = hInstance;
1062 break;
1063
1064 case DLL_PROCESS_DETACH:
1065 break;
1066 }
1067 return 1;
1068 }
1069 #endif
1070