Scippy

SCIP

Solving Constraint Integer Programs

sepa_convexproj.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-2018 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 scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file sepa_convexproj.c
17  * @brief convexproj separator
18  * @author Felipe Serrano
19  *
20  * @todo should separator only be run when SCIPallColsInLP is true?
21  * @todo check if it makes sense to implement the copy callback
22  * @todo add SCIPisStopped(scip) to the condition of time consuming loops
23  */
24 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
25 
26 #include <assert.h>
27 #include <string.h>
28 
29 #include "blockmemshell/memory.h"
30 #include "nlpi/exprinterpret.h"
31 #include "nlpi/nlpi.h"
32 #include "nlpi/pub_expr.h"
33 #include "scip/pub_message.h"
34 #include "scip/pub_misc.h"
35 #include "scip/pub_nlp.h"
36 #include "scip/pub_sepa.h"
37 #include "scip/scip_cut.h"
38 #include "scip/scip_general.h"
39 #include "scip/scip_lp.h"
40 #include "scip/scip_mem.h"
41 #include "scip/scip_message.h"
42 #include "scip/scip_nlp.h"
43 #include "scip/scip_nonlinear.h"
44 #include "scip/scip_numerics.h"
45 #include "scip/scip_param.h"
46 #include "scip/scip_prob.h"
47 #include "scip/scip_sepa.h"
48 #include "scip/scip_sol.h"
49 #include "scip/scip_solvingstats.h"
50 #include "scip/scip_timing.h"
51 #include "scip/scip_tree.h"
52 #include "scip/sepa_convexproj.h"
53 #include <string.h>
54 
55 
56 #define SEPA_NAME "convexproj"
57 #define SEPA_DESC "separate at projection of point onto convex region"
58 #define SEPA_PRIORITY 0
59 #define SEPA_FREQ -1
60 #define SEPA_MAXBOUNDDIST 1.0
61 #define SEPA_USESSUBSCIP FALSE /**< does the separator use a secondary SCIP instance? */
62 #define SEPA_DELAY TRUE /**< should separation method be delayed, if other separators found cuts? */
63 
64 #define DEFAULT_MAXDEPTH -1 /* maximum depth at which the separator is applied; -1 means no limit */
65 #define DEFAULT_NLPTIMELIMIT 0.0 /**< default time limit of NLP solver; 0.0 for no limit */
66 #define DEFAULT_NLPITERLIM 250 /**< default NLP iteration limit */
67 
68 #define VIOLATIONFAC 100 /* points regarded violated if max violation > VIOLATIONFAC*SCIPfeastol */
69 
70 #define NLPVERBOSITY 0 /**< NLP solver verbosity */
71 
72 /*
73  * Data structures
74  */
75 
76 /** side that makes an nlrow convex */
78 {
79  LHS = 0, /**< left hand side */
80  RHS = 1 /**< right hand side */
81 };
82 typedef enum ConvexSide CONVEXSIDE;
83 
84 /** separator data
85  * it keeps the nlpi which represents the projection problem (see sepa_convexproj.h); it also keeps the convex nlrows
86  * and the side which actually makes them convex; when separating, we use the nlpi to compute the projection and then
87  * the convex nlrows to compute the actual gradient cuts */
88 struct SCIP_SepaData
89 {
90  SCIP_NLPI* nlpi; /**< nlpi used to create the nlpi problem */
91  SCIP_NLPIPROBLEM* nlpiprob; /**< nlpi problem representing the convex NLP relaxation */
92  SCIP_VAR** nlpivars; /**< array containing all variables of the nlpi */
93  SCIP_HASHMAP* var2nlpiidx; /**< mapping between variables and nlpi indices */
94  int nlpinvars; /**< total number of nlpi variables */
95 
96  SCIP_Bool skipsepa; /**< should separator be skipped? */
97 
98  SCIP_NLROW** nlrows; /**< convex nlrows */
99  CONVEXSIDE* convexsides; /**< which sides make the nlrows convex */
100  SCIP_Real* constraintviolation;/**< array storing the violation of constraint by current solution; 0.0 if it is not violated */
101  int nnlrows; /**< total number of nlrows */
102  int nlrowssize; /**< memory allocated for nlrows, convexsides and nlrowsidx */
103 
104  SCIP_EXPRINT* exprinterpreter; /**< expression interpreter to compute gradients */
105 
106  /* parameter */
107  SCIP_Real nlptimelimit; /**< time limit of NLP solver; 0.0 for no limit */
108  int nlpiterlimit; /**< iteration limit of NLP solver; 0 for no limit */
109  int maxdepth; /**< maximal depth at which the separator is applied */
110 
111  int ncuts; /**< number of cuts generated */
112 };
113 
114 
115 /*
116  * Local methods
117  */
118 
119 /** clears the sepadata data */
120 static
122  SCIP* scip, /**< SCIP data structure */
123  SCIP_SEPADATA* sepadata /**< separator data */
124  )
125 {
126  assert(sepadata != NULL);
127 
128  /* nlrowssize gets allocated first and then its decided whether to create the nlpiprob */
129  if( sepadata->nlrowssize > 0 )
130  {
131  SCIPfreeBlockMemoryArray(scip, &sepadata->constraintviolation, sepadata->nlrowssize);
132  SCIPfreeBlockMemoryArray(scip, &sepadata->convexsides, sepadata->nlrowssize);
133  SCIPfreeBlockMemoryArray(scip, &sepadata->nlrows, sepadata->nlrowssize);
134  sepadata->nlrowssize = 0;
135  }
136 
137  if( sepadata->nlpiprob != NULL )
138  {
139  assert(sepadata->nlpi != NULL);
140 
141  SCIPfreeBlockMemoryArray(scip, &sepadata->nlpivars, sepadata->nlpinvars);
142 
143  SCIPhashmapFree(&sepadata->var2nlpiidx);
144  SCIP_CALL( SCIPnlpiFreeProblem(sepadata->nlpi, &sepadata->nlpiprob) );
145  SCIP_CALL( SCIPexprintFree(&sepadata->exprinterpreter) );
146 
147  sepadata->nlpinvars = 0;
148  sepadata->nnlrows = 0;
149  }
150  assert(sepadata->nlpinvars == 0);
151  assert(sepadata->nnlrows == 0);
152  assert(sepadata->nlrowssize == 0);
153 
154  sepadata->skipsepa = FALSE;
155 
156  return SCIP_OKAY;
157 }
158 
159 /** computes gradient of exprtree at projection */
160 static
162  SCIP* scip, /**< SCIP data structure */
163  SCIP_EXPRINT* exprint, /**< expressions interpreter */
164  SCIP_SOL* projection, /**< point where we compute gradient */
165  SCIP_EXPRTREE* exprtree, /**< exprtree for which we compute the gradient */
166  SCIP_Real* grad /**< buffer to store the gradient */
167  )
168 {
169  SCIP_Real* x;
170  SCIP_Real val;
171  int nvars;
172  int i;
173 
174  assert(scip != NULL);
175  assert(exprint != NULL);
176  assert(projection != NULL);
177  assert(exprtree != NULL);
178  assert(grad != NULL);
179 
180  nvars = SCIPexprtreeGetNVars(exprtree);
181  assert(nvars > 0);
182 
183  SCIP_CALL( SCIPallocBufferArray(scip, &x, nvars) );
184 
185  /* compile expression exprtree, if not done before */
186  if( SCIPexprtreeGetInterpreterData(exprtree) == NULL )
187  {
188  SCIP_CALL( SCIPexprintCompile(exprint, exprtree) );
189  }
190 
191  for( i = 0; i < nvars; ++i )
192  {
193  x[i] = SCIPgetSolVal(scip, projection, SCIPexprtreeGetVars(exprtree)[i]);
194  }
195 
196  SCIP_CALL( SCIPexprintGrad(exprint, exprtree, x, TRUE, &val, grad) );
197 
198  /*SCIPdebug( for( i = 0; i < nvars; ++i ) printf("%e [%s]\n", grad[i], SCIPvarGetName(SCIPexprtreeGetVars(exprtree)[i])) );*/
199 
200  SCIPfreeBufferArray(scip, &x);
201 
202  return SCIP_OKAY;
203 }
204 
205 /** computes gradient cut (linearization) of nlrow at projection */
206 static
208  SCIP* scip, /**< SCIP data structure */
209  SCIP_SEPA* sepa, /**< the cut separator itself */
210  SCIP_EXPRINT* exprint, /**< expression interpreter */
211  SCIP_SOL* projection, /**< point where we compute gradient cut */
212  SCIP_NLROW* nlrow, /**< constraint for which we generate gradient cut */
213  CONVEXSIDE convexside, /**< which side makes the nlrow convex */
214  SCIP_Real activity, /**< activity of constraint at projection */
215  SCIP_ROW** row /**< storage for cut */
216  )
217 {
218  char rowname[SCIP_MAXSTRLEN];
219  SCIP_SEPADATA* sepadata;
220  SCIP_Real gradx0; /* <grad f(x_0), x_0> */
221  int i;
222 
223  assert(scip != NULL);
224  assert(sepa != NULL);
225  assert(exprint != NULL);
226  assert(nlrow != NULL);
227  assert(row != NULL);
228 
229  sepadata = SCIPsepaGetData(sepa);
230 
231  assert(sepadata != NULL);
232 
233  gradx0 = 0.0;
234 
235  /* an nlrow has a linear part, quadratic part and expression tree; ideally one would just build the gradient but we
236  * do not know if the different parts share variables or not, so we can't just build the gradient; for this reason
237  * we create the row right away and compute the gradients of each part independently and add them to the row; the
238  * row takes care to add coeffs corresponding to the same variable when they appear in different parts of the nlrow
239  * NOTE: a gradient cut is globally valid whenever the constraint from which it is deduced is globally valid; since
240  * we build the convex relaxation using only globally valid constraints, the cuts are globally valid
241  */
242  (void) SCIPsnprintf(rowname, SCIP_MAXSTRLEN, "proj_cut_%s_%u", SCIPnlrowGetName(nlrow), ++(sepadata->ncuts));
243  SCIP_CALL( SCIPcreateEmptyRowSepa(scip, row, sepa, rowname, -SCIPinfinity(scip), SCIPinfinity(scip), TRUE, FALSE ,
244  TRUE) );
245 
246  SCIP_CALL( SCIPcacheRowExtensions(scip, *row) );
247 
248  /* linear part */
249  for( i = 0; i < SCIPnlrowGetNLinearVars(nlrow); i++ )
250  {
251  gradx0 += SCIPgetSolVal(scip, projection, SCIPnlrowGetLinearVars(nlrow)[i]) * SCIPnlrowGetLinearCoefs(nlrow)[i];
252  SCIP_CALL( SCIPaddVarToRow(scip, *row, SCIPnlrowGetLinearVars(nlrow)[i], SCIPnlrowGetLinearCoefs(nlrow)[i]) );
253  }
254 
255  /* quadratic part */
256  for( i = 0; i < SCIPnlrowGetNQuadElems(nlrow); i++ )
257  {
258  SCIP_VAR* var1;
259  SCIP_VAR* var2;
260  SCIP_Real grad1;
261  SCIP_Real grad2;
262 
263  var1 = SCIPnlrowGetQuadVars(nlrow)[SCIPnlrowGetQuadElems(nlrow)[i].idx1];
264  var2 = SCIPnlrowGetQuadVars(nlrow)[SCIPnlrowGetQuadElems(nlrow)[i].idx2];
265  grad1 = SCIPnlrowGetQuadElems(nlrow)[i].coef * SCIPgetSolVal(scip, projection, var2);
266  grad2 = SCIPnlrowGetQuadElems(nlrow)[i].coef * SCIPgetSolVal(scip, projection, var1);
267 
268  SCIP_CALL( SCIPaddVarToRow(scip, *row, var1, grad1) );
269  SCIP_CALL( SCIPaddVarToRow(scip, *row, var2, grad2) );
270 
271  gradx0 += grad1 * SCIPgetSolVal(scip, projection, var1) + grad2 * SCIPgetSolVal(scip, projection, var2);
272  }
273 
274  /* expression tree part */
275  {
276  SCIP_Real* grad;
277  SCIP_EXPRTREE* tree;
278 
279  tree = SCIPnlrowGetExprtree(nlrow);
280 
281  if( tree != NULL && SCIPexprtreeGetNVars(tree) > 0 )
282  {
283  SCIP_CALL( SCIPallocBufferArray(scip, &grad, SCIPexprtreeGetNVars(tree)) );
284 
285  SCIP_CALL( computeGradient(scip, sepadata->exprinterpreter, projection, tree, grad) );
286 
287  for( i = 0; i < SCIPexprtreeGetNVars(tree); i++ )
288  {
289  gradx0 += grad[i] * SCIPgetSolVal(scip, projection, SCIPexprtreeGetVars(tree)[i]);
290  SCIP_CALL( SCIPaddVarToRow(scip, *row, SCIPexprtreeGetVars(tree)[i], grad[i]) );
291  }
292 
293  SCIPfreeBufferArray(scip, &grad);
294  }
295  }
296 
297  SCIP_CALL( SCIPflushRowExtensions(scip, *row) );
298 
299  SCIPdebugPrintf("gradient: ");
300  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, *row, NULL) ) );
301  SCIPdebugPrintf("gradient dot x_0: %g\n", gradx0);
302 
303  /* gradient cut is f(x_0) - <grad f(x_0), x_0> + <grad f(x_0), x> <= rhs or >= lhs */
304  if( convexside == RHS )
305  {
306  assert(!SCIPisInfinity(scip, SCIPnlrowGetRhs(nlrow)));
307  SCIP_CALL( SCIPchgRowRhs(scip, *row, SCIPnlrowGetRhs(nlrow) - activity + gradx0) );
308  }
309  else
310  {
311  assert(convexside == LHS);
312  assert(!SCIPisInfinity(scip, -SCIPnlrowGetLhs(nlrow)));
313  SCIP_CALL( SCIPchgRowLhs(scip, *row, SCIPnlrowGetLhs(nlrow) - activity + gradx0) );
314  }
315 
316  SCIPdebugPrintf("gradient cut: ");
317  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, *row, NULL) ) );
318 
319  return SCIP_OKAY;
320 }
321 
322 /** set quadratic part of objective function: \f$ \sum_i x_i^2 \f$; the objective function is \f$ ||x - x_0||^2 \f$,
323  * where \f$ x_0 \f$ is the point to separate; the only part that changes is the term \f$ -2 \langle x_0, x \rangle \f$
324  * which is linear and is set every time we want to separate a point, see separateCuts
325  */
326 static
328  SCIP* scip, /**< SCIP data structure */
329  SCIP_SEPADATA* sepadata /**< the cut separator data */
330  )
331 {
332  SCIP_QUADELEM* quadelems;
333  int i;
334 
335  assert(scip != NULL);
336  assert(sepadata != NULL);
337  assert(sepadata->nlpi != NULL);
338  assert(sepadata->nlpiprob != NULL);
339  assert(sepadata->var2nlpiidx != NULL);
340  assert(sepadata->nlpinvars > 0);
341 
342  SCIP_CALL( SCIPallocBufferArray(scip, &quadelems, sepadata->nlpinvars) );
343  for( i = 0; i < sepadata->nlpinvars; i++ )
344  {
345  SCIP_VAR* var;
346 
347  var = sepadata->nlpivars[i];
348  assert(SCIPhashmapExists(sepadata->var2nlpiidx, (void*)var) );
349 
350  quadelems[i].idx1 = (int)(size_t)SCIPhashmapGetImage(sepadata->var2nlpiidx, (void*)var);
351  quadelems[i].idx2 = quadelems[i].idx1;
352  quadelems[i].coef = 1.0;
353  }
354 
355  /* set quadratic part of objective function */
356  SCIP_CALL( SCIPnlpiSetObjective(sepadata->nlpi, sepadata->nlpiprob,
357  0, NULL, NULL, sepadata->nlpinvars, quadelems, NULL, NULL, 0.0) );
358 
359  /* free memory */
360  SCIPfreeBufferArray(scip, &quadelems);
361 
362  return SCIP_OKAY;
363 }
364 
365 /** projects sol onto convex relaxation (stored in sepadata) and tries to generate gradient cuts at the projection
366  * it generates cuts only for the constraints that were violated by the LP solution and are now active or still
367  * violated (in case we don't solve to optimality).
368  * @todo: store a feasible solution if one is found to use as warmstart
369  */
370 static
372  SCIP* scip, /**< SCIP data structure */
373  SCIP_SEPA* sepa, /**< the cut separator itself */
374  SCIP_SOL* sol, /**< solution that should be separated */
375  SCIP_RESULT* result /**< pointer to store the result of the separation call */
376  )
377 {
378  SCIP_SEPADATA* sepadata;
379  SCIP_SOL* projection;
380  SCIP_Real* linvals;
381  SCIP_Real* nlpisol;
382  SCIP_Real timelimit;
383  int nlpinvars;
384  int i;
385  int iterlimit;
386  int* lininds;
387  SCIP_Bool nlpunstable;
388 
389  nlpunstable = FALSE;
390 
391  assert(sepa != NULL);
392 
393  sepadata = SCIPsepaGetData(sepa);
394 
395  assert(result != NULL);
396  assert(sepadata != NULL);
397  assert(sepadata->nnlrows > 0);
398  assert(sepadata->nlpi != NULL);
399  assert(sepadata->nlpinvars > 0);
400  assert(sepadata->nlrows != NULL);
401  assert(sepadata->nlpiprob != NULL);
402  assert(sepadata->var2nlpiidx != NULL);
403  assert(sepadata->convexsides != NULL);
404  assert(sepadata->constraintviolation != NULL);
405 
406  nlpinvars = sepadata->nlpinvars;
407  /* set linear part of objective function: \norm(x - x^0)^2 = \norm(x)^2 - \sum 2 * x_i * x^0_i + const
408  * we ignore the constant; x0 is `sol`
409  */
410  SCIP_CALL( SCIPallocBufferArray(scip, &linvals, nlpinvars) );
411  SCIP_CALL( SCIPallocBufferArray(scip, &lininds, nlpinvars) );
412  for( i = 0; i < nlpinvars; i++ )
413  {
414  SCIP_VAR* var;
415 
416  var = sepadata->nlpivars[i];
417  assert(SCIPhashmapExists(sepadata->var2nlpiidx, (void*)var) );
418 
419  lininds[i] = (int)(size_t)SCIPhashmapGetImage(sepadata->var2nlpiidx, (void*)var);
420  linvals[i] = - 2.0 * SCIPgetSolVal(scip, sol, var);
421 
422  /* if coefficient is too large, don't separate */
423  if( SCIPisHugeValue(scip, REALABS(linvals[i])) )
424  {
425  SCIPdebugMsg(scip, "Don't separate points too close to infinity\n");
426  goto CLEANUP;
427  }
428  }
429 
430  /* set linear part of objective function */
431  SCIP_CALL( SCIPnlpiChgLinearCoefs(sepadata->nlpi, sepadata->nlpiprob, -1, nlpinvars, lininds, linvals) );
432 
433  /* set parameters in nlpi; time and iterations limit, tolerance, verbosity; for time limit, get time limit of scip;
434  * if scip doesn't have much time left, don't run separator. otherwise, timelimit is the minimum between whats left
435  * for scip and the timelimit setting
436  */
437  SCIP_CALL( SCIPgetRealParam(scip, "limits/time", &timelimit) );
438  if( !SCIPisInfinity(scip, timelimit) )
439  {
440  timelimit -= SCIPgetSolvingTime(scip);
441  if( timelimit <= 1.0 )
442  {
443  SCIPdebugMsg(scip, "skip NLP solve; no time left\n");
444  goto CLEANUP;
445  }
446  }
447  if( sepadata->nlptimelimit > 0.0 )
448  timelimit = MIN(sepadata->nlptimelimit, timelimit);
449  SCIP_CALL( SCIPnlpiSetRealPar(sepadata->nlpi, sepadata->nlpiprob, SCIP_NLPPAR_TILIM, timelimit) );
450 
451  iterlimit = sepadata->nlpiterlimit > 0 ? sepadata->nlpiterlimit : INT_MAX;
452  SCIP_CALL( SCIPnlpiSetIntPar(sepadata->nlpi, sepadata->nlpiprob, SCIP_NLPPAR_ITLIM, iterlimit) );
453  SCIP_CALL( SCIPnlpiSetRealPar(sepadata->nlpi, sepadata->nlpiprob, SCIP_NLPPAR_FEASTOL, SCIPfeastol(scip) / 10.0) ); /* use tighter tolerances for the NLP solver */
454  SCIP_CALL( SCIPnlpiSetRealPar(sepadata->nlpi, sepadata->nlpiprob, SCIP_NLPPAR_RELOBJTOL, MAX(SCIPfeastol(scip), SCIPdualfeastol(scip))) ); /*lint !e666*/
455  SCIP_CALL( SCIPnlpiSetIntPar(sepadata->nlpi, sepadata->nlpiprob, SCIP_NLPPAR_VERBLEVEL, NLPVERBOSITY) );
456 
457  /* compute the projection onto the convex NLP relaxation */
458  SCIP_CALL( SCIPnlpiSolve(sepadata->nlpi, sepadata->nlpiprob) );
459  SCIPdebugMsg(scip, "NLP solstat = %d\n", SCIPnlpiGetSolstat(sepadata->nlpi, sepadata->nlpiprob));
460 
461  /* if solution is feasible, add cuts */
462  switch( SCIPnlpiGetSolstat(sepadata->nlpi, sepadata->nlpiprob) )
463  {
466  /* @todo: if solution is optimal, we might as well add the cut <x - P(x_0), x_0 - P(x_0)> <= 0
467  * even though this cut is implied by all the gradient cuts of the rows active at the projection,
468  * we do not add them all (only the gradient cuts of constraints that violated the LP solution */
470  /* generate cuts for violated constraints (at sol) that are active or still violated at the projection, since
471  * a suboptimal solution or numerical issues could give a solution of the projection problem where constraints
472  * are not active; if the solution of the projection problem is in the interior of the region, we do nothing
473  */
474 
475  /* get solution: build SCIP_SOL out of nlpi sol */
476  SCIP_CALL( SCIPnlpiGetSolution(sepadata->nlpi, sepadata->nlpiprob, &nlpisol, NULL, NULL, NULL, NULL) );
477  assert(nlpisol != NULL);
478 
479  SCIP_CALL( SCIPcreateSol(scip, &projection, NULL) );
480  for( i = 0; i < nlpinvars; i++ )
481  {
482  SCIP_VAR* var;
483 
484  var = sepadata->nlpivars[i];
485  assert(SCIPhashmapExists(sepadata->var2nlpiidx, (void*)var) );
486 
487  SCIP_CALL( SCIPsetSolVal(scip, projection, var,
488  nlpisol[(int)(size_t)SCIPhashmapGetImage(sepadata->var2nlpiidx, (void *)var)]) );
489  }
490  SCIPdebug( SCIPprintSol(scip, projection, NULL, TRUE) );
491 
492  /* check for active or violated constraints */
493  for( i = 0; i < sepadata->nnlrows; ++i )
494  {
495  SCIP_NLROW* nlrow;
496  CONVEXSIDE convexside;
497  SCIP_Real activity;
498 
499  /* ignore constraints that are not violated by `sol` */
500  if( SCIPisFeasZero(scip, sepadata->constraintviolation[i]) )
501  continue;
502 
503  convexside = sepadata->convexsides[i];
504  nlrow = sepadata->nlrows[i];
505  assert(nlrow != NULL);
506 
507  /* check for currently active constraints at projected point */
508  SCIP_CALL( SCIPgetNlRowSolActivity(scip, nlrow, projection, &activity) );
509 
510  SCIPdebugMsg(scip, "NlRow activity at nlpi solution: %g <= %g <= %g\n", SCIPnlrowGetLhs(nlrow), activity,
511  SCIPnlrowGetRhs(nlrow) );
512 
513  /* if nlrow is active or violates the projection, build gradient cut at projection */
514  if( (convexside == RHS && SCIPisFeasGE(scip, activity, SCIPnlrowGetRhs(nlrow)))
515  || (convexside == LHS && SCIPisFeasLE(scip, activity, SCIPnlrowGetLhs(nlrow))) )
516  {
517  SCIP_ROW* row;
518 
519  SCIP_CALL( generateCut(scip, sepa, sepadata->exprinterpreter, projection, nlrow, convexside, activity,
520  &row) );
521 
522  SCIPdebugMsg(scip, "active or violated nlrow: (sols vio: %e)\n", sepadata->constraintviolation[i]);
523  SCIPdebug( SCIP_CALL( SCIPprintNlRow(scip, nlrow, NULL) ) );
524  SCIPdebugMsg(scip, "cut with efficacy %g generated\n", SCIPgetCutEfficacy(scip, sol, row));
525  SCIPdebug( SCIPprintRow(scip, row, NULL) );
526 
527  /* add cut if it is efficacious for the point we want to separate (sol) */
528  if( SCIPisCutEfficacious(scip, sol, row) )
529  {
530  SCIP_Bool infeasible;
531 
532  SCIP_CALL( SCIPaddRow(scip, row, FALSE, &infeasible) );
533 
534  if( infeasible )
535  {
536  *result = SCIP_CUTOFF;
537  SCIP_CALL( SCIPreleaseRow(scip, &row) );
538  break;
539  }
540  else
541  {
542  *result = SCIP_SEPARATED;
543  }
544  }
545 
546  /* release the row */
547  SCIP_CALL( SCIPreleaseRow(scip, &row) );
548  }
549  }
550 
551 #ifdef SCIP_DEBUG
552  {
553  SCIP_Real distance;
554 
555  /* compute distance between LP sol and its projection (only makes sense when it is optimal) */
556  distance = 0.0;
557  for( i = 0; i < SCIPgetNNLPVars(scip); ++i )
558  {
559  SCIP_VAR* var;
560 
561  var = SCIPgetNLPVars(scip)[i];
562  assert(var != NULL);
563 
564  /* assert NLP solution is within the bounds of the variable (only make sense when sol is optimal) */
565  if( !SCIPisInfinity(scip, -SCIPvarGetLbLocal(var)) )
566  assert(SCIPisFeasLE(scip, SCIPvarGetLbLocal(var), SCIPvarGetNLPSol(var)));
567  if( !SCIPisInfinity(scip, SCIPvarGetUbLocal(var)) )
568  assert(SCIPisFeasLE(scip, SCIPvarGetNLPSol(var), SCIPvarGetUbLocal(var)));
569 
570  /*SCIPdebugMsg(scip, "NLP sol (LP sol): %s = %f (%g)\n", SCIPvarGetName(var),
571  * SCIPvarGetNLPSol(var), SCIPgetSolVal(scip, sol, var));
572  */
573 
574  distance += SQR( SCIPvarGetNLPSol(var) - SCIPgetSolVal(scip, sol, var) );
575  }
576 
577  SCIPdebugMsg(scip, "NLP objval: %e, distance: %e\n", SCIPgetNLPObjval(scip), distance);
578  }
579 #endif
580 
581  /* free solution */
582  SCIP_CALL( SCIPfreeSol(scip, &projection) );
583  break;
584 
587  /* fallthrough;
588  * @todo: write what it means to be locinfeasible and why it can't be used to cutoff the node */
590  /* unknown... assume numerical issues */
591  nlpunstable = TRUE;
592  break;
593 
595  default:
596  SCIPerrorMessage("Projection NLP is not unbounded by construction, should not get here!\n");
597  SCIPABORT();
598  nlpunstable = TRUE;
599  }
600 
601  /* if nlp is detected to be unstable, don't try to separate again */
602  if( nlpunstable )
603  {
604  /* @todo: maybe change objective function to \sum [(x_i - x_i^*)/max(|x_i^*|, 1)]^2
605  * or some other scaling when unstable and try again.
606  * maybe free it here */
607  sepadata->skipsepa = TRUE;
608  }
609 
610  /* reset objective */
611  BMSclearMemoryArray(linvals, nlpinvars);
612  SCIP_CALL( SCIPnlpiChgLinearCoefs(sepadata->nlpi, sepadata->nlpiprob, -1, nlpinvars, lininds, linvals) );
613 
614 CLEANUP:
615  /* free memory */
616  SCIPfreeBufferArray(scip, &lininds);
617  SCIPfreeBufferArray(scip, &linvals);
618 
619  return SCIP_OKAY;
620 }
621 
622 /** computes the violation and maximum violation of the convex nlrows stored in sepadata wrt sol */
623 static
625  SCIP* scip, /**< SCIP data structure */
626  SCIP_SEPADATA* sepadata, /**< separator data */
627  SCIP_SOL* sol, /**< solution that should be separated */
628  SCIP_Real* maxviolation /**< buffer to store maximum violation */
629  )
630 {
631  SCIP_NLROW* nlrow;
632  int i;
633 
634  assert(sepadata != NULL);
635  assert(sepadata->nnlrows > 0);
636  assert(sepadata->nlrows != NULL);
637  assert(sepadata->convexsides != NULL);
638  assert(sepadata->constraintviolation != NULL);
639 
640  *maxviolation = 0.0;
641  for( i = 0; i < sepadata->nnlrows; i++ )
642  {
643  SCIP_Real activity;
644  SCIP_Real violation;
645 
646  nlrow = sepadata->nlrows[i];
647 
648  /* get activity of nlrow */
649  SCIP_CALL( SCIPgetNlRowSolActivity(scip, nlrow, sol, &activity) );
650 
651  /* violation = max{activity - rhs, 0.0} when convex and max{lhs - activity, 0.0} when concave */
652  if( sepadata->convexsides[i] == RHS )
653  {
655  assert(!SCIPisInfinity(scip, SCIPnlrowGetRhs(nlrow)));
656 
657  violation = activity - SCIPnlrowGetRhs(nlrow);
658  sepadata->constraintviolation[i] = MAX(violation, 0.0);
659  }
660  if( sepadata->convexsides[i] == LHS )
661  {
663  assert(!SCIPisInfinity(scip, -SCIPnlrowGetLhs(nlrow)));
664 
665  violation = SCIPnlrowGetLhs(nlrow) - activity;
666  sepadata->constraintviolation[i] = MAX(violation, 0.0);
667  }
668 
669  /* compute maximum */
670  if( *maxviolation < sepadata->constraintviolation[i] )
671  *maxviolation = sepadata->constraintviolation[i];
672  }
673 
674  SCIPdebugMsg(scip, "Maximum violation %g\n", *maxviolation);
675 
676  return SCIP_OKAY;
677 }
678 
679 
680 /** stores, from the constraints represented by nlrows, the nonlinear convex ones in sepadata */
681 static
683  SCIP* scip, /**< SCIP data structure */
684  SCIP_SEPADATA* sepadata, /**< separator data */
685  SCIP_NLROW** nlrows, /**< nlrows from which to store convex ones */
686  int nnlrows /**< number of nlrows */
687  )
688 {
689  int i;
690 
691  assert(scip != NULL);
692  assert(sepadata != NULL);
693 
694  SCIPdebugMsg(scip, "storing convex nlrows\n");
695 
696  sepadata->nlrowssize = nnlrows;
697  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(sepadata->nlrows), nnlrows) );
698  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(sepadata->convexsides), nnlrows) );
699  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(sepadata->constraintviolation), nnlrows) );
700 
701  /* count the number of nonlinear convex rows and store them */
702  sepadata->nnlrows = 0;
703  for( i = 0; i < nnlrows; ++i )
704  {
705  SCIP_NLROW* nlrow;
706 
707  nlrow = nlrows[i];
708  assert(nlrow != NULL);
709 
710  /* linear case */
712  (SCIPnlrowGetNQuadElems(nlrow) == 0 && SCIPnlrowGetExprtree(nlrow) == NULL) )
713  continue;
714 
715  /* nonlinear case */
717  {
718  sepadata->convexsides[sepadata->nnlrows] = RHS;
719  sepadata->nlrows[sepadata->nnlrows] = nlrow;
720  ++(sepadata->nnlrows);
721  }
722  else if( !SCIPisInfinity(scip, -SCIPnlrowGetLhs(nlrow)) && SCIPnlrowGetCurvature(nlrow) == SCIP_EXPRCURV_CONCAVE )
723  {
724  sepadata->convexsides[sepadata->nnlrows] = LHS;
725  sepadata->nlrows[sepadata->nnlrows] = nlrow;
726  ++(sepadata->nnlrows);
727  }
728  }
729 
730  return SCIP_OKAY;
731 }
732 
733 
734 /*
735  * Callback methods of separator
736  */
737 
738 
739 /** destructor of separator to free user data (called when SCIP is exiting) */
740 static
741 SCIP_DECL_SEPAFREE(sepaFreeConvexproj)
742 { /*lint --e{715}*/
743  SCIP_SEPADATA* sepadata;
744 
745  assert(strcmp(SCIPsepaGetName(sepa), SEPA_NAME) == 0);
746 
747  /* free separator data */
748  sepadata = SCIPsepaGetData(sepa);
749  assert(sepadata != NULL);
750 
751  SCIP_CALL( sepadataClear(scip, sepadata) );
752 
753  SCIPfreeBlockMemory(scip, &sepadata);
754 
755  SCIPsepaSetData(sepa, NULL);
756 
757  return SCIP_OKAY;
758 }
759 
760 /** solving process deinitialization method of separator (called before branch and bound process data is freed) */
761 static
762 SCIP_DECL_SEPAEXITSOL(sepaExitsolConvexproj)
763 { /*lint --e{715}*/
764  SCIP_SEPADATA* sepadata;
765 
766  assert(sepa != NULL);
767 
768  sepadata = SCIPsepaGetData(sepa);
769 
770  assert(sepadata != NULL);
771 
772  SCIP_CALL( sepadataClear(scip, sepadata) );
773 
774  return SCIP_OKAY;
775 }
776 
777 
778 /** LP solution separation method of separator */
779 static
780 SCIP_DECL_SEPAEXECLP(sepaExeclpConvexproj)
781 { /*lint --e{715}*/
782  SCIP_Real maxviolation;
783  SCIP_SOL* lpsol;
784  SCIP_SEPADATA* sepadata;
785 
786  *result = SCIP_DIDNOTRUN;
787 
788  sepadata = SCIPsepaGetData(sepa);
789  assert(sepadata != NULL);
790 
791  /* do not run if there is no interesting convex relaxation (with at least one nonlinear convex constraint),
792  * or if we have found it to be numerically unstable
793  * @todo: should it be with at least 2 nonlinear convex constraints?
794  */
795  if( sepadata->skipsepa )
796  {
797  SCIPdebugMsg(scip, "not running because convex relaxation is uninteresting or numerically unstable\n");
798  return SCIP_OKAY;
799  }
800 
801  /* the separator needs an NLP solver */
802  if( SCIPgetNNlpis(scip) == 0 )
803  return SCIP_OKAY;
804 
805  /* only call separator up to a maximum depth */
806  if( sepadata->maxdepth >= 0 && SCIPgetDepth(scip) > sepadata->maxdepth )
807  return SCIP_OKAY;
808 
809  /* only call separator, if we are not close to terminating */
810  if( SCIPisStopped(scip) )
811  return SCIP_OKAY;
812 
813  /* do not run if SCIP does not have constructed an NLP */
814  if( !SCIPisNLPConstructed(scip) )
815  {
816  SCIPdebugMsg(scip, "NLP not constructed, skipping convex projection separator\n");
817  return SCIP_OKAY;
818  }
819 
820  /* recompute convex NLP relaxation if the variable set changed and we are still at the root node
821  * @todo: does it make sense to do this??? */
822  if( sepadata->nlpiprob != NULL && SCIPgetNVars(scip) != sepadata->nlpinvars && SCIPgetDepth(scip) == 0 )
823  {
824  SCIP_CALL( sepadataClear(scip, sepadata) );
825  assert(sepadata->nlpiprob == NULL);
826  }
827 
828  /* create or update convex NLP relaxation */
829  if( sepadata->nlpiprob == NULL )
830  {
831  /* store convex nonlinear constraints */
833 
834  /* check that convex NLP relaxation is interesting (more than one nonlinear constraint) */
835  if( sepadata->nnlrows < 1 )
836  {
837  SCIPdebugMsg(scip, "convex relaxation uninteresting, don't run\n");
838  sepadata->skipsepa = TRUE;
839  return SCIP_OKAY;
840  }
841 
842  /* create the expression interpreter */
843  SCIP_CALL( SCIPexprintCreate(SCIPblkmem(scip), &sepadata->exprinterpreter) );
844 
845  sepadata->nlpinvars = SCIPgetNVars(scip);
846  sepadata->nlpi = SCIPgetNlpis(scip)[0];
847  assert(sepadata->nlpi != NULL);
848 
849  SCIP_CALL( SCIPnlpiCreateProblem(sepadata->nlpi, &sepadata->nlpiprob, "convexproj-nlp") );
850  SCIP_CALL( SCIPhashmapCreate(&sepadata->var2nlpiidx, SCIPblkmem(scip), sepadata->nlpinvars) );
851  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &sepadata->nlpivars, SCIPgetVars(scip), sepadata->nlpinvars) ); /*lint !e666*/
852 
854  sepadata->nlpiprob, sepadata->var2nlpiidx, NULL, SCIPgetCutoffbound(scip), FALSE, TRUE) );
855 
856  /* add rows of the LP */
857  if( SCIPgetDepth(scip) == 0 )
858  {
859  SCIP_CALL( SCIPaddNlpiProbRows(scip, sepadata->nlpi, sepadata->nlpiprob, sepadata->var2nlpiidx,
861  }
862 
863  /* set quadratic part of objective function */
864  SCIP_CALL( setQuadraticObj(scip, sepadata) );
865  }
866  else
867  {
868  SCIP_CALL( SCIPupdateNlpiProb(scip, sepadata->nlpi, sepadata->nlpiprob, sepadata->var2nlpiidx,
869  sepadata->nlpivars, sepadata->nlpinvars, SCIPgetCutoffbound(scip)) );
870  }
871 
872  /* assert that the lp solution satisfies the cutoff bound; if this fails then we shouldn't have a cutoff bound in the
873  * nlpi, since then the projection could be in the interior of the actual convex relaxation */
876 
877  /* get current sol: LP or pseudo solution if LP sol is not available */
879 
880  /* do not run if current solution's violation is small */
881  SCIP_CALL( computeMaxViolation(scip, sepadata, lpsol, &maxviolation) );
882  if( maxviolation < VIOLATIONFAC * SCIPfeastol(scip) )
883  {
884  SCIPdebugMsg(scip, "solution doesn't violate constraints enough, do not separate\n");
885  SCIP_CALL( SCIPfreeSol(scip, &lpsol) );
886  return SCIP_OKAY;
887  }
888 
889  /* run the separator */
890  *result = SCIP_DIDNOTFIND;
891 
892  /* separateCuts computes the projection and then gradient cuts on each constraint that was originally violated */
893  SCIP_CALL( separateCuts(scip, sepa, lpsol, result) );
894 
895  /* free memory */
896  SCIP_CALL( SCIPfreeSol(scip, &lpsol) );
897 
898  return SCIP_OKAY;
899 }
900 
901 
902 /*
903  * separator specific interface methods
904  */
905 
906 /** creates the convexproj separator and includes it in SCIP */
908  SCIP* scip /**< SCIP data structure */
909  )
910 {
911  SCIP_SEPADATA* sepadata;
912  SCIP_SEPA* sepa;
913 
914  /* create convexproj separator data */
915  SCIP_CALL( SCIPallocBlockMemory(scip, &sepadata) );
916 
917  /* this sets all data in sepadata to 0 */
918  BMSclearMemory(sepadata);
919 
920  /* include separator */
923  sepaExeclpConvexproj, NULL,
924  sepadata) );
925  assert(sepa != NULL);
926 
927  /* set non fundamental callbacks via setter functions */
928  SCIP_CALL( SCIPsetSepaFree(scip, sepa, sepaFreeConvexproj) );
929  SCIP_CALL( SCIPsetSepaExitsol(scip, sepa, sepaExitsolConvexproj) );
930 
931  /* add convexproj separator parameters */
932  SCIP_CALL( SCIPaddIntParam(scip, "separating/" SEPA_NAME "/maxdepth",
933  "maximal depth at which the separator is applied (-1: unlimited)",
934  &sepadata->maxdepth, FALSE, DEFAULT_MAXDEPTH, -1, INT_MAX, NULL, NULL) );
935 
936  SCIP_CALL( SCIPaddIntParam(scip, "separating/" SEPA_NAME "/nlpiterlimit",
937  "iteration limit of NLP solver; 0 for no limit",
938  &sepadata->nlpiterlimit, TRUE, DEFAULT_NLPITERLIM, 0, INT_MAX, NULL, NULL) );
939 
940  SCIP_CALL( SCIPaddRealParam(scip, "separating/" SEPA_NAME "/nlptimelimit",
941  "time limit of NLP solver; 0.0 for no limit",
942  &sepadata->nlptimelimit, TRUE, DEFAULT_NLPTIMELIMIT, 0.0, SCIP_REAL_MAX, NULL, NULL) );
943 
944  return SCIP_OKAY;
945 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:116
SCIP_ROW ** SCIPgetLPRows(SCIP *scip)
Definition: scip_lp.c:608
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
int SCIPgetNNLPNlRows(SCIP *scip)
Definition: scip_nlp.c:513
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
Definition: scip_timing.c:436
convexproj separator
#define NULL
Definition: def.h:239
SCIP_Real SCIPfeastol(SCIP *scip)
static SCIP_RETCODE storeNonlinearConvexNlrows(SCIP *scip, SCIP_SEPADATA *sepadata, SCIP_NLROW **nlrows, int nnlrows)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:99
SCIP_Bool SCIPisNLPConstructed(SCIP *scip)
Definition: scip_nlp.c:284
SCIP_RETCODE SCIPcacheRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1547
public methods for SCIP parameter handling
SCIP_VAR ** SCIPgetNLPVars(SCIP *scip)
Definition: scip_nlp.c:351
methods to interpret (evaluate) an expression tree "fast"
static SCIP_DECL_SEPAEXECLP(sepaExeclpConvexproj)
static SCIP_RETCODE computeMaxViolation(SCIP *scip, SCIP_SEPADATA *sepadata, SCIP_SOL *sol, SCIP_Real *maxviolation)
public methods for memory management
SCIP_Real SCIPgetCutoffbound(SCIP *scip)
SCIP_RETCODE SCIPflushRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1570
SCIP_RETCODE SCIPcreateNlpiProb(SCIP *scip, SCIP_NLPI *nlpi, SCIP_NLROW **nlrows, int nnlrows, SCIP_NLPIPROBLEM *nlpiprob, SCIP_HASHMAP *var2idx, SCIP_Real *nlscore, SCIP_Real cutoffbound, SCIP_Bool setobj, SCIP_Bool onlyconvex)
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
Definition: scip_param.c:379
#define SCIP_MAXSTRLEN
Definition: def.h:260
SCIP_RETCODE SCIPaddVarToRow(SCIP *scip, SCIP_ROW *row, SCIP_VAR *var, SCIP_Real val)
Definition: scip_lp.c:1602
#define SQR(x)
Definition: def.h:191
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17399
internal methods for NLPI solver interfaces
SCIP_RETCODE SCIPnlpiCreateProblem(SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM **problem, const char *name)
Definition: nlpi.c:211
static SCIP_DECL_SEPAEXITSOL(sepaExitsolConvexproj)
public methods for timing
SCIP_RETCODE SCIPnlpiGetSolution(SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, SCIP_Real **primalvalues, SCIP_Real **consdualvalues, SCIP_Real **varlbdualvalues, SCIP_Real **varubdualvalues, SCIP_Real *objval)
Definition: nlpi.c:537
SCIP_Real SCIPdualfeastol(SCIP *scip)
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define FALSE
Definition: def.h:65
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:2793
static SCIP_RETCODE setQuadraticObj(SCIP *scip, SCIP_SEPADATA *sepadata)
SCIP_Real SCIPinfinity(SCIP *scip)
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10017
#define TRUE
Definition: def.h:64
#define SCIPdebug(x)
Definition: pub_message.h:74
const char * SCIPsepaGetName(SCIP_SEPA *sepa)
Definition: sepa.c:689
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_RETCODE SCIPexprintCompile(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree)
SCIP_Real SCIPnlrowGetRhs(SCIP_NLROW *nlrow)
Definition: nlp.c:3384
int SCIPnlrowGetNLinearVars(SCIP_NLROW *nlrow)
Definition: nlp.c:3246
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:114
SCIP_RETCODE SCIPgetNlRowSolActivity(SCIP *scip, SCIP_NLROW *nlrow, SCIP_SOL *sol, SCIP_Real *activity)
Definition: scip_nlp.c:1986
SCIP_EXPRCURV SCIPnlrowGetCurvature(SCIP_NLROW *nlrow)
Definition: nlp.c:3394
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:2931
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:142
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:97
#define SCIPdebugMsg
Definition: scip_message.h:88
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:155
public methods for separator plugins
SCIP_VAR ** x
Definition: circlepacking.c:54
SCIP_VAR ** SCIPexprtreeGetVars(SCIP_EXPRTREE *tree)
Definition: nlp.c:102
SCIP_NLROW ** SCIPgetNLPNlRows(SCIP *scip)
Definition: scip_nlp.c:491
public methods for numerical tolerances
SCIP_SEPADATA * SCIPsepaGetData(SCIP_SEPA *sepa)
Definition: sepa.c:600
int SCIPnlrowGetNQuadElems(SCIP_NLROW *nlrow)
Definition: nlp.c:3323
public methods for expressions, expression trees, expression graphs, and related stuff ...
public methods for querying solving statistics
SCIP_Bool SCIPhashmapExists(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3025
SCIP_RETCODE SCIPnlpiSolve(SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem)
Definition: nlpi.c:497
public methods for the branch-and-bound tree
#define SCIPduplicateBlockMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:111
SCIP_Real coef
Definition: type_expr.h:104
SCIP_Bool SCIPisCutEfficacious(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
Definition: scip_cut.c:161
int SCIPgetNNLPVars(SCIP *scip)
Definition: scip_nlp.c:373
SCIP_VAR ** SCIPnlrowGetQuadVars(SCIP_NLROW *nlrow)
Definition: nlp.c:3286
#define SEPA_PRIORITY
#define SCIPerrorMessage
Definition: pub_message.h:45
#define SCIPdebugPrintf
Definition: pub_message.h:80
SCIP_RETCODE SCIPexprintCreate(BMS_BLKMEM *blkmem, SCIP_EXPRINT **exprint)
SCIP_RETCODE SCIPincludeSepaConvexproj(SCIP *scip)
public methods for nonlinear functions
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:128
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:2826
void SCIPsepaSetData(SCIP_SEPA *sepa, SCIP_SEPADATA *sepadata)
Definition: sepa.c:610
SCIP_RETCODE SCIPaddNlpiProbRows(SCIP *scip, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *nlpiprob, SCIP_HASHMAP *var2idx, SCIP_ROW **rows, int nrows)
int SCIPgetNNlpis(SCIP *scip)
Definition: scip_nlp.c:206
#define REALABS(x)
Definition: def.h:174
int SCIPexprtreeGetNVars(SCIP_EXPRTREE *tree)
Definition: expr.c:8612
int SCIPgetNLPRows(SCIP *scip)
Definition: scip_lp.c:629
SCIP_QUADELEM * SCIPnlrowGetQuadElems(SCIP_NLROW *nlrow)
Definition: nlp.c:3333
#define SEPA_DESC
#define SCIP_CALL(x)
Definition: def.h:351
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPaddRow(SCIP *scip, SCIP_ROW *row, SCIP_Bool forcecut, SCIP_Bool *infeasible)
Definition: scip_cut.c:294
SCIP_NLPSOLSTAT SCIPnlpiGetSolstat(SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem)
Definition: nlpi.c:511
SCIP_RETCODE SCIPnlpiSetObjective(SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, int nlins, const int *lininds, const SCIP_Real *linvals, int nquadelems, const SCIP_QUADELEM *quadelems, const int *exprvaridxs, const SCIP_EXPRTREE *exprtree, const SCIP_Real constant)
Definition: nlpi.c:300
public methods for NLP management
SCIP_RETCODE SCIPincludeSepaBasic(SCIP *scip, SCIP_SEPA **sepa, const char *name, const char *desc, int priority, int freq, SCIP_Real maxbounddist, SCIP_Bool usessubscip, SCIP_Bool delay, SCIP_DECL_SEPAEXECLP((*sepaexeclp)), SCIP_DECL_SEPAEXECSOL((*sepaexecsol)), SCIP_SEPADATA *sepadata)
Definition: scip_sepa.c:178
SCIP_Bool SCIPisHugeValue(SCIP *scip, SCIP_Real val)
SCIP_RETCODE SCIPnlpiFreeProblem(SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM **problem)
Definition: nlpi.c:224
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:130
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip_sol.c:1270
public data structures and miscellaneous methods
SCIP_RETCODE SCIPsetSepaExitsol(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAEXITSOL((*sepaexitsol)))
Definition: scip_sepa.c:300
#define SCIP_Bool
Definition: def.h:62
SCIP_RETCODE SCIPchgRowRhs(SCIP *scip, SCIP_ROW *row, SCIP_Real rhs)
Definition: scip_lp.c:1519
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip_lp.c:226
static SCIP_RETCODE separateCuts(SCIP *scip, SCIP_SEPA *sepa, SCIP_SOL *sol, SCIP_RESULT *result)
SCIP_RETCODE SCIPupdateNlpiProb(SCIP *scip, SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *nlpiprob, SCIP_HASHMAP *var2nlpiidx, SCIP_VAR **nlpivars, int nlpinvars, SCIP_Real cutoffbound)
SCIP_Real SCIPvarGetNLPSol(SCIP_VAR *var)
Definition: var.c:17730
static SCIP_RETCODE computeGradient(SCIP *scip, SCIP_EXPRINT *exprint, SCIP_SOL *projection, SCIP_EXPRTREE *exprtree, SCIP_Real *grad)
int SCIPgetDepth(SCIP *scip)
Definition: scip_tree.c:715
SCIP_RETCODE SCIPnlpiSetIntPar(SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, SCIP_NLPPARAM type, int ival)
Definition: nlpi.c:636
SCIP_EXPRINTDATA * SCIPexprtreeGetInterpreterData(SCIP_EXPRTREE *tree)
Definition: expr.c:8657
#define MIN(x, y)
Definition: def.h:209
#define DEFAULT_MAXDEPTH
SCIP_RETCODE SCIPcreateEmptyRowSepa(SCIP *scip, SCIP_ROW **row, SCIP_SEPA *sepa, const char *name, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool removable)
Definition: scip_lp.c:1365
#define SEPA_NAME
SCIP_RETCODE SCIPchgRowLhs(SCIP *scip, SCIP_ROW *row, SCIP_Real lhs)
Definition: scip_lp.c:1495
SCIP_Real SCIPgetCutEfficacy(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
Definition: scip_cut.c:138
public methods for cuts and aggregation rows
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:1034
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
#define BMSclearMemory(ptr)
Definition: memory.h:111
SCIP_RETCODE SCIPexprintGrad(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Bool new_varvals, SCIP_Real *val, SCIP_Real *gradient)
public methods for the LP relaxation, rows and columns
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:2044
#define SCIP_REAL_MAX
Definition: def.h:151
public methods for nonlinear relaxations
SCIP_EXPRTREE * SCIPnlrowGetExprtree(SCIP_NLROW *nlrow)
Definition: nlp.c:3364
static SCIP_RETCODE generateCut(SCIP *scip, SCIP_SEPA *sepa, SCIP_EXPRINT *exprint, SCIP_SOL *projection, SCIP_NLROW *nlrow, CONVEXSIDE convexside, SCIP_Real activity, SCIP_ROW **row)
#define DEFAULT_NLPITERLIM
SCIP_RETCODE SCIPreleaseRow(SCIP *scip, SCIP_ROW **row)
Definition: scip_lp.c:1474
#define SEPA_FREQ
general public methods
#define MAX(x, y)
Definition: def.h:208
SCIP_RETCODE SCIPsetSepaFree(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAFREE((*sepafree)))
Definition: scip_sepa.c:236
SCIP_Real SCIPgetLPObjval(SCIP *scip)
Definition: scip_lp.c:305
public methods for solutions
public methods for message output
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip_prob.c:1999
#define SEPA_USESSUBSCIP
#define SCIP_Real
Definition: def.h:150
#define NLPVERBOSITY
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:739
public methods for message handling
static SCIP_DECL_SEPAFREE(sepaFreeConvexproj)
SCIP_RETCODE SCIPprintRow(SCIP *scip, SCIP_ROW *row, FILE *file)
Definition: scip_lp.c:2094
SCIP_RETCODE SCIPprintNlRow(SCIP *scip, SCIP_NLROW *nlrow, FILE *file)
Definition: scip_nlp.c:2079
SCIP_RETCODE SCIPcreateCurrentSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:532
SCIP_RETCODE SCIPnlpiChgLinearCoefs(SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, const int idx, int nvals, const int *varidxs, const SCIP_Real *vals)
Definition: nlpi.c:395
SCIP_Real SCIPgetNLPObjval(SCIP *scip)
Definition: scip_nlp.c:738
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real * SCIPnlrowGetLinearCoefs(SCIP_NLROW *nlrow)
Definition: nlp.c:3266
const char * SCIPnlrowGetName(SCIP_NLROW *nlrow)
Definition: nlp.c:3413
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17409
SCIP_VAR ** SCIPnlrowGetLinearVars(SCIP_NLROW *nlrow)
Definition: nlp.c:3256
ConvexSide
SCIP_NLPI ** SCIPgetNlpis(SCIP *scip)
Definition: scip_nlp.c:193
SCIP_RETCODE SCIPexprintFree(SCIP_EXPRINT **exprint)
#define SEPA_MAXBOUNDDIST
public methods for separators
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:112
#define SEPA_DELAY
SCIP_Real SCIPnlrowGetLhs(SCIP_NLROW *nlrow)
Definition: nlp.c:3374
#define SCIPABORT()
Definition: def.h:323
public methods for global and local (sub)problems
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1410
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:211
enum ConvexSide CONVEXSIDE
#define DEFAULT_NLPTIMELIMIT
struct SCIP_SepaData SCIP_SEPADATA
Definition: type_sepa.h:38
static SCIP_RETCODE sepadataClear(SCIP *scip, SCIP_SEPADATA *sepadata)
#define VIOLATIONFAC
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:377
SCIP_RETCODE SCIPnlpiSetRealPar(SCIP_NLPI *nlpi, SCIP_NLPIPROBLEM *problem, SCIP_NLPPARAM type, SCIP_Real dval)
Definition: nlpi.c:671
memory allocation routines
SCIP_RETCODE SCIPprintSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)
Definition: scip_sol.c:1824