Scippy

SCIP

Solving Constraint Integer Programs

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-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.c
17  * @brief methods for handling nlp interface
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 #include <stdio.h>
25 #include <assert.h>
26 #include <string.h>
27 
28 #include "scip/pub_message.h"
29 #include "nlpi/nlpi.h"
30 #include "nlpi/struct_nlpi.h"
31 #include "blockmemshell/memory.h"
32 
33 /** compares two NLPIs w.r.t. their priority */
34 SCIP_DECL_SORTPTRCOMP(SCIPnlpiComp)
35 { /*lint --e{715}*/
36  return ((SCIP_NLPI*)elem2)->priority - ((SCIP_NLPI*)elem1)->priority;
37 }
38 
39 /** creates an NLP solver interface */
41  SCIP_NLPI** nlpi, /**< pointer to NLP interface data structure */
42  const char* name, /**< name of NLP interface */
43  const char* description, /**< description of NLP interface */
44  int priority, /**< priority of NLP interface */
45  SCIP_DECL_NLPICOPY ((*nlpicopy)), /**< copying an NLPI */
46  SCIP_DECL_NLPIFREE ((*nlpifree)), /**< free NLPI user data */
47  SCIP_DECL_NLPIGETSOLVERPOINTER ((*nlpigetsolverpointer)), /**< get solver pointer */
48  SCIP_DECL_NLPICREATEPROBLEM ((*nlpicreateproblem)), /**< create a new problem instance */
49  SCIP_DECL_NLPIFREEPROBLEM ((*nlpifreeproblem)), /**< free a problem instance */
50  SCIP_DECL_NLPIGETPROBLEMPOINTER ((*nlpigetproblempointer)), /**< get problem pointer */
51  SCIP_DECL_NLPIADDVARS ((*nlpiaddvars)), /**< add variables */
52  SCIP_DECL_NLPIADDCONSTRAINTS ((*nlpiaddconstraints)), /**< add constraints */
53  SCIP_DECL_NLPISETOBJECTIVE ((*nlpisetobjective)), /**< set objective */
54  SCIP_DECL_NLPICHGVARBOUNDS ((*nlpichgvarbounds)), /**< change variable bounds */
55  SCIP_DECL_NLPICHGCONSSIDES ((*nlpichgconssides)), /**< change constraint sides */
56  SCIP_DECL_NLPIDELVARSET ((*nlpidelvarset)), /**< delete a set of constraints */
57  SCIP_DECL_NLPIDELCONSSET ((*nlpidelconsset)), /**< delete a set of constraints */
58  SCIP_DECL_NLPICHGLINEARCOEFS ((*nlpichglinearcoefs)), /**< change coefficients in linear part of a constraint or objective */
59  SCIP_DECL_NLPICHGQUADCOEFS ((*nlpichgquadcoefs)), /**< change coefficients in quadratic part of a constraint or objective */
60  SCIP_DECL_NLPICHGEXPRTREE ((*nlpichgexprtree)), /**< change nonlinear expression a constraint or objective */
61  SCIP_DECL_NLPICHGNONLINCOEF ((*nlpichgnonlincoef)), /**< change one parameter in nonlinear expressions of a constraint or objective */
62  SCIP_DECL_NLPICHGOBJCONSTANT ((*nlpichgobjconstant)), /**< change the constant offset in the objective */
63  SCIP_DECL_NLPISETINITIALGUESS ((*nlpisetinitialguess)), /**< set initial guess for primal variables */
64  SCIP_DECL_NLPISOLVE ((*nlpisolve)), /**< solve NLP */
65  SCIP_DECL_NLPIGETSOLSTAT ((*nlpigetsolstat)), /**< get solution status */
66  SCIP_DECL_NLPIGETTERMSTAT ((*nlpigettermstat)), /**< get termination status */
67  SCIP_DECL_NLPIGETSOLUTION ((*nlpigetsolution)), /**< get solution */
68  SCIP_DECL_NLPIGETSTATISTICS ((*nlpigetstatistics)), /**< get solve statistics */
69  SCIP_DECL_NLPIGETWARMSTARTSIZE ((*nlpigetwarmstartsize)), /**< get size for warmstart object buffer */
70  SCIP_DECL_NLPIGETWARMSTARTMEMO ((*nlpigetwarmstartmemo)), /**< get warmstart object */
71  SCIP_DECL_NLPISETWARMSTARTMEMO ((*nlpisetwarmstartmemo)), /**< set warmstart object */
72  SCIP_DECL_NLPIGETINTPAR ((*nlpigetintpar)), /**< get value of integer parameter */
73  SCIP_DECL_NLPISETINTPAR ((*nlpisetintpar)), /**< set value of integer parameter */
74  SCIP_DECL_NLPIGETREALPAR ((*nlpigetrealpar)), /**< get value of floating point parameter */
75  SCIP_DECL_NLPISETREALPAR ((*nlpisetrealpar)), /**< set value of floating point parameter */
76  SCIP_DECL_NLPIGETSTRINGPAR ((*nlpigetstringpar)), /**< get value of string parameter */
77  SCIP_DECL_NLPISETSTRINGPAR ((*nlpisetstringpar)), /**< set value of string parameter */
78  SCIP_DECL_NLPISETMESSAGEHDLR ((*nlpisetmessagehdlr)), /**< set message handler */
79  SCIP_NLPIDATA* nlpidata /**< NLP interface local data */
80  )
81 { /*lint --e{715}*/
82  assert(nlpi != NULL);
83 
84  assert(name != NULL);
85  assert(description != NULL);
86  assert(nlpicopy != NULL);
87  assert(nlpifree != NULL);
88  assert(nlpigetsolverpointer != NULL);
89  assert(nlpicreateproblem != NULL);
90  assert(nlpifreeproblem != NULL);
91  assert(nlpigetproblempointer != NULL);
92  assert(nlpiaddvars != NULL);
93  assert(nlpiaddconstraints != NULL);
94  assert(nlpisetobjective != NULL);
95  assert(nlpichgvarbounds != NULL);
96  assert(nlpichgconssides != NULL);
97  assert(nlpidelconsset != NULL);
98  assert(nlpichglinearcoefs != NULL);
99  assert(nlpichgquadcoefs != NULL);
100  assert(nlpichgexprtree != NULL);
101  assert(nlpichgnonlincoef != NULL);
102  assert(nlpichgobjconstant != NULL);
103  assert(nlpisetinitialguess != NULL);
104  assert(nlpisolve != NULL);
105  assert(nlpigetsolstat != NULL);
106  assert(nlpigettermstat != NULL);
107  assert(nlpigetsolution != NULL);
108  assert(nlpigetstatistics != NULL);
109  assert(nlpigetwarmstartsize != NULL);
110  assert(nlpigetwarmstartmemo != NULL);
111  assert(nlpisetwarmstartmemo != NULL);
112  assert(nlpigetintpar != NULL);
113  assert(nlpisetintpar != NULL);
114  assert(nlpigetrealpar != NULL);
115  assert(nlpisetrealpar != NULL);
116  assert(nlpigetstringpar != NULL);
117  assert(nlpisetstringpar != NULL);
118  assert(nlpisetmessagehdlr != NULL);
119 
120  SCIP_ALLOC( BMSallocMemory(nlpi) );
121 
122  SCIP_ALLOC( BMSduplicateMemoryArray(&(*nlpi)->name, name, strlen(name)+1) );
123  SCIP_ALLOC( BMSduplicateMemoryArray(&(*nlpi)->description, description, strlen(description)+1) );
124  (*nlpi)->priority = priority;
125  (*nlpi)->nlpicopy = nlpicopy;
126  (*nlpi)->nlpifree = nlpifree;
127  (*nlpi)->nlpigetsolverpointer = nlpigetsolverpointer;
128  (*nlpi)->nlpicreateproblem = nlpicreateproblem;
129  (*nlpi)->nlpifreeproblem = nlpifreeproblem;
130  (*nlpi)->nlpigetproblempointer = nlpigetproblempointer;
131  (*nlpi)->nlpiaddvars = nlpiaddvars;
132  (*nlpi)->nlpiaddconstraints = nlpiaddconstraints;
133  (*nlpi)->nlpisetobjective = nlpisetobjective;
134  (*nlpi)->nlpichgvarbounds = nlpichgvarbounds;
135  (*nlpi)->nlpichgconssides = nlpichgconssides;
136  (*nlpi)->nlpidelvarset = nlpidelvarset;
137  (*nlpi)->nlpidelconsset = nlpidelconsset;
138  (*nlpi)->nlpichglinearcoefs = nlpichglinearcoefs;
139  (*nlpi)->nlpichgquadcoefs = nlpichgquadcoefs;
140  (*nlpi)->nlpichgexprtree = nlpichgexprtree;
141  (*nlpi)->nlpichgnonlincoef = nlpichgnonlincoef;
142  (*nlpi)->nlpichgobjconstant = nlpichgobjconstant;
143  (*nlpi)->nlpisetinitialguess = nlpisetinitialguess;
144  (*nlpi)->nlpisolve = nlpisolve;
145  (*nlpi)->nlpigetsolstat = nlpigetsolstat;
146  (*nlpi)->nlpigettermstat = nlpigettermstat;
147  (*nlpi)->nlpigetsolution = nlpigetsolution;
148  (*nlpi)->nlpigetstatistics = nlpigetstatistics;
149  (*nlpi)->nlpigetwarmstartsize = nlpigetwarmstartsize;
150  (*nlpi)->nlpigetwarmstartmemo = nlpigetwarmstartmemo;
151  (*nlpi)->nlpisetwarmstartmemo = nlpisetwarmstartmemo;
152  (*nlpi)->nlpigetintpar = nlpigetintpar;
153  (*nlpi)->nlpisetintpar = nlpisetintpar;
154  (*nlpi)->nlpigetrealpar = nlpigetrealpar;
155  (*nlpi)->nlpisetrealpar = nlpisetrealpar;
156  (*nlpi)->nlpigetstringpar = nlpigetstringpar;
157  (*nlpi)->nlpisetstringpar = nlpisetstringpar;
158  (*nlpi)->nlpisetmessagehdlr = nlpisetmessagehdlr;
159  (*nlpi)->nlpidata = nlpidata;
160 
161  return SCIP_OKAY;
162 }
163 
164 /** copies an NLPI */
166  BMS_BLKMEM* blkmem, /**< block memory in target SCIP */
167  SCIP_NLPI* sourcenlpi, /**< pointer to NLPI data structure to copy */
168  SCIP_NLPI** targetnlpi /**< buffer to store pointer to copied NLPI data structure */
169  )
170 {
171  assert(blkmem != NULL);
172  assert(sourcenlpi != NULL);
173  assert(targetnlpi != NULL);
174 
175  SCIP_CALL( (*sourcenlpi->nlpicopy)(blkmem, sourcenlpi, targetnlpi) );
176 
177  return SCIP_OKAY;
178 }
179 
180 /** frees NLPI user data */
182  SCIP_NLPI** nlpi /**< pointer to NLPI data structure */
183  )
184 {
185  assert(nlpi != NULL);
186  assert(*nlpi != NULL);
187 
188  SCIP_CALL( (*(*nlpi)->nlpifree)((*nlpi)) );
189  BMSfreeMemoryArray(&(*nlpi)->name);
190  BMSfreeMemoryArray(&(*nlpi)->description);
191  BMSfreeMemory(nlpi);
192 
193  assert(*nlpi == NULL);
194 
195  return SCIP_OKAY;
196 }
197 
198 /** gets pointer for NLP solver
199  * @return void pointer to solver
200  */
202  SCIP_NLPI* nlpi /**< pointer to NLPI datastructure */
203  )
204 {
205  assert(nlpi != NULL);
206 
207  return (*nlpi->nlpigetsolverpointer)(nlpi);
208 }
209 
210 /** creates a problem instance */
212  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
213  SCIP_NLPIPROBLEM** problem, /**< pointer to store problem data */
214  const char* name /**< name of problem, can be NULL */
215  )
216 {
217  assert(nlpi != NULL);
218  assert(problem != NULL);
219 
220  return (*nlpi->nlpicreateproblem)(nlpi, problem, name);
221 }
222 
223 /** frees a problem instance */
225  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
226  SCIP_NLPIPROBLEM** problem /**< pointer where problem data is stored */
227  )
228 {
229  assert(nlpi != NULL);
230  assert(problem != NULL);
231 
232  return (*nlpi->nlpifreeproblem)(nlpi, problem);
233 }
234 
235 /** gets pointer to solver-internal problem instance
236  * @return void pointer to problem instance
237  */
239  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
240  SCIP_NLPIPROBLEM* problem /**< pointer where problem data is stored */
241  )
242 {
243  assert(nlpi != NULL);
244  assert(problem != NULL);
245 
246  return (*nlpi->nlpigetproblempointer)(nlpi, problem);
247 }
248 
249 /** add variables to nlpi */
251  SCIP_NLPI* nlpi, /**< pointer to NLPI data structure */
252  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
253  int nvars, /**< number of variables */
254  const SCIP_Real* lbs, /**< lower bounds of variables, can be NULL if -infinity */
255  const SCIP_Real* ubs, /**< ubs upper bounds of variables, can be NULL if +infinity */
256  const char** varnames /**< varnames names of variables, can be NULL */
257  )
258 {
259  assert(nlpi != NULL);
260  assert(problem != NULL);
261 
262  SCIP_CALL( (*nlpi->nlpiaddvars)(nlpi, problem, nvars, lbs, ubs, varnames) );
263 
264  return SCIP_OKAY;
265 }
266 
267 /** add constraints to nlpi */
269  SCIP_NLPI* nlpi, /**< pointer to NLPI data structure */
270  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
271  int nconss, /**< number of added constraints */
272  const SCIP_Real* lhss, /**< left hand sides of constraints */
273  const SCIP_Real* rhss, /**< right hand sides of constraints */
274  const int* nlininds, /**< number of linear coefficients for each constraint, may be NULL in case of no linear part */
275  int* const* lininds, /**< indices of variables for linear coefficients for each constraint, may be NULL in case of no linear part */
276  SCIP_Real* const* linvals, /**< values of linear coefficient for each constraint, may be NULL in case of no linear part */
277  const int* nquadelems, /**< number of elements in matrix of quadratic part for each constraint,
278  * may be NULL in case of no quadratic part in any constraint */
279  SCIP_QUADELEM* const* quadelems, /**< quadratic elements specifying quadratic part for each constraint, entry of array may be NULL in case of no quadratic part,
280  * may be NULL in case of no quadratic part in any constraint */
281  int* const* exprvaridxs, /**< indices of variables in expression tree, maps variable indices in expression
282  * tree to indices in nlp, entry of array may be NULL in case of no expression
283  * tree, may be NULL in case of no expression tree in any constraint */
284  SCIP_EXPRTREE* const* exprtrees, /**< exprtrees expression tree for nonquadratic part of constraints, entry of
285  * array may be NULL in case of no nonquadratic part, may be NULL in case of no
286  * nonquadratic part in any constraint */
287  const char** names /**< names of constraints, may be NULL or entries may be NULL */
288  )
289 {
290  assert(nlpi != NULL);
291  assert(problem != NULL);
292 
293  SCIP_CALL( (*nlpi->nlpiaddconstraints)(nlpi, problem, nconss, lhss, rhss, nlininds, lininds, linvals,
294  nquadelems, quadelems, exprvaridxs, exprtrees, names) );
295 
296  return SCIP_OKAY;
297 }
298 
299 /** sets or overwrites objective, a minimization problem is expected */
301  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
302  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
303  int nlins, /**< number of linear variables */
304  const int* lininds, /**< variable indices, may be NULL in case of no linear part */
305  const SCIP_Real* linvals, /**< coefficient values, may be NULL in case of no linear part */
306  int nquadelems, /**< number of entries in matrix of quadratic part */
307  const SCIP_QUADELEM* quadelems, /**< entries in matrix of quadratic part, may be NULL in case of no quadratic part */
308  const int* exprvaridxs, /**< indices of variables in expression tree, maps variable indices in expression
309  * tree to indices in nlp, may be NULL in case of no expression tree */
310  const SCIP_EXPRTREE* exprtree, /**< expression tree for nonquadratic part of objective function, may be NULL in
311  * case of no nonquadratic part */
312  const SCIP_Real constant /**< objective value offset*/
313  )
314 {
315  assert(nlpi != NULL);
316  assert(problem != NULL);
317 
318  SCIP_CALL( (*nlpi->nlpisetobjective)(nlpi, problem, nlins, lininds, linvals, nquadelems, quadelems,
319  exprvaridxs, exprtree, constant) );
320 
321  return SCIP_OKAY;
322 }
323 
324 /** change variable bounds */
326  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
327  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
328  int nvars, /**< number of variables to change bounds */
329  const int* indices, /**< indices of variables to change bounds */
330  const SCIP_Real* lbs, /**< new lower bounds */
331  const SCIP_Real* ubs /**< new upper bounds */
332  )
333 {
334  assert(nlpi != NULL);
335  assert(problem != NULL);
336 
337  SCIP_CALL( (*nlpi->nlpichgvarbounds)(nlpi, problem, nvars, indices, lbs, ubs) );
338 
339  return SCIP_OKAY;
340 }
341 
342 /** change constraint bounds */
344  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
345  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
346  int nconss, /**< number of constraints to change sides */
347  const int* indices, /**< indices of constraints to change sides */
348  const SCIP_Real* lhss, /**< new left hand sides */
349  const SCIP_Real* rhss /**< new right hand sides */
350  )
351 {
352  assert(nlpi != NULL);
353  assert(problem != NULL);
354 
355  SCIP_CALL( (*nlpi->nlpichgconssides)(nlpi, problem, nconss, indices, lhss, rhss) );
356 
357  return SCIP_OKAY;
358 }
359 
360 /** delete a set of variables */
362  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
363  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
364  int* dstats /**< deletion status of vars; 1 if var should be deleted, 0 if not; afterwards -1
365  * if var was deleted */
366  )
367 {
368  assert(nlpi != NULL);
369  assert(problem != NULL);
370 
371  SCIP_CALL( (*nlpi->nlpidelvarset)(nlpi, problem, dstats) );
372 
373  return SCIP_OKAY;
374 }
375 
376 /** delete a set of constraints */
378  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
379  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
380  int* dstats /**< deletion status of rows; 1 if row should be deleted, 0 if not; afterwards -1
381  * if row was deleted */
382  )
383 {
384  assert(nlpi != NULL);
385  assert(problem != NULL);
386 
387  SCIP_CALL( (*nlpi->nlpidelconsset)(nlpi, problem, dstats) );
388 
389  return SCIP_OKAY;
390 }
391 
392 /** changes or adds linear coefficients in a constraint or objective */
394  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
395  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
396  const int idx, /**< index of constraint or -1 for objective */
397  int nvals, /**< number of values in linear constraint */
398  const int* varidxs, /**< indices of variable */
399  const SCIP_Real* vals /**< new values for coefficient */
400  )
401 {
402  assert(nlpi != NULL);
403  assert(problem != NULL);
404 
405  SCIP_CALL( (*nlpi->nlpichglinearcoefs)(nlpi, problem, idx, nvals, varidxs, vals) );
406 
407  return SCIP_OKAY;
408 }
409 
410 /** changes or adds coefficients in the quadratic part of a constraint or objective */
412  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
413  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
414  int idx, /**< index of constraint or -1 for objective */
415  int nquadelems, /**< number of entries in quadratic constraint to change */
416  const SCIP_QUADELEM* quadelems /**< new elements in quadratic matrix (replacing already existing ones or adding new ones) */
417  )
418 {
419  assert(nlpi != NULL);
420  assert(problem != NULL);
421 
422  SCIP_CALL( (*nlpi->nlpichgquadcoefs)(nlpi, problem, idx, nquadelems, quadelems) );
423 
424  return SCIP_OKAY;
425 }
426 
427 /** change the expression tree in the nonlinear part */
429  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
430  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
431  int idxcons, /**< index of constraint or -1 for objective */
432  const int* exprvaridxs, /**< indices of variables in expression tree, maps variable indices in expression tree to indices in nlp, or NULL */
433  SCIP_EXPRTREE* exprtree /**< new expression tree, or NULL for no tree */
434  )
435 {
436  assert(nlpi != NULL);
437  assert(problem != NULL);
438 
439  SCIP_CALL( (*nlpi->nlpichgexprtree)(nlpi, problem, idxcons, exprvaridxs, exprtree) );
440 
441  return SCIP_OKAY;
442 }
443 
444 /** change the value of one parameter in the nonlinear part */
446  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
447  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
448  int considx, /**< index of constraint or -1 for objective */
449  int paramidx, /**< index of parameter */
450  SCIP_Real value /**< new value for nonlinear parameter */
451  )
452 {
453  assert(nlpi != NULL);
454  assert(problem != NULL);
455 
456  SCIP_CALL( (*nlpi->nlpichgnonlincoef)(nlpi, problem, considx, paramidx, value) );
457 
458  return SCIP_OKAY;
459 }
460 
461 /** change the constant offset in the objective */
463  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
464  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
465  SCIP_Real objconstant /**< new value for objective constant */
466  )
467 {
468  assert(nlpi != NULL);
469  assert(problem != NULL);
470 
471  SCIP_CALL( (*nlpi->nlpichgobjconstant)(nlpi, problem, objconstant) );
472 
473  return SCIP_OKAY;
474 }
475 
476 /** sets initial guess for primal variables */
478  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
479  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
480  SCIP_Real* primalvalues, /**< initial primal values for variables, or NULL to clear previous values */
481  SCIP_Real* consdualvalues, /**< initial dual values for constraints, or NULL to clear previous values */
482  SCIP_Real* varlbdualvalues, /**< initial dual values for variable lower bounds, or NULL to clear previous values */
483  SCIP_Real* varubdualvalues /**< initial dual values for variable upper bounds, or NULL to clear previous values */
484  )
485 {
486  assert(nlpi != NULL);
487  assert(problem != NULL);
488 
489  SCIP_CALL( (*nlpi->nlpisetinitialguess)(nlpi, problem, primalvalues, consdualvalues, varlbdualvalues, varubdualvalues) );
490 
491  return SCIP_OKAY;
492 }
493 
494 /** tries to solve NLP */
496  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
497  SCIP_NLPIPROBLEM* problem /**< pointer to problem data structure */
498  )
499 {
500  assert(nlpi != NULL);
501  assert(problem != NULL);
502 
503  SCIP_CALL( (*nlpi->nlpisolve)(nlpi, problem) );
504 
505  return SCIP_OKAY;
506 }
507 
508 /** gives solution status, return: Solution Status */
510  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
511  SCIP_NLPIPROBLEM* problem /**< pointer to problem data structure */
512  )
513 {
514  assert(nlpi != NULL);
515  assert(problem != NULL);
516 
517  return (*nlpi->nlpigetsolstat)(nlpi, problem);
518 }
519 
520 /** gives termination reason; return: Termination Status */
522  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
523  SCIP_NLPIPROBLEM* problem /**< pointer to problem data structure */
524  )
525 {
526  assert(nlpi != NULL);
527  assert(problem != NULL);
528 
529  return (*nlpi->nlpigettermstat)(nlpi, problem);
530 }
531 
532 /** gives primal and dual solution
533  * 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
534  */
536  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
537  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
538  SCIP_Real** primalvalues, /**< buffer to store pointer to array to primal values, or NULL if not needed */
539  SCIP_Real** consdualvalues, /**< buffer to store pointer to array to dual values of constraints, or NULL if not needed */
540  SCIP_Real** varlbdualvalues, /**< buffer to store pointer to array to dual values of variable lower bounds, or NULL if not needed */
541  SCIP_Real** varubdualvalues /**< buffer to store pointer to array to dual values of variable lower bounds, or NULL if not needed */
542  )
543 {
544  assert(nlpi != NULL);
545  assert(problem != NULL);
546 
547  SCIP_CALL( (*nlpi->nlpigetsolution)(nlpi, problem, primalvalues, consdualvalues, varlbdualvalues, varubdualvalues) );
548 
549  return SCIP_OKAY;
550 }
551 
552 /** gives solve statistics */
554  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
555  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
556  SCIP_NLPSTATISTICS* statistics /**< pointer to store statistics */
557  )
558 {
559  assert(nlpi != NULL);
560  assert(problem != NULL);
561 
562  SCIP_CALL( (*nlpi->nlpigetstatistics)(nlpi, problem, statistics) );
563 
564  return SCIP_OKAY;
565 }
566 
567 /** gives required size of a buffer to store a warmstart object */
569  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
570  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
571  size_t* size /**< pointer to store required size for warmstart buffer */
572  )
573 {
574  assert(nlpi != NULL);
575  assert(problem != NULL);
576 
577  SCIP_CALL( (*nlpi->nlpigetwarmstartsize)(nlpi, problem, size) );
578 
579  return SCIP_OKAY;
580 }
581 
582 /** stores warmstart information in buffer */
584  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
585  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
586  void* buffer /**< memory to store warmstart information */
587  )
588 {
589  assert(nlpi != NULL);
590  assert(problem != NULL);
591 
592  SCIP_CALL( (*nlpi->nlpigetwarmstartmemo)(nlpi, problem, buffer) );
593 
594  return SCIP_OKAY;
595 }
596 
597 /** sets warmstart information in solver */
599  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
600  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
601  void* buffer /**< warmstart information */
602  )
603 {
604  assert(nlpi != NULL);
605  assert(problem != NULL);
606 
607  SCIP_CALL( (*nlpi->nlpisetwarmstartmemo)(nlpi, problem, buffer) );
608 
609  return SCIP_OKAY;
610 }
611 
612 /**@name Parameter Methods */
613 /**@{ */
614 
615 /** gets integer parameter of NLP */
617  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
618  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
619  SCIP_NLPPARAM type, /**< parameter number */
620  int* ival /**< pointer to store the parameter value */
621  )
622 {
623  assert(nlpi != NULL);
624  assert(problem != NULL);
625  assert(ival != NULL);
626 
627  SCIP_CALL( (*nlpi->nlpigetintpar)(nlpi, problem, type, ival) );
628 
629  return SCIP_OKAY;
630 }
631 
632 /** sets integer parameter of NLP */
634  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
635  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
636  SCIP_NLPPARAM type, /**< parameter number */
637  int ival /**< parameter value */
638  )
639 {
640  assert(nlpi != NULL);
641  assert(problem != NULL);
642 
643  SCIP_CALL( (*nlpi->nlpisetintpar)(nlpi, problem, type, ival) );
644 
645  return SCIP_OKAY;
646 }
647 
648 /** gets floating point parameter of NLP
649  * if problem is NULL and type == SCIP_NLPPAR_INFINITY, then gets solver-wide value for infinity */
651  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
652  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure, can be NULL only if type == SCIP_NLPPAR_INFINITY */
653  SCIP_NLPPARAM type, /**< parameter number */
654  SCIP_Real* dval /**< pointer to store the parameter value */
655  )
656 {
657  assert(nlpi != NULL);
658  assert(problem != NULL);
659  assert(dval != NULL);
660 
661  SCIP_CALL( (*nlpi->nlpigetrealpar)(nlpi, problem, type, dval) );
662 
663  return SCIP_OKAY;
664 }
665 
666 /** sets floating point parameter of NLP
667  * if problem is NULL and type == SCIP_NLPPAR_INFINITY, then sets solver-wide value for infinity */
669  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
670  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure, can be NULL only if type == SCIP_NLPPAR_INFINITY */
671  SCIP_NLPPARAM type, /**< parameter number */
672  SCIP_Real dval /**< parameter value */
673  )
674 {
675  assert(nlpi != NULL);
676  assert(problem != NULL || type == SCIP_NLPPAR_INFINITY);
677 
678  SCIP_CALL( (*nlpi->nlpisetrealpar)(nlpi, problem, type, dval) );
679 
680  return SCIP_OKAY;
681 }
682 
683 /** gets string parameter of NLP */
685  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
686  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
687  SCIP_NLPPARAM type, /**< parameter number */
688  const char** sval /**< pointer to store the parameter value, the user must not modify the string */
689  )
690 {
691  assert(nlpi != NULL);
692  assert(problem != NULL);
693  assert(sval != NULL);
694 
695  SCIP_CALL( (*nlpi->nlpigetstringpar)(nlpi, problem, type, sval) );
696 
697  return SCIP_OKAY;
698 }
699 
700 /** sets string parameter of NLP */
702  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
703  SCIP_NLPIPROBLEM* problem, /**< pointer to problem data structure */
704  SCIP_NLPPARAM type, /**< parameter number */
705  const char* sval /**< parameter value */
706  )
707 {
708  assert(nlpi != NULL);
709  assert(problem != NULL);
710 
711  SCIP_CALL( (*nlpi->nlpisetstringpar)(nlpi, problem, type, sval) );
712 
713  return SCIP_OKAY;
714 }
715 
716 /** sets message handler for message output */
718  SCIP_NLPI* nlpi, /**< pointer to NLPI datastructure */
719  SCIP_MESSAGEHDLR* messagehdlr /**< pointer to message handler, or NULL to suppress all output */
720  )
721 {
722  assert(nlpi != NULL);
723  assert(messagehdlr != NULL);
724 
725  SCIP_CALL( (*nlpi->nlpisetmessagehdlr)(nlpi, messagehdlr) );
726 
727  return SCIP_OKAY;
728 }
729 
730 /** gets data of an NLPI */
732  SCIP_NLPI* nlpi /**< NLP interface structure */
733  )
734 {
735  assert(nlpi != NULL);
736 
737  return nlpi->nlpidata;
738 }
739 
740 /** gets NLP solver name */
741 const char* SCIPnlpiGetName(
742  SCIP_NLPI* nlpi /**< NLP interface structure */
743  )
744 {
745  assert(nlpi != NULL);
746 
747  return nlpi->name;
748 }
749 
750 /** gets NLP solver descriptions */
751 const char* SCIPnlpiGetDesc(
752  SCIP_NLPI* nlpi /**< NLP interface structure */
753  )
754 {
755  assert(nlpi != NULL);
756 
757  return nlpi->description;
758 }
759 
760 /** gets NLP solver priority */
762  SCIP_NLPI* nlpi /**< NLP interface structure */
763  )
764 {
765  assert(nlpi != NULL);
766 
767  return nlpi->priority;
768 }
769 
770 /** sets NLP solver priority */
772  SCIP_NLPI* nlpi, /**< NLP interface structure */
773  int priority /**< new priority of NLPI */
774  )
775 {
776  assert(nlpi != NULL);
777 
778  nlpi->priority = priority;
779 }
780 
781 /** creates an NLP statistics structure */
783  SCIP_NLPSTATISTICS** statistics /**< pointer where to store NLP statistics structure */
784  )
785 {
786  assert(statistics != NULL);
787 
788  if( BMSallocMemory(statistics) == NULL )
789  return SCIP_NOMEMORY;
790  assert(*statistics != NULL);
791 
792  (*statistics)->niterations = -1;
793  (*statistics)->totaltime = -1.0;
794 
795  return SCIP_OKAY;
796 }
797 
798 /** frees an NLP statistics structure */
800  SCIP_NLPSTATISTICS** statistics /**< pointer where to store NLP statistics structure */
801  )
802 {
803  assert(statistics != NULL);
804 
805  BMSfreeMemory(statistics);
806 
807  assert(*statistics == NULL);
808 }
809 
810 /** gets the number of iterations from an NLP statistics structure */
812  SCIP_NLPSTATISTICS* statistics /**< NLP statistics structure */
813  )
814 {
815  assert(statistics != NULL);
816 
817  return statistics->niterations;
818 }
819 
820 /** gets the total time from an NLP statistics structure */
822  SCIP_NLPSTATISTICS* statistics /**< NLP statistics structure */
823  )
824 {
825  assert(statistics != NULL);
826 
827  return statistics->totaltime;
828 }
829 
830 /** sets the number of iterations in an NLP statistics structure */
832  SCIP_NLPSTATISTICS* statistics, /**< NLP statistics structure */
833  int niterations /**< number of iterations to store */
834  )
835 {
836  assert(statistics != NULL);
837  statistics->niterations = niterations;
838 }
839 
840 /** sets the total time in an NLP statistics structure */
842  SCIP_NLPSTATISTICS* statistics, /**< NLP statistics structure */
843  SCIP_Real totaltime /**< solution time to store */
844  )
845 {
846  assert(statistics != NULL);
847  statistics->totaltime = totaltime;
848 }
849