Scippy

SCIP

Solving Constraint Integer Programs

cons_abspower.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-2015 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 cons_abspower.c
17  * @brief Constraint handler for absolute power constraints \f$\textrm{lhs} \leq \textrm{sign}(x+a) |x+a|^n + c z \leq \textrm{rhs}\f$
18  * @author Stefan Vigerske
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <assert.h>
24 #include <string.h>
25 #include <ctype.h>
26 
27 #include "scip/cons_abspower.h"
28 #include "scip/cons_nonlinear.h"
29 #include "scip/cons_indicator.h"
30 #include "scip/cons_quadratic.h"
31 #include "scip/cons_linear.h"
32 #include "scip/cons_varbound.h"
33 #include "scip/intervalarith.h"
34 #include "scip/heur_subnlp.h"
35 #include "scip/heur_trysol.h"
36 #include "scip/debug.h"
37 
38 /* constraint handler properties */
39 #define CONSHDLR_NAME "abspower"
40 #define CONSHDLR_DESC "constraint handler for absolute power constraints lhs <= sign(x+offset)abs(x+offset)^n + c*z <= rhs"
41 #define CONSHDLR_SEPAPRIORITY 0 /**< priority of the constraint handler for separation */
42 #define CONSHDLR_ENFOPRIORITY -30 /**< priority of the constraint handler for constraint enforcing */
43 #define CONSHDLR_CHECKPRIORITY -3500000 /**< priority of the constraint handler for checking feasibility */
44 #define CONSHDLR_SEPAFREQ 1 /**< frequency for separating cuts; zero means to separate only in the root node */
45 #define CONSHDLR_PROPFREQ 1 /**< frequency for propagating domains; zero means only preprocessing propagation */
46 #define CONSHDLR_EAGERFREQ 100 /**< frequency for using all instead of only the useful constraints in separation,
47  * propagation and enforcement, -1 for no eager evaluations, 0 for first only */
48 #define CONSHDLR_MAXPREROUNDS -1 /**< maximal number of presolving rounds the constraint handler participates in (-1: no limit) */
49 #define CONSHDLR_DELAYSEPA FALSE /**< should separation method be delayed, if other separators found cuts? */
50 #define CONSHDLR_DELAYPROP FALSE /**< should propagation method be delayed, if other propagators found reductions? */
51 #define CONSHDLR_NEEDSCONS TRUE /**< should the constraint handler be skipped, if no constraints are available? */
52 
53 #define CONSHDLR_PRESOLTIMING SCIP_PRESOLTIMING_FAST | SCIP_PRESOLTIMING_MEDIUM
54 #define CONSHDLR_PROP_TIMING SCIP_PROPTIMING_ALWAYS /**< when should the constraint handlers propagation routines be called? */
55 
56 #define QUADCONSUPGD_PRIORITY 50000 /**< priority of the constraint handler for upgrading of quadratic constraints */
57 #define NONLINCONSUPGD_PRIORITY 50000 /**< priority of the constraint handler for upgrading of nonlinear constraints and reformulating expression graph nodes */
58 
59 /*
60  * Local defines
61  */
62 
63 #define PROPVARTOL SCIPepsilon(scip) /**< tolerance to add to variable bounds in domain propagation */
64 #define PROPSIDETOL SCIPepsilon(scip) /**< tolerance to add to constraint sides in domain propagation */
65 #define INITLPMAXVARVAL 1000.0 /**< maximal absolute value of variable for still generating a linearization cut at that point in initlp */
66 
67 /** power function type to be used by a constraint instead of the general pow */
68 #define DECL_MYPOW(x) SCIP_Real x (SCIP_Real base, SCIP_Real exponent)
69 
70 /** sign of a value (-1 or +1)
71  *
72  * 0.0 has sign +1
73  */
74 #define SIGN(x) ((x) >= 0.0 ? 1.0 : -1.0)
75 
76 
77 /*
78  * Data structures
79  */
80 
81 #define ROOTS_KNOWN 10 /**< up to which (integer) exponents precomputed roots have been stored */
82 
83 /** The positive root of the polynomial (n-1) y^n + n y^(n-1) - 1 is needed in separation.
84  * Here we store these roots for small integer values of n.
85  */
86 static
88  -1.0, /* no root for n=0 */
89  -1.0, /* no root for n=1 */
90  0.41421356237309504880, /* root for n=2 (-1+sqrt(2)) */
91  0.5, /* root for n=3 */
92  0.56042566045031785945, /* root for n=4 */
93  0.60582958618826802099, /* root for n=5 */
94  0.64146546982884663257, /* root for n=6 */
95  0.67033204760309682774, /* root for n=7 */
96  0.69428385661425826738, /* root for n=8 */
97  0.71453772716733489700, /* root for n=9 */
98  0.73192937842370733350 /* root for n=10 */
99 };
100 
101 /** constraint data for absolute power constraints */
102 struct SCIP_ConsData
103 {
104  SCIP_VAR* x; /**< variable x in sign(x+offset)|x+offset|^n term */
105  SCIP_VAR* z; /**< linear variable in constraint */
106  SCIP_Real exponent; /**< exponent n of |x+offset| */
107  SCIP_Real xoffset; /**< offset in x+offset */
108  SCIP_Real zcoef; /**< coefficient of linear variable z */
109  SCIP_Real lhs; /**< left hand side of constraint */
110  SCIP_Real rhs; /**< right hand side of constraint */
111 
112  SCIP_Real root; /**< root of polynomial */
113  DECL_MYPOW ((*power)); /**< function for computing power*/
114 
115  SCIP_Real lhsviol; /**< current (scaled) violation of left hand side */
116  SCIP_Real rhsviol; /**< current (scaled) violation of right hand side */
117 
118  SCIP_Bool isxpropagated; /**< have all bound tightenings on x been propagated? */
119  SCIP_Bool iszpropagated; /**< have all bound tightenings on z been propagated? */
120  int xeventfilterpos; /**< position of x var event in SCIP event filter */
121  int zeventfilterpos; /**< position of z var event in SCIP event filter */
122  unsigned int propvarbounds:1; /**< have variable bounds been propagated? */
123 
124  SCIP_NLROW* nlrow; /**< nonlinear row representation of constraint */
125 };
126 
127 /** constraint handler data */
128 struct SCIP_ConshdlrData
129 {
130  SCIP_Real mincutefficacysepa; /**< minimal efficacy of a cut in order to add it to relaxation during separation */
131  SCIP_Real mincutefficacyenfofac;/**< minimal target efficacy of a cut in order to add it to relaxation during enforcement as factor of feasibility tolerance (may be ignored) */
132  char scaling; /**< scaling method of constraints in feasibility check */
133  SCIP_Real cutmaxrange; /**< maximal coef range (maximal abs coef / minimal abs coef) of a cut in order to be added to LP */
134  SCIP_Bool projectrefpoint; /**< whether to project the reference point when linearizing a absolute power constraint in a convex region */
135  int preferzerobranch; /**< how much we prefer to branch on 0.0 first */
136  SCIP_Bool branchminconverror; /**< whether to compute branching point such that the convexification error is minimized after branching on 0.0 */
137  SCIP_Bool addvarboundcons; /**< should variable bound constraints be added? */
138  SCIP_Bool linfeasshift; /**< try linear feasibility shift heuristic in CONSCHECK */
139  SCIP_Bool dualpresolve; /**< should dual presolve be applied? */
140  SCIP_Bool sepainboundsonly; /**< should tangents only be generated in variable bounds during separation? */
141  SCIP_Real sepanlpmincont; /**< minimal required fraction of continuous variables in problem to use solution of NLP relaxation in root for separation */
142  SCIP_Bool enfocutsremovable; /**< are cuts added during enforcement removable from the LP in the same node? */
143 
144  SCIP_HEUR* subnlpheur; /**< a pointer to the subnlp heuristic */
145  SCIP_HEUR* trysolheur; /**< a pointer to the trysol heuristic */
146  SCIP_EVENTHDLR* eventhdlr; /**< our handler for bound change events on variable x */
147  SCIP_CONSHDLR* conshdlrindicator; /**< a pointer to the indicator constraint handler */
148  int newsoleventfilterpos;/**< filter position of new solution event handler, if catched */
149  SCIP_Bool comparedpairwise; /**< did we compare absolute power constraints pairwise in this run? */
150  SCIP_Bool sepanlp; /**< where linearization of the NLP relaxation solution added? */
151  SCIP_NODE* lastenfolpnode; /**< the node for which enforcement was called the last time (and some constraint was violated) */
152  int nenfolprounds; /**< counter on number of enforcement rounds for the current node */
153  unsigned int nsecantcuts; /**< number of secant cuts created so far */
154  unsigned int ncuts; /**< number of linearization cuts created so far */
155 };
156 
157 /*
158  * Propagation rules
159  */
160 
161 enum Proprule
162 {
163  PROPRULE_1, /**< left hand side and bounds on z -> lower bound on x */
164  PROPRULE_2, /**< left hand side and upper bound on x -> bound on z */
165  PROPRULE_3, /**< right hand side and bounds on z -> upper bound on x */
166  PROPRULE_4, /**< right hand side and lower bound on x -> bound on z */
167  PROPRULE_INVALID /**< propagation was applied without a specific propagation rule */
168 };
169 typedef enum Proprule PROPRULE;
171 /*
172  * Local methods
173  */
174 
175 /** power function for square, that should be faster than using pow(x, 2.0) */
176 static
178 {
179  assert(exponent == 2.0);
180  return base*base;
181 }
182 
183 /** process variable event */
184 static
185 SCIP_DECL_EVENTEXEC(processVarEvent)
186 {
187  SCIP_Bool* ispropagated;
188 
189  assert(scip != NULL);
190  assert(event != NULL);
192 
193  ispropagated = (SCIP_Bool*)eventdata;
194  assert(ispropagated != NULL);
195 
196  *ispropagated = FALSE;
197 
198  return SCIP_OKAY;
199 } /*lint !e715*/
200 
201 /** catch variable bound tightening events */
202 static
204  SCIP* scip, /**< SCIP data structure */
205  SCIP_EVENTHDLR* eventhdlr, /**< event handler for variables */
206  SCIP_CONS* cons /**< constraint for which to catch bound change events */
207  )
208 {
209  SCIP_CONSDATA* consdata;
210  SCIP_EVENTTYPE eventtype;
211 
212  assert(scip != NULL);
213  assert(cons != NULL);
214  assert(eventhdlr != NULL);
215 
216  consdata = SCIPconsGetData(cons);
217  assert(consdata != NULL);
218 
219  /* if z is multiaggregated, then bound changes on x could not be propagated, so we do not need to catch them */
220  if( SCIPvarGetStatus(consdata->z) != SCIP_VARSTATUS_MULTAGGR )
221  {
222  eventtype = SCIP_EVENTTYPE_DISABLED;
223  if( !SCIPisInfinity(scip, -consdata->lhs) )
224  eventtype |= SCIP_EVENTTYPE_UBTIGHTENED;
225  if( !SCIPisInfinity(scip, consdata->rhs) )
226  eventtype |= SCIP_EVENTTYPE_LBTIGHTENED;
227 
228  SCIP_CALL( SCIPcatchVarEvent(scip, consdata->x, eventtype, eventhdlr, (SCIP_EVENTDATA*)&consdata->isxpropagated, &consdata->xeventfilterpos) );
229 
230  consdata->isxpropagated = FALSE;
231  }
232  else
233  consdata->isxpropagated = TRUE;
234 
235  /* if x is multiaggregated, then bound changes on z could not be propagated, so we do not need to catch them */
236  if( SCIPvarGetStatus(consdata->x) != SCIP_VARSTATUS_MULTAGGR )
237  {
238  eventtype = SCIP_EVENTTYPE_DISABLED;
239  if( consdata->zcoef > 0.0 )
240  {
241  if( !SCIPisInfinity(scip, -consdata->lhs) )
242  eventtype |= SCIP_EVENTTYPE_UBTIGHTENED;
243  if( !SCIPisInfinity(scip, consdata->rhs) )
244  eventtype |= SCIP_EVENTTYPE_LBTIGHTENED;
245  }
246  else
247  {
248  if( !SCIPisInfinity(scip, -consdata->lhs) )
249  eventtype |= SCIP_EVENTTYPE_LBTIGHTENED;
250  if( !SCIPisInfinity(scip, consdata->rhs) )
251  eventtype |= SCIP_EVENTTYPE_UBTIGHTENED;
252  }
253 
254  SCIP_CALL( SCIPcatchVarEvent(scip, consdata->z, eventtype, eventhdlr, (SCIP_EVENTDATA*)&consdata->iszpropagated, &consdata->zeventfilterpos) );
255  consdata->iszpropagated = FALSE;
256  }
257  else
258  consdata->iszpropagated = TRUE;
259 
260  return SCIP_OKAY;
261 }
262 
263 /** drop variable bound tightening events */
264 static
266  SCIP* scip, /**< SCIP data structure */
267  SCIP_EVENTHDLR* eventhdlr, /**< event handler for variables */
268  SCIP_CONS* cons /**< constraint for which to drop bound change events */
269  )
270 {
271  SCIP_CONSDATA* consdata;
272  SCIP_EVENTTYPE eventtype;
273 
274  assert(scip != NULL);
275  assert(cons != NULL);
276  assert(eventhdlr != NULL);
277 
278  consdata = SCIPconsGetData(cons);
279  assert(consdata != NULL);
280 
281  if( SCIPvarGetStatus(consdata->z) != SCIP_VARSTATUS_MULTAGGR )
282  {
283  eventtype = SCIP_EVENTTYPE_DISABLED;
284  if( !SCIPisInfinity(scip, -consdata->lhs) )
285  eventtype |= SCIP_EVENTTYPE_UBTIGHTENED;
286  if( !SCIPisInfinity(scip, consdata->rhs) )
287  eventtype |= SCIP_EVENTTYPE_LBTIGHTENED;
288 
289  SCIP_CALL( SCIPdropVarEvent(scip, consdata->x, eventtype, eventhdlr, (SCIP_EVENTDATA*)&consdata->isxpropagated, consdata->xeventfilterpos) );
290  consdata->xeventfilterpos = -1;
291  }
292 
293  if( SCIPvarGetStatus(consdata->x) != SCIP_VARSTATUS_MULTAGGR )
294  {
295  eventtype = SCIP_EVENTTYPE_DISABLED;
296  if( consdata->zcoef > 0.0 )
297  {
298  if( !SCIPisInfinity(scip, -consdata->lhs) )
299  eventtype |= SCIP_EVENTTYPE_UBTIGHTENED;
300  if( !SCIPisInfinity(scip, consdata->rhs) )
301  eventtype |= SCIP_EVENTTYPE_LBTIGHTENED;
302  }
303  else
304  {
305  if( !SCIPisInfinity(scip, -consdata->lhs) )
306  eventtype |= SCIP_EVENTTYPE_LBTIGHTENED;
307  if( !SCIPisInfinity(scip, consdata->rhs) )
308  eventtype |= SCIP_EVENTTYPE_UBTIGHTENED;
309  }
310 
311  SCIP_CALL( SCIPdropVarEvent(scip, consdata->z, eventtype, eventhdlr, (SCIP_EVENTDATA*)&consdata->iszpropagated, consdata->zeventfilterpos) );
312  consdata->zeventfilterpos = -1;
313  }
314 
315  assert(consdata->xeventfilterpos == -1);
316  assert(consdata->zeventfilterpos == -1);
317 
318  return SCIP_OKAY;
319 }
320 
321 /** get key of hash element */
322 static
323 SCIP_DECL_HASHGETKEY(presolveFindDuplicatesGetKey)
324 {
325  return elem;
326 } /*lint !e715*/
327 
328 /** checks if two constraints have the same x variable, the same exponent, and either the same offset or the same linear variable and are both equality constraint */
329 static
330 SCIP_DECL_HASHKEYEQ(presolveFindDuplicatesKeyEQ)
331 {
332  SCIP_CONSDATA* consdata1;
333  SCIP_CONSDATA* consdata2;
334 
335  consdata1 = SCIPconsGetData((SCIP_CONS*)key1);
336  consdata2 = SCIPconsGetData((SCIP_CONS*)key2);
337  assert(consdata1 != NULL);
338  assert(consdata2 != NULL);
339 
340  if( consdata1->x != consdata2->x )
341  return FALSE;
342 
343  if( consdata1->exponent != consdata2->exponent ) /*lint !e777*/
344  return FALSE;
345 
346  if( consdata1->xoffset != consdata2->xoffset && consdata1->z != consdata2->z ) /*lint !e777*/
347  return FALSE;
348 
349  return TRUE;
350 } /*lint !e715*/
351 
352 /** get value of hash element when comparing on x */
353 static
354 SCIP_DECL_HASHKEYVAL(presolveFindDuplicatesKeyVal)
355 {
356  SCIP_CONSDATA* consdata;
357 
358  consdata = SCIPconsGetData((SCIP_CONS*)key);
359  assert(consdata != NULL);
360 
361  return ((unsigned int)(size_t)consdata->x << 16) + (unsigned int)(consdata->exponent*0x80);
362 } /*lint !e715*/
363 
364 /** checks if two constraints have the same z variable and the same exponent */
365 static
366 SCIP_DECL_HASHKEYEQ(presolveFindDuplicatesKeyEQ2)
367 {
368  SCIP_CONSDATA* consdata1;
369  SCIP_CONSDATA* consdata2;
370 
371  consdata1 = SCIPconsGetData((SCIP_CONS*)key1);
372  consdata2 = SCIPconsGetData((SCIP_CONS*)key2);
373  assert(consdata1 != NULL);
374  assert(consdata2 != NULL);
375 
376  if( consdata1->z != consdata2->z )
377  return FALSE;
378 
379  if( consdata1->exponent != consdata2->exponent ) /*lint !e777*/
380  return FALSE;
381 
382  return TRUE;
383 } /*lint !e715*/
384 
385 /** get value of hash element when comparing on z */
386 static
387 SCIP_DECL_HASHKEYVAL(presolveFindDuplicatesKeyVal2)
388 {
389  SCIP_CONSDATA* consdata;
390 
391  consdata = SCIPconsGetData((SCIP_CONS*)key);
392  assert(consdata != NULL);
393 
394  return ((unsigned int)(size_t)consdata->z << 16) + (unsigned int)(consdata->exponent*0x80);
395 } /*lint !e715*/
396 
397 /** upgrades a signpower constraint to a linear constraint if a second signpower constraint with same nonlinear term is available */
398 static
400  SCIP* scip, /**< SCIP data structure */
401  SCIP_CONS* cons1, /**< constraint to upgrade to a linear constraint */
402  SCIP_CONS* cons2, /**< constraint which defines a relation for x|x|^{n-1} */
403  SCIP_Bool* infeas, /**< buffer where to indicate if infeasibility has been detected */
404  int* nupgdconss, /**< buffer where to add number of upgraded conss */
405  int* ndelconss, /**< buffer where to add number of deleted conss */
406  int* naggrvars /**< buffer where to add number of aggregated variables */
407  )
408 {
409  SCIP_CONSDATA* consdata1;
410  SCIP_CONSDATA* consdata2;
411  SCIP_CONS* lincons;
412  SCIP_Real lhs;
413  SCIP_Real rhs;
414  SCIP_VAR* vars[2];
415  SCIP_Real coefs[2];
416 
417  assert(scip != NULL);
418  assert(cons1 != NULL);
419  assert(cons2 != NULL);
420  assert(infeas != NULL);
421  assert(nupgdconss != NULL);
422  assert(ndelconss != NULL);
423  assert(naggrvars != NULL);
424 
425  consdata1 = SCIPconsGetData(cons1);
426  consdata2 = SCIPconsGetData(cons2);
427  assert(consdata1 != NULL);
428  assert(consdata2 != NULL);
429 
430  assert(SCIPisEQ(scip, consdata2->lhs, consdata2->rhs));
431  assert(!SCIPisInfinity(scip, consdata2->lhs));
432  assert(consdata1->x == consdata2->x);
433  assert(consdata1->exponent == consdata2->exponent); /*lint !e777*/
434  assert(consdata1->xoffset == consdata2->xoffset); /*lint !e777*/
435 
436  lhs = consdata1->lhs;
437  if( !SCIPisInfinity(scip, -lhs) )
438  lhs -= consdata2->lhs;
439  rhs = consdata1->rhs;
440  if( !SCIPisInfinity(scip, rhs) )
441  rhs -= consdata2->lhs;
442 
443  vars[0] = consdata1->z;
444  vars[1] = consdata2->z;
445 
446  coefs[0] = consdata1->zcoef;
447  coefs[1] = -consdata2->zcoef;
448 
449  if( SCIPisEQ(scip, lhs, rhs) )
450  {
451  SCIP_Bool redundant;
452  SCIP_Bool aggregated;
453 
454  /* try aggregation */
455  SCIP_CALL( SCIPaggregateVars(scip, consdata1->z, consdata2->z, consdata1->zcoef, -consdata2->zcoef, rhs, infeas, &redundant, &aggregated) );
456 
457  /* if infeasibility has been detected, stop here */
458  if( *infeas )
459  return SCIP_OKAY;
460 
461  if( redundant )
462  {
463  /* if redundant is TRUE, then either the aggregation has been done, or it was redundant */
464  if( aggregated )
465  ++*naggrvars;
466 
467  ++*ndelconss;
468 
469  SCIP_CALL( SCIPdelCons(scip, cons1) );
470  return SCIP_OKAY;
471  }
472  }
473 
474  /* if aggregation did not succeed, then either because some variable is multi-aggregated or due to numerics or because lhs != rhs
475  * we then add a linear constraint instead
476  */
477  vars[0] = consdata1->z;
478  vars[1] = consdata2->z;
479  coefs[0] = consdata1->zcoef;
480  coefs[1] = -consdata2->zcoef;
481 
482  SCIP_CALL( SCIPcreateConsLinear(scip, &lincons, SCIPconsGetName(cons1), 2, vars, coefs, lhs, rhs,
486  SCIPconsIsStickingAtNode(cons1)) );
487  SCIP_CALL( SCIPaddCons(scip, lincons) );
488  SCIP_CALL( SCIPreleaseCons(scip, &lincons) );
489 
490  SCIP_CALL( SCIPdelCons(scip, cons1) );
491  ++*nupgdconss;
492 
493  return SCIP_OKAY;
494 }
495 
496 /** solves a system of two absolute power equations
497  * Given: (x+xoffset1)|x+xoffset1|^{exponent-1} + zcoef1 * z == rhs1
498  * and (x+xoffset2)|x+xoffset2|^{exponent-1} + zcoef2 * z == rhs2
499  * with xoffset1 != xoffset2 and zcoef1 * rhs2 == zcoef2 * rhs1 and exponent == 2,
500  * finds values for x and z that satisfy these equations, or reports infeasibility if no solution exists.
501  *
502  * Multiplying the second equation by -zcoef1/zcoef2 and adding it to the first one gives
503  * (x+xoffset1)|x+xoffset1| - zcoef1/zcoef2 (x+offset2)|x+offset2| == 0
504  *
505  * If zcoef1 == zcoef2, then there exists, due to monotonicity of x|x|, no x such that
506  * (x+xoffset1)|x+xoffset1| == (x+xoffset2)|x+xoffset2|.
507  *
508  * In general, for zcoef1 / zcoef2 > 0.0, we get
509  * x = (xoffset2 - xoffset1) / (sqrt(zcoef2 / zcoef1) - 1.0) - xoffset1,
510  * and for zcoef1 / zcoef2 < 0.0, we get
511  * x = (xoffset2 - xoffset1) / (-sqrt(-zcoef2 / zcoef1) - 1.0) - xoffset1.
512  *
513  * This then yields z = (rhs1 - (x+xoffset1)|x+xoffset1|) / zcoef1.
514  */
515 static
517  SCIP* scip, /**< SCIP data structure */
518  SCIP_Bool* infeas, /**< buffer to indicate if the system of equations has no solution */
519  SCIP_Real* xval, /**< buffer to store value of x in the solution, if any */
520  SCIP_Real* zval, /**< buffer to store value of z in the solution, if any */
521  SCIP_Real exponent, /**< exponent in absolute power equations */
522  SCIP_Real xoffset1, /**< offset for x in first absolute power equation */
523  SCIP_Real zcoef1, /**< coefficient of z in first absolute power equation */
524  SCIP_Real rhs1, /**< right-hand-side in first absolute power equation */
525  SCIP_Real xoffset2, /**< offset for x in second absolute power equation */
526  SCIP_Real zcoef2, /**< coefficient of z in second absolute power equation */
527  SCIP_Real rhs2 /**< right-hand-side in second absolute power equation */
528  )
529 {
530  assert(scip != NULL);
531  assert(infeas != NULL);
532  assert(xval != NULL);
533  assert(zval != NULL);
534  assert(exponent == 2.0);
535  assert(!SCIPisEQ(scip, xoffset1, xoffset2));
536  assert(SCIPisEQ(scip, zcoef1 * rhs2, zcoef2 * rhs1));
537  assert(zcoef1 != 0.0);
538  assert(zcoef2 != 0.0);
539 
540  if( xoffset2 < xoffset1 )
541  {
542  presolveFindDuplicatesSolveEquations(scip, infeas, xval, zval, exponent, xoffset2, zcoef2, rhs2, xoffset1, zcoef1, rhs1);
543  return;
544  }
545 
546  if( SCIPisEQ(scip, zcoef1, zcoef2) )
547  {
548  *infeas = TRUE;
549  return;
550  }
551 
552  *infeas = FALSE;
553 
554  if( SCIPisEQ(scip, zcoef1, -zcoef2) )
555  {
556  *xval = - (xoffset1 + xoffset2) / 2.0;
557  }
558  else if( zcoef2 * zcoef1 > 0.0 )
559  {
560  *xval = (xoffset2 - xoffset1) / (sqrt(zcoef2 / zcoef1) - 1.0) - xoffset1;
561  }
562  else
563  {
564  assert(zcoef2 * zcoef1 < 0.0);
565  *xval = (xoffset2 - xoffset1) / (-sqrt(-zcoef2 / zcoef1) - 1.0) - xoffset1;
566  }
567 
568  *zval = rhs1 - (*xval + xoffset1) * REALABS(*xval + xoffset1);
569  *zval /= zcoef1;
570 
571  assert(SCIPisFeasEQ(scip, (*xval + xoffset1) * REALABS(*xval + xoffset1) + zcoef1 * *zval, rhs1));
572  assert(SCIPisFeasEQ(scip, (*xval + xoffset2) * REALABS(*xval + xoffset2) + zcoef2 * *zval, rhs2));
573 }
574 
575 /** finds and removes duplicates in a set of absolute power constraints */
576 static
578  SCIP* scip, /**< SCIP data structure */
579  SCIP_CONSHDLR* conshdlr, /**< constraint handler for absolute power constraints */
580  SCIP_CONS** conss, /**< constraints */
581  int nconss, /**< number of constraints */
582  int* nupgdconss, /**< pointer where to add number of upgraded constraints */
583  int* ndelconss, /**< pointer where to add number of deleted constraints */
584  int* naddconss, /**< pointer where to add number of added constraints */
585  int* nfixedvars, /**< pointer where to add number of fixed variables */
586  int* naggrvars, /**< pointer where to add number of aggregated variables */
587  SCIP_Bool* success, /**< pointer to store whether a duplicate was found (and removed) */
588  SCIP_Bool* infeas /**< pointer to store whether infeasibility was detected */
589  )
590 {
591  SCIP_HASHTABLE* hashtable;
592  SCIP_HASHTABLELIST* hashtablelist;
593  SCIP_CONSHDLRDATA* conshdlrdata;
594  int c;
595 
596  assert(scip != NULL);
597  assert(conshdlr != NULL);
598  assert(conss != NULL || nconss == 0);
599  assert(nupgdconss != NULL);
600  assert(ndelconss != NULL);
601  assert(naddconss != NULL);
602  assert(nfixedvars != NULL);
603  assert(naggrvars != NULL);
604  assert(success != NULL);
605  assert(infeas != NULL);
606 
607  *success = FALSE;
608  *infeas = FALSE;
609 
610  if( nconss <= 1 )
611  return SCIP_OKAY;
612 
613  conshdlrdata = SCIPconshdlrGetData(conshdlr);
614  assert(conshdlrdata != NULL);
615 
616  /* check all constraints in the given set for duplicates, dominance, or possible simplifications w.r.t. the x variable */
617 
619  presolveFindDuplicatesGetKey, presolveFindDuplicatesKeyEQ, presolveFindDuplicatesKeyVal, (void*)scip) );
620 
621  for( c = 0; c < nconss && !*infeas; ++c )
622  {
623  SCIP_CONS* cons0;
624  SCIP_CONS* cons1;
625 
626  cons0 = conss[c]; /*lint !e613*/
627 
628  assert(!SCIPconsIsModifiable(cons0)); /* absolute power constraints aren't modifiable */
629  assert(!SCIPconsIsLocal(cons0)); /* shouldn't have local constraints in presolve */
630  assert(SCIPconsIsActive(cons0)); /* shouldn't get inactive constraints here */
631 
632  hashtablelist = NULL;
633 
634  do
635  {
636  SCIP_CONSDATA* consdata0;
637  SCIP_CONSDATA* consdata1;
638 
639  /* get constraint from current hash table with same x variable as cons0 and same exponent */
640  cons1 = (SCIP_CONS*)(SCIPhashtableRetrieveNext(hashtable, &hashtablelist, (void*)cons0));
641  if( cons1 == NULL )
642  {
643  /* processed all constraints like cons0 from hash table, so insert cons0 and go to conss[c+1] */
644  SCIP_CALL( SCIPhashtableInsert(hashtable, (void*) cons0) );
645  break;
646  }
647 
648  assert(cons0 != cons1);
649 
650  consdata0 = SCIPconsGetData(cons0);
651  consdata1 = SCIPconsGetData(cons1);
652  assert(consdata0 != NULL);
653  assert(consdata1 != NULL);
654 
655  SCIPdebugPrintCons(scip, cons0, NULL);
656  SCIPdebugPrintCons(scip, cons1, NULL);
657 
658  assert(consdata0->x == consdata1->x);
659  assert(consdata0->exponent == consdata1->exponent); /*lint !e777*/
660 
661  if( SCIPisEQ(scip, consdata0->xoffset, consdata1->xoffset) )
662  {
663  /* we have two constraints with the same (x+offset)|x+offset|^n term */
664 
665  /* if both constraints have the same functions; strengthen sides of cons1 and throw cons0 away */
666  if( consdata0->z == consdata1->z && SCIPisEQ(scip, consdata0->zcoef, consdata1->zcoef) )
667  {
668  /* check if side strenghtening would result in inconsistency */
669  if( SCIPisGT(scip, consdata0->lhs, consdata1->rhs) || SCIPisGT(scip, consdata1->lhs, consdata0->rhs) )
670  {
671  SCIPdebugMessage("<%s> and <%s> are contradictory; declare infeasibility\n", SCIPconsGetName(cons0), SCIPconsGetName(cons1));
672  *infeas = TRUE;
673  break;
674  }
675 
676  SCIPdebugMessage("<%s> and <%s> are equivalent; dropping the first\n", SCIPconsGetName(cons0), SCIPconsGetName(cons1));
677 
678  /* if a side of cons1 gets finite via merging with cons0, then this changes locks and events */
679  if( (SCIPisInfinity(scip, -consdata1->lhs) && !SCIPisInfinity(scip, -consdata0->lhs)) ||
680  ( SCIPisInfinity(scip, consdata1->rhs) && !SCIPisInfinity(scip, consdata0->rhs)) )
681  {
682  SCIP_CALL( dropVarEvents(scip, conshdlrdata->eventhdlr, cons1) );
683  SCIP_CALL( SCIPunlockVarCons(scip, consdata1->x, cons1, !SCIPisInfinity(scip, -consdata1->lhs), !SCIPisInfinity(scip, consdata1->rhs)) );
684  if( consdata1->zcoef > 0.0 )
685  SCIP_CALL( SCIPunlockVarCons(scip, consdata1->z, cons1, !SCIPisInfinity(scip, -consdata1->lhs), !SCIPisInfinity(scip, consdata1->rhs)) );
686  else
687  SCIP_CALL( SCIPunlockVarCons(scip, consdata1->z, cons1, !SCIPisInfinity(scip, consdata1->rhs), !SCIPisInfinity(scip, -consdata1->lhs)) );
688 
689  consdata1->lhs = MAX(consdata0->lhs, consdata1->lhs);
690  consdata1->rhs = MIN(consdata0->rhs, consdata1->rhs);
691 
692  SCIP_CALL( catchVarEvents(scip, conshdlrdata->eventhdlr, cons1) );
693  SCIP_CALL( SCIPlockVarCons(scip, consdata1->x, cons1, !SCIPisInfinity(scip, -consdata1->lhs), !SCIPisInfinity(scip, consdata1->rhs)) );
694  if( consdata1->zcoef > 0.0 )
695  SCIP_CALL( SCIPlockVarCons(scip, consdata1->z, cons1, !SCIPisInfinity(scip, -consdata1->lhs), !SCIPisInfinity(scip, consdata1->rhs)) );
696  else
697  SCIP_CALL( SCIPlockVarCons(scip, consdata1->z, cons1, !SCIPisInfinity(scip, consdata1->rhs), !SCIPisInfinity(scip, -consdata1->lhs)) );
698  }
699  else
700  {
701  consdata1->lhs = MAX(consdata0->lhs, consdata1->lhs);
702  consdata1->rhs = MIN(consdata0->rhs, consdata1->rhs);
703  }
704 
705  SCIP_CALL( SCIPdelCons(scip, cons0) );
706  ++*ndelconss;
707  *success = TRUE;
708 
709  break;
710  }
711 
712  /* if cons1 defines a linear expression for sign(x+offset)|x+offset|^n, use it to replace cons0 by a linear constraint */
713  if( SCIPisEQ(scip, consdata1->lhs, consdata1->rhs) )
714  {
715  SCIPdebugMessage("substitute <%s> in <%s> to make linear constraint\n", SCIPconsGetName(cons1), SCIPconsGetName(cons0));
716  SCIP_CALL( presolveFindDuplicatesUpgradeCons(scip, cons0, cons1, infeas, nupgdconss, ndelconss, naggrvars) );
717 
718  *success = TRUE;
719  break;
720  }
721 
722  /* if cons0 defines a linear expression for sign(x+offset)|x+offset|^n, use it to replace cons1 by a linear constraint */
723  if( SCIPisEQ(scip, consdata0->lhs, consdata0->rhs) )
724  {
725  SCIPdebugMessage("substitute <%s> in <%s> to make linear constraint\n", SCIPconsGetName(cons0), SCIPconsGetName(cons1));
726  SCIP_CALL( presolveFindDuplicatesUpgradeCons(scip, cons1, cons0, infeas, nupgdconss, ndelconss, naggrvars) );
727 
728  SCIP_CALL( SCIPhashtableRemove(hashtable, cons1) );
729  *success = TRUE;
730 
731  if( *infeas )
732  break;
733  }
734  else
735  {
736  /* introduce a new equality constraint for sign(x+offset)|x+offset|^n and use it to replace cons0 and cons1 */
737  /* @todo maybe we could be more clever by looking which constraint sides are finite */
738  SCIP_VAR* auxvar;
739  SCIP_CONS* auxcons;
740  char name[SCIP_MAXSTRLEN];
741  SCIP_VAR* vars[2];
742  SCIP_Real coefs[2];
743 
744  SCIPdebugMessage("introduce new auxvar for signpower(%s+%g, %g) to make <%s> and <%s> linear constraint\n", SCIPvarGetName(consdata0->x), consdata0->exponent, consdata0->xoffset, SCIPconsGetName(cons0), SCIPconsGetName(cons1));
745 
746  /* create auxiliary variable to represent sign(x+offset)|x+offset|^n */
747  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "auxvar_abspower%s_%g_%g", SCIPvarGetName(consdata0->x), consdata0->exponent, consdata0->xoffset);
748  SCIP_CALL( SCIPcreateVar(scip, &auxvar, name, -SCIPinfinity(scip), SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS,
749  TRUE, TRUE, NULL, NULL, NULL, NULL, NULL) );
750  SCIP_CALL( SCIPaddVar(scip, auxvar) );
751 
752  /* create auxiliary constraint auxvar = sign(x+offset)|x+offset|^n
753  * as we introduced a new variable, the constraint that "defines" the value for this variable need to be enforced, that is, is not redundent
754  */
755  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "auxcons_abspower%s_%g_%g", SCIPvarGetName(consdata0->x), consdata0->exponent, consdata0->xoffset);
756  SCIP_CALL( SCIPcreateConsAbspower(scip, &auxcons, name, consdata0->x, auxvar, consdata0->exponent, consdata0->xoffset, -1.0, 0.0, 0.0,
757  SCIPconsIsInitial(cons0) || SCIPconsIsInitial(cons1),
758  SCIPconsIsSeparated(cons0) || SCIPconsIsSeparated(cons1),
759  TRUE,
760  TRUE,
762  FALSE,
763  FALSE,
764  SCIPconsIsDynamic(cons0) || SCIPconsIsDynamic(cons1),
765  SCIPconsIsRemovable(cons0) || SCIPconsIsRemovable(cons1),
767  ) );
768  SCIP_CALL( SCIPaddCons(scip, auxcons) );
769  SCIP_CALL( SCIPreleaseCons(scip, &auxcons) );
770  ++*naddconss;
771 
772 #ifdef SCIP_DEBUG_SOLUTION
773  if( SCIPdebugIsMainscip(scip) )
774  {
775  SCIP_Real xval;
776 
777  SCIP_CALL( SCIPdebugGetSolVal(scip, consdata0->x, &xval) );
778  SCIP_CALL( SCIPdebugAddSolVal(scip, auxvar, SIGN(xval + consdata0->xoffset) * pow(REALABS(xval + consdata0->xoffset), consdata0->exponent)) );
779  }
780 #endif
781 
782  /* create linear constraint equivalent for cons0 */
783  vars[0] = auxvar;
784  vars[1] = consdata0->z;
785  coefs[0] = 1.0;
786  coefs[1] = consdata0->zcoef;
787  SCIP_CALL( SCIPcreateConsLinear(scip, &auxcons, SCIPconsGetName(cons0), 2, vars, coefs, consdata0->lhs, consdata0->rhs,
791  SCIPconsIsStickingAtNode(cons0)) );
792  SCIP_CALL( SCIPaddCons(scip, auxcons) );
793  SCIP_CALL( SCIPreleaseCons(scip, &auxcons) );
794  ++*nupgdconss;
795 
796  /* create linear constraint equivalent for cons1 */
797  vars[1] = consdata1->z;
798  coefs[1] = consdata1->zcoef;
799  SCIP_CALL( SCIPcreateConsLinear(scip, &auxcons, SCIPconsGetName(cons1), 2, vars, coefs, consdata1->lhs, consdata1->rhs,
803  SCIPconsIsStickingAtNode(cons1)) );
804  SCIP_CALL( SCIPaddCons(scip, auxcons) );
805  SCIP_CALL( SCIPreleaseCons(scip, &auxcons) );
806  ++*nupgdconss;
807 
808  SCIP_CALL( SCIPreleaseVar(scip, &auxvar) );
809 
810  SCIP_CALL( SCIPdelCons(scip, cons0) );
811  SCIP_CALL( SCIPdelCons(scip, cons1) );
812  SCIP_CALL( SCIPhashtableRemove(hashtable, cons1) );
813  *success = TRUE;
814 
815  break;
816  }
817  }
818  else if( consdata0->z == consdata1->z &&
819  consdata0->exponent == 2.0 &&
820  !SCIPisZero(scip, consdata0->zcoef) &&
821  !SCIPisZero(scip, consdata1->zcoef) &&
822  SCIPisEQ(scip, consdata0->lhs, consdata0->rhs) &&
823  SCIPisEQ(scip, consdata1->lhs, consdata1->rhs) &&
824  SCIPisEQ(scip, consdata0->lhs * consdata1->zcoef, consdata1->lhs * consdata0->zcoef) )
825  {
826  /* If we have two equality constraints with the same variables and the same exponent and compatible constants,
827  * then this system of equations should have either no or a single solution.
828  * Thus, we can report cutoff or fix the variables to this solution, and forget about the constraints.
829  * @todo think about inequalities, differing exponents, and exponents != 2
830  */
831 
832  SCIP_Real xval;
833  SCIP_Real zval;
834 
835  assert(consdata0->x == consdata1->x);
836  assert(consdata0->exponent == consdata1->exponent); /*lint !e777*/
837  assert(!SCIPisEQ(scip, consdata0->xoffset, consdata1->xoffset));
838 
839  presolveFindDuplicatesSolveEquations(scip, infeas, &xval, &zval,
840  consdata0->exponent,
841  consdata0->xoffset, consdata0->zcoef, consdata0->lhs,
842  consdata1->xoffset, consdata1->zcoef, consdata1->lhs);
843 
844  if( *infeas )
845  {
846  SCIPdebugMessage("infeasibility detected while solving the equations, no solution exists\n");
847  SCIPdebugPrintCons(scip, cons0, NULL);
848  SCIPdebugPrintCons(scip, cons1, NULL);
849  break;
850  }
851 
852  SCIPdebugMessage("fixing variables <%s>[%g, %g] to %g and <%s>[%g, %g] to %g due to equations\n",
853  SCIPvarGetName(consdata0->x), SCIPvarGetLbLocal(consdata0->x), SCIPvarGetUbLocal(consdata0->x), xval,
854  SCIPvarGetName(consdata0->z), SCIPvarGetLbLocal(consdata0->z), SCIPvarGetUbLocal(consdata0->z), zval);
855  SCIPdebugPrintCons(scip, cons0, NULL);
856  SCIPdebugPrintCons(scip, cons1, NULL);
857 
859  {
860  SCIP_Bool fixed;
861 
862  SCIP_CALL( SCIPfixVar(scip, consdata0->x, xval, infeas, &fixed) );
863  ++*ndelconss;
864 
865  if( fixed )
866  ++*nfixedvars;
867 
868  if( *infeas )
869  {
870  SCIPdebugMessage("infeasibility detected after fixing <%s>\n", SCIPvarGetName(consdata0->x));
871  break;
872  }
873  }
874  else
875  {
876  SCIP_CONS* lincons;
877  SCIP_Real one;
878 
879  one = 1.0;
880  SCIP_CALL( SCIPcreateConsLinear(scip, &lincons, SCIPconsGetName(cons0), 1, &consdata0->x, &one, xval, xval,
882  SCIP_CALL( SCIPaddCons(scip, lincons) );
883  SCIP_CALL( SCIPreleaseCons(scip, &lincons) );
884  ++*nupgdconss;
885  }
886 
888  {
889  SCIP_Bool fixed;
890 
891  SCIP_CALL( SCIPfixVar(scip, consdata0->z, zval, infeas, &fixed) );
892  ++*ndelconss;
893 
894  if( fixed )
895  ++*nfixedvars;
896 
897  if( *infeas )
898  {
899  SCIPdebugMessage("infeasibility detected after fixing <%s>\n", SCIPvarGetName(consdata0->z));
900  break;
901  }
902  }
903  else
904  {
905  SCIP_CONS* lincons;
906  SCIP_Real one;
907 
908  one = 1.0;
909  SCIP_CALL( SCIPcreateConsLinear(scip, &lincons, SCIPconsGetName(cons1), 1, &consdata0->z, &one, zval, zval,
911  SCIP_CALL( SCIPaddCons(scip, lincons) );
912  SCIP_CALL( SCIPreleaseCons(scip, &lincons) );
913  ++*nupgdconss;
914  }
915 
916  SCIP_CALL( SCIPdelCons(scip, cons0) );
917  SCIP_CALL( SCIPdelCons(scip, cons1) );
918  SCIP_CALL( SCIPhashtableRemove(hashtable, cons1) );
919  *success = TRUE;
920 
921  break;
922  }
923 
924  if( hashtablelist == NULL )
925  {
926  /* processed all constraints like cons0 from hash table, but cons0 could not be removed, so insert cons0 into hashmap and go to conss[c+1] */
927  SCIP_CALL( SCIPhashtableInsert(hashtable, (void*) cons0) );
928  break;
929  }
930  }
931  while( TRUE ); /*lint !e506*/
932  }
933 
934  /* free hash table */
935  SCIPhashtableFree(&hashtable);
936 
937  if( *infeas )
938  return SCIP_OKAY;
939 
940 
941  /* check all constraints in the given set for duplicates, dominance, or possible simplifications w.r.t. the z variable */
942 
944  presolveFindDuplicatesGetKey, presolveFindDuplicatesKeyEQ2, presolveFindDuplicatesKeyVal2, (void*) scip) );
945 
946  for( c = 0; c < nconss && !*infeas; ++c )
947  {
948  SCIP_CONS* cons0;
949  SCIP_CONS* cons1;
950  SCIP_CONSDATA* consdata0;
951 
952  cons0 = conss[c]; /*lint !e613*/
953 
954  assert(!SCIPconsIsModifiable(cons0)); /* absolute power constraints aren't modifiable */
955  assert(!SCIPconsIsLocal(cons0)); /* shouldn't have local constraints in presolve */
956 
957  /* do not consider constraints that we have deleted in the above loop */
958  if( SCIPconsIsDeleted(cons0) )
959  continue;
960  assert(SCIPconsIsActive(cons0)); /* shouldn't get inactive constraints here */
961 
962  consdata0 = SCIPconsGetData(cons0);
963  assert(consdata0 != NULL);
964 
965  /* consider only equality constraints so far
966  * @todo do also something with inequalities
967  */
968  if( !SCIPisEQ(scip, consdata0->lhs, consdata0->rhs) )
969  continue;
970 
971  hashtablelist = NULL;
972 
973  do
974  {
975  SCIP_CONSDATA* consdata1;
976 
977  /* get constraint from current hash table with same z variable as cons0 and same exponent */
978  cons1 = (SCIP_CONS*)(SCIPhashtableRetrieveNext(hashtable, &hashtablelist, (void*)cons0));
979  if( cons1 == NULL )
980  {
981  /* processed all constraints like cons0 from hash table, so insert cons0 and go to conss[c+1] */
982  SCIP_CALL( SCIPhashtableInsert(hashtable, (void*) cons0) );
983  break;
984  }
985 
986  assert(cons0 != cons1);
987  assert(!SCIPconsIsDeleted(cons1));
988 
989  consdata1 = SCIPconsGetData(cons1);
990  assert(consdata1 != NULL);
991 
992  SCIPdebugPrintCons(scip, cons0, NULL);
993  SCIPdebugPrintCons(scip, cons1, NULL);
994 
995  assert(consdata0->z == consdata1->z);
996  assert(consdata0->exponent == consdata1->exponent); /*lint !e777*/
997  assert(SCIPisEQ(scip, consdata1->lhs, consdata1->rhs));
998  assert(!SCIPisZero(scip, consdata1->zcoef));
999 
1000  if( SCIPisEQ(scip, consdata0->lhs*consdata1->zcoef, consdata1->lhs*consdata0->zcoef) )
1001  {
1002  /* have two absolute power equations with same z and compatible constants
1003  * we can then reduce this to one absolute power and one linear equation
1004  * -> x0 + xoffset0 = signpower(zcoef0/zcoef1, 1/exponent) (x1 + xoffset1)
1005  * -> keep cons1
1006  * the latter can be realized as an aggregation (if x0 and x1 are not multiaggregated) or linear constraint
1007  */
1008  SCIP_Bool redundant;
1009  SCIP_Bool aggregated;
1010  SCIP_Real coef;
1011  SCIP_Real rhs;
1012 
1013  SCIPdebugMessage("<%s> and <%s> can be reformulated to one abspower and one aggregation\n", SCIPconsGetName(cons0), SCIPconsGetName(cons1));
1014  SCIPdebugPrintCons(scip, cons0, NULL);
1015  SCIPdebugPrintCons(scip, cons1, NULL);
1016 
1017  if( consdata0->exponent == 2.0 )
1018  coef = SIGN(consdata0->zcoef / consdata1->zcoef) * sqrt(REALABS(consdata0->zcoef / consdata1->zcoef));
1019  else
1020  coef = SIGN(consdata0->zcoef / consdata1->zcoef) * pow(REALABS(consdata0->zcoef / consdata1->zcoef), 1.0/consdata0->exponent);
1021  rhs = coef * consdata1->xoffset - consdata0->xoffset;
1022 
1023  /* try aggregation */
1024  SCIP_CALL( SCIPaggregateVars(scip, consdata0->x, consdata1->x, 1.0, -coef, rhs, infeas, &redundant, &aggregated) );
1025  if( *infeas )
1026  {
1027  /* if infeasibility has been detected, stop here */
1028  break;
1029  }
1030  else if( redundant )
1031  {
1032  /* if redundant is TRUE, then either the aggregation has been done, or it was redundant */
1033  if( aggregated )
1034  ++*naggrvars;
1035 
1036  ++*ndelconss;
1037  }
1038  else
1039  {
1040  /* if aggregation did not succeed, then either because some variable is multi-aggregated or due to numerics
1041  * we then add a linear constraint instead
1042  */
1043  SCIP_CONS* auxcons;
1044  SCIP_VAR* vars[2];
1045  SCIP_Real coefs[2];
1046 
1047  vars[0] = consdata0->x;
1048  vars[1] = consdata1->x;
1049  coefs[0] = 1.0;
1050  coefs[1] = -coef;
1051 
1052  /* create linear constraint equivalent for cons0 */
1053  SCIP_CALL( SCIPcreateConsLinear(scip, &auxcons, SCIPconsGetName(cons0), 2, vars, coefs, rhs, rhs,
1057  SCIPconsIsStickingAtNode(cons0)) );
1058  SCIP_CALL( SCIPaddCons(scip, auxcons) );
1059  SCIPdebugPrintCons(scip, auxcons, NULL);
1060  SCIP_CALL( SCIPreleaseCons(scip, &auxcons) );
1061 
1062  ++*nupgdconss;
1063  }
1064  SCIP_CALL( SCIPdelCons(scip, cons0) );
1065 
1066  *success = TRUE;
1067  break;
1068  }
1069 
1070  if( hashtablelist == NULL )
1071  {
1072  /* processed all constraints like cons0 from hash table, but cons0 could not be removed, so insert cons0 into hashmap and go to conss[c+1] */
1073  SCIP_CALL( SCIPhashtableInsert(hashtable, (void*) cons0) );
1074  break;
1075  }
1076  }
1077  while( TRUE ); /*lint !e506*/
1078  }
1079 
1080  /* free hash table */
1081  SCIPhashtableFree(&hashtable);
1082 
1083  return SCIP_OKAY;
1084 }
1085 
1086 /** fix variables not appearing in any other constraint
1087  *
1088  * @todo generalize to inequalities
1089  * @todo generalize to support discrete variables
1090  * @todo generalize to arbitrary exponents also if z is in objective
1091  */
1092 static
1094  SCIP* scip, /**< SCIP data structure */
1095  SCIP_CONS* cons, /**< constraint */
1096  SCIP_Bool* cutoff, /**< buffer to indicate whether a cutoff was detected */
1097  int* ndelconss, /**< buffer to increase with the number of deleted constraint */
1098  int* nfixedvars /**< buffer to increase with the number of fixed variables */
1099  )
1100 {
1101  SCIP_CONSDATA* consdata;
1102  SCIP_Bool lhsexists;
1103  SCIP_Bool rhsexists;
1104 
1105  assert(scip != NULL);
1106  assert(cons != NULL);
1107  assert(cutoff != NULL);
1108  assert(nfixedvars != NULL);
1109  assert(ndelconss != NULL);
1110 
1111  /* only process checked constraints (for which the locks are increased);
1112  * otherwise we would have to check for variables with nlocks == 0, and these are already processed by the
1113  * dualfix presolver
1114  */
1115  if( !SCIPconsIsChecked(cons) )
1116  return SCIP_OKAY;
1117 
1118  consdata = SCIPconsGetData(cons);
1119  assert(consdata != NULL);
1120 
1121  /* skip dual presolve if multiaggregated variables are present for now (bounds are not updated, difficult to fix) */
1122  if( SCIPvarGetStatus(consdata->x) == SCIP_VARSTATUS_MULTAGGR )
1123  return SCIP_OKAY;
1124  if( SCIPvarGetStatus(consdata->z) == SCIP_VARSTATUS_MULTAGGR )
1125  return SCIP_OKAY;
1126 
1127  /* skip dual presolve if discrete variables are present for now (more difficult to compute fixing value) */
1128  if( SCIPvarGetType(consdata->x) <= SCIP_VARTYPE_INTEGER )
1129  return SCIP_OKAY;
1130  if( SCIPvarGetType(consdata->z) <= SCIP_VARTYPE_INTEGER )
1131  return SCIP_OKAY;
1132 
1133  /* we assume that domain propagation has been run and fixed variables were removed if possible */
1134  assert(consdata->isxpropagated);
1135  assert(consdata->iszpropagated);
1136  assert(consdata->zcoef != 0.0);
1137 
1138  lhsexists = !SCIPisInfinity(scip, -consdata->lhs);
1139  rhsexists = !SCIPisInfinity(scip, consdata->rhs);
1140 
1141  if( SCIPvarGetNLocksDown(consdata->x) == (lhsexists ? 1 : 0) &&
1142  SCIPvarGetNLocksUp(consdata->x) == (rhsexists ? 1 : 0) &&
1143  (consdata->zcoef > 0.0 ? SCIPvarGetNLocksDown(consdata->z) : SCIPvarGetNLocksUp(consdata->z)) == (lhsexists ? 1 : 0) &&
1144  (consdata->zcoef > 0.0 ? SCIPvarGetNLocksUp(consdata->z) : SCIPvarGetNLocksDown(consdata->z)) == (rhsexists ? 1 : 0) )
1145  {
1146  /* x and z are only locked by cons, so we can fix them to an optimal solution of
1147  * min xobj * x + zobj * z
1148  * s.t. lhs <= sign(x+offset)*abs(x+offset)^exponent + zcoef * z <= rhs
1149  * xlb <= x <= xub
1150  * zlb <= z <= zub
1151  */
1152  if( SCIPisEQ(scip, consdata->lhs, consdata->rhs) )
1153  {
1154  /* much simpler case where we can substitute z:
1155  * min xobj * x + zobj/zcoef * (rhs - sign(x+offset)*abs(x+offset)^exponent)
1156  * s.t. xlb <= x <= xub
1157  *
1158  * Since domain propagation had been applied, we can assume that for any valid value for x,
1159  * also the corresponding z value is valid.
1160  */
1161  SCIP_Real xfix;
1162  SCIP_Real xlb;
1163  SCIP_Real xub;
1164  SCIP_Real zfix;
1165  SCIP_Bool fixed;
1166 
1167  xlb = SCIPvarGetLbGlobal(consdata->x);
1168  xub = SCIPvarGetUbGlobal(consdata->x);
1169 
1170  if( SCIPisZero(scip, SCIPvarGetObj(consdata->z)) )
1171  {
1172  /* even simpler case where objective is linear in x */
1173  if( SCIPisZero(scip, SCIPvarGetObj(consdata->x)) )
1174  {
1175  /* simplest case where objective is zero:
1176  * if zero is within bounds, fix to zero, otherwise
1177  * fix x to middle of bounds for numerical stability. */
1178  if(SCIPisLT(scip, xlb, 0.0) && SCIPisGT(scip, xub, 0.0))
1179  xfix = 0.0;
1180  else
1181  xfix = 0.5 * (xlb + xub);
1182  }
1183  else
1184  {
1185  /* fix x to best bound */
1186  xfix = SCIPvarGetBestBoundGlobal(consdata->x);
1187  }
1188  }
1189  else if( consdata->exponent == 2.0 )
1190  {
1191  /* consider cases x <= -offset and x >= -offset separately */
1192  SCIP_Real a;
1193  SCIP_Real b;
1194  SCIP_Real c;
1195  SCIP_Real cand;
1196  SCIP_Real xfixobjval;
1197 
1198  xfix = SCIP_INVALID;
1199  xfixobjval = SCIP_INVALID;
1200 
1201  if( SCIPisLT(scip, xlb, -consdata->xoffset) )
1202  {
1203  /* For x <= -offset, the objective is equivalent to
1204  * zobj/zcoef * x^2 + (xobj + 2 offset zobj/zcoef) * x + offset^2 * zobj/zcoef + other constant
1205  * <-> a * x^2 + b * x + c
1206  *
1207  * critical values for x are xlb, MIN(xub,-offset), and -b/(2*a)
1208  */
1209  a = SCIPvarGetObj(consdata->z) / consdata->zcoef;
1210  b = SCIPvarGetObj(consdata->x) + 2 * consdata->xoffset * SCIPvarGetObj(consdata->z) / consdata->zcoef;
1211  c = consdata->xoffset * consdata->xoffset * SCIPvarGetObj(consdata->z) / consdata->zcoef;
1212 
1213  if( a < 0.0 && SCIPisInfinity(scip, -xlb) )
1214  {
1215  /* if a < 0.0, then a*x^2 is unbounded for x -> -infinity, thus fix x to -infinity */
1216  xfix = -SCIPinfinity(scip);
1217  xfixobjval = -SCIPinfinity(scip);
1218  }
1219  else
1220  {
1221  /* initialize with value for x=xlb */
1222  xfix = xlb;
1223  xfixobjval = a * xlb * xlb + b * xlb + c;
1224 
1225  /* compare with value for x=MIN(-offset,xub) */
1226  cand = MIN(-consdata->xoffset, xub);
1227  if( xfixobjval > a * cand * cand + b * cand + c )
1228  {
1229  xfix = cand;
1230  xfixobjval = a * cand * cand + b * cand + c;
1231  }
1232 
1233  /* compare with value for x=-b/(2*a), if within bounds */
1234  cand = -b/(2.0*a);
1235  if( cand > xlb && cand < -consdata->xoffset && cand < xub && xfixobjval > -b*b/(4.0*a) + c )
1236  {
1237  xfix = cand;
1238  xfixobjval = -b*b/(4.0*a) + c;
1239  }
1240  }
1241  }
1242 
1243  if( SCIPisGT(scip, xub, -consdata->xoffset) )
1244  {
1245  /* For x >= -offset, the objective is equivalent to
1246  * -zobj/zcoef * x^2 + (xobj - 2 offset zobj/zcoef) * x - offset^2 * zobj/zcoef + constants
1247  * <-> a * x^2 + b * x + c
1248  *
1249  * critical values for x are xub, MAX(xlb,-offset), and -b/(2*a)
1250  */
1251  a = -SCIPvarGetObj(consdata->z) / consdata->zcoef;
1252  b = SCIPvarGetObj(consdata->x) - 2 * consdata->xoffset * SCIPvarGetObj(consdata->z) / consdata->zcoef;
1253  c = -consdata->xoffset * consdata->xoffset * SCIPvarGetObj(consdata->z) / consdata->zcoef;
1254 
1255  if( a < 0.0 && SCIPisInfinity(scip, xub) )
1256  {
1257  /* if a < 0.0, then a*x^2 is unbounded for x -> infinity, thus fix x to infinity */
1258  xfix = SCIPinfinity(scip);
1259  /* not needed: xfixobjval = SCIPinfinity(scip); */
1260  }
1261  else
1262  {
1263  if( xfix == SCIP_INVALID ) /*lint !e777*/
1264  {
1265  /* initialize with value for x=xub */
1266  xfix = xub;
1267  xfixobjval = a * xub * xub + b * xub + c;
1268  }
1269  else
1270  {
1271  /* compare with value for x=xub */
1272  cand = xub;
1273  if( xfixobjval > a * cand * cand + b * cand + c )
1274  {
1275  xfix = cand;
1276  xfixobjval = a * cand * cand + b * cand + c;
1277  }
1278  }
1279 
1280  /* compare with value for x=MAX(xlb,-offset) */
1281  cand = MAX(xlb, -consdata->xoffset);
1282  if( xfixobjval > a * cand * cand + b * cand + c )
1283  {
1284  xfix = cand;
1285  xfixobjval = a * cand * cand + b * cand + c;
1286  }
1287 
1288  /* compare with value for x=-b/(2*a), if within bounds */
1289  cand = -b/(2.0*a);
1290  if( cand > xlb && cand > -consdata->xoffset && cand < xub && xfixobjval > -b*b/(4.0*a) + c )
1291  {
1292  xfix = cand;
1293  /* not needed: xfixobjval = -b*b/(4.0*a) + c; */
1294  }
1295  }
1296  }
1297  assert(xfix != SCIP_INVALID); /*lint !e777*/
1298  assert(SCIPisInfinity(scip, -xlb) || SCIPisLE(scip, xlb, xfix));
1299  assert(SCIPisInfinity(scip, xub) || SCIPisGE(scip, xub, xfix));
1300  }
1301  else
1302  {
1303  /* skip dual presolve for exponents != 2 and z in objective for now */
1304  return SCIP_OKAY;
1305  }
1306 
1307  /* compute fixing value for z */
1308  if( SCIPisInfinity(scip, xfix) )
1309  {
1310  if( consdata->zcoef > 0.0 )
1311  {
1312  assert(SCIPisInfinity(scip, -SCIPvarGetLbGlobal(consdata->z)));
1313  zfix = -SCIPinfinity(scip);
1314  }
1315  else
1316  {
1317  assert(SCIPisInfinity(scip, SCIPvarGetUbGlobal(consdata->z)));
1318  zfix = SCIPinfinity(scip);
1319  }
1320  }
1321  else if( SCIPisInfinity(scip, -xfix) )
1322  {
1323  if( consdata->zcoef > 0.0 )
1324  {
1325  assert(SCIPisInfinity(scip, SCIPvarGetUbGlobal(consdata->z)));
1326  zfix = SCIPinfinity(scip);
1327  }
1328  else
1329  {
1330  assert(SCIPisInfinity(scip, -SCIPvarGetLbGlobal(consdata->z)));
1331  zfix = -SCIPinfinity(scip);
1332  }
1333  }
1334  else
1335  {
1336  SCIP_Real zlb;
1337  SCIP_Real zub;
1338 
1339  zlb = SCIPvarGetLbGlobal(consdata->z);
1340  zub = SCIPvarGetUbGlobal(consdata->z);
1341  zfix = consdata->rhs - SIGN(xfix + consdata->xoffset) * consdata->power(ABS(xfix + consdata->xoffset), consdata->exponent);
1342  zfix /= consdata->zcoef;
1343 
1344  /* project zfix into box, it should be at least very close */
1345  assert(SCIPisFeasLE(scip, zlb, zfix));
1346  assert(SCIPisFeasGE(scip, zub, zfix));
1347  zfix = MAX(zlb, MIN(zub, zfix));
1348  }
1349 
1350  /* fix variables according to x=xfix */
1351  SCIPdebugMessage("dual presolve fixes x=<%s>[%g,%g] to %g and z=<%s>[%g,%g] to %g in cons <%s>\n",
1352  SCIPvarGetName(consdata->x), xlb, xub, xfix,
1353  SCIPvarGetName(consdata->z), SCIPvarGetLbGlobal(consdata->z), SCIPvarGetUbGlobal(consdata->z), zfix,
1354  SCIPconsGetName(cons));
1355  SCIPdebugPrintCons(scip, cons, NULL);
1356 
1357  /* fix x */
1358  SCIP_CALL( SCIPfixVar(scip, consdata->x, xfix, cutoff, &fixed) );
1359  if( *cutoff )
1360  return SCIP_OKAY;
1361  if( fixed )
1362  ++*nfixedvars;
1363 
1364  /* fix z */
1365  SCIP_CALL( SCIPfixVar(scip, consdata->z, zfix, cutoff, &fixed) );
1366  if( *cutoff )
1367  return SCIP_OKAY;
1368  if( fixed )
1369  ++*nfixedvars;
1370 
1371  /* delete constraint */
1372  SCIP_CALL( SCIPdelCons(scip, cons) );
1373  ++*ndelconss;
1374  }
1375  }
1376 
1377  return SCIP_OKAY;
1378 }
1379 
1380 /** given a variable and an interval, tightens the local bounds of this variable to the given interval */
1381 static
1383  SCIP* scip, /**< SCIP data structure */
1384  SCIP_VAR* var, /**< variable which bounds to tighten */
1385  SCIP_INTERVAL bounds, /**< new bounds */
1386  SCIP_Bool force, /**< force tightening even if below bound strengthening tolerance */
1387  SCIP_CONS* cons, /**< constraint that is propagated */
1388  SCIP_RESULT* result, /**< pointer to store the result of the propagation call */
1389  int* nchgbds, /**< buffer where to add the number of changed bounds */
1390  int* nfixedvars, /**< buffer where to add the number of fixed variables, can be equal to nchgbds */
1391  int* naddconss /**< buffer where to add the number of added constraints, can be NULL if force is FALSE */
1392  )
1393 {
1394  SCIP_Bool infeas;
1395  SCIP_Bool tightened;
1396 
1397  assert(scip != NULL);
1398  assert(var != NULL);
1399  assert(cons != NULL);
1400  assert(result != NULL);
1401  assert(nchgbds != NULL);
1402  assert(nfixedvars != NULL);
1403 
1404  *result = SCIP_DIDNOTFIND;
1405 
1406  if( SCIPisInfinity(scip, SCIPintervalGetInf(bounds)) || SCIPisInfinity(scip, -SCIPintervalGetSup(bounds)) )
1407  {
1408  /* domain outside [-infty, +infty] -> declare as infeasible */
1409  *result = SCIP_CUTOFF;
1410  return SCIP_OKAY;
1411  }
1412 
1413  /* if variable is not multiaggregated (or aggregated to a multiaggregated), then try SCIPfixVar or SCIPtightenVarLb/Ub
1414  * otherwise, if bound tightening is forced, add a linear constraint
1415  * otherwise, forget about the bound tightening
1416  */
1418  {
1419  /* check if variable can be fixed */
1420  if( SCIPisEQ(scip, bounds.inf, bounds.sup) )
1421  {
1422  if( !SCIPisEQ(scip, SCIPvarGetLbLocal(var), SCIPvarGetUbLocal(var)) )
1423  {
1424  /* if variable not fixed yet, then do so now */
1425  SCIP_Real fixval;
1426 
1427  if( bounds.inf != bounds.sup ) /*lint !e777*/
1428  fixval = (bounds.inf + bounds.sup) / 2.0;
1429  else
1430  fixval = bounds.inf;
1431  SCIP_CALL( SCIPfixVar(scip, var, fixval, &infeas, &tightened) );
1432 
1433  if( infeas )
1434  {
1435  SCIPdebugMessage("found <%s> infeasible due to fixing variable <%s>\n", SCIPconsGetName(cons), SCIPvarGetName(var));
1436  *result = SCIP_CUTOFF;
1437  return SCIP_OKAY;
1438  }
1439  if( tightened )
1440  {
1441  SCIPdebugMessage("fixed variable <%s> in constraint <%s> to %g\n", SCIPvarGetName(var), SCIPconsGetName(cons), SCIPvarGetLbLocal(var));
1442  ++*nfixedvars;
1443  *result = SCIP_REDUCEDDOM;
1444  }
1445  }
1446  else
1447  {
1448  /* only check if new fixing value is consistent with variable bounds, otherwise cutoff */
1449  if( SCIPisLT(scip, bounds.sup, SCIPvarGetUbLocal(var)) || SCIPisGT(scip, bounds.inf, SCIPvarGetLbLocal(var)) )
1450  {
1451  SCIPdebugMessage("found <%s> infeasible due to fixing fixed variable <%s>[%.20g,%.20g] to [%.20g,%.20g]\n",
1452  SCIPconsGetName(cons), SCIPvarGetName(var), SCIPvarGetLbLocal(var), SCIPvarGetUbLocal(var), bounds.inf, bounds.sup);
1453  *result = SCIP_CUTOFF;
1454  return SCIP_OKAY;
1455  }
1456  }
1457 
1458  return SCIP_OKAY;
1459  }
1460 
1461  /* check if lower bound can be tightened */
1462  if( SCIPintervalGetInf(bounds) > SCIPvarGetLbLocal(var) )
1463  {
1464  assert(!SCIPisInfinity(scip, -SCIPintervalGetInf(bounds)));
1465  SCIP_CALL( SCIPtightenVarLb(scip, var, SCIPintervalGetInf(bounds), force, &infeas, &tightened) );
1466  if( infeas )
1467  {
1468  SCIPdebugMessage("found %s infeasible due to domain propagation for variable %s in constraint %s\n", SCIPconsGetName(cons), SCIPvarGetName(var), SCIPconsGetName(cons));
1469  *result = SCIP_CUTOFF;
1470  return SCIP_OKAY;
1471  }
1472  if( tightened )
1473  {
1474  SCIPdebugMessage("tightened lower bound of variable %s in constraint %s to %g\n", SCIPvarGetName(var), SCIPconsGetName(cons), SCIPvarGetLbLocal(var));
1475  ++*nchgbds;
1476  *result = SCIP_REDUCEDDOM;
1477  }
1478  }
1479 
1480  /* check if upper bound can be tightened */
1481  if( SCIPintervalGetSup(bounds) < SCIPvarGetUbLocal(var) )
1482  {
1483  assert(!SCIPisInfinity(scip, SCIPintervalGetSup(bounds)));
1484  SCIP_CALL( SCIPtightenVarUb(scip, var, SCIPintervalGetSup(bounds), force, &infeas, &tightened) );
1485  if( infeas )
1486  {
1487  SCIPdebugMessage("found %s infeasible due to domain propagation for linear variable %s in constraint %s\n", SCIPconsGetName(cons), SCIPvarGetName(var), SCIPconsGetName(cons));
1488  *result = SCIP_CUTOFF;
1489  return SCIP_OKAY;
1490  }
1491  if( tightened )
1492  {
1493  SCIPdebugMessage("tightened upper bound of variable %s in constraint %s to %g\n", SCIPvarGetName(var), SCIPconsGetName(cons), SCIPvarGetUbLocal(var));
1494  ++*nchgbds;
1495  *result = SCIP_REDUCEDDOM;
1496  }
1497  }
1498  }
1499  else if( force && (SCIPisLT(scip, SCIPvarGetLbLocal(var), bounds.inf) || SCIPisGT(scip, SCIPvarGetUbLocal(var), bounds.sup)) )
1500  {
1501  /* add a linear constraint bounds.inf <= x <= bounds.sup */
1502  SCIP_CONS* auxcons;
1503  SCIP_Bool local;
1504  SCIP_Real one;
1505 
1506  assert(naddconss != NULL);
1507 
1508  /* we add constraint as local constraint if we are during probing or if we are during solve and not at the root node */
1509  local = SCIPinProbing(scip) || (SCIPgetStage(scip) == SCIP_STAGE_SOLVING && (SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0));
1510 
1511  one = 1.0;
1512  SCIP_CALL( SCIPcreateConsLinear(scip, &auxcons, SCIPconsGetName(cons), 1, &var, &one, bounds.inf, bounds.sup,
1514  SCIPconsIsChecked(cons), SCIPconsIsPropagated(cons), local,
1515  FALSE, FALSE, TRUE, FALSE) );
1516 
1517  if( local )
1518  {
1519  SCIP_CALL( SCIPaddConsLocal(scip, auxcons, NULL) );
1520  }
1521  else
1522  {
1523  SCIP_CALL( SCIPaddCons(scip, auxcons) );
1524  }
1525  SCIP_CALL( SCIPreleaseCons(scip, &auxcons) );
1526 
1527  ++*naddconss;
1528  *result = SCIP_CONSADDED;
1529  }
1530 
1531  return SCIP_OKAY;
1532 }
1533 
1534 /** computes bounds on z in a absolute power constraints for given bounds on x */
1535 static
1536 void computeBoundsZ(
1537  SCIP* scip, /**< SCIP data structure */
1538  SCIP_CONS* cons, /**< constraint */
1539  SCIP_INTERVAL xbnds, /**< bounds on x that are to be propagated */
1540  SCIP_INTERVAL* zbnds /**< buffer to store corresponding bounds on z */
1541  )
1542 {
1543  SCIP_CONSDATA* consdata;
1544  SCIP_Real bnd;
1545  SCIP_Real x;
1546 
1547  assert(scip != NULL);
1548  assert(cons != NULL);
1549  assert(zbnds != NULL);
1550  assert(!SCIPintervalIsEmpty(SCIPinfinity(scip), xbnds));
1551 
1552  consdata = SCIPconsGetData(cons);
1553  assert(consdata != NULL);
1554 
1555  SCIPintervalSetEntire(SCIPinfinity(scip), zbnds);
1556 
1557  /* apply zcoef*z <= rhs - signedpow(xbnds.inf + offset, n) */
1558  if( !SCIPisInfinity(scip, consdata->rhs) && !SCIPisInfinity(scip, -xbnds.inf) )
1559  {
1560  x = xbnds.inf - PROPVARTOL + consdata->xoffset;
1561  bnd = consdata->rhs + PROPSIDETOL - SIGN(x) * consdata->power(REALABS(x), consdata->exponent);
1562 
1563  if( consdata->zcoef > 0.0 )
1564  zbnds->sup = bnd / consdata->zcoef;
1565  else
1566  zbnds->inf = bnd / consdata->zcoef;
1567  }
1568 
1569  /* apply zcoef*z >= lhs - signedpow(xbnds.sup + offset, n) */
1570  if( !SCIPisInfinity(scip, -consdata->lhs) && !SCIPisInfinity(scip, xbnds.sup) )
1571  {
1572  x = xbnds.sup + PROPVARTOL + consdata->xoffset;
1573  bnd = consdata->lhs - PROPSIDETOL - SIGN(x) * consdata->power(REALABS(x), consdata->exponent);
1574 
1575  if( consdata->zcoef > 0.0 )
1576  zbnds->inf = bnd / consdata->zcoef;
1577  else
1578  zbnds->sup = bnd / consdata->zcoef;
1579  }
1580 
1581  SCIPdebugMessage("given x = [%.20g, %.20g], computed z = [%.20g, %.20g] via", xbnds.inf, xbnds.sup, zbnds->inf, zbnds->sup);
1582  SCIPdebugPrintCons(scip, cons, NULL);
1583 
1584  assert(!SCIPintervalIsEmpty(SCIPinfinity(scip), *zbnds));
1585 }
1586 
1587 /** computes bounds on x in a absolute power constraints for given bounds on z */
1588 static
1589 void computeBoundsX(
1590  SCIP* scip, /**< SCIP data structure */
1591  SCIP_CONS* cons, /**< constraint */
1592  SCIP_INTERVAL zbnds, /**< bounds on x that are to be propagated */
1593  SCIP_INTERVAL* xbnds /**< buffer to store corresponding bounds on z */
1594  )
1595 {
1596  SCIP_CONSDATA* consdata;
1597  SCIP_Real bnd;
1598  SCIP_Real z;
1599 
1600  assert(scip != NULL);
1601  assert(cons != NULL);
1602  assert(xbnds != NULL);
1603  assert(!SCIPintervalIsEmpty(SCIPinfinity(scip), zbnds));
1604 
1605  consdata = SCIPconsGetData(cons);
1606  assert(consdata != NULL);
1607 
1608  SCIPintervalSetEntire(SCIPinfinity(scip), xbnds);
1609 
1610  /* apply signedpow(x+offset, n) <= rhs - (zcoef * zbnds).inf */
1611  z = (consdata->zcoef > 0.0 ? zbnds.inf : zbnds.sup);
1612  if( !SCIPisInfinity(scip, consdata->rhs) && !SCIPisInfinity(scip, REALABS(z)) )
1613  {
1614  bnd = consdata->rhs + PROPSIDETOL - consdata->zcoef * z + REALABS(consdata->zcoef) * PROPVARTOL;
1615  if( consdata->exponent == 2.0 )
1616  bnd = SIGN(bnd) * sqrt(REALABS(bnd));
1617  else
1618  bnd = SIGN(bnd) * pow(REALABS(bnd), 1.0/consdata->exponent);
1619  xbnds->sup = bnd - consdata->xoffset;
1620  }
1621 
1622  /* apply signedpow(x+offset, n) >= lhs - (zcoef * zbnds).sup */
1623  z = (consdata->zcoef > 0.0 ? zbnds.sup : zbnds.inf);
1624  if( !SCIPisInfinity(scip, consdata->rhs) && !SCIPisInfinity(scip, REALABS(z)) )
1625  {
1626  bnd = consdata->lhs - PROPSIDETOL - consdata->zcoef * z - REALABS(consdata->zcoef) * PROPVARTOL;
1627  if( consdata->exponent == 2.0 )
1628  bnd = SIGN(bnd) * sqrt(REALABS(bnd));
1629  else
1630  bnd = SIGN(bnd) * pow(REALABS(bnd), 1.0/consdata->exponent);
1631  xbnds->inf = bnd - consdata->xoffset;
1632  }
1633 
1634  SCIPdebugMessage("given z = [%.20g, %.20g], computed x = [%.20g, %.20g] via", zbnds.inf, zbnds.sup, xbnds->inf, xbnds->sup);
1635  SCIPdebugPrintCons(scip, cons, NULL);
1636 
1637  assert(!SCIPintervalIsEmpty(SCIPinfinity(scip), *xbnds));
1638 }
1639 
1640 /** checks if x or z is fixed and replaces them or deletes constraint */
1641 static
1643  SCIP* scip, /**< SCIP data structure */
1644  SCIP_CONSHDLR* conshdlr, /**< constraint handler for absolute power constraints */
1645  SCIP_CONS* cons, /**< constraint */
1646  int* ndelconss, /**< counter for number of deleted constraints */
1647  int* nupgdconss, /**< counter for number of upgraded constraints */
1648  int* nchgbds, /**< counter for number of variable bound changes */
1649  int* nfixedvars, /**< counter for number of variable fixations */
1650  SCIP_RESULT* result /**< to store result if we detect infeasibility or remove constraint */
1651  )
1652 {
1653  SCIP_CONSHDLRDATA* conshdlrdata;
1654  SCIP_CONSDATA* consdata;
1655  SCIP_Real scalar;
1656  SCIP_Real constant;
1657  SCIP_Real factor;
1658  SCIP_VAR* var;
1659 
1660  assert(scip != NULL);
1661  assert(cons != NULL);
1662  assert(ndelconss != NULL);
1663  assert(nupgdconss != NULL);
1664  assert(nchgbds != NULL);
1665  assert(nfixedvars != NULL);
1666 
1667  conshdlrdata = SCIPconshdlrGetData(conshdlr);
1668  assert(conshdlrdata != NULL);
1669 
1670  consdata = SCIPconsGetData(cons);
1671  assert(consdata != NULL);
1672 
1673  *result = SCIP_DIDNOTFIND;
1674 
1675  if( !SCIPvarIsActive(consdata->x) && SCIPvarGetStatus(consdata->x) != SCIP_VARSTATUS_MULTAGGR )
1676  {
1677  /* replace x variable */
1678 
1679  /* get relation x = scalar * var + constant */
1680  var = consdata->x;
1681  scalar = 1.0;
1682  constant = 0.0;
1683  SCIP_CALL( SCIPgetProbvarSum(scip, &var, &scalar, &constant) );
1684 
1685  if( scalar == 0.0 )
1686  {
1687  SCIP_INTERVAL xbnds;
1688  SCIP_INTERVAL zbnds;
1689  int naddconss;
1690 
1691  naddconss = 0;
1692 
1693  /* x has been fixed to constant */
1694  assert(SCIPisFeasEQ(scip, SCIPvarGetLbGlobal(consdata->x), constant));
1695  assert(SCIPisFeasEQ(scip, SCIPvarGetUbGlobal(consdata->x), constant));
1696 
1697  /* compute corresponding bounds on z */
1698  SCIPintervalSet(&xbnds, constant);
1699  computeBoundsZ(scip, cons, xbnds, &zbnds);
1700 
1701  SCIPdebugMessage("in cons <%s>: x = <%s> fixed to %g -> tighten <%s> to [%g, %g]\n", SCIPconsGetName(cons), SCIPvarGetName(consdata->x), constant, SCIPvarGetName(consdata->z), zbnds.inf, zbnds.sup);
1702 
1703  if( SCIPisEQ(scip, consdata->lhs, consdata->rhs) )
1704  {
1705  /* if sides are equal, then we should either fix z, or declare infeasibility */
1706  if( SCIPisFeasLT(scip, SCIPvarGetUbGlobal(consdata->z), zbnds.inf) || SCIPisFeasGT(scip, SCIPvarGetLbGlobal(consdata->z), zbnds.sup) )
1707  {
1708  SCIPdebugMessage("bounds inconsistent -> cutoff\n");
1709  *result = SCIP_CUTOFF;
1710  return SCIP_OKAY;
1711  }
1712  else
1713  {
1714  /* compute fixing value for z as value corresponding to fixing of x, projected onto bounds of z */
1715  SCIP_Real zfix;
1716 
1717  zfix = consdata->rhs - SIGN(constant + consdata->xoffset) * consdata->power(REALABS(constant + consdata->xoffset), consdata->exponent);
1718  zfix /= consdata->zcoef;
1719  assert(SCIPisLE(scip, zbnds.inf, zfix));
1720  assert(SCIPisGE(scip, zbnds.sup, zfix));
1721  zfix = MIN(SCIPvarGetUbGlobal(consdata->z), MAX(SCIPvarGetLbGlobal(consdata->z), zfix)); /*lint !e666*/
1722 
1723  zbnds.inf = zfix;
1724  zbnds.sup = zfix;
1725  SCIP_CALL( tightenBounds(scip, consdata->z, zbnds, TRUE, cons, result, nchgbds, nfixedvars, &naddconss) );
1726  }
1727  }
1728  else
1729  {
1730  /* tighten bounds on z accordingly */
1731  SCIP_CALL( tightenBounds(scip, consdata->z, zbnds, TRUE, cons, result, nchgbds, nfixedvars, &naddconss) );
1732  }
1733 
1734  /* delete constraint */
1735  SCIP_CALL( SCIPdelCons(scip, cons) );
1736 
1737  /* if tightenBounds added a constraint (because z was multiaggregated), then count this as constraint upgrade, otherwise as constraint deletion */
1738  if( naddconss > 0 )
1739  ++*nupgdconss;
1740  else
1741  ++*ndelconss;
1742 
1743  return SCIP_OKAY;
1744  }
1745 
1746  SCIPdebugMessage("in cons <%s>: x = <%s> replaced by %g*<%s> + %g\n", SCIPconsGetName(cons), SCIPvarGetName(consdata->x), scalar, SCIPvarGetName(var), constant);
1747 
1748  /* constraint will be divided by scalar*pow(|scalar|,exponent-1), if scalar is not 1.0 */
1749  if( scalar == 1.0 )
1750  factor = 1.0;
1751  else if( scalar > 0.0 )
1752  factor = consdata->power( scalar, consdata->exponent);
1753  else
1754  factor = -consdata->power(-scalar, consdata->exponent);
1755 
1756  /* aggregate only if this would not lead to a vanishing or infinite coefficient for z */
1757  if( !SCIPisZero(scip, consdata->zcoef / factor) && !SCIPisInfinity(scip, REALABS(consdata->zcoef / factor)) )
1758  {
1759  /* we drop here the events for both variables, because if x is replaced by a multiaggregated variable here, then we do not need to catch bound tightenings on z anymore */
1760  SCIP_CALL( dropVarEvents(scip, conshdlrdata->eventhdlr, cons) );
1761  SCIP_CALL( SCIPunlockVarCons(scip, consdata->x, cons, !SCIPisInfinity(scip, -consdata->lhs), !SCIPisInfinity(scip, consdata->rhs)) );
1762 
1763  consdata->x = var;
1764  if( SCIPvarIsActive(consdata->x) )
1765  {
1766  SCIP_CALL( SCIPmarkDoNotMultaggrVar(scip, consdata->x) );
1767  }
1768 
1769  /* add constant to offset */
1770  consdata->xoffset += constant;
1771 
1772  /* divide constraint by factor */
1773  if( scalar == 1.0 ) ;
1774  else if( scalar > 0.0 )
1775  {
1776  if( !SCIPisInfinity(scip, -consdata->lhs) )
1777  consdata->lhs /= factor;
1778  if( !SCIPisInfinity(scip, consdata->rhs) )
1779  consdata->rhs /= factor;
1780  consdata->zcoef /= factor;
1781  consdata->xoffset /= scalar;
1782  }
1783  else
1784  {
1785  SCIP_Real oldlhs;
1786 
1787  assert(scalar < 0.0);
1788  assert(factor < 0.0);
1789 
1790  oldlhs = consdata->lhs;
1791 
1792  if( !SCIPisInfinity(scip, consdata->rhs) )
1793  consdata->lhs = consdata->rhs / factor;
1794  else
1795  consdata->lhs = -SCIPinfinity(scip);
1796  if( !SCIPisInfinity(scip, -oldlhs) )
1797  consdata->rhs = oldlhs / factor;
1798  else
1799  consdata->rhs = SCIPinfinity(scip);
1800  consdata->zcoef /= factor;
1801  consdata->xoffset /= scalar;
1802  /* since we flip both constraint sides and the sign of zcoef, the events catched for z remain the same, so update necessary there */
1803  }
1804 
1805  SCIP_CALL( SCIPlockVarCons(scip, consdata->x, cons, !SCIPisInfinity(scip, -consdata->lhs), !SCIPisInfinity(scip, consdata->rhs)) );
1806  SCIP_CALL( catchVarEvents(scip, conshdlrdata->eventhdlr, cons) );
1807 
1808  SCIPdebugPrintCons(scip, cons, NULL);
1809 
1810  /* rerun constraint comparison */
1811  conshdlrdata->comparedpairwise = FALSE;
1812  }
1813  else
1814  {
1815  SCIPwarningMessage(scip, "Skip resolving aggregation of variable <%s> in abspower constraint <%s> to avoid zcoef = %g\n",
1816  SCIPvarGetName(consdata->x), SCIPconsGetName(cons), consdata->zcoef / factor);
1817  }
1818  }
1819 
1820  if( !SCIPvarIsActive(consdata->z) && SCIPvarGetStatus(consdata->z) != SCIP_VARSTATUS_MULTAGGR )
1821  {
1822  /* replace z variable */
1823 
1824  /* get relation z = scalar * var + constant */
1825  var = consdata->z;
1826  scalar = 1.0;
1827  constant = 0.0;
1828  SCIP_CALL( SCIPgetProbvarSum(scip, &var, &scalar, &constant) );
1829 
1830  if( scalar == 0.0 )
1831  {
1832  SCIP_INTERVAL xbnds;
1833  SCIP_INTERVAL zbnds;
1834  int naddconss;
1835 
1836  naddconss = 0;
1837 
1838  /* z has been fixed to constant */
1839  assert(SCIPisFeasEQ(scip, SCIPvarGetLbGlobal(consdata->z), constant));
1840  assert(SCIPisFeasEQ(scip, SCIPvarGetUbGlobal(consdata->z), constant));
1841 
1842  /* compute corresponding bounds on x */
1843  SCIPintervalSet(&zbnds, constant);
1844  computeBoundsX(scip, cons, zbnds, &xbnds);
1845 
1846  SCIPdebugMessage("in cons <%s>: z = <%s> fixed to %g -> tighten <%s> to [%g, %g]\n", SCIPconsGetName(cons), SCIPvarGetName(consdata->z), constant, SCIPvarGetName(consdata->x), xbnds.inf, xbnds.sup);
1847 
1848  if( SCIPisEQ(scip, consdata->lhs, consdata->rhs) )
1849  {
1850  /* if sides are equal, then we should either fix x, or declare infeasibility */
1851  if( SCIPisFeasLT(scip, SCIPvarGetUbGlobal(consdata->x), xbnds.inf) || SCIPisFeasGT(scip, SCIPvarGetLbGlobal(consdata->x), xbnds.sup) )
1852  {
1853  SCIPdebugMessage("bounds inconsistent -> cutoff\n");
1854  *result = SCIP_CUTOFF;
1855  return SCIP_OKAY;
1856  }
1857  else
1858  {
1859  /* compute fixing value for x as value corresponding to fixing of z, projected onto bounds of x */
1860  SCIP_Real xfix;
1861 
1862  xfix = consdata->rhs - consdata->zcoef * constant;
1863  if( consdata->exponent == 2.0 )
1864  xfix = SIGN(xfix) * sqrt(REALABS(xfix)) - consdata->xoffset;
1865  else
1866  xfix = SIGN(xfix) * pow(REALABS(xfix), 1.0/consdata->exponent) - consdata->xoffset;
1867  assert(SCIPisLE(scip, xbnds.inf, xfix));
1868  assert(SCIPisGE(scip, xbnds.sup, xfix));
1869  xfix = MIN(SCIPvarGetUbGlobal(consdata->x), MAX(SCIPvarGetLbGlobal(consdata->x), xfix)); /*lint !e666*/
1870 
1871  xbnds.inf = xfix;
1872  xbnds.sup = xfix;
1873  SCIP_CALL( tightenBounds(scip, consdata->x, xbnds, TRUE, cons, result, nchgbds, nfixedvars, &naddconss) );
1874  }
1875  }
1876  else
1877  {
1878  /* tighten bounds on x accordingly */
1879  SCIP_CALL( tightenBounds(scip, consdata->x, xbnds, TRUE, cons, result, nchgbds, nfixedvars, &naddconss) );
1880  }
1881 
1882  /* delete constraint */
1883  SCIP_CALL( SCIPdelCons(scip, cons) );
1884 
1885  /* if tightenBounds added a constraint (because x was multiaggregated), then count this as constraint upgrade, otherwise as constraint deletion */
1886  if( naddconss > 0 )
1887  ++*nupgdconss;
1888  else
1889  ++*ndelconss;
1890 
1891  return SCIP_OKAY;
1892  }
1893 
1894  SCIPdebugMessage("in cons <%s>: z = <%s> replaced by %g*<%s> + %g\n", SCIPconsGetName(cons), SCIPvarGetName(consdata->z), scalar, SCIPvarGetName(var), constant);
1895 
1896  /* we drop here the events for both variables, because if z is replaced by a multiaggregated variable here, then we do not need to catch bound tightenings on x anymore */
1897  SCIP_CALL( dropVarEvents(scip, conshdlrdata->eventhdlr, cons) );
1898  if( consdata->zcoef > 0.0 )
1899  SCIP_CALL( SCIPunlockVarCons(scip, consdata->z, cons, !SCIPisInfinity(scip, -consdata->lhs), !SCIPisInfinity(scip, consdata->rhs)) );
1900  else
1901  SCIP_CALL( SCIPunlockVarCons(scip, consdata->z, cons, !SCIPisInfinity(scip, consdata->rhs), !SCIPisInfinity(scip, -consdata->lhs)) );
1902 
1903  consdata->z = var;
1904  if( SCIPvarIsActive(consdata->z) )
1905  {
1906  SCIP_CALL( SCIPmarkDoNotMultaggrVar(scip, consdata->z) );
1907  }
1908 
1909  /* substract constant from constraint sides */
1910  if( !SCIPisInfinity(scip, -consdata->lhs) )
1911  consdata->lhs -= consdata->zcoef * constant;
1912  if( !SCIPisInfinity(scip, consdata->rhs) )
1913  consdata->rhs -= consdata->zcoef * constant;
1914 
1915  /* multiply zcoef by scalar */
1916  consdata->zcoef *= scalar;
1917 
1918  if( consdata->zcoef > 0.0 )
1919  SCIP_CALL( SCIPlockVarCons(scip, consdata->z, cons, !SCIPisInfinity(scip, -consdata->lhs), !SCIPisInfinity(scip, consdata->rhs)) );
1920  else
1921  SCIP_CALL( SCIPlockVarCons(scip, consdata->z, cons, !SCIPisInfinity(scip, consdata->rhs), !SCIPisInfinity(scip, -consdata->lhs)) );
1922  SCIP_CALL( catchVarEvents(scip, conshdlrdata->eventhdlr, cons) );
1923 
1924  /* rerun constraint comparison */
1925  conshdlrdata->comparedpairwise = FALSE;
1926  }
1927 
1928  assert(SCIPvarIsActive(consdata->z) || SCIPvarGetStatus(consdata->z) == SCIP_VARSTATUS_MULTAGGR);
1929 
1930  return SCIP_OKAY;
1931 }
1932 
1933 /** gets maximal absolute value in gradient of quadratic function
1934  * thus, gives \f$max(n |x+offset|^{n-1}, |zcoef|)\f$.
1935  */
1936 static
1938  SCIP* scip, /**< SCIP data structure */
1939  SCIP_CONS* cons, /**< constraint */
1940  SCIP_SOL* sol /**< solution or NULL if LP solution should be used */
1941  )
1942 {
1943  SCIP_CONSDATA* consdata;
1944  SCIP_Real xval;
1945  SCIP_Real val;
1946 
1947  assert(scip != NULL);
1948  assert(cons != NULL);
1949 
1950  consdata = SCIPconsGetData(cons);
1951  assert(consdata != NULL);
1952 
1953  xval = SCIPgetSolVal(scip, sol, consdata->x);
1954  assert(!SCIPisInfinity(scip, REALABS(xval)));
1955 
1956  if( consdata->exponent == 2.0 )
1957  val = consdata->exponent * REALABS(xval + consdata->xoffset);
1958  else
1959  val = consdata->exponent * pow(REALABS(xval + consdata->xoffset), consdata->exponent - 1.0);
1960 
1961  return MAX(val, REALABS(consdata->zcoef)); /*lint !e666*/
1962 }
1963 
1964 /** computes violation of a constraint */
1965 static
1967  SCIP* scip, /**< SCIP data structure */
1968  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
1969  SCIP_CONS* cons, /**< constraint */
1970  SCIP_SOL* sol, /**< solution or NULL if LP solution should be used */
1971  SCIP_Real* viol /**< pointer to store absolute (unscaled) constraint violation */
1972  )
1973 {
1974  SCIP_CONSHDLRDATA* conshdlrdata;
1975  SCIP_CONSDATA* consdata;
1976  SCIP_Real val;
1977  SCIP_Real xval;
1978  SCIP_Real zval;
1979 
1980  assert(scip != NULL);
1981  assert(conshdlr != NULL);
1982  assert(cons != NULL);
1983  assert(viol != NULL);
1984 
1985  conshdlrdata = SCIPconshdlrGetData(conshdlr);
1986  assert(conshdlrdata != NULL);
1987 
1988  consdata = SCIPconsGetData(cons);
1989  assert(consdata != NULL);
1990 
1991  xval = SCIPgetSolVal(scip, sol, consdata->x);
1992  zval = SCIPgetSolVal(scip, sol, consdata->z);
1993 
1994  if( SCIPisInfinity(scip, REALABS(xval)) )
1995  {
1996  consdata->lhsviol = (SCIPisInfinity(scip, -consdata->lhs) ? 0.0 : SCIPinfinity(scip));
1997  consdata->rhsviol = (SCIPisInfinity(scip, consdata->rhs) ? 0.0 : SCIPinfinity(scip));
1998 
1999  return SCIP_OKAY;
2000  }
2001  /* project onto local box, in case the LP solution is slightly outside the bounds (which is not our job to enforce) */
2002  if( sol == NULL )
2003  {
2004  SCIP_Real lb;
2005  SCIP_Real ub;
2006  SCIP_Real minval;
2007 
2008  lb = SCIPvarGetLbLocal(consdata->x);
2009  ub = SCIPvarGetUbLocal(consdata->x);
2010  minval = MIN(ub, xval);
2011 
2012 #if 0 /* with non-initial columns, this might fail because variables can shortly be a column variable before entering the LP and have value 0.0 in this case */
2013  assert(SCIPisFeasGE(scip, xval, lb));
2014  assert(SCIPisFeasLE(scip, xval, ub));
2015 #endif
2016  xval = MAX(lb, minval);
2017 
2018  lb = SCIPvarGetLbLocal(consdata->z);
2019  ub = SCIPvarGetUbLocal(consdata->z);
2020  minval = MIN(ub, zval);
2021 
2022 #if 0 /* with non-initial columns, this might fail because variables can shortly be a column variable before entering the LP and have value 0.0 in this case */
2023  assert(SCIPisFeasGE(scip, zval, lb));
2024  assert(SCIPisFeasLE(scip, zval, ub));
2025 #endif
2026  zval = MAX(lb, minval);
2027  }
2028 
2029  xval += consdata->xoffset;
2030 
2031  val = SIGN(xval) * consdata->power(REALABS(xval), consdata->exponent);
2032  val += consdata->zcoef * zval;
2033 
2034  if( val < consdata->lhs && !SCIPisInfinity(scip, -consdata->lhs) )
2035  consdata->lhsviol = *viol = consdata->lhs - val;
2036  else
2037  consdata->lhsviol = 0.0;
2038 
2039  if( val > consdata->rhs && !SCIPisInfinity(scip, consdata->rhs) )
2040  consdata->rhsviol = *viol = val - consdata->rhs;
2041  else
2042  consdata->rhsviol = 0.0;
2043 
2044  switch( conshdlrdata->scaling )
2045  {
2046  case 'o' :
2047  /* no scaling */
2048  break;
2049 
2050  case 'g' :
2051  /* scale by sup-norm of gradient in current point */
2052  if( consdata->lhsviol > 0.0 || consdata->rhsviol > 0.0 )
2053  {
2054  SCIP_Real norm;
2055  norm = getGradientMaxElement(scip, cons, sol);
2056  if( norm > 1.0 )
2057  {
2058  consdata->lhsviol /= norm;
2059  consdata->rhsviol /= norm;
2060  }
2061  }
2062  break;
2063 
2064  case 's' :
2065  {
2066  SCIP_Real absval;
2067 
2068  /* scale by left/right hand side of constraint */
2069  if( consdata->lhsviol > 0.0 )
2070  {
2071  absval = REALABS(consdata->lhs);
2072  consdata->lhsviol /= MAX(1.0, absval);
2073  }
2074 
2075  if( consdata->rhsviol > 0.0 )
2076  {
2077  absval = REALABS(consdata->rhs);
2078  consdata->rhsviol /= MAX(1.0, absval);
2079  }
2080 
2081  break;
2082  }
2083 
2084  default :
2085  SCIPerrorMessage("Unknown scaling method '%c'.", conshdlrdata->scaling);
2086  SCIPABORT();
2087  return SCIP_INVALIDDATA; /*lint !e527*/
2088  }
2089 
2090  return SCIP_OKAY;
2091 }
2092 
2093 /** computes violation of a set of constraints */
2094 static
2096  SCIP* scip, /**< SCIP data structure */
2097  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
2098  SCIP_CONS** conss, /**< constraints */
2099  int nconss, /**< number of constraints */
2100  SCIP_SOL* sol, /**< solution or NULL if LP solution should be used */
2101  SCIP_CONS** maxviolcon /**< buffer to store constraint with largest violation, or NULL if solution is feasible */
2102  )
2103 {
2104  SCIP_CONSDATA* consdata;
2105  SCIP_Real viol;
2106  SCIP_Real maxviol;
2107  int c;
2108 
2109  assert(scip != NULL);
2110  assert(conss != NULL || nconss == 0);
2111  assert(maxviolcon != NULL);
2112 
2113  *maxviolcon = NULL;
2114 
2115  maxviol = 0.0;
2116 
2117  for( c = 0; c < nconss; ++c )
2118  {
2119  assert(conss != NULL);
2120  assert(conss[c] != NULL);
2121 
2122  SCIP_CALL( computeViolation(scip, conshdlr, conss[c], sol, &viol) );
2123 
2124  consdata = SCIPconsGetData(conss[c]);
2125  assert(consdata != NULL);
2126 
2127  viol = MAX(consdata->lhsviol, consdata->rhsviol);
2128  if( viol > maxviol && SCIPisGT(scip, viol, SCIPfeastol(scip)) )
2129  {
2130  maxviol = viol;
2131  *maxviolcon = conss[c];
2132  }
2133  }
2134 
2135  return SCIP_OKAY;
2136 }
2137 
2138 /** proposes branching point for constraint */
2139 static
2141  SCIP* scip, /**< SCIP data structure */
2142  SCIP_CONS* cons, /**< constraint which variable to get branching point for */
2143  int preferzero, /**< how much we prefer branching on -xoffset (0, 1, or 2) if sign is not fixed */
2144  SCIP_Bool branchminconverror /**< whether to minimize convexification error if sign is fixed */
2145  )
2146 {
2147  SCIP_CONSDATA* consdata;
2148  SCIP_VAR* x;
2149  SCIP_Real xref;
2150  SCIP_Real xlb;
2151  SCIP_Real xub;
2152 
2153  assert(scip != NULL);
2154  assert(cons != NULL);
2155 
2156  consdata = SCIPconsGetData(cons);
2157  assert(consdata != NULL);
2158 
2159  x = consdata->x;
2160  xlb = SCIPvarGetLbLocal(x);
2161  xub = SCIPvarGetUbLocal(x);
2162 
2163  /* check if sign of x is not fixed yet */
2164  if( SCIPisLT(scip, xlb, -consdata->xoffset) && SCIPisGT(scip, xub, -consdata->xoffset) )
2165  {
2166  /* if preferzero is 0, just return SCIP_INVALID
2167  * if preferzero is 1, then propose -xoffset if branching on -xoffset would cut off solution in both child nodes, otherwise return SCIP_INVALID
2168  * if preferzero is >1, then always propose -xoffset
2169  */
2170  assert(preferzero >= 0);
2171 
2172  if( preferzero == 0 )
2173  return SCIP_INVALID;
2174 
2175  if( preferzero > 1 || SCIPisInfinity(scip, -xlb) || SCIPisInfinity(scip, xub) )
2176  return -consdata->xoffset;
2177 
2178  xlb += consdata->xoffset;
2179  xub += consdata->xoffset;
2180 
2181  xref = SCIPgetVarSol(scip, x) + consdata->xoffset;
2182  if( SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
2183  {
2184  /* signpow(x,n,offset) + c*z <= 0 is violated
2185  * if we are close to or right of -offset, then branching on -offset gives a convex function on the right branch, this is good
2186  * otherwise if branching on -offset yields a violated secant cut in left branch, then current solution would be cutoff there, this is also still good
2187  */
2188  if( !SCIPisFeasNegative(scip, xref) || SCIPisFeasPositive(scip, -consdata->power(-xlb, consdata->exponent)*xref/xlb + consdata->zcoef * SCIPgetVarSol(scip, consdata->z)) )
2189  return -consdata->xoffset;
2190  return SCIP_INVALID;
2191  }
2192 
2193  assert(SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) );
2194  /* signpow(x,n) + c*z >= 0 is violated
2195  * if we are close to or left of zero, then branching on 0.0 gives a concave function on the left branch, this is good
2196  * otherwise if branching on 0.0 yields a violated secant cut in right branch, then current solution would be cutoff there, this is also still good
2197  */
2198  if( !SCIPisFeasPositive(scip, xref) || SCIPisFeasNegative(scip, -consdata->power(xub, consdata->exponent)*xref/xub + consdata->zcoef * SCIPgetVarSol(scip, consdata->z)) )
2199  return -consdata->xoffset;
2200  return SCIP_INVALID;
2201  }
2202 
2203  if( branchminconverror )
2204  {
2205  /* given x^n with xlb <= x <= xub, then the sum of the integrals between the function and its secant on the left and right branches are minimized
2206  * for branching on ( (ub^n - lb^n) / (n*(ub - lb)) ) ^ (1/(n-1))
2207  */
2208  if( SCIPisGE(scip, xlb, -consdata->xoffset) )
2209  {
2210  SCIP_Real ref;
2211  xlb = MAX(0.0, xlb + consdata->xoffset);
2212  xub = MAX(0.0, xub + consdata->xoffset);
2213 
2214  ref = (consdata->power(xub, consdata->exponent) - consdata->power(xlb, consdata->exponent)) / (consdata->exponent * (xub - xlb));
2215  ref = pow(ref, 1.0/(consdata->exponent-1.0));
2216  ref -= consdata->xoffset;
2217  assert(SCIPisGE(scip, ref, SCIPvarGetLbLocal(x)));
2218  assert(SCIPisLE(scip, ref, SCIPvarGetUbLocal(x)));
2219 
2220  return ref;
2221  }
2222  else
2223  {
2224  SCIP_Real ref;
2225 
2226  assert(SCIPisLE(scip, xub, -consdata->xoffset));
2227 
2228  xlb = MIN(0.0, xlb + consdata->xoffset);
2229  xub = MIN(0.0, xub + consdata->xoffset);
2230 
2231  ref = (consdata->power(-xlb, consdata->exponent) - consdata->power(-xub, consdata->exponent)) / (consdata->exponent * (-xlb + xub));
2232  ref = -pow(ref, 1.0/(consdata->exponent-1.0));
2233  ref -= consdata->xoffset;
2234  assert(SCIPisGE(scip, ref, SCIPvarGetLbLocal(x)));
2235  assert(SCIPisLE(scip, ref, SCIPvarGetUbLocal(x)));
2236 
2237  return ref;
2238  }
2239  }
2240 
2241  return SCIP_INVALID;
2242 }
2243 
2244 /** registers branching variable candidates
2245  * registers x for all violated absolute power constraints where x is not in convex region
2246  */
2247 static
2249  SCIP* scip, /**< SCIP data structure */
2250  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
2251  SCIP_CONS** conss, /**< constraints to check */
2252  int nconss, /**< number of constraints to check */
2253  int* nnotify /**< counter for number of notifications performed */
2254  )
2255 {
2256  SCIP_CONSHDLRDATA* conshdlrdata;
2257  SCIP_CONSDATA* consdata;
2258  SCIP_Bool onlynonfixedsign;
2259  int c;
2260 
2261  assert(scip != NULL);
2262  assert(conshdlr != NULL);
2263  assert(conss != NULL || nconss == 0);
2264 
2265  conshdlrdata = SCIPconshdlrGetData(conshdlr);
2266  assert(conshdlrdata != NULL);
2267 
2268  *nnotify = 0;
2269 
2270  onlynonfixedsign = conshdlrdata->preferzerobranch == 3;
2271 
2272  do
2273  {
2274  for( c = 0; c < nconss; ++c )
2275  {
2276  assert(conss[c] != NULL); /*lint !e613*/
2277 
2278  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
2279  assert(consdata != NULL);
2280 
2281  SCIPdebugMessage("cons <%s> violation: %g %g\n", SCIPconsGetName(conss[c]), consdata->lhsviol, consdata->rhsviol); /*lint !e613*/
2282 
2283  /* skip variables which sign is already fixed, if we are only interested in variables with unfixed sign here */
2284  if( onlynonfixedsign &&
2285  ( !SCIPisLT(scip, SCIPvarGetLbLocal(consdata->x), -consdata->xoffset) ||
2286  !SCIPisGT(scip, SCIPvarGetUbLocal(consdata->x), consdata->xoffset)) )
2287  continue;
2288 
2289  /* if the value of x lies in a concave range (i.e., where a secant approximation is used), then register x as branching variable */
2290  if( (SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) && (SCIPisInfinity(scip, -SCIPvarGetLbLocal(consdata->x)) || SCIPgetSolVal(scip, NULL, consdata->x) + consdata->xoffset <= -consdata->root * (SCIPvarGetLbLocal(consdata->x) + consdata->xoffset))) ||
2291  ( SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) && (SCIPisInfinity(scip, SCIPvarGetUbLocal(consdata->x)) || SCIPgetSolVal(scip, NULL, consdata->x) + consdata->xoffset >= -consdata->root * (SCIPvarGetUbLocal(consdata->x) + consdata->xoffset))) )
2292  {
2293  /* domain propagation should have removed constraints with fixed x, at least for violated constraints */
2294  assert(!SCIPisRelEQ(scip, SCIPvarGetLbLocal(consdata->x), SCIPvarGetUbLocal(consdata->x)));
2295 
2296  SCIPdebugMessage("register var <%s> in cons <%s> with violation %g %g\n", SCIPvarGetName(consdata->x), SCIPconsGetName(conss[c]), consdata->lhsviol, consdata->rhsviol); /*lint !e613*/
2297  SCIP_CALL( SCIPaddExternBranchCand(scip, consdata->x, MAX(consdata->lhsviol, consdata->rhsviol), proposeBranchingPoint(scip, conss[c], conshdlrdata->preferzerobranch, conshdlrdata->branchminconverror)) ); /*lint !e613*/
2298  ++*nnotify;
2299  }
2300  }
2301 
2302  if( onlynonfixedsign && *nnotify == 0 )
2303  {
2304  /* if we could not a variable in a violated constraint which sign is not already fixed, do another round where we consider all variables again */
2305  onlynonfixedsign = FALSE;
2306  continue;
2307  }
2308  }
2309  while( FALSE );
2310 
2311  return SCIP_OKAY;
2312 }
2313 
2314 /** registers a variable from a violated constraint as branching candidate that has a large absolute value in the LP relaxation */
2315 static
2317  SCIP* scip, /**< SCIP data structure */
2318  SCIP_CONS** conss, /**< constraints */
2319  int nconss, /**< number of constraints */
2320  SCIP_VAR** brvar /**< buffer to store branching variable */
2321  )
2322 {
2323  SCIP_CONSDATA* consdata;
2324  SCIP_Real val;
2325  SCIP_Real brvarval;
2326  int c;
2327 
2328  assert(scip != NULL);
2329  assert(conss != NULL || nconss == 0);
2330 
2331  *brvar = NULL;
2332  brvarval = -1.0;
2333 
2334  for( c = 0; c < nconss; ++c )
2335  {
2336  assert(conss != NULL);
2337  consdata = SCIPconsGetData(conss[c]);
2338  assert(consdata != NULL);
2339 
2340  if( !SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) && !SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
2341  continue;
2342 
2343  val = SCIPgetSolVal(scip, NULL, consdata->x) + consdata->xoffset;
2344  if( REALABS(val) > brvarval )
2345  {
2346  brvarval = ABS(val);
2347  *brvar = consdata->x;
2348  }
2349  }
2350 
2351  if( *brvar != NULL )
2352  {
2353  SCIP_CALL( SCIPaddExternBranchCand(scip, *brvar, brvarval, SCIP_INVALID) );
2354  }
2355 
2356  return SCIP_OKAY;
2357 }
2358 
2359 /** resolves a propagation on the given variable by supplying the variables needed for applying the corresponding
2360  * propagation rule (see propagateCons()):
2361  * see cons_varbound
2362  */
2363 static
2365  SCIP* scip, /**< SCIP data structure */
2366  SCIP_CONS* cons, /**< constraint that inferred the bound change */
2367  SCIP_VAR* infervar, /**< variable that was deduced */
2368  PROPRULE proprule, /**< propagation rule that deduced the bound change */
2369  SCIP_BOUNDTYPE boundtype, /**< the type of the changed bound (lower or upper bound) */
2370  SCIP_BDCHGIDX* bdchgidx /**< bound change index (time stamp of bound change), or NULL for current time */
2371  )
2372 {
2373  SCIP_CONSDATA* consdata;
2374 
2375  assert(scip != NULL);
2376  assert(cons != NULL);
2377  assert(infervar != NULL);
2378 
2379  consdata = SCIPconsGetData(cons);
2380  assert(consdata != NULL);
2381  assert(consdata->zcoef != 0.0);
2382 
2383  switch( proprule )
2384  {
2385  case PROPRULE_1:
2386  /* lhs <= sign(x+offset)|x+offset|^n + c*z: left hand side and bounds on z -> lower bound on x */
2387  assert(infervar == consdata->x);
2388  assert(boundtype == SCIP_BOUNDTYPE_LOWER);
2389  assert(!SCIPisInfinity(scip, -consdata->lhs));
2390  if( consdata->zcoef > 0.0 )
2391  {
2392  SCIP_CALL( SCIPaddConflictUb(scip, consdata->z, bdchgidx) );
2393  }
2394  else
2395  {
2396  SCIP_CALL( SCIPaddConflictLb(scip, consdata->z, bdchgidx) );
2397  }
2398  break;
2399 
2400  case PROPRULE_2:
2401  /* lhs <= sign(x+offset)|x+offset|^n + c*z: left hand side and upper bound on x -> bound on z */
2402  assert(infervar == consdata->z);
2403  assert(!SCIPisInfinity(scip, -consdata->lhs));
2404  SCIP_CALL( SCIPaddConflictUb(scip, consdata->x, bdchgidx) );
2405  break;
2406 
2407  case PROPRULE_3:
2408  /* sign(x+offset)|x+offset|^n + c*z <= rhs: right hand side and bounds on z -> upper bound on x */
2409  assert(infervar == consdata->x);
2410  assert(boundtype == SCIP_BOUNDTYPE_UPPER);
2411  assert(!SCIPisInfinity(scip, consdata->rhs));
2412  if( consdata->zcoef > 0.0 )
2413  {
2414  SCIP_CALL( SCIPaddConflictLb(scip, consdata->z, bdchgidx) );
2415  }
2416  else
2417  {
2418  SCIP_CALL( SCIPaddConflictUb(scip, consdata->z, bdchgidx) );
2419  }
2420  break;
2421 
2422  case PROPRULE_4:
2423  /* sign(x+offset)|x+offset|^n + c*z <= rhs: right hand side and lower bound on x -> bound on z */
2424  assert(infervar == consdata->z);
2425  assert(!SCIPisInfinity(scip, consdata->rhs));
2426  SCIP_CALL( SCIPaddConflictLb(scip, consdata->x, bdchgidx) );
2427  break;
2428 
2429  case PROPRULE_INVALID:
2430  default:
2431  SCIPerrorMessage("invalid inference information %d in absolute power constraint <%s>\n", proprule, SCIPconsGetName(cons));
2432  return SCIP_INVALIDDATA;
2433  }
2434 
2435  return SCIP_OKAY;
2436 }
2437 
2438 /** analyze infeasibility */
2439 static
2441  SCIP* scip, /**< SCIP data structure */
2442  SCIP_CONS* cons, /**< variable bound constraint */
2443  SCIP_VAR* infervar, /**< variable that was deduced */
2444  PROPRULE proprule, /**< propagation rule that deduced the bound change */
2445  SCIP_BOUNDTYPE boundtype /**< the type of the changed bound (lower or upper bound) */
2446  )
2447 {
2448  /* conflict analysis can only be applied in solving stage and if it turned on */
2450  return SCIP_OKAY;
2451 
2452  /* initialize conflict analysis, and add all variables of infeasible constraint to conflict candidate queue */
2454 
2455  /* add the bound which got violated */
2456  if( boundtype == SCIP_BOUNDTYPE_LOWER )
2457  {
2458  SCIP_CALL( SCIPaddConflictUb(scip, infervar, NULL) );
2459  }
2460  else
2461  {
2462  assert(boundtype == SCIP_BOUNDTYPE_UPPER);
2463  SCIP_CALL( SCIPaddConflictLb(scip, infervar, NULL) );
2464  }
2465 
2466  /* add the reason for the violated of the bound */
2467  SCIP_CALL( resolvePropagation(scip, cons, infervar, proprule, boundtype, NULL) );
2468 
2469  /* analyze the conflict */
2470  SCIP_CALL( SCIPanalyzeConflictCons(scip, cons, NULL) );
2471 
2472  return SCIP_OKAY;
2473 }
2474 
2475 /** propagation method for absolute power constraint
2476  * SCIPinferVarXbCons to allow for repropagation
2477  */
2478 static
2480  SCIP* scip, /**< SCIP data structure */
2481  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
2482  SCIP_CONS* cons, /**< variable bound constraint */
2483  SCIP_Bool canaddcons, /**< are we allowed to add a linear constraint when enforcing bounds for a multiaggregated variable? */
2484  SCIP_Bool* cutoff, /**< pointer to store whether the node can be cut off */
2485  int* nchgbds, /**< pointer to count number of bound changes */
2486  int* naddconss /**< pointer to count number of added constraints */
2487  )
2488 {
2489  SCIP_CONSDATA* consdata;
2490  SCIP_Real xlb;
2491  SCIP_Real xub;
2492  SCIP_Real zlb;
2493  SCIP_Real zub;
2494  SCIP_Real newlb;
2495  SCIP_Real newub;
2496  SCIP_Bool tightened;
2497  SCIP_Bool tightenedround;
2498  SCIP_Real minact;
2499  SCIP_Real maxact;
2500 
2501  assert(conshdlr != NULL);
2502  assert(cutoff != NULL);
2503  assert(nchgbds != NULL);
2504  assert(naddconss != NULL);
2505 
2506  consdata = SCIPconsGetData(cons);
2507  assert(consdata != NULL);
2508 
2509  SCIPdebugMessage("propagating absolute power constraint <%s>\n", SCIPconsGetName(cons));
2510 
2511  *cutoff = FALSE;
2512 
2513  /* get current bounds of variables */
2514  xlb = SCIPvarGetLbLocal(consdata->x);
2515  xub = SCIPvarGetUbLocal(consdata->x);
2516  zlb = SCIPvarGetLbLocal(consdata->z);
2517  zub = SCIPvarGetUbLocal(consdata->z);
2518 
2519  /* if some bound is not tightened, tighten bounds of variables as long as possible */
2520  tightenedround = !consdata->isxpropagated || !consdata->iszpropagated;
2521  while( tightenedround )
2522  {
2523  tightenedround = FALSE;
2524 
2525  /* propagate left hand side inequality: lhs <= (x+offset)*|x+offset|^n + c*z */
2526  if( !SCIPisInfinity(scip, -consdata->lhs) )
2527  {
2528  assert(!*cutoff);
2529 
2530  /* propagate bounds on x (if not multiaggregated):
2531  * (1) left hand side and bounds on z -> lower bound on x
2532  */
2533  if( SCIPvarIsActive(SCIPvarGetProbvar(consdata->x)) && (!SCIPisFeasEQ(scip, zlb, zub) || !SCIPisInfinity(scip, REALABS(zlb))) )
2534  {
2535  /* if z is fixed, first compute new lower bound on x without tolerances
2536  * if that is feasible, project new lower bound onto current bounds
2537  * otherwise, recompute with tolerances and continue as usual
2538  * do this only if variable is not essentially fixed to value of infinity
2539  */
2540  if( SCIPisFeasEQ(scip, zlb, zub) && !SCIPisInfinity(scip, zub) )
2541  {
2542  assert(!SCIPisInfinity(scip, -zlb));
2543 
2544  newlb = consdata->lhs - consdata->zcoef * (consdata->zcoef > 0.0 ? zub : zlb);
2545 
2546  /* invert sign(x+offset)|x+offset|^(n-1) = y -> x = sign(y)|y|^(1/n) - offset */
2547  if( consdata->exponent == 2.0 )
2548  newlb = SIGN(newlb) * sqrt(ABS(newlb));
2549  else
2550  newlb = SIGN(newlb) * pow(ABS(newlb), 1.0/consdata->exponent);
2551  newlb -= consdata->xoffset;
2552 
2553  if( SCIPisFeasGT(scip, newlb, xub) )
2554  {
2555  /* if new lower bound for x would yield cutoff, recompute with tolerances */
2556  newlb = consdata->lhs - PROPSIDETOL - consdata->zcoef * (consdata->zcoef > 0.0 ? (zub + PROPVARTOL) : (zlb - PROPVARTOL));
2557 
2558  /* invert sign(x+offset)|x+offset|^(n-1) = y -> x = sign(y)|y|^(1/n) - offset */
2559  if( consdata->exponent == 2.0 )
2560  newlb = SIGN(newlb) * sqrt(ABS(newlb));
2561  else
2562  newlb = SIGN(newlb) * pow(ABS(newlb), 1.0/consdata->exponent);
2563  newlb -= consdata->xoffset;
2564  }
2565  else
2566  {
2567  /* project new lower bound onto current bounds */
2568  newlb = MIN(newlb, xub);
2569  }
2570  }
2571  else
2572  {
2573  if( consdata->zcoef > 0.0 )
2574  {
2575  if( !SCIPisInfinity(scip, zub) )
2576  newlb = consdata->lhs - PROPSIDETOL - consdata->zcoef * (zub + PROPVARTOL);
2577  else
2578  newlb = -SCIPinfinity(scip);
2579  }
2580  else
2581  {
2582  if( !SCIPisInfinity(scip, -zlb) )
2583  newlb = consdata->lhs - PROPSIDETOL - consdata->zcoef * (zlb - PROPVARTOL);
2584  else
2585  newlb = -SCIPinfinity(scip);
2586  }
2587 
2588  if( !SCIPisInfinity(scip, -newlb) )
2589  {
2590  /* invert sign(x+offset)|x+offset|^(n-1) = y -> x = sign(y)|y|^(1/n) - offset */
2591  if( consdata->exponent == 2.0 )
2592  newlb = SIGN(newlb) * sqrt(ABS(newlb));
2593  else
2594  newlb = SIGN(newlb) * pow(ABS(newlb), 1.0/consdata->exponent);
2595  newlb -= consdata->xoffset;
2596  }
2597  }
2598 
2599  if( SCIPisInfinity(scip, newlb) )
2600  {
2601  /* we cannot fix a variable to +infinity, so let's report cutoff (there is no solution within SCIPs limitations to infinity) */
2602  SCIPdebugMessage(" -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g] -> cutoff\n", SCIPvarGetName(consdata->x), xlb, xub, newlb, xub);
2603 
2604  *cutoff = TRUE;
2605 
2606  /* analyze infeasibility */
2607  SCIP_CALL( analyzeConflict(scip, cons, consdata->x, PROPRULE_1, SCIP_BOUNDTYPE_LOWER) );
2608  break;
2609  }
2610 
2611  if( !SCIPisInfinity(scip, -newlb) )
2612  {
2613  if( SCIPisLbBetter(scip, newlb, xlb, xub) )
2614  {
2615  SCIPdebugMessage(" -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g]\n",
2616  SCIPvarGetName(consdata->x), xlb, xub, newlb, xub);
2617  SCIP_CALL( SCIPinferVarLbCons(scip, consdata->x, newlb, cons, (int)PROPRULE_1, FALSE, cutoff, &tightened) );
2618 
2619  if( *cutoff )
2620  {
2621  assert(SCIPisInfinity(scip, newlb) || SCIPisGT(scip, newlb, SCIPvarGetUbLocal(consdata->x)));
2622 
2623  /* analyze infeasibility */
2624  SCIP_CALL( analyzeConflict(scip, cons, consdata->x, PROPRULE_1, SCIP_BOUNDTYPE_LOWER) );
2625  break;
2626  }
2627 
2628  if( tightened )
2629  {
2630  tightenedround = TRUE;
2631  (*nchgbds)++;
2632  }
2633  xlb = SCIPvarGetLbLocal(consdata->x);
2634  }
2635  }
2636  }
2637 
2638  assert(!*cutoff);
2639 
2640  /* propagate bounds on z:
2641  * (2) left hand side and upper bound on x -> bound on z
2642  */
2643  if( SCIPvarGetStatus(consdata->z) != SCIP_VARSTATUS_MULTAGGR && !SCIPisInfinity(scip, xub) ) /* cannot change bounds of multaggr vars */
2644  {
2645  SCIP_Real newbd;
2646 
2647  /* if x is fixed, first compute new bound on z without tolerances
2648  * if that is feasible, project new bound onto current bounds
2649  * otherwise, recompute with tolerances and continue as usual
2650  */
2651  if( SCIPisFeasEQ(scip, xlb, xub) )
2652  {
2653  newbd = xub + consdata->xoffset;
2654  newbd = consdata->lhs - SIGN(newbd) * consdata->power(REALABS(newbd), consdata->exponent);
2655  newbd /= consdata->zcoef;
2656 
2657  if( SCIPisInfinity(scip, newbd) )
2658  newbd = SCIPinfinity(scip);
2659  else if( SCIPisInfinity(scip, -newbd) )
2660  newbd = -SCIPinfinity(scip);
2661 
2662  if( (consdata->zcoef > 0.0 && SCIPisFeasGT(scip, newbd, zub)) || (consdata->zcoef < 0.0 && SCIPisFeasLT(scip, newbd, zlb)) )
2663  {
2664  /* if infeasible, recompute with tolerances */
2665  newbd = xub + PROPVARTOL + consdata->xoffset;
2666  newbd = consdata->lhs - PROPSIDETOL - SIGN(newbd) * consdata->power(REALABS(newbd), consdata->exponent);
2667  newbd /= consdata->zcoef;
2668  }
2669  else
2670  {
2671  /* project onto current bounds of z */
2672  newbd = MIN(zub, MAX(zlb, newbd) );
2673  }
2674  }
2675  else
2676  {
2677  newbd = xub + PROPVARTOL + consdata->xoffset;
2678  newbd = consdata->lhs - PROPSIDETOL - SIGN(newbd) * consdata->power(REALABS(newbd), consdata->exponent);
2679  newbd /= consdata->zcoef;
2680  }
2681 
2682  if( consdata->zcoef > 0.0 )
2683  {
2684  newlb = newbd;
2685 
2686  if( SCIPisInfinity(scip, newlb) )
2687  {
2688  /* we cannot fix a variable to +infinity, so let's report cutoff (there is no solution within SCIPs limitations to infinity) */
2689  SCIPdebugMessage(" -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g] -> cutoff\n", SCIPvarGetName(consdata->z), zlb, zub, newlb, zub);
2690 
2691  *cutoff = TRUE;
2692 
2693  /* analyze infeasibility */
2694  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_2, SCIP_BOUNDTYPE_LOWER) );
2695  break;
2696  }
2697 
2698  if( SCIPisLbBetter(scip, newlb, zlb, zub) )
2699  {
2700  SCIPdebugMessage(" -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g]\n",
2701  SCIPvarGetName(consdata->z), zlb, zub, newlb, zub);
2702  SCIP_CALL( SCIPinferVarLbCons(scip, consdata->z, newlb, cons, (int)PROPRULE_2, FALSE, cutoff, &tightened) );
2703 
2704  if( *cutoff )
2705  {
2706  assert(SCIPisInfinity(scip, newlb) || SCIPisGT(scip, newlb, SCIPvarGetUbLocal(consdata->z)));
2707 
2708  /* analyze infeasibility */
2709  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_2, SCIP_BOUNDTYPE_LOWER) );
2710  break;
2711  }
2712 
2713  if( tightened )
2714  {
2715  tightenedround = TRUE;
2716  (*nchgbds)++;
2717  }
2718  zlb = SCIPvarGetLbLocal(consdata->z);
2719  }
2720  }
2721  else
2722  {
2723  newub = newbd;
2724 
2725  if( SCIPisInfinity(scip, -newub) )
2726  {
2727  /* we cannot fix a variable to -infinity, so let's report cutoff (there is no solution within SCIPs limitations to infinity) */
2728  SCIPdebugMessage(" -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g] -> cutoff\n", SCIPvarGetName(consdata->z), zlb, zub, zlb, newub);
2729 
2730  *cutoff = TRUE;
2731 
2732  /* analyze infeasibility */
2733  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_2, SCIP_BOUNDTYPE_UPPER) );
2734  break;
2735  }
2736 
2737  if( SCIPisUbBetter(scip, newub, zlb, zub) )
2738  {
2739  SCIPdebugMessage(" -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g]\n",
2740  SCIPvarGetName(consdata->z), zlb, zub, zlb, newub);
2741  SCIP_CALL( SCIPinferVarUbCons(scip, consdata->z, newub, cons, (int)PROPRULE_2, FALSE, cutoff, &tightened) );
2742 
2743  if( *cutoff )
2744  {
2745  assert(SCIPisInfinity(scip, -newub) || SCIPisLT(scip, newub, SCIPvarGetLbLocal(consdata->z)));
2746 
2747  /* analyze infeasibility */
2748  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_2, SCIP_BOUNDTYPE_UPPER) );
2749  break;
2750  }
2751 
2752  if( tightened )
2753  {
2754  tightenedround = TRUE;
2755  (*nchgbds)++;
2756  }
2757  zub = SCIPvarGetUbLocal(consdata->z);
2758  }
2759  }
2760  }
2761  }
2762 
2763  assert(!*cutoff);
2764 
2765  /* propagate right hand side inequality: sign(x+offset)|x+offset|^n + c*z <= rhs */
2766  if( !SCIPisInfinity(scip, consdata->rhs) )
2767  {
2768  /* propagate bounds on x:
2769  * (3) right hand side and bounds on z -> upper bound on x
2770  */
2771  if( SCIPvarIsActive(SCIPvarGetProbvar(consdata->x)) && (!SCIPisFeasEQ(scip, zlb, zub) || !SCIPisInfinity(scip, REALABS(zlb))) ) /* cannot change bounds of multaggr or fixed vars */
2772  {
2773  /* if z is fixed, first compute new upper bound on x without tolerances
2774  * if that is feasible, project new upper bound onto current bounds
2775  * otherwise, recompute with tolerances and continue as usual
2776  * do this only if variable is not essentially fixed to value of infinity
2777  */
2778  if( SCIPisFeasEQ(scip, zlb, zub) && !SCIPisInfinity(scip, zub) )
2779  {
2780  assert(!SCIPisInfinity(scip, -zlb));
2781 
2782  newub = consdata->rhs - consdata->zcoef * (consdata->zcoef > 0.0 ? zlb : zub);
2783 
2784  /* invert sign(x+offset)|x+offset|^(n-1) = y -> x = sign(y)|y|^(1/n) - offset */
2785  if( consdata->exponent == 2.0 )
2786  newub = SIGN(newub) * sqrt(ABS(newub));
2787  else
2788  newub = SIGN(newub) * pow(ABS(newub), 1.0/consdata->exponent);
2789  newub -= consdata->xoffset;
2790 
2791  if( SCIPisFeasLT(scip, newub, xlb) )
2792  {
2793  /* if new lower bound for x would yield cutoff, recompute with tolerances */
2794  newub = consdata->rhs + PROPSIDETOL - consdata->zcoef * (consdata->zcoef > 0.0 ? (zlb - PROPVARTOL) : (zub + PROPVARTOL));
2795 
2796  /* invert sign(x+offset)|x+offset|^(n-1) = y -> x = sign(y)|y|^(1/n) - offset */
2797  if( consdata->exponent == 2.0 )
2798  newub = SIGN(newub) * sqrt(ABS(newub));
2799  else
2800  newub = SIGN(newub) * pow(ABS(newub), 1.0/consdata->exponent);
2801  newub -= consdata->xoffset;
2802  }
2803  else
2804  {
2805  /* project new upper bound onto current bounds */
2806  newub = MAX(newub, xlb);
2807  }
2808  }
2809  else
2810  {
2811  if( consdata->zcoef > 0.0 )
2812  {
2813  if( !SCIPisInfinity(scip, -zlb) )
2814  newub = consdata->rhs + PROPSIDETOL - consdata->zcoef * (zlb - PROPVARTOL);
2815  else
2816  newub = SCIPinfinity(scip);
2817  }
2818  else
2819  {
2820  if( !SCIPisInfinity(scip, zub) )
2821  newub = consdata->rhs + PROPSIDETOL - consdata->zcoef * (zub + PROPVARTOL);
2822  else
2823  newub = SCIPinfinity(scip);
2824  }
2825  if( !SCIPisInfinity(scip, newub) )
2826  {
2827  /* invert sign(x+offset)|x+offset|^(n-1) = y -> x = sign(y)|y|^(1/n) - offset */
2828  if( consdata->exponent == 2.0 )
2829  newub = SIGN(newub) * sqrt(ABS(newub));
2830  else
2831  newub = SIGN(newub) * pow(ABS(newub), 1.0/consdata->exponent);
2832  newub -= consdata->xoffset;
2833  }
2834  }
2835 
2836  if( SCIPisInfinity(scip, -newub) )
2837  {
2838  /* we cannot fix a variable to -infinity, so let's report cutoff (there is no solution within SCIPs limitations to infinity) */
2839  SCIPdebugMessage(" -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g] -> cutoff\n", SCIPvarGetName(consdata->x), xlb, xub, xlb, newub);
2840 
2841  *cutoff = TRUE;
2842 
2843  /* analyze infeasibility */
2844  SCIP_CALL( analyzeConflict(scip, cons, consdata->x, PROPRULE_3, SCIP_BOUNDTYPE_UPPER) );
2845  break;
2846  }
2847 
2848  if( !SCIPisInfinity(scip, newub) )
2849  {
2850  if( SCIPisUbBetter(scip, newub, xlb, xub) )
2851  {
2852  SCIPdebugMessage(" -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g]\n",
2853  SCIPvarGetName(consdata->x), xlb, xub, xlb, newub);
2854  SCIP_CALL( SCIPinferVarUbCons(scip, consdata->x, newub, cons, (int)PROPRULE_3, FALSE, cutoff, &tightened) );
2855 
2856  if( *cutoff )
2857  {
2858  assert(SCIPisInfinity(scip, -newub) || SCIPisLT(scip, newub, SCIPvarGetLbLocal(consdata->x)));
2859 
2860  /* analyze infeasibility */
2861  SCIP_CALL( analyzeConflict(scip, cons, consdata->x, PROPRULE_3, SCIP_BOUNDTYPE_UPPER) );
2862  break;
2863  }
2864 
2865  if( tightened )
2866  {
2867  tightenedround = TRUE;
2868  (*nchgbds)++;
2869  }
2870  xub = SCIPvarGetUbLocal(consdata->x);
2871  }
2872  }
2873  }
2874 
2875  assert(!*cutoff);
2876 
2877  /* propagate bounds on z:
2878  * (4) right hand side and lower bound on x -> bound on z
2879  */
2880  if( SCIPvarGetStatus(consdata->z) != SCIP_VARSTATUS_MULTAGGR && !SCIPisInfinity(scip, -xlb) ) /* cannot change bounds of multaggr vars */
2881  {
2882  SCIP_Real newbd;
2883 
2884  /* if x is fixed, first compute new bound on z without tolerances
2885  * if that is feasible, project new bound onto current bounds
2886  * otherwise, recompute with tolerances and continue as usual
2887  */
2888  if( SCIPisFeasEQ(scip, xlb, xub) )
2889  {
2890  newbd = xlb + consdata->xoffset;
2891  newbd = consdata->rhs - SIGN(newbd) * consdata->power(REALABS(newbd), consdata->exponent);
2892  newbd /= consdata->zcoef;
2893 
2894  if( SCIPisInfinity(scip, newbd) )
2895  newbd = SCIPinfinity(scip);
2896  else if( SCIPisInfinity(scip, -newbd) )
2897  newbd = -SCIPinfinity(scip);
2898 
2899  if( (consdata->zcoef > 0.0 && SCIPisFeasLT(scip, newbd, zlb)) || (consdata->zcoef < 0.0 && SCIPisFeasGT(scip, newbd, zub)) )
2900  {
2901  /* if infeasible, recompute with tolerances */
2902  newbd = xlb - PROPVARTOL + consdata->xoffset;
2903  newbd = consdata->rhs + PROPSIDETOL - SIGN(newbd) * consdata->power(REALABS(newbd), consdata->exponent);
2904  newbd /= consdata->zcoef;
2905  }
2906  else
2907  {
2908  /* project onto current bounds of z */
2909  newbd = MIN(zub, MAX(zlb, newbd) );
2910  }
2911  }
2912  else
2913  {
2914  newbd = xlb - PROPVARTOL + consdata->xoffset;
2915  newbd = consdata->rhs + PROPSIDETOL - SIGN(newbd) * consdata->power(REALABS(newbd), consdata->exponent);
2916  newbd /= consdata->zcoef;
2917  }
2918 
2919  if( consdata->zcoef > 0.0 )
2920  {
2921  newub = newbd;
2922 
2923  if( SCIPisInfinity(scip, -newub) )
2924  {
2925  /* we cannot fix a variable to -infinity, so let's report cutoff (there is no solution within SCIPs limitations to infinity) */
2926  SCIPdebugMessage(" -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g] -> cutoff\n", SCIPvarGetName(consdata->z), zlb, zub, zlb, newub);
2927 
2928  *cutoff = TRUE;
2929 
2930  /* analyze infeasibility */
2931  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_4, SCIP_BOUNDTYPE_UPPER) );
2932  break;
2933  }
2934 
2935  if( SCIPisUbBetter(scip, newub, zlb, zub) )
2936  {
2937  SCIPdebugMessage(" -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g]\n",
2938  SCIPvarGetName(consdata->z), zlb, zub, zlb, newub);
2939  SCIP_CALL( SCIPinferVarUbCons(scip, consdata->z, newub, cons, (int)PROPRULE_4, FALSE, cutoff, &tightened) );
2940 
2941  if( *cutoff )
2942  {
2943  assert(SCIPisInfinity(scip, -newub) || SCIPisLT(scip, newub, SCIPvarGetLbLocal(consdata->z)));
2944 
2945  /* analyze infeasibility */
2946  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_4, SCIP_BOUNDTYPE_UPPER) );
2947  break;
2948  }
2949 
2950  if( tightened )
2951  {
2952  tightenedround = TRUE;
2953  (*nchgbds)++;
2954  }
2955  zub = SCIPvarGetUbLocal(consdata->z);
2956  }
2957  }
2958  else
2959  {
2960  newlb = newbd;
2961 
2962  if( SCIPisInfinity(scip, newlb) )
2963  {
2964  /* we cannot fix a variable to +infinity, so let's report cutoff (there is no solution within SCIPs limitations to infinity) */
2965  SCIPdebugMessage(" -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g] -> cutoff\n", SCIPvarGetName(consdata->z), zlb, zub, newlb, zub);
2966 
2967  *cutoff = TRUE;
2968 
2969  /* analyze infeasibility */
2970  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_4, SCIP_BOUNDTYPE_LOWER) );
2971  break;
2972  }
2973 
2974  if( SCIPisLbBetter(scip, newlb, zlb, zub) )
2975  {
2976  SCIPdebugMessage(" -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g]\n",
2977  SCIPvarGetName(consdata->z), zlb, zub, newlb, zub);
2978  SCIP_CALL( SCIPinferVarLbCons(scip, consdata->z, newlb, cons, (int)PROPRULE_4, FALSE, cutoff, &tightened) );
2979 
2980  if( *cutoff )
2981  {
2982  assert(SCIPisInfinity(scip, newlb) || SCIPisGT(scip, newlb, SCIPvarGetUbLocal(consdata->z)));
2983 
2984  /* analyze infeasibility */
2985  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_4, SCIP_BOUNDTYPE_LOWER) );
2986  break;
2987  }
2988 
2989  if( tightened )
2990  {
2991  tightenedround = TRUE;
2992  (*nchgbds)++;
2993  }
2994  zlb = SCIPvarGetLbLocal(consdata->z);
2995  }
2996  }
2997  }
2998  }
2999 
3000  assert(!*cutoff);
3001  }
3002 
3003  /* mark the constraint propagated */
3004  consdata->isxpropagated = TRUE;
3005  consdata->iszpropagated = TRUE;
3006 
3007  if( *cutoff )
3008  return SCIP_OKAY;
3009 
3010  /* check for redundancy */
3011  if( !SCIPisInfinity(scip, -xlb) && !SCIPisInfinity(scip, consdata->zcoef > 0.0 ? -zlb : zub) )
3012  minact = SIGN(xlb + consdata->xoffset) * consdata->power(REALABS(xlb + consdata->xoffset), consdata->exponent) + consdata->zcoef * (consdata->zcoef > 0.0 ? zlb : zub);
3013  else
3014  minact = -SCIPinfinity(scip);
3015 
3016  if( !SCIPisInfinity(scip, xub) && !SCIPisInfinity(scip, consdata->zcoef > 0.0 ? zub : -zlb) )
3017  maxact = SIGN(xub + consdata->xoffset) * consdata->power(REALABS(xub + consdata->xoffset), consdata->exponent) + consdata->zcoef * (consdata->zcoef > 0.0 ? zub : zlb);
3018  else
3019  maxact = SCIPinfinity(scip);
3020 
3021  if( SCIPisFeasGE(scip, minact, consdata->lhs) && SCIPisFeasLE(scip, maxact, consdata->rhs) )
3022  {
3023  SCIPdebugMessage("absolute power constraint <%s> is redundant: <%s>[%.15g,%.15g], <%s>[%.15g,%.15g]\n",
3024  SCIPconsGetName(cons),
3025  SCIPvarGetName(consdata->x), SCIPvarGetLbLocal(consdata->x), SCIPvarGetUbLocal(consdata->x),
3026  SCIPvarGetName(consdata->z), SCIPvarGetLbLocal(consdata->z), SCIPvarGetUbLocal(consdata->z));
3027 
3028  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
3029 
3030  return SCIP_OKAY;
3031  }
3032 
3033  /* delete constraint if x has been fixed */
3034  if( SCIPisRelEQ(scip, xlb, xub) && (SCIPvarIsActive(consdata->z) || canaddcons) )
3035  {
3036  SCIP_RESULT tightenresult;
3037  SCIP_INTERVAL xbnds;
3038  SCIP_INTERVAL zbnds;
3039 
3040  SCIPdebugMessage("x-variable in constraint <%s> is fixed: x = <%s>[%.15g,%.15g], z = <%s>[%.15g,%.15g]\n",
3041  SCIPconsGetName(cons), SCIPvarGetName(consdata->x), xlb, xub, SCIPvarGetName(consdata->z), zlb, zub);
3042 
3043  SCIPintervalSetBounds(&xbnds, MIN(xlb, xub), MAX(xlb, xub));
3044  computeBoundsZ(scip, cons, xbnds, &zbnds);
3045 
3046  /* in difference to the loop above, here we enforce a possible bound tightening on z, and may add a linear cons if z is multiaggregated */
3047  SCIP_CALL( tightenBounds(scip, consdata->z, zbnds, TRUE, cons, &tightenresult, nchgbds, nchgbds, naddconss) );
3048  if( tightenresult == SCIP_CUTOFF )
3049  *cutoff = TRUE;
3050 
3051  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
3052 
3053  return SCIP_OKAY;
3054  }
3055 
3056  /* delete constraint if z has been fixed */
3057  if( SCIPisRelEQ(scip, zlb, zub) && (SCIPvarIsActive(consdata->x) || canaddcons) )
3058  {
3059  SCIP_RESULT tightenresult;
3060  SCIP_INTERVAL xbnds;
3061  SCIP_INTERVAL zbnds;
3062 
3063  SCIPdebugMessage("z-variable in constraint <%s> is fixed: x = <%s>[%.15g,%.15g], z = <%s>[%.15g,%.15g]\n",
3064  SCIPconsGetName(cons), SCIPvarGetName(consdata->x), xlb, xub, SCIPvarGetName(consdata->z), zlb, zub);
3065 
3066  SCIPintervalSetBounds(&zbnds, MIN(zlb, zub), MAX(zlb, zub));
3067  computeBoundsX(scip, cons, zbnds, &xbnds);
3068 
3069  /* in difference to the loop above, here we enforce a possible bound tightening on x, and may add a linear cons if x is multiaggregated */
3070  SCIP_CALL( tightenBounds(scip, consdata->x, xbnds, TRUE, cons, &tightenresult, nchgbds, nchgbds, naddconss) );
3071  if( tightenresult == SCIP_CUTOFF )
3072  *cutoff = TRUE;
3073 
3074  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
3075 
3076  return SCIP_OKAY;
3077  }
3078 
3079  return SCIP_OKAY;
3080 }
3081 
3082 /** notifies SCIP about a variable bound lhs <= x + c*y <= rhs */
3083 static
3085  SCIP* scip, /**< SCIP data structure */
3086  SCIP_CONS* cons, /**< absolute power constraint this variable bound is derived form */
3087  SCIP_Bool addcons, /**< should the variable bound be added as constraint to SCIP? */
3088  SCIP_VAR* var, /**< variable x for which we want to add a variable bound */
3089  SCIP_VAR* vbdvar, /**< variable y which makes the bound a variable bound */
3090  SCIP_Real vbdcoef, /**< coefficient c of bounding variable vbdvar */
3091  SCIP_Real lhs, /**< left hand side of varbound constraint */
3092  SCIP_Real rhs, /**< right hand side of varbound constraint */
3093  SCIP_Bool* infeas, /**< pointer to store whether an infeasibility was detected */
3094  int* nbdchgs, /**< pointer where to add number of performed bound changes */
3095  int* naddconss /**< pointer where to add number of added constraints */
3096  )
3097 {
3098  int nbdchgs_local;
3099 
3100  assert(scip != NULL);
3101  assert(cons != NULL);
3102  assert(var != NULL);
3103  assert(vbdvar != NULL);
3104  assert(!SCIPisZero(scip, vbdcoef));
3105  assert(!SCIPisInfinity(scip, ABS(vbdcoef)));
3106  assert(infeas != NULL);
3107 
3108  *infeas = FALSE;
3109 
3110  /* make sure vbdvar is active, so we can search for it in SCIPvarGetVxbdVars() */
3111  if( !SCIPvarIsActive(vbdvar) )
3112  {
3113  SCIP_Real constant;
3114 
3115  constant = 0.0;
3116  SCIP_CALL( SCIPgetProbvarSum(scip, &vbdvar, &vbdcoef, &constant) );
3117  if( !SCIPvarIsActive(vbdvar) || (vbdcoef == 0.0) )
3118  return SCIP_OKAY;
3119 
3120  if( !SCIPisInfinity(scip, -lhs) )
3121  lhs -= constant;
3122  if( !SCIPisInfinity(scip, rhs) )
3123  rhs -= constant;
3124  }
3125 
3126  /* vbdvar should be a non-fixed binary variable */
3127  assert(SCIPvarIsIntegral(vbdvar));
3128  assert(SCIPisZero(scip, SCIPvarGetLbGlobal(vbdvar)));
3129  assert(SCIPisEQ(scip, SCIPvarGetUbGlobal(vbdvar), 1.0));
3130 
3131  SCIPdebugMessage("-> %g <= <%s> + %g*<%s> <= %g\n", lhs, SCIPvarGetName(var), vbdcoef, SCIPvarGetName(vbdvar), rhs);
3132 
3133  if( addcons && SCIPvarGetStatus(var) != SCIP_VARSTATUS_MULTAGGR )
3134  {
3135  SCIP_CONS* vbdcons;
3136  char name[SCIP_MAXSTRLEN];
3137 
3138  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_vbnd", SCIPconsGetName(cons));
3139 
3140  SCIP_CALL( SCIPcreateConsVarbound(scip, &vbdcons, name, var, vbdvar, vbdcoef, lhs, rhs,
3142  SCIP_CALL( SCIPaddCons(scip, vbdcons) );
3143  SCIP_CALL( SCIPreleaseCons(scip, &vbdcons) );
3144 
3145  ++*naddconss;
3146 
3147  return SCIP_OKAY;
3148  }
3149 
3150 
3151  if( !SCIPisInfinity(scip, -lhs) )
3152  {
3153  SCIP_CALL( SCIPaddVarVlb(scip, var, vbdvar, -vbdcoef, lhs, infeas, &nbdchgs_local) );
3154  if( *infeas )
3155  return SCIP_OKAY;
3156  *nbdchgs += nbdchgs_local;
3157  }
3158 
3159  if( !SCIPisInfinity(scip, rhs) )
3160  {
3161  SCIP_CALL( SCIPaddVarVub(scip, var, vbdvar, -vbdcoef, rhs, infeas, &nbdchgs_local) );
3162  if( *infeas )
3163  return SCIP_OKAY;
3164  *nbdchgs += nbdchgs_local;
3165  }
3166 
3167  return SCIP_OKAY;
3168 }
3169 
3170 /** propagates varbounds of variables
3171  * Let f(x) = sign(x+offset)|x+offset|^n, f^{-1}(y) = sign(y)|y|^(1/n) - offset.
3172  * Thus, constraint is lhs <= f(x) + c*z <= rhs.
3173  *
3174  * Given a variable bound constraint x <= a*y + b with y a binary variable, one obtains
3175  * y = 0 -> f(x) <= f(b) -> lhs <= f(b) + c*z
3176  * y = 1 -> f(x) <= f(a+b) -> lhs <= f(a+b) + c*z
3177  * => lhs <= f(b) + y * (f(a+b)-f(b)) + c*z
3178  *
3179  * Given a variable bound constraint x >= a*y + b with y a binary variable, one obtains analogously
3180  * f(b) + y * (f(a+b)-f(b)) + c*z <= rhs
3181  *
3182  * Given a variable bound constraint c*z <= a*y + b with y a binary variable, one obtains
3183  * y = 0 -> lhs <= f(x) + b -> x >= f^{-1}(lhs - b)
3184  * y = 1 -> lhs <= f(x) + a+b -> x >= f^{-1}(lhs - (a+b))
3185  * => x >= f^{-1}(lhs - b) + y * (f^{-1}(lhs - (a+b)) - f^{-1}(lhs - b))
3186  *
3187  * Given a variable bound constraint c*z >= a*y + b with y a binary variable, one obtains analogously
3188  * x <= f^{-1}(rhs - b) + y * (f^{-1}(rhs - (a+b)) - f^{-1}(rhs - b))
3189  */
3190 static
3192  SCIP* scip, /**< SCIP data structure */
3193  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
3194  SCIP_CONS* cons, /**< absolute power constraint */
3195  SCIP_Bool* infeas, /**< pointer to store whether an infeasibility was detected */
3196  int* nbdchgs, /**< pointer where to add number of performed bound changes */
3197  int* naddconss /**< pointer where to add number of added constraints */
3198  )
3199 {
3200  SCIP_CONSHDLRDATA* conshdlrdata;
3201  SCIP_CONSDATA* consdata;
3202  SCIP_VAR* y;
3203  SCIP_Real a;
3204  SCIP_Real b;
3205  SCIP_Real fb;
3206  SCIP_Real fab;
3207  SCIP_Real vbcoef;
3208  SCIP_Real vbconst;
3209  int i;
3210 
3211  assert(scip != NULL);
3212  assert(conshdlr != NULL);
3213  assert(cons != NULL);
3214  assert(infeas != NULL);
3215  assert(nbdchgs != NULL);
3216  assert(naddconss != NULL);
3217 
3218  *infeas = FALSE;
3219 
3220  conshdlrdata = SCIPconshdlrGetData(conshdlr);
3221  assert(conshdlrdata != NULL);
3222 
3223  consdata = SCIPconsGetData(cons);
3224  assert(consdata != NULL);
3225  assert(consdata->z != NULL);
3226 
3227  /* don't do anything if it looks like we have numerical troubles */
3228  if( SCIPisZero(scip, consdata->zcoef) )
3229  return SCIP_OKAY;
3230 
3231  if( !SCIPisInfinity(scip, -consdata->lhs) )
3232  {
3233  /* propagate varbounds x <= a*y+b onto z
3234  * lhs <= f(b) + y * (f(a+b)-f(b)) + c*z
3235  * -> c*z >= lhs-f(b) + y * (f(b)-f(a+b))
3236  */
3237  for( i = 0; i < SCIPvarGetNVubs(consdata->x); ++i )
3238  {
3239  y = SCIPvarGetVubVars(consdata->x)[i];
3240  a = SCIPvarGetVubCoefs(consdata->x)[i];
3241  b = SCIPvarGetVubConstants(consdata->x)[i];
3242 
3243  /* skip variable bound if y is not integer or its valid values are not {0,1}
3244  * @todo extend to arbitrary integer variables
3245  */
3246  if( !SCIPvarIsBinary(y) || SCIPvarGetLbGlobal(y) > 0.5 || SCIPvarGetUbGlobal(y) < 0.5 )
3247  continue;
3248 
3249  /* skip variable bound if coefficient is very small */
3250  if( SCIPisFeasZero(scip, consdata->power(a, consdata->exponent)) )
3251  continue;
3252 
3253  SCIPdebugMessage("propagate variable bound <%s> <= %g*<%s> + %g\n", SCIPvarGetName(consdata->x), a, SCIPvarGetName(y), b);
3254 
3255  fb = SIGN( b + consdata->xoffset) * consdata->power( b + consdata->xoffset, consdata->exponent); /* f( b) = sign( b) | b|^n */
3256  fab = SIGN(a+b + consdata->xoffset) * consdata->power(a+b + consdata->xoffset, consdata->exponent); /* f(a+b) = sign(a+b) |a+b|^n */
3257 
3258  vbcoef = (fb - fab) / consdata->zcoef;
3259  vbconst = (consdata->lhs - fb) / consdata->zcoef;
3260 
3261  if( consdata->zcoef > 0.0 )
3262  {
3263  /* add varbound z >= (lhs-f(b))/c + y * (f(b)-f(a+b))/c */
3264  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->z, y, -vbcoef, vbconst, SCIPinfinity(scip), infeas, nbdchgs, naddconss) );
3265  }
3266  else
3267  {
3268  /* add varbound z <= (lhs-f(b))/c + y * (f(b)-f(a+b))/c */
3269  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->z, y, -vbcoef, -SCIPinfinity(scip), vbconst, infeas, nbdchgs, naddconss) );
3270  }
3271  if( *infeas )
3272  return SCIP_OKAY;
3273  }
3274  }
3275 
3276  /* propagate varbounds x >= a*y+b onto z
3277  * f(b) + y * (f(a+b)-f(b)) + c*z <= rhs
3278  * -> c*z <= rhs-f(b) + y * (f(b)-f(a+b))
3279  */
3280  if( !SCIPisInfinity(scip, consdata->rhs) )
3281  {
3282  for( i = 0; i < SCIPvarGetNVlbs(consdata->x); ++i )
3283  {
3284  y = SCIPvarGetVlbVars(consdata->x)[i];
3285  a = SCIPvarGetVlbCoefs(consdata->x)[i];
3286  b = SCIPvarGetVlbConstants(consdata->x)[i];
3287 
3288  /* skip variable bound if y is not integer or its valid values are not {0,1}
3289  * @todo extend to arbitrary integer variables
3290  */
3291  if( !SCIPvarIsBinary(y) || SCIPvarGetLbGlobal(y) > 0.5 || SCIPvarGetUbGlobal(y) < 0.5 )
3292  continue;
3293 
3294  /* skip variable bound if coefficient is very small */
3295  if( SCIPisFeasZero(scip, consdata->power(a, consdata->exponent)) )
3296  continue;
3297 
3298  SCIPdebugMessage("propagate variable bound <%s> >= %g*<%s> + %g\n", SCIPvarGetName(consdata->x), a, SCIPvarGetName(y), b);
3299 
3300  fb = SIGN( b + consdata->xoffset) * consdata->power( b + consdata->xoffset, consdata->exponent); /* f( b) = sign( b) | b|^n */
3301  fab = SIGN(a+b + consdata->xoffset) * consdata->power(a+b + consdata->xoffset, consdata->exponent); /* f(a+b) = sign(a+b) |a+b|^n */
3302 
3303  vbcoef = (fb - fab) / consdata->zcoef;
3304  vbconst = (consdata->rhs - fb) / consdata->zcoef;
3305 
3306  if( consdata->zcoef > 0.0 )
3307  {
3308  /* add varbound z <= (rhs-f(b))/c + y * (f(b)-f(a+b))/c */
3309  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->z, y, -vbcoef, -SCIPinfinity(scip), vbconst, infeas, nbdchgs, naddconss) );
3310  }
3311  else
3312  {
3313  /* add varbound z >= (rhs-f(b))/c + y * (f(b)-f(a+b))/c */
3314  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->z, y, -vbcoef, vbconst, SCIPinfinity(scip), infeas, nbdchgs, naddconss) );
3315  }
3316  if( *infeas )
3317  return SCIP_OKAY;
3318  }
3319  }
3320 
3321  /* propagate variable upper bounds on z onto x
3322  * c*z <= a*y+b -> x >= f^{-1}(lhs - b) + y * (f^{-1}(lhs - (a+b)) - f^{-1}(lhs - b))
3323  * c*z >= a*y+b -> x <= f^{-1}(rhs - b) + y * (f^{-1}(rhs - (a+b)) - f^{-1}(rhs - b))
3324  */
3325  if( (consdata->zcoef > 0.0 && !SCIPisInfinity(scip, -consdata->lhs)) ||
3326  ( consdata->zcoef < 0.0 && !SCIPisInfinity(scip, consdata->rhs)) )
3327  for( i = 0; i < SCIPvarGetNVubs(consdata->z); ++i )
3328  {
3329  y = SCIPvarGetVubVars(consdata->z)[i];
3330  a = SCIPvarGetVubCoefs(consdata->z)[i] * consdata->zcoef;
3331  b = SCIPvarGetVubConstants(consdata->z)[i] * consdata->zcoef;
3332 
3333  SCIPdebugMessage("propagate variable bound %g*<%s> %c= %g*<%s> + %g\n", consdata->zcoef, SCIPvarGetName(consdata->z), consdata->zcoef > 0 ? '<' : '>', a, SCIPvarGetName(y), b);
3334 
3335  /* skip variable bound if y is not integer or its valid values are not {0,1}
3336  * @todo extend to arbitrary integer variables
3337  */
3338  if( !SCIPvarIsBinary(y) || SCIPvarGetLbGlobal(y) > 0.5 || SCIPvarGetUbGlobal(y) < 0.5 )
3339  continue;
3340 
3341  if( consdata->zcoef > 0.0 )
3342  {
3343  fb = consdata->lhs - b;
3344  fb = SIGN(fb) * pow(ABS(fb), 1.0/consdata->exponent);
3345  fab = consdata->lhs - (a+b);
3346  fab = SIGN(fab) * pow(ABS(fab), 1.0/consdata->exponent);
3347  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->x, y, fb - fab, fb - consdata->xoffset, SCIPinfinity(scip), infeas, nbdchgs, naddconss) );
3348  }
3349  else
3350  {
3351  fb = consdata->rhs - b;
3352  fb = SIGN(fb) * pow(ABS(fb), 1.0/consdata->exponent);
3353  fab = consdata->rhs - (a+b);
3354  fab = SIGN(fab) * pow(ABS(fab), 1.0/consdata->exponent);
3355  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->x, y, fb - fab, -SCIPinfinity(scip), fb - consdata->xoffset, infeas, nbdchgs, naddconss) );
3356  }
3357  if( *infeas )
3358  return SCIP_OKAY;
3359  }
3360 
3361  /* propagate variable lower bounds on z onto x
3362  * c*z <= a*y+b -> x >= f^{-1}(lhs - b) + y * (f^{-1}(lhs - (a+b)) - f^{-1}(lhs - b))
3363  * c*z >= a*y+b -> x <= f^{-1}(rhs - b) + y * (f^{-1}(rhs - (a+b)) - f^{-1}(rhs - b))
3364  */
3365  if( (consdata->zcoef < 0.0 && !SCIPisInfinity(scip, -consdata->lhs)) ||
3366  ( consdata->zcoef > 0.0 && !SCIPisInfinity(scip, consdata->rhs)) )
3367  for( i = 0; i < SCIPvarGetNVlbs(consdata->z); ++i )
3368  {
3369  y = SCIPvarGetVlbVars(consdata->z)[i];
3370  a = SCIPvarGetVlbCoefs(consdata->z)[i] * consdata->zcoef;
3371  b = SCIPvarGetVlbConstants(consdata->z)[i] * consdata->zcoef;
3372 
3373  SCIPdebugMessage("propagate variable bound %g*<%s> %c= %g*<%s> + %g\n", consdata->zcoef, SCIPvarGetName(consdata->z), consdata->zcoef > 0 ? '>' : '<', a, SCIPvarGetName(y), b);
3374 
3375  /* skip variable bound if y is not integer or its valid values are not {0,1}
3376  * @todo extend to arbitrary integer variables
3377  */
3378  if( !SCIPvarIsBinary(y) || SCIPvarGetLbGlobal(y) > 0.5 || SCIPvarGetUbGlobal(y) < 0.5 )
3379  continue;
3380 
3381  if( consdata->zcoef > 0.0 )
3382  {
3383  fb = consdata->rhs - b;
3384  fb = SIGN(fb) * pow(ABS(fb), 1.0/consdata->exponent);
3385  fab = consdata->rhs - (a+b);
3386  fab = SIGN(fab) * pow(ABS(fab), 1.0/consdata->exponent);
3387  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->x, y, fb - fab, -SCIPinfinity(scip), fb - consdata->xoffset, infeas, nbdchgs, naddconss) );
3388  }
3389  else
3390  {
3391  fb = consdata->lhs - b;
3392  fb = SIGN(fb) * pow(ABS(fb), 1.0/consdata->exponent);
3393  fab = consdata->lhs - (a+b);
3394  fab = SIGN(fab) * pow(ABS(fab), 1.0/consdata->exponent);
3395  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->x, y, fb - fab, fb - consdata->xoffset, SCIPinfinity(scip), infeas, nbdchgs, naddconss) );
3396  }
3397  if( *infeas )
3398  return SCIP_OKAY;
3399  }
3400 
3401  return SCIP_OKAY;
3402 }
3403 
3404 /** computes linear underestimator for (x+offset)^n + c*z <= rhs by linearization in x
3405  *
3406  * the generated cut is xmul * n * (refpoint+offset)^(n-1) * x + c*z <= rhs + ((n-1)*refpoint-offset) * (refpoint+offset)^(n-1)
3407  */
3408 static
3410  SCIP* scip, /**< SCIP data structure */
3411  SCIP_ROW** row, /**< buffer to store row */
3412  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
3413  SCIP_Real refpoint, /**< base point for linearization */
3414  SCIP_Real exponent, /**< exponent n in sign(x)abs(x)^n */
3415  SCIP_Real xoffset, /**< offset of x */
3416  SCIP_Real xmult, /**< multiplier for coefficient of x */
3417  SCIP_Real zcoef, /**< coefficient of z */
3418  SCIP_Real rhs, /**< right hand side */
3419  SCIP_VAR* x, /**< variable x */
3420  SCIP_VAR* z, /**< variable z */
3421  SCIP_Bool islocal /**< whether the cut is valid only locally */
3422  )
3423 {
3424  char rowname[SCIP_MAXSTRLEN];
3425  SCIP_CONSHDLRDATA* conshdlrdata;
3426  SCIP_Real tmp;
3427 
3428  assert(scip != NULL);
3429  assert(!SCIPisFeasNegative(scip, refpoint+xoffset));
3430  assert(!SCIPisInfinity(scip, refpoint));
3431 
3432  conshdlrdata = SCIPconshdlrGetData(conshdlr);
3433  assert(conshdlrdata != NULL);
3434 
3435  if( refpoint < -xoffset )
3436  refpoint = -xoffset;
3437 
3438  tmp = exponent == 2.0 ? refpoint+xoffset : pow(refpoint+xoffset, exponent-1);
3439  if( SCIPisInfinity(scip, tmp) )
3440  {
3441  SCIPdebugMessage("skip linearization cut because (refpoint+offset)^(exponent-1) > infinity\n");
3442  *row = NULL;
3443  return SCIP_OKAY;
3444  }
3445 
3446  rhs += ((exponent-1)*refpoint-xoffset)*tmp; /* now rhs is the rhs of the cut */
3447  /* do not change the right hand side to a value > infinity (this would trigger an assertion in lp.c) */
3448  if( SCIPisInfinity(scip, rhs) )
3449  {
3450  SCIPdebugMessage("skip linearization cut because its rhs would be > infinity\n");
3451  *row = NULL;
3452  return SCIP_OKAY;
3453  }
3454 
3455  (void) SCIPsnprintf(rowname, SCIP_MAXSTRLEN, "signpowlinearizecut_%u", ++(conshdlrdata->ncuts));
3456 
3457  SCIP_CALL( SCIPcreateEmptyRowCons(scip, row, conshdlr, rowname, -SCIPinfinity(scip), rhs, islocal,
3458  FALSE /* modifiable */, TRUE /* removable */ ) );
3459 
3460  SCIP_CALL( SCIPaddVarToRow(scip, *row, x, xmult*exponent*tmp) );
3461  SCIP_CALL( SCIPaddVarToRow(scip, *row, z, zcoef) );
3462 
3463  return SCIP_OKAY;
3464 }
3465 
3466 /** computes linear underestimator for (x+xoffset)^n + c*z <= rhs by linearization in x
3467  *
3468  * the generated cut is xmul * n * (refpoint+offset)^(n-1) * x + c*z <= rhs + ((n-1)*refpoint-offset) * (refpoint+offset)^(n-1)
3469  * where refpoint is computed by projecting (xref, zref) onto the graph of (x+offset)^n w.r.t. euclidean norm
3470  *
3471  * Thus, the projection is computed by minimizing 1/2(x-xref)^2 + 1/2(((x+offset)^n-rhs)/(-c) - zref)^2.
3472  * I.e., we aim to find a root of
3473  * g(x) = x - xref + n/c (x+offset)^(n-1) (zref - rhs/c) + n/c^2 (x+offset)^(2n-1)
3474  * We do this numerically by executing up to five newton iterations. It is
3475  * g'(x) = 1 + n(n-1)/c (x+offset)^(n-2) (zref - rhs/c) + n(2n-1)/c^2 (x+offset)^(2n-2)
3476  */
3477 static
3479  SCIP* scip, /**< SCIP data structure */
3480  SCIP_ROW** row, /**< buffer to store row */
3481  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
3482  SCIP_Real xref, /**< reference point for x */
3483  SCIP_Real zref, /**< reference point for z */
3484  SCIP_Real xmin, /**< minimal value x is allowed to take */
3485  SCIP_Real exponent, /**< exponent n in sign(x+offset)abs(x+offset)^n */
3486  SCIP_Real xoffset, /**< offset of x */
3487  SCIP_Real xmult, /**< multiplier for coefficient of x */
3488  SCIP_Real zcoef, /**< coefficient of z */
3489  SCIP_Real rhs, /**< right hand side */
3490  SCIP_VAR* x, /**< variable x */
3491  SCIP_VAR* z, /**< variable z */
3492  SCIP_Bool islocal /**< whether the cut is valid only locally */
3493  )
3494 {
3495  SCIP_Real tmp;
3496  SCIP_Real xproj;
3497  SCIP_Real gval;
3498  SCIP_Real gderiv;
3499  int iter;
3500 
3501  assert(scip != NULL);
3502  assert(!SCIPisFeasNegative(scip, xref+xoffset));
3503  assert(!SCIPisInfinity(scip, xref));
3504 
3505  if( xref < xmin )
3506  xref = xmin;
3507 
3508  xproj = xref;
3509  iter = 0;
3510  if( exponent == 2.0 )
3511  do
3512  {
3513  tmp = (xproj+xoffset) * (xproj+xoffset);
3514  gval = xproj - xref + 2*(xproj+xoffset) / zcoef * ((tmp-rhs)/zcoef + zref);
3515  if( !SCIPisFeasPositive(scip, ABS(gval)) )
3516  break;
3517 
3518  gderiv = 1 + 6 * tmp / (zcoef*zcoef) + 2 / zcoef * (zref - rhs/zcoef);
3519  xproj -= gval / gderiv;
3520 
3521  }
3522  while( ++iter <= 5 );
3523  else
3524  do
3525  {
3526  tmp = pow(xproj + xoffset, exponent-1);
3527  gval = xproj - xref + exponent / zcoef * (pow(xproj+xoffset, 2*exponent-1)/zcoef + tmp * (zref-rhs/zcoef));
3528  if( !SCIPisFeasPositive(scip, ABS(gval)) )
3529  break;
3530 
3531  gderiv = 1 + exponent / zcoef * ( (2*exponent-1)*tmp*tmp/zcoef + (exponent-1)*pow(xproj+xoffset, exponent-2) * (zref-rhs/zcoef) );
3532  xproj -= gval / gderiv;
3533 
3534  }
3535  while( ++iter <= 5 );
3536 
3537  if( xproj < xmin )
3538  xproj = xmin;
3539 
3540  SCIP_CALL( generateLinearizationCut(scip, row, conshdlr, xproj, exponent, xoffset, xmult, zcoef, rhs, x, z, islocal) );
3541 
3542  return SCIP_OKAY;
3543 }
3544 
3545 /** computes secant underestimator for sign(x+offset)abs(x+offset)^n + c*z <= rhs
3546  *
3547  * the generated cut is slope*xmult*x + c*z <= rhs + (-xlb-offset)^n + slope*xlb,
3548  * where slope = (sign(xub+offset)*abs(xub+offset)^n + (-xlb-offset)^n) / (xub - xlb).
3549  *
3550  * the cut is not generated if the given solution (or the LP solution) would not be cutoff
3551  */
3552 static
3554  SCIP* scip, /**< SCIP data structure */
3555  SCIP_ROW** row, /**< buffer to store row */
3556  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
3557  SCIP_SOL* sol, /**< point we want to cut off, or NULL for LP solution */
3558  SCIP_Real xlb, /**< lower bound of x */
3559  SCIP_Real xub, /**< upper bound of x */
3560  SCIP_Real exponent, /**< exponent n in sign(x+offset)abs(x+offset)^n */
3561  SCIP_Real xoffset, /**< offset of x */
3562  DECL_MYPOW ((*mypow)), /**< function to use for computing power */
3563  SCIP_Real xmult, /**< multiplier for coefficient of x */
3564  SCIP_Real zcoef, /**< coefficient of z */
3565  SCIP_Real rhs, /**< right hand side */
3566  SCIP_VAR* x, /**< variable x */
3567  SCIP_VAR* z /**< variable z */
3568  )
3569 {
3570  char rowname[SCIP_MAXSTRLEN];
3571  SCIP_CONSHDLRDATA* conshdlrdata;
3572  SCIP_Real slope, tmp, val;
3573 
3574  assert(scip != NULL);
3575  assert(SCIPisLE(scip, xlb, xub));
3576  assert(!SCIPisPositive(scip, xlb+xoffset));
3577 
3578  conshdlrdata = SCIPconshdlrGetData(conshdlr);
3579  assert(conshdlrdata != NULL);
3580 
3581  /* ignore constraints with fixed x (should be removed soon) */
3582  if( SCIPisRelEQ(scip, xlb, xub) )
3583  return SCIP_OKAY;
3584 
3585  if( xlb > -xoffset )
3586  xlb = -xoffset;
3587 
3588  tmp = mypow(-xlb-xoffset, exponent);
3589  slope = SIGN(xub+xoffset) * mypow(ABS(xub+xoffset), exponent) + tmp;
3590  slope /= xub - xlb;
3591 
3592  /* check if cut would violated solution, check that slope is not above value of infinity */
3593  val = -tmp + slope * (xmult * SCIPgetSolVal(scip, sol, x) - xlb) + zcoef * SCIPgetSolVal(scip, sol, z) - rhs;
3594  if( !SCIPisFeasPositive(scip, val) || SCIPisInfinity(scip, REALABS(slope)) )
3595  {
3596  *row = NULL;
3597  return SCIP_OKAY;
3598  }
3599 
3600  (void) SCIPsnprintf(rowname, SCIP_MAXSTRLEN, "signpowsecantcut_%u", ++(conshdlrdata->nsecantcuts));
3601 
3602  SCIP_CALL( SCIPcreateEmptyRowCons(scip, row, conshdlr, rowname, -SCIPinfinity(scip), SCIPinfinity(scip),
3603  SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0 /* local */, FALSE /* modifiable */, TRUE /* removable */ ) );
3604  SCIP_CALL( SCIPaddVarToRow(scip, *row, x, xmult*slope) );
3605  SCIP_CALL( SCIPaddVarToRow(scip, *row, z, zcoef) );
3606  SCIP_CALL( SCIPchgRowRhs(scip, *row, rhs + tmp + slope*xlb) );
3607 
3608  return SCIP_OKAY;
3609 }
3610 
3611 /** computes secant underestimator for sign(x+xoffset)abs(x+xoffset)^n + c*z <= rhs
3612  *
3613  * The generated cut is slope*xmult*x + c*z <= rhs + (-xlb-xoffset)^n + slope*xlb,
3614  * where slope = (sign(xub+xoffset)*abs(xub+xoffset)^n + (-xlb-xoffset)^n) / (xub - xlb).
3615  */
3616 static
3618  SCIP* scip, /**< SCIP data structure */
3619  SCIP_ROW** row, /**< buffer to store row */
3620  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
3621  SCIP_Real xlb, /**< lower bound of x */
3622  SCIP_Real xub, /**< upper bound of x */
3623  SCIP_Real exponent, /**< exponent n in sign(x)abs(x)^n */
3624  SCIP_Real xoffset, /**< offset of x */
3625  DECL_MYPOW ((*mypow)), /**< function to use for computing power */
3626  SCIP_Real xmult, /**< multiplier for coefficient of x */
3627  SCIP_Real zcoef, /**< coefficient of z */
3628  SCIP_Real rhs, /**< right hand side */
3629  SCIP_VAR* x, /**< variable x */
3630  SCIP_VAR* z /**< variable z */
3631  )
3632 {
3633  SCIP_Real slope, tmp;
3634 
3635  assert(scip != NULL);
3636  assert(SCIPisLE(scip, xlb, xub));
3637  assert(!SCIPisPositive(scip, xlb + xoffset));
3638 
3639  /* ignore constraints with fixed x (should be removed soon) */
3640  if( SCIPisRelEQ(scip, xlb, xub) )
3641  return SCIP_OKAY;
3642 
3643  if( xlb > -xoffset )
3644  xlb = -xoffset;
3645 
3646  tmp = mypow(-xlb-xoffset, exponent);
3647  slope = SIGN(xub+xoffset) * mypow(ABS(xub+xoffset), exponent) + tmp;
3648  slope /= xub - xlb;
3649 
3650  if( SCIPisInfinity(scip, REALABS(slope)) )
3651  return SCIP_OKAY;
3652 
3653  SCIP_CALL( SCIPcreateEmptyRowCons(scip, row, conshdlr, "signpowcut", -SCIPinfinity(scip), SCIPinfinity(scip),
3654  SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0 /* local */, FALSE /* modifiable */, TRUE /* removable */ ) );
3655  SCIP_CALL( SCIPaddVarToRow(scip, *row, x, xmult*slope) );
3656  SCIP_CALL( SCIPaddVarToRow(scip, *row, z, zcoef) );
3657  SCIP_CALL( SCIPchgRowRhs(scip, *row, rhs + tmp + slope*xlb) );
3658 
3659  return SCIP_OKAY;
3660 }
3661 
3662 /** generates a cut
3663  * based on Liberti and Pantelides, Convex Envelopes of Monomials of Odd Degree, J. Global Optimization 25, 157-168, 2003, and previous publications
3664  */
3665 static
3667  SCIP* scip, /**< SCIP data structure */
3668  SCIP_CONS* cons, /**< constraint */
3669  SCIP_SOL* sol, /**< solution to separate, or NULL if LP solution should be used */
3670  SCIP_ROW** row, /**< storage for cut */
3671  SCIP_Bool onlyinbounds /**< whether linearization is allowed only in variable bounds */
3672  )
3673 {
3674  SCIP_CONSHDLRDATA* conshdlrdata;
3675  SCIP_CONSDATA* consdata;
3676  SCIP_SIDETYPE violside;
3677  SCIP_Real c;
3678  SCIP_Real xlb;
3679  SCIP_Real xglb;
3680  SCIP_Real xub;
3681  SCIP_Real xval;
3682  SCIP_Real xoffset;
3683  SCIP_Real xmult;
3684  SCIP_Real zcoef;
3685  SCIP_Real rhs;
3686 
3687  assert(scip != NULL);
3688  assert(cons != NULL);
3689  assert(row != NULL);
3690 
3691  conshdlrdata = SCIPconshdlrGetData(SCIPconsGetHdlr(cons));
3692  assert(conshdlrdata != NULL);
3693 
3694  consdata = SCIPconsGetData(cons);
3695  assert(consdata != NULL);
3696 
3697  assert(SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) || SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)));
3698 
3699  violside = SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) ? SCIP_SIDETYPE_LEFT : SCIP_SIDETYPE_RIGHT;
3700  *row = NULL;
3701 
3702  SCIPdebugMessage("generate cut for constraint <%s> with violated side %d\n", SCIPconsGetName(cons), violside);
3703  SCIPdebugPrintCons(scip, cons, NULL);
3704  SCIPdebugMessage("xlb = %g xub = %g xval = %g\n", SCIPvarGetLbLocal(consdata->x), SCIPvarGetUbLocal(consdata->x), SCIPgetSolVal(scip, sol, consdata->x));
3705 
3706  if( violside == SCIP_SIDETYPE_RIGHT )
3707  {
3708  xglb = SCIPvarGetLbGlobal(consdata->x);
3709  xlb = SCIPvarGetLbLocal(consdata->x);
3710  xub = SCIPvarGetUbLocal(consdata->x);
3711  xval = SCIPgetSolVal(scip, sol, consdata->x);
3712  xoffset = consdata->xoffset;
3713  xmult = 1.0;
3714  zcoef = consdata->zcoef;
3715  rhs = consdata->rhs;
3716  }
3717  else
3718  {
3719  xglb = -SCIPvarGetUbGlobal(consdata->x);
3720  xlb = -SCIPvarGetUbLocal(consdata->x);
3721  xub = -SCIPvarGetLbLocal(consdata->x);
3722  xval = -SCIPgetSolVal(scip, sol, consdata->x);
3723  xoffset = -consdata->xoffset;
3724  xmult = -1.0;
3725  zcoef = -consdata->zcoef;
3726  rhs = -consdata->lhs;
3727  }
3728 
3729  if( SCIPisInfinity(scip, REALABS(xval)) )
3730  {
3731  SCIPdebugMessage("skip separation since x is at infinity\n");
3732  return SCIP_OKAY;
3733  }
3734 
3735  if( !SCIPisNegative(scip, xlb+xoffset) )
3736  {
3737  /* [xlb, xub] completely in positive orthant -> function is convex on whole domain */
3738  SCIP_Bool islocal;
3739 
3740  islocal = (!SCIPconsIsGlobal(cons) || SCIPisNegative(scip, xglb+xoffset)) && SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0;
3741  if( conshdlrdata->projectrefpoint && !onlyinbounds )
3742  {
3743  SCIP_CALL( generateLinearizationCutProject(scip, row, SCIPconsGetHdlr(cons), xval, SCIPgetSolVal(scip, sol, consdata->z), -xoffset, consdata->exponent,
3744  xoffset, xmult, zcoef, rhs, consdata->x, consdata->z, islocal) );
3745  }
3746  else if( !onlyinbounds )
3747  {
3748  SCIP_CALL( generateLinearizationCut(scip, row, SCIPconsGetHdlr(cons), xval, consdata->exponent, xoffset, xmult, zcoef, rhs,
3749  consdata->x, consdata->z, islocal) );
3750  }
3751  else
3752  {
3753  SCIP_CALL( generateLinearizationCut(scip, row, SCIPconsGetHdlr(cons), 2.0*xval > xlb + xub ? xub : xlb, consdata->exponent, xoffset, xmult, zcoef, rhs,
3754  consdata->x, consdata->z, islocal) );
3755  }
3756  }
3757  else if( !SCIPisPositive(scip, xub+xoffset) )
3758  {
3759  /* [xlb, xub] completely in negative orthant -> function is concave on whole domain */
3760  if( SCIPisInfinity(scip, -xlb) )
3761  return SCIP_OKAY;
3762  SCIP_CALL( generateSecantCut(scip, row, SCIPconsGetHdlr(cons), sol, xlb, xub, consdata->exponent, xoffset, consdata->power, xmult, zcoef, rhs, consdata->x, consdata->z) );
3763  }
3764  else if( (c = - consdata->root * (xlb+xoffset) - xoffset) > xub )
3765  {
3766  /* c is right of xub -> use secant */
3767  if( SCIPisInfinity(scip, -xlb) || SCIPisInfinity(scip, xub) )
3768  return SCIP_OKAY;
3769  SCIP_CALL( generateSecantCut(scip, row, SCIPconsGetHdlr(cons), sol, xlb, xub, consdata->exponent, xoffset, consdata->power, xmult, zcoef, rhs, consdata->x, consdata->z) );
3770  }
3771  else if( xval >= c )
3772  {
3773  /* xval is right of c -> use linearization */
3774  if( conshdlrdata->projectrefpoint && !onlyinbounds )
3775  SCIP_CALL( generateLinearizationCutProject(scip, row, SCIPconsGetHdlr(cons), xval, SCIPgetSolVal(scip, sol, consdata->z), c, consdata->exponent,
3776  xoffset, xmult, zcoef, rhs, consdata->x, consdata->z, SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0) );
3777  else if( !onlyinbounds )
3778  SCIP_CALL( generateLinearizationCut(scip, row, SCIPconsGetHdlr(cons), xval, consdata->exponent, xoffset, xmult, zcoef, rhs,
3779  consdata->x, consdata->z, xval+xoffset < - consdata->root * (xglb+xoffset) && SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0) );
3780  else
3781  SCIP_CALL( generateLinearizationCut(scip, row, SCIPconsGetHdlr(cons), xub, consdata->exponent, xoffset, xmult, zcoef, rhs,
3782  consdata->x, consdata->z, xval+xoffset < - consdata->root * (xglb+xoffset) && SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0) );
3783  }
3784  else
3785  {
3786  /* xval between xlb and c -> use secant */
3787  if( SCIPisInfinity(scip, -xlb) || SCIPisInfinity(scip, c) )
3788  return SCIP_OKAY;
3789  SCIP_CALL( generateSecantCut(scip, row, SCIPconsGetHdlr(cons), sol, xlb, c, consdata->exponent, xoffset, consdata->power, xmult, zcoef, rhs, consdata->x, consdata->z) );
3790  }
3791 
3792  /* check numerics */
3793  if( *row != NULL )
3794  {
3795  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, *row, NULL) ) );
3796 
3797  /* check range of coefficients */
3798  SCIPdebugMessage(" -> found cut rhs=%f, min=%f, max=%f range=%g\n",
3799  SCIProwGetRhs(*row),
3800  SCIPgetRowMinCoef(scip, *row), SCIPgetRowMaxCoef(scip, *row),
3801  SCIPgetRowMaxCoef(scip, *row)/SCIPgetRowMinCoef(scip, *row));
3802 
3803  if( SCIPisInfinity(scip, REALABS(SCIProwGetRhs(*row))) )
3804  {
3805  SCIPdebugMessage("skip cut for constraint <%s> because of very large right hand side: %g\n", SCIPconsGetName(cons), SCIProwGetRhs(*row));
3806  SCIP_CALL( SCIPreleaseRow(scip, row) );
3807  return SCIP_OKAY;
3808  }
3809 
3810  if( SCIPgetRowMaxCoef(scip, *row) / SCIPgetRowMinCoef(scip, *row) >= conshdlrdata->cutmaxrange )
3811  {
3812  SCIPdebugMessage("skip cut for constraint <%s> because of very large range: %g\n", SCIPconsGetName(cons), SCIPgetRowMaxCoef(scip, *row)/SCIPgetRowMinCoef(scip, *row));
3813  SCIP_CALL( SCIPreleaseRow(scip, row) );
3814  return SCIP_OKAY;
3815  }
3816  }
3817 
3818  return SCIP_OKAY;
3819 }
3820 
3821 /** tries to separate solution or LP solution by a linear cut
3822  * assumes that constraint violations have been computed
3823  */
3824 static
3826  SCIP* scip, /**< SCIP data structure */
3827  SCIP_CONSHDLR* conshdlr, /**< quadratic constraints handler */
3828  SCIP_CONS** conss, /**< constraints */
3829  int nconss, /**< number of constraints */
3830  int nusefulconss, /**< number of constraints that seem to be useful */
3831  SCIP_SOL* sol, /**< solution to separate, or NULL if LP solution should be used */
3832  SCIP_Real minefficacy, /**< minimal efficacy of a cut if it should be added to the LP */
3833  SCIP_Bool inenforcement, /**< whether we are in constraint enforcement */
3834  SCIP_Bool onlyinbounds, /**< whether linearization is allowed only in variable bounds */
3835  SCIP_Bool* success, /**< result of separation: separated point (TRUE) or not (FALSE) */
3836  SCIP_Bool* cutoff, /**< whether a cutoff has been detected */
3837  SCIP_Real* bestefficacy /**< buffer to store best efficacy of a cut that was added to the LP, if found; or NULL if not of interest */
3838  )
3839 {
3840  SCIP_CONSHDLRDATA* conshdlrdata;
3841  SCIP_CONSDATA* consdata;
3842  SCIP_Real efficacy;
3843  SCIP_Real feasibility;
3844  SCIP_Real norm;
3845  SCIP_Bool convex;
3846  int c;
3847  SCIP_ROW* row;
3848 
3849  assert(scip != NULL);
3850  assert(conshdlr != NULL);
3851  assert(conss != NULL || nconss == 0);
3852  assert(success != NULL);
3853  assert(cutoff != NULL);
3854 
3855  *success = FALSE;
3856  *cutoff = FALSE;
3857 
3858  conshdlrdata = SCIPconshdlrGetData(conshdlr);
3859  assert(conshdlrdata != NULL);
3860 
3861  if( bestefficacy != NULL )
3862  *bestefficacy = 0.0;
3863 
3864  for( c = 0; c < nconss && ! (*cutoff); ++c )
3865  {
3866  assert(conss[c] != NULL); /*lint !e613*/
3867 
3868  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
3869  assert(consdata != NULL);
3870 
3871  if( SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) || SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
3872  {
3873  /* try to generate a cut */
3874  SCIP_CALL( generateCut(scip, conss[c], sol, &row, onlyinbounds) ); /*lint !e613*/
3875  if( row == NULL ) /* failed to generate cut */
3876  continue;
3877 
3878  /* check if we separate in convex area */
3879  if( SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
3880  {
3881  convex = !SCIPisInfinity(scip, -SCIPvarGetLbLocal(consdata->x))
3882  && (!SCIPisNegative(scip, SCIPvarGetLbLocal(consdata->x)+consdata->xoffset)
3883  || SCIPgetSolVal(scip, NULL, consdata->x)+consdata->xoffset >= -consdata->root*(SCIPvarGetLbLocal(consdata->x)+consdata->xoffset));
3884  }
3885  else
3886  {
3887  convex = !SCIPisInfinity(scip, SCIPvarGetUbLocal(consdata->x))
3888  && (!SCIPisPositive(scip, SCIPvarGetUbLocal(consdata->x)+consdata->xoffset)
3889  || SCIPgetSolVal(scip, NULL, consdata->x)+consdata->xoffset <= -consdata->root*(SCIPvarGetUbLocal(consdata->x)+consdata->xoffset));
3890  }
3891 
3892  feasibility = SCIPgetRowSolFeasibility(scip, row, sol);
3893 
3894  switch( conshdlrdata->scaling )
3895  {
3896  case 'o' :
3897  efficacy = -feasibility;
3898  break;
3899 
3900  case 'g' :
3901  /* in difference to SCIPgetCutEfficacy, we scale by norm only if the norm is > 1.0 this avoid finding cuts
3902  * efficient which are only very slightly violated CPLEX does not seem to scale row coefficients up too
3903  * also we use infinity norm, since that seem to be the usual scaling strategy in LP solvers (equilibrium
3904  * scaling) */
3905  norm = SCIPgetRowMaxCoef(scip, row);
3906  efficacy = -feasibility / MAX(1.0, norm);
3907  break;
3908 
3909  case 's' :
3910  {
3911  SCIP_Real abslhs = REALABS(SCIProwGetLhs(row));
3912  SCIP_Real absrhs = REALABS(SCIProwGetRhs(row));
3913  SCIP_Real minval = MIN(abslhs, absrhs);
3914 
3915  efficacy = -feasibility / MAX(1.0, minval);
3916  break;
3917  }
3918 
3919  default:
3920  SCIPerrorMessage("Unknown scaling method '%c'.", conshdlrdata->scaling);
3921  SCIPABORT();
3922  return SCIP_INVALIDDATA; /*lint !e527*/
3923  }
3924 
3925  /* if cut is strong or it's weak but we are convex and desperate (speak, in enforcement), then add,
3926  * unless it corresponds to a bound change that is too weak (<eps) to be added
3927  */
3928  if( (efficacy > minefficacy || (inenforcement && convex && (SCIPgetRelaxFeastolFactor(scip) > 0.0 ? SCIPisPositive(scip, efficacy) : SCIPisFeasPositive(scip, efficacy)))) &&
3929  SCIPisCutApplicable(scip, row) )
3930  {
3931  SCIP_Bool infeasible;
3932 
3933  SCIP_CALL( SCIPaddCut(scip, sol, row, FALSE, &infeasible) );
3934  if ( infeasible )
3935  *cutoff = TRUE;
3936  else
3937  *success = TRUE;
3938  if( bestefficacy != NULL && efficacy > *bestefficacy )
3939  *bestefficacy = efficacy;
3940 
3941  /* notify indicator constraint handler about this cut */
3942  if( conshdlrdata->conshdlrindicator != NULL && !SCIProwIsLocal(row) )
3943  {
3944  SCIP_CALL( SCIPaddRowIndicator(scip, conshdlrdata->conshdlrindicator, row) );
3945  }
3946 
3947  /* mark row as not removable from LP for current node, if in enforcement */
3948  if( inenforcement && !conshdlrdata->enfocutsremovable )
3949  SCIPmarkRowNotRemovableLocal(scip, row);
3950  }
3951 
3952  SCIP_CALL( SCIPreleaseRow (scip, &row) );
3953  }
3954 
3955  /* enforce only useful constraints
3956  * others are only checked and enforced if we are still feasible or have not found a separating cut yet
3957  */
3958  if( c >= nusefulconss && *success )
3959  break;
3960  }
3961 
3962  return SCIP_OKAY;
3963 }
3964 
3965 /** adds linearizations cuts for convex constraints w.r.t. a given reference point to cutpool and sepastore
3966  * if separatedlpsol is not NULL, then a cut that separates the LP solution is added to the sepastore and is forced to enter the LP
3967  * if separatedlpsol is not NULL, but cut does not separate the LP solution, then it is added to the cutpool only
3968  * if separatedlpsol is NULL, then cut is added to cutpool only
3969  */
3970 static
3972  SCIP* scip, /**< SCIP data structure */
3973  SCIP_CONSHDLR* conshdlr, /**< quadratic constraints handler */
3974  SCIP_CONS** conss, /**< constraints */
3975  int nconss, /**< number of constraints */
3976  SCIP_SOL* ref, /**< reference point where to linearize, or NULL for LP solution */
3977  SCIP_Bool* separatedlpsol, /**< buffer to store whether a cut that separates the current LP solution was found and added to LP, or NULL if adding to cutpool only */
3978  SCIP_Real minefficacy /**< minimal efficacy of a cut when checking for separation of LP solution */
3979  )
3980 {
3981  SCIP_CONSDATA* consdata;
3982  SCIP_Bool addedtolp;
3983  SCIP_ROW* row;
3984  int c;
3985 
3986  assert(scip != NULL);
3987  assert(conshdlr != NULL);
3988  assert(conss != NULL || nconss == 0);
3989 
3990  if( separatedlpsol != NULL )
3991  *separatedlpsol = FALSE;
3992 
3993  for( c = 0; c < nconss; ++c )
3994  {
3995  assert(conss[c] != NULL); /*lint !e613*/
3996 
3997  if( SCIPconsIsLocal(conss[c]) ) /*lint !e613*/
3998  continue;
3999 
4000  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
4001  assert(consdata != NULL);
4002 
4003  if( !SCIPisGT(scip, SCIPvarGetUbGlobal(consdata->x), -consdata->xoffset) && !SCIPisInfinity(scip, -consdata->lhs) )
4004  {
4005  /* constraint function is concave for x+offset <= 0.0, so can linearize w.r.t. lhs */
4006  consdata->lhsviol = 1.0;
4007  consdata->rhsviol = 0.0;
4008  SCIP_CALL( generateCut(scip, conss[c], ref, &row, FALSE) ); /*lint !e613*/
4009  }
4010  else if( !SCIPisLT(scip, SCIPvarGetLbGlobal(consdata->x), -consdata->xoffset) && !SCIPisInfinity(scip, -consdata->rhs) )
4011  {
4012  /* constraint function is convex for x+offset >= 0.0, so can linearize w.r.t. rhs */
4013  consdata->lhsviol = 0.0;
4014  consdata->rhsviol = 1.0;
4015  SCIP_CALL( generateCut(scip, conss[c], ref, &row, FALSE) ); /*lint !e613*/
4016  }
4017  else
4018  {
4019  /* sign not fixed or nothing to linearize */
4020  continue;
4021  }
4022 
4023  if( row == NULL )
4024  continue;
4025 
4026  addedtolp = FALSE;
4027 
4028  assert(!SCIProwIsLocal(row));
4029 
4030  /* if caller wants, then check if cut separates LP solution and add to sepastore if so */
4031  if( separatedlpsol != NULL )
4032  {
4033  SCIP_CONSHDLRDATA* conshdlrdata;
4034  SCIP_Real efficacy;
4035  SCIP_Real norm;
4036 
4037  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4038  assert(conshdlrdata != NULL);
4039 
4040  efficacy = -SCIPgetRowLPFeasibility(scip, row);
4041  switch( conshdlrdata->scaling )
4042  {
4043  case 'o' :
4044  break;
4045 
4046  case 'g' :
4047  /* in difference to SCIPgetCutEfficacy, we scale by norm only if the norm is > 1.0 this avoid finding cuts
4048  * efficient which are only very slightly violated CPLEX does not seem to scale row coefficients up too
4049  * also we use infinity norm, since that seem to be the usual scaling strategy in LP solvers (equilibrium
4050  * scaling) */
4051  norm = SCIPgetRowMaxCoef(scip, row);
4052  efficacy /= MAX(1.0, norm);
4053  break;
4054 
4055  case 's' :
4056  {
4057  SCIP_Real abslhs = REALABS(SCIProwGetLhs(row));
4058  SCIP_Real absrhs = REALABS(SCIProwGetRhs(row));
4059  SCIP_Real minval = MIN(abslhs, absrhs);
4060 
4061  efficacy /= MAX(1.0, minval);
4062  break;
4063  }
4064 
4065  default:
4066  SCIPerrorMessage("Unknown scaling method '%c'.", conshdlrdata->scaling);
4067  SCIPABORT();
4068  return SCIP_INVALIDDATA; /*lint !e527*/
4069  }
4070 
4071  if( efficacy >= minefficacy )
4072  {
4073  SCIP_Bool infeasible;
4074 
4075  *separatedlpsol = TRUE;
4076  addedtolp = TRUE;
4077  SCIP_CALL( SCIPaddCut(scip, NULL, row, TRUE, &infeasible) );
4078  assert( ! infeasible );
4079  }
4080  }
4081 
4082  if( !addedtolp )
4083  {
4084  SCIP_CALL( SCIPaddPoolCut(scip, row) );
4085  }
4086 
4087  SCIP_CALL( SCIPreleaseRow(scip, &row) );
4088  }
4089 
4090  return SCIP_OKAY;
4091 }
4092 
4093 /** processes the event that a new primal solution has been found */
4094 static
4095 SCIP_DECL_EVENTEXEC(processNewSolutionEvent)
4097  SCIP_CONSHDLRDATA* conshdlrdata;
4098  SCIP_CONSHDLR* conshdlr;
4099  SCIP_CONS** conss;
4100  int nconss;
4101  SCIP_SOL* sol;
4102 
4103  assert(scip != NULL);
4104  assert(event != NULL);
4105  assert(eventdata != NULL);
4106  assert(eventhdlr != NULL);
4107 
4108  assert((SCIPeventGetType(event) & SCIP_EVENTTYPE_SOLFOUND) != 0);
4109 
4110  conshdlr = (SCIP_CONSHDLR*)eventdata;
4111 
4112  nconss = SCIPconshdlrGetNConss(conshdlr);
4113 
4114  if( nconss == 0 )
4115  return SCIP_OKAY;
4116 
4117  sol = SCIPeventGetSol(event);
4118  assert(sol != NULL);
4119 
4120  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4121  assert(conshdlrdata != NULL);
4122 
4123  /* we are only interested in solution coming from some heuristic other than trysol, but not from the tree
4124  * the reason for ignoring trysol solutions is that they may come from an NLP solve in sepalp, where we already added linearizations,
4125  * or are from the tree, but postprocessed via proposeFeasibleSolution
4126  */
4127  if( SCIPsolGetHeur(sol) == NULL || SCIPsolGetHeur(sol) == conshdlrdata->trysolheur )
4128  return SCIP_OKAY;
4129 
4130  conss = SCIPconshdlrGetConss(conshdlr);
4131  assert(conss != NULL);
4132 
4133  SCIPdebugMessage("catched new sol event %x from heur <%s>; have %d conss\n", SCIPeventGetType(event), SCIPheurGetName(SCIPsolGetHeur(sol)), nconss);
4134 
4135  SCIP_CALL( addLinearizationCuts(scip, conshdlr, conss, nconss, sol, NULL, 0.0) );
4136 
4137  return SCIP_OKAY;
4138 }
4139 
4140 /** given a solution, try to make absolute power constraints feasible by shifting the linear variable z and pass this solution to the trysol heuristic */
4141 static
4143  SCIP* scip, /**< SCIP data structure */
4144  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
4145  SCIP_CONS** conss, /**< constraints to process */
4146  int nconss, /**< number of constraints */
4147  SCIP_SOL* sol /**< solution to process */
4148  )
4149 {
4150  SCIP_CONSDATA* consdata;
4151  SCIP_SOL* newsol;
4152  SCIP_Real xtermval;
4153  SCIP_Real zval;
4154  SCIP_Real viol;
4155  int c;
4156 
4157  assert(scip != NULL);
4158  assert(conshdlr != NULL);
4159  assert(conss != NULL || nconss == 0);
4160 
4161  if( sol != NULL )
4162  {
4163  SCIP_CALL( SCIPcreateSolCopy(scip, &newsol, sol) );
4164  }
4165  else
4166  {
4167  SCIP_CALL( SCIPcreateLPSol(scip, &newsol, NULL) );
4168  }
4169  SCIP_CALL( SCIPunlinkSol(scip, newsol) );
4170 
4171  for( c = 0; c < nconss; ++c )
4172  {
4173  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
4174  assert(consdata != NULL);
4175  assert(consdata->z != NULL);
4176  assert(consdata->zcoef != 0.0);
4177 
4178  /* recompute violation w.r.t. current solution */
4179  SCIP_CALL( computeViolation(scip, conshdlr, conss[c], newsol, &viol) ); /*lint !e613*/
4180 
4181  /* do nothing if constraint is satisfied */
4182  if( !SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) && !SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
4183  continue;
4184 
4185  /* if violation is at infinity, give up */
4186  if( SCIPisInfinity(scip, MAX(consdata->lhsviol, consdata->rhsviol)) )
4187  break;
4188 
4189  /* @todo could also adjust x while keeping z fixed */
4190 
4191  /* if variable is multiaggregated, then cannot set its solution value, so give up */
4192  if( SCIPvarGetStatus(consdata->z) == SCIP_VARSTATUS_MULTAGGR )
4193  break;
4194 
4195  /* compute value of x-term */
4196  xtermval = SCIPgetSolVal(scip, newsol, consdata->x);
4197  xtermval += consdata->xoffset;
4198  xtermval = SIGN(xtermval) * consdata->power(ABS(xtermval), consdata->exponent);
4199 
4200  /* if left hand side is violated, try to set z such that lhs is active */
4201  if( SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) )
4202  {
4203  assert(!SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip))); /* should only have one side violated (otherwise some variable is at infinity) */
4204 
4205  zval = (consdata->lhs - xtermval)/consdata->zcoef;
4206  /* bad luck: z would get value outside of its domain */
4207  if( SCIPisInfinity(scip, REALABS(zval)) || SCIPisFeasLT(scip, zval, SCIPvarGetLbGlobal(consdata->z)) || SCIPisFeasGT(scip, zval, SCIPvarGetUbGlobal(consdata->z)) )
4208  break;
4209  SCIP_CALL( SCIPsetSolVal(scip, newsol, consdata->z, zval) );
4210  }
4211 
4212  /* if right hand side is violated, try to set z such that rhs is active */
4213  if( SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
4214  {
4215  zval = (consdata->rhs - xtermval)/consdata->zcoef;
4216  /* bad luck: z would get value outside of its domain */
4217  if( SCIPisInfinity(scip, REALABS(zval)) || SCIPisFeasLT(scip, zval, SCIPvarGetLbGlobal(consdata->z)) || SCIPisFeasGT(scip, zval, SCIPvarGetUbGlobal(consdata->z)) )
4218  break;
4219  SCIP_CALL( SCIPsetSolVal(scip, newsol, consdata->z, zval) );
4220  }
4221  }
4222 
4223  /* if we have a solution that should satisfy all absolute power constraints and has a better objective than the current upper bound, then pass it to the trysol heuristic */
4224  if( c == nconss )
4225  {
4226  SCIP_CONSHDLRDATA* conshdlrdata;
4227 
4228  SCIPdebugMessage("pass solution with objective val %g to trysol heuristic\n", SCIPgetSolTransObj(scip, newsol));
4229 
4230  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4231  assert(conshdlrdata != NULL);
4232  assert(conshdlrdata->trysolheur != NULL);
4233 
4234  SCIP_CALL( SCIPheurPassSolTrySol(scip, conshdlrdata->trysolheur, newsol) );
4235  }
4236 
4237  SCIP_CALL( SCIPfreeSol(scip, &newsol) );
4238 
4239  return SCIP_OKAY;
4240 }
4241 
4242 /** create a nonlinear row representation of the constraint and stores them in consdata */
4243 static
4245  SCIP* scip, /**< SCIP data structure */
4246  SCIP_CONS* cons /**< absolute power constraint */
4247  )
4248 {
4249  SCIP_CONSDATA* consdata;
4250  SCIP_EXPRTREE* exprtree;
4251  SCIP_QUADELEM quadelem;
4252  SCIP_VAR* linvars[2];
4253  SCIP_Real lincoefs[2];
4254  SCIP_VAR* quadvar;
4255  SCIP_Real constant;
4256  SCIP_Bool expisint;
4257  int sign;
4258  int nlinvars;
4259  int nquadvars;
4260  int nquadelems;
4261  int n;
4262 
4263  assert(scip != NULL);
4264  assert(cons != NULL);
4265 
4266  consdata = SCIPconsGetData(cons);
4267  assert(consdata != NULL);
4268 
4269  if( consdata->nlrow != NULL )
4270  {
4271  SCIP_CALL( SCIPreleaseNlRow(scip, &consdata->nlrow) );
4272  }
4273 
4274  nlinvars = 0;
4275  nquadvars = 0;
4276  nquadelems = 0;
4277  exprtree = NULL;
4278  constant = 0.0;
4279 
4280  /* check if sign of x is fixed */
4281  if( !SCIPisNegative(scip, SCIPvarGetLbGlobal(consdata->x)+consdata->xoffset) )
4282  sign = 1;
4283  else if( !SCIPisPositive(scip, SCIPvarGetUbGlobal(consdata->x)+consdata->xoffset) )
4284  sign = -1;
4285  else
4286  sign = 0;
4287 
4288  /* check if exponent is integral */
4289  expisint = SCIPisIntegral(scip, consdata->exponent);
4290  n = (int)SCIPround(scip, consdata->exponent);
4291 
4292  /* create quadelem or expression tree for nonlinear part sign(x+offset)abs(x+offset)^n */
4293  if( sign != 0 || (expisint && (n % 2 == 1)) )
4294  {
4295  /* sign is fixes or exponent is odd integer */
4296  if( expisint && n == 2 )
4297  {
4298  /* sign of x is clear and exponent is 2.0 -> generate quadratic, linear, and constant term for +/- (x+offset)^n */
4299  assert(sign == -1 || sign == 1);
4300  nquadelems = 1;
4301  quadelem.idx1 = 0;
4302  quadelem.idx2 = 0;
4303  quadelem.coef = (SCIP_Real)sign;
4304  nquadvars = 1;
4305  quadvar = consdata->x;
4306 
4307  if( consdata->xoffset != 0.0 )
4308  {
4309  linvars[0] = consdata->x;
4310  lincoefs[0] = sign * 2.0 * consdata->xoffset;
4311  nlinvars = 1;
4312  constant = sign * consdata->xoffset * consdata->xoffset;
4313  }
4314  }
4315  else
4316  {
4317  /* exponent is odd or sign of x is clear, generate expression tree for +/- (+/-(x+offset))^exponent */
4318  SCIP_EXPR* expr;
4319  SCIP_EXPR* expr2;
4320 
4321  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_VARIDX, 0) ); /* x */
4322  if( consdata->xoffset != 0.0 )
4323  {
4324  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr2, SCIP_EXPR_CONST, consdata->xoffset) );
4325  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_PLUS, expr, expr2) ); /* x + offset */
4326  }
4327  if( sign == -1 && !expisint )
4328  {
4329  /* if exponent is not integer and x is negative, then negate */
4330  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr2, SCIP_EXPR_CONST, -1.0) ); /* -1 */
4331  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_MUL, expr, expr2) ); /* -(x+offset) */
4332  }
4333  /* use intpower for integer exponent and realpower for fractional exponent */
4334  if( expisint )
4335  {
4336  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_INTPOWER, expr, n) ); /* (x+offset)^n */
4337  }
4338  else
4339  {
4340  assert(sign == 1 || sign == -1);
4341  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_REALPOWER, expr, consdata->exponent) ); /* abs(x+offset)^exponent */
4342  }
4343  /* if exponent is even integer, then negate result; if it's an odd integer, then intpower already takes care of correct sign */
4344  if( sign == -1 && !(expisint && n % 2 == 1) )
4345  {
4346  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr2, SCIP_EXPR_CONST, -1.0) ); /* -1 */
4347  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_MUL, expr, expr2) ); /* -abs(x+offset)^exponent */
4348  }
4349  SCIP_CALL( SCIPexprtreeCreate(SCIPblkmem(scip), &exprtree, expr, 1, 0, NULL) );
4350  }
4351  }
4352  else
4353  {
4354  /* exponent is not odd integer and sign of x is not fixed -> generate expression tree for signpower(x+offset, n) */
4355  SCIP_EXPR* expr;
4356  SCIP_EXPR* expr2;
4357 
4358  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_VARIDX, 0) ); /* x */
4359  if( consdata->xoffset != 0.0 )
4360  {
4361  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr2, SCIP_EXPR_CONST, consdata->xoffset) );
4362  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_PLUS, expr, expr2) ); /* x + offset */
4363  }
4364  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_SIGNPOWER, expr, (SCIP_Real)consdata->exponent) ); /* signpower(x+offset, n) */
4365 
4366  SCIP_CALL( SCIPexprtreeCreate(SCIPblkmem(scip), &exprtree, expr, 1, 0, NULL) );
4367  }
4368  assert(exprtree != NULL || nquadelems > 0);
4369 
4370  /* tell expression tree, which is its variable */
4371  if( exprtree != NULL )
4372  {
4373  SCIP_CALL( SCIPexprtreeSetVars(exprtree, 1, &consdata->x) );
4374  }
4375 
4376  assert(nlinvars < 2);
4377  linvars[nlinvars] = consdata->z;
4378  lincoefs[nlinvars] = consdata->zcoef;
4379  ++nlinvars;
4380 
4381  /* create nlrow */
4382  SCIP_CALL( SCIPcreateNlRow(scip, &consdata->nlrow, SCIPconsGetName(cons), constant,
4383  nlinvars, linvars, lincoefs,
4384  nquadvars, &quadvar, nquadelems, &quadelem,
4385  exprtree, consdata->lhs, consdata->rhs
4386  ) );
4387 
4388  if( exprtree != NULL )
4389  {
4390  SCIP_CALL( SCIPexprtreeFree(&exprtree) );
4391  }
4392 
4393  return SCIP_OKAY;
4394 }
4395 
4396 /** upgrades a quadratic constraint where the quadratic part is only a single square term and the quadratic variable sign is fixed to a signpower constraint */
4397 static
4398 SCIP_DECL_QUADCONSUPGD(quadconsUpgdAbspower)
4399 { /*lint --e{715}*/
4400  SCIP_QUADVARTERM quadvarterm;
4401  SCIP_VAR* x;
4402  SCIP_VAR* z;
4403  SCIP_Real xoffset;
4404  SCIP_Real zcoef;
4405  SCIP_Real signpowcoef;
4406  SCIP_Real lhs;
4407  SCIP_Real rhs;
4408 
4409  *nupgdconss = 0;
4410 
4411  /* need at least one linear variable */
4412  if( SCIPgetNLinearVarsQuadratic(scip, cons) == 0 )
4413  return SCIP_OKAY;
4414 
4415  /* consider only quadratic constraints with a single square term */
4416  if( SCIPgetNQuadVarTermsQuadratic(scip, cons) != 1 )
4417  return SCIP_OKAY;
4418  assert(SCIPgetNBilinTermsQuadratic(scip, cons) == 0);
4419 
4420  quadvarterm = SCIPgetQuadVarTermsQuadratic(scip, cons)[0];
4421  if( SCIPisZero(scip, quadvarterm.sqrcoef) )
4422  return SCIP_OKAY;
4423 
4424  x = quadvarterm.var;
4425  xoffset = quadvarterm.lincoef / (2.0 * quadvarterm.sqrcoef);
4426 
4427  /* check that x has fixed sign */
4428  if( SCIPisNegative(scip, SCIPvarGetLbGlobal(x) + xoffset) && SCIPisPositive(scip, SCIPvarGetUbGlobal(x) + xoffset) )
4429  return SCIP_OKAY;
4430 
4431  /* check whether upgdconss array has enough space to store 1 or 2 constraints */
4432  if( SCIPgetNLinearVarsQuadratic(scip, cons) > 1 )
4433  *nupgdconss = -2;
4434  else
4435  *nupgdconss = -1;
4436  if( -*nupgdconss > upgdconsssize )
4437  return SCIP_OKAY;
4438 
4439  *nupgdconss = 0;
4440 
4441  SCIPdebugMessage("upgrade quadratic constraint <%s> to absolute power, x = [%g,%g], offset = %g\n", SCIPconsGetName(cons), SCIPvarGetLbGlobal(x), SCIPvarGetUbGlobal(x), xoffset);
4442  SCIPdebugPrintCons(scip, cons, NULL);
4443 
4444  lhs = SCIPgetLhsQuadratic(scip, cons);
4445  rhs = SCIPgetRhsQuadratic(scip, cons);
4446 
4447  /* get z and its coefficient */
4448  if( SCIPgetNLinearVarsQuadratic(scip, cons) > 1 )
4449  {
4450  /* create auxiliary variable and constraint for linear part, since we can handle only at most one variable in cons_signpower */
4451  char name[SCIP_MAXSTRLEN];
4452  SCIP_VAR* auxvar;
4453 
4454  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_linpart", SCIPconsGetName(cons));
4455  SCIP_CALL( SCIPcreateVar(scip, &auxvar, name, -SCIPinfinity(scip), SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS,
4457  SCIP_CALL( SCIPaddVar(scip, auxvar) );
4458 
4459  SCIP_CALL( SCIPcreateConsLinear(scip, &upgdconss[0], name, SCIPgetNLinearVarsQuadratic(scip, cons),
4461  SCIPisInfinity(scip, -lhs) ? -SCIPinfinity(scip) : 0.0,
4462  SCIPisInfinity(scip, rhs) ? SCIPinfinity(scip) : 0.0,
4466  SCIPconsIsStickingAtNode(cons)) );
4467  SCIP_CALL( SCIPaddCoefLinear(scip, upgdconss[*nupgdconss], auxvar, -1.0) );
4468 
4469  z = auxvar;
4470  zcoef = 1.0;
4471 
4472  ++*nupgdconss;
4473 
4474  /* compute and set value of auxvar in debug solution */
4475 #ifdef SCIP_DEBUG_SOLUTION
4476  if( SCIPdebugIsMainscip(scip) )
4477  {
4478  SCIP_Real debugval;
4479  SCIP_Real debugvarval;
4480  int i;
4481 
4482  debugval = 0.0;
4483  for( i = 0; i < SCIPgetNLinearVarsQuadratic(scip, cons); ++i )
4484  {
4485  SCIP_CALL( SCIPdebugGetSolVal(scip, SCIPgetLinearVarsQuadratic(scip, cons)[i], &debugvarval) );
4486  debugval += SCIPgetCoefsLinearVarsQuadratic(scip, cons)[i] * debugvarval;
4487  }
4488 
4489  SCIP_CALL( SCIPdebugAddSolVal(scip, auxvar, debugval) );
4490  }
4491 #endif
4492 
4493  SCIP_CALL( SCIPreleaseVar(scip, &auxvar) );
4494  }
4495  else
4496  {
4497  assert(SCIPgetNLinearVarsQuadratic(scip, cons) == 1);
4498  z = SCIPgetLinearVarsQuadratic(scip, cons)[0];
4499  zcoef = SCIPgetCoefsLinearVarsQuadratic(scip, cons)[0];
4500  }
4501 
4502  /* we now have lhs <= sqrcoef * (x + offset)^2 - sqrcoef * offset^2 + zcoef * z <= rhs */
4503 
4504  /* move sqrcoef * offset^2 into lhs and rhs */
4505  if( !SCIPisInfinity(scip, -lhs) )
4506  lhs += quadvarterm.sqrcoef * xoffset * xoffset;
4507  if( !SCIPisInfinity(scip, rhs) )
4508  rhs += quadvarterm.sqrcoef * xoffset * xoffset;
4509 
4510  /* divide by sqrcoef if x+offset > 0 and by -sqrcoef if < 0 */
4511  signpowcoef = quadvarterm.sqrcoef;
4512  if( SCIPisNegative(scip, SCIPvarGetLbGlobal(x) + xoffset) )
4513  signpowcoef = -signpowcoef;
4514  if( signpowcoef > 0.0 )
4515  {
4516  if( !SCIPisInfinity(scip, -lhs) )
4517  lhs /= signpowcoef;
4518  if( !SCIPisInfinity(scip, rhs) )
4519  rhs /= signpowcoef;
4520  }
4521  else
4522  {
4523  SCIP_Real newrhs;
4524 
4525  if( !SCIPisInfinity(scip, -lhs) )
4526  newrhs = lhs / signpowcoef;
4527  else
4528  newrhs = SCIPinfinity(scip);
4529  if( !SCIPisInfinity(scip, rhs) )
4530  lhs = rhs / signpowcoef;
4531  else
4532  lhs = -SCIPinfinity(scip);
4533  rhs = newrhs;
4534  }
4535  zcoef /= signpowcoef;
4536 
4537  /* create the absolute power constraint */
4538  SCIP_CALL( SCIPcreateConsAbspower(scip, &upgdconss[*nupgdconss], SCIPconsGetName(cons), x, z, 2.0,
4539  xoffset, zcoef, lhs, rhs,
4543  SCIPconsIsStickingAtNode(cons)) );
4544  SCIPdebugPrintCons(scip, upgdconss[*nupgdconss], NULL);
4545  ++*nupgdconss;
4546 
4547  return SCIP_OKAY;
4548 }
4549 
4550 /** tries to upgrade a nonlinear constraint into a absolute power constraint */
4551 static
4552 SCIP_DECL_NONLINCONSUPGD(nonlinconsUpgdAbspower)
4554  SCIP_EXPRGRAPH* exprgraph;
4555  SCIP_EXPRGRAPHNODE* node;
4556  SCIP_EXPRGRAPHNODE* child;
4557  SCIP_Real exponent;
4558  SCIP_VAR* x;
4559  SCIP_VAR* z;
4560  SCIP_Real signpowcoef;
4561  SCIP_Real zcoef;
4562  SCIP_Real xoffset;
4563  SCIP_Real constant;
4564  SCIP_Real lhs;
4565  SCIP_Real rhs;
4566 
4567  assert(nupgdconss != NULL);
4568  assert(upgdconss != NULL);
4569 
4570  *nupgdconss = 0;
4571 
4572  /* absolute power needs at least one linear variable (constraint is trivial, otherwise) */
4573  if( SCIPgetNLinearVarsNonlinear(scip, cons) == 0 )
4574  return SCIP_OKAY;
4575 
4576  node = SCIPgetExprgraphNodeNonlinear(scip, cons);
4577 
4578  /* no interest in linear constraints */
4579  if( node == NULL )
4580  return SCIP_OKAY;
4581 
4582  /* need exactly one argument */
4583  if( SCIPexprgraphGetNodeNChildren(node) != 1 )
4584  return SCIP_OKAY;
4585 
4586  constant = 0.0;
4587  signpowcoef = 1.0; /* coefficient of sign(x)abs(x)^n term, to be reformulated away... */
4588 
4589  child = SCIPexprgraphGetNodeChildren(node)[0];
4590 
4591  /* check if node expression fits to absolute power constraint */
4592  switch( SCIPexprgraphGetNodeOperator(node) )
4593  {
4594  case SCIP_EXPR_REALPOWER:
4595  /* realpower with exponent > 1.0 can always be signpower, since it assumes that argument is >= 0.0 */
4596  exponent = SCIPexprgraphGetNodeRealPowerExponent(node);
4597  if( exponent <= 1.0 )
4598  return SCIP_OKAY;
4599 
4600  assert(SCIPexprgraphGetNodeBounds(child).inf >= 0.0);
4601  break;
4602 
4603  case SCIP_EXPR_INTPOWER:
4604  {
4605  /* check if exponent > 1.0 and either odd or even with child having fixed sign */
4606  SCIP_INTERVAL childbounds;
4607 
4609  if( exponent <= 1.0 )
4610  return SCIP_OKAY;
4611 
4612  childbounds = SCIPexprgraphGetNodeBounds(child);
4613  if( (int)exponent % 2 == 0 && childbounds.inf < 0.0 && childbounds.sup > 0.0 )
4614  return SCIP_OKAY;
4615 
4616  /* use x^exponent = -sign(x) |x|^exponent if exponent is even and x always negative */
4617  if( (int)exponent % 2 == 0 && childbounds.inf < 0.0 )
4618  signpowcoef = -1.0;
4619 
4620  break;
4621  }
4622 
4623  case SCIP_EXPR_SQUARE:
4624  {
4625  /* check if child has fixed sign */
4626  SCIP_INTERVAL childbounds;
4627 
4628  childbounds = SCIPexprgraphGetNodeBounds(child);
4629  if( childbounds.inf < 0.0 && childbounds.sup > 0.0 )
4630  return SCIP_OKAY;
4631 
4632  /* use x^2 = -sign(x) |x|^2 if x is always negative */
4633  if( childbounds.inf < 0.0 )
4634  signpowcoef = -1.0;
4635 
4636  exponent = 2.0;
4637  break;
4638  }
4639 
4640  case SCIP_EXPR_SIGNPOWER:
4641  /* check if exponent > 1.0 */
4642  exponent = SCIPexprgraphGetNodeSignPowerExponent(node);
4643  if( exponent <= 1.0 )
4644  return SCIP_OKAY;
4645  break;
4646 
4647  case SCIP_EXPR_POLYNOMIAL:
4648  {
4649  SCIP_EXPRDATA_MONOMIAL* monomial;
4650  SCIP_INTERVAL childbounds;
4651 
4652  /* check if only one univariate monomial with exponent > 1.0 */
4653 
4654  /* if sum of univariate monomials, then this should have been taken care of by exprgraphnodeReformSignpower */
4656  return SCIP_OKAY;
4657  assert(SCIPexprgraphGetNodePolynomialNMonomials(node) == 1); /* assume simplified, i.e., no constant polynomial */
4658 
4659  monomial = SCIPexprgraphGetNodePolynomialMonomials(node)[0];
4660  assert(SCIPexprGetMonomialNFactors(monomial) == 1); /* since we have only one children and assume simplified */
4661 
4662  exponent = SCIPexprGetMonomialExponents(monomial)[0];
4663  if( exponent <= 1.0 )
4664  return SCIP_OKAY;
4665 
4666  /* if exponent is even integer and child has mixed sign, then cannot do
4667  * if exponent is even integer and child is always negative, then can do via multiplication by -1.0 */
4668  childbounds = SCIPexprgraphGetNodeBounds(child);
4669  if( SCIPisIntegral(scip, exponent) && ((int)SCIPround(scip, exponent) % 2 == 0) && childbounds.inf < 0.0 )
4670  {
4671  if( childbounds.sup > 0.0 )
4672  return SCIP_OKAY;
4673  signpowcoef = -1.0;
4674  }
4675 
4676  constant = SCIPexprgraphGetNodePolynomialConstant(node);
4677  signpowcoef *= SCIPexprGetMonomialCoef(monomial);
4678 
4679  break;
4680  }
4681 
4682  default:
4683  return SCIP_OKAY;
4684  } /*lint !e788*/
4685  assert(SCIPexprgraphGetNodeNChildren(node) == 1);
4686 
4687  /* check magnitue of coefficient of z in signpower constraint */
4688  zcoef = 1.0;
4689  if( SCIPgetNLinearVarsNonlinear(scip, cons) == 1 )
4690  zcoef = SCIPgetLinearCoefsNonlinear(scip, cons)[0];
4691  zcoef /= signpowcoef;
4693  {
4694  zcoef /= pow(REALABS(SCIPexprgraphGetNodeLinearCoefs(child)[0]), exponent);
4695  }
4696  if( SCIPisZero(scip, zcoef) )
4697  {
4698  SCIPdebugMessage("skip upgrade to signpower since |zcoef| = %g would be zero\n", zcoef);
4699  return SCIP_OKAY;
4700  }
4701 
4702  /* count how many constraints we need to add (use negative numbers, for convenience):
4703  * one constraint for absolute power,
4704  * plus one if we need to replace the linear part by single variable,
4705  * plus one if we need to replace the argument of absolute power by a single variable
4706  */
4707  *nupgdconss = -1;
4708 
4710  {
4711  /* if node has known curvature and we would add auxiliary var for child, then don't upgrade
4712  * it's not really necessary, but may introduce more numerical troubles
4713  * @todo maybe still do if child is linear?
4714  */
4716  {
4717  *nupgdconss = 0;
4718  return SCIP_OKAY;
4719  }
4720 
4721  --*nupgdconss;
4722  }
4723 
4724  if( SCIPgetNLinearVarsNonlinear(scip, cons) > 1 )
4725  --*nupgdconss;
4726 
4727  /* request larger upgdconss array */
4728  if( upgdconsssize < -*nupgdconss )
4729  return SCIP_OKAY;
4730 
4731  SCIPdebugMessage("upgrading constraint <%s>\n", SCIPconsGetName(cons));
4732 
4733  /* start counting at zero again */
4734  *nupgdconss = 0;
4735 
4736  exprgraph = SCIPgetExprgraphNonlinear(scip, SCIPconsGetHdlr(cons));
4737 
4738  lhs = SCIPgetLhsNonlinear(scip, cons);
4739  rhs = SCIPgetRhsNonlinear(scip, cons);
4740 
4741  /* get x and it's offset */
4743  {
4744  x = (SCIP_VAR*)SCIPexprgraphGetNodeVar(exprgraph, child);
4745  xoffset = 0.0;
4746  }
4748  {
4749  SCIP_Real xcoef;
4750 
4752  xcoef = SCIPexprgraphGetNodeLinearCoefs(child)[0];
4753  assert(!SCIPisZero(scip, xcoef));
4754 
4755  signpowcoef *= (xcoef < 0.0 ? -1.0 : 1.0) * pow(REALABS(xcoef), exponent);
4756  xoffset = SCIPexprgraphGetNodeLinearConstant(child) / xcoef;
4757  }
4758  else
4759  {
4760  /* reformulate by adding auxiliary variable and constraint for child */
4761  char name[SCIP_MAXSTRLEN];
4762  SCIP_INTERVAL bounds;
4763  SCIP_VAR* auxvar;
4764  SCIP_Real minusone;
4765 
4766  bounds = SCIPexprgraphGetNodeBounds(child);
4767  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_powerarg", SCIPconsGetName(cons));
4768 
4769  SCIPdebugMessage("add auxiliary variable and constraint %s for node %p(%d,%d)\n", name, (void*)child, SCIPexprgraphGetNodeDepth(child), SCIPexprgraphGetNodePosition(child));
4770 
4771  SCIP_CALL( SCIPcreateVar(scip, &auxvar, name, SCIPintervalGetInf(bounds), SCIPintervalGetSup(bounds), 0.0,
4773  SCIP_CALL( SCIPaddVar(scip, auxvar) );
4774 
4775  /* create new constraint child == auxvar
4776  * since signpower is monotonic, we need only child <= auxvar or child >= auxvar, if not both sides are finite, and depending on signpowcoef
4777  * i.e., we need child - auxvar <= 0.0 if rhs is finite and signpowcoef > 0.0 or lhs is finite and signpowcoef < 0.0
4778  * and we need 0.0 <= child - auxvar if lhs is finite and signpowcoef > 0.0 or rhs is finite and signpowcoef < 0.0
4779  */
4780  minusone = -1.0;
4781  assert(upgdconsssize > *nupgdconss);
4782  SCIP_CALL( SCIPcreateConsNonlinear2(scip, &upgdconss[*nupgdconss], name, 1, &auxvar, &minusone, child,
4783  ((signpowcoef > 0.0 && !SCIPisInfinity(scip, -lhs)) || (signpowcoef < 0.0 && !SCIPisInfinity(scip, rhs))) ? 0.0 : -SCIPinfinity(scip),
4784  ((signpowcoef > 0.0 && !SCIPisInfinity(scip, rhs)) || (signpowcoef < 0.0 && !SCIPisInfinity(scip, -lhs))) ? 0.0 : SCIPinfinity(scip),
4785  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
4786  ++*nupgdconss;
4787 
4788  /* use auxvar to setup absolute power constraint */
4789  x = auxvar;
4790  xoffset = 0.0;
4791 
4792  /* compute and set value of auxvar in debug solution, if debugging is enabled */
4793  SCIP_CALL( SCIPdebugAddSolVal(scip, auxvar, SCIPexprgraphGetNodeVal(child)) ); /*lint !e506 !e774*/
4794 
4795  SCIP_CALL( SCIPreleaseVar(scip, &auxvar) );
4796  }
4797 
4798  /* get z and its coefficient */
4799  if( SCIPgetNLinearVarsNonlinear(scip, cons) > 1 )
4800  {
4801  /* create auxiliary variable and constraint for linear part, since we can handle only at most one variable in cons_signpower */
4802  char name[SCIP_MAXSTRLEN];
4803  SCIP_VAR* auxvar;
4804 
4805  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_linpart", SCIPconsGetName(cons));
4806  SCIP_CALL( SCIPcreateVar(scip, &auxvar, name, -SCIPinfinity(scip), SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS,
4808  SCIP_CALL( SCIPaddVar(scip, auxvar) );
4809 
4810  assert(upgdconsssize > *nupgdconss);
4811  SCIP_CALL( SCIPcreateConsLinear(scip, &upgdconss[*nupgdconss], name, SCIPgetNLinearVarsNonlinear(scip, cons),
4813  SCIPisInfinity(scip, -lhs) ? -SCIPinfinity(scip) : 0.0,
4814  SCIPisInfinity(scip, rhs) ? SCIPinfinity(scip) : 0.0,
4818  SCIPconsIsStickingAtNode(cons)) );
4819  SCIP_CALL( SCIPaddCoefLinear(scip, upgdconss[*nupgdconss], auxvar, -1.0) );
4820 
4821  z = auxvar;
4822  zcoef = 1.0;
4823 
4824  ++*nupgdconss;
4825 
4826  /* compute and set value of auxvar in debug solution */
4827 #ifdef SCIP_DEBUG_SOLUTION
4828  if( SCIPdebugIsMainscip(scip) )
4829  {
4830  SCIP_Real debugval;
4831  SCIP_Real debugvarval;
4832  int i;
4833 
4834  debugval = 0.0;
4835  for( i = 0; i < SCIPgetNLinearVarsNonlinear(scip, cons); ++i )
4836  {
4837  SCIP_CALL( SCIPdebugGetSolVal(scip, SCIPgetLinearVarsNonlinear(scip, cons)[i], &debugvarval) );
4838  debugval += SCIPgetLinearCoefsNonlinear(scip, cons)[i] * debugvarval;
4839  }
4840 
4841  SCIP_CALL( SCIPdebugAddSolVal(scip, auxvar, debugval) );
4842  }
4843 #endif
4844 
4845  SCIP_CALL( SCIPreleaseVar(scip, &auxvar) );
4846  }
4847  else
4848  {
4849  assert(SCIPgetNLinearVarsNonlinear(scip, cons) == 1);
4850  z = SCIPgetLinearVarsNonlinear(scip, cons)[0];
4851  zcoef = SCIPgetLinearCoefsNonlinear(scip, cons)[0];
4852  }
4853 
4854  if( constant != 0.0 )
4855  {
4856  if( !SCIPisInfinity(scip, -lhs) )
4857  lhs -= constant;
4858  if( !SCIPisInfinity(scip, rhs) )
4859  rhs -= constant;
4860  }
4861 
4862  /* divide absolute power constraint by signpowcoef */
4863  if( signpowcoef != 1.0 )
4864  {
4865  zcoef /= signpowcoef;
4866  if( signpowcoef < 0.0 )
4867  {
4868  SCIP_Real newrhs;
4869 
4870  newrhs = SCIPisInfinity(scip, -lhs) ? SCIPinfinity(scip) : lhs/signpowcoef;
4871  lhs = SCIPisInfinity(scip, rhs) ? -SCIPinfinity(scip) : rhs/signpowcoef;
4872  rhs = newrhs;
4873  }
4874  else
4875  {
4876  if( !SCIPisInfinity(scip, -lhs) )
4877  lhs /= signpowcoef;
4878  if( !SCIPisInfinity(scip, rhs) )
4879  rhs /= signpowcoef;
4880  }
4881  }
4882 
4883  /* finally setup a absolute power constraint */
4884 
4885  assert(*nupgdconss < upgdconsssize);
4886  SCIP_CALL( SCIPcreateConsAbspower(scip, &upgdconss[*nupgdconss], SCIPconsGetName(cons),
4887  x, z, exponent, xoffset, zcoef, lhs, rhs,
4891  SCIPconsIsStickingAtNode(cons)) );
4892  ++*nupgdconss;
4893 
4894  return SCIP_OKAY;
4895 }
4896 
4897 /** tries to reformulate a expression graph node via introducing a absolute power constraint
4898  * if node fits to absolute power and has indefinte curvature and has no nonlinear parents and has siblings, then replace by auxvar and absolute power constraint
4899  * if it still has nonlinear parents, then we wait to see if reformulation code move node into auxiliary constraint,
4900  * so we do not add unnessary auxiliary variables for something like an x^2 in an exp(x^2)
4901  * if it has no siblings, then we let the upgrading for nonlinear constraints take care of it,
4902  * since it may be able to upgrade the constraint as a whole and can take the constraint sides into account too (may need only <=/>= auxcons)
4903  */
4904 static
4905 SCIP_DECL_EXPRGRAPHNODEREFORM(exprgraphnodeReformAbspower)
4907  SCIP_EXPRGRAPHNODE* child;
4908  char name[SCIP_MAXSTRLEN];
4909  SCIP_CONS* cons;
4910  SCIP_Real exponent;
4911  SCIP_VAR* x;
4912  SCIP_VAR* z;
4913  SCIP_Real signpowcoef;
4914  SCIP_Real xoffset;
4915  SCIP_Real constant;
4916 
4917  assert(scip != NULL);
4918  assert(exprgraph != NULL);
4919  assert(node != NULL);
4920  assert(naddcons != NULL);
4921  assert(reformnode != NULL);
4922 
4923  *reformnode = NULL;
4924 
4926  return SCIP_OKAY;
4927 
4928  constant = 0.0;
4929  signpowcoef = 1.0; /* coefficient of sign(x)abs(x)^n term, to be move in from of z... */
4930 
4931  /* check if node expression fits to absolute power constraint */
4932  switch( SCIPexprgraphGetNodeOperator(node) )
4933  {
4934  case SCIP_EXPR_REALPOWER:
4935  /* realpower with exponent > 1.0 can always be absolute power, since it assumes that argument is >= 0.0
4936  * @todo we should also ensure that argument is >= 0.0
4937  */
4938  exponent = SCIPexprgraphGetNodeRealPowerExponent(node);
4939  if( exponent <= 1.0 )
4940  return SCIP_OKAY;
4941 
4942  assert(SCIPexprgraphGetNodeBounds(SCIPexprgraphGetNodeChildren(node)[0]).inf >= 0.0);
4943  break;
4944 
4945  case SCIP_EXPR_INTPOWER:
4946  {
4947  /* check if exponent > 1.0 and either odd or even with child having fixed sign */
4948  SCIP_INTERVAL childbounds;
4949 
4951  if( exponent <= 1.0 )
4952  return SCIP_OKAY;
4953 
4955  if( (int)exponent % 2 == 0 && childbounds.inf < 0.0 && childbounds.sup > 0.0 )
4956  return SCIP_OKAY;
4957 
4958  /* use x^exponent = -sign(x) |x|^exponent if exponent is even and x always negative */
4959  if( (int)exponent % 2 == 0 && childbounds.inf < 0.0 )
4960  signpowcoef = -1.0;
4961 
4962  break;
4963  }
4964 
4965  case SCIP_EXPR_SQUARE:
4966  {
4967  /* check if child has fixed sign */
4968  SCIP_INTERVAL childbounds;
4969 
4971  if( childbounds.inf < 0.0 && childbounds.sup > 0.0 )
4972  return SCIP_OKAY;
4973 
4974  /* use x^2 = -sign(x) |x|^2 if x is always negative */
4975  if( childbounds.inf < 0.0 )
4976  signpowcoef = -1.0;
4977 
4978  exponent = 2.0;
4979  break;
4980  }
4981 
4982  case SCIP_EXPR_SIGNPOWER:
4983  /* check if exponent > 1.0 */
4984  exponent = SCIPexprgraphGetNodeSignPowerExponent(node);
4985  if( exponent <= 1.0 )
4986  return SCIP_OKAY;
4987  break;
4988 
4989  case SCIP_EXPR_POLYNOMIAL:
4990  {
4991  SCIP_EXPRDATA_MONOMIAL* monomial;
4992  SCIP_INTERVAL childbounds;
4993 
4994  /* check if only one univariate monomial with exponent > 1.0 */
4995  if( SCIPexprgraphGetNodeNChildren(node) > 1 )
4996  return SCIP_OKAY;
4997  assert(SCIPexprgraphGetNodeNChildren(node) == 1);
4998 
5000  return SCIP_OKAY;
5001  assert(SCIPexprgraphGetNodePolynomialNMonomials(node) == 1); /* assume simplified, i.e., no constant polynomial */
5002 
5003  monomial = SCIPexprgraphGetNodePolynomialMonomials(node)[0];
5004  assert(SCIPexprGetMonomialNFactors(monomial) == 1); /* since we have only one children and assume simplified */
5005 
5006  exponent = SCIPexprGetMonomialExponents(monomial)[0];
5007  if( exponent <= 1.0 )
5008  return SCIP_OKAY;
5009 
5010  /* if exponent is even integer and child has mixed sign, then cannot do
5011  * if exponent is even integer and child is always negative, then can do via multiplication by -1.0 */
5013  if( SCIPisIntegral(scip, exponent) && ((int)SCIPround(scip, exponent) % 2 == 0) && childbounds.inf < 0.0 )
5014  {
5015  if( childbounds.sup > 0.0 )
5016  return SCIP_OKAY;
5017  signpowcoef = -1.0;
5018  }
5019 
5020  constant = SCIPexprgraphGetNodePolynomialConstant(node);
5021  signpowcoef *= SCIPexprGetMonomialCoef(monomial);
5022 
5023  break;
5024  }
5025 
5026  default:
5027  return SCIP_OKAY;
5028  } /*lint !e788*/
5029  assert(SCIPexprgraphGetNodeNChildren(node) == 1);
5030 
5032  return SCIP_OKAY;
5033  if( !SCIPexprgraphHasNodeSibling(node) )
5034  return SCIP_OKAY;
5035 
5036  SCIPdebugMessage("reformulate node %p via signpower\n", (void*)node);
5037 
5038  /* get x and its offset */
5039  child = SCIPexprgraphGetNodeChildren(node)[0];
5041  {
5042  x = (SCIP_VAR*)SCIPexprgraphGetNodeVar(exprgraph, child);
5043  xoffset = 0.0;
5044  }
5046  {
5047  SCIP_Real xcoef;
5048 
5050  xcoef = SCIPexprgraphGetNodeLinearCoefs(child)[0];
5051  assert(!SCIPisZero(scip, xcoef));
5052 
5053  signpowcoef *= (xcoef < 0.0 ? -1.0 : 1.0) * pow(REALABS(xcoef), exponent);
5054  xoffset = SCIPexprgraphGetNodeLinearConstant(child) / xcoef;
5055  }
5056  else
5057  {
5058  /* reformulate by adding auxiliary variable and constraint for child */
5059  SCIP_INTERVAL bounds;
5060  SCIP_VAR* auxvar;
5061  SCIP_Real minusone;
5062 
5063  bounds = SCIPexprgraphGetNodeBounds(child);
5064  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "nlreform%dsp", *naddcons);
5065 
5066  SCIPdebugMessage("add auxiliary variable and constraint %s for node %p(%d,%d)\n", name, (void*)child, SCIPexprgraphGetNodeDepth(child), SCIPexprgraphGetNodePosition(child));
5067 
5068  SCIP_CALL( SCIPcreateVar(scip, &auxvar, name, SCIPintervalGetInf(bounds), SCIPintervalGetSup(bounds), 0.0, SCIP_VARTYPE_CONTINUOUS,
5069  TRUE, TRUE, NULL, NULL, NULL, NULL, NULL) );
5070  SCIP_CALL( SCIPaddVar(scip, auxvar) );
5071 
5072  /* create new constraint child == auxvar */
5073  minusone = -1.0;
5074  SCIP_CALL( SCIPcreateConsNonlinear2(scip, &cons, name, 1, &auxvar, &minusone, child, 0.0, 0.0,
5075  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
5076  SCIP_CALL( SCIPaddCons(scip, cons) );
5077  ++*naddcons;
5078 
5079  /* use auxvar to setup signpower constraint */
5080  x = auxvar;
5081  xoffset = 0.0;
5082 
5083  SCIP_CALL( SCIPdebugAddSolVal(scip, auxvar, SCIPexprgraphGetNodeVal(child)) ); /*lint !e506 !e774*/
5084 
5085  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
5086  SCIP_CALL( SCIPreleaseVar(scip, &auxvar) );
5087  }
5088 
5089  /* create auxiliary variable z and add to expression graph */
5090  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "nlreform%dsp", *naddcons);
5091  SCIP_CALL( SCIPcreateVar(scip, &z, name, -SCIPinfinity(scip), SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS,
5092  TRUE, TRUE, NULL, NULL, NULL, NULL, NULL) );
5093  SCIP_CALL( SCIPaddVar(scip, z) );
5094  SCIP_CALL( SCIPexprgraphAddVars(exprgraph, 1, (void**)&z, reformnode) );
5095 
5096  /* setup a absolute power constraint */
5097  if( REALABS(signpowcoef) * SCIPfeastol(scip) < 1.0 )
5098  {
5099  /* if signpowcoef is not huge (<10^6), then put it into absolute power constraint */
5100  SCIP_CALL( SCIPcreateConsAbspower(scip, &cons, name,
5101  x, z, exponent, xoffset, -1.0/signpowcoef, -constant/signpowcoef, -constant/signpowcoef,
5102  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
5103  SCIP_CALL( SCIPaddCons(scip, cons) );
5104  SCIPdebugPrintCons(scip, cons, NULL);
5105  ++*naddcons;
5106 
5107  /* compute value of z and reformnode and set in debug solution and expression graph, resp. */
5108 #ifdef SCIP_DEBUG_SOLUTION
5109  if( SCIPdebugIsMainscip(scip) )
5110  {
5111  SCIP_Real xval;
5112  SCIP_Real zval;
5113 
5114  SCIP_CALL( SCIPdebugGetSolVal(scip, x, &xval) );
5115  zval = signpowcoef * SIGN(xval + xoffset) * pow(REALABS(xval + xoffset), exponent) + constant;
5116 
5117  SCIP_CALL( SCIPdebugAddSolVal(scip, z, zval) );
5118  SCIPexprgraphSetVarNodeValue(*reformnode, zval);
5119  }
5120 #endif
5121  }
5122  else
5123  {
5124  /* if signpowcoef is huge, then avoid very small coefficient of z
5125  * instead create additional node on top of current reformnode */
5126  SCIP_EXPRGRAPHNODE* linnode;
5127 
5128  SCIP_CALL( SCIPcreateConsAbspower(scip, &cons, name,
5129  x, z, exponent, xoffset, -1.0, 0.0, 0.0,
5130  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
5131  SCIP_CALL( SCIPaddCons(scip, cons) );
5132  SCIPdebugPrintCons(scip, cons, NULL);
5133  ++*naddcons;
5134 
5135  /* compute value of z and reformnode and set in debug solution and expression graph, resp. */
5136 #ifdef SCIP_DEBUG_SOLUTION
5137  if( SCIPdebugIsMainscip(scip) )
5138  {
5139  SCIP_Real xval;
5140  SCIP_Real zval;
5141 
5142  SCIP_CALL( SCIPdebugGetSolVal(scip, x, &xval) );
5143  zval = SIGN(xval + xoffset) * pow(REALABS(xval + xoffset), exponent);
5144 
5145  SCIP_CALL( SCIPdebugAddSolVal(scip, z, zval) );
5146  SCIPexprgraphSetVarNodeValue(*reformnode, zval);
5147  }
5148 #endif
5149 
5150  SCIP_CALL( SCIPexprgraphCreateNodeLinear(SCIPblkmem(scip), &linnode, 1, &signpowcoef, constant) );
5151  SCIP_CALL( SCIPexprgraphAddNode(exprgraph, linnode, -1, 1, reformnode) );
5152 
5153  *reformnode = linnode;
5154  }
5155 
5156  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
5157  SCIP_CALL( SCIPreleaseVar(scip, &z) );
5158 
5159  return SCIP_OKAY;
5160 }
5161 
5162 /*
5163  * Callback methods of constraint handler
5164  */
5165 
5166 /** copy method for constraint handler plugins (called when SCIP copies plugins) */
5167 static
5168 SCIP_DECL_CONSHDLRCOPY(conshdlrCopyAbspower)
5169 { /*lint --e{715}*/
5170  assert(scip != NULL);
5171  assert(conshdlr != NULL);
5172  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
5173 
5174  /* call inclusion method of constraint handler */
5176 
5177  *valid = TRUE;
5178 
5179  return SCIP_OKAY;
5180 }
5181 
5182 /** destructor of constraint handler to free constraint handler data (called when SCIP is exiting) */
5183 static
5184 SCIP_DECL_CONSFREE(consFreeAbspower)
5185 { /*lint --e{715}*/
5186  SCIP_CONSHDLRDATA* conshdlrdata;
5187 
5188  assert(scip != NULL);
5189  assert(conshdlr != NULL);
5190 
5191  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5192  assert(conshdlrdata != NULL);
5193 
5194  SCIPfreeMemory(scip, &conshdlrdata);
5195 
5196  return SCIP_OKAY;
5197 }
5198 
5199 /** initialization method of constraint handler (called after problem was transformed) */
5200 static
5201 SCIP_DECL_CONSINIT(consInitAbspower)
5202 { /*lint --e{715}*/
5203  SCIP_CONSHDLRDATA* conshdlrdata;
5204 
5205  assert(scip != NULL);
5206  assert(conshdlr != NULL);
5207 
5208  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5209  assert(conshdlrdata != NULL);
5210 
5211  conshdlrdata->subnlpheur = SCIPfindHeur(scip, "subnlp");
5212  conshdlrdata->trysolheur = SCIPfindHeur(scip, "trysol");
5213  conshdlrdata->conshdlrindicator = SCIPfindConshdlr(scip, "indicator");
5214  conshdlrdata->nsecantcuts = 0;
5215  conshdlrdata->ncuts = 0;
5216 
5217  return SCIP_OKAY;
5218 }
5219 
5220 /** deinitialization method of constraint handler (called before transformed problem is freed) */
5221 static
5222 SCIP_DECL_CONSEXIT(consExitAbspower)
5223 { /*lint --e{715}*/
5224  SCIP_CONSHDLRDATA* conshdlrdata;
5225 
5226  assert(scip != NULL);
5227  assert(conshdlr != NULL);
5228 
5229  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5230  assert(conshdlrdata != NULL);
5231 
5232  conshdlrdata->subnlpheur = NULL;
5233  conshdlrdata->trysolheur = NULL;
5234  conshdlrdata->conshdlrindicator = NULL;
5235 
5236  return SCIP_OKAY;
5237 }
5238 
5239 /** presolving initialization method of constraint handler (called when presolving is about to begin) */
5240 static
5241 SCIP_DECL_CONSINITPRE(consInitpreAbspower)
5242 { /*lint --e{715}*/
5243  SCIP_CONSHDLRDATA* conshdlrdata;
5244 
5245  assert(conshdlr != NULL);
5246 
5247  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5248  assert(conshdlrdata != NULL);
5249 
5250  /* initialize comparedpairwise flag to TRUE, if at most one constraint, otherwise 0 */
5251  conshdlrdata->comparedpairwise = (nconss <= 1);
5252 
5253  return SCIP_OKAY;
5254 }
5255 
5256 /** presolving deinitialization method of constraint handler (called after presolving has been finished) */
5257 static
5258 SCIP_DECL_CONSEXITPRE(consExitpreAbspower)
5259 { /*lint --e{715}*/
5260  int c;
5261 
5262  assert(scip != NULL);
5263  assert(conss != NULL || nconss == 0);
5264 
5265  /* tell SCIP that we have something nonlinear, and whether we are nonlinear in a continuous variable */
5266  for( c = 0; c < nconss; ++c )
5267  {
5268  assert(conss[c] != NULL); /*lint !e613*/
5269 
5270  if( SCIPconsIsAdded(conss[c]) ) /*lint !e613*/
5271  {
5272  SCIPenableNLP(scip);
5273  break;
5274  }
5275  }
5276 
5277  return SCIP_OKAY;
5278 }
5279 
5280 /** solving process initialization method of constraint handler (called when branch and bound process is about to begin) */
5281 static
5282 SCIP_DECL_CONSINITSOL(consInitsolAbspower)
5283 { /*lint --e{715}*/
5284  SCIP_CONSHDLRDATA* conshdlrdata;
5285  SCIP_CONSDATA* consdata;
5286  int c;
5287 
5288  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5289  assert(conshdlrdata != NULL);
5290 
5291  assert(scip != NULL);
5292  assert(conss != NULL || nconss == 0);
5293 
5294  for( c = 0; c < nconss; ++c )
5295  {
5296  assert(conss[c] != NULL); /*lint !e613*/
5297 
5298  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
5299  assert(consdata != NULL);
5300 
5301  assert(consdata->exponent > 1.0);
5302 
5303  /* setup root that corresponds to exponent */
5304  if( SCIPisIntegral(scip, consdata->exponent) && consdata->exponent-0.5 < ROOTS_KNOWN )
5305  {
5306  consdata->root = roots[(int)SCIPfloor(scip, consdata->exponent+0.5)];
5307  }
5308  else if( SCIPisEQ(scip, consdata->exponent, 1.852) )
5309  {
5310  consdata->root = 0.398217;
5311  }
5312  else
5313  {
5314  SCIP_Real root;
5315  SCIP_Real polyval;
5316  SCIP_Real gradval;
5317  int iter;
5318 
5319  /* search for a positive root of (n-1) y^n + n y^(n-1) - 1
5320  * use the closest precomputed root as starting value */
5321  if( consdata->exponent >= ROOTS_KNOWN )
5322  root = roots[ROOTS_KNOWN];
5323  else if( consdata->exponent <= 2.0 )
5324  root = roots[2];
5325  else
5326  root = roots[(int)SCIPfloor(scip, consdata->exponent)];
5327  iter = 0;
5328  do
5329  {
5330  polyval = (consdata->exponent - 1.0) * consdata->power(root, consdata->exponent) + consdata->exponent * pow(root, consdata->exponent-1.0) - 1.0;
5331  if( SCIPisZero(scip, polyval) )
5332  break;
5333 
5334  /* gradient of (n-1) y^n + n y^(n-1) - 1 is n(n-1)y^(n-1) + n(n-1)y^(n-2) */
5335  gradval = (consdata->exponent - 1.0) * consdata->exponent * (pow(root, consdata->exponent - 1.0) + pow(root, consdata->exponent - 2.0));
5336  if( SCIPisZero(scip, gradval) )
5337  break;
5338 
5339  /* update root by adding -polyval/gradval (Newton's method) */
5340  root -= polyval / gradval;
5341  if( root < 0.0 )
5342  root = 0.0;
5343  }
5344  while( ++iter < 1000 );
5345 
5346  if( !SCIPisZero(scip, polyval) )
5347  {
5348  SCIPerrorMessage("failed to compute root for exponent %g\n", consdata->exponent);
5349  return SCIP_ERROR;
5350  }
5351  SCIPdebugMessage("root for %g is %.20g, certainty = %g\n", consdata->exponent, root, polyval);
5352  /* @todo cache root value?? (they are actually really fast to compute...) */
5353 
5354  consdata->root = root;
5355  }
5356 
5357  /* add nlrow respresentation to NLP, if NLP had been constructed */
5358  if( SCIPisNLPConstructed(scip) && SCIPconsIsEnabled(conss[c]) ) /*lint !e613*/
5359  {
5360  if( consdata->nlrow == NULL )
5361  {
5362  SCIP_CALL( createNlRow(scip, conss[c]) ); /*lint !e613*/
5363  assert(consdata->nlrow != NULL);
5364  }
5365  SCIP_CALL( SCIPaddNlRow(scip, consdata->nlrow) );
5366  }
5367  }
5368 
5369  conshdlrdata->newsoleventfilterpos = -1;
5370  if( nconss != 0 )
5371  {
5372  SCIP_EVENTHDLR* eventhdlr;
5373 
5374  eventhdlr = SCIPfindEventhdlr(scip, CONSHDLR_NAME"_newsolution");
5375  assert(eventhdlr != NULL);
5376 
5377  SCIP_CALL( SCIPcatchEvent(scip, SCIP_EVENTTYPE_SOLFOUND, eventhdlr, (SCIP_EVENTDATA*)conshdlr, &conshdlrdata->newsoleventfilterpos) );
5378  }
5379 
5380  /* reset flags and counters */
5381  conshdlrdata->sepanlp = FALSE;
5382  conshdlrdata->lastenfolpnode = NULL;
5383  conshdlrdata->nenfolprounds = 0;
5384 
5385  return SCIP_OKAY;
5386 }
5387 
5388 /** solving process deinitialization method of constraint handler (called before branch and bound process data is freed) */
5389 static
5390 SCIP_DECL_CONSEXITSOL(consExitsolAbspower)
5391 { /*lint --e{715}*/
5392  SCIP_CONSHDLRDATA* conshdlrdata;
5393  SCIP_CONSDATA* consdata;
5394  int c;
5395 
5396  assert(scip != NULL);
5397  assert(conss != NULL || nconss == 0);
5398 
5399  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5400  assert(conshdlrdata != NULL);
5401 
5402  if( conshdlrdata->newsoleventfilterpos >= 0 )
5403  {
5404  SCIP_EVENTHDLR* eventhdlr;
5405 
5406  eventhdlr = SCIPfindEventhdlr(scip, CONSHDLR_NAME"_newsolution");
5407  assert(eventhdlr != NULL);
5408 
5409  SCIP_CALL( SCIPdropEvent(scip, SCIP_EVENTTYPE_SOLFOUND, eventhdlr, (SCIP_EVENTDATA*)conshdlr, conshdlrdata->newsoleventfilterpos) );
5410  conshdlrdata->newsoleventfilterpos = -1;
5411  }
5412 
5413  for( c = 0; c < nconss; ++c )
5414  {
5415  assert(conss[c] != NULL); /*lint !e613*/
5416 
5417  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
5418  assert(consdata != NULL);
5419 
5420  /* free nonlinear row representation */
5421  if( consdata->nlrow != NULL )
5422  {
5423  SCIP_CALL( SCIPreleaseNlRow(scip, &consdata->nlrow) );
5424  }
5425  }
5426 
5427  return SCIP_OKAY;
5428 }
5429 
5430 /** frees specific constraint data */
5431 static
5432 SCIP_DECL_CONSDELETE(consDeleteAbspower)
5433 { /*lint --e{715}*/
5434  assert(scip != NULL);
5435  assert(conshdlr != NULL);
5436  assert(cons != NULL);
5437  assert(consdata != NULL);
5438  assert((*consdata)->x != NULL);
5439  assert((*consdata)->z != NULL);
5440  assert((*consdata)->xeventfilterpos == -1);
5441  assert((*consdata)->zeventfilterpos == -1);
5442 
5443  if( (*consdata)->nlrow != NULL )
5444  {
5445  SCIP_CALL( SCIPreleaseNlRow(scip, &(*consdata)->nlrow) );
5446  }
5447 
5448  SCIPfreeMemory(scip, consdata);
5449 
5450  return SCIP_OKAY;
5451 }
5452 
5453 /** transforms constraint data into data belonging to the transformed problem */
5454 static
5455 SCIP_DECL_CONSTRANS(consTransAbspower)
5456 { /*lint --e{715}*/
5457  SCIP_CONSDATA* sourcedata;
5458  SCIP_CONSDATA* targetdata;
5459 
5460  sourcedata = SCIPconsGetData(sourcecons);
5461  assert(sourcedata != NULL);
5462 
5463  SCIP_CALL( SCIPduplicateMemory(scip, &targetdata, sourcedata) );
5464  assert(targetdata->xeventfilterpos == -1);
5465  assert(targetdata->zeventfilterpos == -1);
5466 
5467  SCIP_CALL( SCIPgetTransformedVar(scip, sourcedata->x, &targetdata->x) );
5468  SCIP_CALL( SCIPgetTransformedVar(scip, sourcedata->z, &targetdata->z) );
5469 
5470  /* branching on multiaggregated variables does not seem to work well, so avoid multiagg. x */
5471  assert( SCIPvarIsActive(targetdata->x) );
5472  SCIP_CALL( SCIPmarkDoNotMultaggrVar(scip, targetdata->x) );
5473 
5474  /* cannot propagate on multiaggregated vars, so avoid multiagg. z */
5475  assert( SCIPvarIsActive(targetdata->z) );
5476  SCIP_CALL( SCIPmarkDoNotMultaggrVar(scip, targetdata->z) );
5477 
5478  /* create target constraint */
5479  SCIP_CALL( SCIPcreateCons(scip, targetcons, SCIPconsGetName(sourcecons), conshdlr, targetdata,
5480  SCIPconsIsInitial(sourcecons), SCIPconsIsSeparated(sourcecons), SCIPconsIsEnforced(sourcecons),
5481  SCIPconsIsChecked(sourcecons), SCIPconsIsPropagated(sourcecons), SCIPconsIsLocal(sourcecons),
5482  SCIPconsIsModifiable(sourcecons), SCIPconsIsDynamic(sourcecons), SCIPconsIsRemovable(sourcecons),
5483  SCIPconsIsStickingAtNode(sourcecons)) );
5484 
5485  return SCIP_OKAY;
5486 }
5487 
5488 /** LP initialization method of constraint handler (called before the initial LP relaxation at a node is solved)
5489  *
5490  * we add secant underestimators
5491  */
5492 static
5493 SCIP_DECL_CONSINITLP(consInitlpAbspower)
5494 { /*lint --e{715}*/
5495  SCIP_CONSDATA* consdata;
5496  SCIP_CONSHDLRDATA* conshdlrdata;
5497  SCIP_Bool infeasible;
5498  SCIP_ROW* row;
5499  int c;
5500  SCIP_Real xlb;
5501  SCIP_Real xub;
5502 
5503  assert(scip != NULL);
5504  assert(conshdlr != NULL);
5505  assert(conss != NULL || nconss == 0);
5506 
5507  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5508  assert(conshdlrdata != NULL);
5509 
5510  for( c = 0; c < nconss; ++c )
5511  {
5512  assert(conss[c] != NULL); /*lint !e613*/
5513 
5514  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
5515  assert(consdata != NULL);
5516 
5517  xlb = SCIPvarGetLbGlobal(consdata->x);
5518  xub = SCIPvarGetUbGlobal(consdata->x);
5519 
5520  if( SCIPisRelEQ(scip, xlb, xub) )
5521  continue;
5522 
5523  if( !SCIPisInfinity(scip, consdata->rhs) )
5524  {
5525  if( !SCIPisInfinity(scip, -xlb) )
5526  {
5527  if( SCIPisNegative(scip, xlb + consdata->xoffset) )
5528  {
5529  /* generate secant between xlb and right changepoint */
5530  SCIP_CALL( generateSecantCutNoCheck(scip, &row, conshdlr, xlb, MIN(-consdata->root * (xlb+consdata->xoffset) - consdata->xoffset, xub),
5531  consdata->exponent, consdata->xoffset, consdata->power, 1.0, consdata->zcoef, consdata->rhs, consdata->x, consdata->z) );
5532  if( row != NULL )
5533  {
5534  if( !SCIPisInfinity(scip, SCIProwGetRhs(row)) && SCIPgetRowMaxCoef(scip, row)/SCIPgetRowMinCoef(scip, row) < conshdlrdata->cutmaxrange )
5535  {
5536  SCIP_CALL( SCIPaddCut(scip, NULL, row, FALSE /* forcecut */, &infeasible) );
5537  assert( ! infeasible );
5538 
5539  if( conshdlrdata->conshdlrindicator != NULL && !SCIProwIsLocal(row) )
5540  {
5541  SCIP_CALL( SCIPaddRowIndicator(scip, conshdlrdata->conshdlrindicator, row) );
5542  }
5543  }
5544  SCIP_CALL( SCIPreleaseRow(scip, &row) );
5545  }
5546  }
5547  else if( xlb < INITLPMAXVARVAL )
5548  {
5549  /* generate tangent in lower bound */
5550  SCIP_CALL( generateLinearizationCut(scip, &row, conshdlr, xlb, consdata->exponent, consdata->xoffset, 1.0, consdata->zcoef, consdata->rhs,
5551  consdata->x, consdata->z, FALSE) );
5552  assert(row != NULL);
5553  if( !SCIPisInfinity(scip, SCIProwGetRhs(row)) && SCIPgetRowMaxCoef(scip, row)/SCIPgetRowMinCoef(scip, row) < conshdlrdata->cutmaxrange )
5554  {
5555  SCIP_CALL( SCIPaddCut(scip, NULL, row, FALSE /* forcecut */, &infeasible) );
5556  assert( ! infeasible );
5557 
5558  if( conshdlrdata->conshdlrindicator != NULL )
5559  {
5560  SCIP_CALL( SCIPaddRowIndicator(scip, conshdlrdata->conshdlrindicator, row) );
5561  }
5562  }
5563  SCIP_CALL( SCIPreleaseRow(scip, &row) );
5564  }
5565  }
5566 
5567  if( !SCIPisInfinity(scip, xub) )
5568  {
5569  /* generate tangent in upper bound */
5570  if( -consdata->root * (xlb+consdata->xoffset) - consdata->xoffset < xub && xub <= INITLPMAXVARVAL )
5571  {
5572  SCIP_CALL( generateLinearizationCut(scip, &row, conshdlr, xub, consdata->exponent, consdata->xoffset, 1.0, consdata->zcoef, consdata->rhs,
5573  consdata->x, consdata->z, FALSE) );
5574  assert(row != NULL);
5575  if( !SCIPisInfinity(scip, SCIProwGetRhs(row)) && SCIPgetRowMaxCoef(scip, row)/SCIPgetRowMinCoef(scip, row) < conshdlrdata->cutmaxrange )
5576  {
5577  SCIP_CALL( SCIPaddCut(scip, NULL, row, FALSE /* forcecut */, &infeasible) );
5578  assert( ! infeasible );
5579 
5580  if( conshdlrdata->conshdlrindicator != NULL )
5581  {
5582  SCIP_CALL( SCIPaddRowIndicator(scip, conshdlrdata->conshdlrindicator, row) );
5583  }
5584  }
5585  SCIP_CALL( SCIPreleaseRow(scip, &row) );
5586  }
5587  }
5588  }
5589 
5590  if( !SCIPisInfinity(scip, -consdata->lhs) )
5591  {
5592  if( !SCIPisInfinity(scip, xub) )
5593  {
5594  if( SCIPisPositive(scip, xub + consdata->xoffset) )
5595  {
5596  /* generate secant between left change point and upper bound */
5597  SCIP_CALL( generateSecantCutNoCheck(scip, &row, conshdlr, -xub, MIN(consdata->root * (xub+consdata->xoffset) + consdata->xoffset, -xlb),
5598  consdata->exponent, -consdata->xoffset, consdata->power, -1.0, -consdata->zcoef, -consdata->lhs, consdata->x, consdata->z) );
5599  if( row != NULL )
5600  {
5601  if( !SCIPisInfinity(scip, SCIProwGetRhs(row)) && SCIPgetRowMaxCoef(scip, row)/SCIPgetRowMinCoef(scip, row) < conshdlrdata->cutmaxrange )
5602  {
5603  SCIP_CALL( SCIPaddCut(scip, NULL, row, FALSE /* forcecut */, &infeasible) );
5604  assert( ! infeasible );
5605 
5606  if( conshdlrdata->conshdlrindicator != NULL && !SCIProwIsLocal(row) )
5607  {
5608  SCIP_CALL( SCIPaddRowIndicator(scip, conshdlrdata->conshdlrindicator, row) );
5609  }
5610  }
5611  SCIP_CALL( SCIPreleaseRow(scip, &row) );
5612  }
5613  }
5614  else if( xub >= -INITLPMAXVARVAL )
5615  {
5616  /* generate tangent in upper bound */
5617  SCIP_CALL( generateLinearizationCut(scip, &row, conshdlr, -xub, consdata->exponent, -consdata->xoffset, -1.0, -consdata->zcoef, -consdata->lhs,
5618  consdata->x, consdata->z, FALSE) );
5619  assert(row != NULL);
5620  if( !SCIPisInfinity(scip, SCIProwGetRhs(row)) && SCIPgetRowMaxCoef(scip, row)/SCIPgetRowMinCoef(scip, row) < conshdlrdata->cutmaxrange )
5621  {
5622  SCIP_CALL( SCIPaddCut(scip, NULL, row, FALSE /* forcecut */, &infeasible) );
5623  assert( ! infeasible );
5624 
5625  if( conshdlrdata->conshdlrindicator != NULL )
5626  {
5627  SCIP_CALL( SCIPaddRowIndicator(scip, conshdlrdata->conshdlrindicator, row) );
5628  }
5629  }
5630  SCIP_CALL( SCIPreleaseRow(scip, &row) );
5631  }
5632  }
5633 
5634  if( !SCIPisInfinity(scip, -xlb) )
5635  {
5636  /* generate tangent in lower bound */
5637  if( -consdata->root * (xub+consdata->xoffset) - consdata->xoffset > xlb && xlb >= -INITLPMAXVARVAL )
5638  {
5639  SCIP_CALL( generateLinearizationCut(scip, &row, conshdlr, -xlb, consdata->exponent, -consdata->xoffset, -1.0, -consdata->zcoef, -consdata->lhs,
5640  consdata->x, consdata->z, FALSE) );
5641  assert(row != NULL);
5642  if( !SCIPisInfinity(scip, SCIProwGetRhs(row)) && SCIPgetRowMaxCoef(scip, row)/SCIPgetRowMinCoef(scip, row) < conshdlrdata->cutmaxrange )
5643  {
5644  SCIP_CALL( SCIPaddCut(scip, NULL, row, FALSE /* forcecut */, &infeasible) );
5645  assert( ! infeasible );
5646 
5647  if( conshdlrdata->conshdlrindicator != NULL )
5648  {
5649  SCIP_CALL( SCIPaddRowIndicator(scip, conshdlrdata->conshdlrindicator, row) );
5650  }
5651  }
5652  SCIP_CALL( SCIPreleaseRow(scip, &row) );
5653  }
5654  }
5655  }
5656  }
5657 
5658  return SCIP_OKAY;
5659 }
5660 
5661 /** separation method of constraint handler for LP solutions */
5662 static
5663 SCIP_DECL_CONSSEPALP(consSepalpAbspower)
5664 { /*lint --e{715}*/
5665  SCIP_CONSHDLRDATA* conshdlrdata;
5666  SCIP_CONS* maxviolcon;
5667  SCIP_Bool success;
5668  SCIP_Bool cutoff;
5669 
5670  assert(scip != NULL);
5671  assert(conshdlr != NULL);
5672  assert(conss != NULL || nconss == 0);
5673  assert(result != NULL);
5674 
5675  *result = SCIP_DIDNOTFIND;
5676 
5677  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5678  assert(conshdlrdata != NULL);
5679 
5680  SCIP_CALL( computeViolations(scip, conshdlr, conss, nconss, NULL, &maxviolcon) );
5681  if( maxviolcon == NULL )
5682  return SCIP_OKAY;
5683 
5684  /* at root, check if we want to solve the NLP relaxation and use its solutions as reference point
5685  * if there is something convex, then linearizing in the solution of the NLP relaxation can be very useful
5686  */
5687  if( SCIPgetDepth(scip) == 0 && !conshdlrdata->sepanlp &&
5688  (SCIPgetNContVars(scip) >= conshdlrdata->sepanlpmincont * SCIPgetNVars(scip) || (SCIPgetLPSolstat(scip) == SCIP_LPSOLSTAT_UNBOUNDEDRAY && conshdlrdata->sepanlpmincont <= 1.0)) &&
5689  SCIPisNLPConstructed(scip) && SCIPgetNNlpis(scip) > 0 )
5690  {
5691  SCIP_CONSDATA* consdata;
5692  SCIP_NLPSOLSTAT solstat;
5693  SCIP_Bool solvednlp;
5694  int c;
5695 
5696  solstat = SCIPgetNLPSolstat(scip);
5697  solvednlp = FALSE;
5698  if( solstat == SCIP_NLPSOLSTAT_UNKNOWN )
5699  {
5700  /* NLP is not solved yet, so we might want to do this
5701  * but first check whether there is a violated constraint side which corresponds to a convex function
5702  * @todo put this check into initsol and update via consenable/consdisable
5703  */
5704  for( c = 0; c < nconss; ++c )
5705  {
5706  assert(conss[c] != NULL); /*lint !e613*/
5707 
5708  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
5709  assert(consdata != NULL);
5710 
5711  /* skip feasible constraints */
5712  if( !SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) && !SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
5713  continue;
5714 
5715  if( (!SCIPisGT(scip, SCIPvarGetUbGlobal(consdata->x), -consdata->xoffset) && !SCIPisInfinity(scip, -consdata->lhs)) ||
5716  ( !SCIPisLT(scip, SCIPvarGetLbGlobal(consdata->x), -consdata->xoffset) && !SCIPisInfinity(scip, -consdata->rhs)) )
5717  break;
5718  }
5719 
5720  if( c < nconss )
5721  {
5722  /* try to solve NLP and update solstat */
5723 
5724  /* ensure linear conss are in NLP */
5725  if( conshdlrdata->subnlpheur != NULL )
5726  {
5727  SCIP_CALL( SCIPaddLinearConsToNlpHeurSubNlp(scip, conshdlrdata->subnlpheur, TRUE, TRUE) );
5728  }
5729 
5730  /* set LP solution as starting values, if available */
5732  {
5734  }
5735 
5736  /* SCIP_CALL( SCIPsetNLPIntPar(scip, SCIP_NLPPAR_VERBLEVEL, 1) ); */
5737  SCIP_CALL( SCIPsolveNLP(scip) );
5738 
5739  solstat = SCIPgetNLPSolstat(scip);
5740  SCIPdebugMessage("solved NLP relax, solution status: %d\n", solstat);
5741 
5742  solvednlp = TRUE;
5743  }
5744  }
5745 
5746  conshdlrdata->sepanlp = TRUE;
5747 
5748  if( solstat == SCIP_NLPSOLSTAT_GLOBINFEASIBLE )
5749  {
5750  SCIPdebugMessage("NLP relaxation is globally infeasible, thus can cutoff node\n");
5751  *result = SCIP_CUTOFF;
5752  return SCIP_OKAY;
5753  }
5754 
5755  if( solstat <= SCIP_NLPSOLSTAT_FEASIBLE )
5756  {
5757  /* if we have feasible NLP solution, generate linearization cuts there */
5758  SCIP_Bool lpsolseparated;
5759  SCIP_SOL* nlpsol;
5760 
5761  SCIP_CALL( SCIPcreateNLPSol(scip, &nlpsol, NULL) );
5762  assert(nlpsol != NULL);
5763 
5764  /* if we solved the NLP and solution is integral, then pass it to trysol heuristic */
5765  if( solvednlp && conshdlrdata->trysolheur != NULL )
5766  {
5767  int nfracvars;
5768 
5769  nfracvars = 0;
5770  if( SCIPgetNBinVars(scip) > 0 || SCIPgetNIntVars(scip) > 0 )
5771  {
5772  SCIP_CALL( SCIPgetNLPFracVars(scip, NULL, NULL, NULL, &nfracvars, NULL) );
5773  }
5774 
5775  if( nfracvars == 0 )
5776  {
5777  SCIP_CALL( SCIPheurPassSolTrySol(scip, conshdlrdata->trysolheur, nlpsol) );
5778  }
5779  }
5780 
5781  SCIP_CALL( addLinearizationCuts(scip, conshdlr, conss, nconss, nlpsol, &lpsolseparated, conshdlrdata->mincutefficacysepa) );
5782 
5783  SCIP_CALL( SCIPfreeSol(scip, &nlpsol) );
5784 
5785  /* if a cut that separated the LP solution was added, then return, otherwise continue with usual separation in LP solution */
5786  if( lpsolseparated )
5787  {
5788  SCIPdebugMessage("linearization cuts separate LP solution\n");
5789 
5790  *result = SCIP_SEPARATED;
5791 
5792  return SCIP_OKAY;
5793  }
5794  }
5795  }
5796  /* if we do not want to try solving the NLP, or have no NLP, or have no NLP solver, or solving the NLP failed,
5797  * or separating with NLP solution as reference point failed, then try (again) with LP solution as reference point
5798  */
5799 
5800  SCIP_CALL( separatePoint(scip, conshdlr, conss, nconss, nusefulconss, NULL, conshdlrdata->mincutefficacysepa, FALSE, conshdlrdata->sepainboundsonly, &success, &cutoff, NULL) );
5801  if( cutoff )
5802  *result = SCIP_CUTOFF;
5803  else if( success )
5804  *result = SCIP_SEPARATED;
5805 
5806  return SCIP_OKAY;
5807 }
5808 
5809 /** separation method of constraint handler for arbitrary primal solutions */
5810 static
5811 SCIP_DECL_CONSSEPASOL(consSepasolAbspower)
5812 { /*lint --e{715}*/
5813  SCIP_CONSHDLRDATA* conshdlrdata;
5814  SCIP_CONS* maxviolcon;
5815  SCIP_Bool success;
5816  SCIP_Bool cutoff;
5817 
5818  assert(scip != NULL);
5819  assert(conshdlr != NULL);
5820  assert(conss != NULL || nconss == 0);
5821  assert(sol != NULL);
5822  assert(result != NULL);
5823 
5824  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5825  assert(conshdlrdata != NULL);
5826 
5827  *result = SCIP_DIDNOTFIND;
5828 
5829  SCIP_CALL( computeViolations(scip, conshdlr, conss, nconss, sol, &maxviolcon) );
5830  if( maxviolcon == NULL )
5831  return SCIP_OKAY;
5832 
5833  SCIP_CALL( separatePoint(scip, conshdlr, conss, nconss, nusefulconss, sol, conshdlrdata->mincutefficacysepa, FALSE, FALSE, &success, &cutoff, NULL) );
5834  if( cutoff )
5835  *result = SCIP_CUTOFF;
5836  else if( success )
5837  *result = SCIP_SEPARATED;
5838 
5839  return SCIP_OKAY;
5840 }
5841 
5842 /** constraint enforcing method of constraint handler for LP solutions */
5843 static
5844 SCIP_DECL_CONSENFOLP(consEnfolpAbspower)
5845 { /*lint --e{715}*/
5846  SCIP_CONSHDLRDATA* conshdlrdata;
5847  SCIP_CONS* maxviolcons;
5848  SCIP_CONSDATA* consdata;
5849  SCIP_Bool success;
5850  SCIP_Bool cutoff;
5851  SCIP_Real minefficacy;
5852  SCIP_Real sepaefficacy;
5853  SCIP_Real leastpossibleefficacy;
5854  SCIP_Real maxviol;
5855  int nnotify;
5856  int c;
5857 
5858  assert(scip != NULL);
5859  assert(conshdlr != NULL);
5860  assert(conss != NULL || nconss == 0);
5861  assert(result != NULL);
5862 
5863  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5864  assert(conshdlrdata != NULL);
5865 
5866  SCIP_CALL( computeViolations(scip, conshdlr, conss, nconss, NULL, &maxviolcons) );
5867 
5868  if( maxviolcons == NULL )
5869  {
5870  *result = SCIP_FEASIBLE;
5871  return SCIP_OKAY;
5872  }
5873 
5874  *result = SCIP_INFEASIBLE;
5875 
5876  /* if we are above the 100'th enforcement round for this node, something is strange
5877  * (maybe the LP does not think that the cuts we add are violated, or we do ECP on a high-dimensional convex function)
5878  * in this case, check if some limit is hit or SCIP should stop for some other reason and terminate enforcement by creating a dummy node
5879  * (in optimized more, returning SCIP_INFEASIBLE in *result would be sufficient, but in debug mode this would give an assert in scip.c)
5880  * the reason to wait for 100 rounds is to avoid calls to SCIPisStopped in normal runs, which may be expensive
5881  * we only increment nenfolprounds until 101 to avoid an overflow
5882  */
5883  if( conshdlrdata->lastenfolpnode == SCIPgetCurrentNode(scip) )
5884  {
5885  if( conshdlrdata->nenfolprounds > 100 )
5886  {
5887  if( SCIPisStopped(scip) )
5888  {
5889  SCIP_NODE* child;
5890 
5891  SCIP_CALL( SCIPcreateChild(scip, &child, 1.0, SCIPnodeGetEstimate(SCIPgetCurrentNode(scip))) );
5892  *result = SCIP_BRANCHED;
5893 
5894  return SCIP_OKAY;
5895  }
5896  }
5897  else
5898  ++conshdlrdata->nenfolprounds;
5899  }
5900  else
5901  {
5902  conshdlrdata->lastenfolpnode = SCIPgetCurrentNode(scip);
5903  conshdlrdata->nenfolprounds = 0;
5904  }
5905 
5906  /* run domain propagation for violated constraints */
5907  for( c = 0; c < nconss; ++c )
5908  {
5909  int nchgbds;
5910  int naddconss;
5911 
5912  assert(conss[c] != NULL); /*lint !e613*/
5913 
5914  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
5915  assert(consdata != NULL);
5916 
5917  if( !SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) && !SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
5918  continue;
5919 
5920  nchgbds = 0;
5921  naddconss = 0;
5922  SCIP_CALL( propagateCons(scip, conshdlr, conss[c], TRUE, &cutoff, &nchgbds, &naddconss) ); /*lint !e613*/
5923  if( cutoff )
5924  {
5925  *result = SCIP_CUTOFF;
5926  return SCIP_OKAY;
5927  }
5928  if( nchgbds )
5929  *result = SCIP_REDUCEDDOM;
5930  if( naddconss )
5931  *result = SCIP_CONSADDED;
5932  }
5933  if( *result == SCIP_REDUCEDDOM || *result == SCIP_CONSADDED )
5934  return SCIP_OKAY;
5935 
5936  consdata = SCIPconsGetData(maxviolcons);
5937  assert(consdata != NULL);
5938  maxviol = consdata->lhsviol + consdata->rhsviol;
5939  assert(SCIPisGT(scip, maxviol, SCIPfeastol(scip)));
5940 
5941  /* we would like a cut that is efficient enough that it is not redundant in the LP (>feastol)
5942  * however, if the maximal violation is very small, also the best cut efficacy cannot be large
5943  * thus, in the latter case, we are also happy if the efficacy is at least, say, 75% of the maximal violation
5944  * but in any case we need an efficacy that is at least feastol
5945  */
5946  minefficacy = MIN(0.75*maxviol, conshdlrdata->mincutefficacyenfofac * SCIPfeastol(scip)); /*lint !e666*/
5947  minefficacy = MAX(minefficacy, SCIPfeastol(scip)); /*lint !e666*/
5948  SCIP_CALL( separatePoint(scip, conshdlr, conss, nconss, nusefulconss, NULL, minefficacy, TRUE, FALSE, &success, &cutoff, &sepaefficacy) );
5949  if( cutoff )
5950  {
5951  SCIPdebugMessage("separation detected cutoff.\n");
5952  *result = SCIP_CUTOFF;
5953  return SCIP_OKAY;
5954  }
5955  if( success )
5956  {
5957  SCIPdebugMessage("separation succeeded (bestefficacy = %g, minefficacy = %g)\n", sepaefficacy, minefficacy);
5958  *result = SCIP_SEPARATED;
5959  return SCIP_OKAY;
5960  }
5961  SCIPdebugMessage("separation failed (bestefficacy = %g < %g = minefficacy ); max viol: %g\n", sepaefficacy, minefficacy, maxviol);
5962 
5963  /* we are not feasible, the whole node is not infeasible, and we cannot find a reasonable cut
5964  * -> collect variables for branching
5965  */
5966  SCIP_CALL( registerBranchingCandidates(scip, conshdlr, conss, nconss, &nnotify) );
5967 
5968  /* if sepastore can decrease LP feasibility tolerance, we can add cuts with efficacy in [eps, feastol] */
5969  leastpossibleefficacy = SCIPgetRelaxFeastolFactor(scip) > 0.0 ? SCIPepsilon(scip) : SCIPfeastol(scip);
5970  if( nnotify == 0 && !solinfeasible && minefficacy > leastpossibleefficacy )
5971  {
5972  /* fallback 1: we also have no branching candidates, so try to find a weak cut */
5973  SCIP_CALL( separatePoint(scip, conshdlr, conss, nconss, nusefulconss, NULL, leastpossibleefficacy, TRUE, FALSE, &success, &cutoff, &sepaefficacy) );
5974  if( cutoff )
5975  {
5976  SCIPdebugMessage("separation detected cutoff.\n");
5977  *result = SCIP_CUTOFF;
5978  return SCIP_OKAY;
5979  }
5980  if( success )
5981  {
5982  *result = SCIP_SEPARATED;
5983  return SCIP_OKAY;
5984  }
5985  }
5986 
5987  if( nnotify == 0 && !solinfeasible )
5988  {
5989  /* fallback 2: separation probably failed because of numerical difficulties with a convex constraint;
5990  if noone declared solution infeasible yet and we had not even found a weak cut, try to resolve by branching */
5991  SCIP_VAR* brvar = NULL;
5992  SCIP_CALL( registerLargeLPValueVariableForBranching(scip, conss, nconss, &brvar) );
5993  if( brvar == NULL )
5994  {
5995  SCIPwarningMessage(scip, "Could not find any branching variable candidate. Cutting off node. Max viol = %g.\n", SCIPconsGetData(maxviolcons)->lhsviol+SCIPconsGetData(maxviolcons)->rhsviol);
5996  *result = SCIP_CUTOFF;
5997  return SCIP_OKAY;
5998  }
5999  else
6000  {
6001  SCIPdebugMessage("Could not find any usual branching variable candidate. Proposed variable %s with LP value %g for branching. Max. viol. cons. <%s>: %g+%g\n", SCIPvarGetName(brvar), SCIPgetSolVal(scip, NULL, brvar), SCIPconsGetName(maxviolcons), SCIPconsGetData(maxviolcons)->lhsviol, SCIPconsGetData(maxviolcons)->rhsviol);
6002  nnotify = 1;
6003  }
6004  }
6005 
6006  assert(*result == SCIP_INFEASIBLE && (solinfeasible || nnotify > 0));
6007  return SCIP_OKAY;
6008 }
6009 
6010 
6011 /** constraint enforcing method of constraint handler for pseudo solutions */
6012 static
6013 SCIP_DECL_CONSENFOPS(consEnfopsAbspower)
6014 { /*lint --e{715}*/
6015  SCIP_CONSHDLRDATA* conshdlrdata;
6016  SCIP_CONS* maxviolcon;
6017  SCIP_CONSDATA* consdata;
6018  int c;
6019  int nnotify;
6020 
6021  assert(scip != NULL);
6022  assert(conshdlr != NULL);
6023  assert(conss != NULL || nconss == 0);
6024 
6025  conshdlrdata = SCIPconshdlrGetData(conshdlr);
6026  assert(conshdlrdata != NULL);
6027 
6028  SCIP_CALL( computeViolations(scip, conshdlr, conss, nconss, NULL, &maxviolcon) );
6029  if( maxviolcon == NULL )
6030  {
6031  *result = SCIP_FEASIBLE;
6032  return SCIP_OKAY;
6033  }
6034 
6035  *result = SCIP_INFEASIBLE;
6036 
6037  /* run domain propagation for violated constraints */
6038  for( c = 0; c < nconss; ++c )
6039  {
6040  SCIP_Bool cutoff;
6041  int nchgbds;
6042  int naddconss;
6043 
6044  assert(conss[c] != NULL); /*lint !e613*/
6045 
6046  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
6047  assert(consdata != NULL);
6048 
6049  if( !SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) && !SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
6050  continue;
6051 
6052  nchgbds = 0;
6053  naddconss = 0;
6054  SCIP_CALL( propagateCons(scip, conshdlr, conss[c], TRUE, &cutoff, &nchgbds, &naddconss) ); /*lint !e613*/
6055  if( cutoff )
6056  {
6057  *result = SCIP_CUTOFF;
6058  return SCIP_OKAY;
6059  }
6060  if( nchgbds )
6061  *result = SCIP_REDUCEDDOM;
6062  if( naddconss )
6063  *result = SCIP_CONSADDED;
6064  }
6065  if( *result == SCIP_REDUCEDDOM || *result == SCIP_CONSADDED )
6066  return SCIP_OKAY;
6067 
6068  /* we are not feasible and we cannot proof that the whole node is infeasible
6069  * -> branch on all unfixed variables in violated constraints
6070  */
6071  nnotify = 0;
6072  for( c = 0; c < nconss; ++c )
6073  {
6074  assert(conss != NULL);
6075  consdata = SCIPconsGetData(conss[c]);
6076  assert(consdata != NULL);
6077  SCIPdebugMessage("cons <%s> violation: %g %g\n", SCIPconsGetName(conss[c]), consdata->lhsviol, consdata->rhsviol);
6078 
6079  if( !SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) && !SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
6080  continue;
6081 
6082  SCIPdebugMessage("cons <%s> violation: %g %g\n", SCIPconsGetName(conss[c]), consdata->lhsviol, consdata->rhsviol);
6083 
6084  /* domain propagation should have removed cons when x is fixed */
6085  assert(!SCIPisRelEQ(scip, SCIPvarGetLbLocal(consdata->x), SCIPvarGetUbLocal(consdata->x)));
6086 
6087  SCIP_CALL( SCIPaddExternBranchCand(scip, consdata->x, consdata->lhsviol + consdata->rhsviol, proposeBranchingPoint(scip, conss[c], conshdlrdata->preferzerobranch, conshdlrdata->branchminconverror)) );
6088  ++nnotify;
6089  }
6090 
6091  if( nnotify == 0 )
6092  {
6093  SCIPdebugMessage("All variables in violated constraints fixed (up to epsilon). Cannot find branching candidate. Forcing solution of LP.\n");
6094  *result = SCIP_SOLVELP;
6095  }
6096 
6097  assert(*result == SCIP_SOLVELP || (*result == SCIP_INFEASIBLE && nnotify > 0));
6098  return SCIP_OKAY;
6099 }
6100 
6101 
6102 /** domain propagation method of constraint handler */
6103 static
6104 SCIP_DECL_CONSPROP(consPropAbspower)
6105 { /*lint --e{715}*/
6106  int c;
6107  int nchgbds;
6108  int naddconss;
6109  SCIP_Bool cutoff = FALSE;
6110 
6111  assert(scip != NULL);
6112  assert(conshdlr != NULL);
6113  assert(conss != NULL || nconss == 0);
6114  assert(result != NULL);
6115 
6116  *result = SCIP_DIDNOTFIND;
6117 
6118  for( c = 0; c < nconss; ++c )
6119  {
6120  assert(conss != NULL);
6121 
6122  /* propagate constraint, but do not allow to add a constraint for tightening a multiaggregated variable (not allowed in CONSPROP) */
6123  nchgbds = 0;
6124  naddconss = 0;
6125  SCIP_CALL( propagateCons(scip, conshdlr, conss[c], FALSE, &cutoff, &nchgbds, &naddconss) );
6126  assert(naddconss == 0);
6127 
6128  if( cutoff )
6129  {
6130  *result = SCIP_CUTOFF;
6131  break;
6132  }
6133 
6134  if( nchgbds )
6135  *result = SCIP_REDUCEDDOM;
6136 
6137  if( c >= nusefulconss && *result != SCIP_DIDNOTFIND )
6138  break;
6139  }
6140 
6141  return SCIP_OKAY;
6142 }
6143 
6144 /** presolving method of constraint handler */
6145 static
6146 SCIP_DECL_CONSPRESOL(consPresolAbspower)
6147 { /*lint --e{715}*/
6148  SCIP_CONSHDLRDATA* conshdlrdata;
6149  SCIP_CONSDATA* consdata;
6150  SCIP_RESULT replaceresult;
6151  SCIP_Bool success;
6152  SCIP_Bool infeas;
6153  int localnchgbds;
6154  int localnaddconss;
6155  int c;
6156 
6157  assert(scip != NULL);
6158  assert(conss != NULL || nconss == 0);
6159  assert(result != NULL);
6160 
6161  conshdlrdata = SCIPconshdlrGetData(conshdlr);
6162  assert(conshdlrdata != NULL);
6163 
6164  *result = SCIP_DIDNOTFIND;
6165 
6166  /* check for duplicates, if not done yet or if absolute power constraints were modified (variable fixings) or new absolute power constraints had been added */
6167  if( !conshdlrdata->comparedpairwise && (presoltiming & SCIP_PRESOLTIMING_MEDIUM) != 0 )
6168  {
6169  SCIP_CALL( presolveFindDuplicates(scip, conshdlr, conss, nconss, nupgdconss, ndelconss, naddconss, nfixedvars, naggrvars, &success, &infeas) );
6170  if( infeas )
6171  {
6172  *result = SCIP_CUTOFF;
6173  return SCIP_OKAY;
6174  }
6175  if( success )
6176  *result = SCIP_SUCCESS;
6177 
6178  conshdlrdata->comparedpairwise = TRUE;
6179 
6180  return SCIP_OKAY;
6181  }
6182 
6183  for( c = 0; c < nconss; ++c )
6184  {
6185  assert(conss[c] != NULL); /*lint !e613*/
6186 
6187  if( SCIPconsIsDeleted(conss[c]) ) /*lint !e613*/
6188  continue;
6189 
6190  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
6191  assert(consdata != NULL);
6192 
6193  SCIPdebugMessage("presolving constraint <%s>\n", SCIPconsGetName(conss[c])); /*lint !e613*/
6194  SCIPdebugPrintCons(scip, conss[c], NULL); /*lint !e613*/
6195 
6196  /* check if we can upgrade to a linear constraint */
6197  if( consdata->exponent == 1.0 )
6198  {
6199  SCIP_VAR* vars[2];
6200  SCIP_Real coefs[2];
6201  SCIP_CONS* lincons;
6202  SCIP_Real lhs;
6203  SCIP_Real rhs;
6204 
6205  vars[0] = consdata->x;
6206  vars[1] = consdata->z;
6207  coefs[0] = 1.0;
6208  coefs[1] = consdata->zcoef;
6209  lhs = consdata->lhs;
6210  rhs = consdata->rhs;
6211  if( !SCIPisInfinity(scip, -lhs) )
6212  lhs -= consdata->xoffset;
6213  if( !SCIPisInfinity(scip, rhs) )
6214  rhs -= consdata->xoffset;
6215 
6216  SCIP_CALL( SCIPcreateConsLinear(scip, &lincons, SCIPconsGetName(conss[c]), 2, vars, coefs, lhs, rhs,
6217  SCIPconsIsInitial(conss[c]), SCIPconsIsSeparated(conss[c]), SCIPconsIsEnforced(conss[c]),
6218  SCIPconsIsChecked(conss[c]), SCIPconsIsPropagated(conss[c]), SCIPconsIsLocal(conss[c]),
6219  SCIPconsIsModifiable(conss[c]), SCIPconsIsDynamic(conss[c]), SCIPconsIsRemovable(conss[c]),
6220  SCIPconsIsStickingAtNode(conss[c])) ); /*lint !e613*/
6221  SCIP_CALL( SCIPaddCons(scip, lincons) );
6222  SCIP_CALL( SCIPreleaseCons(scip, &lincons) );
6223 
6224  SCIP_CALL( SCIPdelCons(scip, conss[c]) ); /*lint !e613*/
6225  ++*nupgdconss;
6226  continue;
6227  }
6228 
6229  /* check for fixed variables */
6230  replaceresult = SCIP_DIDNOTFIND;
6231  SCIP_CALL( checkFixedVariables(scip, conshdlr, conss[c], ndelconss, nupgdconss, nchgbds, nfixedvars, &replaceresult) ); /*lint !e613*/
6232  switch( replaceresult )
6233  {
6234  case SCIP_DIDNOTFIND:
6235  break;
6236 
6237  case SCIP_CUTOFF:
6238  *result = SCIP_CUTOFF;
6239  return SCIP_OKAY;
6240 
6241  case SCIP_REDUCEDDOM:
6242  case SCIP_CONSADDED:
6243  *result = SCIP_SUCCESS;
6244  break;
6245 
6246  default:
6247  SCIPerrorMessage("invalid result from checkFixedVariables\n");
6248  SCIPABORT();
6249  return SCIP_INVALIDDATA; /*lint !e527*/
6250  } /*lint !e788*/
6251 
6252  if( SCIPconsIsDeleted(conss[c]) ) /*lint !e613*/
6253  {
6254  *result = SCIP_SUCCESS;
6255  continue;
6256  }
6257 
6258  /* another check for upgrading to a varbound constraint */
6259  if( SCIPvarIsBinary(consdata->x) )
6260  {
6261  SCIP_CONS* lincons;
6262  SCIP_Real lhs;
6263  SCIP_Real rhs;
6264  SCIP_Real zcoef;
6265 
6266  /* for binary variable x,
6267  * sign(x+offset)|x+offset|^n = sign(offset)|offset|^n * (1-x) + sign(offset+1) |offset+1|^n x
6268  * = sign(offset)|offset|^n + (sign(offset+1) |offset+1|^n - sign(offset)|offset|^n) * x
6269  * => constraint is lhs <= sign(offset)|offset|^n + (sign(offset+1) |offset+1|^n - sign(offset)|offset|^n) * x + c*z <= rhs
6270  * upgrade to varbound constraint if z is not continuous, otherwise linear
6271  */
6272  if( consdata->xoffset != 0.0 )
6273  {
6274  SCIP_Real xcoef;
6275 
6276  xcoef = SIGN(consdata->xoffset + 1.0) * consdata->power(ABS(consdata->xoffset + 1.0), consdata->exponent)
6277  -SIGN(consdata->xoffset) * consdata->power(ABS(consdata->xoffset), consdata->exponent);
6278 
6279  if( xcoef < 0.0 )
6280  {
6281  if( SCIPisInfinity(scip, consdata->rhs) )
6282  lhs = -SCIPinfinity(scip);
6283  else
6284  lhs = (consdata->rhs - SIGN(consdata->xoffset) * consdata->power(ABS(consdata->xoffset), consdata->exponent)) / xcoef;
6285  if( SCIPisInfinity(scip, -consdata->lhs) )
6286  rhs = SCIPinfinity(scip);
6287  else
6288  rhs = (consdata->lhs - SIGN(consdata->xoffset) * consdata->power(ABS(consdata->xoffset), consdata->exponent)) / xcoef;
6289  }
6290  else
6291  {
6292  if( SCIPisInfinity(scip, -consdata->lhs) )
6293  lhs = -SCIPinfinity(scip);
6294  else
6295  lhs = (consdata->lhs - SIGN(consdata->xoffset) * consdata->power(ABS(consdata->xoffset), consdata->exponent)) / xcoef;
6296  if( SCIPisInfinity(scip, consdata->rhs) )
6297  rhs = SCIPinfinity(scip);
6298  else
6299  rhs = (consdata->rhs - SIGN(consdata->xoffset) * consdata->power(ABS(consdata->xoffset), consdata->exponent)) / xcoef;
6300  }
6301  zcoef = consdata->zcoef / xcoef;
6302  }
6303  else
6304  {
6305  lhs = consdata->lhs;
6306  rhs = consdata->rhs;
6307  zcoef = consdata->zcoef;
6308  }
6309 
6310  if( SCIPvarGetType(consdata->z) < SCIP_VARTYPE_CONTINUOUS )
6311  {
6312  SCIP_CALL( SCIPcreateConsVarbound(scip, &lincons, SCIPconsGetName(conss[c]),
6313  consdata->x, consdata->z, zcoef, lhs, rhs,
6314  SCIPconsIsInitial(conss[c]), SCIPconsIsSeparated(conss[c]), SCIPconsIsEnforced(conss[c]),
6315  SCIPconsIsChecked(conss[c]), SCIPconsIsPropagated(conss[c]), SCIPconsIsLocal(conss[c]),
6316  SCIPconsIsModifiable(conss[c]), SCIPconsIsDynamic(conss[c]), SCIPconsIsRemovable(conss[c]),
6317  SCIPconsIsStickingAtNode(conss[c])) ); /*lint !e613*/
6318  }
6319  else
6320  {
6321  SCIP_CALL( SCIPcreateConsLinear(scip, &lincons, SCIPconsGetName(conss[c]),
6322  1, &consdata->z, &zcoef, lhs, rhs,
6323  SCIPconsIsInitial(conss[c]), SCIPconsIsSeparated(conss[c]), SCIPconsIsEnforced(conss[c]),
6324  SCIPconsIsChecked(conss[c]), SCIPconsIsPropagated(conss[c]), SCIPconsIsLocal(conss[c]),
6325  SCIPconsIsModifiable(conss[c]), SCIPconsIsDynamic(conss[c]), SCIPconsIsRemovable(conss[c]),
6326  SCIPconsIsStickingAtNode(conss[c])) ); /*lint !e613*/
6327  SCIP_CALL( SCIPaddCoefLinear(scip, lincons, consdata->x, 1.0) );
6328  }
6329  SCIP_CALL( SCIPaddCons(scip, lincons) );
6330 
6331  SCIPdebugMessage("upgraded constraint <%s> to linear constraint due to binary x-variable\n", SCIPconsGetName(conss[c])); /*lint !e613*/
6332  SCIPdebugPrintCons(scip, conss[c], NULL); /*lint !e613*/
6333  SCIPdebugPrintCons(scip, lincons, NULL);
6334 
6335  SCIP_CALL( SCIPreleaseCons(scip, &lincons) );
6336 
6337  SCIP_CALL( SCIPdelCons(scip, conss[c]) ); /*lint !e613*/
6338  ++*nupgdconss;
6339  continue;
6340  }
6341 
6342  /* run domain propagation, also checks for redundancy */
6343  localnchgbds = 0;
6344  localnaddconss = 0;
6345  SCIP_CALL( propagateCons(scip, conshdlr, conss[c], TRUE, &infeas, &localnchgbds, &localnaddconss) ); /*lint !e613*/
6346  if( infeas )
6347  {
6348  SCIPdebugMessage("propagation on constraint <%s> says problem is infeasible in presolve\n", SCIPconsGetName(conss[c])); /*lint !e613*/
6349  *result = SCIP_CUTOFF;
6350  return SCIP_OKAY;
6351  }
6352  if( localnchgbds > 0 || localnaddconss > 0 )
6353  {
6354  *nchgbds += localnchgbds;
6355  *naddconss += localnaddconss;
6356  *result = SCIP_SUCCESS;
6357  }
6358  if( SCIPconsIsDeleted(conss[c]) ) /*lint !e613*/
6359  {
6360  ++*ndelconss;
6361  *result = SCIP_SUCCESS;
6362  continue;
6363  }
6364 
6365  if( conshdlrdata->dualpresolve && SCIPallowDualReds(scip) )
6366  {
6367  /* check if a variable can be fixed because it appears in no other constraint */
6368  SCIP_CALL( presolveDual(scip, conss[c], &infeas, ndelconss, nfixedvars) ); /*lint !e613*/
6369  if( infeas )
6370  {
6371  SCIPdebugMessage("dual presolve on constraint <%s> says problem is infeasible in presolve\n", SCIPconsGetName(conss[c])); /*lint !e613*/
6372  *result = SCIP_CUTOFF;
6373  return SCIP_OKAY;
6374  }
6375  if( SCIPconsIsDeleted(conss[c]) ) /*lint !e613*/
6376  {
6377  *result = SCIP_SUCCESS;
6378  continue;
6379  }
6380  }
6381 
6382  /* propagate variable bound constraints */
6383  if( !consdata->propvarbounds && SCIPallowObjProp(scip) )
6384  {
6385  SCIP_CALL( propagateVarbounds(scip, conshdlr, conss[c], &infeas, nchgbds, naddconss) ); /*lint !e613*/
6386 
6387  if( infeas )
6388  {
6389  *result = SCIP_CUTOFF;
6390  return SCIP_OKAY;
6391  }
6392 
6393  consdata->propvarbounds = TRUE;
6394  }
6395 
6396  /* check if we can make z implicit integer
6397  * if constraint is signpow(x,n) + c*z = rhs with x integer, |c| = 1, rhs and n integral, then z is implicit integral
6398  */
6399  if( SCIPvarGetType(consdata->z) == SCIP_VARTYPE_CONTINUOUS && SCIPvarGetType(consdata->x) != SCIP_VARTYPE_CONTINUOUS &&
6400  SCIPisEQ(scip, consdata->lhs, consdata->rhs) && SCIPisIntegral(scip, consdata->rhs) && SCIPisEQ(scip, REALABS(consdata->zcoef), 1.0) && SCIPisIntegral(scip, consdata->exponent)
6401  )
6402  {
6403  SCIPdebugMessage("make z = <%s> implicit integer in cons <%s>\n", SCIPvarGetName(consdata->z), SCIPconsGetName(conss[c])); /*lint !e613*/
6404  SCIPdebugPrintCons(scip, conss[c], NULL); /*lint !e613*/
6405  SCIP_CALL( SCIPchgVarType(scip, consdata->z, SCIP_VARTYPE_IMPLINT, &infeas) );
6406  if( infeas )
6407  {
6408  SCIPdebugMessage("problem found infeasible in presolve when making <%s> implicit integer\n", SCIPvarGetName(consdata->z));
6409  *result = SCIP_CUTOFF;
6410  return SCIP_OKAY;
6411  }
6412  else
6413  {
6414  ++*nchgvartypes;
6415  }
6416  }
6417  }
6418 
6419  return SCIP_OKAY;
6420 }
6421 
6422 /** resolves a propagation on the given variable by supplying the variables needed for applying the corresponding
6423  * propagation rule (see propagateCons()):
6424  * (1) left hand side and bounds on z -> lower bound on x
6425  * (2) left hand side and upper bound on x -> bound on z
6426  * (3) right hand side and bounds on z -> upper bound on x
6427  * (4) right hand side and lower bound on x -> bound on z
6428  */
6429 static
6430 SCIP_DECL_CONSRESPROP(consRespropAbspower)
6432  assert(result != NULL);
6433 
6434  SCIP_CALL( resolvePropagation(scip, cons, infervar, (PROPRULE)inferinfo, boundtype, bdchgidx) );
6435 
6436  *result = SCIP_SUCCESS;
6437 
6438  return SCIP_OKAY;
6439 } /*lint !e715*/
6440 
6441 /** variable rounding lock method of constraint handler */
6442 static
6443 SCIP_DECL_CONSLOCK(consLockAbspower)
6444 { /*lint --e{715}*/
6445  SCIP_CONSDATA* consdata;
6446  SCIP_Bool haslb;
6447  SCIP_Bool hasub;
6448 
6449  assert(scip != NULL);
6450  assert(cons != NULL);
6451 
6452  consdata = SCIPconsGetData(cons);
6453  assert(consdata != NULL);
6454 
6455  haslb = !SCIPisInfinity(scip, -consdata->lhs);
6456  hasub = !SCIPisInfinity(scip, consdata->rhs);
6457 
6458  if( consdata->x != NULL )
6459  {
6460  if( haslb )
6461  {
6462  SCIP_CALL( SCIPaddVarLocks(scip, consdata->x, nlockspos, nlocksneg) );
6463  }
6464  if( hasub )
6465  {
6466  SCIP_CALL( SCIPaddVarLocks(scip, consdata->x, nlocksneg, nlockspos) );
6467  }
6468  }
6469 
6470  if( consdata->z != NULL )
6471  {
6472  if( consdata->zcoef > 0 )
6473  {
6474  if( haslb )
6475  {
6476  SCIP_CALL( SCIPaddVarLocks(scip, consdata->z, nlockspos, nlocksneg) );
6477  }
6478  if( hasub )
6479  {
6480  SCIP_CALL( SCIPaddVarLocks(scip, consdata->z, nlocksneg, nlockspos) );
6481  }
6482  }
6483  else
6484  {
6485  if( haslb )
6486  {
6487  SCIP_CALL( SCIPaddVarLocks(scip, consdata->z, nlocksneg, nlockspos) );
6488  }
6489  if( hasub )
6490  {
6491  SCIP_CALL( SCIPaddVarLocks(scip, consdata->z, nlockspos, nlocksneg) );
6492  }
6493  }
6494  }
6495 
6496  return SCIP_OKAY;
6497 }
6498 
6499 /** constraint activation notification method of constraint handler */
6500 static
6501 SCIP_DECL_CONSACTIVE(consActiveAbspower)
6502 { /*lint --e{715}*/
6503  SCIP_CONSHDLRDATA* conshdlrdata;
6504 
6505  assert(conshdlr != NULL);
6506 
6507  conshdlrdata = SCIPconshdlrGetData(conshdlr);
6508  assert(conshdlrdata != NULL);
6509 
6510  /* (re)run constraint comparison, since new constraint is added */
6511  conshdlrdata->comparedpairwise = FALSE;
6512 
6513  return SCIP_OKAY;
6514 }
6515 
6516 /** constraint enabling notification method of constraint handler */
6517 static
6518 SCIP_DECL_CONSENABLE(consEnableAbspower)
6519 { /*lint --e{715}*/
6520  SCIP_CONSHDLRDATA* conshdlrdata;
6521 
6522  assert(scip != NULL);
6523  assert(cons != NULL);
6524  assert(conshdlr != NULL);
6525 
6526  conshdlrdata = SCIPconshdlrGetData(conshdlr);
6527  assert(conshdlrdata != NULL);
6528  assert(conshdlrdata->eventhdlr != NULL);
6529 
6530  SCIP_CALL( catchVarEvents(scip, conshdlrdata->eventhdlr, cons) );
6531 
6532  return SCIP_OKAY;
6533 }
6534 
6535 /** constraint disabling notification method of constraint handler */
6536 static
6537 SCIP_DECL_CONSDISABLE(consDisableAbspower)
6538 { /*lint --e{715}*/
6539  SCIP_CONSHDLRDATA* conshdlrdata;
6540 
6541  assert(scip != NULL);
6542  assert(cons != NULL);
6543  assert(conshdlr != NULL);
6544 
6545  conshdlrdata = SCIPconshdlrGetData(conshdlr);
6546  assert(conshdlrdata != NULL);
6547  assert(conshdlrdata->eventhdlr != NULL);
6548 
6549  SCIP_CALL( dropVarEvents(scip, conshdlrdata->eventhdlr, cons) );
6550 
6551  return SCIP_OKAY;
6552 }
6553 
6554 /** constraint display method of constraint handler */
6555 static
6556 SCIP_DECL_CONSPRINT(consPrintAbspower)
6557 { /*lint --e{715}*/
6558  SCIP_CONSDATA* consdata;
6559 
6560  assert(scip != NULL);
6561  assert(cons != NULL);
6562 
6563  consdata = SCIPconsGetData(cons);
6564  assert(consdata != NULL);
6565 
6566  /* print left hand side for ranged rows */
6567  if( !SCIPisInfinity(scip, -consdata->lhs)
6568  && !SCIPisInfinity(scip, consdata->rhs)
6569  && !SCIPisEQ(scip, consdata->lhs, consdata->rhs) )
6570  SCIPinfoMessage(scip, file, "%.15g <= ", consdata->lhs);
6571 
6572  /* print coefficients and variables */
6573  SCIPinfoMessage(scip, file, "signpower(");
6574  SCIP_CALL( SCIPwriteVarName(scip, file, consdata->x, TRUE) );
6575  SCIPinfoMessage(scip, file, " %+.15g, %.15g) ", consdata->xoffset, consdata->exponent);
6576 
6577  SCIPinfoMessage(scip, file, "%+.15g", consdata->zcoef);
6578  SCIP_CALL( SCIPwriteVarName(scip, file, consdata->z, TRUE) );
6579 
6580  /* print right hand side */
6581  if( SCIPisEQ(scip, consdata->lhs, consdata->rhs) )
6582  {
6583  SCIPinfoMessage(scip, file, " == %.15g", consdata->rhs);
6584  }
6585  else if( !SCIPisInfinity(scip, consdata->rhs) )
6586  {
6587  SCIPinfoMessage(scip, file, " <= %.15g", consdata->rhs);
6588  }
6589  else if( !SCIPisInfinity(scip, -consdata->lhs) )
6590  {
6591  SCIPinfoMessage(scip, file, " >= %.15g", consdata->lhs);
6592  }
6593  else
6594  {
6595  SCIPinfoMessage(scip, file, " [free]");
6596  }
6597 
6598  return SCIP_OKAY;
6599 }
6600 
6601 /** feasibility check method of constraint handler for integral solutions */
6602 static
6603 SCIP_DECL_CONSCHECK(consCheckAbspower)
6604 { /*lint --e{715}*/
6605  SCIP_CONSHDLRDATA* conshdlrdata;
6606  SCIP_CONSDATA* consdata;
6607  SCIP_Bool dolinfeasshift;
6608  SCIP_Real maxviol;
6609  SCIP_Real viol;
6610  int c;
6611 
6612  assert(scip != NULL);
6613  assert(conss != NULL || nconss == 0);
6614  assert(result != NULL);
6615 
6616  conshdlrdata = SCIPconshdlrGetData(conshdlr);
6617  assert(conshdlrdata != NULL);
6618 
6619  *result = SCIP_FEASIBLE;
6620 
6621  maxviol = 0.0;
6622  viol = SCIP_INVALID;
6623 
6624  dolinfeasshift = conshdlrdata->linfeasshift && (conshdlrdata->trysolheur != NULL) && SCIPgetStage(scip) > SCIP_STAGE_PROBLEM && SCIPgetStage(scip) < SCIP_STAGE_SOLVED;
6625  for( c = 0; c < nconss; ++c )
6626  {
6627  assert(conss != NULL);
6628  SCIP_CALL( computeViolation(scip, conshdlr, conss[c], sol, &viol) );
6629 
6630  consdata = SCIPconsGetData(conss[c]);
6631  assert(consdata != NULL);
6632 
6633  if( SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) || SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
6634  {
6635  *result = SCIP_INFEASIBLE;
6636 
6637  if( printreason )
6638  {
6639  SCIPinfoMessage(scip, NULL, "absolute power constraint <%s> violated by %g (scaled = %g)\n\t",
6640  SCIPconsGetName(conss[c]), viol, MAX(consdata->lhsviol, consdata->rhsviol));
6641  SCIP_CALL( consPrintAbspower(scip, conshdlr, conss[c], NULL) );
6642  SCIPinfoMessage(scip, NULL, ";\n");
6643  }
6644 
6645  if( conshdlrdata->subnlpheur == NULL && !dolinfeasshift )
6646  return SCIP_OKAY;
6647  if( consdata->lhsviol > maxviol || consdata->rhsviol > maxviol )
6648  maxviol = MAX(consdata->lhsviol, consdata->rhsviol);
6649  }
6650  }
6651 
6652  if( *result == SCIP_INFEASIBLE && dolinfeasshift )
6653  {
6654  SCIP_CALL( proposeFeasibleSolution(scip, conshdlr, conss, nconss, sol) );
6655  }
6656 
6657  if( *result == SCIP_INFEASIBLE && conshdlrdata->subnlpheur != NULL && sol != NULL )
6658  {
6659  SCIP_CALL( SCIPupdateStartpointHeurSubNlp(scip, conshdlrdata->subnlpheur, sol, maxviol) );
6660  }
6661 
6662  return SCIP_OKAY;
6663 }
6664 
6665 /** constraint copying method of constraint handler */
6666 static
6667 SCIP_DECL_CONSCOPY(consCopyAbspower)
6668 { /*lint --e{715}*/
6669  SCIP_CONSDATA* consdata;
6670  SCIP_VAR* x;
6671  SCIP_VAR* z;
6672 
6673  assert(scip != NULL);
6674  assert(cons != NULL);
6675  assert(sourcescip != NULL);
6676  assert(sourcecons != NULL);
6677  assert(varmap != NULL);
6678  assert(valid != NULL);
6679 
6680  consdata = SCIPconsGetData(sourcecons);
6681  assert(consdata != NULL);
6682 
6683  *valid = TRUE;
6684  *cons = NULL;
6685 
6686  SCIP_CALL( SCIPgetVarCopy(sourcescip, scip, consdata->x, &x, varmap, consmap, global, valid) );
6687 
6688  if( *valid )
6689  {
6690  SCIP_CALL( SCIPgetVarCopy(sourcescip, scip, consdata->z, &z, varmap, consmap, global, valid) );
6691  }
6692 
6693  if( *valid )
6694  {
6695  SCIP_CALL( SCIPcreateConsAbspower(scip, cons, name != NULL ? name : SCIPconsGetName(sourcecons),
6696  x, z, consdata->exponent, consdata->xoffset, consdata->zcoef, consdata->lhs, consdata->rhs,
6697  initial, separate, enforce, check, propagate, local, FALSE, dynamic, removable, stickingatnode) ); /*lint !e644*/
6698  }
6699 
6700  return SCIP_OKAY;
6701 }
6702 
6703 /** constraint parsing method of constraint handler */
6704 static
6705 SCIP_DECL_CONSPARSE(consParseAbspower)
6707  SCIP_Real lhs;
6708  SCIP_Real rhs;
6709  SCIP_Real xoffset;
6710  SCIP_Real exponent;
6711  SCIP_Real zcoef;
6712  SCIP_Real value;
6713  char* endptr;
6714  char sense;
6715  SCIP_VAR* x;
6716  SCIP_VAR* z;
6717 
6718  *success = TRUE;
6719 
6720  /* set right hand and left side to their default values */
6721  lhs = -SCIPinfinity(scip);
6722  rhs = SCIPinfinity(scip);
6723 
6724  SCIPdebugMessage("start parsing absolute power constraint expression %s\n", str);
6725 
6726  if( strncmp(str, "signpower(", 10) != 0 )
6727  {
6728  /* str does not start with signpower string, so may be left-hand-side of ranged constraint */
6729  if( !SCIPstrToRealValue(str, &lhs, &endptr) )
6730  {
6731  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "Syntax error: left-hand-side or 'signpower(' expected at begin on '%s'\n", str);
6732  *success = FALSE;
6733  return SCIP_OKAY;
6734  }
6735  str = endptr;
6736  }
6737  else
6738  {
6739  str += 10;
6740  }
6741 
6742  /* parse (x +offset, exponent) +coef z */
6743 
6744  /* parse variable name */
6745  SCIP_CALL( SCIPparseVarName(scip, str, &x, &endptr) );
6746  if( x == NULL )
6747  {
6748  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "unknown variable name at '%s'\n", str);
6749  *success = FALSE;
6750  return SCIP_OKAY;
6751  }
6752  str = endptr;
6753 
6754  /* skip whitespace */
6755  while( isspace((int)*str) )
6756  ++str;
6757 
6758  /* parse offset */
6759  if( !SCIPstrToRealValue(str, &xoffset, &endptr) )
6760  {
6761  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "expected coefficient at begin of '%s'\n", str);
6762  *success = FALSE;
6763  return SCIP_OKAY;
6764  }
6765  str = endptr;
6766 
6767  if( *str != ',' )
6768  {
6769  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "expected ',' at begin of '%s'\n", str);
6770  *success = FALSE;
6771  return SCIP_OKAY;
6772  }
6773  ++str;
6774 
6775  /* skip whitespace */
6776  while( isspace((int)*str) )
6777  ++str;
6778 
6779  /* parse exponent */
6780  if( !SCIPstrToRealValue(str, &exponent, &endptr) )
6781  {
6782  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "expected coefficient at begin of '%s'\n", str);
6783  *success = FALSE;
6784  return SCIP_OKAY;
6785  }
6786  str = endptr;
6787 
6788  if( *str != ')' )
6789  {
6790  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "expected ')' at begin of '%s'\n", str);
6791  *success = FALSE;
6792  return SCIP_OKAY;
6793  }
6794  ++str;
6795 
6796  /* skip whitespace */
6797  while( isspace((int)*str) )
6798  ++str;
6799 
6800  /* parse coefficient */
6801  if( !SCIPstrToRealValue(str, &zcoef, &endptr) )
6802  {
6803  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "expected coefficient at begin of '%s'\n", str);
6804  *success = FALSE;
6805  return SCIP_OKAY;
6806  }
6807  str = endptr;
6808 
6809  /* parse variable name */
6810  SCIP_CALL( SCIPparseVarName(scip, str, &z, &endptr) );
6811  if( z == NULL )
6812  {
6813  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "unknown variable name at '%s'\n", str);
6814  *success = FALSE;
6815  return SCIP_OKAY;
6816  }
6817  str = endptr;
6818 
6819  /* skip whitespace */
6820  while( isspace((int)*str) )
6821  ++str;
6822 
6823  if( strncmp(str, "[free]", 6) != 0 )
6824  {
6825  /* parse sense */
6826  if( (*str != '<' && *str != '>' && *str != '=') || str[1] != '=' )
6827  {
6828  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "expected sense at begin of '%s'\n", str);
6829  *success = FALSE;
6830  return SCIP_OKAY;
6831  }
6832  sense = *str;
6833  str += 2;
6834 
6835  /* parse value at rhs */
6836  if( !SCIPstrToRealValue(str, &value, &endptr) )
6837  {
6838  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "expected rhs value at begin of '%s'\n", str);
6839  *success = FALSE;
6840  return SCIP_OKAY;
6841  }
6842 
6843  switch( sense )
6844  {
6845  case '<' :
6846  rhs = value;
6847  break;
6848  case '>' :
6849  lhs = value;
6850  break;
6851  case '=' :
6852  lhs = rhs = value;
6853  break;
6854  default:
6855  SCIPABORT(); /* checked above that this cannot happen */
6856  return SCIP_INVALIDDATA; /*lint !e527*/
6857  }
6858  }
6859 
6860  SCIP_CALL( SCIPcreateConsAbspower(scip, cons, name, x, z, exponent, xoffset, zcoef, lhs, rhs,
6861  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode) );
6862 
6863  return SCIP_OKAY;
6864 } /*lint !e715*/
6865 
6866 /** constraint method of constraint handler which returns the variables (if possible) */
6867 static
6868 SCIP_DECL_CONSGETVARS(consGetVarsAbspower)
6869 { /*lint --e{715}*/
6870 
6871  if( varssize < 2 )
6872  (*success) = FALSE;
6873  else
6874  {
6875  SCIP_CONSDATA* consdata;
6876  assert(cons != NULL);
6877  assert(vars != NULL);
6878 
6879  consdata = SCIPconsGetData(cons);
6880  assert(consdata != NULL);
6881 
6882  vars[0] = consdata->x;
6883  vars[1] = consdata->z;
6884  (*success) = TRUE;
6885  }
6886 
6887  return SCIP_OKAY;
6888 }
6889 
6890 /** constraint method of constraint handler which returns the number of variables (if possible) */
6891 static
6892 SCIP_DECL_CONSGETNVARS(consGetNVarsAbspower)
6893 { /*lint --e{715}*/
6894  (*nvars) = 2;
6895  (*success) = TRUE;
6896 
6897  return SCIP_OKAY;
6898 }
6899 
6900 /*
6901  * constraint specific interface methods
6902  */
6903 
6904 /** creates the handler for absolute power constraints and includes it in SCIP */
6906  SCIP* scip /**< SCIP data structure */
6907  )
6908 {
6909  SCIP_CONSHDLRDATA* conshdlrdata;
6910  SCIP_CONSHDLR* conshdlr;
6911  SCIP_EVENTHDLR* eventhdlr;
6912 
6913  /* create absolute power constraint handler data */
6914  SCIP_CALL( SCIPallocMemory(scip, &conshdlrdata) );
6915  BMSclearMemory(conshdlrdata);
6916 
6917  /* include constraint handler */
6920  consEnfolpAbspower, consEnfopsAbspower, consCheckAbspower, consLockAbspower,
6921  conshdlrdata) );
6922 
6923  assert(conshdlr != NULL);
6924 
6925 
6926  /* set non-fundamental callbacks via specific setter functions */
6927  SCIP_CALL( SCIPsetConshdlrActive(scip, conshdlr, consActiveAbspower) );
6928  SCIP_CALL( SCIPsetConshdlrCopy(scip, conshdlr, conshdlrCopyAbspower, consCopyAbspower) );
6929  SCIP_CALL( SCIPsetConshdlrDelete(scip, conshdlr, consDeleteAbspower) );
6930  SCIP_CALL( SCIPsetConshdlrDisable(scip, conshdlr, consDisableAbspower) );
6931  SCIP_CALL( SCIPsetConshdlrEnable(scip, conshdlr, consEnableAbspower) );
6932  SCIP_CALL( SCIPsetConshdlrExit(scip, conshdlr, consExitAbspower) );
6933  SCIP_CALL( SCIPsetConshdlrExitpre(scip, conshdlr, consExitpreAbspower) );
6934  SCIP_CALL( SCIPsetConshdlrExitsol(scip, conshdlr, consExitsolAbspower) );
6935  SCIP_CALL( SCIPsetConshdlrFree(scip, conshdlr, consFreeAbspower) );
6936  SCIP_CALL( SCIPsetConshdlrGetVars(scip, conshdlr, consGetVarsAbspower) );
6937  SCIP_CALL( SCIPsetConshdlrGetNVars(scip, conshdlr, consGetNVarsAbspower) );
6938  SCIP_CALL( SCIPsetConshdlrInit(scip, conshdlr, consInitAbspower) );
6939  SCIP_CALL( SCIPsetConshdlrInitpre(scip, conshdlr, consInitpreAbspower) );
6940  SCIP_CALL( SCIPsetConshdlrInitsol(scip, conshdlr, consInitsolAbspower) );
6941  SCIP_CALL( SCIPsetConshdlrInitlp(scip, conshdlr, consInitlpAbspower) );
6942  SCIP_CALL( SCIPsetConshdlrParse(scip, conshdlr, consParseAbspower) );
6943  SCIP_CALL( SCIPsetConshdlrPresol(scip, conshdlr, consPresolAbspower, CONSHDLR_MAXPREROUNDS, CONSHDLR_PRESOLTIMING) );
6944  SCIP_CALL( SCIPsetConshdlrPrint(scip, conshdlr, consPrintAbspower) );
6945  SCIP_CALL( SCIPsetConshdlrProp(scip, conshdlr, consPropAbspower, CONSHDLR_PROPFREQ, CONSHDLR_DELAYPROP,
6947  SCIP_CALL( SCIPsetConshdlrResprop(scip, conshdlr, consRespropAbspower) );
6948  SCIP_CALL( SCIPsetConshdlrSepa(scip, conshdlr, consSepalpAbspower, consSepasolAbspower, CONSHDLR_SEPAFREQ,
6950  SCIP_CALL( SCIPsetConshdlrTrans(scip, conshdlr, consTransAbspower) );
6951 
6952  /* include the quadratic constraint upgrade in the quadratic constraint handler */
6954 
6955  /* include the absolute power constraint upgrade and node reform in the nonlinear constraint handler
6956  * we give it higher priority as quadratic, so it also takes care of x^2 constraints, if possible
6957  */
6958  SCIP_CALL( SCIPincludeNonlinconsUpgrade(scip, nonlinconsUpgdAbspower, exprgraphnodeReformAbspower, NONLINCONSUPGD_PRIORITY, TRUE, CONSHDLR_NAME) );
6959 
6960  /* add absolute power constraint handler parameters */
6961  SCIP_CALL( SCIPaddRealParam(scip, "constraints/" CONSHDLR_NAME "/minefficacysepa",
6962  "minimal efficacy for a cut to be added to the LP during separation; overwrites separating/efficacy",
6963  &conshdlrdata->mincutefficacysepa, FALSE, 0.0001, 0.0, SCIPinfinity(scip), NULL, NULL) );
6964 
6965  SCIP_CALL( SCIPaddRealParam(scip, "constraints/" CONSHDLR_NAME "/minefficacyenfofac",
6966  "minimal target efficacy of a cut in order to add it to relaxation during enforcement as factor of feasibility tolerance (may be ignored)",
6967  &conshdlrdata->mincutefficacyenfofac, FALSE, 2.0, 1.0, SCIPinfinity(scip), NULL, NULL) );
6968 
6969  SCIP_CALL( SCIPaddCharParam(scip, "constraints/" CONSHDLR_NAME "/scaling",
6970  "whether scaling of infeasibility is 'o'ff, by sup-norm of function 'g'radient, or by left/right hand 's'ide",
6971  &conshdlrdata->scaling, TRUE, 'o', "ogs", NULL, NULL) );
6972 
6973  SCIP_CALL( SCIPaddRealParam(scip, "constraints/" CONSHDLR_NAME "/cutmaxrange",
6974  "maximal coef range of a cut (maximal coefficient divided by minimal coefficient) in order to be added to LP relaxation",
6975  &conshdlrdata->cutmaxrange, FALSE, 1e+7, 0.0, SCIPinfinity(scip), NULL, NULL) );
6976 
6977  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/projectrefpoint",
6978  "whether to project the reference point when linearizing an absolute power constraint in a convex region",
6979  &conshdlrdata->projectrefpoint, FALSE, TRUE, NULL, NULL) );
6980 
6981  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/preferzerobranch",
6982  "how much to prefer branching on 0.0 when sign of variable is not fixed yet: 0 no preference, 1 prefer if LP solution will be cutoff in both child nodes, 2 prefer always, 3 ensure always",
6983  &conshdlrdata->preferzerobranch, FALSE, 1, 0, 3, NULL, NULL) );
6984 
6985  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/branchminconverror",
6986  "whether to compute branching point such that the convexification error is minimized (after branching on 0.0)",
6987  &conshdlrdata->branchminconverror, FALSE, FALSE, NULL, NULL) );
6988 
6989  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/addvarboundcons",
6990  "should variable bound constraints be added for derived variable bounds?",
6991  &conshdlrdata->addvarboundcons, TRUE, TRUE, NULL, NULL) );
6992 
6993  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/linfeasshift",
6994  "whether to try to make solutions in check function feasible by shifting the linear variable z",
6995  &conshdlrdata->linfeasshift, FALSE, TRUE, NULL, NULL) );
6996 
6997  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/dualpresolve",
6998  "should dual presolve be applied?",
6999  &conshdlrdata->dualpresolve, FALSE, TRUE, NULL, NULL) );
7000 
7001  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/sepainboundsonly",
7002  "whether to separate linearization cuts only in the variable bounds (does not affect enforcement)",
7003  &conshdlrdata->sepainboundsonly, FALSE, FALSE, NULL, NULL) );
7004 
7005  SCIP_CALL( SCIPaddRealParam(scip, "constraints/" CONSHDLR_NAME "/sepanlpmincont",
7006  "minimal required fraction of continuous variables in problem to use solution of NLP relaxation in root for separation",
7007  &conshdlrdata->sepanlpmincont, FALSE, 1.0, 0.0, 2.0, NULL, NULL) );
7008 
7009  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/enfocutsremovable",
7010  "are cuts added during enforcement removable from the LP in the same node?",
7011  &conshdlrdata->enfocutsremovable, TRUE, FALSE, NULL, NULL) );
7012 
7013  SCIP_CALL( SCIPincludeEventhdlrBasic(scip, &eventhdlr, CONSHDLR_NAME, "signals a bound change on a variable to an absolute power constraint",
7014  processVarEvent, NULL) );
7015  conshdlrdata->eventhdlr = eventhdlr;
7016 
7017  SCIP_CALL( SCIPincludeEventhdlrBasic(scip, NULL, CONSHDLR_NAME"_newsolution", "handles the event that a new primal solution has been found",
7018  processNewSolutionEvent, NULL) );
7019 
7020  return SCIP_OKAY;
7021 }
7022 
7023 /** creates and captures a absolute power constraint
7024  *
7025  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
7026  */
7028  SCIP* scip, /**< SCIP data structure */
7029  SCIP_CONS** cons, /**< pointer to hold the created constraint */
7030  const char* name, /**< name of constraint */
7031  SCIP_VAR* x, /**< nonlinear variable x in constraint */
7032  SCIP_VAR* z, /**< linear variable z in constraint */
7033  SCIP_Real exponent, /**< exponent n of |x+offset|^n term in constraint */
7034  SCIP_Real xoffset, /**< offset in |x+offset|^n term in constraint */
7035  SCIP_Real zcoef, /**< coefficient of z in constraint */
7036  SCIP_Real lhs, /**< left hand side of constraint */
7037  SCIP_Real rhs, /**< right hand side of constraint */
7038  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
7039  * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
7040  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
7041  * Usually set to TRUE. */
7042  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
7043  * TRUE for model constraints, FALSE for additional, redundant constraints. */
7044  SCIP_Bool check, /**< should the constraint be checked for feasibility?
7045  * TRUE for model constraints, FALSE for additional, redundant constraints. */
7046  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
7047  * Usually set to TRUE. */
7048  SCIP_Bool local, /**< is constraint only valid locally?
7049  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
7050  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
7051  * Usually set to FALSE. In column generation applications, set to TRUE if pricing
7052  * adds coefficients to this constraint. */
7053  SCIP_Bool dynamic, /**< is constraint subject to aging?
7054  * Usually set to FALSE. Set to TRUE for own cuts which
7055  * are seperated as constraints. */
7056  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
7057  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
7058  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
7059  * if it may be moved to a more global node?
7060  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
7061  )
7062 {
7063  SCIP_CONSHDLR* conshdlr;
7064  SCIP_CONSDATA* consdata;
7065 
7066  assert(x != NULL);
7067  assert(z != NULL);
7068  assert(exponent > 1.0);
7069  assert(!SCIPisZero(scip, zcoef));
7070  assert(!SCIPisInfinity(scip, REALABS(zcoef)));
7071  assert(!modifiable); /* we do not support column generation */
7072 
7073  /* find the absolute power constraint handler */
7074  conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME);
7075  if( conshdlr == NULL )
7076  {
7077  SCIPerrorMessage("absolute power constraint handler not found\n");
7078  return SCIP_PLUGINNOTFOUND;
7079  }
7080 
7081  /* create constraint data */
7082  SCIP_CALL( SCIPallocMemory( scip, &consdata) );
7083  BMSclearMemory(consdata);
7084  consdata->xeventfilterpos = -1;
7085  consdata->zeventfilterpos = -1;
7086 
7087  consdata->x = x;
7088  consdata->z = z;
7089  consdata->xoffset = xoffset;
7090  consdata->zcoef = zcoef;
7091  consdata->lhs = lhs;
7092  consdata->rhs = rhs;
7093 
7094  if( SCIPisEQ(scip, exponent, 2.0) )
7095  {
7096  consdata->exponent = 2.0;
7097  consdata->power = square;
7098  }
7099  else
7100  {
7101  consdata->exponent = exponent;
7102  consdata->power = pow;
7103  }
7104 
7105  /* branching on multiaggregated variables does not seem to work well, so try to avoid multiagg. x */
7106  if( SCIPvarIsActive(x) )
7107  SCIP_CALL( SCIPmarkDoNotMultaggrVar(scip, x) );
7108 
7109  /* cannot propagate on multiaggregated vars, so avoid multiagg. z */
7110  if( SCIPvarIsActive(z) )
7111  SCIP_CALL( SCIPmarkDoNotMultaggrVar(scip, z) );
7112 
7113  /* create constraint */
7114  SCIP_CALL( SCIPcreateCons(scip, cons, name, conshdlr, consdata, initial, separate, enforce, check, propagate,
7115  local, modifiable, dynamic, removable, stickingatnode) );
7116 
7117  return SCIP_OKAY;
7118 }
7119 
7120 /** creates and captures an absolute power constraint
7121  * in its most basic version, i. e., all constraint flags are set to their basic value as explained for the
7122  * method SCIPcreateConsAbspower(); all flags can be set via SCIPsetConsFLAGNAME-methods in scip.h
7123  *
7124  * @see SCIPcreateConsAbspower() for information about the basic constraint flag configuration
7125  *
7126  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
7127  */
7129  SCIP* scip, /**< SCIP data structure */
7130  SCIP_CONS** cons, /**< pointer to hold the created constraint */
7131  const char* name, /**< name of constraint */
7132  SCIP_VAR* x, /**< nonlinear variable x in constraint */
7133  SCIP_VAR* z, /**< linear variable z in constraint */
7134  SCIP_Real exponent, /**< exponent n of |x+offset|^n term in constraint */
7135  SCIP_Real xoffset, /**< offset in |x+offset|^n term in constraint */
7136  SCIP_Real zcoef, /**< coefficient of z in constraint */
7137  SCIP_Real lhs, /**< left hand side of constraint */
7138  SCIP_Real rhs /**< right hand side of constraint */
7139  )
7140 {
7141  assert(scip != NULL);
7142 
7143  SCIP_CALL( SCIPcreateConsAbspower(scip, cons, name, x, z, exponent, xoffset, zcoef, lhs, rhs,
7144  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
7145 
7146  return SCIP_OKAY;
7147 }
7148 
7149 /** gets the absolute power constraint as a nonlinear row representation */
7151  SCIP* scip, /**< SCIP data structure */
7152  SCIP_CONS* cons, /**< constraint */
7153  SCIP_NLROW** nlrow /**< a buffer where to store pointer to nonlinear row */
7154  )
7155 {
7156  SCIP_CONSDATA* consdata;
7157 
7158  assert(cons != NULL);
7159  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
7160  assert(nlrow != NULL);
7161 
7162  consdata = SCIPconsGetData(cons);
7163  assert(consdata != NULL);
7164 
7165  if( consdata->nlrow == NULL )
7166  {
7167  SCIP_CALL( createNlRow(scip, cons) );
7168  }
7169  assert(consdata->nlrow != NULL);
7170  *nlrow = consdata->nlrow;
7171 
7172  return SCIP_OKAY;
7173 }
7174 
7175 /** gets nonlinear variable x in absolute power constraint */
7177  SCIP* scip, /**< SCIP data structure */
7178  SCIP_CONS* cons /**< absolute power constraint */
7179  )
7180 {
7181  SCIP_CONSDATA* consdata;
7182 
7183  assert(cons != NULL);
7184  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
7185 
7186  consdata = SCIPconsGetData(cons);
7187  assert(consdata != NULL);
7188 
7189  return consdata->x;
7190 }
7191 
7192 /** gets linear variable z in absolute power constraint */
7194  SCIP* scip, /**< SCIP data structure */
7195  SCIP_CONS* cons /**< absolute power constraint */
7196  )
7197 {
7198  SCIP_CONSDATA* consdata;
7199 
7200  assert(cons != NULL);
7201  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
7202 
7203  consdata = SCIPconsGetData(cons);
7204  assert(consdata != NULL);
7205 
7206  return consdata->z;
7207 }
7208 
7209 /** gets exponent in power term in absolute power constraint */
7211  SCIP* scip, /**< SCIP data structure */
7212  SCIP_CONS* cons /**< absolute power constraint */
7213  )
7214 {
7215  SCIP_CONSDATA* consdata;
7216 
7217  assert(cons != NULL);
7218  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
7219 
7220  consdata = SCIPconsGetData(cons);
7221  assert(consdata != NULL);
7222 
7223  return consdata->exponent;
7224 }
7225 
7226 /** gets offset in power term in absolute power constraint */
7228  SCIP* scip, /**< SCIP data structure */
7229  SCIP_CONS* cons /**< absolute power constraint */
7230  )
7231 {
7232  SCIP_CONSDATA* consdata;
7233 
7234  assert(cons != NULL);
7235  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
7236 
7237  consdata = SCIPconsGetData(cons);
7238  assert(consdata != NULL);
7239 
7240  return consdata->xoffset;
7241 }
7242 
7243 /** gets coefficient of linear variable in absolute power constraint */
7245  SCIP* scip, /**< SCIP data structure */
7246  SCIP_CONS* cons /**< absolute power constraint */
7247  )
7248 {
7249  SCIP_CONSDATA* consdata;
7250 
7251  assert(cons != NULL);
7252  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
7253 
7254  consdata = SCIPconsGetData(cons);
7255  assert(consdata != NULL);
7256 
7257  return consdata->zcoef;
7258 }
7259 
7260 /** gets left hand side in absolute power constraint */
7262  SCIP* scip, /**< SCIP data structure */
7263  SCIP_CONS* cons /**< absolute power constraint */
7264  )
7265 {
7266  SCIP_CONSDATA* consdata;
7267 
7268  assert(cons != NULL);
7269  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
7270 
7271  consdata = SCIPconsGetData(cons);
7272  assert(consdata != NULL);
7273 
7274  return consdata->lhs;
7275 }
7276 
7277 /** gets right hand side in absolute power constraint */
7279  SCIP* scip, /**< SCIP data structure */
7280  SCIP_CONS* cons /**< absolute power constraint */
7281  )
7282 {
7283  SCIP_CONSDATA* consdata;
7284 
7285  assert(cons != NULL);
7286  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
7287 
7288  consdata = SCIPconsGetData(cons);
7289  assert(consdata != NULL);
7290 
7291  return consdata->rhs;
7292 }
7293 
7294 /** gets the absolute violation of a absolute power constraint by a solution */
7296  SCIP* scip, /**< SCIP data structure */
7297  SCIP_CONS* cons, /**< absolute power constraint */
7298  SCIP_SOL* sol /**< LP solution */
7299  )
7300 {
7301  SCIP_CONSDATA* consdata;
7302  SCIP_Real z_val;
7303  SCIP_Real x_val;
7304  SCIP_Real rhs;
7305  SCIP_Real proj_val;
7306 
7307  assert(cons != NULL);
7308  assert(strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) == 0);
7309 
7310  consdata = SCIPconsGetData(cons);
7311  assert(consdata != NULL);
7312  assert(consdata->lhs == 0.0);
7313  assert(consdata->rhs == 0.0);
7314 
7315  z_val = SCIPgetSolVal(scip, sol, consdata->z);
7316  x_val = SCIPgetSolVal(scip, sol, consdata->x);
7317 
7318  rhs = -1.0 * consdata->zcoef * z_val;
7319  proj_val = SIGN(rhs) * pow(REALABS(rhs), 1.0 / consdata->exponent) - consdata->xoffset;
7320 
7321  SCIPdebugMessage("computing slack: linear: %f, power: %f, projected: %f\n", z_val, x_val, proj_val);
7322 
7323  return x_val - proj_val;
7324 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:51
SCIP_RETCODE SCIPunlinkSol(SCIP *scip, SCIP_SOL *sol)
Definition: scip.c:34422
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip.c:22764
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41180
enum SCIP_BoundType SCIP_BOUNDTYPE
Definition: type_lp.h:50
SCIP_Real SCIPexprgraphGetNodeVal(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:13078
#define INITLPMAXVARVAL
Definition: cons_abspower.c:66
SCIP_RETCODE SCIPwriteVarName(SCIP *scip, FILE *file, SCIP_VAR *var, SCIP_Bool type)
Definition: scip.c:15939
static SCIP_DECL_HASHGETKEY(presolveFindDuplicatesGetKey)
SCIPInterval square(const SCIPInterval &x)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:41293
SCIP_Real SCIPgetRowSolFeasibility(SCIP *scip, SCIP_ROW *row, SCIP_SOL *sol)
Definition: scip.c:28295
int SCIPgetNVars(SCIP *scip)
Definition: scip.c:10735
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip.c:5847
SCIP_RETCODE SCIPsetConshdlrTrans(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSTRANS((*constrans)))
Definition: scip.c:5557
SCIP_RETCODE SCIPsetConshdlrActive(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSACTIVE((*consactive)))
Definition: scip.c:5626
void SCIPexprgraphSetVarNodeValue(SCIP_EXPRGRAPHNODE *varnode, SCIP_Real value)
Definition: expr.c:14706
SCIP_Bool SCIPintervalIsEmpty(SCIP_Real infinity, SCIP_INTERVAL operand)
SCIP_RETCODE SCIPexprgraphAddNode(SCIP_EXPRGRAPH *exprgraph, SCIP_EXPRGRAPHNODE *node, int mindepth, int nchildren, SCIP_EXPRGRAPHNODE **children)
Definition: expr.c:14906
SCIP_EXPRGRAPH * SCIPgetExprgraphNonlinear(SCIP *scip, SCIP_CONSHDLR *conshdlr)
SCIP_HEUR * SCIPsolGetHeur(SCIP_SOL *sol)
Definition: sol.c:2193
primal heuristic that tries a given solution
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16341
static SCIP_DECL_CONSPROP(consPropAbspower)
#define PROPSIDETOL
Definition: cons_abspower.c:65
static SCIP_RETCODE resolvePropagation(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *infervar, PROPRULE proprule, SCIP_BOUNDTYPE boundtype, SCIP_BDCHGIDX *bdchgidx)
SCIP_RETCODE SCIPexprgraphAddVars(SCIP_EXPRGRAPH *exprgraph, int nvars, void **vars, SCIP_EXPRGRAPHNODE **varnodes)
Definition: expr.c:14990
SCIP_RETCODE SCIPaggregateVars(SCIP *scip, SCIP_VAR *varx, SCIP_VAR *vary, SCIP_Real scalarx, SCIP_Real scalary, SCIP_Real rhs, SCIP_Bool *infeasible, SCIP_Bool *redundant, SCIP_Bool *aggregated)
Definition: scip.c:22873
static SCIP_RETCODE generateSecantCut(SCIP *scip, SCIP_ROW **row, SCIP_CONSHDLR *conshdlr, SCIP_SOL *sol, SCIP_Real xlb, SCIP_Real xub, SCIP_Real exponent, SCIP_Real xoffset, DECL_MYPOW((*mypow)), SCIP_Real xmult, SCIP_Real zcoef, SCIP_Real rhs, SCIP_VAR *x, SCIP_VAR *z)
Constraint handler for variable bound constraints .
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
Definition: scip.c:41256
static SCIP_RETCODE dropVarEvents(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_CONS *cons)
#define PROPVARTOL
Definition: cons_abspower.c:64
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1147
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:1562
SCIP_RETCODE SCIPcreateNLPSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip.c:33682
#define SCIPduplicateMemory(scip, ptr, source)
Definition: scip.h:20367
int SCIPexprgraphGetNodeNChildren(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12716
SCIP_Real SCIPgetRowMinCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:28032
SCIP_QUADVARTERM * SCIPgetQuadVarTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
Definition: scip.c:10415
SCIP_RETCODE SCIPdelCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:11577
static SCIP_DECL_CONSDISABLE(consDisableAbspower)
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:16521
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip.c:1220
SCIP_RETCODE SCIPcreateVar(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype, SCIP_Bool initial, SCIP_Bool removable, SCIP_DECL_VARDELORIG((*vardelorig)), SCIP_DECL_VARTRANS((*vartrans)), SCIP_DECL_VARDELTRANS((*vardeltrans)), SCIP_DECL_VARCOPY((*varcopy)), SCIP_VARDATA *vardata)
Definition: scip.c:15823
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41528
SCIP_Real SCIPgetRelaxFeastolFactor(SCIP *scip)
Definition: scip.c:31157
#define SCIP_MAXSTRLEN
Definition: def.h:198
SCIP_RETCODE SCIPsetConshdlrResprop(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSRESPROP((*consresprop)))
Definition: scip.c:5603
SCIP_RETCODE SCIPsetConshdlrSepa(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSSEPALP((*conssepalp)), SCIP_DECL_CONSSEPASOL((*conssepasol)), int sepafreq, int sepapriority, SCIP_Bool delaysepa)
Definition: scip.c:5215
int SCIPconshdlrGetNConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4292
SCIPInterval pow(const SCIPInterval &x, const SCIPInterval &y)
#define NULL
Definition: lpi_spx.cpp:130
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17011
SCIP_CONS ** SCIPconshdlrGetConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4262
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip.c:1125
static SCIP_DECL_CONSINITPRE(consInitpreAbspower)
SCIP_RETCODE SCIPcreateNlRow(SCIP *scip, SCIP_NLROW **nlrow, const char *name, SCIP_Real constant, int nlinvars, SCIP_VAR **linvars, SCIP_Real *lincoefs, int nquadvars, SCIP_VAR **quadvars, int nquadelems, SCIP_QUADELEM *quadelems, SCIP_EXPRTREE *expression, SCIP_Real lhs, SCIP_Real rhs)
Definition: scip.c:29352
SCIP_Real * SCIPvarGetVubConstants(SCIP_VAR *var)
Definition: var.c:17221
SCIP_Bool SCIPconsIsModifiable(SCIP_CONS *cons)
Definition: cons.c:7853
static SCIP_RETCODE addLinearizationCuts(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS **conss, int nconss, SCIP_SOL *ref, SCIP_Bool *separatedlpsol, SCIP_Real minefficacy)
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:18914
SCIP_VAR ** SCIPvarGetVlbVars(SCIP_VAR *var)
Definition: var.c:17159
static SCIP_DECL_CONSPARSE(consParseAbspower)
SCIP_Bool SCIPconsIsActive(SCIP_CONS *cons)
Definition: cons.c:7685
SCIP_RETCODE SCIPsetConshdlrCopy(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSHDLRCOPY((*conshdlrcopy)), SCIP_DECL_CONSCOPY((*conscopy)))
Definition: scip.c:5303
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:16965
int SCIPnodeGetDepth(SCIP_NODE *node)
Definition: tree.c:7026
SCIP_RETCODE SCIPheurPassSolTrySol(SCIP *scip, SCIP_HEUR *heur, SCIP_SOL *sol)
Definition: heur_trysol.c:236
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip.c:34453
int SCIPvarGetNVubs(SCIP_VAR *var)
Definition: var.c:17189
constraint handler for indicator constraints
SCIP_Bool SCIPisConflictAnalysisApplicable(SCIP *scip)
Definition: scip.c:24307
SCIP_Real SCIPgetExponentAbspower(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPgetProbvarSum(SCIP *scip, SCIP_VAR **var, SCIP_Real *scalar, SCIP_Real *constant)
Definition: scip.c:17512
SCIP_RETCODE SCIPsetConshdlrGetVars(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSGETVARS((*consgetvars)))
Definition: scip.c:5787
SCIP_RETCODE SCIPsetConshdlrEnable(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSENABLE((*consenable)))
Definition: scip.c:5672
SCIP_HEUR * SCIPfindHeur(SCIP *scip, const char *name)
Definition: scip.c:7362
#define FALSE
Definition: def.h:53
SCIP_Real SCIPgetSolTransObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip.c:34723
static SCIP_DECL_CONSINITSOL(consInitsolAbspower)
int SCIPgetNBinVars(SCIP *scip)
Definition: scip.c:10780
static SCIP_DECL_CONSINITLP(consInitlpAbspower)
SCIP_RETCODE SCIPexprtreeSetVars(SCIP_EXPRTREE *tree, int nvars, SCIP_VAR **vars)
Definition: nlp.c:111
static SCIP_DECL_CONSEXITPRE(consExitpreAbspower)
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: scip.c:7747
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:8169
SCIP_Real SCIPexprgraphGetNodeSignPowerExponent(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12845
static SCIP_RETCODE generateLinearizationCutProject(SCIP *scip, SCIP_ROW **row, SCIP_CONSHDLR *conshdlr, SCIP_Real xref, SCIP_Real zref, SCIP_Real xmin, SCIP_Real exponent, SCIP_Real xoffset, SCIP_Real xmult, SCIP_Real zcoef, SCIP_Real rhs, SCIP_VAR *x, SCIP_VAR *z, SCIP_Bool islocal)
#define TRUE
Definition: def.h:52
#define SCIPdebug(x)
Definition: pub_message.h:74
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
Definition: cons.c:7644
SCIP_RETCODE SCIPaddExternBranchCand(SCIP *scip, SCIP_VAR *var, SCIP_Real score, SCIP_Real solval)
Definition: scip.c:33006
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
enum Proprule PROPRULE
SCIP_RETCODE SCIPsolveNLP(SCIP *scip)
Definition: scip.c:28754
SCIP_NLPSOLSTAT SCIPgetNLPSolstat(SCIP *scip)
Definition: scip.c:28777
static SCIP_RETCODE tightenBounds(SCIP *scip, SCIP_VAR *var, SCIP_INTERVAL bounds, SCIP_Bool force, SCIP_CONS *cons, SCIP_RESULT *result, int *nchgbds, int *nfixedvars, int *naddconss)
SCIP_RETCODE SCIPsetConshdlrParse(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPARSE((*consparse)))
Definition: scip.c:5764
SCIP_INTERVAL SCIPexprgraphGetNodeBounds(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:13068
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:41580
static SCIP_DECL_CONSENFOPS(consEnfopsAbspower)
void SCIPintervalSetBounds(SCIP_INTERVAL *resultant, SCIP_Real inf, SCIP_Real sup)
SCIP_Bool SCIPallowDualReds(SCIP *scip)
Definition: scip.c:23070
SCIP_VAR ** SCIPgetLinearVarsNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Bool SCIPisCutApplicable(SCIP *scip, SCIP_ROW *cut)
Definition: scip.c:30559
#define CONSHDLR_CHECKPRIORITY
Definition: cons_abspower.c:43
static SCIP_RETCODE checkFixedVariables(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS *cons, int *ndelconss, int *nupgdconss, int *nchgbds, int *nfixedvars, SCIP_RESULT *result)
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip.c:26426
static SCIP_DECL_HASHKEYVAL(presolveFindDuplicatesKeyVal)
#define SCIPdebugMessage
Definition: pub_message.h:77
#define SIGN(x)
Definition: cons_abspower.c:75
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip.c:34593
static SCIP_RETCODE generateCut(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol, SCIP_ROW **row, SCIP_Bool onlyinbounds)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:16803
static SCIP_DECL_HASHKEYEQ(presolveFindDuplicatesKeyEQ)
static SCIP_Real proposeBranchingPoint(SCIP *scip, SCIP_CONS *cons, int preferzero, SCIP_Bool branchminconverror)
int SCIPgetNLinearVarsNonlinear(SCIP *scip, SCIP_CONS *cons)
static SCIP_DECL_CONSTRANS(consTransAbspower)
SCIP_Real SCIPgetRhsNonlinear(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE separatePoint(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS **conss, int nconss, int nusefulconss, SCIP_SOL *sol, SCIP_Real minefficacy, SCIP_Bool inenforcement, SCIP_Bool onlyinbounds, SCIP_Bool *success, SCIP_Bool *cutoff, SCIP_Real *bestefficacy)
static SCIP_DECL_CONSGETVARS(consGetVarsAbspower)
int SCIPgetNContVars(SCIP *scip)
Definition: scip.c:10915
SCIP_RETCODE SCIPexprtreeCreate(BMS_BLKMEM *blkmem, SCIP_EXPRTREE **tree, SCIP_EXPR *root, int nvars, int nparams, SCIP_Real *params)
Definition: expr.c:8611
SCIP_RETCODE SCIPchgRowRhs(SCIP *scip, SCIP_ROW *row, SCIP_Real rhs)
Definition: scip.c:27770
SCIP_Bool SCIPconsIsLocal(SCIP_CONS *cons)
Definition: cons.c:7843
static SCIP_DECL_NONLINCONSUPGD(nonlinconsUpgdAbspower)
SCIP_Bool SCIPconsIsSeparated(SCIP_CONS *cons)
Definition: cons.c:7783
SCIP_RETCODE SCIPaddCut(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut, SCIP_Bool forcecut, SCIP_Bool *infeasible)
Definition: scip.c:30577
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip.c:24936
#define SCIPdebugPrintCons(x, y, z)
Definition: pub_message.h:83
SCIP_RETCODE SCIPcreateConsAbspower(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *x, SCIP_VAR *z, SCIP_Real exponent, SCIP_Real xoffset, SCIP_Real zcoef, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
#define NONLINCONSUPGD_PRIORITY
Definition: cons_abspower.c:58
SCIP_Real SCIPgetRowMaxCoef(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:28050
static SCIP_DECL_CONSENABLE(consEnableAbspower)
SCIP_RETCODE SCIPgetNLPFracVars(SCIP *scip, SCIP_VAR ***fracvars, SCIP_Real **fracvarssol, SCIP_Real **fracvarsfrac, int *nfracvars, int *npriofracvars)
Definition: scip.c:28897
SCIP_Real SCIPgetLhsNonlinear(SCIP *scip, SCIP_CONS *cons)
static SCIP_DECL_CONSEXIT(consExitAbspower)
#define CONSHDLR_DELAYSEPA
Definition: cons_abspower.c:50
int SCIPexprgraphGetNodePolynomialNMonomials(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12939
SCIP_Bool SCIPisLbBetter(SCIP *scip, SCIP_Real newlb, SCIP_Real oldlb, SCIP_Real oldub)
Definition: scip.c:41863
SCIP_RETCODE SCIPsetConshdlrFree(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSFREE((*consfree)))
Definition: scip.c:5328
static SCIP_DECL_QUADCONSUPGD(quadconsUpgdAbspower)
SCIP_Bool SCIPconsIsInitial(SCIP_CONS *cons)
Definition: cons.c:7773
SCIP_RETCODE SCIPcreateConsVarbound(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *var, SCIP_VAR *vbdvar, SCIP_Real vbdcoef, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
SCIP_RETCODE SCIPinferVarUbCons(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_CONS *infercons, int inferinfo, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
Definition: scip.c:20638
SCIP_RETCODE SCIPhashtableCreate(SCIP_HASHTABLE **hashtable, BMS_BLKMEM *blkmem, int tablesize, SCIP_DECL_HASHGETKEY((*hashgetkey)), SCIP_DECL_HASHKEYEQ((*hashkeyeq)), SCIP_DECL_HASHKEYVAL((*hashkeyval)), void *userptr)
Definition: misc.c:1475
SCIP_EVENTHDLR * SCIPfindEventhdlr(SCIP *scip, const char *name)
Definition: scip.c:7877
SCIP_RETCODE SCIPanalyzeConflictCons(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *success)
Definition: scip.c:24707
SCIP_RETCODE SCIPaddNlRow(SCIP *scip, SCIP_NLROW *nlrow)
Definition: scip.c:28645
int SCIPexprGetMonomialNFactors(SCIP_EXPRDATA_MONOMIAL *monomial)
Definition: expr.c:5790
SCIP_RETCODE SCIPsetConshdlrInit(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINIT((*consinit)))
Definition: scip.c:5352
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:3516
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:16460
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:3542
SCIP_RETCODE SCIPparseVarName(SCIP *scip, const char *str, SCIP_VAR **var, char **endptr)
Definition: scip.c:16242
SCIP_Bool SCIPvarIsIntegral(SCIP_VAR *var)
Definition: var.c:16532
SCIP_VAR * SCIPgetLinearVarAbspower(SCIP *scip, SCIP_CONS *cons)
SCIP_EXPROP SCIPexprgraphGetNodeOperator(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12776
SCIP_CONSHDLRDATA * SCIPconshdlrGetData(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:3921
SCIP_EXPRDATA_MONOMIAL ** SCIPexprgraphGetNodePolynomialMonomials(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12927
SCIP_RETCODE SCIPcatchVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip.c:36232
SCIP_Real coef
Definition: type_expr.h:102
#define SCIP_EVENTTYPE_SOLFOUND
Definition: type_event.h:118
SCIP_Real inf
Definition: intervalarith.h:38
void * SCIPhashtableRetrieveNext(SCIP_HASHTABLE *hashtable, SCIP_HASHTABLELIST **hashtablelist, void *key)
Definition: misc.c:1651
SCIP_RETCODE SCIPinitConflictAnalysis(SCIP *scip)
Definition: scip.c:24329
SCIP_RETCODE SCIPincludeNonlinconsUpgrade(SCIP *scip, SCIP_DECL_NONLINCONSUPGD((*nonlinconsupgd)), SCIP_DECL_EXPRGRAPHNODEREFORM((*nodereform)), int priority, SCIP_Bool active, const char *conshdlrname)
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41193
#define CONSHDLR_ENFOPRIORITY
Definition: cons_abspower.c:42
static SCIP_RETCODE createNlRow(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPgetVarCopy(SCIP *sourcescip, SCIP *targetscip, SCIP_VAR *sourcevar, SCIP_VAR **targetvar, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, SCIP_Bool *success)
Definition: scip.c:1750
SCIP_Real SCIPexprgraphGetNodeLinearConstant(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12867
#define SCIP_PRESOLTIMING_MEDIUM
Definition: type_timing.h:44
SCIP_Real SCIPexprgraphGetNodePolynomialConstant(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12951
SCIP_Real * SCIPgetLinearCoefsNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Bool SCIPisFeasPositive(SCIP *scip, SCIP_Real val)
Definition: scip.c:41592
SCIP_Bool SCIPexprgraphHasNodeNonlinearAncestor(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:14381
SCIP_EXPRCURV SCIPexprgraphGetNodeCurvature(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:13088
static void computeBoundsX(SCIP *scip, SCIP_CONS *cons, SCIP_INTERVAL zbnds, SCIP_INTERVAL *xbnds)
SCIP_VAR ** SCIPvarGetVubVars(SCIP_VAR *var)
Definition: var.c:17201
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
Definition: scip.c:41317
SCIP_RETCODE SCIPgetTransformedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **transvar)
Definition: scip.c:17159
SCIP_Bool SCIPconsIsStickingAtNode(SCIP_CONS *cons)
Definition: cons.c:7883
#define SCIPallocMemory(scip, ptr)
Definition: scip.h:20355
int SCIPgetNLinearVarsQuadratic(SCIP *scip, SCIP_CONS *cons)
#define CONSHDLR_EAGERFREQ
Definition: cons_abspower.c:46
static void computeBoundsZ(SCIP *scip, SCIP_CONS *cons, SCIP_INTERVAL xbnds, SCIP_INTERVAL *zbnds)
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:18924
interval arithmetics for provable bounds
SCIP_RETCODE SCIPunlockVarCons(SCIP *scip, SCIP_VAR *var, SCIP_CONS *cons, SCIP_Bool lockdown, SCIP_Bool lockup)
Definition: scip.c:19592
#define QUADCONSUPGD_PRIORITY
Definition: cons_abspower.c:57
enum SCIP_NlpSolStat SCIP_NLPSOLSTAT
Definition: type_nlpi.h:69
SCIP_Real SCIPintervalGetInf(SCIP_INTERVAL interval)
static void presolveFindDuplicatesSolveEquations(SCIP *scip, SCIP_Bool *infeas, SCIP_Real *xval, SCIP_Real *zval, SCIP_Real exponent, SCIP_Real xoffset1, SCIP_Real zcoef1, SCIP_Real rhs1, SCIP_Real xoffset2, SCIP_Real zcoef2, SCIP_Real rhs2)
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
Definition: scip.c:41604
#define DECL_MYPOW(x)
Definition: cons_abspower.c:69
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:3901
int SCIPcalcHashtableSize(int minsize)
Definition: misc.c:1152
SCIP_Real SCIPepsilon(SCIP *scip)
Definition: scip.c:40692
SCIPInterval sqrt(const SCIPInterval &x)
SCIP_Bool SCIPisNLPConstructed(SCIP *scip)
Definition: scip.c:28394
static SCIP_RETCODE proposeFeasibleSolution(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS **conss, int nconss, SCIP_SOL *sol)
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41206
SCIP_RETCODE SCIPsetConshdlrPresol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPRESOL((*conspresol)), int maxprerounds, SCIP_PRESOLTIMING presoltiming)
Definition: scip.c:5496
SCIP_Real SCIPgetRowLPFeasibility(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:28138
SCIP_RETCODE SCIPaddPoolCut(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:30672
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip.c:40927
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:7624
#define CONSHDLR_NEEDSCONS
Definition: cons_abspower.c:52
static SCIP_RETCODE catchVarEvents(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_CONS *cons)
SCIPInterval sign(const SCIPInterval &x)
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41515
static SCIP_DECL_CONSACTIVE(consActiveAbspower)
SCIP_Real SCIPfloor(SCIP *scip, SCIP_Real val)
Definition: scip.c:41366
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
Definition: lp.c:19023
struct SCIP_EventData SCIP_EVENTDATA
Definition: type_event.h:146
static SCIP_RETCODE presolveFindDuplicates(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS **conss, int nconss, int *nupgdconss, int *ndelconss, int *naddconss, int *nfixedvars, int *naggrvars, SCIP_Bool *success, SCIP_Bool *infeas)
constraint handler for quadratic constraints
SCIP_RETCODE SCIPsetConshdlrExitpre(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSEXITPRE((*consexitpre)))
Definition: scip.c:5472
static SCIP_DECL_CONSFREE(consFreeAbspower)
static SCIP_RETCODE computeViolation(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS *cons, SCIP_SOL *sol, SCIP_Real *viol)
SCIP_Bool SCIPconsIsGlobal(SCIP_CONS *cons)
Definition: cons.c:7833
#define REALABS(x)
Definition: def.h:148
static SCIP_RETCODE presolveDual(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *cutoff, int *ndelconss, int *nfixedvars)
void SCIPenableNLP(SCIP *scip)
Definition: scip.c:28379
SCIP_Real SCIPgetViolationAbspower(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol)
int SCIPvarGetNLocksUp(SCIP_VAR *var)
Definition: var.c:3204
static SCIP_Real getGradientMaxElement(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol)
static SCIP_DECL_EVENTEXEC(processVarEvent)
SCIP_Real SCIPinfinity(SCIP *scip)
Definition: scip.c:41245
SCIP_RETCODE SCIPexprgraphCreateNodeLinear(BMS_BLKMEM *blkmem, SCIP_EXPRGRAPHNODE **node, int ncoefs, SCIP_Real *coefs, SCIP_Real constant)
Definition: expr.c:13181
#define SCIP_CALL(x)
Definition: def.h:263
SCIP_RETCODE SCIPsetConshdlrProp(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPROP((*consprop)), int propfreq, SCIP_Bool delayprop, SCIP_PROPTIMING proptiming)
Definition: scip.c:5261
#define SCIP_EVENTTYPE_LBTIGHTENED
Definition: type_event.h:55
#define CONSHDLR_SEPAPRIORITY
Definition: cons_abspower.c:41
SCIP_RETCODE SCIPincludeConshdlrBasic(SCIP *scip, SCIP_CONSHDLR **conshdlrptr, const char *name, const char *desc, int enfopriority, int chckpriority, int eagerfreq, SCIP_Bool needscons, SCIP_DECL_CONSENFOLP((*consenfolp)), SCIP_DECL_CONSENFOPS((*consenfops)), SCIP_DECL_CONSCHECK((*conscheck)), SCIP_DECL_CONSLOCK((*conslock)), SCIP_CONSHDLRDATA *conshdlrdata)
Definition: scip.c:5161
static SCIP_RETCODE computeViolations(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS **conss, int nconss, SCIP_SOL *sol, SCIP_CONS **maxviolcon)
SCIP_Real sup
Definition: intervalarith.h:39
SCIP_RETCODE SCIPhashtableRemove(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:1714
void SCIPintervalSet(SCIP_INTERVAL *resultant, SCIP_Real value)
SCIP_RETCODE SCIPaddLinearConsToNlpHeurSubNlp(SCIP *scip, SCIP_HEUR *heur, SCIP_Bool addcombconss, SCIP_Bool addcontconss)
Definition: heur_subnlp.c:2224
SCIP_Bool SCIPinProbing(SCIP *scip)
Definition: scip.c:31741
SCIP_VAR ** SCIPgetLinearVarsQuadratic(SCIP *scip, SCIP_CONS *cons)
static SCIP_DECL_CONSDELETE(consDeleteAbspower)
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41554
SCIP_RETCODE SCIPaddRowIndicator(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_ROW *row)
static SCIP_RETCODE generateSecantCutNoCheck(SCIP *scip, SCIP_ROW **row, SCIP_CONSHDLR *conshdlr, SCIP_Real xlb, SCIP_Real xub, SCIP_Real exponent, SCIP_Real xoffset, DECL_MYPOW((*mypow)), SCIP_Real xmult, SCIP_Real zcoef, SCIP_Real rhs, SCIP_VAR *x, SCIP_VAR *z)
#define SCIPdebugGetSolVal(scip, var, val)
Definition: debug.h:246
SCIP_EXPRGRAPHNODE * SCIPgetExprgraphNodeNonlinear(SCIP *scip, SCIP_CONS *cons)
struct SCIP_ConsData SCIP_CONSDATA
Definition: type_cons.h:50
#define CONSHDLR_PROP_TIMING
Definition: cons_abspower.c:55
#define SCIP_EVENTTYPE_BOUNDTIGHTENED
Definition: type_event.h:97
SCIP_CONSDATA * SCIPconsGetData(SCIP_CONS *cons)
Definition: cons.c:7654
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
Definition: scip.c:16968
SCIP_RETCODE SCIPcreateConsBasicAbspower(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *x, SCIP_VAR *z, SCIP_Real exponent, SCIP_Real xoffset, SCIP_Real zcoef, SCIP_Real lhs, SCIP_Real rhs)
SCIP_Bool SCIPexprgraphHasNodeSibling(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:14346
SCIP_RETCODE SCIPsetConshdlrDisable(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSDISABLE((*consdisable)))
Definition: scip.c:5695
static SCIP_DECL_CONSGETNVARS(consGetNVarsAbspower)
SCIP_RETCODE SCIPdelConsLocal(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:12117
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41219
static SCIP_DECL_CONSPRINT(consPrintAbspower)
SCIP_RETCODE SCIPmarkDoNotMultaggrVar(SCIP *scip, SCIP_VAR *var)
Definition: scip.c:23106
SCIP_RETCODE SCIPchgVarType(SCIP *scip, SCIP_VAR *var, SCIP_VARTYPE vartype, SCIP_Bool *infeasible)
Definition: scip.c:22668
SCIP_SOL * SCIPeventGetSol(SCIP_EVENT *event)
Definition: event.c:1181
SCIP_RETCODE SCIPtightenVarLb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
Definition: scip.c:20259
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17021
static SCIP_RETCODE registerLargeLPValueVariableForBranching(SCIP *scip, SCIP_CONS **conss, int nconss, SCIP_VAR **brvar)
unsigned int SCIP_EVENTTYPE
Definition: type_event.h:125
SCIP_RETCODE SCIPsetConshdlrInitpre(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINITPRE((*consinitpre)))
Definition: scip.c:5448
SCIP_RETCODE SCIPcreateCons(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_CONSHDLR *conshdlr, SCIP_CONSDATA *consdata, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: scip.c:24759
static SCIP_RETCODE presolveFindDuplicatesUpgradeCons(SCIP *scip, SCIP_CONS *cons1, SCIP_CONS *cons2, SCIP_Bool *infeas, int *nupgdconss, int *ndelconss, int *naggrvars)
#define SCIP_Bool
Definition: def.h:50
SCIP_Real SCIPvarGetBestBoundGlobal(SCIP_VAR *var)
Definition: var.c:16985
SCIP_Real * SCIPvarGetVubCoefs(SCIP_VAR *var)
Definition: var.c:17211
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip.c:801
SCIP_Bool SCIPconsIsDynamic(SCIP_CONS *cons)
Definition: cons.c:7863
constraint handler for nonlinear constraints
static SCIP_DECL_CONSSEPALP(consSepalpAbspower)
#define MAX(x, y)
Definition: tclique_def.h:75
SCIP_Bool SCIPstrToRealValue(const char *str, SCIP_Real *value, char **endptr)
Definition: misc.c:8240
SCIP_RETCODE SCIPaddConflictLb(SCIP *scip, SCIP_VAR *var, SCIP_BDCHGIDX *bdchgidx)
Definition: scip.c:24356
SCIP_RETCODE SCIPincludeConshdlrAbspower(SCIP *scip)
static SCIP_RETCODE propagateVarbounds(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS *cons, SCIP_Bool *infeas, int *nbdchgs, int *naddconss)
SCIP_RETCODE SCIPcreateSolCopy(SCIP *scip, SCIP_SOL **sol, SCIP_SOL *sourcesol)
Definition: scip.c:33881
SCIP_Real * SCIPvarGetVlbConstants(SCIP_VAR *var)
Definition: var.c:17179
methods for debugging
SCIP_Bool SCIPconsIsRemovable(SCIP_CONS *cons)
Definition: cons.c:7873
SCIP_Bool SCIPconsIsAdded(SCIP_CONS *cons)
Definition: cons.c:7973
SCIP_Bool SCIPallowObjProp(SCIP *scip)
Definition: scip.c:23080
static SCIP_DECL_CONSSEPASOL(consSepasolAbspower)
static SCIP_DECL_CONSCHECK(consCheckAbspower)
SCIP_Bool SCIPconsIsDeleted(SCIP_CONS *cons)
Definition: cons.c:7743
static SCIP_DECL_EXPRGRAPHNODEREFORM(exprgraphnodeReformAbspower)
SCIP_RETCODE SCIPexprCreate(BMS_BLKMEM *blkmem, SCIP_EXPR **expr, SCIP_EXPROP op,...)
Definition: expr.c:5853
SCIP_Real * SCIPgetCoefsLinearVarsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPexprtreeFree(SCIP_EXPRTREE **tree)
Definition: expr.c:8692
SCIP_RETCODE SCIPaddVarVlb(SCIP *scip, SCIP_VAR *var, SCIP_VAR *vlbvar, SCIP_Real vlbcoef, SCIP_Real vlbconstant, SCIP_Bool *infeasible, int *nbdchgs)
Definition: scip.c:21569
int SCIPgetNQuadVarTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
static SCIP_DECL_CONSRESPROP(consRespropAbspower)
SCIP_RETCODE SCIPsetConshdlrInitlp(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINITLP((*consinitlp)))
Definition: scip.c:5580
void SCIPmarkRowNotRemovableLocal(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:28014
SCIP_Real SCIPintervalGetSup(SCIP_INTERVAL interval)
int SCIPvarGetNVlbs(SCIP_VAR *var)
Definition: var.c:17147
static SCIP_RETCODE addVarbound(SCIP *scip, SCIP_CONS *cons, SCIP_Bool addcons, SCIP_VAR *var, SCIP_VAR *vbdvar, SCIP_Real vbdcoef, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool *infeas, int *nbdchgs, int *naddconss)
static SCIP_DECL_CONSINIT(consInitAbspower)
#define SCIP_EVENTTYPE_UBTIGHTENED
Definition: type_event.h:57
Constraint handler for linear constraints in their most general form, .
#define BMSclearMemory(ptr)
Definition: memory.h:84
SCIP_Real SCIPexprGetMonomialCoef(SCIP_EXPRDATA_MONOMIAL *monomial)
Definition: expr.c:5780
Constraint handler for absolute power constraints .
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
Definition: scip.c:36389
SCIP_Real SCIPnodeGetEstimate(SCIP_NODE *node)
Definition: tree.c:7046
#define ROOTS_KNOWN
Definition: cons_abspower.c:82
Proprule
int SCIPgetDepth(SCIP *scip)
Definition: scip.c:37750
void * SCIPexprgraphGetNodeVar(SCIP_EXPRGRAPH *exprgraph, SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12808
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip.c:1270
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41232
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
Definition: misc.c:1505
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
#define SCIP_EVENTTYPE_DISABLED
Definition: type_event.h:43
SCIP_RETCODE SCIPinferVarLbCons(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_CONS *infercons, int inferinfo, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
Definition: scip.c:20535
int SCIPexprgraphGetNodeIntPowerExponent(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12834
SCIP_RETCODE SCIPdropVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip.c:36278
SCIP_RETCODE SCIPsetConshdlrDelete(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSDELETE((*consdelete)))
Definition: scip.c:5534
static SCIP_RETCODE propagateCons(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS *cons, SCIP_Bool canaddcons, SCIP_Bool *cutoff, int *nchgbds, int *naddconss)
#define CONSHDLR_NAME
Definition: cons_abspower.c:39
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:11514
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16506
SCIP_RETCODE SCIPsetConshdlrInitsol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINITSOL((*consinitsol)))
Definition: scip.c:5400
SCIP_RETCODE SCIPupdateStartpointHeurSubNlp(SCIP *scip, SCIP_HEUR *heur, SCIP_SOL *solcand, SCIP_Real violation)
Definition: heur_subnlp.c:2258
SCIP_Real * SCIPvarGetVlbCoefs(SCIP_VAR *var)
Definition: var.c:17169
#define SCIPfreeMemory(scip, ptr)
Definition: scip.h:20371
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:16955
SCIP_Real SCIPgetLhsAbspower(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip.c:36198
SCIP_RETCODE SCIPsetConshdlrPrint(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPRINT((*consprint)))
Definition: scip.c:5741
SCIP_Real * SCIPexprgraphGetNodeLinearCoefs(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12856
SCIP_RETCODE SCIPreleaseNlRow(SCIP *scip, SCIP_NLROW **nlrow)
Definition: scip.c:29459
#define CONSHDLR_SEPAFREQ
Definition: cons_abspower.c:44
void SCIPintervalSetEntire(SCIP_Real infinity, SCIP_INTERVAL *resultant)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip.c:1253
int SCIPexprgraphGetNodePosition(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12766
static SCIP_DECL_CONSLOCK(consLockAbspower)
int SCIPgetNBilinTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
int SCIPgetNIntVars(SCIP *scip)
Definition: scip.c:10825
SCIP_Bool SCIPisIntegral(SCIP *scip, SCIP_Real val)
Definition: scip.c:41329
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
static SCIP_DECL_CONSPRESOL(consPresolAbspower)
SCIP_RETCODE SCIPcreateConsNonlinear2(SCIP *scip, SCIP_CONS **cons, const char *name, int nlinvars, SCIP_VAR **linvars, SCIP_Real *lincoefs, SCIP_EXPRGRAPHNODE *exprgraphnode, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
#define CONSHDLR_MAXPREROUNDS
Definition: cons_abspower.c:49
static SCIP_DECL_CONSENFOLP(consEnfolpAbspower)
SCIP_RETCODE SCIPsetConshdlrExitsol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSEXITSOL((*consexitsol)))
Definition: scip.c:5424
NLP local search primal heuristic using sub-SCIPs.
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41541
SCIP_RETCODE SCIPlockVarCons(SCIP *scip, SCIP_VAR *var, SCIP_CONS *cons, SCIP_Bool lockdown, SCIP_Bool lockup)
Definition: scip.c:19519
static SCIP_Real roots[ROOTS_KNOWN+1]
Definition: cons_abspower.c:88
#define SCIP_Real
Definition: def.h:124
SCIP_Bool SCIPconsIsChecked(SCIP_CONS *cons)
Definition: cons.c:7803
SCIP_Real SCIPgetOffsetAbspower(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE analyzeConflict(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *infervar, PROPRULE proprule, SCIP_BOUNDTYPE boundtype)
SCIP_RETCODE SCIPaddCharParam(SCIP *scip, const char *name, const char *desc, char *valueptr, SCIP_Bool isadvanced, char defaultvalue, const char *allowedvalues, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:3626
SCIP_RETCODE SCIPtightenVarUb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
Definition: scip.c:20365
#define MIN(x, y)
Definition: memory.c:63
SCIP_RETCODE SCIPcreateEmptyRowCons(SCIP *scip, SCIP_ROW **row, SCIP_CONSHDLR *conshdlr, const char *name, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool removable)
Definition: scip.c:27587
SCIP_RETCODE SCIPcreateLPSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip.c:33654
SCIP_RETCODE SCIPprintRow(SCIP *scip, SCIP_ROW *row, FILE *file)
Definition: scip.c:28321
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41567
SCIP_RETCODE SCIPincludeQuadconsUpgrade(SCIP *scip, SCIP_DECL_QUADCONSUPGD((*quadconsupgd)), int priority, SCIP_Bool active, const char *conshdlrname)
SCIP_EXPRGRAPHNODE ** SCIPexprgraphGetNodeChildren(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12726
#define SCIP_INVALID
Definition: def.h:144
static SCIP_DECL_CONSCOPY(consCopyAbspower)
SCIP_Real SCIPfeastol(SCIP *scip)
Definition: scip.c:40720
SCIP_Real * SCIPexprGetMonomialExponents(SCIP_EXPRDATA_MONOMIAL *monomial)
Definition: expr.c:5810
SCIP_RETCODE SCIPreleaseRow(SCIP *scip, SCIP_ROW **row)
Definition: scip.c:27725
SCIP_VAR * SCIPgetNonlinearVarAbspower(SCIP *scip, SCIP_CONS *cons)
#define CONSHDLR_PROPFREQ
Definition: cons_abspower.c:45
SCIP_RETCODE SCIPsetNLPInitialGuessSol(SCIP *scip, SCIP_SOL *sol)
Definition: scip.c:28722
int SCIPgetNNlpis(SCIP *scip)
Definition: scip.c:8654
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
Definition: event.c:917
#define SCIPdebugAddSolVal(scip, var, val)
Definition: debug.h:245
SCIP_Real SCIPgetVarSol(SCIP *scip, SCIP_VAR *var)
Definition: scip.c:17711
SCIP_Real SCIPgetRhsAbspower(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPsetConshdlrExit(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSEXIT((*consexit)))
Definition: scip.c:5376
SCIP_Real SCIPround(SCIP *scip, SCIP_Real val)
Definition: scip.c:41390
SCIP_RETCODE SCIPaddVarLocks(SCIP *scip, SCIP_VAR *var, int nlocksdown, int nlocksup)
Definition: scip.c:19465
SCIP_Bool SCIPisRelEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41891
struct SCIP_ConshdlrData SCIP_CONSHDLRDATA
Definition: type_cons.h:49
#define CONSHDLR_PRESOLTIMING
Definition: cons_abspower.c:54
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
Definition: var.c:16628
#define CONSHDLR_DESC
Definition: cons_abspower.c:40
SCIP_RETCODE SCIPcreateChild(SCIP *scip, SCIP_NODE **node, SCIP_Real nodeselprio, SCIP_Real estimate)
Definition: scip.c:33311
SCIP_RETCODE SCIPaddConsLocal(SCIP *scip, SCIP_CONS *cons, SCIP_NODE *validnode)
Definition: scip.c:12036
SCIP_Real SCIPexprgraphGetNodeRealPowerExponent(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12823
SCIP_RETCODE SCIPaddConflictUb(SCIP *scip, SCIP_VAR *var, SCIP_BDCHGIDX *bdchgidx)
Definition: scip.c:24423
static SCIP_DECL_CONSEXITSOL(consExitsolAbspower)
SCIP_Real SCIPgetLhsQuadratic(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE registerBranchingCandidates(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS **conss, int nconss, int *nnotify)
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
Definition: scip.c:41305
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:3598
#define CONSHDLR_DELAYPROP
Definition: cons_abspower.c:51
SCIP_RETCODE SCIPsetConshdlrGetNVars(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSGETNVARS((*consgetnvars)))
Definition: scip.c:5810
SCIP_Bool SCIPconsIsEnabled(SCIP_CONS *cons)
Definition: cons.c:7711
static SCIP_RETCODE generateLinearizationCut(SCIP *scip, SCIP_ROW **row, SCIP_CONSHDLR *conshdlr, SCIP_Real refpoint, SCIP_Real exponent, SCIP_Real xoffset, SCIP_Real xmult, SCIP_Real zcoef, SCIP_Real rhs, SCIP_VAR *x, SCIP_VAR *z, SCIP_Bool islocal)
SCIP_VAR * SCIPvarGetProbvar(SCIP_VAR *var)
Definition: var.c:11481
SCIP_RETCODE SCIPaddVarToRow(SCIP *scip, SCIP_ROW *row, SCIP_VAR *var, SCIP_Real val)
Definition: scip.c:27851
#define SCIPABORT()
Definition: def.h:235
SCIP_RETCODE SCIPaddVarVub(SCIP *scip, SCIP_VAR *var, SCIP_VAR *vubvar, SCIP_Real vubcoef, SCIP_Real vubconstant, SCIP_Bool *infeasible, int *nbdchgs)
Definition: scip.c:21628
SCIP_Bool SCIPconsIsEnforced(SCIP_CONS *cons)
Definition: cons.c:7793
SCIP_Bool SCIPconsIsPropagated(SCIP_CONS *cons)
Definition: cons.c:7823
int SCIPvarGetNLocksDown(SCIP_VAR *var)
Definition: var.c:3149
SCIP_Real SCIPgetRhsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetCoefLinearAbspower(SCIP *scip, SCIP_CONS *cons)
int SCIPexprgraphGetNodeDepth(SCIP_EXPRGRAPHNODE *node)
Definition: expr.c:12756
SCIP_Bool SCIPisUbBetter(SCIP *scip, SCIP_Real newub, SCIP_Real oldlb, SCIP_Real oldub)
Definition: scip.c:41878
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip.c:36164
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip.c:34217
static SCIP_DECL_CONSHDLRCOPY(conshdlrCopyAbspower)
SCIP_RETCODE SCIPgetNlRowAbspower(SCIP *scip, SCIP_CONS *cons, SCIP_NLROW **nlrow)
enum SCIP_SideType SCIP_SIDETYPE
Definition: type_lp.h:58