source: branches/devel/Cbc/src/Cbc_C_Interface.h

Last change on this file was 539, checked in by forrest, 13 years ago

for nonlinear

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.2 KB
Line 
1/* Copyright (C) 2004 International Business Machines
2   Corporation and others.  All Rights Reserved.*/
3#ifndef CbcModelC_H
4#define CbcModelC_H
5
6/* include all defines and ugly stuff */
7#include "Coin_C_defines.h"
8
9/** This is a first "C" interface to Cbc.
10    It is mostly similar to the "C" interface to Clp and
11    was contributed by Bob Entriken.
12*/
13
14#ifdef __cplusplus
15extern "C"{
16#endif
17 
18  /**@name Constructors and destructor
19     These do not have an exact analogue in C++.
20     The user does not need to know structure of Cbc_Model.
21     
22     For all functions outside this group there is an exact C++
23     analogue created by taking the first parameter out, removing the Cbc_
24     from name and applying the method to an object of type ClpSimplex.
25  */
26  /*@{*/
27
28  /** Default constructor */
29  COINLIBAPI Cbc_Model * COINLINKAGE Cbc_newModel(void);
30  /** Destructor */
31  COINLIBAPI void COINLINKAGE Cbc_deleteModel(Cbc_Model * model);
32  /*@}*/
33
34  /**@name Load model - loads some stuff and initializes others */
35  /*@{*/
36  /** Loads a problem (the constraints on the
37      rows are given by lower and upper bounds). If a pointer is NULL then the
38      following values are the default:
39      <ul>
40      <li> <code>colub</code>: all columns have upper bound infinity
41      <li> <code>collb</code>: all columns have lower bound 0
42      <li> <code>rowub</code>: all rows have upper bound infinity
43      <li> <code>rowlb</code>: all rows have lower bound -infinity
44      <li> <code>obj</code>: all variables have 0 objective coefficient
45      </ul>
46  */
47  /** Just like the other loadProblem() method except that the matrix is
48        given in a standard column major ordered format (without gaps). */
49  COINLIBAPI void COINLINKAGE Cbc_loadProblem (Cbc_Model * model,  const int numcols, const int numrows,
50                      const CoinBigIndex * start, const int* index,
51                      const double* value,
52                      const double* collb, const double* colub,   
53                      const double* obj,
54                      const double* rowlb, const double* rowub);
55  /** Read an mps file from the given filename */
56  COINLIBAPI int COINLINKAGE Cbc_readMps(Cbc_Model * model,const char *filename);
57  /** Write an mps file from the given filename */
58  COINLIBAPI void COINLINKAGE Cbc_writeMps(Cbc_Model * model,const char *filename);  /** Copy in integer informations */
59  /** Copy in integer informations */
60  COINLIBAPI void COINLINKAGE Cbc_copyInIntegerInformation(Cbc_Model * model,const char * information);
61  /** Drop integer informations */
62  COINLIBAPI void COINLINKAGE Cbc_deleteIntegerInformation(Cbc_Model * model);
63  /** Resizes rim part of model  */
64  COINLIBAPI void COINLINKAGE Cbc_resize (Cbc_Model * model, int newNumberRows, int newNumberColumns);
65  /** Deletes rows */
66  COINLIBAPI void COINLINKAGE Cbc_deleteRows(Cbc_Model * model, int number, const int * which);
67  /** Add rows */
68  COINLIBAPI void COINLINKAGE Cbc_addRows(Cbc_Model * model, int number, const double * rowLower, 
69               const double * rowUpper,
70               const int * rowStarts, const int * columns,
71               const double * elements);
72
73  /** Deletes columns */
74  COINLIBAPI void COINLINKAGE Cbc_deleteColumns(Cbc_Model * model, int number, const int * which);
75  /** Add columns */
76  COINLIBAPI void COINLINKAGE Cbc_addColumns(Cbc_Model * model, int number, const double * columnLower, 
77                  const double * columnUpper,
78                  const double * objective,
79                  const int * columnStarts, const int * rows,
80                  const double * elements);
81  /** Drops names - makes lengthnames 0 and names empty */
82  COINLIBAPI void COINLINKAGE Cbc_dropNames(Cbc_Model * model);
83  /** Copies in names */
84  COINLIBAPI void COINLINKAGE Cbc_copyNames(Cbc_Model * model, const char * const * rowNames,
85                 const char * const * columnNames);
86 
87  /*@}*/
88  /**@name gets and sets - you will find some synonyms at the end of this file */
89  /*@{*/ 
90  /** Number of rows */
91  COINLIBAPI int COINLINKAGE Cbc_numberRows(Cbc_Model * model);
92  /** Number of columns */
93  COINLIBAPI int COINLINKAGE Cbc_numberColumns(Cbc_Model * model);
94  /** Primal tolerance to use */
95  COINLIBAPI double COINLINKAGE Cbc_primalTolerance(Cbc_Model * model);
96  COINLIBAPI void COINLINKAGE Cbc_setPrimalTolerance(Cbc_Model * model,  double value) ;
97  /** Dual tolerance to use */
98  COINLIBAPI double COINLINKAGE Cbc_dualTolerance(Cbc_Model * model);
99  COINLIBAPI void COINLINKAGE Cbc_setDualTolerance(Cbc_Model * model,  double value) ;
100  /* Integer tolerance to use */
101  COINLIBAPI double COINLINKAGE Cbc_integerTolerance(Cbc_Model * model);
102  COINLIBAPI void COINLINKAGE Cbc_setIntegerTolerance(Cbc_Model * model,  double value);
103  /** Dual objective limit */
104  COINLIBAPI double COINLINKAGE Cbc_dualObjectiveLimit(Cbc_Model * model);
105  COINLIBAPI void COINLINKAGE Cbc_setDualObjectiveLimit(Cbc_Model * model, double value);
106  /** Objective offset */
107  COINLIBAPI double COINLINKAGE Cbc_objectiveOffset(Cbc_Model * model);
108  COINLIBAPI void COINLINKAGE Cbc_setObjectiveOffset(Cbc_Model * model, double value);
109  /** Fills in array with problem name  */
110  COINLIBAPI void COINLINKAGE Cbc_problemName(Cbc_Model * model, int maxNumberCharacters, char * array);
111  /** Sets problem name.  Must have NULL at end.  */
112  COINLIBAPI int COINLINKAGE
113  Cbc_setProblemName(Cbc_Model * model, int maxNumberCharacters, char * array);
114  /** Number of iterations */
115  COINLIBAPI int COINLINKAGE Cbc_numberIterations(Cbc_Model * model);
116  COINLIBAPI void COINLINKAGE Cbc_setNumberIterations(Cbc_Model * model, int numberIterations);
117  /** Maximum number of iterations (only useful in initial solve) */
118  COINLIBAPI int Cbc_maximumIterations(Cbc_Model * model);
119  COINLIBAPI void COINLINKAGE Cbc_setMaximumIterations(Cbc_Model * model, int value);
120  /** Maximum time in seconds (from when set called) */
121  COINLIBAPI double COINLINKAGE Cbc_maximumSeconds(Cbc_Model * model);
122  COINLIBAPI void COINLINKAGE Cbc_setMaximumSeconds(Cbc_Model * model, double value);
123  /** Returns true if hit maximum iterations (or time) */
124  COINLIBAPI int COINLINKAGE Cbc_hitMaximumIterations(Cbc_Model * model);
125  /** Status of problem:
126      0 - optimal
127      1 - primal infeasible
128      2 - dual infeasible
129      3 - stopped on iterations etc
130      4 - stopped due to errors
131  */
132  COINLIBAPI int COINLINKAGE Cbc_LPstatus(Cbc_Model * model);
133  /** Set problem status */
134  COINLIBAPI void COINLINKAGE Cbc_setProblemLPStatus(Cbc_Model * model, int problemStatus);
135  /** Secondary status of problem - may get extended
136      0 - none
137      1 - primal infeasible because dual limit reached
138      2 - scaled problem optimal - unscaled has primal infeasibilities
139      3 - scaled problem optimal - unscaled has dual infeasibilities
140      4 - scaled problem optimal - unscaled has both dual and primal infeasibilities
141  */
142  COINLIBAPI int COINLINKAGE Cbc_secondaryLPStatus(Cbc_Model * model);
143  COINLIBAPI void COINLINKAGE Cbc_setSecondaryLPStatus(Cbc_Model * model, int status);
144  /** Final status of BAB problem
145      Some of these can be found out by is...... functions
146      -1 before branchAndBound
147      0 finished - check isProvenOptimal or isProvenInfeasible to see if solution found
148      (or check value of best solution)
149      1 stopped - on maxnodes, maxsols, maxtime
150      2 difficulties so run was abandoned
151      (5 event user programmed event occurred)
152  */
153  COINLIBAPI int COINLINKAGE Cbc_status(Cbc_Model * model);
154  /** Set problem status */
155  COINLIBAPI void COINLINKAGE Cbc_setProblemStatus(Cbc_Model * model, int problemStatus);
156  /** Secondary status of BAB problem
157      -1 unset (status_ will also be -1)
158      0 search completed with solution
159      1 linear relaxation not feasible (or worse than cutoff)
160      2 stopped on gap
161      3 stopped on nodes
162      4 stopped on time
163      5 stopped on user event
164      6 stopped on solutions
165      7 linear relaxation unbounded
166  */
167  COINLIBAPI int COINLINKAGE Cbc_secondaryStatus(Cbc_Model * model);
168  COINLIBAPI void COINLINKAGE Cbc_setSecondaryStatus(Cbc_Model * model, int status);
169  /** Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore */
170  COINLIBAPI double COINLINKAGE Cbc_optimizationDirection(Cbc_Model * model);
171  COINLIBAPI void COINLINKAGE Cbc_setOptimizationDirection(Cbc_Model * model, double value);
172  /** Primal row solution */
173  COINLIBAPI double * COINLINKAGE Cbc_primalRowSolution(Cbc_Model * model);
174  /** Primal column solution */
175  COINLIBAPI double * COINLINKAGE Cbc_primalColumnSolution(Cbc_Model * model);
176  /** Dual row solution */
177  COINLIBAPI double * COINLINKAGE Cbc_dualRowSolution(Cbc_Model * model);
178  /** Reduced costs */
179  COINLIBAPI double * COINLINKAGE Cbc_dualColumnSolution(Cbc_Model * model);
180  /** Row lower */
181  COINLIBAPI double* COINLINKAGE Cbc_rowLower(Cbc_Model * model);
182  /** Row upper  */
183  COINLIBAPI double* COINLINKAGE Cbc_rowUpper(Cbc_Model * model);
184  /** Objective */
185  COINLIBAPI double * COINLINKAGE Cbc_objective(Cbc_Model * model);           
186  /** Column Lower */
187  COINLIBAPI double * COINLINKAGE Cbc_columnLower(Cbc_Model * model);
188  /** Column Upper */
189  COINLIBAPI double * COINLINKAGE Cbc_columnUpper(Cbc_Model * model);
190  /** Number of elements in matrix */
191  COINLIBAPI int COINLINKAGE Cbc_getNumElements(Cbc_Model * model);
192  /** Column starts in matrix */
193  COINLIBAPI const CoinBigIndex * COINLINKAGE Cbc_getVectorStarts(Cbc_Model * model); 
194  /** Row indices in matrix */
195  COINLIBAPI const int * COINLINKAGE Cbc_getIndices(Cbc_Model * model); 
196  /** Column vector lengths in matrix */
197  COINLIBAPI const int * COINLINKAGE Cbc_getVectorLengths(Cbc_Model * model); 
198  /** Element values in matrix */
199  COINLIBAPI const double * COINLINKAGE Cbc_getElements(Cbc_Model * model); 
200  /** Objective value */
201  COINLIBAPI double COINLINKAGE Cbc_objectiveValue(Cbc_Model * model);
202  /** Integer information */
203  COINLIBAPI char * COINLINKAGE Cbc_integerInformation(Cbc_Model * model);
204  /** Infeasibility/unbounded ray (NULL returned if none/wrong)
205      Up to user to use delete [] on these arrays.  */
206  COINLIBAPI double * COINLINKAGE Cbc_infeasibilityRay(Cbc_Model * model);
207  COINLIBAPI double * COINLINKAGE Cbc_unboundedRay(Cbc_Model * model);
208  /** See if status array exists (partly for OsiClp) */
209  COINLIBAPI int COINLINKAGE Cbc_statusExists(Cbc_Model * model);
210  /** Return address of status array (char[numberRows+numberColumns]) */
211  COINLIBAPI void  COINLINKAGE Cbc_getBasisStatus(Cbc_Model * model, int * cstat, int * rstat);
212  /** Copy in status vector */
213  COINLIBAPI void COINLINKAGE setBasisStatus(Cbc_Model * model, int * cstat, int * rstat);
214 
215  /** User pointer for whatever reason */
216  COINLIBAPI void COINLINKAGE Cbc_setUserPointer (Cbc_Model * model, void * pointer);
217  COINLIBAPI void * COINLINKAGE Cbc_getUserPointer (Cbc_Model * model);
218  /*@}*/
219  /**@name Message handling.  Call backs are handled by ONE function */
220  /*@{*/
221  /** Pass in Callback function.
222   Message numbers up to 1000000 are Clp, Coin ones have 1000000 added */
223  COINLIBAPI void COINLINKAGE Cbc_registerCallBack(Cbc_Model * model, 
224                                                   cbc_callback userCallBack);
225  /** Unset Callback function */
226  COINLIBAPI void COINLINKAGE Cbc_clearCallBack(Cbc_Model * model);
227  /** Amount of print out:
228      0 - none
229      1 - just final
230      2 - just factorizations
231      3 - as 2 plus a bit more
232      4 - verbose
233      above that 8,16,32 etc just for selective debug
234  */
235  COINLIBAPI void COINLINKAGE Cbc_setLogLevel(Cbc_Model * model, int value);
236  COINLIBAPI int COINLINKAGE Cbc_logLevel(Cbc_Model * model);
237  /** length of names (0 means no names0 */
238  COINLIBAPI int COINLINKAGE Cbc_lengthNames(Cbc_Model * model);
239  /** Fill in array (at least lengthNames+1 long) with a row name */
240  COINLIBAPI void COINLINKAGE Cbc_rowName(Cbc_Model * model, int iRow, char * name);
241  /** Fill in array (at least lengthNames+1 long) with a column name */
242  COINLIBAPI void COINLINKAGE Cbc_columnName(Cbc_Model * model, int iColumn, char * name);
243
244  /*@}*/
245
246
247  /**@name Functions most useful to user */
248  /*@{*/
249  /** General solve algorithm which can do presolve.
250      See  ClpSolve.hpp for options
251   */
252  COINLIBAPI int COINLINKAGE Cbc_initialSolve(Cbc_Model * model);
253  /* General solve algorithm which can do presolve.
254     See  CbcModel.hpp for options
255  */
256  COINLIBAPI int COINLINKAGE Cbc_branchAndBound(Cbc_Model * model);
257  /** Dual initial solve */
258  COINLIBAPI int COINLINKAGE Cbc_initialDualSolve(Cbc_Model * model);
259  /** Primal initial solve */
260  COINLIBAPI int COINLINKAGE Cbc_initialPrimalSolve(Cbc_Model * model);
261  /** Dual algorithm - see ClpSimplexDual.hpp for method */
262  COINLIBAPI int COINLINKAGE Cbc_dual(Cbc_Model * model, int ifValuesPass);
263  /** Primal algorithm - see ClpSimplexPrimal.hpp for method */
264  COINLIBAPI int COINLINKAGE Cbc_primal(Cbc_Model * model, int ifValuesPass);
265  /** Sets or unsets scaling, 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later) */
266  COINLIBAPI void COINLINKAGE Cbc_scaling(Cbc_Model * model, int mode);
267  /** Gets scalingFlag */
268  COINLIBAPI int COINLINKAGE Cbc_scalingFlag(Cbc_Model * model);
269  /** Crash - at present just aimed at dual, returns
270      -2 if dual preferred and crash basis created
271      -1 if dual preferred and all slack basis preferred
272       0 if basis going in was not all slack
273       1 if primal preferred and all slack basis preferred
274       2 if primal preferred and crash basis created.
275       
276       if gap between bounds <="gap" variables can be flipped
277
278       If "pivot" is
279       0 No pivoting (so will just be choice of algorithm)
280       1 Simple pivoting e.g. gub
281       2 Mini iterations
282  */
283  COINLIBAPI int COINLINKAGE Cbc_crash(Cbc_Model * model, double gap,int pivot);
284  /*@}*/
285
286
287  /**@name most useful gets and sets */
288  /*@{*/ 
289  /** If problem is primal feasible */
290  COINLIBAPI int COINLINKAGE Cbc_primalFeasible(Cbc_Model * model);
291  /** If problem is dual feasible */
292  COINLIBAPI int COINLINKAGE Cbc_dualFeasible(Cbc_Model * model);
293  /** Dual bound */
294  COINLIBAPI double COINLINKAGE Cbc_dualBound(Cbc_Model * model);
295  COINLIBAPI void COINLINKAGE Cbc_setDualBound(Cbc_Model * model, double value);
296  /** Infeasibility cost */
297  COINLIBAPI double COINLINKAGE Cbc_infeasibilityCost(Cbc_Model * model);
298  COINLIBAPI void COINLINKAGE Cbc_setInfeasibilityCost(Cbc_Model * model, double value);
299  /** Perturbation:
300      50  - switch on perturbation
301      100 - auto perturb if takes too long (1.0e-6 largest nonzero)
302      101 - we are perturbed
303      102 - don't try perturbing again
304      default is 100
305      others are for playing
306  */
307  COINLIBAPI int COINLINKAGE Cbc_perturbation(Cbc_Model * model);
308  COINLIBAPI void COINLINKAGE Cbc_setPerturbation(Cbc_Model * model, int value);
309  /** Current (or last) algorithm */
310  COINLIBAPI int COINLINKAGE Cbc_algorithm(Cbc_Model * model); 
311  /** Set algorithm */
312  COINLIBAPI void COINLINKAGE Cbc_setAlgorithm(Cbc_Model * model, int value);
313  /** Sum of dual infeasibilities */
314  COINLIBAPI double COINLINKAGE Cbc_sumDualInfeasibilities(Cbc_Model * model); 
315  /** Number of dual infeasibilities */
316  COINLIBAPI int COINLINKAGE Cbc_numberDualInfeasibilities(Cbc_Model * model); 
317  /** Sum of primal infeasibilities */
318  COINLIBAPI double COINLINKAGE Cbc_sumPrimalInfeasibilities(Cbc_Model * model); 
319  /** Number of primal infeasibilities */
320  COINLIBAPI int COINLINKAGE Cbc_numberPrimalInfeasibilities(Cbc_Model * model); 
321  /** Save model to file, returns 0 if success.  This is designed for
322      use outside algorithms so does not save iterating arrays etc.
323  It does not save any messaging information.
324  Does not save scaling values.
325  It does not know about all types of virtual functions.
326  */
327  COINLIBAPI int COINLINKAGE Cbc_saveModel(Cbc_Model * model, const char * fileName);
328  /** Restore model from file, returns 0 if success,
329      deletes current model */
330  COINLIBAPI int COINLINKAGE Cbc_restoreModel(Cbc_Model * model, const char * fileName);
331 
332  /** Just check solution (for external use) - sets sum of
333      infeasibilities etc */
334  COINLIBAPI void COINLINKAGE Cbc_checkSolution(Cbc_Model * model);
335  /*@}*/
336
337  /******************** End of most useful part **************/
338  /**@name gets and sets - some synonyms */
339  /*@{*/ 
340  /** Number of rows */
341  COINLIBAPI int COINLINKAGE Cbc_getNumRows(Cbc_Model * model);
342  /** Number of columns */
343  COINLIBAPI int COINLINKAGE Cbc_getNumCols(Cbc_Model * model);
344  /** Number of iterations */
345  COINLIBAPI int COINLINKAGE Cbc_getIterationCount(Cbc_Model * model);
346  /** Are there a numerical difficulties? */
347  COINLIBAPI int COINLINKAGE Cbc_isAbandoned(Cbc_Model * model);
348  /** Is optimality proven? */
349  COINLIBAPI int COINLINKAGE Cbc_isProvenOptimal(Cbc_Model * model);
350  /** Is primal infeasiblity proven? */
351  COINLIBAPI int COINLINKAGE Cbc_isProvenPrimalInfeasible(Cbc_Model * model);
352  /** Is dual infeasiblity proven? */
353  COINLIBAPI int COINLINKAGE Cbc_isProvenDualInfeasible(Cbc_Model * model);
354  /** Is the given primal objective limit reached? */
355  COINLIBAPI int COINLINKAGE Cbc_isPrimalObjectiveLimitReached(Cbc_Model * model) ;
356  /** Is the given dual objective limit reached? */
357  COINLIBAPI int COINLINKAGE Cbc_isDualObjectiveLimitReached(Cbc_Model * model) ;
358  /** Iteration limit reached? */
359  COINLIBAPI int COINLINKAGE Cbc_isIterationLimitReached(Cbc_Model * model);
360  /** Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore */
361  COINLIBAPI double COINLINKAGE Cbc_getObjSense(Cbc_Model * model);
362  /** Primal row solution */
363  COINLIBAPI const double * COINLINKAGE Cbc_getRowActivity(Cbc_Model * model);
364  /** Primal column solution */
365  COINLIBAPI const double * COINLINKAGE Cbc_getColSolution(Cbc_Model * model);
366  COINLIBAPI void COINLINKAGE Cbc_setColSolution(Cbc_Model * model, const double * input);
367  /** Dual row solution */
368  COINLIBAPI const double * COINLINKAGE Cbc_getRowPrice(Cbc_Model * model);
369  /** Reduced costs */
370  COINLIBAPI const double * COINLINKAGE Cbc_getReducedCost(Cbc_Model * model);
371  /** Row lower */
372  COINLIBAPI const double* COINLINKAGE Cbc_getRowLower(Cbc_Model * model);
373  /** Row upper  */
374  COINLIBAPI const double* COINLINKAGE Cbc_getRowUpper(Cbc_Model * model);
375  /** Objective */
376  COINLIBAPI const double * COINLINKAGE Cbc_getObjCoefficients(Cbc_Model * model); 
377  /** Column Lower */
378  COINLIBAPI const double * COINLINKAGE Cbc_getColLower(Cbc_Model * model);
379  /** Column Upper */
380  COINLIBAPI const double * COINLINKAGE Cbc_getColUpper(Cbc_Model * model);
381  /** Objective value */
382  COINLIBAPI double COINLINKAGE Cbc_getObjValue(Cbc_Model * model);
383  /** Print the model */
384  COINLIBAPI void COINLINKAGE Cbc_printModel(Cbc_Model * model, const char * prefix);
385  /** Determine whether the variable at location i is integer restricted */
386  COINLIBAPI int COINLINKAGE Cbc_isInteger(Cbc_Model * model, int i);
387  /** Return CPU time */
388  COINLIBAPI double COINLINKAGE Cbc_cpuTime(Cbc_Model * model);
389  /** Number of nodes explored in B&B tree */
390  COINLIBAPI int COINLINKAGE Cbc_getNodeCount(Cbc_Model * model);
391  /** Return a copy of this model */
392  COINLIBAPI Cbc_Model * COINLINKAGE Cbc_clone(Cbc_Model * model);
393  /** Set this the variable to be continuous */
394  COINLIBAPI Cbc_Model * COINLINKAGE Cbc_setContinuous(Cbc_Model * model, int iColumn);
395  /* Add an SOS constraint to the model */
396  COINLIBAPI void  COINLINKAGE Cbc_addSOS(Cbc_Model * model, int numberMembers,
397             const int * which, const double * weights, int identifier, int type);
398  /* Delete all object information */
399  COINLIBAPI void  COINLINKAGE Cbc_deleteObjects(Cbc_Model * model);
400  /* Print the solution */
401  COINLIBAPI void  COINLINKAGE Cbc_printSolution(Cbc_Model * model);
402  /*@}*/
403#ifdef __cplusplus
404          }
405#endif
406#endif
Note: See TracBrowser for help on using the repository browser.