Scippy

SCIP

Solving Constraint Integer Programs

scip_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-2022 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 visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file scip_nlpi.h
17  * @ingroup PUBLICCOREAPI
18  * @brief public methods for NLPI solver interfaces
19  * @author Stefan Vigerske
20  * @author Thorsten Gellermann
21  */
22 
23 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
24 
25 #ifndef __SCIP_SCIP_NLPI_H__
26 #define __SCIP_SCIP_NLPI_H__
27 
28 #include "scip/type_nlpi.h"
29 #include "scip/type_misc.h"
30 #include "scip/type_lp.h"
31 #include "blockmemshell/memory.h"
32 #include "scip/pub_nlpi.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /**@addtogroup PublicNLPIInterfaceMethods
39  *
40  * @{
41  */
42 
43 /** creates an NLPI and includes it into SCIP */
44 SCIP_EXPORT
46  SCIP* scip, /**< SCIP data structure */
47  const char* name, /**< name of NLP interface */
48  const char* description, /**< description of NLP interface */
49  int priority, /**< priority of NLP interface */
50  SCIP_DECL_NLPICOPY ((*nlpicopy)), /**< copying an NLPI, can be NULL */
51  SCIP_DECL_NLPIFREE ((*nlpifree)), /**< free NLPI user data */
52  SCIP_DECL_NLPIGETSOLVERPOINTER ((*nlpigetsolverpointer)), /**< get solver pointer, can be NULL */
53  SCIP_DECL_NLPICREATEPROBLEM ((*nlpicreateproblem)), /**< create a new problem instance */
54  SCIP_DECL_NLPIFREEPROBLEM ((*nlpifreeproblem)), /**< free a problem instance */
55  SCIP_DECL_NLPIGETPROBLEMPOINTER ((*nlpigetproblempointer)), /**< get problem pointer, can be NULL */
56  SCIP_DECL_NLPIADDVARS ((*nlpiaddvars)), /**< add variables */
57  SCIP_DECL_NLPIADDCONSTRAINTS ((*nlpiaddconstraints)), /**< add constraints */
58  SCIP_DECL_NLPISETOBJECTIVE ((*nlpisetobjective)), /**< set objective */
59  SCIP_DECL_NLPICHGVARBOUNDS ((*nlpichgvarbounds)), /**< change variable bounds */
60  SCIP_DECL_NLPICHGCONSSIDES ((*nlpichgconssides)), /**< change constraint sides */
61  SCIP_DECL_NLPIDELVARSET ((*nlpidelvarset)), /**< delete a set of constraints */
62  SCIP_DECL_NLPIDELCONSSET ((*nlpidelconsset)), /**< delete a set of constraints */
63  SCIP_DECL_NLPICHGLINEARCOEFS ((*nlpichglinearcoefs)), /**< change coefficients in linear part of a constraint or objective */
64  SCIP_DECL_NLPICHGEXPR ((*nlpichgexpr)), /**< change nonlinear expression a constraint or objective */
65  SCIP_DECL_NLPICHGOBJCONSTANT ((*nlpichgobjconstant)), /**< change the constant offset in the objective */
66  SCIP_DECL_NLPISETINITIALGUESS ((*nlpisetinitialguess)), /**< set initial guess, can be NULL */
67  SCIP_DECL_NLPISOLVE ((*nlpisolve)), /**< solve NLP */
68  SCIP_DECL_NLPIGETSOLSTAT ((*nlpigetsolstat)), /**< get solution status */
69  SCIP_DECL_NLPIGETTERMSTAT ((*nlpigettermstat)), /**< get termination status */
70  SCIP_DECL_NLPIGETSOLUTION ((*nlpigetsolution)), /**< get solution */
71  SCIP_DECL_NLPIGETSTATISTICS ((*nlpigetstatistics)), /**< get solve statistics */
72  SCIP_NLPIDATA* nlpidata /**< NLP interface local data */
73  );
74 
75 /** returns the NLPI of the given name, or NULL if not existing */
76 SCIP_EXPORT
78  SCIP* scip, /**< SCIP data structure */
79  const char* name /**< name of NLPI */
80  );
81 
82 /** returns the array of currently available NLPIs (sorted by priority) */
83 SCIP_EXPORT
85  SCIP* scip /**< SCIP data structure */
86  );
87 
88 /** returns the number of currently available NLPIs */
89 SCIP_EXPORT
90 int SCIPgetNNlpis(
91  SCIP* scip /**< SCIP data structure */
92  );
93 
94 /** sets the priority of an NLPI */
95 SCIP_EXPORT
97  SCIP* scip, /**< SCIP data structure */
98  SCIP_NLPI* nlpi, /**< NLPI */
99  int priority /**< new priority of the NLPI */
100  );
101 
102 /** gets internal pointer to NLP solver
103  *
104  * Depending on the solver interface, a solver pointer may exist for every NLP problem instance.
105  * For this case, a NLPI problem can be passed in as well.
106  */
107 SCIP_EXPORT
108 SCIP_DECL_NLPIGETSOLVERPOINTER(SCIPgetNlpiSolverPointer);
109 
110 /** creates an empty problem instance */
111 SCIP_EXPORT
112 SCIP_DECL_NLPICREATEPROBLEM(SCIPcreateNlpiProblem);
113 
114 /** frees a problem instance */
115 SCIP_EXPORT
116 SCIP_DECL_NLPIFREEPROBLEM(SCIPfreeNlpiProblem);
117 
118 /** gets internal pointer to solver-internal problem instance */
119 SCIP_EXPORT
120 SCIP_DECL_NLPIGETPROBLEMPOINTER(SCIPgetNlpiProblemPointer);
121 
122 /** add variables to nlpi */
123 SCIP_EXPORT
124 SCIP_DECL_NLPIADDVARS(SCIPaddNlpiVars);
125 
126 /** add constraints to nlpi */
127 SCIP_EXPORT
128 SCIP_DECL_NLPIADDCONSTRAINTS(SCIPaddNlpiConstraints);
129 
130 /** sets or overwrites objective, a minimization problem is expected */
131 SCIP_EXPORT
132 SCIP_DECL_NLPISETOBJECTIVE(SCIPsetNlpiObjective);
133 
134 /** change variable bounds */
135 SCIP_EXPORT
136 SCIP_DECL_NLPICHGVARBOUNDS(SCIPchgNlpiVarBounds);
137 
138 /** change constraint sides */
139 SCIP_EXPORT
140 SCIP_DECL_NLPICHGCONSSIDES(SCIPchgNlpiConsSides);
141 
142 /** delete a set of variables */
143 SCIP_EXPORT
144 SCIP_DECL_NLPIDELVARSET(SCIPdelNlpiVarSet);
145 
146 /** delete a set of constraints */
147 SCIP_EXPORT
148 SCIP_DECL_NLPIDELCONSSET(SCIPdelNlpiConsSet);
149 
150 /** changes or adds linear coefficients in a constraint or objective */
151 SCIP_EXPORT
152 SCIP_DECL_NLPICHGLINEARCOEFS(SCIPchgNlpiLinearCoefs);
153 
154 /** change the expression in the nonlinear part */
155 SCIP_EXPORT
156 SCIP_DECL_NLPICHGEXPR(SCIPchgNlpiExpr);
157 
158 /** change the constant offset in the objective */
159 SCIP_EXPORT
160 SCIP_DECL_NLPICHGOBJCONSTANT(SCIPchgNlpiObjConstant);
161 
162 /** sets initial guess */
163 SCIP_EXPORT
164 SCIP_DECL_NLPISETINITIALGUESS(SCIPsetNlpiInitialGuess);
165 
166 /** try to solve NLP with all parameters given as SCIP_NLPPARAM struct
167  *
168  * Typical use is
169  *
170  * SCIP_NLPPARAM nlparam = { SCIP_NLPPARAM_DEFAULT(scip); }
171  * nlpparam.iterlimit = 42;
172  * SCIP_CALL( SCIPsolveNlpiParam(scip, nlpi, nlpiproblem, nlpparam) );
173  *
174  * or, in "one" line:
175  *
176  * SCIP_CALL( SCIPsolveNlpiParam(scip, nlpi, nlpiproblem,
177  * (SCIP_NLPPARAM){ SCIP_NLPPARAM_DEFAULT(scip), .iterlimit = 42 }) );
178  *
179  * To get the latter, also \ref SCIPsolveNlpi can be used.
180  */
181 SCIP_EXPORT
182 SCIP_DECL_NLPISOLVE(SCIPsolveNlpiParam);
183 
184 /** try to solve NLP with non-default parameters given as optional arguments
185  *
186  * Typical use is
187  *
188  * SCIP_CALL( SCIPsolveNlpi(scip, nlpi, nlpiproblem) );
189  *
190  * to solve with default parameters.
191  * Additionally, one or several values of SCIP_NLPPARAM can be set:
192  *
193  * SCIP_CALL( SCIPsolveNlpi(scip, nlpi, nlpiproblem, .iterlimit = 42, .verblevel = 1) ); //lint !e666
194  */
195 /* the problem argument has been made part of the variadic arguments, since ISO C99 requires at least one argument for the "..." part and we want to allow leaving all parameters at default
196  * for the same reason, we set the .caller argument, so that macro SCIP_VARARGS_REST will have at least one arg to return
197  */
198 #if !defined(_MSC_VER) || _MSC_VER >= 1800
199 #define SCIPsolveNlpi(scip, nlpi, ...) \
200  SCIPsolveNlpiParam(scip, nlpi, SCIP_VARARGS_FIRST((__VA_ARGS__, ignored)), \
201  (SCIP_NLPPARAM){ SCIP_NLPPARAM_DEFAULT_INITS(scip), SCIP_VARARGS_REST(__VA_ARGS__, .caller = __FILE__) })
202 #else
203 /* very old MSVC doesn't support C99's designated initializers, so have a version of SCIPsolveNlpi() that just ignores given parameters
204  * (compilation of scip_nlpi.c will print a warning)
205  */
206 #define SCIPsolveNlpi(scip, nlpi, ...) \
207  SCIPsolveNlpiParam(scip, nlpi, SCIP_VARARGS_FIRST((__VA_ARGS__, ignored)), SCIP_NLPPARAM_DEFAULT_STATIC)
208 #endif
209 
210 /** gives solution status */
211 SCIP_EXPORT
212 SCIP_DECL_NLPIGETSOLSTAT(SCIPgetNlpiSolstat);
213 
214 /** gives termination reason */
215 SCIP_EXPORT
216 SCIP_DECL_NLPIGETTERMSTAT(SCIPgetNlpiTermstat);
217 
218 /** gives primal and dual solution
219  * 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
220  */
221 SCIP_EXPORT
222 SCIP_DECL_NLPIGETSOLUTION(SCIPgetNlpiSolution);
223 
224 /** gives solve statistics */
225 SCIP_EXPORT
226 SCIP_DECL_NLPIGETSTATISTICS(SCIPgetNlpiStatistics);
227 
228 
229 /**@name Convenience methods to setup and update an NLPI problem using NLROWS
230  *
231  * These methods can be used, for example, to create a NLPI problem that contains only the convex rows of the SCIP NLP relaxation.
232  * @{
233  */
234 
235 /** creates a NLPI problem from given nonlinear rows
236  *
237  * The function computes for each variable the number of non-linear occurrences and stores it in the nlscore array.
238  *
239  * @note the first row corresponds always to the cutoff row (even if cutoffbound is SCIPinfinity(scip))
240  **/
241 SCIP_EXPORT
243  SCIP* scip, /**< SCIP data structure */
244  SCIP_NLPI* nlpi, /**< interface to NLP solver */
245  SCIP_NLPIPROBLEM** nlpiprob, /**< buffer to store pointer to created nlpi problem */
246  const char* name, /**< name to give to problem */
247  SCIP_NLROW** nlrows, /**< nonlinear rows */
248  int nnlrows, /**< number of nonlinear rows */
249  SCIP_HASHMAP* var2idx, /**< empty hash map to store mapping between variables and indices in nlpiprob */
250  SCIP_HASHMAP* nlrow2idx, /**< empty hash map to store mapping between variables and indices in nlpiprob, can be NULL */
251  SCIP_Real* nlscore, /**< array to store the score of each nonlinear variable (NULL if not needed) */
252  SCIP_Real cutoffbound, /**< cutoff bound */
253  SCIP_Bool setobj, /**< whether the objective function should be set to one of the SCIP problem */
254  SCIP_Bool onlyconvex /**< filter only for convex constraints */
255  );
256 
257 /** updates variable bounds and the cutoff row in a NLPI problem
258  *
259  * The NLPI problem must have been setup by SCIPcreateNlpiProblemFromNlRows().
260  */
261 SCIP_EXPORT
263  SCIP* scip, /**< SCIP data structure */
264  SCIP_NLPI* nlpi, /**< interface to NLP solver */
265  SCIP_NLPIPROBLEM* nlpiprob, /**< nlpi problem representing the convex NLP relaxation */
266  SCIP_HASHMAP* var2nlpiidx, /**< mapping between variables and nlpi indices */
267  SCIP_VAR** nlpivars, /**< array containing all variables of the nlpi */
268  int nlpinvars, /**< total number of nlpi variables */
269  SCIP_Real cutoffbound /**< new cutoff bound */
270  );
271 
272 /** adds SCIP_ROWs to a NLPI problem */
273 SCIP_EXPORT
275  SCIP* scip, /**< SCIP data structure */
276  SCIP_NLPI* nlpi, /**< interface to NLP solver */
277  SCIP_NLPIPROBLEM* nlpiprob, /**< nlpi problem */
278  SCIP_HASHMAP* var2idx, /**< empty hash map to store mapping between variables and indices in nlpiprob */
279  SCIP_ROW** rows, /**< rows to add */
280  int nrows /**< number of rows to add */
281  );
282 
283 /** adds SCIP_NLROWs to a NLPI problem */
284 SCIP_EXPORT
286  SCIP* scip, /**< SCIP data structure */
287  SCIP_NLPI* nlpi, /**< interface to NLP solver */
288  SCIP_NLPIPROBLEM* nlpiprob, /**< nlpi problem */
289  SCIP_HASHMAP* var2idx, /**< empty hash map to store mapping between variables and indices in nlpiprob */
290  SCIP_NLROW** nlrows, /**< rows to add */
291  int nnlrows /**< number of rows to add */
292  );
293 
294 /** @} */
295 
296 /** @} */
297 
298 #ifdef __cplusplus
299 }
300 #endif
301 
302 #endif /* __SCIP_SCIP_NLPI_H__ */
SCIP_DECL_NLPICHGCONSSIDES(SCIPchgNlpiConsSides)
Definition: scip_nlpi.c:292
SCIP_DECL_NLPICHGEXPR(SCIPchgNlpiExpr)
Definition: scip_nlpi.c:332
SCIP_DECL_NLPISOLVE(SCIPsolveNlpiParam)
Definition: scip_nlpi.c:376
type definitions for miscellaneous datastructures
SCIP_NLPI * SCIPfindNlpi(SCIP *scip, const char *name)
Definition: scip_nlpi.c:164
SCIP_DECL_NLPICREATEPROBLEM(SCIPcreateNlpiProblem)
Definition: scip_nlpi.c:224
SCIP_DECL_NLPISETOBJECTIVE(SCIPsetNlpiObjective)
Definition: scip_nlpi.c:272
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
SCIP_DECL_NLPICHGVARBOUNDS(SCIPchgNlpiVarBounds)
Definition: scip_nlpi.c:282
SCIP_DECL_NLPISETINITIALGUESS(SCIPsetNlpiInitialGuess)
Definition: scip_nlpi.c:352
SCIP_DECL_NLPIGETSOLSTAT(SCIPgetNlpiSolstat)
Definition: scip_nlpi.c:391
SCIP_NLPI ** SCIPgetNlpis(SCIP *scip)
Definition: scip_nlpi.c:177
SCIP_DECL_NLPIGETSTATISTICS(SCIPgetNlpiStatistics)
Definition: scip_nlpi.c:419
type definitions for LP management
int SCIPgetNNlpis(SCIP *scip)
Definition: scip_nlpi.c:190
SCIP_DECL_NLPIADDCONSTRAINTS(SCIPaddNlpiConstraints)
Definition: scip_nlpi.c:262
struct SCIP_NlpiData SCIP_NLPIDATA
Definition: type_nlpi.h:43
SCIP_RETCODE SCIPupdateNlpiProblem(SCIP *scip, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *nlpiprob, SCIP_HASHMAP *var2nlpiidx, SCIP_VAR **nlpivars, int nlpinvars, SCIP_Real cutoffbound)
Definition: scip_nlpi.c:720
#define SCIP_DECL_NLPICOPY(x)
Definition: type_nlpi.h:206
SCIP_DECL_NLPIGETSOLUTION(SCIPgetNlpiSolution)
Definition: scip_nlpi.c:409
SCIP_DECL_NLPIADDVARS(SCIPaddNlpiVars)
Definition: scip_nlpi.c:252
SCIP_DECL_NLPICHGLINEARCOEFS(SCIPchgNlpiLinearCoefs)
Definition: scip_nlpi.c:322
SCIP_DECL_NLPICHGOBJCONSTANT(SCIPchgNlpiObjConstant)
Definition: scip_nlpi.c:342
SCIP_RETCODE SCIPaddNlpiProblemRows(SCIP *scip, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *nlpiprob, SCIP_HASHMAP *var2idx, SCIP_ROW **rows, int nrows)
Definition: scip_nlpi.c:772
#define SCIP_Bool
Definition: def.h:84
SCIP_DECL_NLPIDELVARSET(SCIPdelNlpiVarSet)
Definition: scip_nlpi.c:302
SCIP_RETCODE SCIPcreateNlpiProblemFromNlRows(SCIP *scip, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM **nlpiprob, const char *name, SCIP_NLROW **nlrows, int nnlrows, SCIP_HASHMAP *var2idx, SCIP_HASHMAP *nlrow2idx, SCIP_Real *nlscore, SCIP_Real cutoffbound, SCIP_Bool setobj, SCIP_Bool onlyconvex)
Definition: scip_nlpi.c:434
public methods for NLP solver interfaces
SCIP_DECL_NLPIDELCONSSET(SCIPdelNlpiConsSet)
Definition: scip_nlpi.c:312
SCIP_DECL_NLPIGETTERMSTAT(SCIPgetNlpiTermstat)
Definition: scip_nlpi.c:399
SCIP_DECL_NLPIFREEPROBLEM(SCIPfreeNlpiProblem)
Definition: scip_nlpi.c:234
SCIP_RETCODE SCIPsetNlpiPriority(SCIP *scip, SCIP_NLPI *nlpi, int priority)
Definition: scip_nlpi.c:201
#define SCIP_DECL_NLPIFREE(x)
Definition: type_nlpi.h:216
#define SCIP_Real
Definition: def.h:177
SCIP_RETCODE SCIPaddNlpiProblemNlRows(SCIP *scip, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *nlpiprob, SCIP_HASHMAP *var2idx, SCIP_NLROW **nlrows, int nnlrows)
Definition: scip_nlpi.c:855
SCIP_RETCODE SCIPincludeNlpi(SCIP *scip, const char *name, const char *description, int priority, SCIP_DECL_NLPICOPY((*nlpicopy)), SCIP_DECL_NLPIFREE((*nlpifree)), SCIP_DECL_NLPIGETSOLVERPOINTER((*nlpigetsolverpointer)), SCIP_DECL_NLPICREATEPROBLEM((*nlpicreateproblem)), SCIP_DECL_NLPIFREEPROBLEM((*nlpifreeproblem)), SCIP_DECL_NLPIGETPROBLEMPOINTER((*nlpigetproblempointer)), SCIP_DECL_NLPIADDVARS((*nlpiaddvars)), SCIP_DECL_NLPIADDCONSTRAINTS((*nlpiaddconstraints)), SCIP_DECL_NLPISETOBJECTIVE((*nlpisetobjective)), SCIP_DECL_NLPICHGVARBOUNDS((*nlpichgvarbounds)), SCIP_DECL_NLPICHGCONSSIDES((*nlpichgconssides)), SCIP_DECL_NLPIDELVARSET((*nlpidelvarset)), SCIP_DECL_NLPIDELCONSSET((*nlpidelconsset)), SCIP_DECL_NLPICHGLINEARCOEFS((*nlpichglinearcoefs)), SCIP_DECL_NLPICHGEXPR((*nlpichgexpr)), SCIP_DECL_NLPICHGOBJCONSTANT((*nlpichgobjconstant)), SCIP_DECL_NLPISETINITIALGUESS((*nlpisetinitialguess)), SCIP_DECL_NLPISOLVE((*nlpisolve)), SCIP_DECL_NLPIGETSOLSTAT((*nlpigetsolstat)), SCIP_DECL_NLPIGETTERMSTAT((*nlpigettermstat)), SCIP_DECL_NLPIGETSOLUTION((*nlpigetsolution)), SCIP_DECL_NLPIGETSTATISTICS((*nlpigetstatistics)), SCIP_NLPIDATA *nlpidata)
Definition: scip_nlpi.c:98
SCIP_DECL_NLPIGETSOLVERPOINTER(SCIPgetNlpiSolverPointer)
Definition: scip_nlpi.c:216
SCIP_DECL_NLPIGETPROBLEMPOINTER(SCIPgetNlpiProblemPointer)
Definition: scip_nlpi.c:244
type definitions for NLP solver interfaces
memory allocation routines