source: trunk/Cbc/src/Cbc_C_Interface.h @ 2021

Last change on this file since 2021 was 2021, checked in by mlubin, 5 years ago

Improved documentation. Tests for callbacks and row/column names. More restructuring.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.4 KB
Line 
1/* $Id: Cbc_C_Interface.h 2021 2014-03-17 20:21:18Z mlubin $ */
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/** This is a "C" interface to Cbc.
16    Original verison contributed by Bob Entriken,
17    significantly updated by Miles Lubin.
18*/
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24    /**@name Constructors and destructor
25       The user does not need to know structure of Cbc_Model.
26    */
27    /*@{*/
28
29    /** Default Cbc_Model constructor */
30    COINLIBAPI Cbc_Model * COINLINKAGE
31    Cbc_newModel(void)
32    ;
33    /** Cbc_Model Destructor */
34    COINLIBAPI void COINLINKAGE
35    Cbc_deleteModel(Cbc_Model * model)
36    ;
37    /** Current version of Cbc */
38    COINLIBAPI const char* COINLINKAGE Cbc_getVersion(void)
39    ;
40    /*@}*/
41
42    /**@name Getting and setting model data */
43    /*@{*/
44    /** Loads a problem (the constraints on the
45        rows are given by lower and upper bounds). If a pointer is NULL then the
46        following values are the default:
47        <ul>
48        <li> <code>colub</code>: all columns have upper bound infinity
49        <li> <code>collb</code>: all columns have lower bound 0
50        <li> <code>rowub</code>: all rows have upper bound infinity
51        <li> <code>rowlb</code>: all rows have lower bound -infinity
52        <li> <code>obj</code>: all variables have 0 objective coefficient
53        </ul>
54
55     The constraint matrix is
56     given in standard compressed sparse column (without gaps).
57     <ul>
58     <li> <code>start[i]</code> stores the starting index of the ith column
59     <li> <code>index[k]</code> stores the row index of the kth nonzero element
60     <li> <code>value[k]</code> stores the coefficient of the kth nonzero element
61     </ul>
62    */
63    COINLIBAPI void COINLINKAGE
64    Cbc_loadProblem (Cbc_Model * model,  const int numcols, const int numrows,
65                     const CoinBigIndex * start, const int* index,
66                     const double* value,
67                     const double* collb, const double* colub,
68                     const double* obj,
69                     const double* rowlb, const double* rowub)
70    ;
71    /** Read an mps file from the given filename */
72    COINLIBAPI int COINLINKAGE
73    Cbc_readMps(Cbc_Model * model, const char *filename)
74    ;
75    /** Write an mps file from the given filename */
76    COINLIBAPI void COINLINKAGE
77    Cbc_writeMps(Cbc_Model * model, const char *filename)
78    ;
79    /** Deletes rows */
80    COINLIBAPI void COINLINKAGE
81    Cbc_deleteRows(Cbc_Model * model, int number, const int * which)
82    ;
83    /** Add rows */
84    COINLIBAPI void COINLINKAGE
85    Cbc_addRows(Cbc_Model * model, const int number, const double * rowLower,
86                const double * rowUpper,
87                const int * rowStarts, const int * columns,
88                const double * elements)
89    ;
90
91    /** Deletes columns */
92    COINLIBAPI void COINLINKAGE
93    Cbc_deleteColumns(Cbc_Model * model, int number, const int * which)
94    ;
95    /** Add columns */
96    COINLIBAPI void COINLINKAGE
97    Cbc_addColumns(Cbc_Model * model, int number, const double * columnLower,
98                   const double * columnUpper,
99                   const double * objective,
100                   const int * columnStarts, const int * rows,
101                   const double * elements);
102    /** Drops names - makes lengthnames 0 and names empty */
103    COINLIBAPI void COINLINKAGE
104    Cbc_dropNames(Cbc_Model * model)
105    ;
106    /** Copies in names */
107    COINLIBAPI void COINLINKAGE
108    Cbc_copyNames(Cbc_Model * model, const char * const * rowNamesIn,
109                  const char * const * columnNamesIn)
110    ;
111
112    /** Fills in array with problem name  */
113    COINLIBAPI void COINLINKAGE
114    Cbc_problemName(Cbc_Model * model, int maxNumberCharacters, char * array)
115    ;
116    /** Sets problem name.
117   
118      \p array must be a null-terminated string.
119    */
120    COINLIBAPI int COINLINKAGE
121    Cbc_setProblemName(Cbc_Model * model, const char * array)
122    ;
123
124    /** Number of nonzero elements in constraint matrix */
125    COINLIBAPI int COINLINKAGE
126    Cbc_getNumElements(Cbc_Model * model)
127    ;
128    /** "Column start" vector of constraint matrix. Same format as Cbc_loadProblem() */
129    COINLIBAPI const CoinBigIndex * COINLINKAGE
130    Cbc_getVectorStarts(Cbc_Model * model)
131    ;
132    /** "Row index" vector of constraint matrix */
133    COINLIBAPI const int * COINLINKAGE
134    Cbc_getIndices(Cbc_Model * model)
135    ;
136    /** Coefficient vector of constraint matrix */
137    COINLIBAPI const double * COINLINKAGE
138    Cbc_getElements(Cbc_Model * model)
139    ;
140
141    /** Maximum lenght of a row or column name */
142    COINLIBAPI size_t COINLINKAGE
143    Cbc_maxNameLength(Cbc_Model * model)
144    ;
145    /** Fill in first maxLength bytes of name array with a row name */
146    COINLIBAPI void COINLINKAGE
147    Cbc_getRowName(Cbc_Model * model, int iRow, char * name, size_t maxLength)
148    ;
149    /** Fill in first maxLength bytes of name array with a column name */
150    COINLIBAPI void COINLINKAGE
151    Cbc_getColName(Cbc_Model * model, int iColumn, char * name, size_t maxLength)
152    ;
153    /** Set the name of a column */
154    COINLIBAPI void COINLINKAGE
155    Cbc_setColName(Cbc_Model * model, int iColumn, const char * name)
156    ;
157    /** Set the name of a row */
158    COINLIBAPI void COINLINKAGE
159    Cbc_setRowName(Cbc_Model * model, int iRow, const char * name)
160    ;
161    /** Number of constraints in the model */
162    COINLIBAPI int COINLINKAGE
163    Cbc_getNumRows(Cbc_Model * model)
164    ;
165    /** Number of variables in the model */
166    COINLIBAPI int COINLINKAGE
167    Cbc_getNumCols(Cbc_Model * model)
168    ;
169    /** Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore) */
170    COINLIBAPI void COINLINKAGE
171    Cbc_setObjSense(Cbc_Model * model, double sense)
172    ;
173    /** Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore) */
174    COINLIBAPI double COINLINKAGE
175    Cbc_getObjSense(Cbc_Model * model)
176    ;
177    /** Constraint lower bounds */
178    COINLIBAPI const double* COINLINKAGE
179    Cbc_getRowLower(Cbc_Model * model)
180    ;
181    /** Constraint upper bounds */
182    COINLIBAPI const double* COINLINKAGE
183    Cbc_getRowUpper(Cbc_Model * model)
184    ;
185    /** Objective vector */
186    COINLIBAPI const double * COINLINKAGE
187    Cbc_getObjCoefficients(Cbc_Model * model)
188    ;
189    /** Variable lower bounds */
190    COINLIBAPI const double * COINLINKAGE
191    Cbc_getColLower(Cbc_Model * model)
192    ;
193    /** Variable upper bounds */
194    COINLIBAPI const double * COINLINKAGE
195    Cbc_getColUpper(Cbc_Model * model)
196    ;
197    /** Determine whether the ith variable is integer restricted */
198    COINLIBAPI int COINLINKAGE
199    Cbc_isInteger(Cbc_Model * model, int i)
200    ;
201    /** Set this variable to be continuous */
202    COINLIBAPI Cbc_Model * COINLINKAGE
203    Cbc_setContinuous(Cbc_Model * model, int iColumn)
204    ;
205    /** Set this variable to be integer */
206    COINLIBAPI Cbc_Model * COINLINKAGE
207    Cbc_setInteger(Cbc_Model * model, int iColumn)
208    ;
209    /** Add SOS constraints to the model using dense matrix */
210    COINLIBAPI void  COINLINKAGE
211    Cbc_addSOS_Dense(Cbc_Model * model, int numObjects, const int * len,
212                     const int * const * which, const double * weights, const int type)
213    ;
214    /** Add SOS constraints to the model using row-order matrix */
215    COINLIBAPI void  COINLINKAGE
216    Cbc_addSOS_Sparse(Cbc_Model * model, const int * rowStarts,
217                      const int * rowIndices, const double * weights, const int type)
218    ;
219    /** Print the model */
220    COINLIBAPI void COINLINKAGE
221    Cbc_printModel(Cbc_Model * model, const char * argPrefix)
222    ;
223    /** Return a copy of this model */
224    COINLIBAPI Cbc_Model * COINLINKAGE
225    Cbc_clone(Cbc_Model * model)
226    ;
227    /*@}*/
228    /**@name Solver parameters */
229    /*@{*/
230    /** Set parameter "name" to value "value". Note that this
231     * translates directly to using "-name value" as a
232     * command-line argument to Cbc.*/
233    COINLIBAPI void COINLINKAGE
234    Cbc_setParameter(Cbc_Model * model, const char * name, const char * value)
235    ;
236
237   
238    /*@}*/
239    /**@name Message handling.  Call backs are handled by ONE function */
240    /*@{*/
241    /** Pass in Callback function.
242     Message numbers up to 1000000 are Clp, Coin ones have 1000000 added */
243    COINLIBAPI void COINLINKAGE
244    Cbc_registerCallBack(Cbc_Model * model,
245                         cbc_callback userCallBack)
246    ;
247    /** Unset Callback function */
248    COINLIBAPI void COINLINKAGE
249    Cbc_clearCallBack(Cbc_Model * model)
250    ;
251
252    /*@}*/
253
254
255    /**@name Solving the model */
256    /*@{*/
257    /* Solve the model with Cbc (using CbcMain1).
258    */
259    COINLIBAPI int COINLINKAGE
260    Cbc_solve(Cbc_Model * model)
261    ;
262    /*@}*/
263
264
265    /**@name Accessing the solution and solution status */
266    /*@{*/
267
268    /** Sum of primal infeasibilities */
269    COINLIBAPI double COINLINKAGE
270    Cbc_sumPrimalInfeasibilities(Cbc_Model * model)
271    ;
272    /** Number of primal infeasibilities */
273    COINLIBAPI int COINLINKAGE
274    Cbc_numberPrimalInfeasibilities(Cbc_Model * model)
275    ;
276
277    /** Just check solution (for external use) - sets sum of
278        infeasibilities etc */
279    COINLIBAPI void COINLINKAGE
280    Cbc_checkSolution(Cbc_Model * model)
281    ;
282
283    /** Number of iterations */
284    COINLIBAPI int COINLINKAGE
285    Cbc_getIterationCount(Cbc_Model * model)
286    ;
287    /** Are there a numerical difficulties? */
288    COINLIBAPI int COINLINKAGE
289    Cbc_isAbandoned(Cbc_Model * model)
290    ;
291    /** Is optimality proven? */
292    COINLIBAPI int COINLINKAGE
293    Cbc_isProvenOptimal(Cbc_Model * model)
294    ;
295    /** Is infeasiblity proven (or none better than cutoff)? */
296    COINLIBAPI int COINLINKAGE
297    Cbc_isProvenInfeasible(Cbc_Model * model)
298    ;
299    /** Was continuous solution unbounded? */
300    COINLIBAPI int COINLINKAGE
301    Cbc_isContinuousUnbounded(Cbc_Model * model)
302    ;
303    /** Node limit reached? */
304    COINLIBAPI int COINLINKAGE
305    Cbc_isNodeLimitReached(Cbc_Model * model)
306    ;
307    /** Time limit reached? */
308    COINLIBAPI int COINLINKAGE
309    Cbc_isSecondsLimitReached(Cbc_Model * model)
310    ;
311    /** Solution limit reached? */
312    COINLIBAPI int COINLINKAGE
313    Cbc_isSolutionLimitReached(Cbc_Model * model)
314    ;
315    /** Are there numerical difficulties (for initialSolve) ? */
316    COINLIBAPI int COINLINKAGE
317    Cbc_isInitialSolveAbandoned(Cbc_Model * model)
318    ;
319    /** Is optimality proven (for initialSolve) ? */
320    COINLIBAPI int COINLINKAGE
321    Cbc_isInitialSolveProvenOptimal(Cbc_Model * model)
322    ;
323    /** Is primal infeasiblity proven (for initialSolve) ? */
324    COINLIBAPI int COINLINKAGE
325    Cbc_isInitialSolveProvenPrimalInfeasible(Cbc_Model * model)
326    ;
327    /** "row" solution
328     *  This is the vector A*x, where A is the constraint matrix
329     *  and x is the current solution. */
330    COINLIBAPI const double * COINLINKAGE
331    Cbc_getRowActivity(Cbc_Model * model)
332    ;
333    /** Best feasible solution vector */
334    COINLIBAPI const double * COINLINKAGE
335    Cbc_getColSolution(Cbc_Model * model)
336    ;
337    /** Objective value of best feasible solution */
338    COINLIBAPI double COINLINKAGE
339    Cbc_getObjValue(Cbc_Model * model)
340    ;
341    /** Best known bound on the optimal objective value */
342    COINLIBAPI double COINLINKAGE
343    Cbc_getBestPossibleObjValue(Cbc_Model * model)
344    ;
345    /** Number of nodes explored in B&B tree */
346    COINLIBAPI int COINLINKAGE
347    Cbc_getNodeCount(Cbc_Model * model)
348    ;
349    /** Print the solution */
350    COINLIBAPI void  COINLINKAGE
351    Cbc_printSolution(Cbc_Model * model)
352    ;
353    /** Final status of problem
354        Some of these can be found out by is...... functions
355        -1 before branchAndBound
356        0 finished - check isProvenOptimal or isProvenInfeasible to see if solution found
357        (or check value of best solution)
358        1 stopped - on maxnodes, maxsols, maxtime
359        2 difficulties so run was abandoned
360        (5 event user programmed event occurred)
361    */
362    COINLIBAPI int COINLINKAGE
363    Cbc_status(Cbc_Model * model)
364    ;
365    /** Secondary status of problem
366        -1 unset (status_ will also be -1)
367        0 search completed with solution
368        1 linear relaxation not feasible (or worse than cutoff)
369        2 stopped on gap
370        3 stopped on nodes
371        4 stopped on time
372        5 stopped on user event
373        6 stopped on solutions
374        7 linear relaxation unbounded
375        8 stopped on iteration limit
376    */
377    COINLIBAPI int COINLINKAGE
378    Cbc_secondaryStatus(Cbc_Model * model)
379    ;
380    /*@}*/
381#ifdef __cplusplus
382}
383#endif
384#endif
Note: See TracBrowser for help on using the repository browser.