1/* $Id: Clp_C_Interface.h 1665 2011-01-04 17:55:54Z lou $ */
2/*
3 Copyright (C) 2002, 2003 International Business Machines Corporation
4 and others. All Rights Reserved.
5
6 This code is licensed under the terms of the Eclipse Public License (EPL).
7*/
8#ifndef ClpSimplexC_H
9#define ClpSimplexC_H
10
11/* include all defines and ugly stuff */
12#include "Coin_C_defines.h"
13
14/** This is a first "C" interface to Clp.
15 It has similarities to the OSL V3 interface
16 and only has most common functions
17*/
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23 /**@name Constructors and destructor
24 These do not have an exact analogue in C++.
25 The user does not need to know structure of Clp_Simplex.
26
27 For all functions outside this group there is an exact C++
28 analogue created by taking the first parameter out, removing the Clp_
29 from name and applying the method to an object of type ClpSimplex.
30 */
31 /*@{*/
32
33 /** Default constructor */
34 COINLIBAPI Clp_Simplex * COINLINKAGE Clp_newModel(void);
35 /** Destructor */
36 COINLIBAPI void COINLINKAGE Clp_deleteModel(Clp_Simplex * model);
37 /*@}*/
38
39 /**@name Load model - loads some stuff and initializes others */
40 /*@{*/
41 /** Loads a problem (the constraints on the
42 rows are given by lower and upper bounds). If a pointer is NULL then the
43 following values are the default:
44 <ul>
45 <li> <code>colub</code>: all columns have upper bound infinity
46 <li> <code>collb</code>: all columns have lower bound 0
47 <li> <code>rowub</code>: all rows have upper bound infinity
48 <li> <code>rowlb</code>: all rows have lower bound -infinity
49 <li> <code>obj</code>: all variables have 0 objective coefficient
50 </ul>
51 */
52 /** Just like the other loadProblem() method except that the matrix is
53 given in a standard column major ordered format (without gaps). */
54 COINLIBAPI void COINLINKAGE Clp_loadProblem (Clp_Simplex * model, const int numcols, const int numrows,
55 const CoinBigIndex * start, const int* index,
56 const double* value,
57 const double* collb, const double* colub,
58 const double* obj,
59 const double* rowlb, const double* rowub);
60
61 /* read quadratic part of the objective (the matrix part) */
62 COINLIBAPI void COINLINKAGE
63 Clp_loadQuadraticObjective(Clp_Simplex * model,
64 const int numberColumns,
65 const CoinBigIndex * start,
66 const int * column,
67 const double * element);
68 /** Read an mps file from the given filename */
69 COINLIBAPI int COINLINKAGE Clp_readMps(Clp_Simplex * model, const char *filename,
70 int keepNames,
71 int ignoreErrors);
72 /** Copy in integer informations */
73 COINLIBAPI void COINLINKAGE Clp_copyInIntegerInformation(Clp_Simplex * model, const char * information);
74 /** Drop integer informations */
75 COINLIBAPI void COINLINKAGE Clp_deleteIntegerInformation(Clp_Simplex * model);
76 /** Resizes rim part of model */
77 COINLIBAPI void COINLINKAGE Clp_resize (Clp_Simplex * model, int newNumberRows, int newNumberColumns);
78 /** Deletes rows */
79 COINLIBAPI void COINLINKAGE Clp_deleteRows(Clp_Simplex * model, int number, const int * which);
80 /** Add rows */
81 COINLIBAPI void COINLINKAGE Clp_addRows(Clp_Simplex * model, int number, const double * rowLower,
82 const double * rowUpper,
83 const int * rowStarts, const int * columns,
84 const double * elements);
85
86 /** Deletes columns */
87 COINLIBAPI void COINLINKAGE Clp_deleteColumns(Clp_Simplex * model, int number, const int * which);
88 /** Add columns */
89 COINLIBAPI void COINLINKAGE Clp_addColumns(Clp_Simplex * model, int number, const double * columnLower,
90 const double * columnUpper,
91 const double * objective,
92 const int * columnStarts, const int * rows,
93 const double * elements);
94 /** Change row lower bounds */
95 COINLIBAPI void COINLINKAGE Clp_chgRowLower(Clp_Simplex * model, const double * rowLower);
96 /** Change row upper bounds */
97 COINLIBAPI void COINLINKAGE Clp_chgRowUpper(Clp_Simplex * model, const double * rowUpper);
98 /** Change column lower bounds */
99 COINLIBAPI void COINLINKAGE Clp_chgColumnLower(Clp_Simplex * model, const double * columnLower);
100 /** Change column upper bounds */
101 COINLIBAPI void COINLINKAGE Clp_chgColumnUpper(Clp_Simplex * model, const double * columnUpper);
102 /** Change objective coefficients */
103 COINLIBAPI void COINLINKAGE Clp_chgObjCoefficients(Clp_Simplex * model, const double * objIn);
104 /** Drops names - makes lengthnames 0 and names empty */
105 COINLIBAPI void COINLINKAGE Clp_dropNames(Clp_Simplex * model);
106 /** Copies in names */
107 COINLIBAPI void COINLINKAGE Clp_copyNames(Clp_Simplex * model, const char * const * rowNames,
108 const char * const * columnNames);
109
110 /*@}*/
111 /**@name gets and sets - you will find some synonyms at the end of this file */
112 /*@{*/
113 /** Number of rows */
114 COINLIBAPI int COINLINKAGE Clp_numberRows(Clp_Simplex * model);
115 /** Number of columns */
116 COINLIBAPI int COINLINKAGE Clp_numberColumns(Clp_Simplex * model);
117 /** Primal tolerance to use */
118 COINLIBAPI double COINLINKAGE Clp_primalTolerance(Clp_Simplex * model);
119 COINLIBAPI void COINLINKAGE Clp_setPrimalTolerance(Clp_Simplex * model, double value) ;
120 /** Dual tolerance to use */
121 COINLIBAPI double COINLINKAGE Clp_dualTolerance(Clp_Simplex * model);
122 COINLIBAPI void COINLINKAGE Clp_setDualTolerance(Clp_Simplex * model, double value) ;
123 /** Dual objective limit */
124 COINLIBAPI double COINLINKAGE Clp_dualObjectiveLimit(Clp_Simplex * model);
125 COINLIBAPI void COINLINKAGE Clp_setDualObjectiveLimit(Clp_Simplex * model, double value);
126 /** Objective offset */
127 COINLIBAPI double COINLINKAGE Clp_objectiveOffset(Clp_Simplex * model);
128 COINLIBAPI void COINLINKAGE Clp_setObjectiveOffset(Clp_Simplex * model, double value);
129 /** Fills in array with problem name */
130 COINLIBAPI void COINLINKAGE Clp_problemName(Clp_Simplex * model, int maxNumberCharacters, char * array);
131 /* Sets problem name. Must have \0 at end. */
132 COINLIBAPI int COINLINKAGE
133 Clp_setProblemName(Clp_Simplex * model, int maxNumberCharacters, char * array);
134 /** Number of iterations */
135 COINLIBAPI int COINLINKAGE Clp_numberIterations(Clp_Simplex * model);
136 COINLIBAPI void COINLINKAGE Clp_setNumberIterations(Clp_Simplex * model, int numberIterations);
137 /** Maximum number of iterations */
138 COINLIBAPI int maximumIterations(Clp_Simplex * model);
139 COINLIBAPI void COINLINKAGE Clp_setMaximumIterations(Clp_Simplex * model, int value);
140 /** Maximum time in seconds (from when set called) */
141 COINLIBAPI double COINLINKAGE Clp_maximumSeconds(Clp_Simplex * model);
142 COINLIBAPI void COINLINKAGE Clp_setMaximumSeconds(Clp_Simplex * model, double value);
143 /** Returns true if hit maximum iterations (or time) */
144 COINLIBAPI int COINLINKAGE Clp_hitMaximumIterations(Clp_Simplex * model);
145 /** Status of problem:
146 0 - optimal
147 1 - primal infeasible
148 2 - dual infeasible
149 3 - stopped on iterations etc
150 4 - stopped due to errors
151 */
152 COINLIBAPI int COINLINKAGE Clp_status(Clp_Simplex * model);
153 /** Set problem status */
154 COINLIBAPI void COINLINKAGE Clp_setProblemStatus(Clp_Simplex * model, int problemStatus);
155 /** Secondary status of problem - may get extended
156 0 - none
157 1 - primal infeasible because dual limit reached
158 2 - scaled problem optimal - unscaled has primal infeasibilities
159 3 - scaled problem optimal - unscaled has dual infeasibilities
160 4 - scaled problem optimal - unscaled has both dual and primal infeasibilities
161 */
162 COINLIBAPI int COINLINKAGE Clp_secondaryStatus(Clp_Simplex * model);
163 COINLIBAPI void COINLINKAGE Clp_setSecondaryStatus(Clp_Simplex * model, int status);
164 /** Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore */
165 COINLIBAPI double COINLINKAGE Clp_optimizationDirection(Clp_Simplex * model);
166 COINLIBAPI void COINLINKAGE Clp_setOptimizationDirection(Clp_Simplex * model, double value);
167 /** Primal row solution */
168 COINLIBAPI double * COINLINKAGE Clp_primalRowSolution(Clp_Simplex * model);
169 /** Primal column solution */
170 COINLIBAPI double * COINLINKAGE Clp_primalColumnSolution(Clp_Simplex * model);
171 /** Dual row solution */
172 COINLIBAPI double * COINLINKAGE Clp_dualRowSolution(Clp_Simplex * model);
173 /** Reduced costs */
174 COINLIBAPI double * COINLINKAGE Clp_dualColumnSolution(Clp_Simplex * model);
175 /** Row lower */
176 COINLIBAPI double* COINLINKAGE Clp_rowLower(Clp_Simplex * model);
177 /** Row upper */
178 COINLIBAPI double* COINLINKAGE Clp_rowUpper(Clp_Simplex * model);
179 /** Objective */
180 COINLIBAPI double * COINLINKAGE Clp_objective(Clp_Simplex * model);
181 /** Column Lower */
182 COINLIBAPI double * COINLINKAGE Clp_columnLower(Clp_Simplex * model);
183 /** Column Upper */
184 COINLIBAPI double * COINLINKAGE Clp_columnUpper(Clp_Simplex * model);
185 /** Number of elements in matrix */
186 COINLIBAPI int COINLINKAGE Clp_getNumElements(Clp_Simplex * model);
187 /* Column starts in matrix */
188 COINLIBAPI const CoinBigIndex * COINLINKAGE Clp_getVectorStarts(Clp_Simplex * model);
189 /* Row indices in matrix */
190 COINLIBAPI const int * COINLINKAGE Clp_getIndices(Clp_Simplex * model);
191 /* Column vector lengths in matrix */
192 COINLIBAPI const int * COINLINKAGE Clp_getVectorLengths(Clp_Simplex * model);
193 /* Element values in matrix */
194 COINLIBAPI const double * COINLINKAGE Clp_getElements(Clp_Simplex * model);
195 /** Objective value */
196 COINLIBAPI double COINLINKAGE Clp_objectiveValue(Clp_Simplex * model);
197 /** Integer information */
198 COINLIBAPI char * COINLINKAGE Clp_integerInformation(Clp_Simplex * model);
199 /** Infeasibility/unbounded ray (NULL returned if none/wrong)
200 Up to user to use delete [] on these arrays. */
201 COINLIBAPI double * COINLINKAGE Clp_infeasibilityRay(Clp_Simplex * model);
202 COINLIBAPI double * COINLINKAGE Clp_unboundedRay(Clp_Simplex * model);
203 /** See if status array exists (partly for OsiClp) */
204 COINLIBAPI int COINLINKAGE Clp_statusExists(Clp_Simplex * model);
205 /** Return address of status array (char[numberRows+numberColumns]) */
206 COINLIBAPI unsigned char * COINLINKAGE Clp_statusArray(Clp_Simplex * model);
207 /** Copy in status vector */
208 COINLIBAPI void COINLINKAGE Clp_copyinStatus(Clp_Simplex * model, const unsigned char * statusArray);
209 /* status values are as in ClpSimplex.hpp i.e. 0 - free, 1 basic, 2 at upper,
210 3 at lower, 4 superbasic, (5 fixed) */
211 /* Get variable basis info */
212 COINLIBAPI int COINLINKAGE Clp_getColumnStatus(Clp_Simplex * model, int sequence);
213 /* Get row basis info */
214 COINLIBAPI int COINLINKAGE Clp_getRowStatus(Clp_Simplex * model, int sequence);
215 /* Set variable basis info (and value if at bound) */
216 COINLIBAPI void COINLINKAGE Clp_setColumnStatus(Clp_Simplex * model,
217 int sequence, int value);
218 /* Set row basis info (and value if at bound) */
219 COINLIBAPI void COINLINKAGE Clp_setRowStatus(Clp_Simplex * model,
220 int sequence, int value);
221
222 /** User pointer for whatever reason */
223 COINLIBAPI void COINLINKAGE Clp_setUserPointer (Clp_Simplex * model, void * pointer);
224 COINLIBAPI void * COINLINKAGE Clp_getUserPointer (Clp_Simplex * model);
225 /*@}*/
226 /**@name Message handling. Call backs are handled by ONE function */
227 /*@{*/
228 /** Pass in Callback function.
229 Message numbers up to 1000000 are Clp, Coin ones have 1000000 added */
230 COINLIBAPI void COINLINKAGE Clp_registerCallBack(Clp_Simplex * model,
231 clp_callback userCallBack);
232 /** Unset Callback function */
233 COINLIBAPI void COINLINKAGE Clp_clearCallBack(Clp_Simplex * model);
234 /** Amount of print out:
235 0 - none
236 1 - just final
237 2 - just factorizations
238 3 - as 2 plus a bit more
239 4 - verbose
240 above that 8,16,32 etc just for selective debug
241 */
242 COINLIBAPI void COINLINKAGE Clp_setLogLevel(Clp_Simplex * model, int value);
243 COINLIBAPI int COINLINKAGE Clp_logLevel(Clp_Simplex * model);
244 /** length of names (0 means no names0 */
245 COINLIBAPI int COINLINKAGE Clp_lengthNames(Clp_Simplex * model);
246 /** Fill in array (at least lengthNames+1 long) with a row name */
247 COINLIBAPI void COINLINKAGE Clp_rowName(Clp_Simplex * model, int iRow, char * name);
248 /** Fill in array (at least lengthNames+1 long) with a column name */
249 COINLIBAPI void COINLINKAGE Clp_columnName(Clp_Simplex * model, int iColumn, char * name);
250
251 /*@}*/
252
253
254 /**@name Functions most useful to user */
255 /*@{*/
256 /** General solve algorithm which can do presolve.
257 See ClpSolve.hpp for options
258 */
259 COINLIBAPI int COINLINKAGE Clp_initialSolve(Clp_Simplex * model);
260 /** Dual initial solve */
261 COINLIBAPI int COINLINKAGE Clp_initialDualSolve(Clp_Simplex * model);
262 /** Primal initial solve */
263 COINLIBAPI int COINLINKAGE Clp_initialPrimalSolve(Clp_Simplex * model);
264 /** Barrier initial solve */
265 COINLIBAPI int COINLINKAGE Clp_initialBarrierSolve(Clp_Simplex * model);
266 /** Barrier initial solve, no crossover */
267 COINLIBAPI int COINLINKAGE Clp_initialBarrierNoCrossSolve(Clp_Simplex * model);
268 /** Dual algorithm - see ClpSimplexDual.hpp for method */
269 COINLIBAPI int COINLINKAGE Clp_dual(Clp_Simplex * model, int ifValuesPass);
270 /** Primal algorithm - see ClpSimplexPrimal.hpp for method */
271 COINLIBAPI int COINLINKAGE Clp_primal(Clp_Simplex * model, int ifValuesPass);
272#ifndef SLIM_CLP
273 /** Solve the problem with the idiot code */
274 COINLIBAPI void COINLINKAGE Clp_idiot(Clp_Simplex * model, int tryhard);
275#endif
276 /** Sets or unsets scaling, 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later) */
277 COINLIBAPI void COINLINKAGE Clp_scaling(Clp_Simplex * model, int mode);
278 /** Gets scalingFlag */
279 COINLIBAPI int COINLINKAGE Clp_scalingFlag(Clp_Simplex * model);
280 /** Crash - at present just aimed at dual, returns
281 -2 if dual preferred and crash basis created
282 -1 if dual preferred and all slack basis preferred
283 0 if basis going in was not all slack
284 1 if primal preferred and all slack basis preferred
285 2 if primal preferred and crash basis created.
286
287 if gap between bounds <="gap" variables can be flipped
288
289 If "pivot" is
290 0 No pivoting (so will just be choice of algorithm)
291 1 Simple pivoting e.g. gub
292 2 Mini iterations
293 */
294 COINLIBAPI int COINLINKAGE Clp_crash(Clp_Simplex * model, double gap, int pivot);
295 /*@}*/
296
297
298 /**@name most useful gets and sets */
299 /*@{*/
300 /** If problem is primal feasible */
301 COINLIBAPI int COINLINKAGE Clp_primalFeasible(Clp_Simplex * model);
302 /** If problem is dual feasible */
303 COINLIBAPI int COINLINKAGE Clp_dualFeasible(Clp_Simplex * model);
304 /** Dual bound */
305 COINLIBAPI double COINLINKAGE Clp_dualBound(Clp_Simplex * model);
306 COINLIBAPI void COINLINKAGE Clp_setDualBound(Clp_Simplex * model, double value);
307 /** Infeasibility cost */
308 COINLIBAPI double COINLINKAGE Clp_infeasibilityCost(Clp_Simplex * model);
309 COINLIBAPI void COINLINKAGE Clp_setInfeasibilityCost(Clp_Simplex * model, double value);
310 /** Perturbation:
311 50 - switch on perturbation
312 100 - auto perturb if takes too long (1.0e-6 largest nonzero)
313 101 - we are perturbed
314 102 - don't try perturbing again
315 default is 100
316 others are for playing
317 */
318 COINLIBAPI int COINLINKAGE Clp_perturbation(Clp_Simplex * model);
319 COINLIBAPI void COINLINKAGE Clp_setPerturbation(Clp_Simplex * model, int value);
320 /** Current (or last) algorithm */
321 COINLIBAPI int COINLINKAGE Clp_algorithm(Clp_Simplex * model);
322 /** Set algorithm */
323 COINLIBAPI void COINLINKAGE Clp_setAlgorithm(Clp_Simplex * model, int value);
324 /** Sum of dual infeasibilities */
325 COINLIBAPI double COINLINKAGE Clp_sumDualInfeasibilities(Clp_Simplex * model);
326 /** Number of dual infeasibilities */
327 COINLIBAPI int COINLINKAGE Clp_numberDualInfeasibilities(Clp_Simplex * model);
328 /** Sum of primal infeasibilities */
329 COINLIBAPI double COINLINKAGE Clp_sumPrimalInfeasibilities(Clp_Simplex * model);
330 /** Number of primal infeasibilities */
331 COINLIBAPI int COINLINKAGE Clp_numberPrimalInfeasibilities(Clp_Simplex * model);
332 /** Save model to file, returns 0 if success. This is designed for
333 use outside algorithms so does not save iterating arrays etc.
334 It does not save any messaging information.
335 Does not save scaling values.
336 It does not know about all types of virtual functions.
337 */
338 COINLIBAPI int COINLINKAGE Clp_saveModel(Clp_Simplex * model, const char * fileName);
339 /** Restore model from file, returns 0 if success,
340 deletes current model */
341 COINLIBAPI int COINLINKAGE Clp_restoreModel(Clp_Simplex * model, const char * fileName);
342
343 /** Just check solution (for external use) - sets sum of
344 infeasibilities etc */
345 COINLIBAPI void COINLINKAGE Clp_checkSolution(Clp_Simplex * model);
346 /*@}*/
347
348 /******************** End of most useful part **************/
349 /**@name gets and sets - some synonyms */
350 /*@{*/
351 /** Number of rows */
352 COINLIBAPI int COINLINKAGE Clp_getNumRows(Clp_Simplex * model);
353 /** Number of columns */
354 COINLIBAPI int COINLINKAGE Clp_getNumCols(Clp_Simplex * model);
355 /** Number of iterations */
356 COINLIBAPI int COINLINKAGE Clp_getIterationCount(Clp_Simplex * model);
357 /** Are there a numerical difficulties? */
358 COINLIBAPI int COINLINKAGE Clp_isAbandoned(Clp_Simplex * model);
359 /** Is optimality proven? */
360 COINLIBAPI int COINLINKAGE Clp_isProvenOptimal(Clp_Simplex * model);
361 /** Is primal infeasiblity proven? */
362 COINLIBAPI int COINLINKAGE Clp_isProvenPrimalInfeasible(Clp_Simplex * model);
363 /** Is dual infeasiblity proven? */
364 COINLIBAPI int COINLINKAGE Clp_isProvenDualInfeasible(Clp_Simplex * model);
365 /** Is the given primal objective limit reached? */
366 COINLIBAPI int COINLINKAGE Clp_isPrimalObjectiveLimitReached(Clp_Simplex * model) ;
367 /** Is the given dual objective limit reached? */
368 COINLIBAPI int COINLINKAGE Clp_isDualObjectiveLimitReached(Clp_Simplex * model) ;
369 /** Iteration limit reached? */
370 COINLIBAPI int COINLINKAGE Clp_isIterationLimitReached(Clp_Simplex * model);
371 /** Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore */
372 COINLIBAPI double COINLINKAGE Clp_getObjSense(Clp_Simplex * model);
373 /** Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore */
374 COINLIBAPI void COINLINKAGE Clp_setObjSense(Clp_Simplex * model, double objsen);
375 /** Primal row solution */
376 COINLIBAPI const double * COINLINKAGE Clp_getRowActivity(Clp_Simplex * model);
377 /** Primal column solution */
378 COINLIBAPI const double * COINLINKAGE Clp_getColSolution(Clp_Simplex * model);
379 COINLIBAPI void COINLINKAGE Clp_setColSolution(Clp_Simplex * model, const double * input);
380 /** Dual row solution */
381 COINLIBAPI const double * COINLINKAGE Clp_getRowPrice(Clp_Simplex * model);
382 /** Reduced costs */
383 COINLIBAPI const double * COINLINKAGE Clp_getReducedCost(Clp_Simplex * model);
384 /** Row lower */
385 COINLIBAPI const double* COINLINKAGE Clp_getRowLower(Clp_Simplex * model);
386 /** Row upper */
387 COINLIBAPI const double* COINLINKAGE Clp_getRowUpper(Clp_Simplex * model);
388 /** Objective */
389 COINLIBAPI const double * COINLINKAGE Clp_getObjCoefficients(Clp_Simplex * model);
390 /** Column Lower */
391 COINLIBAPI const double * COINLINKAGE Clp_getColLower(Clp_Simplex * model);
392 /** Column Upper */
393 COINLIBAPI const double * COINLINKAGE Clp_getColUpper(Clp_Simplex * model);
394 /** Objective value */
395 COINLIBAPI double COINLINKAGE Clp_getObjValue(Clp_Simplex * model);
396 /** Print model for debugging purposes */
397 COINLIBAPI void COINLINKAGE Clp_printModel(Clp_Simplex * model, const char * prefix);
398 /* Small element value - elements less than this set to zero,
399 default is 1.0e-20 */
400 COINLIBAPI double COINLINKAGE Clp_getSmallElementValue(Clp_Simplex * model);
401 COINLIBAPI void COINLINKAGE Clp_setSmallElementValue(Clp_Simplex * model, double value);
402 /*@}*/
403#ifdef __cplusplus
404}
405#endif
406#endif
407