1 | /* $Id: Cbc_C_Interface.h 2059 2014-08-23 16:31:35Z tkr $ */ |
---|
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 | /** Write an mps file from the given filename */ |
---|
85 | COINLIBAPI void COINLINKAGE |
---|
86 | Cbc_writeMps(Cbc_Model * model, const char *filename) |
---|
87 | ; |
---|
88 | /** Provide an initial feasible solution to accelerate branch-and-bound |
---|
89 | Note that feasibility of the solution is *not* verified. |
---|
90 | */ |
---|
91 | COINLIBAPI void COINLINKAGE |
---|
92 | Cbc_setInitialSolution(Cbc_Model *model, const double * sol) |
---|
93 | ; |
---|
94 | /** Fills in array with problem name */ |
---|
95 | COINLIBAPI void COINLINKAGE |
---|
96 | Cbc_problemName(Cbc_Model * model, int maxNumberCharacters, char * array) |
---|
97 | ; |
---|
98 | /** Sets problem name. |
---|
99 | |
---|
100 | \p array must be a null-terminated string. |
---|
101 | */ |
---|
102 | COINLIBAPI int COINLINKAGE |
---|
103 | Cbc_setProblemName(Cbc_Model * model, const char * array) |
---|
104 | ; |
---|
105 | |
---|
106 | /** Number of nonzero elements in constraint matrix */ |
---|
107 | COINLIBAPI int COINLINKAGE |
---|
108 | Cbc_getNumElements(Cbc_Model * model) |
---|
109 | ; |
---|
110 | /** "Column start" vector of constraint matrix. Same format as Cbc_loadProblem() */ |
---|
111 | COINLIBAPI const CoinBigIndex * COINLINKAGE |
---|
112 | Cbc_getVectorStarts(Cbc_Model * model) |
---|
113 | ; |
---|
114 | /** "Row index" vector of constraint matrix */ |
---|
115 | COINLIBAPI const int * COINLINKAGE |
---|
116 | Cbc_getIndices(Cbc_Model * model) |
---|
117 | ; |
---|
118 | /** Coefficient vector of constraint matrix */ |
---|
119 | COINLIBAPI const double * COINLINKAGE |
---|
120 | Cbc_getElements(Cbc_Model * model) |
---|
121 | ; |
---|
122 | |
---|
123 | /** Maximum lenght of a row or column name */ |
---|
124 | COINLIBAPI size_t COINLINKAGE |
---|
125 | Cbc_maxNameLength(Cbc_Model * model) |
---|
126 | ; |
---|
127 | /** Fill in first maxLength bytes of name array with a row name */ |
---|
128 | COINLIBAPI void COINLINKAGE |
---|
129 | Cbc_getRowName(Cbc_Model * model, int iRow, char * name, size_t maxLength) |
---|
130 | ; |
---|
131 | /** Fill in first maxLength bytes of name array with a column name */ |
---|
132 | COINLIBAPI void COINLINKAGE |
---|
133 | Cbc_getColName(Cbc_Model * model, int iColumn, char * name, size_t maxLength) |
---|
134 | ; |
---|
135 | /** Set the name of a column */ |
---|
136 | COINLIBAPI void COINLINKAGE |
---|
137 | Cbc_setColName(Cbc_Model * model, int iColumn, const char * name) |
---|
138 | ; |
---|
139 | /** Set the name of a row */ |
---|
140 | COINLIBAPI void COINLINKAGE |
---|
141 | Cbc_setRowName(Cbc_Model * model, int iRow, const char * name) |
---|
142 | ; |
---|
143 | /** Number of constraints in the model */ |
---|
144 | COINLIBAPI int COINLINKAGE |
---|
145 | Cbc_getNumRows(Cbc_Model * model) |
---|
146 | ; |
---|
147 | /** Number of variables in the model */ |
---|
148 | COINLIBAPI int COINLINKAGE |
---|
149 | Cbc_getNumCols(Cbc_Model * model) |
---|
150 | ; |
---|
151 | /** Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore) */ |
---|
152 | COINLIBAPI void COINLINKAGE |
---|
153 | Cbc_setObjSense(Cbc_Model * model, double sense) |
---|
154 | ; |
---|
155 | /** Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore) */ |
---|
156 | COINLIBAPI double COINLINKAGE |
---|
157 | Cbc_getObjSense(Cbc_Model * model) |
---|
158 | ; |
---|
159 | /** Constraint lower bounds */ |
---|
160 | COINLIBAPI const double* COINLINKAGE |
---|
161 | Cbc_getRowLower(Cbc_Model * model) |
---|
162 | ; |
---|
163 | /** Set the lower bound of a single constraint */ |
---|
164 | COINLIBAPI void COINLINKAGE |
---|
165 | Cbc_setRowLower(Cbc_Model * model, int index, double value) |
---|
166 | ; |
---|
167 | /** Constraint upper bounds */ |
---|
168 | COINLIBAPI const double* COINLINKAGE |
---|
169 | Cbc_getRowUpper(Cbc_Model * model) |
---|
170 | ; |
---|
171 | /** Set the upper bound of a single constraint */ |
---|
172 | COINLIBAPI void COINLINKAGE |
---|
173 | Cbc_setRowUpper(Cbc_Model * model, int index, double value) |
---|
174 | ; |
---|
175 | /** Objective vector */ |
---|
176 | COINLIBAPI const double * COINLINKAGE |
---|
177 | Cbc_getObjCoefficients(Cbc_Model * model) |
---|
178 | ; |
---|
179 | /** Set the objective coefficient of a single variable */ |
---|
180 | COINLIBAPI void COINLINKAGE |
---|
181 | Cbc_setObjCoeff(Cbc_Model * model, int index, double value) |
---|
182 | ; |
---|
183 | /** Variable lower bounds */ |
---|
184 | COINLIBAPI const double * COINLINKAGE |
---|
185 | Cbc_getColLower(Cbc_Model * model) |
---|
186 | ; |
---|
187 | /** Set the lower bound of a single variable */ |
---|
188 | COINLIBAPI void COINLINKAGE |
---|
189 | Cbc_setColLower(Cbc_Model * model, int index, double value) |
---|
190 | ; |
---|
191 | /** Variable upper bounds */ |
---|
192 | COINLIBAPI const double * COINLINKAGE |
---|
193 | Cbc_getColUpper(Cbc_Model * model) |
---|
194 | ; |
---|
195 | /** Set the upper bound of a single variable */ |
---|
196 | COINLIBAPI void COINLINKAGE |
---|
197 | Cbc_setColUpper(Cbc_Model * model, int index, double value) |
---|
198 | ; |
---|
199 | /** Determine whether the ith variable is integer restricted */ |
---|
200 | COINLIBAPI int COINLINKAGE |
---|
201 | Cbc_isInteger(Cbc_Model * model, int i) |
---|
202 | ; |
---|
203 | /** Set this variable to be continuous */ |
---|
204 | COINLIBAPI void COINLINKAGE |
---|
205 | Cbc_setContinuous(Cbc_Model * model, int iColumn) |
---|
206 | ; |
---|
207 | /** Set this variable to be integer */ |
---|
208 | COINLIBAPI void COINLINKAGE |
---|
209 | Cbc_setInteger(Cbc_Model * model, int iColumn) |
---|
210 | ; |
---|
211 | /** Add SOS constraints to the model using row-order matrix |
---|
212 | * Unable to confirm that this function is working. */ |
---|
213 | COINLIBAPI void COINLINKAGE |
---|
214 | Cbc_addSOS(Cbc_Model * model, int numRows, const int * rowStarts, |
---|
215 | const int * colIndices, const double * weights, const int type) |
---|
216 | ; |
---|
217 | /** Print the model */ |
---|
218 | COINLIBAPI void COINLINKAGE |
---|
219 | Cbc_printModel(Cbc_Model * model, const char * argPrefix) |
---|
220 | ; |
---|
221 | /** Return a copy of this model */ |
---|
222 | COINLIBAPI Cbc_Model * COINLINKAGE |
---|
223 | Cbc_clone(Cbc_Model * model) |
---|
224 | ; |
---|
225 | /*@}*/ |
---|
226 | /**@name Solver parameters */ |
---|
227 | /*@{*/ |
---|
228 | /** Set parameter "name" to value "value". Note that this |
---|
229 | * translates directly to using "-name value" as a |
---|
230 | * command-line argument to Cbc.*/ |
---|
231 | COINLIBAPI void COINLINKAGE |
---|
232 | Cbc_setParameter(Cbc_Model * model, const char * name, const char * value) |
---|
233 | ; |
---|
234 | |
---|
235 | |
---|
236 | /*@}*/ |
---|
237 | /**@name Message handling. Call backs are handled by ONE function */ |
---|
238 | /*@{*/ |
---|
239 | /** Pass in Callback function. |
---|
240 | Message numbers up to 1000000 are Clp, Coin ones have 1000000 added */ |
---|
241 | COINLIBAPI void COINLINKAGE |
---|
242 | Cbc_registerCallBack(Cbc_Model * model, |
---|
243 | cbc_callback userCallBack) |
---|
244 | ; |
---|
245 | /** Unset Callback function */ |
---|
246 | COINLIBAPI void COINLINKAGE |
---|
247 | Cbc_clearCallBack(Cbc_Model * model) |
---|
248 | ; |
---|
249 | |
---|
250 | /*@}*/ |
---|
251 | |
---|
252 | |
---|
253 | /**@name Solving the model */ |
---|
254 | /*@{*/ |
---|
255 | /* Solve the model with Cbc (using CbcMain1). |
---|
256 | */ |
---|
257 | COINLIBAPI int COINLINKAGE |
---|
258 | Cbc_solve(Cbc_Model * model) |
---|
259 | ; |
---|
260 | /*@}*/ |
---|
261 | |
---|
262 | |
---|
263 | /**@name Accessing the solution and solution status */ |
---|
264 | /*@{*/ |
---|
265 | |
---|
266 | /** Sum of primal infeasibilities */ |
---|
267 | COINLIBAPI double COINLINKAGE |
---|
268 | Cbc_sumPrimalInfeasibilities(Cbc_Model * model) |
---|
269 | ; |
---|
270 | /** Number of primal infeasibilities */ |
---|
271 | COINLIBAPI int COINLINKAGE |
---|
272 | Cbc_numberPrimalInfeasibilities(Cbc_Model * model) |
---|
273 | ; |
---|
274 | |
---|
275 | /** Just check solution (for external use) - sets sum of |
---|
276 | infeasibilities etc */ |
---|
277 | COINLIBAPI void COINLINKAGE |
---|
278 | Cbc_checkSolution(Cbc_Model * model) |
---|
279 | ; |
---|
280 | |
---|
281 | /** Number of iterations */ |
---|
282 | COINLIBAPI int COINLINKAGE |
---|
283 | Cbc_getIterationCount(Cbc_Model * model) |
---|
284 | ; |
---|
285 | /** Are there a numerical difficulties? */ |
---|
286 | COINLIBAPI int COINLINKAGE |
---|
287 | Cbc_isAbandoned(Cbc_Model * model) |
---|
288 | ; |
---|
289 | /** Is optimality proven? */ |
---|
290 | COINLIBAPI int COINLINKAGE |
---|
291 | Cbc_isProvenOptimal(Cbc_Model * model) |
---|
292 | ; |
---|
293 | /** Is infeasiblity proven (or none better than cutoff)? */ |
---|
294 | COINLIBAPI int COINLINKAGE |
---|
295 | Cbc_isProvenInfeasible(Cbc_Model * model) |
---|
296 | ; |
---|
297 | /** Was continuous solution unbounded? */ |
---|
298 | COINLIBAPI int COINLINKAGE |
---|
299 | Cbc_isContinuousUnbounded(Cbc_Model * model) |
---|
300 | ; |
---|
301 | /** Node limit reached? */ |
---|
302 | COINLIBAPI int COINLINKAGE |
---|
303 | Cbc_isNodeLimitReached(Cbc_Model * model) |
---|
304 | ; |
---|
305 | /** Time limit reached? */ |
---|
306 | COINLIBAPI int COINLINKAGE |
---|
307 | Cbc_isSecondsLimitReached(Cbc_Model * model) |
---|
308 | ; |
---|
309 | /** Solution limit reached? */ |
---|
310 | COINLIBAPI int COINLINKAGE |
---|
311 | Cbc_isSolutionLimitReached(Cbc_Model * model) |
---|
312 | ; |
---|
313 | /** Are there numerical difficulties (for initialSolve) ? */ |
---|
314 | COINLIBAPI int COINLINKAGE |
---|
315 | Cbc_isInitialSolveAbandoned(Cbc_Model * model) |
---|
316 | ; |
---|
317 | /** Is optimality proven (for initialSolve) ? */ |
---|
318 | COINLIBAPI int COINLINKAGE |
---|
319 | Cbc_isInitialSolveProvenOptimal(Cbc_Model * model) |
---|
320 | ; |
---|
321 | /** Is primal infeasiblity proven (for initialSolve) ? */ |
---|
322 | COINLIBAPI int COINLINKAGE |
---|
323 | Cbc_isInitialSolveProvenPrimalInfeasible(Cbc_Model * model) |
---|
324 | ; |
---|
325 | /** "row" solution |
---|
326 | * This is the vector A*x, where A is the constraint matrix |
---|
327 | * and x is the current solution. */ |
---|
328 | COINLIBAPI const double * COINLINKAGE |
---|
329 | Cbc_getRowActivity(Cbc_Model * model) |
---|
330 | ; |
---|
331 | /** Best feasible solution vector */ |
---|
332 | COINLIBAPI const double * COINLINKAGE |
---|
333 | Cbc_getColSolution(Cbc_Model * model) |
---|
334 | ; |
---|
335 | /** Objective value of best feasible solution */ |
---|
336 | COINLIBAPI double COINLINKAGE |
---|
337 | Cbc_getObjValue(Cbc_Model * model) |
---|
338 | ; |
---|
339 | /** Best known bound on the optimal objective value */ |
---|
340 | COINLIBAPI double COINLINKAGE |
---|
341 | Cbc_getBestPossibleObjValue(Cbc_Model * model) |
---|
342 | ; |
---|
343 | /** Number of nodes explored in B&B tree */ |
---|
344 | COINLIBAPI int COINLINKAGE |
---|
345 | Cbc_getNodeCount(Cbc_Model * model) |
---|
346 | ; |
---|
347 | /** Print the solution */ |
---|
348 | COINLIBAPI void COINLINKAGE |
---|
349 | Cbc_printSolution(Cbc_Model * model) |
---|
350 | ; |
---|
351 | /** Final status of problem |
---|
352 | Some of these can be found out by is...... functions |
---|
353 | -1 before branchAndBound |
---|
354 | 0 finished - check isProvenOptimal or isProvenInfeasible to see if solution found |
---|
355 | (or check value of best solution) |
---|
356 | 1 stopped - on maxnodes, maxsols, maxtime |
---|
357 | 2 difficulties so run was abandoned |
---|
358 | (5 event user programmed event occurred) |
---|
359 | */ |
---|
360 | COINLIBAPI int COINLINKAGE |
---|
361 | Cbc_status(Cbc_Model * model) |
---|
362 | ; |
---|
363 | /** Secondary status of problem |
---|
364 | -1 unset (status_ will also be -1) |
---|
365 | 0 search completed with solution |
---|
366 | 1 linear relaxation not feasible (or worse than cutoff) |
---|
367 | 2 stopped on gap |
---|
368 | 3 stopped on nodes |
---|
369 | 4 stopped on time |
---|
370 | 5 stopped on user event |
---|
371 | 6 stopped on solutions |
---|
372 | 7 linear relaxation unbounded |
---|
373 | 8 stopped on iteration limit |
---|
374 | */ |
---|
375 | COINLIBAPI int COINLINKAGE |
---|
376 | Cbc_secondaryStatus(Cbc_Model * model) |
---|
377 | ; |
---|
378 | /*@}*/ |
---|
379 | #ifdef __cplusplus |
---|
380 | } |
---|
381 | #endif |
---|
382 | #endif |
---|