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