1 | /* $Id: Cbc_C_Interface.h 2453 2018-12-21 20:19:20Z unxusr $ */ |
---|
2 | /* |
---|
3 | Copyright (C) 2004 International Business Machines Corporation and others. |
---|
4 | All Rights Reserved. |
---|
5 | |
---|
6 | This code is licensed under the terms of the Eclipse Public License (EPL). |
---|
7 | */ |
---|
8 | #ifndef CbcModelC_H |
---|
9 | #define CbcModelC_H |
---|
10 | |
---|
11 | /* include all defines and ugly stuff */ |
---|
12 | #include "Coin_C_defines.h" |
---|
13 | #include <stddef.h> |
---|
14 | |
---|
15 | /* |
---|
16 | * Original verison contributed by Bob Entriken, |
---|
17 | * significantly updated by Miles Lubin. |
---|
18 | */ |
---|
19 | |
---|
20 | |
---|
21 | #ifdef __cplusplus |
---|
22 | extern "C" { |
---|
23 | #endif |
---|
24 | |
---|
25 | /**@name Constructors and destructor |
---|
26 | This is a "C" interface to Cbc. |
---|
27 | The user does not need to know structure of Cbc_Model. |
---|
28 | */ |
---|
29 | /*@{*/ |
---|
30 | |
---|
31 | /** Default Cbc_Model constructor */ |
---|
32 | COINLIBAPI Cbc_Model * COINLINKAGE |
---|
33 | Cbc_newModel(void) |
---|
34 | ; |
---|
35 | /** Cbc_Model Destructor */ |
---|
36 | COINLIBAPI void COINLINKAGE |
---|
37 | Cbc_deleteModel(Cbc_Model * model) |
---|
38 | ; |
---|
39 | /** Current version of Cbc */ |
---|
40 | COINLIBAPI const char* COINLINKAGE Cbc_getVersion(void) |
---|
41 | ; |
---|
42 | /*@}*/ |
---|
43 | |
---|
44 | /**@name Getting and setting model data |
---|
45 | Note that problem access and modification methods, |
---|
46 | such as getColLower and setColLower, |
---|
47 | are *not valid* after calling Cbc_solve(). |
---|
48 | Therefore it is not recommended to reuse a Cbc_Model |
---|
49 | object for multiple solves. A workaround is to call Cbc_clone() |
---|
50 | before solving. |
---|
51 | * */ |
---|
52 | /*@{*/ |
---|
53 | /** Loads a problem (the constraints on the |
---|
54 | rows are given by lower and upper bounds). If a pointer is NULL then the |
---|
55 | following values are the default: |
---|
56 | <ul> |
---|
57 | <li> <code>colub</code>: all columns have upper bound infinity |
---|
58 | <li> <code>collb</code>: all columns have lower bound 0 |
---|
59 | <li> <code>rowub</code>: all rows have upper bound infinity |
---|
60 | <li> <code>rowlb</code>: all rows have lower bound -infinity |
---|
61 | <li> <code>obj</code>: all variables have 0 objective coefficient |
---|
62 | </ul> |
---|
63 | |
---|
64 | The constraint matrix is |
---|
65 | given in standard compressed sparse column (without gaps). |
---|
66 | <ul> |
---|
67 | <li> <code>start[i]</code> stores the starting index of the ith column |
---|
68 | <li> <code>index[k]</code> stores the row index of the kth nonzero element |
---|
69 | <li> <code>value[k]</code> stores the coefficient of the kth nonzero element |
---|
70 | </ul> |
---|
71 | */ |
---|
72 | COINLIBAPI void COINLINKAGE |
---|
73 | Cbc_loadProblem (Cbc_Model * model, const int numcols, const int numrows, |
---|
74 | const CoinBigIndex * start, const int* index, |
---|
75 | const double* value, |
---|
76 | const double* collb, const double* colub, |
---|
77 | const double* obj, |
---|
78 | const double* rowlb, const double* rowub) |
---|
79 | ; |
---|
80 | /** Read an mps file from the given filename */ |
---|
81 | COINLIBAPI int COINLINKAGE |
---|
82 | Cbc_readMps(Cbc_Model * model, const char *filename) |
---|
83 | ; |
---|
84 | /** Read an lp file from the given filename */ |
---|
85 | COINLIBAPI int COINLINKAGE |
---|
86 | Cbc_readLp(Cbc_Model * model, const char *filename) |
---|
87 | ; |
---|
88 | /** Write an mps file from the given filename */ |
---|
89 | COINLIBAPI void COINLINKAGE |
---|
90 | Cbc_writeMps(Cbc_Model * model, const char *filename) |
---|
91 | ; |
---|
92 | /** Write an lp file from the given filename */ |
---|
93 | COINLIBAPI void COINLINKAGE |
---|
94 | Cbc_writeLp(Cbc_Model * model, const char *filename) |
---|
95 | ; |
---|
96 | /** Provide an initial feasible solution to accelerate branch-and-bound |
---|
97 | Note that feasibility of the solution is *not* verified. |
---|
98 | */ |
---|
99 | COINLIBAPI void COINLINKAGE |
---|
100 | Cbc_setInitialSolution(Cbc_Model *model, const double * sol) |
---|
101 | ; |
---|
102 | /** Fills in array with problem name */ |
---|
103 | COINLIBAPI void COINLINKAGE |
---|
104 | Cbc_problemName(Cbc_Model * model, int maxNumberCharacters, char * array) |
---|
105 | ; |
---|
106 | /** Sets problem name. |
---|
107 | |
---|
108 | \p array must be a null-terminated string. |
---|
109 | */ |
---|
110 | COINLIBAPI int COINLINKAGE |
---|
111 | Cbc_setProblemName(Cbc_Model * model, const char * array) |
---|
112 | ; |
---|
113 | |
---|
114 | /** Number of nonzero elements in constraint matrix */ |
---|
115 | COINLIBAPI int COINLINKAGE |
---|
116 | Cbc_getNumElements(Cbc_Model * model) |
---|
117 | ; |
---|
118 | /** "Column start" vector of constraint matrix. Same format as Cbc_loadProblem() */ |
---|
119 | COINLIBAPI const CoinBigIndex * COINLINKAGE |
---|
120 | Cbc_getVectorStarts(Cbc_Model * model) |
---|
121 | ; |
---|
122 | /** "Row index" vector of constraint matrix */ |
---|
123 | COINLIBAPI const int * COINLINKAGE |
---|
124 | Cbc_getIndices(Cbc_Model * model) |
---|
125 | ; |
---|
126 | /** Coefficient vector of constraint matrix */ |
---|
127 | COINLIBAPI const double * COINLINKAGE |
---|
128 | Cbc_getElements(Cbc_Model * model) |
---|
129 | ; |
---|
130 | |
---|
131 | /** Maximum lenght of a row or column name */ |
---|
132 | COINLIBAPI size_t COINLINKAGE |
---|
133 | Cbc_maxNameLength(Cbc_Model * model) |
---|
134 | ; |
---|
135 | /** Fill in first maxLength bytes of name array with a row name */ |
---|
136 | COINLIBAPI void COINLINKAGE |
---|
137 | Cbc_getRowName(Cbc_Model * model, int iRow, char * name, size_t maxLength) |
---|
138 | ; |
---|
139 | /** Fill in first maxLength bytes of name array with a column name */ |
---|
140 | COINLIBAPI void COINLINKAGE |
---|
141 | Cbc_getColName(Cbc_Model * model, int iColumn, char * name, size_t maxLength) |
---|
142 | ; |
---|
143 | /** Set the name of a column */ |
---|
144 | COINLIBAPI void COINLINKAGE |
---|
145 | Cbc_setColName(Cbc_Model * model, int iColumn, const char * name) |
---|
146 | ; |
---|
147 | /** Set the name of a row */ |
---|
148 | COINLIBAPI void COINLINKAGE |
---|
149 | Cbc_setRowName(Cbc_Model * model, int iRow, const char * name) |
---|
150 | ; |
---|
151 | /** Number of constraints in the model */ |
---|
152 | COINLIBAPI int COINLINKAGE |
---|
153 | Cbc_getNumRows(Cbc_Model * model) |
---|
154 | ; |
---|
155 | /** Number of non-zero entries in a row */ |
---|
156 | COINLIBAPI int COINLINKAGE |
---|
157 | Cbc_getRowNz(Cbc_Model * model, int row) |
---|
158 | ; |
---|
159 | /** Indices of variables that appear on this row */ |
---|
160 | COINLIBAPI const int * COINLINKAGE |
---|
161 | Cbc_getRowIndices(Cbc_Model * model, int row) |
---|
162 | ; |
---|
163 | /** Coefficients of variables that appear on this row */ |
---|
164 | COINLIBAPI const double * COINLINKAGE |
---|
165 | Cbc_getRowCoeffs(Cbc_Model * model, int row) |
---|
166 | ; |
---|
167 | /** Number of non-zero entries in a column */ |
---|
168 | COINLIBAPI int COINLINKAGE |
---|
169 | Cbc_getColNz(Cbc_Model * model, int col) |
---|
170 | ; |
---|
171 | /** Indices of rows that a column appears */ |
---|
172 | COINLIBAPI const int * COINLINKAGE |
---|
173 | Cbc_getColIndices(Cbc_Model * model, int col) |
---|
174 | ; |
---|
175 | /** Coefficients that a column appear in rows */ |
---|
176 | COINLIBAPI const double * COINLINKAGE |
---|
177 | Cbc_getColCoeffs(Cbc_Model * model, int col) |
---|
178 | ; |
---|
179 | /** Right hand side of a row */ |
---|
180 | COINLIBAPI double COINLINKAGE |
---|
181 | Cbc_getRowRHS(Cbc_Model * model, int row) |
---|
182 | ; |
---|
183 | /** Sense a row */ |
---|
184 | COINLIBAPI char COINLINKAGE |
---|
185 | Cbc_getRowSense(Cbc_Model * model, int row) |
---|
186 | ; |
---|
187 | /** Number of variables in the model */ |
---|
188 | COINLIBAPI int COINLINKAGE |
---|
189 | Cbc_getNumCols(Cbc_Model * model) |
---|
190 | ; |
---|
191 | /** Number of integer variables in the model */ |
---|
192 | COINLIBAPI int COINLINKAGE |
---|
193 | Cbc_getNumIntegers(Cbc_Model * model) |
---|
194 | ; |
---|
195 | /** Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore) */ |
---|
196 | COINLIBAPI void COINLINKAGE |
---|
197 | Cbc_setObjSense(Cbc_Model * model, double sense) |
---|
198 | ; |
---|
199 | /** Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore) */ |
---|
200 | COINLIBAPI double COINLINKAGE |
---|
201 | Cbc_getObjSense(Cbc_Model * model) |
---|
202 | ; |
---|
203 | /** Constraint lower bounds */ |
---|
204 | COINLIBAPI const double* COINLINKAGE |
---|
205 | Cbc_getRowLower(Cbc_Model * model) |
---|
206 | ; |
---|
207 | /** Set the lower bound of a single constraint */ |
---|
208 | COINLIBAPI void COINLINKAGE |
---|
209 | Cbc_setRowLower(Cbc_Model * model, int index, double value) |
---|
210 | ; |
---|
211 | /** Constraint upper bounds */ |
---|
212 | COINLIBAPI const double* COINLINKAGE |
---|
213 | Cbc_getRowUpper(Cbc_Model * model) |
---|
214 | ; |
---|
215 | /** Set the upper bound of a single constraint */ |
---|
216 | COINLIBAPI void COINLINKAGE |
---|
217 | Cbc_setRowUpper(Cbc_Model * model, int index, double value) |
---|
218 | ; |
---|
219 | /** Objective vector */ |
---|
220 | COINLIBAPI const double * COINLINKAGE |
---|
221 | Cbc_getObjCoefficients(Cbc_Model * model) |
---|
222 | ; |
---|
223 | /** Set the objective coefficient of a single variable */ |
---|
224 | COINLIBAPI void COINLINKAGE |
---|
225 | Cbc_setObjCoeff(Cbc_Model * model, int index, double value) |
---|
226 | ; |
---|
227 | /** Variable lower bounds */ |
---|
228 | COINLIBAPI const double * COINLINKAGE |
---|
229 | Cbc_getColLower(Cbc_Model * model) |
---|
230 | ; |
---|
231 | /** Set the lower bound of a single variable */ |
---|
232 | COINLIBAPI void COINLINKAGE |
---|
233 | Cbc_setColLower(Cbc_Model * model, int index, double value) |
---|
234 | ; |
---|
235 | /** Variable upper bounds */ |
---|
236 | COINLIBAPI const double * COINLINKAGE |
---|
237 | Cbc_getColUpper(Cbc_Model * model) |
---|
238 | ; |
---|
239 | /** Set the upper bound of a single variable */ |
---|
240 | COINLIBAPI void COINLINKAGE |
---|
241 | Cbc_setColUpper(Cbc_Model * model, int index, double value) |
---|
242 | ; |
---|
243 | /** Determine whether the ith variable is integer restricted */ |
---|
244 | COINLIBAPI int COINLINKAGE |
---|
245 | Cbc_isInteger(Cbc_Model * model, int i) |
---|
246 | ; |
---|
247 | /** Set this variable to be continuous */ |
---|
248 | COINLIBAPI void COINLINKAGE |
---|
249 | Cbc_setContinuous(Cbc_Model * model, int iColumn) |
---|
250 | ; |
---|
251 | /** Set this variable to be integer */ |
---|
252 | COINLIBAPI void COINLINKAGE |
---|
253 | Cbc_setInteger(Cbc_Model * model, int iColumn) |
---|
254 | ; |
---|
255 | /** Adds a new column */ |
---|
256 | COINLIBAPI void COINLINKAGE |
---|
257 | Cbc_addCol( Cbc_Model *model, const char *name, double lb, |
---|
258 | double ub, double obj, char isInteger, |
---|
259 | int nz, int *rows, double *coefs ) |
---|
260 | ; |
---|
261 | /** Adds a new row */ |
---|
262 | COINLIBAPI void COINLINKAGE |
---|
263 | Cbc_addRow( Cbc_Model *model, const char *name, int nz, |
---|
264 | const int *cols, const double *coefs, char sense, double rhs ) |
---|
265 | ; |
---|
266 | /** Add SOS constraints to the model using row-order matrix */ |
---|
267 | COINLIBAPI void COINLINKAGE |
---|
268 | Cbc_addSOS(Cbc_Model * model, int numRows, const int * rowStarts, |
---|
269 | const int * colIndices, const double * weights, const int type) |
---|
270 | ; |
---|
271 | /** Print the model */ |
---|
272 | COINLIBAPI void COINLINKAGE |
---|
273 | Cbc_printModel(Cbc_Model * model, const char * argPrefix) |
---|
274 | ; |
---|
275 | /** Return a copy of this model */ |
---|
276 | COINLIBAPI Cbc_Model * COINLINKAGE |
---|
277 | Cbc_clone(Cbc_Model * model) |
---|
278 | ; |
---|
279 | /*@}*/ |
---|
280 | /**@name Solver parameters */ |
---|
281 | /*@{*/ |
---|
282 | /** Set parameter "name" to value "value". Note that this |
---|
283 | * translates directly to using "-name value" as a |
---|
284 | * command-line argument to Cbc.*/ |
---|
285 | COINLIBAPI void COINLINKAGE |
---|
286 | Cbc_setParameter(Cbc_Model * model, const char * name, const char * value) |
---|
287 | ; |
---|
288 | |
---|
289 | |
---|
290 | /*@}*/ |
---|
291 | /**@name Message handling. Call backs are handled by ONE function */ |
---|
292 | /*@{*/ |
---|
293 | /** Pass in Callback function. |
---|
294 | Message numbers up to 1000000 are Clp, Coin ones have 1000000 added */ |
---|
295 | COINLIBAPI void COINLINKAGE |
---|
296 | Cbc_registerCallBack(Cbc_Model * model, |
---|
297 | cbc_callback userCallBack) |
---|
298 | ; |
---|
299 | /** Unset Callback function */ |
---|
300 | COINLIBAPI void COINLINKAGE |
---|
301 | Cbc_clearCallBack(Cbc_Model * model) |
---|
302 | ; |
---|
303 | |
---|
304 | /*@}*/ |
---|
305 | |
---|
306 | |
---|
307 | /**@name Solving the model */ |
---|
308 | /*@{*/ |
---|
309 | /* Solve the model with Cbc (using CbcMain1). |
---|
310 | */ |
---|
311 | COINLIBAPI int COINLINKAGE |
---|
312 | Cbc_solve(Cbc_Model * model) |
---|
313 | ; |
---|
314 | /*@}*/ |
---|
315 | |
---|
316 | |
---|
317 | /**@name Accessing the solution and solution status */ |
---|
318 | /*@{*/ |
---|
319 | |
---|
320 | /** Sum of primal infeasibilities */ |
---|
321 | COINLIBAPI double COINLINKAGE |
---|
322 | Cbc_sumPrimalInfeasibilities(Cbc_Model * model) |
---|
323 | ; |
---|
324 | /** Number of primal infeasibilities */ |
---|
325 | COINLIBAPI int COINLINKAGE |
---|
326 | Cbc_numberPrimalInfeasibilities(Cbc_Model * model) |
---|
327 | ; |
---|
328 | |
---|
329 | /** Just check solution (for external use) - sets sum of |
---|
330 | infeasibilities etc */ |
---|
331 | COINLIBAPI void COINLINKAGE |
---|
332 | Cbc_checkSolution(Cbc_Model * model) |
---|
333 | ; |
---|
334 | |
---|
335 | /** Number of iterations */ |
---|
336 | COINLIBAPI int COINLINKAGE |
---|
337 | Cbc_getIterationCount(Cbc_Model * model) |
---|
338 | ; |
---|
339 | /** Are there a numerical difficulties? */ |
---|
340 | COINLIBAPI int COINLINKAGE |
---|
341 | Cbc_isAbandoned(Cbc_Model * model) |
---|
342 | ; |
---|
343 | /** Is optimality proven? */ |
---|
344 | COINLIBAPI int COINLINKAGE |
---|
345 | Cbc_isProvenOptimal(Cbc_Model * model) |
---|
346 | ; |
---|
347 | /** Is infeasiblity proven (or none better than cutoff)? */ |
---|
348 | COINLIBAPI int COINLINKAGE |
---|
349 | Cbc_isProvenInfeasible(Cbc_Model * model) |
---|
350 | ; |
---|
351 | /** Was continuous solution unbounded? */ |
---|
352 | COINLIBAPI int COINLINKAGE |
---|
353 | Cbc_isContinuousUnbounded(Cbc_Model * model) |
---|
354 | ; |
---|
355 | /** Node limit reached? */ |
---|
356 | COINLIBAPI int COINLINKAGE |
---|
357 | Cbc_isNodeLimitReached(Cbc_Model * model) |
---|
358 | ; |
---|
359 | /** Time limit reached? */ |
---|
360 | COINLIBAPI int COINLINKAGE |
---|
361 | Cbc_isSecondsLimitReached(Cbc_Model * model) |
---|
362 | ; |
---|
363 | /** Solution limit reached? */ |
---|
364 | COINLIBAPI int COINLINKAGE |
---|
365 | Cbc_isSolutionLimitReached(Cbc_Model * model) |
---|
366 | ; |
---|
367 | /** Are there numerical difficulties (for initialSolve) ? */ |
---|
368 | COINLIBAPI int COINLINKAGE |
---|
369 | Cbc_isInitialSolveAbandoned(Cbc_Model * model) |
---|
370 | ; |
---|
371 | /** Is optimality proven (for initialSolve) ? */ |
---|
372 | COINLIBAPI int COINLINKAGE |
---|
373 | Cbc_isInitialSolveProvenOptimal(Cbc_Model * model) |
---|
374 | ; |
---|
375 | /** Is primal infeasiblity proven (for initialSolve) ? */ |
---|
376 | COINLIBAPI int COINLINKAGE |
---|
377 | Cbc_isInitialSolveProvenPrimalInfeasible(Cbc_Model * model) |
---|
378 | ; |
---|
379 | /** "row" solution |
---|
380 | * This is the vector A*x, where A is the constraint matrix |
---|
381 | * and x is the current solution. */ |
---|
382 | COINLIBAPI const double * COINLINKAGE |
---|
383 | Cbc_getRowActivity(Cbc_Model * model) |
---|
384 | ; |
---|
385 | /** Best feasible solution vector */ |
---|
386 | COINLIBAPI const double * COINLINKAGE |
---|
387 | Cbc_getColSolution(Cbc_Model * model) |
---|
388 | ; |
---|
389 | /** Objective value of best feasible solution */ |
---|
390 | COINLIBAPI double COINLINKAGE |
---|
391 | Cbc_getObjValue(Cbc_Model * model) |
---|
392 | ; |
---|
393 | /** Best known bound on the optimal objective value */ |
---|
394 | COINLIBAPI double COINLINKAGE |
---|
395 | Cbc_getBestPossibleObjValue(Cbc_Model * model) |
---|
396 | ; |
---|
397 | /** Best integer feasible solution or NULL if no integer feas sol found */ |
---|
398 | COINLIBAPI double* COINLINKAGE |
---|
399 | Cbc_bestSolution(Cbc_Model * model) |
---|
400 | ; |
---|
401 | /** Number of nodes explored in B&B tree */ |
---|
402 | COINLIBAPI int COINLINKAGE |
---|
403 | Cbc_getNodeCount(Cbc_Model * model) |
---|
404 | ; |
---|
405 | /** Print the solution */ |
---|
406 | COINLIBAPI void COINLINKAGE |
---|
407 | Cbc_printSolution(Cbc_Model * model) |
---|
408 | ; |
---|
409 | /** Final status of problem |
---|
410 | Some of these can be found out by is...... functions |
---|
411 | -1 before branchAndBound |
---|
412 | 0 finished - check isProvenOptimal or isProvenInfeasible to see if solution found |
---|
413 | (or check value of best solution) |
---|
414 | 1 stopped - on maxnodes, maxsols, maxtime |
---|
415 | 2 difficulties so run was abandoned |
---|
416 | (5 event user programmed event occurred) |
---|
417 | */ |
---|
418 | COINLIBAPI int COINLINKAGE |
---|
419 | Cbc_status(Cbc_Model * model) |
---|
420 | ; |
---|
421 | /** Secondary status of problem |
---|
422 | -1 unset (status_ will also be -1) |
---|
423 | 0 search completed with solution |
---|
424 | 1 linear relaxation not feasible (or worse than cutoff) |
---|
425 | 2 stopped on gap |
---|
426 | 3 stopped on nodes |
---|
427 | 4 stopped on time |
---|
428 | 5 stopped on user event |
---|
429 | 6 stopped on solutions |
---|
430 | 7 linear relaxation unbounded |
---|
431 | 8 stopped on iteration limit |
---|
432 | */ |
---|
433 | COINLIBAPI int COINLINKAGE |
---|
434 | Cbc_secondaryStatus(Cbc_Model * model) |
---|
435 | ; |
---|
436 | /*@}*/ |
---|
437 | #ifdef __cplusplus |
---|
438 | } |
---|
439 | #endif |
---|
440 | #endif |
---|