Scippy

SCIP

Solving Constraint Integer Programs

nlpioracle.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 nlpioracle.h
17  * @brief methods to store an NLP and request function, gradient, and hessian values
18  * @author Stefan Vigerske
19  *
20  * Not a full NLPI, but implements a common part of many NLPIs that takes care
21  * of the problem storage and function, gradient, and hessian evaluation.
22  */
23 
24 #ifndef __SCIP_NLPI_ORACLE_H__
25 #define __SCIP_NLPI_ORACLE_H__
26 
27 #include "scip/type_message.h"
28 #include "nlpi/type_nlpi.h"
29 
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 typedef struct SCIP_NlpiOracle SCIP_NLPIORACLE; /**< NLPI oracle data structure */
36 
37 /** creates an NLPIORACLE data structure */
38 extern
40  BMS_BLKMEM* blkmem, /**< block memory */
41  SCIP_NLPIORACLE** oracle /**< pointer to store NLPIORACLE data structure */
42  );
43 
44 /** frees an NLPIORACLE data structure */
45 extern
47  SCIP_NLPIORACLE** oracle /**< pointer to NLPIORACLE data structure */
48  );
49 
50 /** sets the value for infinity */
51 extern
53  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
54  SCIP_Real infinity /**< value to use for infinity */
55  );
56 
57 /** gets the value for infinity */
58 extern
60  SCIP_NLPIORACLE* oracle /**< pointer to NLPIORACLE data structure */
61  );
62 
63 /** sets the problem name (used for printing) */
64 extern
66  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
67  const char* name /**< name of problem */
68  );
69 
70 /** gets the problem name, or NULL if none set */
71 extern
73  SCIP_NLPIORACLE* oracle /**< pointer to NLPIORACLE data structure */
74  );
75 
76 /** adds variables */
77 extern
79  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
80  int nvars, /**< number of variables to add */
81  const SCIP_Real* lbs, /**< array with lower bounds of new variables, or NULL if all -infinity */
82  const SCIP_Real* ubs, /**< array with upper bounds of new variables, or NULL if all +infinity */
83  const char** varnames /**< array with names of new variables, or NULL if no names should be stored */
84  );
85 
86 /** adds constraints
87  *
88  * linear coefficients: row(=constraint) oriented matrix;
89  * quadratic coefficients: row oriented matrix for each constraint
90  */
91 extern
93  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
94  int nconss, /**< number of constraints to add */
95  const SCIP_Real* lhss, /**< array with left-hand sides of constraints, or NULL if all -infinity */
96  const SCIP_Real* rhss, /**< array with right-hand sides of constraints, or NULL if all +infinity */
97  const int* nlininds, /**< number of linear coefficients for each constraint, may be NULL in case of no linear part */
98  int* const* lininds, /**< indices of variables for linear coefficients for each constraint, may be NULL in case of no linear part */
99  SCIP_Real* const* linvals, /**< values of linear coefficient for each constraint, may be NULL in case of no linear part */
100  const int* nquadelems, /**< number of elements in matrix of quadratic part for each constraint,
101  * may be NULL in case of no quadratic part in any constraint */
102  SCIP_QUADELEM* const* quadelems, /**< quadratic elements specifying quadratic part for each constraint, entry of array may be NULL in case of no quadratic part,
103  * may be NULL in case of no quadratic part in any constraint */
104  int* const* exprvaridxs, /**< NULL if no nonquadratic parts, otherwise epxrvaridxs[.] maps variable indices in expression tree to indices in nlp */
105  SCIP_EXPRTREE* const* exprtrees, /**< NULL if no nonquadratic parts, otherwise exprtrees[.] gives nonquadratic part,
106  * or NULL if no nonquadratic part in this constraint */
107  const char** consnames /**< names of new constraints, or NULL if no names should be stored */
108  );
109 
110 /** sets or overwrites objective, a minimization problem is expected
111  *
112  * May change sparsity pattern.
113  */
114 extern
116  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
117  const SCIP_Real constant, /**< constant part of objective */
118  int nlin, /**< number of linear variable coefficients */
119  const int* lininds, /**< indices of linear variables, or NULL if no linear part */
120  const SCIP_Real* linvals, /**< coefficients of linear variables, or NULL if no linear part */
121  int nquadelems, /**< number of entries in matrix of quadratic part */
122  const SCIP_QUADELEM* quadelems, /**< entries in matrix of quadratic part, may be NULL in case of no quadratic part */
123  const int* exprvaridxs, /**< maps variable indices in expression tree to indices in nlp, or NULL if no nonquadratic part */
124  const SCIP_EXPRTREE* exprtree /**< expression tree of nonquadratic part, or NULL if no nonquadratic part */
125  );
126 
127 /** change variable bounds */
128 extern
130  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
131  int nvars, /**< number of variables to change bounds */
132  const int* indices, /**< array with indices of variables to change bounds */
133  const SCIP_Real* lbs, /**< array with new lower bounds, or NULL if all should be -infty */
134  const SCIP_Real* ubs /**< array with new upper bounds, or NULL if all should be +infty */
135  );
136 
137 /** change constraint sides */
138 extern
140  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
141  int nconss, /**< number of constraints to change sides */
142  const int* indices, /**< array with indices of constraints to change sides */
143  const SCIP_Real* lhss, /**< array with new left-hand sides, or NULL if all should be -infty */
144  const SCIP_Real* rhss /**< array with new right-hand sides, or NULL if all should be +infty */
145  );
146 
147 /** deletes a set of variables */
148 extern
150  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
151  int* delstats /**< array with deletion status of vars in input (1 if var should be deleted, 0 if not);
152  * new position of var in output (-1 if var was deleted) */
153  );
154 
155 /** deletes a set of constraints */
156 extern
158  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
159  int* delstats /**< array with deletion status of rows in input (1 if row should be deleted, 0 if not);
160  * new position of row in output (-1 if row was deleted) */
161  );
162 
163 /** changes (or adds) linear coefficients in one constraint or objective */
164 extern
166  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
167  int considx, /**< index of constraint where linear coefficients should be changed, or -1 for objective */
168  int nentries, /**< number of coefficients to change */
169  const int* varidxs, /**< array with indices of variables which coefficients should be changed */
170  const SCIP_Real* newcoefs /**< array with new coefficients of variables */
171  );
172 
173 /** changes (or adds) coefficients in the quadratic part of one constraint or objective */
174 extern
176  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
177  int considx, /**< index of constraint where quadratic coefficients should be changed, or -1 for objective */
178  int nquadelems, /**< number of entries in quadratic constraint to change */
179  const SCIP_QUADELEM* quadelems /**< new elements in quadratic matrix (replacing already existing ones or adding new ones) */
180  );
181 
182 /** replaces expression tree of one constraint or objective */
183 extern
185  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
186  int considx, /**< index of constraint where expression tree should be changed, or -1 for objective */
187  const int* exprvaridxs, /**< problem indices of variables in expression tree */
188  const SCIP_EXPRTREE* exprtree /**< new expression tree, or NULL */
189  );
190 
191 /** changes one parameter of expression tree of one constraint or objective
192  */
193 extern
195  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
196  int considx, /**< index of constraint where parameter should be changed in expression tree, or -1 for objective */
197  int paramidx, /**< index of parameter */
198  SCIP_Real paramval /**< new value of parameter */
199  );
200 
201 /** changes the constant value in the objective function
202  */
203 extern
205  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
206  SCIP_Real objconstant /**< new value for objective constant */
207  );
208 
209 /** gives the current number of variables */
210 extern
212  SCIP_NLPIORACLE* oracle /**< pointer to NLPIORACLE data structure */
213  );
214 
215 /** gives the current number of constraints */
216 extern
218  SCIP_NLPIORACLE* oracle /**< pointer to NLPIORACLE data structure */
219  );
220 
221 /** gives the variables lower bounds */
222 extern
224  SCIP_NLPIORACLE* oracle /**< pointer to NLPIORACLE data structure */
225  );
226 
227 /** gives the variables upper bounds */
228 extern
230  SCIP_NLPIORACLE* oracle /**< pointer to NLPIORACLE data structure */
231  );
232 
233 /** gives the variables names, or NULL if not set */
234 extern
236  SCIP_NLPIORACLE* oracle /**< pointer to NLPIORACLE data structure */
237  );
238 
239 /** Gives maximum degree of a variable w.r.t. objective and all constraints.
240  * The degree of a variable is the degree of the summand where it appears in, and is infinity for nonpolynomial terms.
241  */
242 extern
244  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
245  int varidx /**< the variable for which the degree is returned */
246  );
247 
248 /** Gives maximum degree of all variables w.r.t. objective and all constraints.
249  * The degree of a variable is the degree of the summand where it appears in, and is infinity for nonpolynomial terms.
250  */
251 extern
253  SCIP_NLPIORACLE* oracle /**< pointer to NLPIORACLE data structure */
254  );
255 
256 /** gives left-hand side of a constraint */
257 extern
259  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
260  int considx /**< constraint index */
261  );
262 
263 /** gives right-hand side of a constraint */
264 extern
266  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
267  int considx /**< constraint index */
268  );
269 
270 /** gives name of a constraint, may be NULL */
271 extern
273  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
274  int considx /**< constraint index */
275  );
276 
277 /** gives maximum degree of a constraint or objective
278  * The degree is the maximal degree of all summands,, and is infinity for nonpolynomial terms.
279  */
280 extern
282  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
283  int considx /**< index of constraint for which the degree is requested, or -1 for objective */
284  );
285 
286 /** Gives maximum degree over all constraints and the objective (or over all variables, resp.).
287  * Thus, if this function returns 0, then the objective and all constraints are constant.
288  * If it returns 1, then the problem in linear.
289  * If it returns 2, then its a QP, QCP, or QCQP.
290  * And if it returns > 2, then it is an NLP.
291  */
292 extern
294  SCIP_NLPIORACLE* oracle /**< pointer to NLPIORACLE data structure */
295  );
296 
297 /** evaluates the objective function in a given point */
298 extern
300  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
301  const SCIP_Real* x, /**< point where to evaluate */
302  SCIP_Real* objval /**< pointer to store objective value */
303  );
304 
305 /** evaluates one constraint function in a given point */
306 extern
308  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
309  int considx, /**< index of constraint to evaluate */
310  const SCIP_Real* x, /**< point where to evaluate */
311  SCIP_Real* conval /**< pointer to store constraint value */
312  );
313 
314 /** evaluates all constraint functions in a given point */
315 extern
317  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
318  const SCIP_Real* x, /**< point where to evaluate */
319  SCIP_Real* convals /**< pointer to store constraint values */
320  );
321 
322 /** computes the objective gradient in a given point */
323 extern
325  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
326  const SCIP_Real* x, /**< point where to evaluate */
327  SCIP_Bool isnewx, /**< has the point x changed since the last call to some evaluation function? */
328  SCIP_Real* objval, /**< pointer to buffer objective value */
329  SCIP_Real* objgrad /**< pointer to buffer (dense) objective gradient */
330  );
331 
332 /** computes a constraints gradient in a given point */
333 extern
335  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
336  const int considx, /**< index of constraint to compute gradient for */
337  const SCIP_Real* x, /**< point where to evaluate */
338  SCIP_Bool isnewx, /**< has the point x changed since the last call to some evaluation function? */
339  SCIP_Real* conval, /**< pointer to store constraint value */
340  SCIP_Real* congrad /**< pointer to store (dense) constraint gradient */
341  );
342 
343 /** gets sparsity pattern (rowwise) of Jacobian matrix
344  *
345  * Note that internal data is returned in *offset and *col, thus the user does not need to allocate memory there.
346  * Adding or deleting constraints destroys the sparsity structure and make another call to this function necessary.
347  */
348 extern
350  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
351  const int** offset, /**< pointer to store pointer that stores the offsets to each rows sparsity pattern in col, can be NULL */
352  const int** col /**< pointer to store pointer that stores the indices of variables that appear in each row,
353  * offsets[nconss] gives length of col, can be NULL */
354  );
355 
356 /** evaluates the Jacobi matrix in a given point
357  *
358  * The values in the Jacobi matrix are returned in the same order as specified by the offset and col arrays obtained by SCIPnlpiOracleGetJacobianSparsity.
359  * The user need to call SCIPnlpiOracleGetJacobianSparsity at least ones before using this function.
360  */
361 extern
363  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
364  const SCIP_Real* x, /**< point where to evaluate */
365  SCIP_Bool isnewx, /**< has the point x changed since the last call to some evaluation function? */
366  SCIP_Real* convals, /**< pointer to store constraint values, can be NULL */
367  SCIP_Real* jacobi /**< pointer to store sparse jacobian values */
368  );
369 
370 /** gets sparsity pattern of the Hessian matrix of the Lagrangian
371  *
372  * Note that internal data is returned in *offset and *col, thus the user must not to allocate memory there.
373  * Adding or deleting variables, objective, or constraints may destroy the sparsity structure and make another call to this function necessary.
374  * Only elements of the lower left triangle and the diagonal are counted.
375  */
376 extern
378  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
379  const int** offset, /**< pointer to store pointer that stores the offsets to each rows sparsity pattern in col, can be NULL */
380  const int** col /**< pointer to store pointer that stores the indices of variables that appear in each row,
381  * offsets[nconss] gives length of col, can be NULL */
382  );
383 
384 /** evaluates the Hessian matrix of the Lagrangian in a given point
385  *
386  * The values in the Hessian matrix are returned in the same order as specified by the offset and col arrays obtained by SCIPnlpiOracleGetHessianLagSparsity.
387  * The user must call SCIPnlpiOracleGetHessianLagSparsity at least ones before using this function.
388  * Only elements of the lower left triangle and the diagonal are computed.
389  */
390 extern
392  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
393  const SCIP_Real* x, /**< point where to evaluate */
394  SCIP_Bool isnewx, /**< has the point x changed since the last call to some evaluation function? */
395  SCIP_Real objfactor, /**< weight for objective function */
396  const SCIP_Real* lambdas, /**< array with weights (Lagrangian multipliers) for the constraints */
397  SCIP_Real* hessian /**< pointer to store sparse hessian values */
398  );
399 
400 /** prints the problem to a file. */
401 extern
403  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
404  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
405  FILE* file /**< file to print to, or NULL for standard output */
406  );
407 
408 /** prints the problem to a file in GAMS format
409  * If there are variable (equation, resp.) names with more than 9 characters, then variable (equation, resp.) names are prefixed with an unique identifier.
410  * This is to make it easier to identify variables solution output in the listing file.
411  * Names with more than 64 characters are shorten to 64 letters due to GAMS limits.
412  */
413 extern
415  SCIP_NLPIORACLE* oracle, /**< pointer to NLPIORACLE data structure */
416  SCIP_Real* initval, /**< starting point values for variables or NULL */
417  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
418  FILE* file /**< file to print to, or NULL for standard output */
419  );
420 
421 #ifdef __cplusplus
422 }
423 #endif
424 
425 #endif
426