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