Scippy

SCIP

Solving Constraint Integer Programs

scip_nlpi.c
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-2024 Zuse Institute Berlin (ZIB) */
7 /* */
8 /* Licensed under the Apache License, Version 2.0 (the "License"); */
9 /* you may not use this file except in compliance with the License. */
10 /* You may obtain a copy of the License at */
11 /* */
12 /* http://www.apache.org/licenses/LICENSE-2.0 */
13 /* */
14 /* Unless required by applicable law or agreed to in writing, software */
15 /* distributed under the License is distributed on an "AS IS" BASIS, */
16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17 /* See the License for the specific language governing permissions and */
18 /* limitations under the License. */
19 /* */
20 /* You should have received a copy of the Apache-2.0 license */
21 /* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22 /* */
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 
25 /**@file scip_nlpi.c
26  * @ingroup OTHER_CFILES
27  * @brief public methods for NLP interfaces
28  * @author Stefan Vigerske
29  * @author Thorsten Gellermann
30  *
31  * @todo check SCIP_STAGE_* switches
32  * @todo allow for optional callbacks
33  */
34 
35 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36 
37 #include "scip/scip_nlp.h"
38 #include "blockmemshell/memory.h"
39 #include "scip/scip_expr.h"
40 #include "scip/scip_lp.h"
41 #include "scip/scip_message.h"
42 #include "scip/scip_mem.h"
43 #include "scip/scip_nlpi.h"
44 #include "scip/scip_numerics.h"
45 #include "scip/scip_param.h"
46 #include "scip/scip_prob.h"
47 #include "scip/pub_expr.h"
48 #include "scip/pub_lp.h"
49 #include "scip/pub_var.h"
50 #include "scip/pub_message.h"
51 #include "scip/expr_varidx.h"
52 #include "scip/debug.h"
53 #include "scip/nlpi.h"
54 #include "scip/paramset.h"
55 #include "scip/set.h"
56 #include "scip/struct_scip.h"
57 
58 
59 /** method to call, when the priority of an NLPI was changed */
60 static
61 SCIP_DECL_PARAMCHGD(paramChgdNlpiPriority)
62 { /*lint --e{715}*/
63  SCIP_PARAMDATA* paramdata;
64 
65  paramdata = SCIPparamGetData(param);
66  assert(paramdata != NULL);
67 
68  /* use SCIPsetSetPriorityNlpi() to mark the nlpis unsorted */
70 
71  return SCIP_OKAY;
72 }
73 
74 /** create varidx expression for var expression
75  *
76  * called when expr is duplicated for addition to NLPI
77  */
78 static
79 SCIP_DECL_EXPR_MAPEXPR(mapvar2varidx)
80 {
81  SCIP_HASHMAP* var2idx;
82  int varidx;
83 
84  assert(sourcescip != NULL);
85  assert(sourcescip == targetscip);
86  assert(sourceexpr != NULL);
87  assert(targetexpr != NULL);
88  assert(*targetexpr == NULL);
89  assert(mapexprdata != NULL);
90 
91  /* do not provide map if not variable */
92  if( !SCIPisExprVar(sourcescip, sourceexpr) )
93  return SCIP_OKAY;
94 
95  assert(SCIPvarIsActive(SCIPgetVarExprVar(sourceexpr)));
96 
97  var2idx = (SCIP_HASHMAP*)mapexprdata;
98  assert(SCIPhashmapExists(var2idx, SCIPgetVarExprVar(sourceexpr)));
99 
100  varidx = SCIPhashmapGetImageInt(var2idx, SCIPgetVarExprVar(sourceexpr));
101 
102  SCIP_CALL( SCIPcreateExprVaridx(targetscip, targetexpr, varidx, ownercreate, ownercreatedata) );
103 
104  return SCIP_OKAY;
105 }
106 
107 /** creates an NLPI and includes it into SCIP */
109  SCIP* scip, /**< SCIP data structure */
110  const char* name, /**< name of NLP interface */
111  const char* description, /**< description of NLP interface */
112  int priority, /**< priority of NLP interface */
113  SCIP_DECL_NLPICOPY ((*nlpicopy)), /**< copying an NLPI, can be NULL */
114  SCIP_DECL_NLPIFREE ((*nlpifree)), /**< free NLPI user data */
115  SCIP_DECL_NLPIGETSOLVERPOINTER ((*nlpigetsolverpointer)), /**< get solver pointer, can be NULL */
116  SCIP_DECL_NLPICREATEPROBLEM ((*nlpicreateproblem)), /**< create a new problem instance */
117  SCIP_DECL_NLPIFREEPROBLEM ((*nlpifreeproblem)), /**< free a problem instance */
118  SCIP_DECL_NLPIGETPROBLEMPOINTER ((*nlpigetproblempointer)), /**< get problem pointer, can be NULL */
119  SCIP_DECL_NLPIADDVARS ((*nlpiaddvars)), /**< add variables */
120  SCIP_DECL_NLPIADDCONSTRAINTS ((*nlpiaddconstraints)), /**< add constraints */
121  SCIP_DECL_NLPISETOBJECTIVE ((*nlpisetobjective)), /**< set objective */
122  SCIP_DECL_NLPICHGVARBOUNDS ((*nlpichgvarbounds)), /**< change variable bounds */
123  SCIP_DECL_NLPICHGCONSSIDES ((*nlpichgconssides)), /**< change constraint sides */
124  SCIP_DECL_NLPIDELVARSET ((*nlpidelvarset)), /**< delete a set of constraints */
125  SCIP_DECL_NLPIDELCONSSET ((*nlpidelconsset)), /**< delete a set of constraints */
126  SCIP_DECL_NLPICHGLINEARCOEFS ((*nlpichglinearcoefs)), /**< change coefficients in linear part of a constraint or objective */
127  SCIP_DECL_NLPICHGEXPR ((*nlpichgexpr)), /**< change nonlinear expression a constraint or objective */
128  SCIP_DECL_NLPICHGOBJCONSTANT ((*nlpichgobjconstant)), /**< change the constant offset in the objective */
129  SCIP_DECL_NLPISETINITIALGUESS ((*nlpisetinitialguess)), /**< set initial guess, can be NULL */
130  SCIP_DECL_NLPISOLVE ((*nlpisolve)), /**< solve NLP */
131  SCIP_DECL_NLPIGETSOLSTAT ((*nlpigetsolstat)), /**< get solution status */
132  SCIP_DECL_NLPIGETTERMSTAT ((*nlpigettermstat)), /**< get termination status */
133  SCIP_DECL_NLPIGETSOLUTION ((*nlpigetsolution)), /**< get solution */
134  SCIP_DECL_NLPIGETSTATISTICS ((*nlpigetstatistics)), /**< get solve statistics */
135  SCIP_NLPIDATA* nlpidata /**< NLP interface local data */
136  )
137 {
138  SCIP_NLPI* nlpi = NULL;
140  char paramdesc[SCIP_MAXSTRLEN];
141 
142  assert(scip != NULL);
143 
144  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeNlpi", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
145 
146  /* check whether NLPI of given name is already present */
147  if( SCIPfindNlpi(scip, name) != NULL )
148  {
149  SCIPerrorMessage("NLPI <%s> already included.\n", name);
150  return SCIP_INVALIDDATA;
151  }
152 
153  SCIP_CALL( SCIPnlpiCreate(&nlpi, name, description, priority,
154  nlpicopy, nlpifree, nlpigetsolverpointer,
155  nlpicreateproblem, nlpifreeproblem, nlpigetproblempointer,
156  nlpiaddvars, nlpiaddconstraints, nlpisetobjective, nlpichgvarbounds, nlpichgconssides, nlpidelvarset, nlpidelconsset, nlpichglinearcoefs, nlpichgexpr, nlpichgobjconstant,
157  nlpisetinitialguess, nlpisolve, nlpigetsolstat, nlpigettermstat, nlpigetsolution, nlpigetstatistics,
158  nlpidata) );
159  assert(nlpi != NULL);
160 
161  SCIP_CALL( SCIPsetIncludeNlpi(scip->set, nlpi) );
162 
163  /* add parameters */
164  (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "nlpi/%s/priority", name);
165  (void) SCIPsnprintf(paramdesc, SCIP_MAXSTRLEN, "priority of NLPI <%s>", name);
166  SCIP_CALL( SCIPaddIntParam(scip, paramname, paramdesc,
167  NULL, FALSE, SCIPnlpiGetPriority(nlpi), INT_MIN/4, INT_MAX/4,
168  paramChgdNlpiPriority, (SCIP_PARAMDATA*)nlpi) ); /*lint !e740*/
169 
170  return SCIP_OKAY;
171 }
172 
173 /** returns the NLPI of the given name, or NULL if not existing */
175  SCIP* scip, /**< SCIP data structure */
176  const char* name /**< name of NLPI */
177  )
178 {
179  assert(scip != NULL);
180  assert(scip->set != NULL);
181  assert(name != NULL);
182 
183  return SCIPsetFindNlpi(scip->set, name);
184 }
185 
186 /** returns the array of currently available NLPIs (sorted by priority) */
188  SCIP* scip /**< SCIP data structure */
189  )
190 {
191  assert(scip != NULL);
192  assert(scip->set != NULL);
193 
194  SCIPsetSortNlpis(scip->set);
195 
196  return scip->set->nlpis;
197 }
198 
199 /** returns the number of currently available NLPIs */
201  SCIP* scip /**< SCIP data structure */
202  )
203 {
204  assert(scip != NULL);
205  assert(scip->set != NULL);
206 
207  return scip->set->nnlpis;
208 }
209 
210 /** sets the priority of an NLPI */
212  SCIP* scip, /**< SCIP data structure */
213  SCIP_NLPI* nlpi, /**< NLPI */
214  int priority /**< new priority of the NLPI */
215  )
216 {
217  assert(scip != NULL);
218  assert(scip->set != NULL);
219 
220  SCIPsetSetPriorityNlpi(scip->set, nlpi, priority);
221 
222  return SCIP_OKAY;
223 }
224 
225 /** gets internal pointer to NLP solver */
226 SCIP_DECL_NLPIGETSOLVERPOINTER(SCIPgetNlpiSolverPointer)
227 {
228  assert(scip != NULL);
229 
230  return SCIPnlpiGetSolverPointer(scip->set, nlpi, problem);
231 }
232 
233 /** creates an empty problem instance */
234 SCIP_DECL_NLPICREATEPROBLEM(SCIPcreateNlpiProblem)
235 {
236  assert(scip != NULL);
237 
238  SCIP_CALL( SCIPnlpiCreateProblem(scip->set, nlpi, problem, name) );
239 
240  return SCIP_OKAY;
241 }
242 
243 /** frees a problem instance */
244 SCIP_DECL_NLPIFREEPROBLEM(SCIPfreeNlpiProblem)
245 {
246  assert(scip != NULL);
247 
248  SCIP_CALL( SCIPnlpiFreeProblem(scip->set, nlpi, problem) );
249 
250  return SCIP_OKAY;
251 }
252 
253 /** gets internal pointer to solver-internal problem instance */
254 SCIP_DECL_NLPIGETPROBLEMPOINTER(SCIPgetNlpiProblemPointer)
255 {
256  assert(scip != NULL);
257 
258  return SCIPnlpiGetProblemPointer(scip->set, nlpi, problem);
259 }
260 
261 /** add variables to nlpi */
262 SCIP_DECL_NLPIADDVARS(SCIPaddNlpiVars)
263 {
264  assert(scip != NULL);
265 
266  SCIP_CALL( SCIPnlpiAddVars(scip->set, nlpi, problem, nvars, lbs, ubs, varnames) );
267 
268  return SCIP_OKAY;
269 }
270 
271 /** add constraints to nlpi */
272 SCIP_DECL_NLPIADDCONSTRAINTS(SCIPaddNlpiConstraints)
273 {
274  assert(scip != NULL);
275 
276  SCIP_CALL( SCIPnlpiAddConstraints(scip->set, nlpi, problem, nconss, lhss, rhss, nlininds, lininds, linvals, exprs, names) );
277 
278  return SCIP_OKAY;
279 }
280 
281 /** sets or overwrites objective, a minimization problem is expected */
282 SCIP_DECL_NLPISETOBJECTIVE(SCIPsetNlpiObjective)
283 {
284  assert(scip != NULL);
285 
286  SCIP_CALL( SCIPnlpiSetObjective(scip->set, nlpi, problem, nlins, lininds, linvals, expr, constant) );
287 
288  return SCIP_OKAY;
289 }
290 
291 /** change variable bounds */
292 SCIP_DECL_NLPICHGVARBOUNDS(SCIPchgNlpiVarBounds)
293 {
294  assert(scip != NULL);
295 
296  SCIP_CALL( SCIPnlpiChgVarBounds(scip->set, nlpi, problem, nvars, indices, lbs, ubs) );
297 
298  return SCIP_OKAY;
299 }
300 
301 /** change constraint sides */
302 SCIP_DECL_NLPICHGCONSSIDES(SCIPchgNlpiConsSides)
303 {
304  assert(scip != NULL);
305 
306  SCIP_CALL( SCIPnlpiChgConsSides(scip->set, nlpi, problem, nconss, indices, lhss, rhss) );
307 
308  return SCIP_OKAY;
309 }
310 
311 /** delete a set of variables */
312 SCIP_DECL_NLPIDELVARSET(SCIPdelNlpiVarSet)
313 {
314  assert(scip != NULL);
315 
316  SCIP_CALL( SCIPnlpiDelVarSet(scip->set, nlpi, problem, dstats, dstatssize) );
317 
318  return SCIP_OKAY;
319 }
320 
321 /** delete a set of constraints */
322 SCIP_DECL_NLPIDELCONSSET(SCIPdelNlpiConsSet)
323 {
324  assert(scip != NULL);
325 
326  SCIP_CALL( SCIPnlpiDelConsSet(scip->set, nlpi, problem, dstats, dstatssize) );
327 
328  return SCIP_OKAY;
329 }
330 
331 /** changes or adds linear coefficients in a constraint or objective */
332 SCIP_DECL_NLPICHGLINEARCOEFS(SCIPchgNlpiLinearCoefs)
333 {
334  assert(scip != NULL);
335 
336  SCIP_CALL( SCIPnlpiChgLinearCoefs(scip->set, nlpi, problem, idx, nvals, varidxs, vals) );
337 
338  return SCIP_OKAY;
339 }
340 
341 /** change the expression in the nonlinear part */
342 SCIP_DECL_NLPICHGEXPR(SCIPchgNlpiExpr)
343 {
344  assert(scip != NULL);
345 
346  SCIP_CALL( SCIPnlpiChgExpr(scip->set, nlpi, problem, idxcons, expr) );
347 
348  return SCIP_OKAY;
349 }
350 
351 /** change the constant offset in the objective */
352 SCIP_DECL_NLPICHGOBJCONSTANT(SCIPchgNlpiObjConstant)
353 {
354  assert(scip != NULL);
355 
356  SCIP_CALL( SCIPnlpiChgObjConstant(scip->set, nlpi, problem, objconstant) );
357 
358  return SCIP_OKAY;
359 }
360 
361 /** sets initial guess */
362 SCIP_DECL_NLPISETINITIALGUESS(SCIPsetNlpiInitialGuess)
363 {
364  assert(scip != NULL);
365 
366  SCIP_CALL( SCIPnlpiSetInitialGuess(scip->set, nlpi, problem, primalvalues, consdualvalues, varlbdualvalues, varubdualvalues) );
367 
368  return SCIP_OKAY;
369 }
370 
371 /** try to solve NLP with all parameters given as SCIP_NLPPARAM struct
372  *
373  * Typical use is
374  *
375  * SCIP_NLPPARAM nlparam = { SCIP_NLPPARAM_DEFAULT(scip); }
376  * nlpparam.iterlim = 42;
377  * SCIP_CALL( SCIPsolveNlpiParam(scip, nlpi, nlpiproblem, nlpparam) );
378  *
379  * or, in "one" line:
380  *
381  * SCIP_CALL( SCIPsolveNlpiParam(scip, nlpi, nlpiproblem,
382  * (SCIP_NLPPARAM){ SCIP_NLPPARAM_DEFAULT(scip), .iterlimit = 42 }) );
383  *
384  * To get the latter, also \ref SCIPsolveNlpi can be used.
385  */
386 SCIP_DECL_NLPISOLVE(SCIPsolveNlpiParam)
387 {
388  assert(scip != NULL);
389 
390  SCIP_CALL( SCIPnlpiSolve(scip->set, scip->stat, nlpi, problem, &param) );
391 
392  return SCIP_OKAY;
393 }
394 
395 #if defined(_MSC_VER) && _MSC_VER < 1800
396 /* warn that SCIPsolveNlpi() macro isn't perfect with ancient MSVC */
397 #pragma message ( "Warning: designated initializers not supported by this version of MSVC. Parameters given to NLP solves will be ignored." )
398 #endif
399 
400 /** gives solution status */
401 SCIP_DECL_NLPIGETSOLSTAT(SCIPgetNlpiSolstat)
402 {
403  assert(scip != NULL);
404 
405  return SCIPnlpiGetSolstat(scip->set, nlpi, problem);
406 }
407 
408 /** gives termination reason */
409 SCIP_DECL_NLPIGETTERMSTAT(SCIPgetNlpiTermstat)
410 {
411  assert(scip != NULL);
412 
413  return SCIPnlpiGetTermstat(scip->set, nlpi, problem);
414 }
415 
416 /** gives primal and dual solution
417  * 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
418  */
419 SCIP_DECL_NLPIGETSOLUTION(SCIPgetNlpiSolution)
420 {
421  assert(scip != NULL);
422 
423  SCIP_CALL( SCIPnlpiGetSolution(scip->set, nlpi, problem, primalvalues, consdualvalues, varlbdualvalues, varubdualvalues, objval) );
424 
425  return SCIP_OKAY;
426 }
427 
428 /** gives solve statistics */
429 SCIP_DECL_NLPIGETSTATISTICS(SCIPgetNlpiStatistics)
430 {
431  assert(scip != NULL);
432 
433  SCIP_CALL( SCIPnlpiGetStatistics(scip->set, nlpi, problem, statistics) );
434 
435  return SCIP_OKAY;
436 }
437 
438 /** creates a NLPI problem from given nonlinear rows
439  *
440  * The function computes for each variable the number of non-linear occurrences and stores it in the nlscore array.
441  *
442  * @note the first row corresponds always to the cutoff row (even if cutoffbound is SCIPinfinity(scip))
443  **/
445  SCIP* scip, /**< SCIP data structure */
446  SCIP_NLPI* nlpi, /**< interface to NLP solver */
447  SCIP_NLPIPROBLEM** nlpiprob, /**< buffer to store pointer to created nlpi problem */
448  const char* name, /**< name to give to problem */
449  SCIP_NLROW** nlrows, /**< nonlinear rows */
450  int nnlrows, /**< number of nonlinear rows */
451  SCIP_HASHMAP* var2idx, /**< empty hash map to store mapping between variables and indices in nlpiprob */
452  SCIP_HASHMAP* nlrow2idx, /**< empty hash map to store mapping between variables and indices in nlpiprob, can be NULL */
453  SCIP_Real* nlscore, /**< array to store the score of each nonlinear variable (NULL if not needed) */
454  SCIP_Real cutoffbound, /**< cutoff bound */
455  SCIP_Bool setobj, /**< whether the objective function should be set to one of the SCIP problem */
456  SCIP_Bool onlyconvex /**< filter only for convex constraints */
457  )
458 {
459  SCIP_EXPR** exprs;
460  SCIP_Real** linvals;
461  int** lininds;
462  int* nlininds;
463  SCIP_Real* lhss;
464  SCIP_Real* rhss;
465  const char** names;
466  SCIP_VAR** vars;
467  int nvars;
468  SCIP_Real* lbs;
469  SCIP_Real* ubs;
470  SCIP_Real* objvals = NULL;
471  int* objinds = NULL;
472  const char** varnames;
473  int nobjinds;
474  int nconss;
475  SCIP_EXPRITER* it = NULL;
476  int i;
477 
478  assert(nlpiprob != NULL);
479  assert(name != NULL);
480  assert(var2idx != NULL);
481  assert(nlrows != NULL);
482  assert(nnlrows > 0);
483  assert(nlpi != NULL);
484 
485  SCIPdebugMsg(scip, "SCIPcreateNlpiProblemFromNlRows() called with cutoffbound %g\n", cutoffbound);
486 
487  SCIP_CALL( SCIPnlpiCreateProblem(scip->set, nlpi, nlpiprob, name) );
488 
489  if( nlscore != NULL )
490  {
491  BMSclearMemoryArray(nlscore, SCIPgetNVars(scip));
492  }
493  vars = SCIPgetVars(scip);
494  nvars = SCIPgetNVars(scip);
495  nconss = 0;
496 
497  SCIP_CALL( SCIPallocBufferArray(scip, &exprs, nnlrows + 1) );
498  SCIP_CALL( SCIPallocBufferArray(scip, &linvals, nnlrows + 1) );
499  SCIP_CALL( SCIPallocBufferArray(scip, &lininds, nnlrows + 1) );
500  SCIP_CALL( SCIPallocBufferArray(scip, &nlininds, nnlrows + 1) );
501  SCIP_CALL( SCIPallocBufferArray(scip, &names, nnlrows + 1) );
502  SCIP_CALL( SCIPallocBufferArray(scip, &lhss, nnlrows + 1) );
503  SCIP_CALL( SCIPallocBufferArray(scip, &rhss, nnlrows + 1) );
504 
505  if( setobj )
506  {
507  SCIP_CALL( SCIPallocBufferArray(scip, &objvals, nvars) );
508  SCIP_CALL( SCIPallocBufferArray(scip, &objinds, nvars) );
509  }
510 
511  SCIP_CALL( SCIPallocBufferArray(scip, &lbs, nvars) );
512  SCIP_CALL( SCIPallocBufferArray(scip, &ubs, nvars) );
513  SCIP_CALL( SCIPallocBufferArray(scip, &varnames, nvars) );
514 
515  /* create a unique mapping between variables and {0,..,nvars-1} */
516  nobjinds = 0;
517  for( i = 0; i < nvars; ++i )
518  {
519  assert(vars[i] != NULL);
520  SCIP_CALL( SCIPhashmapInsertInt(var2idx, (void*)vars[i], i) );
521 
522  lbs[i] = SCIPvarGetLbLocal(vars[i]);
523  ubs[i] = SCIPvarGetUbLocal(vars[i]);
524  varnames[i] = SCIPvarGetName(vars[i]);
525 
526  /* collect non-zero objective coefficients */
527  if( setobj && !SCIPisZero(scip, SCIPvarGetObj(vars[i])) )
528  {
529  assert(objvals != NULL);
530  assert(objinds != NULL);
531 
532  objvals[nobjinds] = SCIPvarGetObj(vars[i]);
533  objinds[nobjinds] = i;
534  ++nobjinds;
535  }
536  }
537 
538  /* add variables */
539  SCIP_CALL( SCIPaddNlpiVars(scip, nlpi, *nlpiprob, nvars, lbs, ubs, varnames) );
540  SCIPfreeBufferArray(scip, &varnames);
541  SCIPfreeBufferArray(scip, &ubs);
542  SCIPfreeBufferArray(scip, &lbs);
543 
544  /* set the objective function */
545  if( setobj )
546  {
547  if( nobjinds > 0 )
548  {
549  SCIP_CALL( SCIPsetNlpiObjective(scip, nlpi, *nlpiprob, nobjinds, objinds, objvals, NULL, 0.0) );
550  }
551 
552  SCIPfreeBufferArray(scip, &objinds);
553  SCIPfreeBufferArray(scip, &objvals);
554  }
555 
556  /* add row for cutoff bound even if cutoffbound == SCIPinfinity() */
557  lhss[nconss] = -SCIPinfinity(scip);
558  rhss[nconss] = cutoffbound;
559  names[nconss] = "objcutoff";
560  lininds[nconss] = NULL;
561  linvals[nconss] = NULL;
562  nlininds[nconss] = 0;
563  exprs[nconss] = NULL;
564 
565  SCIP_CALL( SCIPallocBufferArray(scip, &lininds[nconss], nvars) ); /*lint !e866*/
566  SCIP_CALL( SCIPallocBufferArray(scip, &linvals[nconss], nvars) ); /*lint !e866*/
567 
568  for( i = 0; i < nvars; ++i )
569  {
570  if( !SCIPisZero(scip, SCIPvarGetObj(vars[i])) )
571  {
572  linvals[nconss][nlininds[nconss]] = SCIPvarGetObj(vars[i]);
573  lininds[nconss][nlininds[nconss]] = i;
574  ++nlininds[nconss];
575  }
576  }
577  ++nconss;
578 
579  if( nlscore != NULL )
580  {
581  SCIP_CALL( SCIPcreateExpriter(scip, &it) );
582  }
583 
584  /* add convex nonlinear rows to NLPI problem */
585  for( i = 0; i < nnlrows; ++i )
586  {
587  SCIP_Bool userhs;
588  SCIP_Bool uselhs;
589  int k;
590  SCIP_NLROW* nlrow;
591 
592  nlrow = nlrows[i];
593  assert(nlrow != NULL);
594 
595  uselhs = FALSE;
596  userhs = FALSE;
597 
598  /* check curvature together with constraint sides of a nonlinear row */
599  if( SCIPnlrowGetExpr(nlrow) == NULL )
600  {
601  uselhs = TRUE;
602  userhs = TRUE;
603  }
604  else
605  {
606  if( (!onlyconvex || SCIPnlrowGetCurvature(nlrow) == SCIP_EXPRCURV_CONVEX)
607  && !SCIPisInfinity(scip, SCIPnlrowGetRhs(nlrow)) )
608  userhs = TRUE;
609  if( (!onlyconvex || SCIPnlrowGetCurvature(nlrow) == SCIP_EXPRCURV_CONCAVE)
610  && !SCIPisInfinity(scip, SCIPnlrowGetLhs(nlrow)) )
611  uselhs = TRUE;
612  }
613 
614  if( !uselhs && !userhs )
615  continue;
616 
617  lhss[nconss] = uselhs ? SCIPnlrowGetLhs(nlrow) - SCIPnlrowGetConstant(nlrow) : -SCIPinfinity(scip);
618  rhss[nconss] = userhs ? SCIPnlrowGetRhs(nlrow) - SCIPnlrowGetConstant(nlrow) : SCIPinfinity(scip);
619  names[nconss] = SCIPnlrowGetName(nlrow);
620  nlininds[nconss] = 0;
621  lininds[nconss] = NULL;
622  linvals[nconss] = NULL;
623 
624  /* copy linear part */
625  if( SCIPnlrowGetNLinearVars(nlrow) > 0 )
626  {
627  SCIP_VAR* var;
628 
629  nlininds[nconss] = SCIPnlrowGetNLinearVars(nlrow);
630 
631  SCIP_CALL( SCIPallocBufferArray(scip, &lininds[nconss], nlininds[nconss]) ); /*lint !e866*/
632  SCIP_CALL( SCIPallocBufferArray(scip, &linvals[nconss], nlininds[nconss]) ); /*lint !e866*/
633 
634  for( k = 0; k < nlininds[nconss]; ++k )
635  {
636  var = SCIPnlrowGetLinearVars(nlrow)[k];
637  assert(var != NULL);
638  assert(SCIPhashmapExists(var2idx, (void*)var));
639 
640  lininds[nconss][k] = SCIPhashmapGetImageInt(var2idx, (void*)var);
641  assert(var == vars[lininds[nconss][k]]);
642  linvals[nconss][k] = SCIPnlrowGetLinearCoefs(nlrow)[k];
643  }
644  }
645 
646  if( SCIPnlrowGetExpr(nlrow) != NULL )
647  {
648  /* create copy of expr that uses varidx expressions corresponding to variables indices in NLPI */
649  SCIP_CALL( SCIPduplicateExpr(scip, SCIPnlrowGetExpr(nlrow), &exprs[nconss], mapvar2varidx, var2idx, NULL, NULL) );
650  }
651  else
652  {
653  exprs[nconss] = NULL;
654  }
655 
656  /* update nlscore */
657  if( nlscore != NULL && exprs[nconss] != NULL )
658  {
659  SCIP_EXPR* expr;
660  int varidx;
661 
662  SCIP_CALL( SCIPexpriterInit(it, exprs[nconss], SCIP_EXPRITER_DFS, FALSE) );
663  for( expr = exprs[nconss]; !SCIPexpriterIsEnd(it); expr = SCIPexpriterGetNext(it) ) /*lint !e441*/ /*lint !e440*/
664  {
665  if( !SCIPisExprVaridx(scip, expr) )
666  continue;
667 
668  varidx = SCIPgetIndexExprVaridx(expr);
669  assert(varidx >= 0);
670  assert(varidx < nvars);
671 
672  /* update nlscore */
673  nlscore[varidx] += 1.0;
674  }
675  }
676 
677  /* if the row to index hash map is provided, we need to store the row index */
678  if( nlrow2idx != NULL )
679  {
680  SCIP_CALL( SCIPhashmapInsertInt(nlrow2idx, nlrow, nconss) );
681  }
682 
683  ++nconss;
684  }
685  assert(nconss > 0);
686 
687  /* pass all constraint information to nlpi */
688  SCIP_CALL( SCIPaddNlpiConstraints(scip, nlpi, *nlpiprob, nconss, lhss, rhss, nlininds, lininds, linvals,
689  exprs, names) );
690 
691  if( it != NULL )
692  {
693  SCIPfreeExpriter(&it);
694  }
695 
696  /* free memory */
697  for( i = nconss - 1; i > 0; --i )
698  {
699  if( nlininds[i] > 0 )
700  {
701  assert(linvals[i] != NULL);
702  assert(lininds[i] != NULL);
703  SCIPfreeBufferArray(scip, &linvals[i]);
704  SCIPfreeBufferArray(scip, &lininds[i]);
705  }
706  if( exprs[i] != NULL )
707  {
708  SCIP_CALL( SCIPreleaseExpr(scip, &exprs[i]) );
709  }
710  }
711  /* free row for cutoff bound even if objective is 0 */
712  SCIPfreeBufferArray(scip, &linvals[i]);
713  SCIPfreeBufferArray(scip, &lininds[i]);
714 
715  SCIPfreeBufferArray(scip, &rhss);
716  SCIPfreeBufferArray(scip, &lhss);
717  SCIPfreeBufferArray(scip, &names);
718  SCIPfreeBufferArray(scip, &nlininds);
719  SCIPfreeBufferArray(scip, &lininds);
720  SCIPfreeBufferArray(scip, &linvals);
721  SCIPfreeBufferArray(scip, &exprs);
722 
723  return SCIP_OKAY;
724 }
725 
726 /** updates variable bounds and the cutoff row in a NLPI problem
727  *
728  * The NLPI problem must have been setup by SCIPcreateNlpiProblemFromNlRows().
729  */
731  SCIP* scip, /**< SCIP data structure */
732  SCIP_NLPI* nlpi, /**< interface to NLP solver */
733  SCIP_NLPIPROBLEM* nlpiprob, /**< nlpi problem representing the convex NLP relaxation */
734  SCIP_HASHMAP* var2nlpiidx, /**< mapping between variables and nlpi indices */
735  SCIP_VAR** nlpivars, /**< array containing all variables of the nlpi */
736  int nlpinvars, /**< total number of nlpi variables */
737  SCIP_Real cutoffbound /**< new cutoff bound */
738  )
739 {
740  SCIP_Real* lbs;
741  SCIP_Real* ubs;
742  SCIP_Real lhs;
743  SCIP_Real rhs;
744  int* inds;
745  int i;
746 
747  SCIPdebugMsg(scip, "SCIPupdateNlpiProblem() called\n");
748 
749  /* update variable bounds */
750  SCIP_CALL( SCIPallocBufferArray(scip, &lbs, nlpinvars) );
751  SCIP_CALL( SCIPallocBufferArray(scip, &ubs, nlpinvars) );
752  SCIP_CALL( SCIPallocBufferArray(scip, &inds, nlpinvars) );
753 
754  for( i = 0; i < nlpinvars; ++i )
755  {
756  assert(nlpivars[i] != NULL);
757  assert(SCIPhashmapExists(var2nlpiidx, (void*)nlpivars[i]));
758 
759  lbs[i] = SCIPvarGetLbLocal(nlpivars[i]);
760  ubs[i] = SCIPvarGetUbLocal(nlpivars[i]);
761  inds[i] = SCIPhashmapGetImageInt(var2nlpiidx, (void*)nlpivars[i]);
762  assert(inds[i] >= 0 && inds[i] < nlpinvars);
763  }
764 
765  SCIP_CALL( SCIPchgNlpiVarBounds(scip, nlpi, nlpiprob, nlpinvars, inds, lbs, ubs) );
766 
767  SCIPfreeBufferArray(scip, &inds);
768  SCIPfreeBufferArray(scip, &ubs);
769  SCIPfreeBufferArray(scip, &lbs);
770 
771  /* update cutoff row */
772  lhs = -SCIPinfinity(scip);
773  rhs = cutoffbound;
774  i = 0;
775 
776  SCIP_CALL( SCIPchgNlpiConsSides(scip, nlpi, nlpiprob, 1, &i, &lhs, &rhs) );
777 
778  return SCIP_OKAY;
779 }
780 
781 /** adds SCIP_ROWs to a NLPI problem */
783  SCIP* scip, /**< SCIP data structure */
784  SCIP_NLPI* nlpi, /**< interface to NLP solver */
785  SCIP_NLPIPROBLEM* nlpiprob, /**< nlpi problem */
786  SCIP_HASHMAP* var2idx, /**< empty hash map to store mapping between variables and indices in nlpiprob */
787  SCIP_ROW** rows, /**< rows to add */
788  int nrows /**< number of rows to add */
789  )
790 {
791  const char** names;
792  SCIP_Real* lhss;
793  SCIP_Real* rhss;
794  SCIP_Real** linvals;
795  int** lininds;
796  int* nlininds;
797  int i;
798 
799  assert(nlpi != NULL);
800  assert(nlpiprob != NULL);
801  assert(var2idx != NULL);
802  assert(nrows == 0 || rows != NULL);
803 
804  SCIPdebugMsg(scip, "SCIPaddNlpiProblemRows() called with %d rows\n", nrows);
805 
806  if( nrows <= 0 )
807  return SCIP_OKAY;
808 
809  SCIP_CALL( SCIPallocBufferArray(scip, &names, nrows) );
810  SCIP_CALL( SCIPallocBufferArray(scip, &lhss, nrows) );
811  SCIP_CALL( SCIPallocBufferArray(scip, &rhss, nrows) );
812  SCIP_CALL( SCIPallocBufferArray(scip, &linvals, nrows) );
813  SCIP_CALL( SCIPallocBufferArray(scip, &lininds, nrows) );
814  SCIP_CALL( SCIPallocBufferArray(scip, &nlininds, nrows) );
815 
816  for( i = 0; i < nrows; ++i )
817  {
818  int k;
819 
820  assert(rows[i] != NULL);
821  assert(SCIProwGetNNonz(rows[i]) <= SCIPgetNVars(scip));
822 
823  names[i] = SCIProwGetName(rows[i]);
824  lhss[i] = SCIProwGetLhs(rows[i]) - SCIProwGetConstant(rows[i]);
825  rhss[i] = SCIProwGetRhs(rows[i]) - SCIProwGetConstant(rows[i]);
826  nlininds[i] = SCIProwGetNNonz(rows[i]);
827  linvals[i] = SCIProwGetVals(rows[i]);
828  lininds[i] = NULL;
829 
830  SCIP_CALL( SCIPallocBufferArray(scip, &lininds[i], SCIProwGetNNonz(rows[i])) ); /*lint !e866*/
831 
832  for( k = 0; k < SCIProwGetNNonz(rows[i]); ++k )
833  {
834  SCIP_VAR* var;
835 
836  var = SCIPcolGetVar(SCIProwGetCols(rows[i])[k]);
837  assert(var != NULL);
838  assert(SCIPhashmapExists(var2idx, (void*)var));
839 
840  lininds[i][k] = SCIPhashmapGetImageInt(var2idx, (void*)var);
841  assert(lininds[i][k] >= 0 && lininds[i][k] < SCIPgetNVars(scip));
842  }
843  }
844 
845  /* pass all linear rows to the nlpi */
846  SCIP_CALL( SCIPaddNlpiConstraints(scip, nlpi, nlpiprob, nrows, lhss, rhss, nlininds, lininds, linvals,
847  NULL, names) );
848 
849  /* free memory */
850  for( i = nrows - 1; i >= 0; --i )
851  {
852  SCIPfreeBufferArray(scip, &lininds[i]);
853  }
854  SCIPfreeBufferArray(scip, &nlininds);
855  SCIPfreeBufferArray(scip, &lininds);
856  SCIPfreeBufferArray(scip, &linvals);
857  SCIPfreeBufferArray(scip, &rhss);
858  SCIPfreeBufferArray(scip, &lhss);
859  SCIPfreeBufferArray(scip, &names);
860 
861  return SCIP_OKAY;
862 }
863 
864 /** adds SCIP_NLROWs to a NLPI problem */
866  SCIP* scip, /**< SCIP data structure */
867  SCIP_NLPI* nlpi, /**< interface to NLP solver */
868  SCIP_NLPIPROBLEM* nlpiprob, /**< nlpi problem */
869  SCIP_HASHMAP* var2idx, /**< empty hash map to store mapping between variables and indices in nlpiprob */
870  SCIP_NLROW** nlrows, /**< rows to add */
871  int nnlrows /**< number of rows to add */
872  )
873 {
874  const char** names;
875  SCIP_Real* lhss;
876  SCIP_Real* rhss;
877  SCIP_Real** linvals;
878  int** lininds;
879  int* nlininds;
880  SCIP_EXPR** exprs;
881  int i;
882 
883  assert(nlpi != NULL);
884  assert(nlpiprob != NULL);
885  assert(var2idx != NULL);
886  assert(nnlrows == 0 || nlrows != NULL);
887 
888  SCIPdebugMsg(scip, "SCIPaddNlpiProblemNlRows() called with %d rows\n", nnlrows);
889 
890  if( nnlrows <= 0 )
891  return SCIP_OKAY;
892 
893  SCIP_CALL( SCIPallocBufferArray(scip, &names, nnlrows) );
894  SCIP_CALL( SCIPallocBufferArray(scip, &lhss, nnlrows) );
895  SCIP_CALL( SCIPallocBufferArray(scip, &rhss, nnlrows) );
896  SCIP_CALL( SCIPallocBufferArray(scip, &linvals, nnlrows) );
897  SCIP_CALL( SCIPallocBufferArray(scip, &lininds, nnlrows) );
898  SCIP_CALL( SCIPallocBufferArray(scip, &nlininds, nnlrows) );
899  SCIP_CALL( SCIPallocBufferArray(scip, &exprs, nnlrows) );
900 
901  for( i = 0; i < nnlrows; ++i )
902  {
903  SCIP_NLROW* nlrow;
904 
905  nlrow = nlrows[i];
906  assert(nlrow != NULL);
907 
908  lhss[i] = !SCIPisInfinity(scip, -SCIPnlrowGetLhs(nlrow)) ? SCIPnlrowGetLhs(nlrow) - SCIPnlrowGetConstant(nlrow) : -SCIPinfinity(scip);
909  rhss[i] = !SCIPisInfinity(scip, SCIPnlrowGetRhs(nlrow)) ? SCIPnlrowGetRhs(nlrow) - SCIPnlrowGetConstant(nlrow) : SCIPinfinity(scip);
910  names[i] = SCIPnlrowGetName(nlrow);
911  nlininds[i] = 0;
912  lininds[i] = NULL;
913  linvals[i] = NULL;
914 
915  /* copy linear part */
916  if( SCIPnlrowGetNLinearVars(nlrow) > 0 )
917  {
918  SCIP_VAR* var;
919  int k;
920 
921  nlininds[i] = SCIPnlrowGetNLinearVars(nlrow);
922 
923  SCIP_CALL( SCIPallocBufferArray(scip, &lininds[i], nlininds[i]) ); /*lint !e866*/
924  SCIP_CALL( SCIPallocBufferArray(scip, &linvals[i], nlininds[i]) ); /*lint !e866*/
925 
926  for( k = 0; k < nlininds[i]; ++k )
927  {
928  var = SCIPnlrowGetLinearVars(nlrow)[k];
929  assert(var != NULL);
930  assert(SCIPhashmapExists(var2idx, (void*)var));
931 
932  lininds[i][k] = SCIPhashmapGetImageInt(var2idx, (void*)var);
933  linvals[i][k] = SCIPnlrowGetLinearCoefs(nlrow)[k];
934  }
935  }
936 
937  if( SCIPnlrowGetExpr(nlrow) != NULL )
938  {
939  /* create copy of expr that uses varidx expressions corresponding to variables indices in NLPI */
940  SCIP_CALL( SCIPduplicateExpr(scip, SCIPnlrowGetExpr(nlrow), &exprs[i], mapvar2varidx, var2idx, NULL, NULL) );
941  }
942  else
943  {
944  exprs[i] = NULL;
945  }
946  }
947 
948  /* pass all rows to the nlpi */
949  SCIP_CALL( SCIPaddNlpiConstraints(scip, nlpi, nlpiprob, nnlrows, lhss, rhss, nlininds, lininds, linvals, exprs, names) );
950 
951  /* free memory */
952  for( i = nnlrows - 1; i >= 0; --i )
953  {
954  SCIPfreeBufferArrayNull(scip, &linvals[i]);
955  SCIPfreeBufferArrayNull(scip, &lininds[i]);
956  if( exprs[i] != NULL )
957  {
958  SCIP_CALL( SCIPreleaseExpr(scip, &exprs[i]) );
959  }
960  }
961  SCIPfreeBufferArray(scip, &exprs);
962  SCIPfreeBufferArray(scip, &nlininds);
963  SCIPfreeBufferArray(scip, &lininds);
964  SCIPfreeBufferArray(scip, &linvals);
965  SCIPfreeBufferArray(scip, &rhss);
966  SCIPfreeBufferArray(scip, &lhss);
967  SCIPfreeBufferArray(scip, &names);
968 
969  return SCIP_OKAY;
970 }
int SCIPnlpiGetPriority(SCIP_NLPI *nlpi)
Definition: nlpi.c:742
SCIP_STAT * stat
Definition: struct_scip.h:80
SCIP_DECL_NLPICHGCONSSIDES(SCIPchgNlpiConsSides)
Definition: scip_nlpi.c:302
SCIP_DECL_NLPICHGEXPR(SCIPchgNlpiExpr)
Definition: scip_nlpi.c:342
SCIP_DECL_NLPISOLVE(SCIPsolveNlpiParam)
Definition: scip_nlpi.c:386
#define NULL
Definition: def.h:267
SCIP_RETCODE SCIPexpriterInit(SCIP_EXPRITER *iterator, SCIP_EXPR *expr, SCIP_EXPRITER_TYPE type, SCIP_Bool allowrevisit)
Definition: expriter.c:501
public methods for SCIP parameter handling
SCIP_NLPI * SCIPfindNlpi(SCIP *scip, const char *name)
Definition: scip_nlpi.c:174
SCIP_NLPI * SCIPsetFindNlpi(SCIP_SET *set, const char *name)
Definition: set.c:5235
SCIP_DECL_NLPICREATEPROBLEM(SCIPcreateNlpiProblem)
Definition: scip_nlpi.c:234
public methods for memory management
SCIP_PARAMDATA * SCIPparamGetData(SCIP_PARAM *param)
Definition: paramset.c:679
#define SCIP_MAXSTRLEN
Definition: def.h:288
static SCIP_DECL_EXPR_MAPEXPR(mapvar2varidx)
Definition: scip_nlpi.c:79
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:17213
struct SCIP_ParamData SCIP_PARAMDATA
Definition: type_paramset.h:87
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:18135
internal methods for NLP solver interfaces
SCIP_RETCODE SCIPnlpiChgObjConstant(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, SCIP_Real objconstant)
Definition: nlpi.c:508
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:17351
SCIP_VAR ** SCIPnlrowGetLinearVars(SCIP_NLROW *nlrow)
Definition: nlp.c:1877
void * SCIPnlpiGetSolverPointer(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem)
Definition: nlpi.c:228
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:17292
#define FALSE
Definition: def.h:94
const char * SCIPnlrowGetName(SCIP_NLROW *nlrow)
Definition: nlp.c:1936
SCIP_RETCODE SCIPduplicateExpr(SCIP *scip, SCIP_EXPR *expr, SCIP_EXPR **copyexpr, SCIP_DECL_EXPR_MAPEXPR((*mapexpr)), void *mapexprdata, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
Definition: scip_expr.c:1281
SCIP_DECL_NLPISETOBJECTIVE(SCIPsetNlpiObjective)
Definition: scip_nlpi.c:282
SCIP_Real SCIPinfinity(SCIP *scip)
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10877
#define TRUE
Definition: def.h:93
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
SCIP_DECL_NLPICHGVARBOUNDS(SCIPchgNlpiVarBounds)
Definition: scip_nlpi.c:292
SCIP_RETCODE SCIPhashmapInsertInt(SCIP_HASHMAP *hashmap, void *origin, int image)
Definition: misc.c:3192
SCIP_RETCODE SCIPnlpiGetSolution(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, SCIP_Real **primalvalues, SCIP_Real **consdualvalues, SCIP_Real **varlbdualvalues, SCIP_Real **varubdualvalues, SCIP_Real *objval)
Definition: nlpi.c:653
SCIP_Real SCIPnlrowGetRhs(SCIP_NLROW *nlrow)
Definition: nlp.c:1917
SCIP_RETCODE SCIPnlpiAddConstraints(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, int nconss, const SCIP_Real *lhss, const SCIP_Real *rhss, const int *nlininds, int *const *lininds, SCIP_Real *const *linvals, SCIP_EXPR **exprs, const char **names)
Definition: nlpi.c:325
int SCIPnlrowGetNLinearVars(SCIP_NLROW *nlrow)
Definition: nlp.c:1867
SCIP_DECL_NLPISETINITIALGUESS(SCIPsetNlpiInitialGuess)
Definition: scip_nlpi.c:362
public methods for problem variables
SCIP_RETCODE SCIPsetIncludeNlpi(SCIP_SET *set, SCIP_NLPI *nlpi)
Definition: set.c:5212
SCIP_DECL_NLPIGETSOLSTAT(SCIPgetNlpiSolstat)
Definition: scip_nlpi.c:401
SCIP_EXPRCURV SCIPnlrowGetCurvature(SCIP_NLROW *nlrow)
Definition: nlp.c:1927
SCIP_NLPI ** SCIPgetNlpis(SCIP *scip)
Definition: scip_nlpi.c:187
internal methods for handling parameter settings
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:136
#define SCIPdebugMsg
Definition: scip_message.h:78
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:83
SCIP_NLPTERMSTAT SCIPnlpiGetTermstat(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem)
Definition: nlpi.c:636
SCIP_DECL_NLPIGETSTATISTICS(SCIPgetNlpiStatistics)
Definition: scip_nlpi.c:429
SCIP_RETCODE SCIPnlpiChgVarBounds(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, const int nvars, const int *indices, const SCIP_Real *lbs, const SCIP_Real *ubs)
Definition: nlpi.c:376
static SCIP_DECL_PARAMCHGD(paramChgdNlpiPriority)
Definition: scip_nlpi.c:61
SCIP_RETCODE SCIPnlpiAddVars(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, int nvars, const SCIP_Real *lbs, const SCIP_Real *ubs, const char **varnames)
Definition: nlpi.c:302
public methods for numerical tolerances
public functions to work with algebraic expressions
SCIP_Bool SCIPhashmapExists(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3423
SCIP_NLPI ** nlpis
Definition: struct_set.h:108
int SCIPgetNNlpis(SCIP *scip)
Definition: scip_nlpi.c:200
SCIP_RETCODE SCIPnlpiGetStatistics(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, SCIP_NLPSTATISTICS *statistics)
Definition: nlpi.c:675
public methods for NLPI solver interfaces
SCIP_RETCODE SCIPnlpiSetInitialGuess(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, SCIP_Real *primalvalues, SCIP_Real *consdualvalues, SCIP_Real *varlbdualvalues, SCIP_Real *varubdualvalues)
Definition: nlpi.c:528
void SCIPsetSetPriorityNlpi(SCIP_SET *set, SCIP_NLPI *nlpi, int priority)
Definition: set.c:5269
handler for variable index expressions
#define SCIPerrorMessage
Definition: pub_message.h:64
SCIP_DECL_NLPIADDCONSTRAINTS(SCIPaddNlpiConstraints)
Definition: scip_nlpi.c:272
struct SCIP_NlpiData SCIP_NLPIDATA
Definition: type_nlpi.h:52
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:730
SCIP_VAR * SCIPgetVarExprVar(SCIP_EXPR *expr)
Definition: expr_var.c:416
SCIP_RETCODE SCIPcheckStage(SCIP *scip, const char *method, SCIP_Bool init, SCIP_Bool problem, SCIP_Bool transforming, SCIP_Bool transformed, SCIP_Bool initpresolve, SCIP_Bool presolving, SCIP_Bool exitpresolve, SCIP_Bool presolved, SCIP_Bool initsolve, SCIP_Bool solving, SCIP_Bool solved, SCIP_Bool exitsolve, SCIP_Bool freetrans, SCIP_Bool freescip)
Definition: debug.c:2208
#define SCIPfreeBufferArrayNull(scip, ptr)
Definition: scip_mem.h:137
public functions to work with algebraic expressions
#define SCIP_DECL_NLPICOPY(x)
Definition: type_nlpi.h:215
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:17420
SCIP_DECL_NLPIGETSOLUTION(SCIPgetNlpiSolution)
Definition: scip_nlpi.c:419
SCIP_DECL_NLPIADDVARS(SCIPaddNlpiVars)
Definition: scip_nlpi.c:262
SCIP_DECL_NLPICHGLINEARCOEFS(SCIPchgNlpiLinearCoefs)
Definition: scip_nlpi.c:332
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:380
SCIP main data structure.
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:17302
SCIP_RETCODE SCIPnlpiCreate(SCIP_NLPI **nlpi, 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: nlpi.c:53
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
Definition: lp.c:17238
SCIP_RETCODE SCIPcreateExpriter(SCIP *scip, SCIP_EXPRITER **iterator)
Definition: scip_expr.c:2337
SCIP_DECL_NLPICHGOBJCONSTANT(SCIPchgNlpiObjConstant)
Definition: scip_nlpi.c:352
SCIP_RETCODE SCIPaddNlpiProblemRows(SCIP *scip, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *nlpiprob, SCIP_HASHMAP *var2idx, SCIP_ROW **rows, int nrows)
Definition: scip_nlpi.c:782
SCIP_RETCODE SCIPnlpiFreeProblem(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM **problem)
Definition: nlpi.c:266
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:124
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
Definition: lp.c:17248
#define SCIP_Bool
Definition: def.h:91
SCIP_DECL_NLPIDELVARSET(SCIPdelNlpiVarSet)
Definition: scip_nlpi.c:312
SCIP_RETCODE SCIPnlpiChgExpr(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, int idxcons, SCIP_EXPR *expr)
Definition: nlpi.c:487
static const char * paramname[]
Definition: lpi_msk.c:5096
SCIP_RETCODE SCIPreleaseExpr(SCIP *scip, SCIP_EXPR **expr)
Definition: scip_expr.c:1417
void SCIPsetSortNlpis(SCIP_SET *set)
Definition: set.c:5255
methods for debugging
public methods for LP management
SCIP_RETCODE SCIPnlpiChgLinearCoefs(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, int idx, int nvals, const int *varidxs, const SCIP_Real *vals)
Definition: nlpi.c:464
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17927
SCIP_EXPR * SCIPexpriterGetNext(SCIP_EXPRITER *iterator)
Definition: expriter.c:858
SCIP_RETCODE SCIPnlpiDelVarSet(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, int *dstats, int dstatssize)
Definition: nlpi.c:422
SCIP_RETCODE SCIPnlpiCreateProblem(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM **problem, const char *name)
Definition: nlpi.c:244
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:444
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
public methods for the LP relaxation, rows and columns
SCIP_DECL_NLPIDELCONSSET(SCIPdelNlpiConsSet)
Definition: scip_nlpi.c:322
SCIP_DECL_NLPIGETTERMSTAT(SCIPgetNlpiTermstat)
Definition: scip_nlpi.c:409
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:1992
int SCIPparamGetInt(SCIP_PARAM *param)
Definition: paramset.c:734
SCIP_DECL_NLPIFREEPROBLEM(SCIPfreeNlpiProblem)
Definition: scip_nlpi.c:244
void SCIPfreeExpriter(SCIP_EXPRITER **iterator)
Definition: scip_expr.c:2351
public methods for nonlinear relaxation
SCIP_Real * SCIPnlrowGetLinearCoefs(SCIP_NLROW *nlrow)
Definition: nlp.c:1887
SCIP_Real SCIProwGetConstant(SCIP_ROW *row)
Definition: lp.c:17258
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:17042
SCIP_RETCODE SCIPnlpiChgConsSides(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, int nconss, const int *indices, const SCIP_Real *lhss, const SCIP_Real *rhss)
Definition: nlpi.c:399
SCIP_NLPSOLSTAT SCIPnlpiGetSolstat(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem)
Definition: nlpi.c:621
SCIP_RETCODE SCIPsetNlpiPriority(SCIP *scip, SCIP_NLPI *nlpi, int priority)
Definition: scip_nlpi.c:211
SCIP_SET * set
Definition: struct_scip.h:73
public methods for message output
SCIP_Bool SCIPisExprVaridx(SCIP *scip, SCIP_EXPR *expr)
Definition: expr_varidx.c:252
SCIP_Bool SCIPisExprVar(SCIP *scip, SCIP_EXPR *expr)
Definition: scip_expr.c:1431
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip_prob.c:1947
#define SCIP_DECL_NLPIFREE(x)
Definition: type_nlpi.h:225
SCIP_RETCODE SCIPnlpiSolve(SCIP_SET *set, SCIP_STAT *stat, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, SCIP_NLPPARAM *param)
Definition: nlpi.c:551
#define SCIP_Real
Definition: def.h:173
public methods for message handling
int nnlpis
Definition: struct_set.h:153
SCIP_RETCODE SCIPaddNlpiProblemNlRows(SCIP *scip, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *nlpiprob, SCIP_HASHMAP *var2idx, SCIP_NLROW **nlrows, int nnlrows)
Definition: scip_nlpi.c:865
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:18145
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:108
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:130
SCIP_RETCODE SCIPnlpiDelConsSet(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, int *dstats, int dstatssize)
Definition: nlpi.c:443
SCIP_Bool SCIPexpriterIsEnd(SCIP_EXPRITER *iterator)
Definition: expriter.c:969
void * SCIPnlpiGetProblemPointer(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem)
Definition: nlpi.c:285
SCIP_Real SCIPnlrowGetConstant(SCIP_NLROW *nlrow)
Definition: nlp.c:1857
int SCIPhashmapGetImageInt(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3281
SCIP_DECL_NLPIGETSOLVERPOINTER(SCIPgetNlpiSolverPointer)
Definition: scip_nlpi.c:226
SCIP_Real SCIPnlrowGetLhs(SCIP_NLROW *nlrow)
Definition: nlp.c:1907
public methods for global and local (sub)problems
int SCIPgetIndexExprVaridx(SCIP_EXPR *expr)
Definition: expr_varidx.c:267
SCIP_RETCODE SCIPcreateExprVaridx(SCIP *scip, SCIP_EXPR **expr, int varidx, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
Definition: expr_varidx.c:220
SCIP_RETCODE SCIPnlpiSetObjective(SCIP_SET *set, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, int nlins, const int *lininds, const SCIP_Real *linvals, SCIP_EXPR *expr, const SCIP_Real constant)
Definition: nlpi.c:352
SCIP_EXPR * SCIPnlrowGetExpr(SCIP_NLROW *nlrow)
Definition: nlp.c:1897
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
Definition: var.c:17749
SCIP_DECL_NLPIGETPROBLEMPOINTER(SCIPgetNlpiProblemPointer)
Definition: scip_nlpi.c:254
memory allocation routines