Scippy

SCIP

Solving Constraint Integer Programs

nlpi.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2014 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file nlpi.h
17  * @brief internal methods for NLPI solver interfaces
18  * @author Stefan Vigerske
19  * @author Thorsten Gellermann
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #ifndef __SCIP_NLPI_H__
25 #define __SCIP_NLPI_H__
26 
27 #include "nlpi/type_nlpi.h"
28 #include "scip/type_misc.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /** compares two NLPIs w.r.t. their priority */
35 SCIP_DECL_SORTPTRCOMP(SCIPnlpiComp);
36 
37 /** creates an NLP solver interface */
38 extern
40  SCIP_NLPI** nlpi, /**< pointer to NLP interface data structure */
41  const char* name, /**< name of NLP interface */
42  const char* description, /**< description of NLP interface */
43  int priority, /**< priority of NLP interface */
44  SCIP_DECL_NLPICOPY ((*nlpicopy)), /**< copying an NLPI */
45  SCIP_DECL_NLPIFREE ((*nlpifree)), /**< free NLPI user data */
46  SCIP_DECL_NLPIGETSOLVERPOINTER ((*nlpigetsolverpointer)), /**< get solver pointer */
47  SCIP_DECL_NLPICREATEPROBLEM ((*nlpicreateproblem)), /**< create a new problem instance */
48  SCIP_DECL_NLPIFREEPROBLEM ((*nlpifreeproblem)), /**< free a problem instance */
49  SCIP_DECL_NLPIGETPROBLEMPOINTER ((*nlpigetproblempointer)), /**< get problem pointer */
50  SCIP_DECL_NLPIADDVARS ((*nlpiaddvars)), /**< add variables */
51  SCIP_DECL_NLPIADDCONSTRAINTS ((*nlpiaddconstraints)), /**< add constraints */
52  SCIP_DECL_NLPISETOBJECTIVE ((*nlpisetobjective)), /**< set objective */
53  SCIP_DECL_NLPICHGVARBOUNDS ((*nlpichgvarbounds)), /**< change variable bounds */
54  SCIP_DECL_NLPICHGCONSSIDES ((*nlpichgconssides)), /**< change constraint sides */
55  SCIP_DECL_NLPIDELVARSET ((*nlpidelvarset)), /**< delete a set of constraints */
56  SCIP_DECL_NLPIDELCONSSET ((*nlpidelconsset)), /**< delete a set of constraints */
57  SCIP_DECL_NLPICHGLINEARCOEFS ((*nlpichglinearcoefs)), /**< change coefficients in linear part of a constraint or objective */
58  SCIP_DECL_NLPICHGQUADCOEFS ((*nlpichgquadcoefs)), /**< change coefficients in quadratic part of a constraint or objective */
59  SCIP_DECL_NLPICHGEXPRTREE ((*nlpichgexprtree)), /**< change nonlinear expression a constraint or objective */
60  SCIP_DECL_NLPICHGNONLINCOEF ((*nlpichgnonlincoef)), /**< change one parameter in nonlinear expressions of a constraint or objective */
61  SCIP_DECL_NLPICHGOBJCONSTANT ((*nlpichgobjconstant)), /**< change the constant offset in the objective */
62  SCIP_DECL_NLPISETINITIALGUESS ((*nlpisetinitialguess)), /**< set initial guess for primal variables */
63  SCIP_DECL_NLPISOLVE ((*nlpisolve)), /**< solve NLP */
64  SCIP_DECL_NLPIGETSOLSTAT ((*nlpigetsolstat)), /**< get solution status */
65  SCIP_DECL_NLPIGETTERMSTAT ((*nlpigettermstat)), /**< get termination status */
66  SCIP_DECL_NLPIGETSOLUTION ((*nlpigetsolution)), /**< get solution */
67  SCIP_DECL_NLPIGETSTATISTICS ((*nlpigetstatistics)), /**< get solve statistics */
68  SCIP_DECL_NLPIGETWARMSTARTSIZE ((*nlpigetwarmstartsize)), /**< get size for warmstart object buffer */
69  SCIP_DECL_NLPIGETWARMSTARTMEMO ((*nlpigetwarmstartmemo)), /**< get warmstart object */
70  SCIP_DECL_NLPISETWARMSTARTMEMO ((*nlpisetwarmstartmemo)), /**< set warmstart object */
71  SCIP_DECL_NLPIGETINTPAR ((*nlpigetintpar)), /**< get value of integer parameter */
72  SCIP_DECL_NLPISETINTPAR ((*nlpisetintpar)), /**< set value of integer parameter */
73  SCIP_DECL_NLPIGETREALPAR ((*nlpigetrealpar)), /**< get value of floating point parameter */
74  SCIP_DECL_NLPISETREALPAR ((*nlpisetrealpar)), /**< set value of floating point parameter */
75  SCIP_DECL_NLPIGETSTRINGPAR ((*nlpigetstringpar)), /**< get value of string parameter */
76  SCIP_DECL_NLPISETSTRINGPAR ((*nlpisetstringpar)), /**< set value of string parameter */
77  SCIP_DECL_NLPISETMESSAGEHDLR ((*nlpisetmessagehdlr)), /**< set message handler */
78  SCIP_NLPIDATA* nlpidata /**< NLP interface local data */
79  );
80 
81 /** copies an NLPI */
82 extern
84  BMS_BLKMEM* blkmem, /**< block memory in target SCIP */
85  SCIP_NLPI* sourcenlpi, /**< pointer to NLPI data structure to copy */
86  SCIP_NLPI** targetnlpi /**< buffer to store pointer to copied NLPI data structure */
87  );
88 
89 /** frees NLPI user data */
90 extern
92  SCIP_NLPI** nlpi /**< pointer to NLPI data structure */
93  );
94 
95 /** gets pointer for NLP solver
96  * @return void pointer to solver
97  */
98 extern
100  SCIP_NLPI* nlpi /**< pointer to NLPI datastructure */
101  );
102 
103 /** creates a problem instance */
104 extern
106  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
107  SCIP_NLPIPROBLEM** problem, /**< pointer to store problem data */
108  const char* name /**< name of problem, can be NULL */
109  );
110 
111 /** frees a problem instance */
112 extern
114  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
115  SCIP_NLPIPROBLEM** problem /**< pointer where problem data is stored */
116  );
117 
118 /** gets pointer to solver-internal problem instance
119  * @return void pointer to problem instance
120  */
121 extern
123  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
124  SCIP_NLPIPROBLEM* problem /**< pointer where problem data is stored */
125  );
126 
127 /** add variables to nlpi */
128 extern
130  SCIP_NLPI* nlpi, /**< pointer to NLPI data structure */
131  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
132  int nvars, /**< number of variables */
133  const SCIP_Real* lbs, /**< lower bounds of variables, can be NULL if -infinity */
134  const SCIP_Real* ubs, /**< upper bounds of variables, can be NULL if +infinity */
135  const char** varnames /**< varnames names of variables, can be NULL */
136  );
137 
138 /** add constraints to nlpi */
139 extern
141  SCIP_NLPI* nlpi, /**< pointer to NLPI data structure */
142  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
143  int nconss, /**< number of added constraints */
144  const SCIP_Real* lhss, /**< left hand sides of constraints, can be NULL if -infinity */
145  const SCIP_Real* rhss, /**< right hand sides of constraints, can be NULL if +infinity */
146  const int* nlininds, /**< number of linear coefficients for each constraint, may be NULL in case of no linear part */
147  int* const* lininds, /**< indices of variables for linear coefficients for each constraint, may be NULL in case of no linear part */
148  SCIP_Real* const* linvals, /**< values of linear coefficient for each constraint, may be NULL in case of no linear part */
149  const int* nquadelems, /**< number of elements in matrix of quadratic part for each constraint,
150  * may be NULL in case of no quadratic part in any constraint */
151  SCIP_QUADELEM* const* quadelems, /**< quadratic elements specifying quadratic part for each constraint, entry of array may be NULL in case of no quadratic part,
152  * may be NULL in case of no quadratic part in any constraint */
153  int* const* exprvaridxs, /**< indices of variables in expression tree, maps variable indices in expression
154  * tree to indices in nlp, entry of array may be NULL in case of no expression
155  * tree, may be NULL in case of no expression tree in any constraint */
156  SCIP_EXPRTREE* const* exprtrees, /**< exprtrees expression tree for nonquadratic part of constraints, entry of
157  * array may be NULL in case of no nonquadratic part, may be NULL in case of no
158  * nonquadratic part in any constraint */
159  const char** names /**< names of constraints, may be NULL or entries may be NULL */
160  );
161 
162 
163 /** sets or overwrites objective, a minimization problem is expected */
164 extern
166  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
167  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
168  int nlins, /**< number of linear variables */
169  const int* lininds, /**< variable indices, may be NULL in case of no linear part */
170  const SCIP_Real* linvals, /**< coefficient values, may be NULL in case of no linear part */
171  int nquadelems, /**< number of entries in matrix of quadratic part */
172  const SCIP_QUADELEM* quadelems, /**< entries in matrix of quadratic part, may be NULL in case of no quadratic part */
173  const int* exprvaridxs, /**< indices of variables in expression tree, maps variable indices in expression
174  * tree to indices in nlp, may be NULL in case of no expression tree */
175  const SCIP_EXPRTREE* exprtree, /**< expression tree for nonquadratic part of objective function, may be NULL in
176  * case of no nonquadratic part */
177  const SCIP_Real constant /**< objective value offset*/
178  );
179 
180 /** change variable bounds */
181 extern
183  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
184  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
185  int nvars, /**< number of variables to change bounds */
186  const int* indices, /**< indices of variables to change bounds */
187  const SCIP_Real* lbs, /**< new lower bounds */
188  const SCIP_Real* ubs /**< new upper bounds */
189  );
190 
191 /** change constraint sides */
192 extern
194  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
195  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
196  int nconss, /**< number of constraints to change sides */
197  const int* indices, /**< indices of constraints to change sides */
198  const SCIP_Real* lhss, /**< new left hand sides */
199  const SCIP_Real* rhss /**< new right hand sides */
200  );
201 
202 /** delete a set of variables */
203 extern
205  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
206  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
207  int* dstats /**< deletion status of vars; 1 if var should be deleted, 0 if not; afterwards -1
208  * if var was deleted */
209  );
210 
211 /** delete a set of constraints */
212 extern
214  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
215  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
216  int* dstats /**< deletion status of rows; 1 if row should be deleted, 0 if not; afterwards -1
217  * if row was deleted */
218  );
219 
220 /** changes or adds linear coefficients in a constraint or objective */
221 extern
223  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
224  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
225  const int idx, /**< index of constraint or -1 for objective */
226  int nvals, /**< number of values in linear constraint */
227  const int* varidxs, /**< indices of variable */
228  const SCIP_Real* vals /**< new values for coefficient */
229  );
230 
231 /** changes or adds coefficients in the quadratic part of a constraint or objective */
232 extern
234  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
235  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
236  int idx, /**< index of constraint or -1 for objective */
237  int nquadelems, /**< number of entries in quadratic constraint to change */
238  const SCIP_QUADELEM* quadelems /**< new elements in quadratic matrix (replacing already existing ones or adding new ones) */
239  );
240 
241 /** change the expression tree in the nonlinear part */
242 extern
244  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
245  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
246  int idxcons, /**< index of constraint or -1 for objective */
247  const int* exprvaridxs, /**< indices of variables in expression tree, maps variable indices in expression tree to indices in nlp, or NULL */
248  SCIP_EXPRTREE* exprtree /**< new expression tree, or NULL for no tree */
249  );
250 
251 /** change the value of one parameter in the nonlinear part */
252 extern
254  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
255  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
256  int idxcons, /**< index of constraint or -1 for objective */
257  int idxparam, /**< index of parameter */
258  SCIP_Real value /**< new value for nonlinear parameter */
259  );
260 
261 /** change the constant offset in the objective */
262 extern
264  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
265  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
266  SCIP_Real objconstant /**< new value for objective constant */
267  );
268 
269 /** sets initial guess for primal variables */
270 extern
272  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
273  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
274  SCIP_Real* primalvalues, /**< initial primal values for variables, or NULL to clear previous values */
275  SCIP_Real* consdualvalues, /**< initial dual values for constraints, or NULL to clear previous values */
276  SCIP_Real* varlbdualvalues, /**< initial dual values for variable lower bounds, or NULL to clear previous values */
277  SCIP_Real* varubdualvalues /**< initial dual values for variable upper bounds, or NULL to clear previous values */
278  );
279 
280 /** tries to solve NLP */
281 extern
283  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
284  SCIP_NLPIPROBLEM* problem /**< pointer to problem data structure */
285  );
286 
287 /** gives solution status
288  * @return solution status */
289 extern
291  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
292  SCIP_NLPIPROBLEM* problem /**< pointer to problem data structure */
293  );
294 
295 /** gives termination reason
296  * @return termination status */
297 extern
299  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
300  SCIP_NLPIPROBLEM* problem /**< pointer to problem data structure */
301  );
302 
303 /** gives primal and dual solution
304  * for a ranged constraint, the dual variable is positive if the right hand side is active and negative if the left hand side is active
305  */
306 extern
308  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
309  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
310  SCIP_Real** primalvalues, /**< buffer to store pointer to array to primal values, or NULL if not needed */
311  SCIP_Real** consdualvalues, /**< buffer to store pointer to array to dual values of constraints, or NULL if not needed */
312  SCIP_Real** varlbdualvalues, /**< buffer to store pointer to array to dual values of variable lower bounds, or NULL if not needed */
313  SCIP_Real** varubdualvalues /**< buffer to store pointer to array to dual values of variable lower bounds, or NULL if not needed */
314  );
315 
316 /** gives solve statistics */
317 extern
319  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
320  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
321  SCIP_NLPSTATISTICS* statistics /**< pointer to store statistics */
322  );
323 
324 /** gives required size of a buffer to store a warmstart object */
325 extern
327  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
328  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
329  size_t* size /**< pointer to store required size for warmstart buffer */
330  );
331 
332 /** stores warmstart information in buffer */
333 extern
335  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
336  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
337  void* buffer /**< memory to store warmstart information */
338  );
339 
340 /** sets warmstart information in solver */
341 extern
343  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
344  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
345  void* buffer /**< warmstart information */
346  );
347 
348 /**@name Parameter Methods */
349 /**@{ */
350 
351 /** gets integer parameter of NLP */
352 extern
354  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
355  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
356  SCIP_NLPPARAM type, /**< parameter number */
357  int* ival /**< pointer to store the parameter value */
358  );
359 
360 /** sets integer parameter of NLP */
361 extern
363  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
364  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
365  SCIP_NLPPARAM type, /**< parameter number */
366  int ival /**< parameter value */
367  );
368 
369 /** gets floating point parameter of NLP
370  * if problem is NULL and type == SCIP_NLPPAR_INFINITY, then gets solver-wide value for infinity */
371 extern
373  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
374  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure, can be NULL only if type == SCIP_NLPPAR_INFINITY */
375  SCIP_NLPPARAM type, /**< parameter number */
376  SCIP_Real* dval /**< pointer to store the parameter value */
377  );
378 
379 /** sets floating point parameter of NLP
380  * if problem is NULL and type == SCIP_NLPPAR_INFINITY, then sets solver-wide value for infinity */
381 extern
383  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
384  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure, can be NULL only if type == SCIP_NLPPAR_INFINITY */
385  SCIP_NLPPARAM type, /**< parameter number */
386  SCIP_Real dval /**< parameter value */
387  );
388 
389 /** gets string parameter of NLP */
390 extern
392  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
393  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
394  SCIP_NLPPARAM type, /**< parameter number */
395  const char** sval /**< pointer to store the parameter value, the user must not modify the string */
396  );
397 
398 /** sets string parameter of NLP */
399 extern
401  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
402  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
403  SCIP_NLPPARAM type, /**< parameter number */
404  const char* sval /**< parameter value */
405  );
406 
407 /** sets message handler for message output */
408 extern
410  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
411  SCIP_MESSAGEHDLR* messagehdlr /**< pointer to message handler, or NULL to suppress all output */
412  );
413 
414 /** gets data of an NLPI */
416  SCIP_NLPI* nlpi /**< NLP interface structure */
417  );
418 
419 /** gets NLP solver name */
420 const char* SCIPnlpiGetName(
421  SCIP_NLPI* nlpi /**< NLP interface structure */
422  );
423 
424 /** gets NLP solver descriptions */
425 const char* SCIPnlpiGetDesc(
426  SCIP_NLPI* nlpi /**< NLP interface structure */
427  );
428 
429 /** gets NLP solver priority */
431  SCIP_NLPI* nlpi /**< NLP interface structure */
432  );
433 
434 /** sets NLP solver priority */
436  SCIP_NLPI* nlpi, /**< NLP interface structure */
437  int priority /**< new priority of NLPI */
438  );
439 
440 /** creates an NLP statistics structure */
442  SCIP_NLPSTATISTICS** statistics /**< pointer where to store NLP statistics structure */
443  );
444 
445 /** frees an NLP statistics structure */
447  SCIP_NLPSTATISTICS** statistics /**< pointer where to store NLP statistics structure */
448  );
449 
450 /** gets the number of iterations from an NLP statistics structure */
452  SCIP_NLPSTATISTICS* statistics /**< NLP statistics structure */
453  );
454 
455 /** gets the total time from an NLP statistics structure */
457  SCIP_NLPSTATISTICS* statistics /**< NLP statistics structure */
458  );
459 
460 /** sets the number of iterations in an NLP statistics structure */
462  SCIP_NLPSTATISTICS* statistics, /**< NLP statistics structure */
463  int niterations /**< number of iterations to store */
464  );
465 
466 /** sets the total time in an NLP statistics structure */
468  SCIP_NLPSTATISTICS* statistics, /**< NLP statistics structure */
469  SCIP_Real totaltime /**< solution time to store */
470  );
471 
472 #ifdef __cplusplus
473 }
474 #endif
475 
476 #endif /* __SCIP_NLPI_H__ */
477