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-2019 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file 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 #define SCIP_PRIVATE_ROWPREP
24 
25 #include <ctype.h>
26 #include "nlpi/pub_expr.h"
27 #include "nlpi/type_expr.h"
28 #include "nlpi/type_nlpi.h"
29 #include "scip/cons_abspower.h"
30 #include "scip/cons_indicator.h"
31 #include "scip/cons_linear.h"
32 #include "scip/cons_nonlinear.h"
33 #include "scip/cons_quadratic.h"
34 #include "scip/cons_varbound.h"
35 #include "scip/debug.h"
36 #include "scip/heur_subnlp.h"
37 #include "scip/heur_trysol.h"
38 #include "scip/intervalarith.h"
39 #include "scip/pub_cons.h"
40 #include "scip/pub_event.h"
41 #include "scip/pub_heur.h"
42 #include "scip/pub_lp.h"
43 #include "scip/pub_message.h"
44 #include "scip/pub_misc.h"
45 #include "scip/pub_nlp.h"
46 #include "scip/pub_sol.h"
47 #include "scip/pub_tree.h"
48 #include "scip/pub_var.h"
49 #include "scip/scip_branch.h"
50 #include "scip/scip_conflict.h"
51 #include "scip/scip_cons.h"
52 #include "scip/scip_copy.h"
53 #include "scip/scip_cut.h"
54 #include "scip/scip_event.h"
55 #include "scip/scip_general.h"
56 #include "scip/scip_heur.h"
57 #include "scip/scip_lp.h"
58 #include "scip/scip_mem.h"
59 #include "scip/scip_message.h"
60 #include "scip/scip_nlp.h"
61 #include "scip/scip_numerics.h"
62 #include "scip/scip_param.h"
63 #include "scip/scip_prob.h"
64 #include "scip/scip_probing.h"
65 #include "scip/scip_sepa.h"
66 #include "scip/scip_sol.h"
67 #include "scip/scip_tree.h"
68 #include "scip/scip_var.h"
69 #include <string.h>
70 
71 /* constraint handler properties */
72 #define CONSHDLR_NAME "abspower"
73 #define CONSHDLR_DESC "constraint handler for absolute power constraints lhs <= sign(x+offset)abs(x+offset)^n + c*z <= rhs"
74 #define CONSHDLR_SEPAPRIORITY 0 /**< priority of the constraint handler for separation */
75 #define CONSHDLR_ENFOPRIORITY -30 /**< priority of the constraint handler for constraint enforcing */
76 #define CONSHDLR_CHECKPRIORITY -3500000 /**< priority of the constraint handler for checking feasibility */
77 #define CONSHDLR_SEPAFREQ 1 /**< frequency for separating cuts; zero means to separate only in the root node */
78 #define CONSHDLR_PROPFREQ 1 /**< frequency for propagating domains; zero means only preprocessing propagation */
79 #define CONSHDLR_EAGERFREQ 100 /**< frequency for using all instead of only the useful constraints in separation,
80  * propagation and enforcement, -1 for no eager evaluations, 0 for first only */
81 #define CONSHDLR_MAXPREROUNDS -1 /**< maximal number of presolving rounds the constraint handler participates in (-1: no limit) */
82 #define CONSHDLR_DELAYSEPA FALSE /**< should separation method be delayed, if other separators found cuts? */
83 #define CONSHDLR_DELAYPROP FALSE /**< should propagation method be delayed, if other propagators found reductions? */
84 #define CONSHDLR_NEEDSCONS TRUE /**< should the constraint handler be skipped, if no constraints are available? */
85 
86 #define CONSHDLR_PRESOLTIMING SCIP_PRESOLTIMING_FAST | SCIP_PRESOLTIMING_MEDIUM
87 #define CONSHDLR_PROP_TIMING SCIP_PROPTIMING_ALWAYS /**< when should the constraint handlers propagation routines be called? */
88 
89 #define QUADCONSUPGD_PRIORITY 50000 /**< priority of the constraint handler for upgrading of quadratic constraints */
90 #define NONLINCONSUPGD_PRIORITY 50000 /**< priority of the constraint handler for upgrading of nonlinear constraints and reformulating expression graph nodes */
91 
92 /*
93  * Local defines
94  */
95 
96 #define PROPVARTOL SCIPepsilon(scip) /**< tolerance to add to variable bounds in domain propagation */
97 #define PROPSIDETOL SCIPepsilon(scip) /**< tolerance to add to constraint sides in domain propagation */
98 #define INITLPMAXVARVAL 1000.0 /**< maximal absolute value of variable for still generating a linearization cut at that point in initlp */
99 
100 /** power function type to be used by a constraint instead of the general pow */
101 #define DECL_MYPOW(x) SCIP_Real x (SCIP_Real base, SCIP_Real exponent)
103 /** sign of a value (-1 or +1)
104  *
105  * 0.0 has sign +1
106  */
107 #define SIGN(x) ((x) >= 0.0 ? 1.0 : -1.0)
109 
110 /*
111  * Data structures
112  */
113 
114 #define ROOTS_KNOWN 10 /**< up to which (integer) exponents precomputed roots have been stored */
116 /** The positive root of the polynomial (n-1) y^n + n y^(n-1) - 1 is needed in separation.
117  * Here we store these roots for small integer values of n.
118  */
119 static
121  -1.0, /* no root for n=0 */
122  -1.0, /* no root for n=1 */
123  0.41421356237309504880, /* root for n=2 (-1+sqrt(2)) */
124  0.5, /* root for n=3 */
125  0.56042566045031785945, /* root for n=4 */
126  0.60582958618826802099, /* root for n=5 */
127  0.64146546982884663257, /* root for n=6 */
128  0.67033204760309682774, /* root for n=7 */
129  0.69428385661425826738, /* root for n=8 */
130  0.71453772716733489700, /* root for n=9 */
131  0.73192937842370733350 /* root for n=10 */
132 };
133 
134 /** constraint data for absolute power constraints */
135 struct SCIP_ConsData
136 {
137  SCIP_VAR* x; /**< variable x in sign(x+offset)|x+offset|^n term */
138  SCIP_VAR* z; /**< linear variable in constraint */
139  SCIP_Real exponent; /**< exponent n of |x+offset| */
140  SCIP_Real xoffset; /**< offset in x+offset */
141  SCIP_Real zcoef; /**< coefficient of linear variable z */
142  SCIP_Real lhs; /**< left hand side of constraint */
143  SCIP_Real rhs; /**< right hand side of constraint */
144 
145  SCIP_Real root; /**< root of polynomial */
146  DECL_MYPOW ((*power)); /**< function for computing power*/
147 
148  SCIP_Real lhsviol; /**< current violation of left hand side */
149  SCIP_Real rhsviol; /**< current violation of right hand side */
150 
151  int xeventfilterpos; /**< position of x var event in SCIP event filter */
152  int zeventfilterpos; /**< position of z var event in SCIP event filter */
153  unsigned int propvarbounds:1; /**< have variable bounds been propagated? */
154 
155  SCIP_NLROW* nlrow; /**< nonlinear row representation of constraint */
156 };
157 
158 /** constraint handler data */
159 struct SCIP_ConshdlrData
160 {
161  SCIP_Real cutmaxrange; /**< maximal coef range (maximal abs coef / minimal abs coef) of a cut in order to be added to LP */
162  SCIP_Bool projectrefpoint; /**< whether to project the reference point when linearizing a absolute power constraint in a convex region */
163  int preferzerobranch; /**< how much we prefer to branch on 0.0 first */
164  SCIP_Bool branchminconverror; /**< whether to compute branching point such that the convexification error is minimized after branching on 0.0 */
165  SCIP_Bool addvarboundcons; /**< should variable bound constraints be added? */
166  SCIP_Bool linfeasshift; /**< try linear feasibility shift heuristic in CONSCHECK */
167  SCIP_Bool dualpresolve; /**< should dual presolve be applied? */
168  SCIP_Bool sepainboundsonly; /**< should tangents only be generated in variable bounds during separation? */
169  SCIP_Real sepanlpmincont; /**< minimal required fraction of continuous variables in problem to use solution of NLP relaxation in root for separation */
170  SCIP_Bool enfocutsremovable; /**< are cuts added during enforcement removable from the LP in the same node? */
171 
172  SCIP_HEUR* subnlpheur; /**< a pointer to the subnlp heuristic */
173  SCIP_HEUR* trysolheur; /**< a pointer to the trysol heuristic */
174  SCIP_EVENTHDLR* eventhdlr; /**< our handler for bound change events on variable x */
175  SCIP_CONSHDLR* conshdlrindicator; /**< a pointer to the indicator constraint handler */
176  int newsoleventfilterpos;/**< filter position of new solution event handler, if catched */
177  SCIP_Bool comparedpairwise; /**< did we compare absolute power constraints pairwise in this run? */
178  SCIP_Bool sepanlp; /**< where linearization of the NLP relaxation solution added? */
179  SCIP_NODE* lastenfonode; /**< the node for which enforcement was called the last time (and some constraint was violated) */
180  int nenforounds; /**< counter on number of enforcement rounds for the current node */
181  unsigned int nsecantcuts; /**< number of secant cuts created so far */
182  unsigned int ncuts; /**< number of linearization cuts created so far */
183 };
184 
185 /*
186  * Propagation rules
187  */
188 
189 enum Proprule
190 {
191  PROPRULE_1, /**< left hand side and bounds on z -> lower bound on x */
192  PROPRULE_2, /**< left hand side and upper bound on x -> bound on z */
193  PROPRULE_3, /**< right hand side and bounds on z -> upper bound on x */
194  PROPRULE_4, /**< right hand side and lower bound on x -> bound on z */
195  PROPRULE_INVALID /**< propagation was applied without a specific propagation rule */
196 };
197 typedef enum Proprule PROPRULE;
199 /*
200  * Local methods
201  */
202 
203 /** computes bounds on x in a absolute power constraints for given bounds on z */
204 static
205 void computeBoundsX(
206  SCIP* scip, /**< SCIP data structure */
207  SCIP_CONS* cons, /**< constraint */
208  SCIP_INTERVAL zbnds, /**< bounds on x that are to be propagated */
209  SCIP_INTERVAL* xbnds /**< buffer to store corresponding bounds on z */
210  );
211 
212 /** power function for square, that should be faster than using pow(x, 2.0) */
213 static
215 {
216  assert(exponent == 2.0);
217  return base*base;
218 }
219 
220 /** process variable event */
221 static
222 SCIP_DECL_EVENTEXEC(processVarEvent)
223 {
224  SCIP_CONS* cons;
225 
226  assert(scip != NULL);
227  assert(event != NULL);
229 
230  cons = (SCIP_CONS*) eventdata;
231  assert(cons != NULL);
232 
233  assert(SCIPconsGetData(cons) != NULL);
234  assert(SCIPeventGetVar(event) == SCIPconsGetData(cons)->x || SCIPeventGetVar(event) == SCIPconsGetData(cons)->z);
235 
237 
238  return SCIP_OKAY;
239 } /*lint !e715*/
240 
241 /** catch variable bound tightening events */
242 static
244  SCIP* scip, /**< SCIP data structure */
245  SCIP_EVENTHDLR* eventhdlr, /**< event handler for variables */
246  SCIP_CONS* cons /**< constraint for which to catch bound change events */
247  )
248 {
249  SCIP_CONSDATA* consdata;
250  SCIP_EVENTTYPE eventtype;
251 
252  assert(scip != NULL);
253  assert(cons != NULL);
254  assert(eventhdlr != NULL);
255 
256  consdata = SCIPconsGetData(cons);
257  assert(consdata != NULL);
258 
259  /* if z is multiaggregated, then bound changes on x could not be propagated, so we do not need to catch them */
260  if( SCIPvarGetStatus(consdata->z) != SCIP_VARSTATUS_MULTAGGR )
261  {
262  eventtype = SCIP_EVENTTYPE_DISABLED;
263  if( !SCIPisInfinity(scip, -consdata->lhs) )
264  eventtype |= SCIP_EVENTTYPE_UBTIGHTENED;
265  if( !SCIPisInfinity(scip, consdata->rhs) )
266  eventtype |= SCIP_EVENTTYPE_LBTIGHTENED;
267 
268  SCIP_CALL( SCIPcatchVarEvent(scip, consdata->x, eventtype, eventhdlr, (SCIP_EVENTDATA*)cons, &consdata->xeventfilterpos) );
269 
270  SCIP_CALL( SCIPmarkConsPropagate(scip, cons) );
271  }
272 
273  /* if x is multiaggregated, then bound changes on z could not be propagated, so we do not need to catch them */
274  if( SCIPvarGetStatus(consdata->x) != SCIP_VARSTATUS_MULTAGGR )
275  {
276  eventtype = SCIP_EVENTTYPE_DISABLED;
277  if( consdata->zcoef > 0.0 )
278  {
279  if( !SCIPisInfinity(scip, -consdata->lhs) )
280  eventtype |= SCIP_EVENTTYPE_UBTIGHTENED;
281  if( !SCIPisInfinity(scip, consdata->rhs) )
282  eventtype |= SCIP_EVENTTYPE_LBTIGHTENED;
283  }
284  else
285  {
286  if( !SCIPisInfinity(scip, -consdata->lhs) )
287  eventtype |= SCIP_EVENTTYPE_LBTIGHTENED;
288  if( !SCIPisInfinity(scip, consdata->rhs) )
289  eventtype |= SCIP_EVENTTYPE_UBTIGHTENED;
290  }
291 
292  SCIP_CALL( SCIPcatchVarEvent(scip, consdata->z, eventtype, eventhdlr, (SCIP_EVENTDATA*)cons, &consdata->zeventfilterpos) );
293 
294  SCIP_CALL( SCIPmarkConsPropagate(scip, cons) );
295  }
296 
297  return SCIP_OKAY;
298 }
299 
300 /** drop variable bound tightening events */
301 static
303  SCIP* scip, /**< SCIP data structure */
304  SCIP_EVENTHDLR* eventhdlr, /**< event handler for variables */
305  SCIP_CONS* cons /**< constraint for which to drop bound change events */
306  )
307 {
308  SCIP_CONSDATA* consdata;
309  SCIP_EVENTTYPE eventtype;
310 
311  assert(scip != NULL);
312  assert(cons != NULL);
313  assert(eventhdlr != NULL);
314 
315  consdata = SCIPconsGetData(cons);
316  assert(consdata != NULL);
317 
318  if( SCIPvarGetStatus(consdata->z) != SCIP_VARSTATUS_MULTAGGR )
319  {
320  eventtype = SCIP_EVENTTYPE_DISABLED;
321  if( !SCIPisInfinity(scip, -consdata->lhs) )
322  eventtype |= SCIP_EVENTTYPE_UBTIGHTENED;
323  if( !SCIPisInfinity(scip, consdata->rhs) )
324  eventtype |= SCIP_EVENTTYPE_LBTIGHTENED;
325 
326  SCIP_CALL( SCIPdropVarEvent(scip, consdata->x, eventtype, eventhdlr, (SCIP_EVENTDATA*)cons, consdata->xeventfilterpos) );
327  consdata->xeventfilterpos = -1;
328  }
329 
330  if( SCIPvarGetStatus(consdata->x) != SCIP_VARSTATUS_MULTAGGR )
331  {
332  eventtype = SCIP_EVENTTYPE_DISABLED;
333  if( consdata->zcoef > 0.0 )
334  {
335  if( !SCIPisInfinity(scip, -consdata->lhs) )
336  eventtype |= SCIP_EVENTTYPE_UBTIGHTENED;
337  if( !SCIPisInfinity(scip, consdata->rhs) )
338  eventtype |= SCIP_EVENTTYPE_LBTIGHTENED;
339  }
340  else
341  {
342  if( !SCIPisInfinity(scip, -consdata->lhs) )
343  eventtype |= SCIP_EVENTTYPE_LBTIGHTENED;
344  if( !SCIPisInfinity(scip, consdata->rhs) )
345  eventtype |= SCIP_EVENTTYPE_UBTIGHTENED;
346  }
347 
348  SCIP_CALL( SCIPdropVarEvent(scip, consdata->z, eventtype, eventhdlr, (SCIP_EVENTDATA*)cons, consdata->zeventfilterpos) );
349  consdata->zeventfilterpos = -1;
350  }
351 
352  assert(consdata->xeventfilterpos == -1);
353  assert(consdata->zeventfilterpos == -1);
354 
355  return SCIP_OKAY;
356 }
357 
358 /** get key of hash element */
359 static
360 SCIP_DECL_HASHGETKEY(presolveFindDuplicatesGetKey)
361 {
362  return elem;
363 } /*lint !e715*/
364 
365 /** 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 */
366 static
367 SCIP_DECL_HASHKEYEQ(presolveFindDuplicatesKeyEQ)
368 {
369  SCIP_CONSDATA* consdata1;
370  SCIP_CONSDATA* consdata2;
371 
372  consdata1 = SCIPconsGetData((SCIP_CONS*)key1);
373  consdata2 = SCIPconsGetData((SCIP_CONS*)key2);
374  assert(consdata1 != NULL);
375  assert(consdata2 != NULL);
376 
377  if( consdata1->x != consdata2->x )
378  return FALSE;
379 
380  if( consdata1->exponent != consdata2->exponent ) /*lint !e777*/
381  return FALSE;
382 
383  if( consdata1->xoffset != consdata2->xoffset && consdata1->z != consdata2->z ) /*lint !e777*/
384  return FALSE;
385 
386  return TRUE;
387 } /*lint !e715*/
388 
389 /** get value of hash element when comparing on x */
390 static
391 SCIP_DECL_HASHKEYVAL(presolveFindDuplicatesKeyVal)
392 {
393  SCIP_CONSDATA* consdata;
394 
395  consdata = SCIPconsGetData((SCIP_CONS*)key);
396  assert(consdata != NULL);
397 
398  return SCIPhashTwo(SCIPvarGetIndex(consdata->x),
399  SCIPrealHashCode(consdata->exponent));
400 } /*lint !e715*/
401 
402 /** checks if two constraints have the same z variable and the same exponent */
403 static
404 SCIP_DECL_HASHKEYEQ(presolveFindDuplicatesKeyEQ2)
405 {
406  SCIP_CONSDATA* consdata1;
407  SCIP_CONSDATA* consdata2;
408 
409  consdata1 = SCIPconsGetData((SCIP_CONS*)key1);
410  consdata2 = SCIPconsGetData((SCIP_CONS*)key2);
411  assert(consdata1 != NULL);
412  assert(consdata2 != NULL);
413 
414  if( consdata1->z != consdata2->z )
415  return FALSE;
416 
417  if( consdata1->exponent != consdata2->exponent ) /*lint !e777*/
418  return FALSE;
419 
420  return TRUE;
421 } /*lint !e715*/
422 
423 /** get value of hash element when comparing on z */
424 static
425 SCIP_DECL_HASHKEYVAL(presolveFindDuplicatesKeyVal2)
426 {
427  SCIP_CONSDATA* consdata;
428 
429  consdata = SCIPconsGetData((SCIP_CONS*)key);
430  assert(consdata != NULL);
431 
432  return SCIPhashTwo(SCIPvarGetIndex(consdata->z),
433  SCIPrealHashCode(consdata->exponent));
434 } /*lint !e715*/
435 
436 /** upgrades a signpower constraint to a linear constraint if a second signpower constraint with same nonlinear term is available */
437 static
439  SCIP* scip, /**< SCIP data structure */
440  SCIP_CONS* cons1, /**< constraint to upgrade to a linear constraint */
441  SCIP_CONS* cons2, /**< constraint which defines a relation for x|x|^{n-1} */
442  SCIP_Bool* infeas, /**< buffer where to indicate if infeasibility has been detected */
443  int* nupgdconss, /**< buffer where to add number of upgraded conss */
444  int* ndelconss, /**< buffer where to add number of deleted conss */
445  int* naggrvars /**< buffer where to add number of aggregated variables */
446  )
447 {
448  SCIP_CONSDATA* consdata1;
449  SCIP_CONSDATA* consdata2;
450  SCIP_CONS* lincons;
451  SCIP_Real lhs;
452  SCIP_Real rhs;
453  SCIP_VAR* vars[2];
454  SCIP_Real coefs[2];
455 
456  assert(scip != NULL);
457  assert(cons1 != NULL);
458  assert(cons2 != NULL);
459  assert(infeas != NULL);
460  assert(nupgdconss != NULL);
461  assert(ndelconss != NULL);
462  assert(naggrvars != NULL);
463 
464  consdata1 = SCIPconsGetData(cons1);
465  consdata2 = SCIPconsGetData(cons2);
466  assert(consdata1 != NULL);
467  assert(consdata2 != NULL);
468 
469  assert(SCIPisEQ(scip, consdata2->lhs, consdata2->rhs));
470  assert(!SCIPisInfinity(scip, consdata2->lhs));
471  assert(consdata1->x == consdata2->x);
472  assert(consdata1->exponent == consdata2->exponent); /*lint !e777*/
473  assert(consdata1->xoffset == consdata2->xoffset); /*lint !e777*/
474 
475  lhs = consdata1->lhs;
476  if( !SCIPisInfinity(scip, -lhs) )
477  lhs -= consdata2->lhs;
478  rhs = consdata1->rhs;
479  if( !SCIPisInfinity(scip, rhs) )
480  rhs -= consdata2->lhs;
481 
482  vars[0] = consdata1->z;
483  vars[1] = consdata2->z;
484 
485  coefs[0] = consdata1->zcoef;
486  coefs[1] = -consdata2->zcoef;
487 
488  if( SCIPisEQ(scip, lhs, rhs) )
489  {
490  SCIP_Bool redundant;
491  SCIP_Bool aggregated;
492 
493  /* try aggregation */
494  SCIP_CALL( SCIPaggregateVars(scip, consdata1->z, consdata2->z, consdata1->zcoef, -consdata2->zcoef, rhs, infeas, &redundant, &aggregated) );
495 
496  /* if infeasibility has been detected, stop here */
497  if( *infeas )
498  return SCIP_OKAY;
499 
500  if( redundant )
501  {
502  /* if redundant is TRUE, then either the aggregation has been done, or it was redundant */
503  if( aggregated )
504  ++*naggrvars;
505 
506  ++*ndelconss;
507 
508  SCIP_CALL( SCIPdelCons(scip, cons1) );
509  return SCIP_OKAY;
510  }
511  }
512 
513  /* if aggregation did not succeed, then either because some variable is multi-aggregated or due to numerics or because lhs != rhs
514  * we then add a linear constraint instead
515  */
516  vars[0] = consdata1->z;
517  vars[1] = consdata2->z;
518  coefs[0] = consdata1->zcoef;
519  coefs[1] = -consdata2->zcoef;
520 
521  SCIP_CALL( SCIPcreateConsLinear(scip, &lincons, SCIPconsGetName(cons1), 2, vars, coefs, lhs, rhs,
525  SCIPconsIsStickingAtNode(cons1)) );
526  SCIP_CALL( SCIPaddCons(scip, lincons) );
527  SCIP_CALL( SCIPreleaseCons(scip, &lincons) );
528 
529  SCIP_CALL( SCIPdelCons(scip, cons1) );
530  ++*nupgdconss;
531 
532  return SCIP_OKAY;
533 }
534 
535 /** solves a system of two absolute power equations
536  * Given: (x+xoffset1)|x+xoffset1|^{exponent-1} + zcoef1 * z == rhs1
537  * and (x+xoffset2)|x+xoffset2|^{exponent-1} + zcoef2 * z == rhs2
538  * with xoffset1 != xoffset2 and zcoef1 * rhs2 == zcoef2 * rhs1 and exponent == 2,
539  * finds values for x and z that satisfy these equations, or reports infeasibility if no solution exists.
540  *
541  * Multiplying the second equation by -zcoef1/zcoef2 and adding it to the first one gives
542  * (x+xoffset1)|x+xoffset1| - zcoef1/zcoef2 (x+offset2)|x+offset2| == 0
543  *
544  * If zcoef1 == zcoef2, then there exists, due to monotonicity of x|x|, no x such that
545  * (x+xoffset1)|x+xoffset1| == (x+xoffset2)|x+xoffset2|.
546  *
547  * In general, for zcoef1 / zcoef2 > 0.0, we get
548  * x = (xoffset2 - xoffset1) / (sqrt(zcoef2 / zcoef1) - 1.0) - xoffset1,
549  * and for zcoef1 / zcoef2 < 0.0, we get
550  * x = (xoffset2 - xoffset1) / (-sqrt(-zcoef2 / zcoef1) - 1.0) - xoffset1.
551  *
552  * This then yields z = (rhs1 - (x+xoffset1)|x+xoffset1|) / zcoef1.
553  */
554 static
556  SCIP* scip, /**< SCIP data structure */
557  SCIP_Bool* infeas, /**< buffer to indicate if the system of equations has no solution */
558  SCIP_Real* xval, /**< buffer to store value of x in the solution, if any */
559  SCIP_Real* zval, /**< buffer to store value of z in the solution, if any */
560  SCIP_Real exponent, /**< exponent in absolute power equations */
561  SCIP_Real xoffset1, /**< offset for x in first absolute power equation */
562  SCIP_Real zcoef1, /**< coefficient of z in first absolute power equation */
563  SCIP_Real rhs1, /**< right-hand-side in first absolute power equation */
564  SCIP_Real xoffset2, /**< offset for x in second absolute power equation */
565  SCIP_Real zcoef2, /**< coefficient of z in second absolute power equation */
566  SCIP_Real rhs2 /**< right-hand-side in second absolute power equation */
567  )
568 {
569  assert(scip != NULL);
570  assert(infeas != NULL);
571  assert(xval != NULL);
572  assert(zval != NULL);
573  assert(exponent == 2.0);
574  assert(!SCIPisEQ(scip, xoffset1, xoffset2));
575  assert(SCIPisEQ(scip, zcoef1 * rhs2, zcoef2 * rhs1));
576  assert(zcoef1 != 0.0);
577  assert(zcoef2 != 0.0);
578 
579  if( xoffset2 < xoffset1 )
580  {
581  presolveFindDuplicatesSolveEquations(scip, infeas, xval, zval, exponent, xoffset2, zcoef2, rhs2, xoffset1, zcoef1, rhs1);
582  return;
583  }
584 
585  if( SCIPisEQ(scip, zcoef1, zcoef2) )
586  {
587  *infeas = TRUE;
588  return;
589  }
590 
591  *infeas = FALSE;
592 
593  if( SCIPisEQ(scip, zcoef1, -zcoef2) )
594  {
595  *xval = - (xoffset1 + xoffset2) / 2.0;
596  }
597  else if( zcoef2 * zcoef1 > 0.0 )
598  {
599  *xval = (xoffset2 - xoffset1) / (sqrt(zcoef2 / zcoef1) - 1.0) - xoffset1;
600  }
601  else
602  {
603  assert(zcoef2 * zcoef1 < 0.0);
604  *xval = (xoffset2 - xoffset1) / (-sqrt(-zcoef2 / zcoef1) - 1.0) - xoffset1;
605  }
606 
607  *zval = rhs1 - (*xval + xoffset1) * REALABS(*xval + xoffset1);
608  *zval /= zcoef1;
609 
610  assert(SCIPisFeasEQ(scip, (*xval + xoffset1) * REALABS(*xval + xoffset1) + zcoef1 * *zval, rhs1));
611  assert(SCIPisFeasEQ(scip, (*xval + xoffset2) * REALABS(*xval + xoffset2) + zcoef2 * *zval, rhs2));
612 }
613 
614 /** finds and removes duplicates in a set of absolute power constraints */
615 static
617  SCIP* scip, /**< SCIP data structure */
618  SCIP_CONSHDLR* conshdlr, /**< constraint handler for absolute power constraints */
619  SCIP_CONS** conss, /**< constraints */
620  int nconss, /**< number of constraints */
621  int* nupgdconss, /**< pointer where to add number of upgraded constraints */
622  int* ndelconss, /**< pointer where to add number of deleted constraints */
623  int* naddconss, /**< pointer where to add number of added constraints */
624  int* nfixedvars, /**< pointer where to add number of fixed variables */
625  int* naggrvars, /**< pointer where to add number of aggregated variables */
626  SCIP_Bool* success, /**< pointer to store whether a duplicate was found (and removed) */
627  SCIP_Bool* infeas /**< pointer to store whether infeasibility was detected */
628  )
629 {
630  SCIP_MULTIHASH* multihash;
631  SCIP_MULTIHASHLIST* multihashlist;
632  SCIP_CONSHDLRDATA* conshdlrdata;
633  int c;
634 
635  assert(scip != NULL);
636  assert(conshdlr != NULL);
637  assert(conss != NULL || nconss == 0);
638  assert(nupgdconss != NULL);
639  assert(ndelconss != NULL);
640  assert(naddconss != NULL);
641  assert(nfixedvars != NULL);
642  assert(naggrvars != NULL);
643  assert(success != NULL);
644  assert(infeas != NULL);
645 
646  *success = FALSE;
647  *infeas = FALSE;
648 
649  if( nconss <= 1 )
650  return SCIP_OKAY;
651 
652  conshdlrdata = SCIPconshdlrGetData(conshdlr);
653  assert(conshdlrdata != NULL);
654 
655  /* check all constraints in the given set for duplicates, dominance, or possible simplifications w.r.t. the x variable */
656 
658  presolveFindDuplicatesGetKey, presolveFindDuplicatesKeyEQ, presolveFindDuplicatesKeyVal, (void*)scip) );
659 
660  for( c = 0; c < nconss && !*infeas; ++c )
661  {
662  SCIP_CONS* cons0;
663  SCIP_CONS* cons1;
664 
665  cons0 = conss[c]; /*lint !e613*/
666 
667  assert(!SCIPconsIsModifiable(cons0)); /* absolute power constraints aren't modifiable */
668  assert(!SCIPconsIsLocal(cons0)); /* shouldn't have local constraints in presolve */
669  assert(SCIPconsIsActive(cons0)); /* shouldn't get inactive constraints here */
670 
671  multihashlist = NULL;
672 
673  do
674  {
675  SCIP_CONSDATA* consdata0;
676  SCIP_CONSDATA* consdata1;
677 
678  /* get constraint from current hash table with same x variable as cons0 and same exponent */
679  cons1 = (SCIP_CONS*)(SCIPmultihashRetrieveNext(multihash, &multihashlist, (void*)cons0));
680  if( cons1 == NULL )
681  {
682  /* processed all constraints like cons0 from hash table, so insert cons0 and go to conss[c+1] */
683  SCIP_CALL( SCIPmultihashInsert(multihash, (void*) cons0) );
684  break;
685  }
686 
687  assert(cons0 != cons1);
688 
689  consdata0 = SCIPconsGetData(cons0);
690  consdata1 = SCIPconsGetData(cons1);
691  assert(consdata0 != NULL);
692  assert(consdata1 != NULL);
693 
694  SCIPdebugPrintCons(scip, cons0, NULL);
695  SCIPdebugPrintCons(scip, cons1, NULL);
696 
697  assert(consdata0->x == consdata1->x);
698  assert(consdata0->exponent == consdata1->exponent); /*lint !e777*/
699 
700  if( SCIPisEQ(scip, consdata0->xoffset, consdata1->xoffset) )
701  {
702  /* we have two constraints with the same (x+offset)|x+offset|^n term */
703 
704  /* if both constraints have the same functions; strengthen sides of cons1 and throw cons0 away */
705  if( consdata0->z == consdata1->z && SCIPisEQ(scip, consdata0->zcoef, consdata1->zcoef) )
706  {
707  /* check if side strenghtening would result in inconsistency */
708  if( SCIPisGT(scip, consdata0->lhs, consdata1->rhs) || SCIPisGT(scip, consdata1->lhs, consdata0->rhs) )
709  {
710  SCIPdebugMsg(scip, "<%s> and <%s> are contradictory; declare infeasibility\n", SCIPconsGetName(cons0), SCIPconsGetName(cons1));
711  *infeas = TRUE;
712  break;
713  }
714 
715  SCIPdebugMsg(scip, "<%s> and <%s> are equivalent; dropping the first\n", SCIPconsGetName(cons0), SCIPconsGetName(cons1));
716 
717  /* if a side of cons1 gets finite via merging with cons0, then this changes locks and events */
718  if( (SCIPisInfinity(scip, -consdata1->lhs) && !SCIPisInfinity(scip, -consdata0->lhs)) ||
719  ( SCIPisInfinity(scip, consdata1->rhs) && !SCIPisInfinity(scip, consdata0->rhs)) )
720  {
721  SCIP_CALL( dropVarEvents(scip, conshdlrdata->eventhdlr, cons1) );
722  SCIP_CALL( SCIPunlockVarCons(scip, consdata1->x, cons1, !SCIPisInfinity(scip, -consdata1->lhs), !SCIPisInfinity(scip, consdata1->rhs)) );
723  if( consdata1->zcoef > 0.0 )
724  SCIP_CALL( SCIPunlockVarCons(scip, consdata1->z, cons1, !SCIPisInfinity(scip, -consdata1->lhs), !SCIPisInfinity(scip, consdata1->rhs)) );
725  else
726  SCIP_CALL( SCIPunlockVarCons(scip, consdata1->z, cons1, !SCIPisInfinity(scip, consdata1->rhs), !SCIPisInfinity(scip, -consdata1->lhs)) );
727 
728  consdata1->lhs = MAX(consdata0->lhs, consdata1->lhs);
729  consdata1->rhs = MIN(consdata0->rhs, consdata1->rhs);
730 
731  SCIP_CALL( catchVarEvents(scip, conshdlrdata->eventhdlr, cons1) );
732  SCIP_CALL( SCIPlockVarCons(scip, consdata1->x, cons1, !SCIPisInfinity(scip, -consdata1->lhs), !SCIPisInfinity(scip, consdata1->rhs)) );
733  if( consdata1->zcoef > 0.0 )
734  SCIP_CALL( SCIPlockVarCons(scip, consdata1->z, cons1, !SCIPisInfinity(scip, -consdata1->lhs), !SCIPisInfinity(scip, consdata1->rhs)) );
735  else
736  SCIP_CALL( SCIPlockVarCons(scip, consdata1->z, cons1, !SCIPisInfinity(scip, consdata1->rhs), !SCIPisInfinity(scip, -consdata1->lhs)) );
737  }
738  else
739  {
740  consdata1->lhs = MAX(consdata0->lhs, consdata1->lhs);
741  consdata1->rhs = MIN(consdata0->rhs, consdata1->rhs);
742  }
743 
744  SCIP_CALL( SCIPdelCons(scip, cons0) );
745  ++*ndelconss;
746  *success = TRUE;
747 
748  break;
749  }
750 
751  /* if cons1 defines a linear expression for sign(x+offset)|x+offset|^n, use it to replace cons0 by a linear constraint */
752  if( SCIPisEQ(scip, consdata1->lhs, consdata1->rhs) )
753  {
754  SCIPdebugMsg(scip, "substitute <%s> in <%s> to make linear constraint\n", SCIPconsGetName(cons1), SCIPconsGetName(cons0));
755  SCIP_CALL( presolveFindDuplicatesUpgradeCons(scip, cons0, cons1, infeas, nupgdconss, ndelconss, naggrvars) );
756 
757  *success = TRUE;
758  break;
759  }
760 
761  /* if cons0 defines a linear expression for sign(x+offset)|x+offset|^n, use it to replace cons1 by a linear constraint */
762  if( SCIPisEQ(scip, consdata0->lhs, consdata0->rhs) )
763  {
764  SCIPdebugMsg(scip, "substitute <%s> in <%s> to make linear constraint\n", SCIPconsGetName(cons0), SCIPconsGetName(cons1));
765  SCIP_CALL( presolveFindDuplicatesUpgradeCons(scip, cons1, cons0, infeas, nupgdconss, ndelconss, naggrvars) );
766 
767  SCIP_CALL( SCIPmultihashRemove(multihash, cons1) );
768  *success = TRUE;
769 
770  if( *infeas )
771  break;
772  }
773  else
774  {
775  /* introduce a new equality constraint for sign(x+offset)|x+offset|^n and use it to replace cons0 and cons1 */
776  /* @todo maybe we could be more clever by looking which constraint sides are finite */
777  SCIP_VAR* auxvar;
778  SCIP_CONS* auxcons;
779  char name[SCIP_MAXSTRLEN];
780  SCIP_VAR* vars[2];
781  SCIP_Real coefs[2];
782 
783  SCIPdebugMsg(scip, "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));
784 
785  /* create auxiliary variable to represent sign(x+offset)|x+offset|^n */
786  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "auxvar_abspower%s_%g_%g", SCIPvarGetName(consdata0->x), consdata0->exponent, consdata0->xoffset);
787  SCIP_CALL( SCIPcreateVar(scip, &auxvar, name, -SCIPinfinity(scip), SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS,
788  TRUE, TRUE, NULL, NULL, NULL, NULL, NULL) );
789  SCIP_CALL( SCIPaddVar(scip, auxvar) );
790 
791  /* create auxiliary constraint auxvar = sign(x+offset)|x+offset|^n
792  * as we introduced a new variable, the constraint that "defines" the value for this variable need to be enforced, that is, is not redundent
793  */
794  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "auxcons_abspower%s_%g_%g", SCIPvarGetName(consdata0->x), consdata0->exponent, consdata0->xoffset);
795  SCIP_CALL( SCIPcreateConsAbspower(scip, &auxcons, name, consdata0->x, auxvar, consdata0->exponent, consdata0->xoffset, -1.0, 0.0, 0.0,
796  SCIPconsIsInitial(cons0) || SCIPconsIsInitial(cons1),
797  SCIPconsIsSeparated(cons0) || SCIPconsIsSeparated(cons1),
798  TRUE,
799  TRUE,
801  FALSE,
802  FALSE,
803  SCIPconsIsDynamic(cons0) || SCIPconsIsDynamic(cons1),
804  SCIPconsIsRemovable(cons0) || SCIPconsIsRemovable(cons1),
806  ) );
807  SCIP_CALL( SCIPaddCons(scip, auxcons) );
808  SCIP_CALL( SCIPreleaseCons(scip, &auxcons) );
809  ++*naddconss;
810 
811 #ifdef WITH_DEBUG_SOLUTION
812  if( SCIPdebugIsMainscip(scip) )
813  {
814  SCIP_Real xval;
815 
816  SCIP_CALL( SCIPdebugGetSolVal(scip, consdata0->x, &xval) );
817  SCIP_CALL( SCIPdebugAddSolVal(scip, auxvar, SIGN(xval + consdata0->xoffset) * pow(REALABS(xval + consdata0->xoffset), consdata0->exponent)) );
818  }
819 #endif
820 
821  /* create linear constraint equivalent for cons0 */
822  vars[0] = auxvar;
823  vars[1] = consdata0->z;
824  coefs[0] = 1.0;
825  coefs[1] = consdata0->zcoef;
826  SCIP_CALL( SCIPcreateConsLinear(scip, &auxcons, SCIPconsGetName(cons0), 2, vars, coefs, consdata0->lhs, consdata0->rhs,
830  SCIPconsIsStickingAtNode(cons0)) );
831  SCIP_CALL( SCIPaddCons(scip, auxcons) );
832  SCIP_CALL( SCIPreleaseCons(scip, &auxcons) );
833  ++*nupgdconss;
834 
835  /* create linear constraint equivalent for cons1 */
836  vars[1] = consdata1->z;
837  coefs[1] = consdata1->zcoef;
838  SCIP_CALL( SCIPcreateConsLinear(scip, &auxcons, SCIPconsGetName(cons1), 2, vars, coefs, consdata1->lhs, consdata1->rhs,
842  SCIPconsIsStickingAtNode(cons1)) );
843  SCIP_CALL( SCIPaddCons(scip, auxcons) );
844  SCIP_CALL( SCIPreleaseCons(scip, &auxcons) );
845  ++*nupgdconss;
846 
847  SCIP_CALL( SCIPreleaseVar(scip, &auxvar) );
848 
849  SCIP_CALL( SCIPdelCons(scip, cons0) );
850  SCIP_CALL( SCIPdelCons(scip, cons1) );
851  SCIP_CALL( SCIPmultihashRemove(multihash, cons1) );
852  *success = TRUE;
853 
854  break;
855  }
856  }
857  else if( consdata0->z == consdata1->z &&
858  consdata0->exponent == 2.0 &&
859  !SCIPisZero(scip, consdata0->zcoef) &&
860  !SCIPisZero(scip, consdata1->zcoef) &&
861  SCIPisEQ(scip, consdata0->lhs, consdata0->rhs) &&
862  SCIPisEQ(scip, consdata1->lhs, consdata1->rhs) &&
863  SCIPisEQ(scip, consdata0->lhs * consdata1->zcoef, consdata1->lhs * consdata0->zcoef) )
864  {
865  /* If we have two equality constraints with the same variables and the same exponent and compatible constants,
866  * then this system of equations should have either no or a single solution.
867  * Thus, we can report cutoff or fix the variables to this solution, and forget about the constraints.
868  * @todo think about inequalities, differing exponents, and exponents != 2
869  */
870 
871  SCIP_Real xval;
872  SCIP_Real zval;
873 
874  assert(consdata0->x == consdata1->x);
875  assert(consdata0->exponent == consdata1->exponent); /*lint !e777*/
876  assert(!SCIPisEQ(scip, consdata0->xoffset, consdata1->xoffset));
877 
878  presolveFindDuplicatesSolveEquations(scip, infeas, &xval, &zval,
879  consdata0->exponent,
880  consdata0->xoffset, consdata0->zcoef, consdata0->lhs,
881  consdata1->xoffset, consdata1->zcoef, consdata1->lhs);
882 
883  if( *infeas )
884  {
885  SCIPdebugMsg(scip, "infeasibility detected while solving the equations, no solution exists\n");
886  SCIPdebugPrintCons(scip, cons0, NULL);
887  SCIPdebugPrintCons(scip, cons1, NULL);
888  break;
889  }
890 
891  SCIPdebugMsg(scip, "fixing variables <%s>[%g, %g] to %g and <%s>[%g, %g] to %g due to equations\n",
892  SCIPvarGetName(consdata0->x), SCIPvarGetLbLocal(consdata0->x), SCIPvarGetUbLocal(consdata0->x), xval,
893  SCIPvarGetName(consdata0->z), SCIPvarGetLbLocal(consdata0->z), SCIPvarGetUbLocal(consdata0->z), zval);
894  SCIPdebugPrintCons(scip, cons0, NULL);
895  SCIPdebugPrintCons(scip, cons1, NULL);
896 
898  {
899  SCIP_Bool fixed;
900 
901  SCIP_CALL( SCIPfixVar(scip, consdata0->x, xval, infeas, &fixed) );
902  ++*ndelconss;
903 
904  if( fixed )
905  ++*nfixedvars;
906 
907  if( *infeas )
908  {
909  SCIPdebugMsg(scip, "infeasibility detected after fixing <%s>\n", SCIPvarGetName(consdata0->x));
910  break;
911  }
912  }
913  else
914  {
915  SCIP_CONS* lincons;
916  SCIP_Real one;
917 
918  one = 1.0;
919  SCIP_CALL( SCIPcreateConsLinear(scip, &lincons, SCIPconsGetName(cons0), 1, &consdata0->x, &one, xval, xval,
921  SCIP_CALL( SCIPaddCons(scip, lincons) );
922  SCIP_CALL( SCIPreleaseCons(scip, &lincons) );
923  ++*nupgdconss;
924  }
925 
927  {
928  SCIP_Bool fixed;
929 
930  SCIP_CALL( SCIPfixVar(scip, consdata0->z, zval, infeas, &fixed) );
931  ++*ndelconss;
932 
933  if( fixed )
934  ++*nfixedvars;
935 
936  if( *infeas )
937  {
938  SCIPdebugMsg(scip, "infeasibility detected after fixing <%s>\n", SCIPvarGetName(consdata0->z));
939  break;
940  }
941  }
942  else
943  {
944  SCIP_CONS* lincons;
945  SCIP_Real one;
946 
947  one = 1.0;
948  SCIP_CALL( SCIPcreateConsLinear(scip, &lincons, SCIPconsGetName(cons1), 1, &consdata0->z, &one, zval, zval,
950  SCIP_CALL( SCIPaddCons(scip, lincons) );
951  SCIP_CALL( SCIPreleaseCons(scip, &lincons) );
952  ++*nupgdconss;
953  }
954 
955  SCIP_CALL( SCIPdelCons(scip, cons0) );
956  SCIP_CALL( SCIPdelCons(scip, cons1) );
957  SCIP_CALL( SCIPmultihashRemove(multihash, cons1) );
958  *success = TRUE;
959 
960  break;
961  }
962 
963  if( multihashlist == NULL )
964  {
965  /* 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] */
966  SCIP_CALL( SCIPmultihashInsert(multihash, (void*) cons0) );
967  break;
968  }
969  }
970  while( TRUE ); /*lint !e506*/
971  }
972 
973  /* free hash table */
974  SCIPmultihashFree(&multihash);
975 
976  if( *infeas )
977  return SCIP_OKAY;
978 
979  /* check all constraints in the given set for duplicates, dominance, or possible simplifications w.r.t. the z variable */
980 
982  presolveFindDuplicatesGetKey, presolveFindDuplicatesKeyEQ2, presolveFindDuplicatesKeyVal2, (void*) scip) );
983 
984  for( c = 0; c < nconss && !*infeas; ++c )
985  {
986  SCIP_CONS* cons0;
987  SCIP_CONS* cons1;
988  SCIP_CONSDATA* consdata0;
989 
990  cons0 = conss[c]; /*lint !e613*/
991 
992  assert(!SCIPconsIsModifiable(cons0)); /* absolute power constraints aren't modifiable */
993  assert(!SCIPconsIsLocal(cons0)); /* shouldn't have local constraints in presolve */
994 
995  /* do not consider constraints that we have deleted in the above loop */
996  if( SCIPconsIsDeleted(cons0) )
997  continue;
998  assert(SCIPconsIsActive(cons0)); /* shouldn't get inactive constraints here */
999 
1000  consdata0 = SCIPconsGetData(cons0);
1001  assert(consdata0 != NULL);
1002 
1003  /* consider only equality constraints so far
1004  * @todo do also something with inequalities
1005  */
1006  if( !SCIPisEQ(scip, consdata0->lhs, consdata0->rhs) )
1007  continue;
1008 
1009  multihashlist = NULL;
1010 
1011  do
1012  {
1013  SCIP_CONSDATA* consdata1;
1014 
1015  /* get constraint from current hash table with same z variable as cons0 and same exponent */
1016  cons1 = (SCIP_CONS*)(SCIPmultihashRetrieveNext(multihash, &multihashlist, (void*)cons0));
1017  if( cons1 == NULL )
1018  {
1019  /* processed all constraints like cons0 from hash table, so insert cons0 and go to conss[c+1] */
1020  SCIP_CALL( SCIPmultihashInsert(multihash, (void*) cons0) );
1021  break;
1022  }
1023 
1024  assert(cons0 != cons1);
1025  assert(!SCIPconsIsDeleted(cons1));
1026 
1027  consdata1 = SCIPconsGetData(cons1);
1028  assert(consdata1 != NULL);
1029 
1030  SCIPdebugPrintCons(scip, cons0, NULL);
1031  SCIPdebugPrintCons(scip, cons1, NULL);
1032 
1033  assert(consdata0->z == consdata1->z);
1034  assert(consdata0->exponent == consdata1->exponent); /*lint !e777*/
1035  assert(SCIPisEQ(scip, consdata1->lhs, consdata1->rhs));
1036  assert(!SCIPisZero(scip, consdata1->zcoef));
1037 
1038  if( SCIPisEQ(scip, consdata0->lhs*consdata1->zcoef, consdata1->lhs*consdata0->zcoef) )
1039  {
1040  /* have two absolute power equations with same z and compatible constants
1041  * we can then reduce this to one absolute power and one linear equation
1042  * -> x0 + xoffset0 = signpower(zcoef0/zcoef1, 1/exponent) (x1 + xoffset1)
1043  * -> keep cons1
1044  * the latter can be realized as an aggregation (if x0 and x1 are not multiaggregated) or linear constraint
1045  */
1046  SCIP_Bool redundant;
1047  SCIP_Bool aggregated;
1048  SCIP_Real coef;
1049  SCIP_Real rhs;
1050 
1051  SCIPdebugMsg(scip, "<%s> and <%s> can be reformulated to one abspower and one aggregation\n", SCIPconsGetName(cons0), SCIPconsGetName(cons1));
1052  SCIPdebugPrintCons(scip, cons0, NULL);
1053  SCIPdebugPrintCons(scip, cons1, NULL);
1054 
1055  if( consdata0->exponent == 2.0 )
1056  coef = SIGN(consdata0->zcoef / consdata1->zcoef) * sqrt(REALABS(consdata0->zcoef / consdata1->zcoef));
1057  else
1058  coef = SIGN(consdata0->zcoef / consdata1->zcoef) * pow(REALABS(consdata0->zcoef / consdata1->zcoef), 1.0/consdata0->exponent);
1059  rhs = coef * consdata1->xoffset - consdata0->xoffset;
1060 
1061  /* try aggregation */
1062  SCIP_CALL( SCIPaggregateVars(scip, consdata0->x, consdata1->x, 1.0, -coef, rhs, infeas, &redundant, &aggregated) );
1063  if( *infeas )
1064  {
1065  /* if infeasibility has been detected, stop here */
1066  break;
1067  }
1068  else if( redundant )
1069  {
1070  /* if redundant is TRUE, then either the aggregation has been done, or it was redundant */
1071  if( aggregated )
1072  ++*naggrvars;
1073 
1074  ++*ndelconss;
1075  }
1076  else
1077  {
1078  /* if aggregation did not succeed, then either because some variable is multi-aggregated or due to numerics
1079  * we then add a linear constraint instead
1080  */
1081  SCIP_CONS* auxcons;
1082  SCIP_VAR* vars[2];
1083  SCIP_Real coefs[2];
1084 
1085  vars[0] = consdata0->x;
1086  vars[1] = consdata1->x;
1087  coefs[0] = 1.0;
1088  coefs[1] = -coef;
1089 
1090  /* create linear constraint equivalent for cons0 */
1091  SCIP_CALL( SCIPcreateConsLinear(scip, &auxcons, SCIPconsGetName(cons0), 2, vars, coefs, rhs, rhs,
1095  SCIPconsIsStickingAtNode(cons0)) );
1096  SCIP_CALL( SCIPaddCons(scip, auxcons) );
1097  SCIPdebugPrintCons(scip, auxcons, NULL);
1098  SCIP_CALL( SCIPreleaseCons(scip, &auxcons) );
1099 
1100  ++*nupgdconss;
1101  }
1102  SCIP_CALL( SCIPdelCons(scip, cons0) );
1103 
1104  *success = TRUE;
1105  break;
1106  }
1107 
1108  if( multihashlist == NULL )
1109  {
1110  /* 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] */
1111  SCIP_CALL( SCIPmultihashInsert(multihash, (void*) cons0) );
1112  break;
1113  }
1114  }
1115  while( TRUE ); /*lint !e506*/
1116  }
1117 
1118  /* free hash table */
1119  SCIPmultihashFree(&multihash);
1120 
1121  return SCIP_OKAY;
1122 }
1123 
1124 /** fix variables not appearing in any other constraint
1125  *
1126  * @todo generalize to inequalities
1127  * @todo generalize to support discrete variables
1128  * @todo generalize to arbitrary exponents also if z is in objective
1129  */
1130 static
1132  SCIP* scip, /**< SCIP data structure */
1133  SCIP_CONS* cons, /**< constraint */
1134  SCIP_Bool* cutoff, /**< buffer to indicate whether a cutoff was detected */
1135  int* ndelconss, /**< buffer to increase with the number of deleted constraint */
1136  int* nfixedvars /**< buffer to increase with the number of fixed variables */
1137  )
1138 {
1139  SCIP_CONSDATA* consdata;
1140  SCIP_Bool lhsexists;
1141  SCIP_Bool rhsexists;
1142 
1143  assert(scip != NULL);
1144  assert(cons != NULL);
1145  assert(cutoff != NULL);
1146  assert(nfixedvars != NULL);
1147  assert(ndelconss != NULL);
1148 
1149  /* only process checked constraints (for which the locks are increased);
1150  * otherwise we would have to check for variables with nlocks == 0, and these are already processed by the
1151  * dualfix presolver
1152  */
1153  if( !SCIPconsIsChecked(cons) )
1154  return SCIP_OKAY;
1155 
1156  consdata = SCIPconsGetData(cons);
1157  assert(consdata != NULL);
1158 
1159  /* skip dual presolve if multiaggregated variables are present for now (bounds are not updated, difficult to fix) */
1160  if( SCIPvarGetStatus(consdata->x) == SCIP_VARSTATUS_MULTAGGR )
1161  return SCIP_OKAY;
1162  if( SCIPvarGetStatus(consdata->z) == SCIP_VARSTATUS_MULTAGGR )
1163  return SCIP_OKAY;
1164 
1165  /* skip dual presolve if discrete variables are present for now (more difficult to compute fixing value) */
1166  if( SCIPvarGetType(consdata->x) <= SCIP_VARTYPE_INTEGER )
1167  return SCIP_OKAY;
1168  if( SCIPvarGetType(consdata->z) <= SCIP_VARTYPE_INTEGER )
1169  return SCIP_OKAY;
1170 
1171  /* we assume that domain propagation has been run and fixed variables were removed if possible */
1172  assert(!SCIPconsIsMarkedPropagate(cons));
1173  assert(consdata->zcoef != 0.0);
1174 
1175  lhsexists = !SCIPisInfinity(scip, -consdata->lhs);
1176  rhsexists = !SCIPisInfinity(scip, consdata->rhs);
1177 
1178  if( SCIPvarGetNLocksDownType(consdata->x, SCIP_LOCKTYPE_MODEL) == (lhsexists ? 1 : 0) &&
1179  SCIPvarGetNLocksUpType(consdata->x, SCIP_LOCKTYPE_MODEL) == (rhsexists ? 1 : 0) &&
1180  (consdata->zcoef > 0.0 ? SCIPvarGetNLocksDownType(consdata->z, SCIP_LOCKTYPE_MODEL) :
1181  SCIPvarGetNLocksUpType(consdata->z, SCIP_LOCKTYPE_MODEL)) == (lhsexists ? 1 : 0) &&
1182  (consdata->zcoef > 0.0 ? SCIPvarGetNLocksUpType(consdata->z, SCIP_LOCKTYPE_MODEL) :
1183  SCIPvarGetNLocksDownType(consdata->z, SCIP_LOCKTYPE_MODEL)) == (rhsexists ? 1 : 0) )
1184  {
1185  /* x and z are only locked by cons, so we can fix them to an optimal solution of
1186  * min xobj * x + zobj * z
1187  * s.t. lhs <= sign(x+offset)*abs(x+offset)^exponent + zcoef * z <= rhs
1188  * xlb <= x <= xub
1189  * zlb <= z <= zub
1190  */
1191  if( SCIPisEQ(scip, consdata->lhs, consdata->rhs) )
1192  {
1193  /* much simpler case where we can substitute z:
1194  * min xobj * x + zobj/zcoef * (rhs - sign(x+offset)*abs(x+offset)^exponent)
1195  * s.t. xlb <= x <= xub
1196  */
1197  SCIP_Real xfix;
1198  SCIP_Real xlb;
1199  SCIP_Real xub;
1200  SCIP_Real zfix;
1201  SCIP_INTERVAL xbnds;
1202  SCIP_INTERVAL zbnds;
1203  SCIP_Bool fixed;
1204 
1205  /* Since domain propagation has been applied, we would like to assume that for any valid value for x,
1206  * also the corresponding z value is valid. However, domain propagation only applies sufficiently
1207  * strong bound tightenings, so we better recompute the bounds on x.
1208  */
1209  SCIPintervalSetBounds(&zbnds, SCIPvarGetLbGlobal(consdata->z), SCIPvarGetUbGlobal(consdata->z));
1210  computeBoundsX(scip, cons, zbnds, &xbnds);
1211  xlb = MAX(SCIPvarGetLbGlobal(consdata->x), xbnds.inf); /*lint !e666*/
1212  xub = MIN(SCIPvarGetUbGlobal(consdata->x), xbnds.sup); /*lint !e666*/
1213 
1214  /* with our own "local" boundtightening, xlb might end slightly above xub,
1215  * which can result in xfix being outside bounds below, see also #2202
1216  */
1217  assert(SCIPisFeasLE(scip, xlb, xub));
1218  if( xub < xlb )
1219  xlb = xub = (xlb + xub)/2.0;
1220 
1221  if( SCIPisZero(scip, SCIPvarGetObj(consdata->z)) )
1222  {
1223  /* even simpler case where objective is linear in x */
1224  if( SCIPisZero(scip, SCIPvarGetObj(consdata->x)) )
1225  {
1226  /* simplest case where objective is zero:
1227  * if zero is within bounds, fix to zero, otherwise
1228  * fix x to middle of bounds for numerical stability. */
1229  if(SCIPisLT(scip, xlb, 0.0) && SCIPisGT(scip, xub, 0.0))
1230  xfix = 0.0;
1231  else
1232  xfix = 0.5 * (xlb + xub);
1233  }
1234  else
1235  {
1236  /* fix x to best bound */
1237  xfix = (SCIPvarGetObj(consdata->x) >= 0.0) ? xlb : xub;
1238  }
1239  }
1240  else if( consdata->exponent == 2.0 )
1241  {
1242  /* consider cases x <= -offset and x >= -offset separately */
1243  SCIP_Real a;
1244  SCIP_Real b;
1245  SCIP_Real c;
1246  SCIP_Real cand;
1247  SCIP_Real xfixobjval;
1248 
1249  xfix = SCIP_INVALID;
1250  xfixobjval = SCIP_INVALID;
1251 
1252  if( SCIPisLT(scip, xlb, -consdata->xoffset) )
1253  {
1254  /* For x <= -offset, the objective is equivalent to
1255  * zobj/zcoef * x^2 + (xobj + 2 offset zobj/zcoef) * x + offset^2 * zobj/zcoef + other constant
1256  * <-> a * x^2 + b * x + c
1257  *
1258  * critical values for x are xlb, MIN(xub,-offset), and -b/(2*a)
1259  */
1260  a = SCIPvarGetObj(consdata->z) / consdata->zcoef;
1261  b = SCIPvarGetObj(consdata->x) + 2 * consdata->xoffset * SCIPvarGetObj(consdata->z) / consdata->zcoef;
1262  c = consdata->xoffset * consdata->xoffset * SCIPvarGetObj(consdata->z) / consdata->zcoef;
1263 
1264  if( a < 0.0 && SCIPisInfinity(scip, -xlb) )
1265  {
1266  /* if a < 0.0, then a*x^2 is unbounded for x -> -infinity, thus fix x to -infinity */
1267  xfix = -SCIPinfinity(scip);
1268  xfixobjval = -SCIPinfinity(scip);
1269  }
1270  else
1271  {
1272  /* initialize with value for x=xlb */
1273  xfix = xlb;
1274  xfixobjval = a * xlb * xlb + b * xlb + c;
1275 
1276  /* compare with value for x=MIN(-offset,xub) */
1277  cand = MIN(-consdata->xoffset, xub);
1278  if( xfixobjval > a * cand * cand + b * cand + c )
1279  {
1280  xfix = cand;
1281  xfixobjval = a * cand * cand + b * cand + c;
1282  }
1283 
1284  /* compare with value for x=-b/(2*a), if within bounds */
1285  cand = -b/(2.0*a);
1286  if( cand > xlb && cand < -consdata->xoffset && cand < xub && xfixobjval > -b*b/(4.0*a) + c )
1287  {
1288  xfix = cand;
1289  xfixobjval = -b*b/(4.0*a) + c;
1290  }
1291  }
1292  }
1293 
1294  if( SCIPisGT(scip, xub, -consdata->xoffset) )
1295  {
1296  /* For x >= -offset, the objective is equivalent to
1297  * -zobj/zcoef * x^2 + (xobj - 2 offset zobj/zcoef) * x - offset^2 * zobj/zcoef + constants
1298  * <-> a * x^2 + b * x + c
1299  *
1300  * critical values for x are xub, MAX(xlb,-offset), and -b/(2*a)
1301  */
1302  a = -SCIPvarGetObj(consdata->z) / consdata->zcoef;
1303  b = SCIPvarGetObj(consdata->x) - 2 * consdata->xoffset * SCIPvarGetObj(consdata->z) / consdata->zcoef;
1304  c = -consdata->xoffset * consdata->xoffset * SCIPvarGetObj(consdata->z) / consdata->zcoef;
1305 
1306  if( a < 0.0 && SCIPisInfinity(scip, xub) )
1307  {
1308  /* if a < 0.0, then a*x^2 is unbounded for x -> infinity, thus fix x to infinity */
1309  xfix = SCIPinfinity(scip);
1310  /* not needed: xfixobjval = SCIPinfinity(scip); */
1311  }
1312  else
1313  {
1314  if( xfix == SCIP_INVALID ) /*lint !e777*/
1315  {
1316  /* initialize with value for x=xub */
1317  xfix = xub;
1318  xfixobjval = a * xub * xub + b * xub + c;
1319  }
1320  else
1321  {
1322  /* compare with value for x=xub */
1323  cand = xub;
1324  if( xfixobjval > a * cand * cand + b * cand + c )
1325  {
1326  xfix = cand;
1327  xfixobjval = a * cand * cand + b * cand + c;
1328  }
1329  }
1330 
1331  /* compare with value for x=MAX(xlb,-offset) */
1332  cand = MAX(xlb, -consdata->xoffset);
1333  if( xfixobjval > a * cand * cand + b * cand + c )
1334  {
1335  xfix = cand;
1336  xfixobjval = a * cand * cand + b * cand + c;
1337  }
1338 
1339  /* compare with value for x=-b/(2*a), if within bounds */
1340  cand = -b/(2.0*a);
1341  if( cand > xlb && cand > -consdata->xoffset && cand < xub && xfixobjval > -b*b/(4.0*a) + c )
1342  {
1343  xfix = cand;
1344  /* not needed: xfixobjval = -b*b/(4.0*a) + c; */
1345  }
1346  }
1347  }
1348  assert(xfix != SCIP_INVALID); /*lint !e777*/
1349  assert(SCIPisInfinity(scip, -xlb) || SCIPisLE(scip, xlb, xfix));
1350  assert(SCIPisInfinity(scip, xub) || SCIPisGE(scip, xub, xfix));
1351  }
1352  else
1353  {
1354  /* skip dual presolve for exponents != 2 and z in objective for now */
1355  return SCIP_OKAY;
1356  }
1357 
1358  /* compute fixing value for z */
1359  if( SCIPisInfinity(scip, xfix) )
1360  {
1361  if( consdata->zcoef > 0.0 )
1362  {
1363  assert(SCIPisInfinity(scip, -SCIPvarGetLbGlobal(consdata->z)));
1364  zfix = -SCIPinfinity(scip);
1365  }
1366  else
1367  {
1368  assert(SCIPisInfinity(scip, SCIPvarGetUbGlobal(consdata->z)));
1369  zfix = SCIPinfinity(scip);
1370  }
1371  }
1372  else if( SCIPisInfinity(scip, -xfix) )
1373  {
1374  if( consdata->zcoef > 0.0 )
1375  {
1376  assert(SCIPisInfinity(scip, SCIPvarGetUbGlobal(consdata->z)));
1377  zfix = SCIPinfinity(scip);
1378  }
1379  else
1380  {
1381  assert(SCIPisInfinity(scip, -SCIPvarGetLbGlobal(consdata->z)));
1382  zfix = -SCIPinfinity(scip);
1383  }
1384  }
1385  else
1386  {
1387  SCIP_Real zlb;
1388  SCIP_Real zub;
1389 
1390  zlb = SCIPvarGetLbGlobal(consdata->z);
1391  zub = SCIPvarGetUbGlobal(consdata->z);
1392  zfix = consdata->rhs - SIGN(xfix + consdata->xoffset) * consdata->power(ABS(xfix + consdata->xoffset), consdata->exponent);
1393  zfix /= consdata->zcoef;
1394 
1395  /* project zfix into box, it should be at least very close */
1396  assert(SCIPisFeasLE(scip, zlb, zfix));
1397  assert(SCIPisFeasGE(scip, zub, zfix));
1398  zfix = MAX(zlb, MIN(zub, zfix));
1399  }
1400 
1401  /* fix variables according to x=xfix */
1402  SCIPdebugMsg(scip, "dual presolve fixes x=<%s>[%g,%g] to %g and z=<%s>[%g,%g] to %g in cons <%s>\n",
1403  SCIPvarGetName(consdata->x), xlb, xub, xfix,
1404  SCIPvarGetName(consdata->z), SCIPvarGetLbGlobal(consdata->z), SCIPvarGetUbGlobal(consdata->z), zfix,
1405  SCIPconsGetName(cons));
1406  SCIPdebugPrintCons(scip, cons, NULL);
1407 
1408  /* fix x */
1409  SCIP_CALL( SCIPfixVar(scip, consdata->x, xfix, cutoff, &fixed) );
1410  if( *cutoff )
1411  return SCIP_OKAY;
1412  if( fixed )
1413  ++*nfixedvars;
1414 
1415  /* fix z */
1416  SCIP_CALL( SCIPfixVar(scip, consdata->z, zfix, cutoff, &fixed) );
1417  if( *cutoff )
1418  return SCIP_OKAY;
1419  if( fixed )
1420  ++*nfixedvars;
1421 
1422  /* delete constraint */
1423  SCIP_CALL( SCIPdelCons(scip, cons) );
1424  ++*ndelconss;
1425  }
1426  }
1427 
1428  return SCIP_OKAY;
1429 }
1430 
1431 /** given a variable and an interval, tightens the local bounds of this variable to the given interval */
1432 static
1434  SCIP* scip, /**< SCIP data structure */
1435  SCIP_VAR* var, /**< variable which bounds to tighten */
1436  SCIP_INTERVAL bounds, /**< new bounds */
1437  SCIP_Bool force, /**< force tightening even if below bound strengthening tolerance */
1438  SCIP_CONS* cons, /**< constraint that is propagated */
1439  SCIP_RESULT* result, /**< pointer to store the result of the propagation call */
1440  int* nchgbds, /**< buffer where to add the number of changed bounds */
1441  int* nfixedvars, /**< buffer where to add the number of fixed variables, can be equal to nchgbds */
1442  int* naddconss /**< buffer where to add the number of added constraints, can be NULL if force is FALSE */
1443  )
1444 {
1445  SCIP_Bool infeas;
1446  SCIP_Bool tightened;
1447 
1448  assert(scip != NULL);
1449  assert(var != NULL);
1450  assert(cons != NULL);
1451  assert(result != NULL);
1452  assert(nchgbds != NULL);
1453  assert(nfixedvars != NULL);
1454 
1455  *result = SCIP_DIDNOTFIND;
1456 
1457  if( SCIPisInfinity(scip, SCIPintervalGetInf(bounds)) || SCIPisInfinity(scip, -SCIPintervalGetSup(bounds)) )
1458  {
1459  /* domain outside [-infty, +infty] -> declare as infeasible */
1460  *result = SCIP_CUTOFF;
1461  return SCIP_OKAY;
1462  }
1463 
1464  /* if variable is not multiaggregated (or aggregated to a multiaggregated), then try SCIPfixVar or SCIPtightenVarLb/Ub
1465  * otherwise, if bound tightening is forced, add a linear constraint
1466  * otherwise, forget about the bound tightening
1467  */
1469  {
1470  /* check if variable can be fixed */
1471  if( SCIPisEQ(scip, bounds.inf, bounds.sup) )
1472  {
1473  if( !SCIPisEQ(scip, SCIPvarGetLbLocal(var), SCIPvarGetUbLocal(var)) )
1474  {
1475  /* if variable not fixed yet, then do so now */
1476  SCIP_Real fixval;
1477 
1478  if( bounds.inf != bounds.sup ) /*lint !e777*/
1479  fixval = (bounds.inf + bounds.sup) / 2.0;
1480  else
1481  fixval = bounds.inf;
1482  SCIP_CALL( SCIPfixVar(scip, var, fixval, &infeas, &tightened) );
1483 
1484  if( infeas )
1485  {
1486  SCIPdebugMsg(scip, "found <%s> infeasible due to fixing variable <%s>\n", SCIPconsGetName(cons), SCIPvarGetName(var));
1487  *result = SCIP_CUTOFF;
1488  return SCIP_OKAY;
1489  }
1490  if( tightened )
1491  {
1492  SCIPdebugMsg(scip, "fixed variable <%s> in constraint <%s> to %g\n", SCIPvarGetName(var), SCIPconsGetName(cons), SCIPvarGetLbLocal(var));
1493  ++*nfixedvars;
1494  *result = SCIP_REDUCEDDOM;
1495  }
1496  }
1497  else
1498  {
1499  /* only check if new fixing value is consistent with variable bounds, otherwise cutoff */
1500  if( SCIPisLT(scip, bounds.sup, SCIPvarGetUbLocal(var)) || SCIPisGT(scip, bounds.inf, SCIPvarGetLbLocal(var)) )
1501  {
1502  SCIPdebugMsg(scip, "found <%s> infeasible due to fixing fixed variable <%s>[%.20g,%.20g] to [%.20g,%.20g]\n",
1503  SCIPconsGetName(cons), SCIPvarGetName(var), SCIPvarGetLbLocal(var), SCIPvarGetUbLocal(var), bounds.inf, bounds.sup);
1504  *result = SCIP_CUTOFF;
1505  return SCIP_OKAY;
1506  }
1507  }
1508 
1509  return SCIP_OKAY;
1510  }
1511 
1512  /* check if lower bound can be tightened */
1513  if( SCIPintervalGetInf(bounds) > SCIPvarGetLbLocal(var) )
1514  {
1515  assert(!SCIPisInfinity(scip, -SCIPintervalGetInf(bounds)));
1516  SCIP_CALL( SCIPtightenVarLb(scip, var, SCIPintervalGetInf(bounds), force, &infeas, &tightened) );
1517  if( infeas )
1518  {
1519  SCIPdebugMsg(scip, "found %s infeasible due to domain propagation for variable %s in constraint %s\n", SCIPconsGetName(cons), SCIPvarGetName(var), SCIPconsGetName(cons));
1520  *result = SCIP_CUTOFF;
1521  return SCIP_OKAY;
1522  }
1523  if( tightened )
1524  {
1525  SCIPdebugMsg(scip, "tightened lower bound of variable %s in constraint %s to %g\n", SCIPvarGetName(var), SCIPconsGetName(cons), SCIPvarGetLbLocal(var));
1526  ++*nchgbds;
1527  *result = SCIP_REDUCEDDOM;
1528  }
1529  }
1530 
1531  /* check if upper bound can be tightened */
1532  if( SCIPintervalGetSup(bounds) < SCIPvarGetUbLocal(var) )
1533  {
1534  assert(!SCIPisInfinity(scip, SCIPintervalGetSup(bounds)));
1535  SCIP_CALL( SCIPtightenVarUb(scip, var, SCIPintervalGetSup(bounds), force, &infeas, &tightened) );
1536  if( infeas )
1537  {
1538  SCIPdebugMsg(scip, "found %s infeasible due to domain propagation for linear variable %s in constraint %s\n", SCIPconsGetName(cons), SCIPvarGetName(var), SCIPconsGetName(cons));
1539  *result = SCIP_CUTOFF;
1540  return SCIP_OKAY;
1541  }
1542  if( tightened )
1543  {
1544  SCIPdebugMsg(scip, "tightened upper bound of variable %s in constraint %s to %g\n", SCIPvarGetName(var), SCIPconsGetName(cons), SCIPvarGetUbLocal(var));
1545  ++*nchgbds;
1546  *result = SCIP_REDUCEDDOM;
1547  }
1548  }
1549  }
1550  else if( force && (SCIPisLT(scip, SCIPvarGetLbLocal(var), bounds.inf) || SCIPisGT(scip, SCIPvarGetUbLocal(var), bounds.sup)) )
1551  {
1552  /* add a linear constraint bounds.inf <= x <= bounds.sup */
1553  SCIP_CONS* auxcons;
1554  SCIP_Bool local;
1555  SCIP_Real one;
1556 
1557  assert(naddconss != NULL);
1558 
1559  /* we add constraint as local constraint if we are during probing or if we are during solve and not at the root node */
1560  local = SCIPinProbing(scip) || (SCIPgetStage(scip) == SCIP_STAGE_SOLVING && (SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0));
1561 
1562  one = 1.0;
1563  SCIP_CALL( SCIPcreateConsLinear(scip, &auxcons, SCIPconsGetName(cons), 1, &var, &one, bounds.inf, bounds.sup,
1565  SCIPconsIsChecked(cons), SCIPconsIsPropagated(cons), local,
1566  FALSE, FALSE, TRUE, FALSE) );
1567 
1568  if( local )
1569  {
1570  SCIP_CALL( SCIPaddConsLocal(scip, auxcons, NULL) );
1571  }
1572  else
1573  {
1574  SCIP_CALL( SCIPaddCons(scip, auxcons) );
1575  }
1576  SCIP_CALL( SCIPreleaseCons(scip, &auxcons) );
1577 
1578  ++*naddconss;
1579  *result = SCIP_CONSADDED;
1580  }
1581 
1582  return SCIP_OKAY;
1583 }
1584 
1585 /** computes bounds on z in a absolute power constraints for given bounds on x */
1586 static
1587 void computeBoundsZ(
1588  SCIP* scip, /**< SCIP data structure */
1589  SCIP_CONS* cons, /**< constraint */
1590  SCIP_INTERVAL xbnds, /**< bounds on x that are to be propagated */
1591  SCIP_INTERVAL* zbnds /**< buffer to store corresponding bounds on z */
1592  )
1593 {
1594  SCIP_CONSDATA* consdata;
1595  SCIP_Real bnd;
1596  SCIP_Real x;
1597 
1598  assert(scip != NULL);
1599  assert(cons != NULL);
1600  assert(zbnds != NULL);
1601  assert(!SCIPintervalIsEmpty(SCIPinfinity(scip), xbnds));
1602 
1603  consdata = SCIPconsGetData(cons);
1604  assert(consdata != NULL);
1605 
1606  SCIPintervalSetEntire(SCIPinfinity(scip), zbnds);
1607 
1608  /* apply zcoef*z <= rhs - signedpow(xbnds.inf + offset, n) */
1609  if( !SCIPisInfinity(scip, consdata->rhs) && !SCIPisInfinity(scip, -xbnds.inf) )
1610  {
1611  x = xbnds.inf - PROPVARTOL + consdata->xoffset;
1612  bnd = consdata->rhs + PROPSIDETOL - SIGN(x) * consdata->power(REALABS(x), consdata->exponent);
1613 
1614  if( consdata->zcoef > 0.0 )
1615  zbnds->sup = bnd / consdata->zcoef;
1616  else
1617  zbnds->inf = bnd / consdata->zcoef;
1618  }
1619 
1620  /* apply zcoef*z >= lhs - signedpow(xbnds.sup + offset, n) */
1621  if( !SCIPisInfinity(scip, -consdata->lhs) && !SCIPisInfinity(scip, xbnds.sup) )
1622  {
1623  x = xbnds.sup + PROPVARTOL + consdata->xoffset;
1624  bnd = consdata->lhs - PROPSIDETOL - SIGN(x) * consdata->power(REALABS(x), consdata->exponent);
1625 
1626  if( consdata->zcoef > 0.0 )
1627  zbnds->inf = bnd / consdata->zcoef;
1628  else
1629  zbnds->sup = bnd / consdata->zcoef;
1630  }
1631 
1632  SCIPdebugMsg(scip, "given x = [%.20g, %.20g], computed z = [%.20g, %.20g] via", xbnds.inf, xbnds.sup, zbnds->inf, zbnds->sup);
1633  SCIPdebugPrintCons(scip, cons, NULL);
1634 
1635  assert(!SCIPintervalIsEmpty(SCIPinfinity(scip), *zbnds));
1636 }
1637 
1638 /** computes bounds on x in a absolute power constraints for given bounds on z */
1639 static
1640 void computeBoundsX(
1641  SCIP* scip, /**< SCIP data structure */
1642  SCIP_CONS* cons, /**< constraint */
1643  SCIP_INTERVAL zbnds, /**< bounds on x that are to be propagated */
1644  SCIP_INTERVAL* xbnds /**< buffer to store corresponding bounds on z */
1645  )
1646 {
1647  SCIP_CONSDATA* consdata;
1648  SCIP_Real bnd;
1649  SCIP_Real z;
1650 
1651  assert(scip != NULL);
1652  assert(cons != NULL);
1653  assert(xbnds != NULL);
1654  assert(!SCIPintervalIsEmpty(SCIPinfinity(scip), zbnds));
1655 
1656  consdata = SCIPconsGetData(cons);
1657  assert(consdata != NULL);
1658 
1659  SCIPintervalSetEntire(SCIPinfinity(scip), xbnds);
1660 
1661  /* apply signedpow(x+offset, n) <= rhs - (zcoef * zbnds).inf */
1662  z = (consdata->zcoef > 0.0 ? zbnds.inf : zbnds.sup);
1663  if( !SCIPisInfinity(scip, consdata->rhs) && !SCIPisInfinity(scip, REALABS(z)) )
1664  {
1665  bnd = consdata->rhs + PROPSIDETOL - consdata->zcoef * z + REALABS(consdata->zcoef) * PROPVARTOL;
1666  if( consdata->exponent == 2.0 )
1667  bnd = SIGN(bnd) * sqrt(REALABS(bnd));
1668  else
1669  bnd = SIGN(bnd) * pow(REALABS(bnd), 1.0/consdata->exponent);
1670  xbnds->sup = bnd - consdata->xoffset;
1671  }
1672 
1673  /* apply signedpow(x+offset, n) >= lhs - (zcoef * zbnds).sup */
1674  z = (consdata->zcoef > 0.0 ? zbnds.sup : zbnds.inf);
1675  if( !SCIPisInfinity(scip, consdata->rhs) && !SCIPisInfinity(scip, REALABS(z)) )
1676  {
1677  bnd = consdata->lhs - PROPSIDETOL - consdata->zcoef * z - REALABS(consdata->zcoef) * PROPVARTOL;
1678  if( consdata->exponent == 2.0 )
1679  bnd = SIGN(bnd) * sqrt(REALABS(bnd));
1680  else
1681  bnd = SIGN(bnd) * pow(REALABS(bnd), 1.0/consdata->exponent);
1682  xbnds->inf = bnd - consdata->xoffset;
1683  }
1684 
1685  SCIPdebugMsg(scip, "given z = [%.20g, %.20g], computed x = [%.20g, %.20g] via", zbnds.inf, zbnds.sup, xbnds->inf, xbnds->sup);
1686  SCIPdebugPrintCons(scip, cons, NULL);
1687 
1688  assert(!SCIPintervalIsEmpty(SCIPinfinity(scip), *xbnds));
1689 }
1690 
1691 /** checks if x or z is fixed and replaces them or deletes constraint */
1692 static
1694  SCIP* scip, /**< SCIP data structure */
1695  SCIP_CONSHDLR* conshdlr, /**< constraint handler for absolute power constraints */
1696  SCIP_CONS* cons, /**< constraint */
1697  int* ndelconss, /**< counter for number of deleted constraints */
1698  int* nupgdconss, /**< counter for number of upgraded constraints */
1699  int* nchgbds, /**< counter for number of variable bound changes */
1700  int* nfixedvars, /**< counter for number of variable fixations */
1701  SCIP_RESULT* result /**< to store result if we detect infeasibility or remove constraint */
1702  )
1703 {
1704  SCIP_CONSHDLRDATA* conshdlrdata;
1705  SCIP_CONSDATA* consdata;
1706  SCIP_Real scalar;
1707  SCIP_Real constant;
1708  SCIP_Real factor;
1709  SCIP_VAR* var;
1710 
1711  assert(scip != NULL);
1712  assert(cons != NULL);
1713  assert(ndelconss != NULL);
1714  assert(nupgdconss != NULL);
1715  assert(nchgbds != NULL);
1716  assert(nfixedvars != NULL);
1717 
1718  conshdlrdata = SCIPconshdlrGetData(conshdlr);
1719  assert(conshdlrdata != NULL);
1720 
1721  consdata = SCIPconsGetData(cons);
1722  assert(consdata != NULL);
1723 
1724  *result = SCIP_DIDNOTFIND;
1725 
1726  if( !SCIPvarIsActive(consdata->x) && SCIPvarGetStatus(consdata->x) != SCIP_VARSTATUS_MULTAGGR )
1727  {
1728  /* replace x variable */
1729 
1730  /* get relation x = scalar * var + constant */
1731  var = consdata->x;
1732  scalar = 1.0;
1733  constant = 0.0;
1734  SCIP_CALL( SCIPgetProbvarSum(scip, &var, &scalar, &constant) );
1735 
1736  if( scalar == 0.0 )
1737  {
1738  SCIP_INTERVAL xbnds;
1739  SCIP_INTERVAL zbnds;
1740  int naddconss;
1741 
1742  naddconss = 0;
1743 
1744  /* x has been fixed to constant */
1745  assert(SCIPisFeasEQ(scip, SCIPvarGetLbGlobal(consdata->x), constant));
1746  assert(SCIPisFeasEQ(scip, SCIPvarGetUbGlobal(consdata->x), constant));
1747 
1748  /* compute corresponding bounds on z */
1749  SCIPintervalSet(&xbnds, constant);
1750  computeBoundsZ(scip, cons, xbnds, &zbnds);
1751 
1752  SCIPdebugMsg(scip, "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);
1753 
1754  if( SCIPisEQ(scip, consdata->lhs, consdata->rhs) )
1755  {
1756  /* if sides are equal, then we should either fix z, or declare infeasibility */
1757  if( SCIPisFeasLT(scip, SCIPvarGetUbGlobal(consdata->z), zbnds.inf) || SCIPisFeasGT(scip, SCIPvarGetLbGlobal(consdata->z), zbnds.sup) )
1758  {
1759  SCIPdebugMsg(scip, "bounds inconsistent -> cutoff\n");
1760  *result = SCIP_CUTOFF;
1761  return SCIP_OKAY;
1762  }
1763  else
1764  {
1765  /* compute fixing value for z as value corresponding to fixing of x, projected onto bounds of z */
1766  SCIP_Real zfix;
1767 
1768  zfix = consdata->rhs - SIGN(constant + consdata->xoffset) * consdata->power(REALABS(constant + consdata->xoffset), consdata->exponent);
1769  zfix /= consdata->zcoef;
1770  assert(SCIPisLE(scip, zbnds.inf, zfix));
1771  assert(SCIPisGE(scip, zbnds.sup, zfix));
1772  zfix = MIN(SCIPvarGetUbGlobal(consdata->z), MAX(SCIPvarGetLbGlobal(consdata->z), zfix)); /*lint !e666*/
1773 
1774  zbnds.inf = zfix;
1775  zbnds.sup = zfix;
1776  SCIP_CALL( tightenBounds(scip, consdata->z, zbnds, TRUE, cons, result, nchgbds, nfixedvars, &naddconss) );
1777  }
1778  }
1779  else
1780  {
1781  /* tighten bounds on z accordingly */
1782  SCIP_CALL( tightenBounds(scip, consdata->z, zbnds, TRUE, cons, result, nchgbds, nfixedvars, &naddconss) );
1783  }
1784 
1785  /* delete constraint */
1786  SCIP_CALL( SCIPdelCons(scip, cons) );
1787 
1788  /* if tightenBounds added a constraint (because z was multiaggregated), then count this as constraint upgrade, otherwise as constraint deletion */
1789  if( naddconss > 0 )
1790  ++*nupgdconss;
1791  else
1792  ++*ndelconss;
1793 
1794  return SCIP_OKAY;
1795  }
1796 
1797  SCIPdebugMsg(scip, "in cons <%s>: x = <%s> replaced by %g*<%s> + %g\n", SCIPconsGetName(cons), SCIPvarGetName(consdata->x), scalar, SCIPvarGetName(var), constant);
1798 
1799  /* constraint will be divided by scalar*pow(|scalar|,exponent-1), if scalar is not 1.0 */
1800  if( scalar == 1.0 )
1801  factor = 1.0;
1802  else if( scalar > 0.0 )
1803  factor = consdata->power( scalar, consdata->exponent);
1804  else
1805  factor = -consdata->power(-scalar, consdata->exponent);
1806 
1807  /* aggregate only if this would not lead to a vanishing or infinite coefficient for z */
1808  if( !SCIPisZero(scip, consdata->zcoef / factor) && !SCIPisInfinity(scip, REALABS(consdata->zcoef / factor)) )
1809  {
1810  /* 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 */
1811  SCIP_CALL( dropVarEvents(scip, conshdlrdata->eventhdlr, cons) );
1812  SCIP_CALL( SCIPunlockVarCons(scip, consdata->x, cons, !SCIPisInfinity(scip, -consdata->lhs), !SCIPisInfinity(scip, consdata->rhs)) );
1813 
1814  consdata->x = var;
1815  if( SCIPvarIsActive(consdata->x) )
1816  {
1817  SCIP_CALL( SCIPmarkDoNotMultaggrVar(scip, consdata->x) );
1818  }
1819 
1820  /* add constant to offset */
1821  consdata->xoffset += constant;
1822 
1823  /* divide constraint by factor */
1824  if( scalar == 1.0 ) ;
1825  else if( scalar > 0.0 )
1826  {
1827  if( !SCIPisInfinity(scip, -consdata->lhs) )
1828  consdata->lhs /= factor;
1829  if( !SCIPisInfinity(scip, consdata->rhs) )
1830  consdata->rhs /= factor;
1831  consdata->zcoef /= factor;
1832  consdata->xoffset /= scalar;
1833  }
1834  else
1835  {
1836  SCIP_Real oldlhs;
1837 
1838  assert(scalar < 0.0);
1839  assert(factor < 0.0);
1840 
1841  oldlhs = consdata->lhs;
1842 
1843  if( !SCIPisInfinity(scip, consdata->rhs) )
1844  consdata->lhs = consdata->rhs / factor;
1845  else
1846  consdata->lhs = -SCIPinfinity(scip);
1847  if( !SCIPisInfinity(scip, -oldlhs) )
1848  consdata->rhs = oldlhs / factor;
1849  else
1850  consdata->rhs = SCIPinfinity(scip);
1851  consdata->zcoef /= factor;
1852  consdata->xoffset /= scalar;
1853  /* since we flip both constraint sides and the sign of zcoef, the events catched for z remain the same, so update necessary there */
1854  }
1855 
1856  SCIP_CALL( SCIPlockVarCons(scip, consdata->x, cons, !SCIPisInfinity(scip, -consdata->lhs), !SCIPisInfinity(scip, consdata->rhs)) );
1857  SCIP_CALL( catchVarEvents(scip, conshdlrdata->eventhdlr, cons) );
1858 
1859  SCIPdebugPrintCons(scip, cons, NULL);
1860 
1861  /* rerun constraint comparison */
1862  conshdlrdata->comparedpairwise = FALSE;
1863  }
1864  else
1865  {
1866  SCIPwarningMessage(scip, "Skip resolving aggregation of variable <%s> in abspower constraint <%s> to avoid zcoef = %g\n",
1867  SCIPvarGetName(consdata->x), SCIPconsGetName(cons), consdata->zcoef / factor);
1868  }
1869  }
1870 
1871  if( !SCIPvarIsActive(consdata->z) && SCIPvarGetStatus(consdata->z) != SCIP_VARSTATUS_MULTAGGR )
1872  {
1873  /* replace z variable */
1874 
1875  /* get relation z = scalar * var + constant */
1876  var = consdata->z;
1877  scalar = 1.0;
1878  constant = 0.0;
1879  SCIP_CALL( SCIPgetProbvarSum(scip, &var, &scalar, &constant) );
1880 
1881  if( scalar == 0.0 )
1882  {
1883  SCIP_INTERVAL xbnds;
1884  SCIP_INTERVAL zbnds;
1885  int naddconss;
1886 
1887  naddconss = 0;
1888 
1889  /* z has been fixed to constant */
1890  assert(SCIPisFeasEQ(scip, SCIPvarGetLbGlobal(consdata->z), constant));
1891  assert(SCIPisFeasEQ(scip, SCIPvarGetUbGlobal(consdata->z), constant));
1892 
1893  /* compute corresponding bounds on x */
1894  SCIPintervalSet(&zbnds, constant);
1895  computeBoundsX(scip, cons, zbnds, &xbnds);
1896 
1897  SCIPdebugMsg(scip, "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);
1898 
1899  if( SCIPisEQ(scip, consdata->lhs, consdata->rhs) )
1900  {
1901  /* if sides are equal, then we should either fix x, or declare infeasibility */
1902  if( SCIPisFeasLT(scip, SCIPvarGetUbGlobal(consdata->x), xbnds.inf) || SCIPisFeasGT(scip, SCIPvarGetLbGlobal(consdata->x), xbnds.sup) )
1903  {
1904  SCIPdebugMsg(scip, "bounds inconsistent -> cutoff\n");
1905  *result = SCIP_CUTOFF;
1906  return SCIP_OKAY;
1907  }
1908  else
1909  {
1910  /* compute fixing value for x as value corresponding to fixing of z, projected onto bounds of x */
1911  SCIP_Real xfix;
1912 
1913  xfix = consdata->rhs - consdata->zcoef * constant;
1914  if( consdata->exponent == 2.0 )
1915  xfix = SIGN(xfix) * sqrt(REALABS(xfix)) - consdata->xoffset;
1916  else
1917  xfix = SIGN(xfix) * pow(REALABS(xfix), 1.0/consdata->exponent) - consdata->xoffset;
1918  assert(SCIPisLE(scip, xbnds.inf, xfix));
1919  assert(SCIPisGE(scip, xbnds.sup, xfix));
1920  xfix = MIN(SCIPvarGetUbGlobal(consdata->x), MAX(SCIPvarGetLbGlobal(consdata->x), xfix)); /*lint !e666*/
1921 
1922  xbnds.inf = xfix;
1923  xbnds.sup = xfix;
1924  SCIP_CALL( tightenBounds(scip, consdata->x, xbnds, TRUE, cons, result, nchgbds, nfixedvars, &naddconss) );
1925  }
1926  }
1927  else
1928  {
1929  /* tighten bounds on x accordingly */
1930  SCIP_CALL( tightenBounds(scip, consdata->x, xbnds, TRUE, cons, result, nchgbds, nfixedvars, &naddconss) );
1931  }
1932 
1933  /* delete constraint */
1934  SCIP_CALL( SCIPdelCons(scip, cons) );
1935 
1936  /* if tightenBounds added a constraint (because x was multiaggregated), then count this as constraint upgrade, otherwise as constraint deletion */
1937  if( naddconss > 0 )
1938  ++*nupgdconss;
1939  else
1940  ++*ndelconss;
1941 
1942  return SCIP_OKAY;
1943  }
1944 
1945  SCIPdebugMsg(scip, "in cons <%s>: z = <%s> replaced by %g*<%s> + %g\n", SCIPconsGetName(cons), SCIPvarGetName(consdata->z), scalar, SCIPvarGetName(var), constant);
1946 
1947  /* 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 */
1948  SCIP_CALL( dropVarEvents(scip, conshdlrdata->eventhdlr, cons) );
1949  if( consdata->zcoef > 0.0 )
1950  SCIP_CALL( SCIPunlockVarCons(scip, consdata->z, cons, !SCIPisInfinity(scip, -consdata->lhs), !SCIPisInfinity(scip, consdata->rhs)) );
1951  else
1952  SCIP_CALL( SCIPunlockVarCons(scip, consdata->z, cons, !SCIPisInfinity(scip, consdata->rhs), !SCIPisInfinity(scip, -consdata->lhs)) );
1953 
1954  consdata->z = var;
1955  if( SCIPvarIsActive(consdata->z) )
1956  {
1957  SCIP_CALL( SCIPmarkDoNotMultaggrVar(scip, consdata->z) );
1958  }
1959 
1960  /* substract constant from constraint sides */
1961  if( !SCIPisInfinity(scip, -consdata->lhs) )
1962  consdata->lhs -= consdata->zcoef * constant;
1963  if( !SCIPisInfinity(scip, consdata->rhs) )
1964  consdata->rhs -= consdata->zcoef * constant;
1965 
1966  /* multiply zcoef by scalar */
1967  consdata->zcoef *= scalar;
1968 
1969  if( consdata->zcoef > 0.0 )
1970  SCIP_CALL( SCIPlockVarCons(scip, consdata->z, cons, !SCIPisInfinity(scip, -consdata->lhs), !SCIPisInfinity(scip, consdata->rhs)) );
1971  else
1972  SCIP_CALL( SCIPlockVarCons(scip, consdata->z, cons, !SCIPisInfinity(scip, consdata->rhs), !SCIPisInfinity(scip, -consdata->lhs)) );
1973  SCIP_CALL( catchVarEvents(scip, conshdlrdata->eventhdlr, cons) );
1974 
1975  /* rerun constraint comparison */
1976  conshdlrdata->comparedpairwise = FALSE;
1977  }
1978 
1979  assert(SCIPvarIsActive(consdata->z) || SCIPvarGetStatus(consdata->z) == SCIP_VARSTATUS_MULTAGGR);
1980 
1981  return SCIP_OKAY;
1982 }
1983 
1984 /** computes violation of a constraint */
1985 static
1987  SCIP* scip, /**< SCIP data structure */
1988  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
1989  SCIP_CONS* cons, /**< constraint */
1990  SCIP_SOL* sol, /**< solution or NULL if LP solution should be used */
1991  SCIP_Real* viol, /**< pointer to store absolute (unscaled) constraint violation */
1992  SCIP_Bool* solviolbounds /**< buffer to store whether the solution violates bounds on x by more than feastol */
1993  )
1994 {
1995  SCIP_CONSDATA* consdata;
1996  SCIP_Real val;
1997  SCIP_Real xval;
1998  SCIP_Real zval;
1999  SCIP_Real relviol;
2000 
2001  assert(scip != NULL);
2002  assert(conshdlr != NULL);
2003  assert(cons != NULL);
2004  assert(viol != NULL);
2005  assert(solviolbounds != NULL);
2006 
2007  consdata = SCIPconsGetData(cons);
2008  assert(consdata != NULL);
2009 
2010  *solviolbounds = FALSE;
2011  xval = SCIPgetSolVal(scip, sol, consdata->x);
2012  zval = SCIPgetSolVal(scip, sol, consdata->z);
2013 
2014  if( SCIPisInfinity(scip, REALABS(xval)) )
2015  {
2016  consdata->lhsviol = (SCIPisInfinity(scip, -consdata->lhs) ? 0.0 : SCIPinfinity(scip));
2017  consdata->rhsviol = (SCIPisInfinity(scip, consdata->rhs) ? 0.0 : SCIPinfinity(scip));
2018 
2019  return SCIP_OKAY;
2020  }
2021 
2022  if( sol == NULL )
2023  {
2024  SCIP_Real lb;
2025  SCIP_Real ub;
2026 
2027  lb = SCIPvarGetLbLocal(consdata->x);
2028  ub = SCIPvarGetUbLocal(consdata->x);
2029 
2030  /* with non-initial columns, variables can shortly be a column variable before entering the LP and have value 0.0 in this case, which might be outside bounds */
2031  if( (!SCIPisInfinity(scip, -lb) && !SCIPisFeasGE(scip, xval, lb)) || (!SCIPisInfinity(scip, ub) && !SCIPisFeasLE(scip, xval, ub)) )
2032  *solviolbounds = TRUE;
2033  else
2034  xval = MAX(lb, MIN(ub, xval)); /* project x onto local box if just slightly outside (or even not outside) */
2035  }
2036 
2037  xval += consdata->xoffset;
2038 
2039  val = SIGN(xval) * consdata->power(REALABS(xval), consdata->exponent);
2040  val += consdata->zcoef * zval;
2041 
2042  *viol = 0.0;
2043  relviol = 0.0;
2044  if( val < consdata->lhs && !SCIPisInfinity(scip, -consdata->lhs) )
2045  {
2046  consdata->lhsviol = *viol = consdata->lhs - val;
2047  relviol = SCIPrelDiff(consdata->lhs, val);
2048  }
2049  else
2050  consdata->lhsviol = 0.0;
2051 
2052  if( val > consdata->rhs && !SCIPisInfinity(scip, consdata->rhs) )
2053  {
2054  consdata->rhsviol = *viol = val - consdata->rhs;
2055  relviol = SCIPrelDiff(val, consdata->rhs);
2056  }
2057  else
2058  consdata->rhsviol = 0.0;
2059 
2060  if( sol != NULL )
2061  SCIPupdateSolConsViolation(scip, sol, *viol, relviol);
2062 
2063  return SCIP_OKAY;
2064 }
2065 
2066 /** computes violation of a set of constraints */
2067 static
2069  SCIP* scip, /**< SCIP data structure */
2070  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
2071  SCIP_CONS** conss, /**< constraints */
2072  int nconss, /**< number of constraints */
2073  SCIP_SOL* sol, /**< solution or NULL if LP solution should be used */
2074  SCIP_Bool* solviolbounds, /**< buffer to store whether the solution violates bounds on x by more than feastol */
2075  SCIP_CONS** maxviolcon /**< buffer to store constraint with largest violation, or NULL if solution is feasible */
2076  )
2077 {
2078  SCIP_CONSDATA* consdata;
2079  SCIP_Real viol;
2080  SCIP_Real maxviol;
2081  SCIP_Bool solviolbounds1;
2082  int c;
2083 
2084  assert(scip != NULL);
2085  assert(conss != NULL || nconss == 0);
2086  assert(solviolbounds != NULL);
2087  assert(maxviolcon != NULL);
2088 
2089  *solviolbounds = FALSE;
2090  *maxviolcon = NULL;
2091 
2092  maxviol = 0.0;
2093 
2094  for( c = 0; c < nconss; ++c )
2095  {
2096  assert(conss != NULL);
2097  assert(conss[c] != NULL);
2098 
2099  SCIP_CALL( computeViolation(scip, conshdlr, conss[c], sol, &viol, &solviolbounds1) );
2100  *solviolbounds |= solviolbounds1;
2101 
2102  consdata = SCIPconsGetData(conss[c]);
2103  assert(consdata != NULL);
2104 
2105  viol = MAX(consdata->lhsviol, consdata->rhsviol);
2106  if( viol > maxviol && SCIPisGT(scip, viol, SCIPfeastol(scip)) )
2107  {
2108  maxviol = viol;
2109  *maxviolcon = conss[c];
2110  }
2111  }
2112 
2113  return SCIP_OKAY;
2114 }
2115 
2116 /** proposes branching point for constraint */
2117 static
2119  SCIP* scip, /**< SCIP data structure */
2120  SCIP_CONS* cons, /**< constraint which variable to get branching point for */
2121  SCIP_SOL* sol, /**< solution to branch on (NULL for LP or pseudosol) */
2122  int preferzero, /**< how much we prefer branching on -xoffset (0, 1, or 2) if sign is not fixed */
2123  SCIP_Bool branchminconverror /**< whether to minimize convexification error if sign is fixed */
2124  )
2125 {
2126  SCIP_CONSDATA* consdata;
2127  SCIP_VAR* x;
2128  SCIP_Real xref;
2129  SCIP_Real zref;
2130  SCIP_Real xlb;
2131  SCIP_Real xub;
2132 
2133  assert(scip != NULL);
2134  assert(cons != NULL);
2135 
2136  consdata = SCIPconsGetData(cons);
2137  assert(consdata != NULL);
2138 
2139  x = consdata->x;
2140  xlb = SCIPvarGetLbLocal(x);
2141  xub = SCIPvarGetUbLocal(x);
2142 
2143  /* check if sign of x is not fixed yet */
2144  if( SCIPisLT(scip, xlb, -consdata->xoffset) && SCIPisGT(scip, xub, -consdata->xoffset) )
2145  {
2146  /* if preferzero is 0, just return SCIP_INVALID
2147  * if preferzero is 1, then propose -xoffset if branching on -xoffset would cut off solution in both child nodes, otherwise return SCIP_INVALID
2148  * if preferzero is >1, then always propose -xoffset
2149  */
2150  assert(preferzero >= 0);
2151 
2152  if( preferzero == 0 )
2153  return SCIP_INVALID;
2154 
2155  if( preferzero > 1 || SCIPisInfinity(scip, -xlb) || SCIPisInfinity(scip, xub) )
2156  return -consdata->xoffset;
2157 
2158  xlb += consdata->xoffset;
2159  xub += consdata->xoffset;
2160 
2161  xref = SCIPgetSolVal(scip, sol, x) + consdata->xoffset;
2162  zref = SCIPgetSolVal(scip, sol, consdata->z);
2163  if( SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
2164  {
2165  /* signpow(x,n,offset) + c*z <= 0 is violated
2166  * if we are close to or right of -offset, then branching on -offset gives a convex function on the right branch, this is good
2167  * 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
2168  */
2169  if( !SCIPisFeasNegative(scip, xref) || SCIPisFeasPositive(scip, -consdata->power(-xlb, consdata->exponent)*xref/xlb + consdata->zcoef * zref) )
2170  return -consdata->xoffset;
2171  return SCIP_INVALID;
2172  }
2173 
2174  assert(SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) );
2175  /* signpow(x,n) + c*z >= 0 is violated
2176  * 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
2177  * 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
2178  */
2179  if( !SCIPisFeasPositive(scip, xref) || SCIPisFeasNegative(scip, -consdata->power(xub, consdata->exponent)*xref/xub + consdata->zcoef * zref) )
2180  return -consdata->xoffset;
2181  return SCIP_INVALID;
2182  }
2183 
2184  if( branchminconverror )
2185  {
2186  /* 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
2187  * for branching on ( (ub^n - lb^n) / (n*(ub - lb)) ) ^ (1/(n-1))
2188  */
2189  if( SCIPisGE(scip, xlb, -consdata->xoffset) )
2190  {
2191  SCIP_Real ref;
2192  xlb = MAX(0.0, xlb + consdata->xoffset);
2193  xub = MAX(0.0, xub + consdata->xoffset);
2194 
2195  ref = (consdata->power(xub, consdata->exponent) - consdata->power(xlb, consdata->exponent)) / (consdata->exponent * (xub - xlb));
2196  ref = pow(ref, 1.0/(consdata->exponent-1.0));
2197  ref -= consdata->xoffset;
2198  assert(SCIPisGE(scip, ref, SCIPvarGetLbLocal(x)));
2199  assert(SCIPisLE(scip, ref, SCIPvarGetUbLocal(x)));
2200 
2201  return ref;
2202  }
2203  else
2204  {
2205  SCIP_Real ref;
2206 
2207  assert(SCIPisLE(scip, xub, -consdata->xoffset));
2208 
2209  xlb = MIN(0.0, xlb + consdata->xoffset);
2210  xub = MIN(0.0, xub + consdata->xoffset);
2211 
2212  ref = (consdata->power(-xlb, consdata->exponent) - consdata->power(-xub, consdata->exponent)) / (consdata->exponent * (-xlb + xub));
2213  ref = -pow(ref, 1.0/(consdata->exponent-1.0));
2214  ref -= consdata->xoffset;
2215  assert(SCIPisGE(scip, ref, SCIPvarGetLbLocal(x)));
2216  assert(SCIPisLE(scip, ref, SCIPvarGetUbLocal(x)));
2217 
2218  return ref;
2219  }
2220  }
2221 
2222  return SCIP_INVALID;
2223 }
2224 
2225 /** registers branching variable candidates
2226  * registers x for all violated absolute power constraints where x is not in convex region
2227  */
2228 static
2230  SCIP* scip, /**< SCIP data structure */
2231  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
2232  SCIP_CONS** conss, /**< constraints to check */
2233  int nconss, /**< number of constraints to check */
2234  SCIP_SOL* sol, /**< solution to enforce (NULL for the LP solution) */
2235  int* nnotify /**< counter for number of notifications performed */
2236  )
2237 {
2238  SCIP_CONSHDLRDATA* conshdlrdata;
2239  SCIP_CONSDATA* consdata;
2240  SCIP_Bool onlynonfixedsign;
2241  int c;
2242 
2243  assert(scip != NULL);
2244  assert(conshdlr != NULL);
2245  assert(conss != NULL || nconss == 0);
2246 
2247  conshdlrdata = SCIPconshdlrGetData(conshdlr);
2248  assert(conshdlrdata != NULL);
2249 
2250  *nnotify = 0;
2251 
2252  onlynonfixedsign = conshdlrdata->preferzerobranch == 3;
2253 
2254  do
2255  {
2256  for( c = 0; c < nconss; ++c )
2257  {
2258  assert(conss[c] != NULL); /*lint !e613*/
2259 
2260  /* skip constraints that have been marked to be removed by propagateCons() */
2261  if( !SCIPconsIsEnabled(conss[c]) ) /*lint !e613*/
2262  continue;
2263 
2264  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
2265  assert(consdata != NULL);
2266 
2267  SCIPdebugMsg(scip, "cons <%s> violation: %g %g\n", SCIPconsGetName(conss[c]), consdata->lhsviol, consdata->rhsviol); /*lint !e613*/
2268 
2269  /* skip variables which sign is already fixed, if we are only interested in variables with unfixed sign here */
2270  if( onlynonfixedsign &&
2271  ( !SCIPisLT(scip, SCIPvarGetLbLocal(consdata->x), -consdata->xoffset) ||
2272  !SCIPisGT(scip, SCIPvarGetUbLocal(consdata->x), consdata->xoffset)) )
2273  continue;
2274 
2275  /* if the value of x lies in a concave range (i.e., where a secant approximation is used), then register x as branching variable */
2276  if( (SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) && (SCIPisInfinity(scip, -SCIPvarGetLbLocal(consdata->x)) || SCIPgetSolVal(scip, sol, consdata->x) + consdata->xoffset <= -consdata->root * (SCIPvarGetLbLocal(consdata->x) + consdata->xoffset))) ||
2277  ( SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) && (SCIPisInfinity(scip, SCIPvarGetUbLocal(consdata->x)) || SCIPgetSolVal(scip, sol, consdata->x) + consdata->xoffset >= -consdata->root * (SCIPvarGetUbLocal(consdata->x) + consdata->xoffset))) )
2278  {
2279  /* domain propagation should have removed constraints with fixed x, at least for violated constraints */
2280  assert(!SCIPisRelEQ(scip, SCIPvarGetLbLocal(consdata->x), SCIPvarGetUbLocal(consdata->x)));
2281 
2282  SCIPdebugMsg(scip, "register var <%s> in cons <%s> with violation %g %g\n", SCIPvarGetName(consdata->x), SCIPconsGetName(conss[c]), consdata->lhsviol, consdata->rhsviol); /*lint !e613*/
2283  SCIP_CALL( SCIPaddExternBranchCand(scip, consdata->x, MAX(consdata->lhsviol, consdata->rhsviol), proposeBranchingPoint(scip, conss[c], sol, conshdlrdata->preferzerobranch, conshdlrdata->branchminconverror)) ); /*lint !e613*/
2284  ++*nnotify;
2285  }
2286  }
2287 
2288  if( onlynonfixedsign && *nnotify == 0 )
2289  {
2290  /* 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 */
2291  onlynonfixedsign = FALSE;
2292  continue;
2293  }
2294  break;
2295  }
2296  while( TRUE ); /*lint !e506 */
2297 
2298  return SCIP_OKAY; /*lint !e438*/
2299 }
2300 
2301 /** registers a variable from a violated constraint as branching candidate that has a large absolute value in the relaxation */
2302 static
2304  SCIP* scip, /**< SCIP data structure */
2305  SCIP_CONS** conss, /**< constraints */
2306  int nconss, /**< number of constraints */
2307  SCIP_SOL* sol, /**< solution to enforce (NULL for the LP solution) */
2308  SCIP_VAR** brvar /**< buffer to store branching variable */
2309  )
2310 {
2311  SCIP_CONSDATA* consdata;
2312  SCIP_Real val;
2313  SCIP_Real brvarval;
2314  int c;
2315 
2316  assert(scip != NULL);
2317  assert(conss != NULL || nconss == 0);
2318 
2319  *brvar = NULL;
2320  brvarval = -1.0;
2321 
2322  for( c = 0; c < nconss; ++c )
2323  {
2324  assert(conss != NULL);
2325  consdata = SCIPconsGetData(conss[c]);
2326  assert(consdata != NULL);
2327 
2328  /* skip constraints that have been marked to be removed by propagateCons() */
2329  if( !SCIPconsIsEnabled(conss[c]) )
2330  continue;
2331 
2332  if( !SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) && !SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
2333  continue;
2334 
2335  val = SCIPgetSolVal(scip, sol, consdata->x) + consdata->xoffset;
2336  if( REALABS(val) > brvarval )
2337  {
2338  brvarval = ABS(val);
2339  *brvar = consdata->x;
2340  }
2341  }
2342 
2343  if( *brvar != NULL )
2344  {
2345  SCIP_CALL( SCIPaddExternBranchCand(scip, *brvar, brvarval, SCIP_INVALID) );
2346  }
2347 
2348  return SCIP_OKAY;
2349 }
2350 
2351 /* try to fix almost fixed x variable in violated constraint */
2352 static
2354  SCIP* scip, /**< SCIP data structure */
2355  SCIP_CONS** conss, /**< constraints */
2356  int nconss, /**< number of constraints */
2357  SCIP_Bool* infeasible, /**< buffer to store whether infeasibility was detected */
2358  SCIP_Bool* reduceddom /**< buffer to store whether some variable bound was tightened */
2359  )
2360 {
2361  SCIP_CONSDATA* consdata;
2362  SCIP_Real lb;
2363  SCIP_Real ub;
2364  SCIP_Bool tightened;
2365  int c;
2366 
2367  assert(scip != NULL);
2368  assert(conss != NULL);
2369  assert(infeasible != NULL);
2370  assert(reduceddom != NULL);
2371 
2372  *infeasible = FALSE;
2373  *reduceddom = FALSE;
2374 
2375  for( c = 0; c < nconss; ++c )
2376  {
2377  consdata = SCIPconsGetData(conss[c]);
2378  assert(consdata != NULL);
2379 
2380  /* if constraint not violated, then continue */
2381  if( !SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) && !SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
2382  continue;
2383 
2384  lb = SCIPvarGetLbLocal(consdata->x);
2385  ub = SCIPvarGetUbLocal(consdata->x);
2386 
2387  /* if x not almost fixed, then continue */
2388  if( !SCIPisRelEQ(scip, lb, ub) )
2389  continue;
2390 
2391  /* if x fixed already, then continue */
2392  if( SCIPisEQ(scip, lb, ub) )
2393  continue;
2394 
2395  assert(!SCIPisInfinity(scip, -lb));
2396  assert(!SCIPisInfinity(scip, ub));
2397 
2398  /* try to fix variable */
2399  SCIP_CALL( SCIPtightenVarLb(scip, consdata->x, (lb+ub)/2.0, TRUE, infeasible, &tightened) );
2400  if( *infeasible )
2401  {
2402  SCIPdebugMsg(scip, "Fixing almost fixed variable <%s> lead to infeasibility.\n", SCIPvarGetName(consdata->x));
2403  return SCIP_OKAY;
2404  }
2405  if( tightened )
2406  {
2407  SCIPdebugMsg(scip, "Tightened lower bound of almost fixed variable <%s>.\n", SCIPvarGetName(consdata->x));
2408  *reduceddom = TRUE;
2409  }
2410 
2411  SCIP_CALL( SCIPtightenVarUb(scip, consdata->x, (lb+ub)/2.0, TRUE, infeasible, &tightened) );
2412  if( *infeasible )
2413  {
2414  SCIPdebugMsg(scip, "Fixing almost fixed variable <%s> lead to infeasibility.\n", SCIPvarGetName(consdata->x));
2415  return SCIP_OKAY;
2416  }
2417  if( tightened )
2418  {
2419  SCIPdebugMsg(scip, "Tightened upper bound of almost fixed variable <%s>.\n", SCIPvarGetName(consdata->x));
2420  *reduceddom = TRUE;
2421  }
2422 
2423  /* stop as soon as one variable has been fixed to start another enfo round */
2424  if( *reduceddom )
2425  break;
2426  }
2427 
2428  return SCIP_OKAY;
2429 }
2430 
2431 /** resolves a propagation on the given variable by supplying the variables needed for applying the corresponding
2432  * propagation rule (see propagateCons()):
2433  * see cons_varbound
2434  */
2435 static
2437  SCIP* scip, /**< SCIP data structure */
2438  SCIP_CONS* cons, /**< constraint that inferred the bound change */
2439  SCIP_VAR* infervar, /**< variable that was deduced */
2440  PROPRULE proprule, /**< propagation rule that deduced the bound change */
2441  SCIP_BOUNDTYPE boundtype, /**< the type of the changed bound (lower or upper bound) */
2442  SCIP_BDCHGIDX* bdchgidx /**< bound change index (time stamp of bound change), or NULL for current time */
2443  )
2444 {
2445  SCIP_CONSDATA* consdata;
2446 
2447  assert(scip != NULL);
2448  assert(cons != NULL);
2449  assert(infervar != NULL);
2450 
2451  consdata = SCIPconsGetData(cons);
2452  assert(consdata != NULL);
2453  assert(consdata->zcoef != 0.0);
2454 
2455  switch( proprule )
2456  {
2457  case PROPRULE_1:
2458  /* lhs <= sign(x+offset)|x+offset|^n + c*z: left hand side and bounds on z -> lower bound on x */
2459  assert(infervar == consdata->x);
2460  assert(boundtype == SCIP_BOUNDTYPE_LOWER);
2461  assert(!SCIPisInfinity(scip, -consdata->lhs));
2462  if( consdata->zcoef > 0.0 )
2463  {
2464  SCIP_CALL( SCIPaddConflictUb(scip, consdata->z, bdchgidx) );
2465  }
2466  else
2467  {
2468  SCIP_CALL( SCIPaddConflictLb(scip, consdata->z, bdchgidx) );
2469  }
2470  break;
2471 
2472  case PROPRULE_2:
2473  /* lhs <= sign(x+offset)|x+offset|^n + c*z: left hand side and upper bound on x -> bound on z */
2474  assert(infervar == consdata->z);
2475  assert(!SCIPisInfinity(scip, -consdata->lhs));
2476  SCIP_CALL( SCIPaddConflictUb(scip, consdata->x, bdchgidx) );
2477  break;
2478 
2479  case PROPRULE_3:
2480  /* sign(x+offset)|x+offset|^n + c*z <= rhs: right hand side and bounds on z -> upper bound on x */
2481  assert(infervar == consdata->x);
2482  assert(boundtype == SCIP_BOUNDTYPE_UPPER);
2483  assert(!SCIPisInfinity(scip, consdata->rhs));
2484  if( consdata->zcoef > 0.0 )
2485  {
2486  SCIP_CALL( SCIPaddConflictLb(scip, consdata->z, bdchgidx) );
2487  }
2488  else
2489  {
2490  SCIP_CALL( SCIPaddConflictUb(scip, consdata->z, bdchgidx) );
2491  }
2492  break;
2493 
2494  case PROPRULE_4:
2495  /* sign(x+offset)|x+offset|^n + c*z <= rhs: right hand side and lower bound on x -> bound on z */
2496  assert(infervar == consdata->z);
2497  assert(!SCIPisInfinity(scip, consdata->rhs));
2498  SCIP_CALL( SCIPaddConflictLb(scip, consdata->x, bdchgidx) );
2499  break;
2500 
2501  case PROPRULE_INVALID:
2502  default:
2503  SCIPerrorMessage("invalid inference information %d in absolute power constraint <%s>\n", proprule, SCIPconsGetName(cons));
2504  return SCIP_INVALIDDATA;
2505  }
2506 
2507  return SCIP_OKAY;
2508 }
2509 
2510 /** analyze infeasibility */
2511 static
2513  SCIP* scip, /**< SCIP data structure */
2514  SCIP_CONS* cons, /**< variable bound constraint */
2515  SCIP_VAR* infervar, /**< variable that was deduced */
2516  PROPRULE proprule, /**< propagation rule that deduced the bound change */
2517  SCIP_BOUNDTYPE boundtype /**< the type of the changed bound (lower or upper bound) */
2518  )
2519 {
2520  /* conflict analysis can only be applied in solving stage and if it turned on */
2522  return SCIP_OKAY;
2523 
2524  /* initialize conflict analysis, and add all variables of infeasible constraint to conflict candidate queue */
2526 
2527  /* add the bound which got violated */
2528  if( boundtype == SCIP_BOUNDTYPE_LOWER )
2529  {
2530  SCIP_CALL( SCIPaddConflictUb(scip, infervar, NULL) );
2531  }
2532  else
2533  {
2534  assert(boundtype == SCIP_BOUNDTYPE_UPPER);
2535  SCIP_CALL( SCIPaddConflictLb(scip, infervar, NULL) );
2536  }
2537 
2538  /* add the reason for the violated of the bound */
2539  SCIP_CALL( resolvePropagation(scip, cons, infervar, proprule, boundtype, NULL) );
2540 
2541  /* analyze the conflict */
2542  SCIP_CALL( SCIPanalyzeConflictCons(scip, cons, NULL) );
2543 
2544  return SCIP_OKAY;
2545 }
2546 
2547 /** propagation method for absolute power constraint
2548  * SCIPinferVarXbCons to allow for repropagation
2549  */
2550 static
2552  SCIP* scip, /**< SCIP data structure */
2553  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
2554  SCIP_CONS* cons, /**< variable bound constraint */
2555  SCIP_Bool canaddcons, /**< are we allowed to add a linear constraint when enforcing bounds for a multiaggregated variable? */
2556  SCIP_Bool* cutoff, /**< pointer to store whether the node can be cut off */
2557  int* nchgbds, /**< pointer to count number of bound changes */
2558  int* naddconss /**< pointer to count number of added constraints */
2559  )
2560 {
2561  SCIP_CONSDATA* consdata;
2562  SCIP_Real xlb;
2563  SCIP_Real xub;
2564  SCIP_Real zlb;
2565  SCIP_Real zub;
2566  SCIP_Real newlb;
2567  SCIP_Real newub;
2568  SCIP_Bool tightened;
2569  SCIP_Bool tightenedround;
2570  SCIP_Real minact;
2571  SCIP_Real maxact;
2572 
2573  assert(conshdlr != NULL);
2574  assert(cutoff != NULL);
2575  assert(nchgbds != NULL);
2576  assert(naddconss != NULL);
2577 
2578  consdata = SCIPconsGetData(cons);
2579  assert(consdata != NULL);
2580 
2581  SCIPdebugMsg(scip, "propagating absolute power constraint <%s>\n", SCIPconsGetName(cons));
2582 
2583  *cutoff = FALSE;
2584 
2585  /* get current bounds of variables */
2586  xlb = SCIPvarGetLbLocal(consdata->x);
2587  xub = SCIPvarGetUbLocal(consdata->x);
2588  zlb = SCIPvarGetLbLocal(consdata->z);
2589  zub = SCIPvarGetUbLocal(consdata->z);
2590 
2591  /* if some bound is not tightened, tighten bounds of variables as long as possible */
2592  tightenedround = SCIPconsIsMarkedPropagate(cons);
2593  while( tightenedround )
2594  {
2595  tightenedround = FALSE;
2596 
2597  /* propagate left hand side inequality: lhs <= (x+offset)*|x+offset|^n + c*z */
2598  if( !SCIPisInfinity(scip, -consdata->lhs) )
2599  {
2600  assert(!*cutoff);
2601 
2602  /* propagate bounds on x (if not multiaggregated):
2603  * (1) left hand side and bounds on z -> lower bound on x
2604  */
2605  if( SCIPvarIsActive(SCIPvarGetProbvar(consdata->x)) && (!SCIPisFeasEQ(scip, zlb, zub) || !SCIPisInfinity(scip, REALABS(zlb))) )
2606  {
2607  /* if z is fixed, first compute new lower bound on x without tolerances
2608  * if that is feasible, project new lower bound onto current bounds
2609  * otherwise, recompute with tolerances and continue as usual
2610  * do this only if variable is not essentially fixed to value of infinity
2611  */
2612  if( SCIPisFeasEQ(scip, zlb, zub) && !SCIPisInfinity(scip, zub) )
2613  {
2614  assert(!SCIPisInfinity(scip, -zlb));
2615 
2616  newlb = consdata->lhs - consdata->zcoef * (consdata->zcoef > 0.0 ? zub : zlb);
2617 
2618  /* invert sign(x+offset)|x+offset|^(n-1) = y -> x = sign(y)|y|^(1/n) - offset */
2619  if( consdata->exponent == 2.0 )
2620  newlb = SIGN(newlb) * sqrt(ABS(newlb));
2621  else
2622  newlb = SIGN(newlb) * pow(ABS(newlb), 1.0/consdata->exponent);
2623  newlb -= consdata->xoffset;
2624 
2625  if( SCIPisFeasGT(scip, newlb, xub) )
2626  {
2627  /* if new lower bound for x would yield cutoff, recompute with tolerances */
2628  newlb = consdata->lhs - PROPSIDETOL - consdata->zcoef * (consdata->zcoef > 0.0 ? (zub + PROPVARTOL) : (zlb - PROPVARTOL));
2629 
2630  /* invert sign(x+offset)|x+offset|^(n-1) = y -> x = sign(y)|y|^(1/n) - offset */
2631  if( consdata->exponent == 2.0 )
2632  newlb = SIGN(newlb) * sqrt(ABS(newlb));
2633  else
2634  newlb = SIGN(newlb) * pow(ABS(newlb), 1.0/consdata->exponent);
2635  newlb -= consdata->xoffset;
2636  }
2637  else
2638  {
2639  /* project new lower bound onto current bounds */
2640  newlb = MIN(newlb, xub);
2641  }
2642  }
2643  else
2644  {
2645  if( consdata->zcoef > 0.0 )
2646  {
2647  if( !SCIPisInfinity(scip, zub) )
2648  newlb = consdata->lhs - PROPSIDETOL - consdata->zcoef * (zub + PROPVARTOL);
2649  else
2650  newlb = -SCIPinfinity(scip);
2651  }
2652  else
2653  {
2654  if( !SCIPisInfinity(scip, -zlb) )
2655  newlb = consdata->lhs - PROPSIDETOL - consdata->zcoef * (zlb - PROPVARTOL);
2656  else
2657  newlb = -SCIPinfinity(scip);
2658  }
2659 
2660  if( !SCIPisInfinity(scip, -newlb) )
2661  {
2662  /* invert sign(x+offset)|x+offset|^(n-1) = y -> x = sign(y)|y|^(1/n) - offset */
2663  if( consdata->exponent == 2.0 )
2664  newlb = SIGN(newlb) * sqrt(ABS(newlb));
2665  else
2666  newlb = SIGN(newlb) * pow(ABS(newlb), 1.0/consdata->exponent);
2667  newlb -= consdata->xoffset;
2668  }
2669  }
2670 
2671  if( SCIPisInfinity(scip, newlb) )
2672  {
2673  /* we cannot fix a variable to +infinity, so let's report cutoff (there is no solution within SCIPs limitations to infinity) */
2674  SCIPdebugMsg(scip, " -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g] -> cutoff\n", SCIPvarGetName(consdata->x), xlb, xub, newlb, xub);
2675 
2676  *cutoff = TRUE;
2677 
2678  /* analyze infeasibility */
2679  SCIP_CALL( analyzeConflict(scip, cons, consdata->x, PROPRULE_1, SCIP_BOUNDTYPE_LOWER) );
2680  break;
2681  }
2682 
2683  if( !SCIPisInfinity(scip, -newlb) )
2684  {
2685  if( SCIPisLbBetter(scip, newlb, xlb, xub) )
2686  {
2687  SCIPdebugMsg(scip, " -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g]\n",
2688  SCIPvarGetName(consdata->x), xlb, xub, newlb, xub);
2689  SCIP_CALL( SCIPinferVarLbCons(scip, consdata->x, newlb, cons, (int)PROPRULE_1, FALSE, cutoff, &tightened) );
2690 
2691  if( *cutoff )
2692  {
2693  assert(SCIPisInfinity(scip, newlb) || SCIPisGT(scip, newlb, SCIPvarGetUbLocal(consdata->x)));
2694 
2695  /* analyze infeasibility */
2696  SCIP_CALL( analyzeConflict(scip, cons, consdata->x, PROPRULE_1, SCIP_BOUNDTYPE_LOWER) );
2697  break;
2698  }
2699 
2700  if( tightened )
2701  {
2702  tightenedround = TRUE;
2703  (*nchgbds)++;
2704  }
2705  xlb = SCIPvarGetLbLocal(consdata->x);
2706  }
2707  }
2708  }
2709 
2710  assert(!*cutoff);
2711 
2712  /* propagate bounds on z:
2713  * (2) left hand side and upper bound on x -> bound on z
2714  */
2715  if( SCIPvarGetStatus(consdata->z) != SCIP_VARSTATUS_MULTAGGR && !SCIPisInfinity(scip, xub) ) /* cannot change bounds of multaggr vars */
2716  {
2717  SCIP_Real newbd;
2718 
2719  /* if x is fixed, first compute new bound on z without tolerances
2720  * if that is feasible, project new bound onto current bounds
2721  * otherwise, recompute with tolerances and continue as usual
2722  */
2723  if( SCIPisFeasEQ(scip, xlb, xub) )
2724  {
2725  newbd = xub + consdata->xoffset;
2726  newbd = consdata->lhs - SIGN(newbd) * consdata->power(REALABS(newbd), consdata->exponent);
2727  newbd /= consdata->zcoef;
2728 
2729  if( SCIPisInfinity(scip, newbd) )
2730  newbd = SCIPinfinity(scip);
2731  else if( SCIPisInfinity(scip, -newbd) )
2732  newbd = -SCIPinfinity(scip);
2733 
2734  if( (consdata->zcoef > 0.0 && SCIPisFeasGT(scip, newbd, zub)) || (consdata->zcoef < 0.0 && SCIPisFeasLT(scip, newbd, zlb)) )
2735  {
2736  /* if infeasible, recompute with tolerances */
2737  newbd = xub + PROPVARTOL + consdata->xoffset;
2738  newbd = consdata->lhs - PROPSIDETOL - SIGN(newbd) * consdata->power(REALABS(newbd), consdata->exponent);
2739  newbd /= consdata->zcoef;
2740  }
2741  else
2742  {
2743  /* project onto current bounds of z */
2744  newbd = MIN(zub, MAX(zlb, newbd) );
2745  }
2746  }
2747  else
2748  {
2749  newbd = xub + PROPVARTOL + consdata->xoffset;
2750  newbd = consdata->lhs - PROPSIDETOL - SIGN(newbd) * consdata->power(REALABS(newbd), consdata->exponent);
2751  newbd /= consdata->zcoef;
2752  }
2753 
2754  if( consdata->zcoef > 0.0 )
2755  {
2756  newlb = newbd;
2757 
2758  if( SCIPisInfinity(scip, newlb) )
2759  {
2760  /* we cannot fix a variable to +infinity, so let's report cutoff (there is no solution within SCIPs limitations to infinity) */
2761  SCIPdebugMsg(scip, " -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g] -> cutoff\n", SCIPvarGetName(consdata->z), zlb, zub, newlb, zub);
2762 
2763  *cutoff = TRUE;
2764 
2765  /* analyze infeasibility */
2766  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_2, SCIP_BOUNDTYPE_LOWER) );
2767  break;
2768  }
2769 
2770  if( SCIPisLbBetter(scip, newlb, zlb, zub) )
2771  {
2772  SCIPdebugMsg(scip, " -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g]\n",
2773  SCIPvarGetName(consdata->z), zlb, zub, newlb, zub);
2774  SCIP_CALL( SCIPinferVarLbCons(scip, consdata->z, newlb, cons, (int)PROPRULE_2, FALSE, cutoff, &tightened) );
2775 
2776  if( *cutoff )
2777  {
2778  assert(SCIPisInfinity(scip, newlb) || SCIPisGT(scip, newlb, SCIPvarGetUbLocal(consdata->z)));
2779 
2780  /* analyze infeasibility */
2781  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_2, SCIP_BOUNDTYPE_LOWER) );
2782  break;
2783  }
2784 
2785  if( tightened )
2786  {
2787  tightenedround = TRUE;
2788  (*nchgbds)++;
2789  }
2790  zlb = SCIPvarGetLbLocal(consdata->z);
2791  }
2792  }
2793  else
2794  {
2795  newub = newbd;
2796 
2797  if( SCIPisInfinity(scip, -newub) )
2798  {
2799  /* we cannot fix a variable to -infinity, so let's report cutoff (there is no solution within SCIPs limitations to infinity) */
2800  SCIPdebugMsg(scip, " -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g] -> cutoff\n", SCIPvarGetName(consdata->z), zlb, zub, zlb, newub);
2801 
2802  *cutoff = TRUE;
2803 
2804  /* analyze infeasibility */
2805  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_2, SCIP_BOUNDTYPE_UPPER) );
2806  break;
2807  }
2808 
2809  if( SCIPisUbBetter(scip, newub, zlb, zub) )
2810  {
2811  SCIPdebugMsg(scip, " -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g]\n",
2812  SCIPvarGetName(consdata->z), zlb, zub, zlb, newub);
2813  SCIP_CALL( SCIPinferVarUbCons(scip, consdata->z, newub, cons, (int)PROPRULE_2, FALSE, cutoff, &tightened) );
2814 
2815  if( *cutoff )
2816  {
2817  assert(SCIPisInfinity(scip, -newub) || SCIPisLT(scip, newub, SCIPvarGetLbLocal(consdata->z)));
2818 
2819  /* analyze infeasibility */
2820  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_2, SCIP_BOUNDTYPE_UPPER) );
2821  break;
2822  }
2823 
2824  if( tightened )
2825  {
2826  tightenedround = TRUE;
2827  (*nchgbds)++;
2828  }
2829  zub = SCIPvarGetUbLocal(consdata->z);
2830  }
2831  }
2832  }
2833  }
2834 
2835  assert(!*cutoff);
2836 
2837  /* propagate right hand side inequality: sign(x+offset)|x+offset|^n + c*z <= rhs */
2838  if( !SCIPisInfinity(scip, consdata->rhs) )
2839  {
2840  /* propagate bounds on x:
2841  * (3) right hand side and bounds on z -> upper bound on x
2842  */
2843  if( SCIPvarIsActive(SCIPvarGetProbvar(consdata->x)) && (!SCIPisFeasEQ(scip, zlb, zub) || !SCIPisInfinity(scip, REALABS(zlb))) ) /* cannot change bounds of multaggr or fixed vars */
2844  {
2845  /* if z is fixed, first compute new upper bound on x without tolerances
2846  * if that is feasible, project new upper bound onto current bounds
2847  * otherwise, recompute with tolerances and continue as usual
2848  * do this only if variable is not essentially fixed to value of infinity
2849  */
2850  if( SCIPisFeasEQ(scip, zlb, zub) && !SCIPisInfinity(scip, zub) )
2851  {
2852  assert(!SCIPisInfinity(scip, -zlb));
2853 
2854  newub = consdata->rhs - consdata->zcoef * (consdata->zcoef > 0.0 ? zlb : zub);
2855 
2856  /* invert sign(x+offset)|x+offset|^(n-1) = y -> x = sign(y)|y|^(1/n) - offset */
2857  if( consdata->exponent == 2.0 )
2858  newub = SIGN(newub) * sqrt(ABS(newub));
2859  else
2860  newub = SIGN(newub) * pow(ABS(newub), 1.0/consdata->exponent);
2861  newub -= consdata->xoffset;
2862 
2863  if( SCIPisFeasLT(scip, newub, xlb) )
2864  {
2865  /* if new lower bound for x would yield cutoff, recompute with tolerances */
2866  newub = consdata->rhs + PROPSIDETOL - consdata->zcoef * (consdata->zcoef > 0.0 ? (zlb - PROPVARTOL) : (zub + PROPVARTOL));
2867 
2868  /* invert sign(x+offset)|x+offset|^(n-1) = y -> x = sign(y)|y|^(1/n) - offset */
2869  if( consdata->exponent == 2.0 )
2870  newub = SIGN(newub) * sqrt(ABS(newub));
2871  else
2872  newub = SIGN(newub) * pow(ABS(newub), 1.0/consdata->exponent);
2873  newub -= consdata->xoffset;
2874  }
2875  else
2876  {
2877  /* project new upper bound onto current bounds */
2878  newub = MAX(newub, xlb);
2879  }
2880  }
2881  else
2882  {
2883  if( consdata->zcoef > 0.0 )
2884  {
2885  if( !SCIPisInfinity(scip, -zlb) )
2886  newub = consdata->rhs + PROPSIDETOL - consdata->zcoef * (zlb - PROPVARTOL);
2887  else
2888  newub = SCIPinfinity(scip);
2889  }
2890  else
2891  {
2892  if( !SCIPisInfinity(scip, zub) )
2893  newub = consdata->rhs + PROPSIDETOL - consdata->zcoef * (zub + PROPVARTOL);
2894  else
2895  newub = SCIPinfinity(scip);
2896  }
2897  if( !SCIPisInfinity(scip, newub) )
2898  {
2899  /* invert sign(x+offset)|x+offset|^(n-1) = y -> x = sign(y)|y|^(1/n) - offset */
2900  if( consdata->exponent == 2.0 )
2901  newub = SIGN(newub) * sqrt(ABS(newub));
2902  else
2903  newub = SIGN(newub) * pow(ABS(newub), 1.0/consdata->exponent);
2904  newub -= consdata->xoffset;
2905  }
2906  }
2907 
2908  if( SCIPisInfinity(scip, -newub) )
2909  {
2910  /* we cannot fix a variable to -infinity, so let's report cutoff (there is no solution within SCIPs limitations to infinity) */
2911  SCIPdebugMsg(scip, " -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g] -> cutoff\n", SCIPvarGetName(consdata->x), xlb, xub, xlb, newub);
2912 
2913  *cutoff = TRUE;
2914 
2915  /* analyze infeasibility */
2916  SCIP_CALL( analyzeConflict(scip, cons, consdata->x, PROPRULE_3, SCIP_BOUNDTYPE_UPPER) );
2917  break;
2918  }
2919 
2920  if( !SCIPisInfinity(scip, newub) )
2921  {
2922  if( SCIPisUbBetter(scip, newub, xlb, xub) )
2923  {
2924  SCIPdebugMsg(scip, " -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g]\n",
2925  SCIPvarGetName(consdata->x), xlb, xub, xlb, newub);
2926  SCIP_CALL( SCIPinferVarUbCons(scip, consdata->x, newub, cons, (int)PROPRULE_3, FALSE, cutoff, &tightened) );
2927 
2928  if( *cutoff )
2929  {
2930  assert(SCIPisInfinity(scip, -newub) || SCIPisLT(scip, newub, SCIPvarGetLbLocal(consdata->x)));
2931 
2932  /* analyze infeasibility */
2933  SCIP_CALL( analyzeConflict(scip, cons, consdata->x, PROPRULE_3, SCIP_BOUNDTYPE_UPPER) );
2934  break;
2935  }
2936 
2937  if( tightened )
2938  {
2939  tightenedround = TRUE;
2940  (*nchgbds)++;
2941  }
2942  xub = SCIPvarGetUbLocal(consdata->x);
2943  }
2944  }
2945  }
2946 
2947  assert(!*cutoff);
2948 
2949  /* propagate bounds on z:
2950  * (4) right hand side and lower bound on x -> bound on z
2951  */
2952  if( SCIPvarGetStatus(consdata->z) != SCIP_VARSTATUS_MULTAGGR && !SCIPisInfinity(scip, -xlb) ) /* cannot change bounds of multaggr vars */
2953  {
2954  SCIP_Real newbd;
2955 
2956  /* if x is fixed, first compute new bound on z without tolerances
2957  * if that is feasible, project new bound onto current bounds
2958  * otherwise, recompute with tolerances and continue as usual
2959  */
2960  if( SCIPisFeasEQ(scip, xlb, xub) )
2961  {
2962  newbd = xlb + consdata->xoffset;
2963  newbd = consdata->rhs - SIGN(newbd) * consdata->power(REALABS(newbd), consdata->exponent);
2964  newbd /= consdata->zcoef;
2965 
2966  if( SCIPisInfinity(scip, newbd) )
2967  newbd = SCIPinfinity(scip);
2968  else if( SCIPisInfinity(scip, -newbd) )
2969  newbd = -SCIPinfinity(scip);
2970 
2971  if( (consdata->zcoef > 0.0 && SCIPisFeasLT(scip, newbd, zlb)) || (consdata->zcoef < 0.0 && SCIPisFeasGT(scip, newbd, zub)) )
2972  {
2973  /* if infeasible, recompute with tolerances */
2974  newbd = xlb - PROPVARTOL + consdata->xoffset;
2975  newbd = consdata->rhs + PROPSIDETOL - SIGN(newbd) * consdata->power(REALABS(newbd), consdata->exponent);
2976  newbd /= consdata->zcoef;
2977  }
2978  else
2979  {
2980  /* project onto current bounds of z */
2981  newbd = MIN(zub, MAX(zlb, newbd) );
2982  }
2983  }
2984  else
2985  {
2986  newbd = xlb - PROPVARTOL + consdata->xoffset;
2987  newbd = consdata->rhs + PROPSIDETOL - SIGN(newbd) * consdata->power(REALABS(newbd), consdata->exponent);
2988  newbd /= consdata->zcoef;
2989  }
2990 
2991  if( consdata->zcoef > 0.0 )
2992  {
2993  newub = newbd;
2994 
2995  if( SCIPisInfinity(scip, -newub) )
2996  {
2997  /* we cannot fix a variable to -infinity, so let's report cutoff (there is no solution within SCIPs limitations to infinity) */
2998  SCIPdebugMsg(scip, " -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g] -> cutoff\n", SCIPvarGetName(consdata->z), zlb, zub, zlb, newub);
2999 
3000  *cutoff = TRUE;
3001 
3002  /* analyze infeasibility */
3003  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_4, SCIP_BOUNDTYPE_UPPER) );
3004  break;
3005  }
3006 
3007  if( SCIPisUbBetter(scip, newub, zlb, zub) )
3008  {
3009  SCIPdebugMsg(scip, " -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g]\n",
3010  SCIPvarGetName(consdata->z), zlb, zub, zlb, newub);
3011  SCIP_CALL( SCIPinferVarUbCons(scip, consdata->z, newub, cons, (int)PROPRULE_4, FALSE, cutoff, &tightened) );
3012 
3013  if( *cutoff )
3014  {
3015  assert(SCIPisInfinity(scip, -newub) || SCIPisLT(scip, newub, SCIPvarGetLbLocal(consdata->z)));
3016 
3017  /* analyze infeasibility */
3018  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_4, SCIP_BOUNDTYPE_UPPER) );
3019  break;
3020  }
3021 
3022  if( tightened )
3023  {
3024  tightenedround = TRUE;
3025  (*nchgbds)++;
3026  }
3027  zub = SCIPvarGetUbLocal(consdata->z);
3028  }
3029  }
3030  else
3031  {
3032  newlb = newbd;
3033 
3034  if( SCIPisInfinity(scip, newlb) )
3035  {
3036  /* we cannot fix a variable to +infinity, so let's report cutoff (there is no solution within SCIPs limitations to infinity) */
3037  SCIPdebugMsg(scip, " -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g] -> cutoff\n", SCIPvarGetName(consdata->z), zlb, zub, newlb, zub);
3038 
3039  *cutoff = TRUE;
3040 
3041  /* analyze infeasibility */
3042  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_4, SCIP_BOUNDTYPE_LOWER) );
3043  break;
3044  }
3045 
3046  if( SCIPisLbBetter(scip, newlb, zlb, zub) )
3047  {
3048  SCIPdebugMsg(scip, " -> tighten <%s>[%.15g,%.15g] -> [%.15g,%.15g]\n",
3049  SCIPvarGetName(consdata->z), zlb, zub, newlb, zub);
3050  SCIP_CALL( SCIPinferVarLbCons(scip, consdata->z, newlb, cons, (int)PROPRULE_4, FALSE, cutoff, &tightened) );
3051 
3052  if( *cutoff )
3053  {
3054  assert(SCIPisInfinity(scip, newlb) || SCIPisGT(scip, newlb, SCIPvarGetUbLocal(consdata->z)));
3055 
3056  /* analyze infeasibility */
3057  SCIP_CALL( analyzeConflict(scip, cons, consdata->z, PROPRULE_4, SCIP_BOUNDTYPE_LOWER) );
3058  break;
3059  }
3060 
3061  if( tightened )
3062  {
3063  tightenedround = TRUE;
3064  (*nchgbds)++;
3065  }
3066  zlb = SCIPvarGetLbLocal(consdata->z);
3067  }
3068  }
3069  }
3070  }
3071 
3072  assert(!*cutoff);
3073  }
3074 
3075  /* mark the constraint propagated */
3076  SCIP_CALL( SCIPunmarkConsPropagate(scip, cons) );
3077 
3078  if( *cutoff )
3079  return SCIP_OKAY;
3080 
3081  /* check for redundancy */
3082  if( !SCIPisInfinity(scip, -xlb) && !SCIPisInfinity(scip, consdata->zcoef > 0.0 ? -zlb : zub) )
3083  minact = SIGN(xlb + consdata->xoffset) * consdata->power(REALABS(xlb + consdata->xoffset), consdata->exponent) + consdata->zcoef * (consdata->zcoef > 0.0 ? zlb : zub);
3084  else
3085  minact = -SCIPinfinity(scip);
3086 
3087  if( !SCIPisInfinity(scip, xub) && !SCIPisInfinity(scip, consdata->zcoef > 0.0 ? zub : -zlb) )
3088  maxact = SIGN(xub + consdata->xoffset) * consdata->power(REALABS(xub + consdata->xoffset), consdata->exponent) + consdata->zcoef * (consdata->zcoef > 0.0 ? zub : zlb);
3089  else
3090  maxact = SCIPinfinity(scip);
3091 
3092  if( (SCIPisInfinity(scip, -consdata->lhs) || SCIPisGE(scip, minact, consdata->lhs)) &&
3093  (SCIPisInfinity(scip, consdata->rhs) || SCIPisLE(scip, maxact, consdata->rhs)) )
3094  {
3095  SCIPdebugMsg(scip, "absolute power constraint <%s> is redundant: <%s>[%.15g,%.15g], <%s>[%.15g,%.15g]\n",
3096  SCIPconsGetName(cons),
3097  SCIPvarGetName(consdata->x), SCIPvarGetLbLocal(consdata->x), SCIPvarGetUbLocal(consdata->x),
3098  SCIPvarGetName(consdata->z), SCIPvarGetLbLocal(consdata->z), SCIPvarGetUbLocal(consdata->z));
3099 
3100  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
3101 
3102  return SCIP_OKAY;
3103  }
3104 
3105  /* delete constraint if x has been fixed */
3106  if( SCIPisRelEQ(scip, xlb, xub) && (SCIPvarIsActive(consdata->z) || canaddcons) )
3107  {
3108  SCIP_RESULT tightenresult;
3109  SCIP_INTERVAL xbnds;
3110  SCIP_INTERVAL zbnds;
3111 
3112  SCIPdebugMsg(scip, "x-variable in constraint <%s> is fixed: x = <%s>[%.15g,%.15g], z = <%s>[%.15g,%.15g]\n",
3113  SCIPconsGetName(cons), SCIPvarGetName(consdata->x), xlb, xub, SCIPvarGetName(consdata->z), zlb, zub);
3114 
3115  SCIPintervalSetBounds(&xbnds, MIN(xlb, xub), MAX(xlb, xub));
3116  computeBoundsZ(scip, cons, xbnds, &zbnds);
3117 
3118  /* 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 */
3119  SCIP_CALL( tightenBounds(scip, consdata->z, zbnds, TRUE, cons, &tightenresult, nchgbds, nchgbds, naddconss) );
3120  if( tightenresult == SCIP_CUTOFF )
3121  *cutoff = TRUE;
3122 
3123  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
3124 
3125  return SCIP_OKAY;
3126  }
3127 
3128  /* delete constraint if z has been fixed */
3129  if( SCIPisRelEQ(scip, zlb, zub) && (SCIPvarIsActive(consdata->x) || canaddcons) )
3130  {
3131  SCIP_RESULT tightenresult;
3132  SCIP_INTERVAL xbnds;
3133  SCIP_INTERVAL zbnds;
3134 
3135  SCIPdebugMsg(scip, "z-variable in constraint <%s> is fixed: x = <%s>[%.15g,%.15g], z = <%s>[%.15g,%.15g]\n",
3136  SCIPconsGetName(cons), SCIPvarGetName(consdata->x), xlb, xub, SCIPvarGetName(consdata->z), zlb, zub);
3137 
3138  SCIPintervalSetBounds(&zbnds, MIN(zlb, zub), MAX(zlb, zub));
3139  computeBoundsX(scip, cons, zbnds, &xbnds);
3140 
3141  /* 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 */
3142  SCIP_CALL( tightenBounds(scip, consdata->x, xbnds, TRUE, cons, &tightenresult, nchgbds, nchgbds, naddconss) );
3143  if( tightenresult == SCIP_CUTOFF )
3144  *cutoff = TRUE;
3145 
3146  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
3147 
3148  return SCIP_OKAY;
3149  }
3150 
3151  return SCIP_OKAY;
3152 }
3153 
3154 /** notifies SCIP about a variable bound lhs <= x + c*y <= rhs */
3155 static
3157  SCIP* scip, /**< SCIP data structure */
3158  SCIP_CONS* cons, /**< absolute power constraint this variable bound is derived form */
3159  SCIP_Bool addcons, /**< should the variable bound be added as constraint to SCIP? */
3160  SCIP_VAR* var, /**< variable x for which we want to add a variable bound */
3161  SCIP_VAR* vbdvar, /**< variable y which makes the bound a variable bound */
3162  SCIP_Real vbdcoef, /**< coefficient c of bounding variable vbdvar */
3163  SCIP_Real lhs, /**< left hand side of varbound constraint */
3164  SCIP_Real rhs, /**< right hand side of varbound constraint */
3165  SCIP_Bool* infeas, /**< pointer to store whether an infeasibility was detected */
3166  int* nbdchgs, /**< pointer where to add number of performed bound changes */
3167  int* naddconss /**< pointer where to add number of added constraints */
3168  )
3169 {
3170  int nbdchgs_local;
3171 
3172  assert(scip != NULL);
3173  assert(cons != NULL);
3174  assert(var != NULL);
3175  assert(vbdvar != NULL);
3176  assert(!SCIPisZero(scip, vbdcoef));
3177  assert(!SCIPisInfinity(scip, ABS(vbdcoef)));
3178  assert(infeas != NULL);
3179 
3180  *infeas = FALSE;
3181 
3182  /* make sure vbdvar is active, so we can search for it in SCIPvarGetVxbdVars() */
3183  if( !SCIPvarIsActive(vbdvar) )
3184  {
3185  SCIP_Real constant;
3186 
3187  constant = 0.0;
3188  SCIP_CALL( SCIPgetProbvarSum(scip, &vbdvar, &vbdcoef, &constant) );
3189  if( !SCIPvarIsActive(vbdvar) || (vbdcoef == 0.0) )
3190  return SCIP_OKAY;
3191 
3192  if( !SCIPisInfinity(scip, -lhs) )
3193  lhs -= constant;
3194  if( !SCIPisInfinity(scip, rhs) )
3195  rhs -= constant;
3196  }
3197 
3198  /* vbdvar should be a non-fixed binary variable */
3199  assert(SCIPvarIsIntegral(vbdvar));
3200  assert(SCIPisZero(scip, SCIPvarGetLbGlobal(vbdvar)));
3201  assert(SCIPisEQ(scip, SCIPvarGetUbGlobal(vbdvar), 1.0));
3202 
3203  SCIPdebugMsg(scip, "-> %g <= <%s> + %g*<%s> <= %g\n", lhs, SCIPvarGetName(var), vbdcoef, SCIPvarGetName(vbdvar), rhs);
3204 
3205  if( addcons && SCIPvarGetStatus(var) != SCIP_VARSTATUS_MULTAGGR )
3206  {
3207  SCIP_CONS* vbdcons;
3208  char name[SCIP_MAXSTRLEN];
3209 
3210  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_vbnd", SCIPconsGetName(cons));
3211 
3212  SCIP_CALL( SCIPcreateConsVarbound(scip, &vbdcons, name, var, vbdvar, vbdcoef, lhs, rhs,
3214  SCIP_CALL( SCIPaddCons(scip, vbdcons) );
3215  SCIP_CALL( SCIPreleaseCons(scip, &vbdcons) );
3216 
3217  ++*naddconss;
3218 
3219  return SCIP_OKAY;
3220  }
3221 
3222  if( !SCIPisInfinity(scip, -lhs) )
3223  {
3224  SCIP_CALL( SCIPaddVarVlb(scip, var, vbdvar, -vbdcoef, lhs, infeas, &nbdchgs_local) );
3225  if( *infeas )
3226  return SCIP_OKAY;
3227  *nbdchgs += nbdchgs_local;
3228  }
3229 
3230  if( !SCIPisInfinity(scip, rhs) )
3231  {
3232  SCIP_CALL( SCIPaddVarVub(scip, var, vbdvar, -vbdcoef, rhs, infeas, &nbdchgs_local) );
3233  if( *infeas )
3234  return SCIP_OKAY;
3235  *nbdchgs += nbdchgs_local;
3236  }
3237 
3238  return SCIP_OKAY;
3239 }
3240 
3241 /** propagates varbounds of variables
3242  * Let f(x) = sign(x+offset)|x+offset|^n, f^{-1}(y) = sign(y)|y|^(1/n) - offset.
3243  * Thus, constraint is lhs <= f(x) + c*z <= rhs.
3244  *
3245  * Given a variable bound constraint x <= a*y + b with y a binary variable, one obtains
3246  * y = 0 -> f(x) <= f(b) -> lhs <= f(b) + c*z
3247  * y = 1 -> f(x) <= f(a+b) -> lhs <= f(a+b) + c*z
3248  * => lhs <= f(b) + y * (f(a+b)-f(b)) + c*z
3249  *
3250  * Given a variable bound constraint x >= a*y + b with y a binary variable, one obtains analogously
3251  * f(b) + y * (f(a+b)-f(b)) + c*z <= rhs
3252  *
3253  * Given a variable bound constraint c*z <= a*y + b with y a binary variable, one obtains
3254  * y = 0 -> lhs <= f(x) + b -> x >= f^{-1}(lhs - b)
3255  * y = 1 -> lhs <= f(x) + a+b -> x >= f^{-1}(lhs - (a+b))
3256  * => x >= f^{-1}(lhs - b) + y * (f^{-1}(lhs - (a+b)) - f^{-1}(lhs - b))
3257  *
3258  * Given a variable bound constraint c*z >= a*y + b with y a binary variable, one obtains analogously
3259  * x <= f^{-1}(rhs - b) + y * (f^{-1}(rhs - (a+b)) - f^{-1}(rhs - b))
3260  */
3261 static
3263  SCIP* scip, /**< SCIP data structure */
3264  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
3265  SCIP_CONS* cons, /**< absolute power constraint */
3266  SCIP_Bool* infeas, /**< pointer to store whether an infeasibility was detected */
3267  int* nbdchgs, /**< pointer where to add number of performed bound changes */
3268  int* naddconss /**< pointer where to add number of added constraints */
3269  )
3270 {
3271  SCIP_CONSHDLRDATA* conshdlrdata;
3272  SCIP_CONSDATA* consdata;
3273  SCIP_VAR* y;
3274  SCIP_Real a;
3275  SCIP_Real b;
3276  SCIP_Real fb;
3277  SCIP_Real fab;
3278  SCIP_Real vbcoef;
3279  SCIP_Real vbconst;
3280  int i;
3281 
3282  assert(scip != NULL);
3283  assert(conshdlr != NULL);
3284  assert(cons != NULL);
3285  assert(infeas != NULL);
3286  assert(nbdchgs != NULL);
3287  assert(naddconss != NULL);
3288 
3289  *infeas = FALSE;
3290 
3291  conshdlrdata = SCIPconshdlrGetData(conshdlr);
3292  assert(conshdlrdata != NULL);
3293 
3294  consdata = SCIPconsGetData(cons);
3295  assert(consdata != NULL);
3296  assert(consdata->z != NULL);
3297 
3298  /* don't do anything if it looks like we have numerical troubles */
3299  if( SCIPisZero(scip, consdata->zcoef) )
3300  return SCIP_OKAY;
3301 
3302  if( !SCIPisInfinity(scip, -consdata->lhs) )
3303  {
3304  /* propagate varbounds x <= a*y+b onto z
3305  * lhs <= f(b) + y * (f(a+b)-f(b)) + c*z
3306  * -> c*z >= lhs-f(b) + y * (f(b)-f(a+b))
3307  */
3308  for( i = 0; i < SCIPvarGetNVubs(consdata->x); ++i )
3309  {
3310  y = SCIPvarGetVubVars(consdata->x)[i];
3311  a = SCIPvarGetVubCoefs(consdata->x)[i];
3312  b = SCIPvarGetVubConstants(consdata->x)[i];
3313 
3314  /* skip variable bound if y is not integer or its valid values are not {0,1}
3315  * @todo extend to arbitrary integer variables
3316  */
3317  if( !SCIPvarIsBinary(y) || SCIPvarGetLbGlobal(y) > 0.5 || SCIPvarGetUbGlobal(y) < 0.5 )
3318  continue;
3319 
3320  /* skip variable bound if coefficient is very small */
3321  if( SCIPisFeasZero(scip, consdata->power(a, consdata->exponent)) )
3322  continue;
3323 
3324  SCIPdebugMsg(scip, "propagate variable bound <%s> <= %g*<%s> + %g\n", SCIPvarGetName(consdata->x), a, SCIPvarGetName(y), b);
3325 
3326  fb = SIGN( b + consdata->xoffset) * consdata->power( b + consdata->xoffset, consdata->exponent); /* f( b) = sign( b) | b|^n */
3327  fab = SIGN(a+b + consdata->xoffset) * consdata->power(a+b + consdata->xoffset, consdata->exponent); /* f(a+b) = sign(a+b) |a+b|^n */
3328 
3329  vbcoef = (fb - fab) / consdata->zcoef;
3330  vbconst = (consdata->lhs - fb) / consdata->zcoef;
3331 
3332  if( consdata->zcoef > 0.0 )
3333  {
3334  /* add varbound z >= (lhs-f(b))/c + y * (f(b)-f(a+b))/c */
3335  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->z, y, -vbcoef, vbconst, SCIPinfinity(scip), infeas, nbdchgs, naddconss) );
3336  }
3337  else
3338  {
3339  /* add varbound z <= (lhs-f(b))/c + y * (f(b)-f(a+b))/c */
3340  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->z, y, -vbcoef, -SCIPinfinity(scip), vbconst, infeas, nbdchgs, naddconss) );
3341  }
3342  if( *infeas )
3343  return SCIP_OKAY;
3344  }
3345  }
3346 
3347  /* propagate varbounds x >= a*y+b onto z
3348  * f(b) + y * (f(a+b)-f(b)) + c*z <= rhs
3349  * -> c*z <= rhs-f(b) + y * (f(b)-f(a+b))
3350  */
3351  if( !SCIPisInfinity(scip, consdata->rhs) )
3352  {
3353  for( i = 0; i < SCIPvarGetNVlbs(consdata->x); ++i )
3354  {
3355  y = SCIPvarGetVlbVars(consdata->x)[i];
3356  a = SCIPvarGetVlbCoefs(consdata->x)[i];
3357  b = SCIPvarGetVlbConstants(consdata->x)[i];
3358 
3359  /* skip variable bound if y is not integer or its valid values are not {0,1}
3360  * @todo extend to arbitrary integer variables
3361  */
3362  if( !SCIPvarIsBinary(y) || SCIPvarGetLbGlobal(y) > 0.5 || SCIPvarGetUbGlobal(y) < 0.5 )
3363  continue;
3364 
3365  /* skip variable bound if coefficient is very small */
3366  if( SCIPisFeasZero(scip, consdata->power(a, consdata->exponent)) )
3367  continue;
3368 
3369  SCIPdebugMsg(scip, "propagate variable bound <%s> >= %g*<%s> + %g\n", SCIPvarGetName(consdata->x), a, SCIPvarGetName(y), b);
3370 
3371  fb = SIGN( b + consdata->xoffset) * consdata->power( b + consdata->xoffset, consdata->exponent); /* f( b) = sign( b) | b|^n */
3372  fab = SIGN(a+b + consdata->xoffset) * consdata->power(a+b + consdata->xoffset, consdata->exponent); /* f(a+b) = sign(a+b) |a+b|^n */
3373 
3374  vbcoef = (fb - fab) / consdata->zcoef;
3375  vbconst = (consdata->rhs - fb) / consdata->zcoef;
3376 
3377  if( consdata->zcoef > 0.0 )
3378  {
3379  /* add varbound z <= (rhs-f(b))/c + y * (f(b)-f(a+b))/c */
3380  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->z, y, -vbcoef, -SCIPinfinity(scip), vbconst, infeas, nbdchgs, naddconss) );
3381  }
3382  else
3383  {
3384  /* add varbound z >= (rhs-f(b))/c + y * (f(b)-f(a+b))/c */
3385  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->z, y, -vbcoef, vbconst, SCIPinfinity(scip), infeas, nbdchgs, naddconss) );
3386  }
3387  if( *infeas )
3388  return SCIP_OKAY;
3389  }
3390  }
3391 
3392  /* propagate variable upper bounds on z onto x
3393  * c*z <= a*y+b -> x >= f^{-1}(lhs - b) + y * (f^{-1}(lhs - (a+b)) - f^{-1}(lhs - b))
3394  * c*z >= a*y+b -> x <= f^{-1}(rhs - b) + y * (f^{-1}(rhs - (a+b)) - f^{-1}(rhs - b))
3395  */
3396  if( (consdata->zcoef > 0.0 && !SCIPisInfinity(scip, -consdata->lhs)) ||
3397  ( consdata->zcoef < 0.0 && !SCIPisInfinity(scip, consdata->rhs)) )
3398  for( i = 0; i < SCIPvarGetNVubs(consdata->z); ++i )
3399  {
3400  y = SCIPvarGetVubVars(consdata->z)[i];
3401  a = SCIPvarGetVubCoefs(consdata->z)[i] * consdata->zcoef;
3402  b = SCIPvarGetVubConstants(consdata->z)[i] * consdata->zcoef;
3403 
3404  SCIPdebugMsg(scip, "propagate variable bound %g*<%s> %c= %g*<%s> + %g\n", consdata->zcoef, SCIPvarGetName(consdata->z), consdata->zcoef > 0 ? '<' : '>', a, SCIPvarGetName(y), b);
3405 
3406  /* skip variable bound if y is not integer or its valid values are not {0,1}
3407  * @todo extend to arbitrary integer variables
3408  */
3409  if( !SCIPvarIsBinary(y) || SCIPvarGetLbGlobal(y) > 0.5 || SCIPvarGetUbGlobal(y) < 0.5 )
3410  continue;
3411 
3412  if( consdata->zcoef > 0.0 )
3413  {
3414  fb = consdata->lhs - b;
3415  fb = SIGN(fb) * pow(ABS(fb), 1.0/consdata->exponent);
3416  fab = consdata->lhs - (a+b);
3417  fab = SIGN(fab) * pow(ABS(fab), 1.0/consdata->exponent);
3418  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->x, y, fb - fab, fb - consdata->xoffset, SCIPinfinity(scip), infeas, nbdchgs, naddconss) );
3419  }
3420  else
3421  {
3422  fb = consdata->rhs - b;
3423  fb = SIGN(fb) * pow(ABS(fb), 1.0/consdata->exponent);
3424  fab = consdata->rhs - (a+b);
3425  fab = SIGN(fab) * pow(ABS(fab), 1.0/consdata->exponent);
3426  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->x, y, fb - fab, -SCIPinfinity(scip), fb - consdata->xoffset, infeas, nbdchgs, naddconss) );
3427  }
3428  if( *infeas )
3429  return SCIP_OKAY;
3430  }
3431 
3432  /* propagate variable lower bounds on z onto x
3433  * c*z <= a*y+b -> x >= f^{-1}(lhs - b) + y * (f^{-1}(lhs - (a+b)) - f^{-1}(lhs - b))
3434  * c*z >= a*y+b -> x <= f^{-1}(rhs - b) + y * (f^{-1}(rhs - (a+b)) - f^{-1}(rhs - b))
3435  */
3436  if( (consdata->zcoef < 0.0 && !SCIPisInfinity(scip, -consdata->lhs)) ||
3437  ( consdata->zcoef > 0.0 && !SCIPisInfinity(scip, consdata->rhs)) )
3438  for( i = 0; i < SCIPvarGetNVlbs(consdata->z); ++i )
3439  {
3440  y = SCIPvarGetVlbVars(consdata->z)[i];
3441  a = SCIPvarGetVlbCoefs(consdata->z)[i] * consdata->zcoef;
3442  b = SCIPvarGetVlbConstants(consdata->z)[i] * consdata->zcoef;
3443 
3444  SCIPdebugMsg(scip, "propagate variable bound %g*<%s> %c= %g*<%s> + %g\n", consdata->zcoef, SCIPvarGetName(consdata->z), consdata->zcoef > 0 ? '>' : '<', a, SCIPvarGetName(y), b);
3445 
3446  /* skip variable bound if y is not integer or its valid values are not {0,1}
3447  * @todo extend to arbitrary integer variables
3448  */
3449  if( !SCIPvarIsBinary(y) || SCIPvarGetLbGlobal(y) > 0.5 || SCIPvarGetUbGlobal(y) < 0.5 )
3450  continue;
3451 
3452  if( consdata->zcoef > 0.0 )
3453  {
3454  fb = consdata->rhs - b;
3455  fb = SIGN(fb) * pow(ABS(fb), 1.0/consdata->exponent);
3456  fab = consdata->rhs - (a+b);
3457  fab = SIGN(fab) * pow(ABS(fab), 1.0/consdata->exponent);
3458  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->x, y, fb - fab, -SCIPinfinity(scip), fb - consdata->xoffset, infeas, nbdchgs, naddconss) );
3459  }
3460  else
3461  {
3462  fb = consdata->lhs - b;
3463  fb = SIGN(fb) * pow(ABS(fb), 1.0/consdata->exponent);
3464  fab = consdata->lhs - (a+b);
3465  fab = SIGN(fab) * pow(ABS(fab), 1.0/consdata->exponent);
3466  SCIP_CALL( addVarbound(scip, cons, conshdlrdata->addvarboundcons, consdata->x, y, fb - fab, fb - consdata->xoffset, SCIPinfinity(scip), infeas, nbdchgs, naddconss) );
3467  }
3468  if( *infeas )
3469  return SCIP_OKAY;
3470  }
3471 
3472  return SCIP_OKAY;
3473 }
3474 
3475 /** computes linear underestimator for (x+offset)^n + c*z <= rhs by linearization in x
3476  *
3477  * the generated cut is xmul * n * (refpoint+offset)^(n-1) * x + c*z <= rhs + ((n-1)*refpoint-offset) * (refpoint+offset)^(n-1)
3478  */
3479 static
3481  SCIP* scip, /**< SCIP data structure */
3482  SCIP_ROWPREP** rowprep, /**< buffer to store rowprep */
3483  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
3484  SCIP_Real refpoint, /**< base point for linearization */
3485  SCIP_Real exponent, /**< exponent n in sign(x)abs(x)^n */
3486  SCIP_Real xoffset, /**< offset of x */
3487  SCIP_Real xmult, /**< multiplier for coefficient of x */
3488  SCIP_Real zcoef, /**< coefficient of z */
3489  SCIP_Real rhs, /**< right hand side */
3490  SCIP_VAR* x, /**< variable x */
3491  SCIP_VAR* z, /**< variable z */
3492  SCIP_Bool islocal /**< whether the cut is valid only locally */
3493  )
3494 {
3495  SCIP_CONSHDLRDATA* conshdlrdata;
3496  SCIP_Real tmp;
3497 
3498  assert(scip != NULL);
3499  assert(rowprep != NULL);
3500  assert(!SCIPisFeasNegative(scip, refpoint+xoffset));
3501  assert(!SCIPisInfinity(scip, refpoint));
3502 
3503  conshdlrdata = SCIPconshdlrGetData(conshdlr);
3504  assert(conshdlrdata != NULL);
3505 
3506  if( refpoint < -xoffset )
3507  refpoint = -xoffset;
3508 
3509  tmp = exponent == 2.0 ? refpoint+xoffset : pow(refpoint+xoffset, exponent-1);
3510  if( SCIPisInfinity(scip, tmp) )
3511  {
3512  SCIPdebugMsg(scip, "skip linearization cut because (refpoint+offset)^(exponent-1) > infinity\n");
3513  *rowprep = NULL;
3514  return SCIP_OKAY;
3515  }
3516 
3517  rhs += ((exponent-1)*refpoint-xoffset)*tmp; /* now rhs is the rhs of the cut */
3518  /* do not change the right hand side to a value > infinity (this would trigger an assertion in lp.c) */
3519  if( SCIPisInfinity(scip, rhs) )
3520  {
3521  SCIPdebugMsg(scip, "skip linearization cut because its rhs would be > infinity\n");
3522  *rowprep = NULL;
3523  return SCIP_OKAY;
3524  }
3525 
3526  SCIP_CALL( SCIPcreateRowprep(scip, rowprep, SCIP_SIDETYPE_RIGHT, islocal) );
3527  (void) SCIPsnprintf((*rowprep)->name, (int)sizeof((*rowprep)->name), "signpowlinearizecut_%u", ++(conshdlrdata->ncuts));
3528  SCIPaddRowprepSide(*rowprep, rhs);
3529  SCIP_CALL( SCIPaddRowprepTerm(scip, *rowprep, x, xmult*exponent*tmp) );
3530  SCIP_CALL( SCIPaddRowprepTerm(scip, *rowprep, z, zcoef) );
3531 
3532  return SCIP_OKAY;
3533 }
3534 
3535 /** computes linear underestimator for (x+xoffset)^n + c*z <= rhs by linearization in x
3536  *
3537  * the generated cut is xmul * n * (refpoint+offset)^(n-1) * x + c*z <= rhs + ((n-1)*refpoint-offset) * (refpoint+offset)^(n-1)
3538  * where refpoint is computed by projecting (xref, zref) onto the graph of (x+offset)^n w.r.t. euclidean norm
3539  *
3540  * Thus, the projection is computed by minimizing 1/2(x-xref)^2 + 1/2(((x+offset)^n-rhs)/(-c) - zref)^2.
3541  * I.e., we aim to find a root of
3542  * g(x) = x - xref + n/c (x+offset)^(n-1) (zref - rhs/c) + n/c^2 (x+offset)^(2n-1)
3543  * We do this numerically by executing up to five newton iterations. It is
3544  * g'(x) = 1 + n(n-1)/c (x+offset)^(n-2) (zref - rhs/c) + n(2n-1)/c^2 (x+offset)^(2n-2)
3545  */
3546 static
3548  SCIP* scip, /**< SCIP data structure */
3549  SCIP_ROWPREP** rowprep, /**< buffer to store rowprep */
3550  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
3551  SCIP_Real xref, /**< reference point for x */
3552  SCIP_Real zref, /**< reference point for z */
3553  SCIP_Real xmin, /**< minimal value x is allowed to take */
3554  SCIP_Real exponent, /**< exponent n in sign(x+offset)abs(x+offset)^n */
3555  SCIP_Real xoffset, /**< offset of x */
3556  SCIP_Real xmult, /**< multiplier for coefficient of x */
3557  SCIP_Real zcoef, /**< coefficient of z */
3558  SCIP_Real rhs, /**< right hand side */
3559  SCIP_VAR* x, /**< variable x */
3560  SCIP_VAR* z, /**< variable z */
3561  SCIP_Bool islocal /**< whether the cut is valid only locally */
3562  )
3563 {
3564  SCIP_Real tmp;
3565  SCIP_Real xproj;
3566  SCIP_Real gval;
3567  SCIP_Real gderiv;
3568  int iter;
3569 
3570  assert(scip != NULL);
3571  assert(!SCIPisFeasNegative(scip, xref+xoffset));
3572  assert(!SCIPisInfinity(scip, xref));
3573 
3574  if( xref < xmin )
3575  xref = xmin;
3576 
3577  xproj = xref;
3578  iter = 0;
3579  if( exponent == 2.0 )
3580  {
3581  do
3582  {
3583  tmp = (xproj+xoffset) * (xproj+xoffset);
3584  gval = xproj - xref + 2*(xproj+xoffset) / zcoef * ((tmp-rhs)/zcoef + zref);
3585  if( !SCIPisFeasPositive(scip, ABS(gval)) )
3586  break;
3587 
3588  gderiv = 1 + 6 * tmp / (zcoef*zcoef) + 2 / zcoef * (zref - rhs/zcoef);
3589  xproj -= gval / gderiv;
3590  }
3591  while( ++iter <= 5 );
3592  }
3593  else
3594  {
3595  do
3596  {
3597  tmp = pow(xproj + xoffset, exponent-1);
3598  gval = xproj - xref + exponent / zcoef * (pow(xproj+xoffset, 2*exponent-1)/zcoef + tmp * (zref-rhs/zcoef));
3599  if( !SCIPisFeasPositive(scip, ABS(gval)) )
3600  break;
3601 
3602  gderiv = 1 + exponent / zcoef * ( (2*exponent-1)*tmp*tmp/zcoef + (exponent-1)*pow(xproj+xoffset, exponent-2) * (zref-rhs/zcoef) );
3603  xproj -= gval / gderiv;
3604  }
3605  while( ++iter <= 5 );
3606  }
3607 
3608  if( xproj < xmin )
3609  xproj = xmin;
3610 
3611  SCIP_CALL( generateLinearizationCut(scip, rowprep, conshdlr, xproj, exponent, xoffset, xmult, zcoef, rhs, x, z, islocal) );
3612 
3613  return SCIP_OKAY;
3614 }
3615 
3616 /** computes secant underestimator for sign(x+offset)abs(x+offset)^n + c*z <= rhs
3617  *
3618  * the generated cut is slope*xmult*x + c*z <= rhs + (-xlb-offset)^n + slope*xlb,
3619  * where slope = (sign(xub+offset)*abs(xub+offset)^n + (-xlb-offset)^n) / (xub - xlb).
3620  *
3621  * the cut is not generated if the given solution (or the LP solution) would not be cutoff
3622  */
3623 static
3625  SCIP* scip, /**< SCIP data structure */
3626  SCIP_ROWPREP** rowprep, /**< buffer to store rowprep */
3627  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
3628  SCIP_SOL* sol, /**< point we want to cut off, or NULL for LP solution */
3629  SCIP_Real xlb, /**< lower bound of x */
3630  SCIP_Real xub, /**< upper bound of x */
3631  SCIP_Real exponent, /**< exponent n in sign(x+offset)abs(x+offset)^n */
3632  SCIP_Real xoffset, /**< offset of x */
3633  DECL_MYPOW ((*mypow)), /**< function to use for computing power */
3634  SCIP_Real xmult, /**< multiplier for coefficient of x */
3635  SCIP_Real zcoef, /**< coefficient of z */
3636  SCIP_Real rhs, /**< right hand side */
3637  SCIP_VAR* x, /**< variable x */
3638  SCIP_VAR* z /**< variable z */
3639  )
3640 {
3641  SCIP_CONSHDLRDATA* conshdlrdata;
3642  SCIP_Real slope, tmp, val;
3643 
3644  assert(scip != NULL);
3645  assert(SCIPisLE(scip, xlb, xub));
3646  assert(!SCIPisPositive(scip, xlb+xoffset));
3647 
3648  conshdlrdata = SCIPconshdlrGetData(conshdlr);
3649  assert(conshdlrdata != NULL);
3650 
3651  /* ignore constraints with fixed x (should be removed soon) */
3652  if( SCIPisRelEQ(scip, xlb, xub) )
3653  {
3654  SCIPdebugMsg(scip, "skip secant cut because <%s> is fixed [%.20g,%.20g]\n", SCIPvarGetName(x), SCIPvarGetLbLocal(x), SCIPvarGetUbLocal(x));
3655  return SCIP_OKAY;
3656  }
3657 
3658  if( xlb > -xoffset )
3659  xlb = -xoffset;
3660 
3661  tmp = mypow(-xlb-xoffset, exponent);
3662  slope = SIGN(xub+xoffset) * mypow(ABS(xub+xoffset), exponent) + tmp;
3663  slope /= xub - xlb;
3664 
3665  /* check if cut would violated solution, check that slope is not above value of infinity */
3666  val = -tmp + slope * (xmult * SCIPgetSolVal(scip, sol, x) - xlb) + zcoef * SCIPgetSolVal(scip, sol, z) - rhs;
3667  if( !SCIPisFeasPositive(scip, val) || SCIPisInfinity(scip, REALABS(slope)) )
3668  {
3669  *rowprep = NULL;
3670  return SCIP_OKAY;
3671  }
3672 
3673  SCIP_CALL( SCIPcreateRowprep(scip, rowprep, SCIP_SIDETYPE_RIGHT, SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0 /* local */) );
3674  (void) SCIPsnprintf((*rowprep)->name, SCIP_MAXSTRLEN, "signpowsecantcut_%u", ++(conshdlrdata->nsecantcuts));
3675 
3676  SCIP_CALL( SCIPaddRowprepTerm(scip, *rowprep, x, xmult*slope) );
3677  SCIP_CALL( SCIPaddRowprepTerm(scip, *rowprep, z, zcoef) );
3678  SCIPaddRowprepSide(*rowprep, rhs + tmp + slope*xlb);
3679 
3680  return SCIP_OKAY;
3681 }
3682 
3683 /** computes secant underestimator for sign(x+xoffset)abs(x+xoffset)^n + c*z <= rhs
3684  *
3685  * The generated cut is slope*xmult*x + c*z <= rhs + (-xlb-xoffset)^n + slope*xlb,
3686  * where slope = (sign(xub+xoffset)*abs(xub+xoffset)^n + (-xlb-xoffset)^n) / (xub - xlb).
3687  */
3688 static
3690  SCIP* scip, /**< SCIP data structure */
3691  SCIP_ROWPREP** rowprep, /**< buffer to store rowprep */
3692  SCIP_Real xlb, /**< lower bound of x */
3693  SCIP_Real xub, /**< upper bound of x */
3694  SCIP_Real exponent, /**< exponent n in sign(x)abs(x)^n */
3695  SCIP_Real xoffset, /**< offset of x */
3696  DECL_MYPOW ((*mypow)), /**< function to use for computing power */
3697  SCIP_Real xmult, /**< multiplier for coefficient of x */
3698  SCIP_Real zcoef, /**< coefficient of z */
3699  SCIP_Real rhs, /**< right hand side */
3700  SCIP_VAR* x, /**< variable x */
3701  SCIP_VAR* z /**< variable z */
3702  )
3703 {
3704  SCIP_Real slope, tmp;
3705 
3706  assert(scip != NULL);
3707  assert(rowprep != NULL);
3708  assert(SCIPisLE(scip, xlb, xub));
3709  assert(!SCIPisPositive(scip, xlb + xoffset));
3710 
3711  /* ignore constraints with fixed x (should be removed soon) */
3712  if( SCIPisRelEQ(scip, xlb, xub) )
3713  return SCIP_OKAY;
3714 
3715  if( xlb > -xoffset )
3716  xlb = -xoffset;
3717 
3718  tmp = mypow(-xlb-xoffset, exponent);
3719  slope = SIGN(xub+xoffset) * mypow(ABS(xub+xoffset), exponent) + tmp;
3720  slope /= xub - xlb;
3721 
3722  if( SCIPisInfinity(scip, REALABS(slope)) )
3723  return SCIP_OKAY;
3724 
3725  SCIP_CALL( SCIPcreateRowprep(scip, rowprep, SCIP_SIDETYPE_RIGHT, SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0 /* local */) );
3726  (void)SCIPmemccpy((*rowprep)->name, "signpowcut", '\0', 11);
3727  SCIP_CALL( SCIPaddRowprepTerm(scip, *rowprep, x, xmult*slope) );
3728  SCIP_CALL( SCIPaddRowprepTerm(scip, *rowprep, z, zcoef) );
3729  SCIPaddRowprepSide(*rowprep, rhs + tmp + slope*xlb);
3730 
3731  return SCIP_OKAY;
3732 }
3733 
3734 /** generates a cut
3735  * based on Liberti and Pantelides, Convex Envelopes of Monomials of Odd Degree, J. Global Optimization 25, 157-168, 2003, and previous publications
3736  */
3737 static
3739  SCIP* scip, /**< SCIP data structure */
3740  SCIP_CONS* cons, /**< constraint */
3741  SCIP_SIDETYPE violside, /**< side to separate */
3742  SCIP_SOL* sol, /**< solution to separate, or NULL if LP solution should be used */
3743  SCIP_ROW** row, /**< storage for cut */
3744  SCIP_Bool onlyinbounds, /**< whether linearization is allowed only in variable bounds */
3745  SCIP_Real minviol /**< a minimal violation in sol we hope to achieve */
3746  )
3747 {
3748  SCIP_CONSHDLRDATA* conshdlrdata;
3749  SCIP_CONSDATA* consdata;
3750  SCIP_ROWPREP* rowprep = NULL;
3751  SCIP_Real c;
3752  SCIP_Real xlb;
3753  SCIP_Real xglb;
3754  SCIP_Real xub;
3755  SCIP_Real xval;
3756  SCIP_Real xoffset;
3757  SCIP_Real xmult;
3758  SCIP_Real zcoef;
3759  SCIP_Real rhs;
3760 
3761  assert(scip != NULL);
3762  assert(cons != NULL);
3763  assert(row != NULL);
3764 
3765  conshdlrdata = SCIPconshdlrGetData(SCIPconsGetHdlr(cons));
3766  assert(conshdlrdata != NULL);
3767 
3768  consdata = SCIPconsGetData(cons);
3769  assert(consdata != NULL);
3770 
3771  assert(SCIPisGT(scip, violside == SCIP_SIDETYPE_LEFT ? consdata->lhsviol : consdata->rhsviol, SCIPfeastol(scip)));
3772 
3773  *row = NULL;
3774 
3775  SCIPdebugMsg(scip, "generate cut for constraint <%s> with violated side %d\n", SCIPconsGetName(cons), violside);
3776  SCIPdebugPrintCons(scip, cons, NULL);
3777  SCIPdebugMsg(scip, "xlb = %g xub = %g xval = %g zval = %.15g\n", SCIPvarGetLbLocal(consdata->x), SCIPvarGetUbLocal(consdata->x), SCIPgetSolVal(scip, sol, consdata->x), SCIPgetSolVal(scip, sol, consdata->z));
3778 
3779  if( violside == SCIP_SIDETYPE_RIGHT )
3780  {
3781  xglb = SCIPvarGetLbGlobal(consdata->x);
3782  xlb = SCIPvarGetLbLocal(consdata->x);
3783  xub = SCIPvarGetUbLocal(consdata->x);
3784  xval = SCIPgetSolVal(scip, sol, consdata->x);
3785  xoffset = consdata->xoffset;
3786  xmult = 1.0;
3787  zcoef = consdata->zcoef;
3788  rhs = consdata->rhs;
3789  }
3790  else
3791  {
3792  xglb = -SCIPvarGetUbGlobal(consdata->x);
3793  xlb = -SCIPvarGetUbLocal(consdata->x);
3794  xub = -SCIPvarGetLbLocal(consdata->x);
3795  xval = -SCIPgetSolVal(scip, sol, consdata->x);
3796  xoffset = -consdata->xoffset;
3797  xmult = -1.0;
3798  zcoef = -consdata->zcoef;
3799  rhs = -consdata->lhs;
3800  }
3801  /* move reference point onto local domain, if clearly (>eps) outside */
3802  if( SCIPisLT(scip, xval, xlb) )
3803  xval = xlb;
3804  else if( SCIPisGT(scip, xval, xub) )
3805  xval = xub;
3806 
3807  if( SCIPisInfinity(scip, REALABS(xval)) )
3808  {
3809  SCIPdebugMsg(scip, "skip separation since x is at infinity\n");
3810  return SCIP_OKAY;
3811  }
3812 
3813  if( !SCIPisNegative(scip, xlb+xoffset) )
3814  {
3815  /* [xlb, xub] completely in positive orthant -> function is convex on whole domain */
3816  SCIP_Bool islocal;
3817 
3818  islocal = (!SCIPconsIsGlobal(cons) || SCIPisNegative(scip, xglb+xoffset)) && SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0;
3819  if( conshdlrdata->projectrefpoint && !onlyinbounds )
3820  {
3821  SCIP_CALL( generateLinearizationCutProject(scip, &rowprep, SCIPconsGetHdlr(cons), xval, SCIPgetSolVal(scip, sol, consdata->z), -xoffset, consdata->exponent,
3822  xoffset, xmult, zcoef, rhs, consdata->x, consdata->z, islocal) );
3823  }
3824  else if( !onlyinbounds )
3825  {
3826  SCIP_CALL( generateLinearizationCut(scip, &rowprep, SCIPconsGetHdlr(cons), xval, consdata->exponent, xoffset, xmult, zcoef, rhs,
3827  consdata->x, consdata->z, islocal) );
3828  }
3829  else
3830  {
3831  SCIP_CALL( generateLinearizationCut(scip, &rowprep, SCIPconsGetHdlr(cons), 2.0*xval > xlb + xub ? xub : xlb, consdata->exponent, xoffset, xmult, zcoef, rhs,
3832  consdata->x, consdata->z, islocal) );
3833  }
3834  }
3835  else if( !SCIPisPositive(scip, xub+xoffset) )
3836  {
3837  /* [xlb, xub] completely in negative orthant -> function is concave on whole domain */
3838  if( SCIPisInfinity(scip, -xlb) )
3839  return SCIP_OKAY;
3840  SCIP_CALL( generateSecantCut(scip, &rowprep, SCIPconsGetHdlr(cons), sol, xlb, xub, consdata->exponent, xoffset, consdata->power, xmult, zcoef, rhs, consdata->x, consdata->z) );
3841  }
3842  else if( (c = - consdata->root * (xlb+xoffset) - xoffset) > xub )
3843  {
3844  /* c is right of xub -> use secant */
3845  if( SCIPisInfinity(scip, -xlb) || SCIPisInfinity(scip, xub) )
3846  return SCIP_OKAY;
3847  SCIP_CALL( generateSecantCut(scip, &rowprep, SCIPconsGetHdlr(cons), sol, xlb, xub, consdata->exponent, xoffset, consdata->power, xmult, zcoef, rhs, consdata->x, consdata->z) );
3848  }
3849  else if( xval >= c )
3850  {
3851  /* xval is right of c -> use linearization */
3852  if( conshdlrdata->projectrefpoint && !onlyinbounds )
3853  SCIP_CALL( generateLinearizationCutProject(scip, &rowprep, SCIPconsGetHdlr(cons), xval, SCIPgetSolVal(scip, sol, consdata->z), c, consdata->exponent,
3854  xoffset, xmult, zcoef, rhs, consdata->x, consdata->z, SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0) );
3855  else if( !onlyinbounds )
3856  SCIP_CALL( generateLinearizationCut(scip, &rowprep, SCIPconsGetHdlr(cons), xval, consdata->exponent, xoffset, xmult, zcoef, rhs,
3857  consdata->x, consdata->z, xval+xoffset < - consdata->root * (xglb+xoffset) && SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0) );
3858  else
3859  SCIP_CALL( generateLinearizationCut(scip, &rowprep, SCIPconsGetHdlr(cons), xub, consdata->exponent, xoffset, xmult, zcoef, rhs,
3860  consdata->x, consdata->z, xub+xoffset < - consdata->root * (xglb+xoffset) && SCIPnodeGetDepth(SCIPgetCurrentNode(scip)) > 0) );
3861  }
3862  else
3863  {
3864  /* xval between xlb and c -> use secant */
3865  if( SCIPisInfinity(scip, -xlb) || SCIPisInfinity(scip, c) )
3866  return SCIP_OKAY;
3867  SCIP_CALL( generateSecantCut(scip, &rowprep, SCIPconsGetHdlr(cons), sol, xlb, c, consdata->exponent, xoffset, consdata->power, xmult, zcoef, rhs, consdata->x, consdata->z) );
3868  }
3869 
3870  /* check and improve numerics */
3871  if( rowprep != NULL )
3872  {
3873  SCIP_Real coefrange;
3874 
3875  SCIPdebug( SCIPprintRowprep(scip, rowprep, NULL) );
3876 
3877  /* we should not need SCIPmergeRowprep() with only 2 vars in the row */
3878  assert(rowprep->nvars <= 2);
3879 
3880  SCIP_CALL( SCIPcleanupRowprep(scip, rowprep, sol, conshdlrdata->cutmaxrange, minviol, &coefrange, NULL) );
3881 
3882  if( coefrange >= conshdlrdata->cutmaxrange )
3883  {
3884  SCIPdebugMsg(scip, "skip cut for constraint <%s> because of very large range: %g\n", SCIPconsGetName(cons), coefrange);
3885  }
3886  else if( SCIPisInfinity(scip, REALABS(rowprep->side)) )
3887  {
3888  SCIPdebugMsg(scip, "skip cut for constraint <%s> because of very large side: %g\n", SCIPconsGetName(cons), rowprep->side);
3889  }
3890  else if( rowprep->nvars > 0 && SCIPisInfinity(scip, REALABS(rowprep->coefs[0])) )
3891  {
3892  SCIPdebugMsg(scip, "skip cut for constraint <%s> because of very large coef: %g\n", SCIPconsGetName(cons), rowprep->coefs[0]);
3893  }
3894  else
3895  {
3896  SCIP_CALL( SCIPgetRowprepRowCons(scip, row, rowprep, SCIPconsGetHdlr(cons)) );
3897  }
3898 
3899  SCIPfreeRowprep(scip, &rowprep);
3900  }
3901 
3902  return SCIP_OKAY;
3903 }
3904 
3905 /** tries to separate solution or LP solution by a linear cut
3906  * assumes that constraint violations have been computed
3907  */
3908 static
3910  SCIP* scip, /**< SCIP data structure */
3911  SCIP_CONSHDLR* conshdlr, /**< quadratic constraints handler */
3912  SCIP_CONS** conss, /**< constraints */
3913  int nconss, /**< number of constraints */
3914  int nusefulconss, /**< number of constraints that seem to be useful */
3915  SCIP_SOL* sol, /**< solution to separate, or NULL if LP solution should be used */
3916  SCIP_Real minefficacy, /**< minimal efficacy of a cut if it should be added to the LP */
3917  SCIP_Bool inenforcement, /**< whether we are in constraint enforcement */
3918  SCIP_Bool onlyinbounds, /**< whether linearization is allowed only in variable bounds */
3919  SCIP_Bool* success, /**< result of separation: separated point (TRUE) or not (FALSE) */
3920  SCIP_Bool* cutoff, /**< whether a cutoff has been detected */
3921  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 */
3922  )
3923 {
3924  SCIP_CONSHDLRDATA* conshdlrdata;
3925  SCIP_CONSDATA* consdata;
3926  SCIP_SIDETYPE side;
3927  SCIP_Real efficacy;
3928  int c;
3929  SCIP_ROW* row;
3930 
3931  assert(scip != NULL);
3932  assert(conshdlr != NULL);
3933  assert(conss != NULL || nconss == 0);
3934  assert(success != NULL);
3935  assert(cutoff != NULL);
3936 
3937  *success = FALSE;
3938  *cutoff = FALSE;
3939 
3940  conshdlrdata = SCIPconshdlrGetData(conshdlr);
3941  assert(conshdlrdata != NULL);
3942 
3943  if( bestefficacy != NULL )
3944  *bestefficacy = 0.0;
3945 
3946  for( c = 0, side = SCIP_SIDETYPE_LEFT; c < nconss && ! (*cutoff); c = (side == SCIP_SIDETYPE_RIGHT ? c+1 : c), side = (side == SCIP_SIDETYPE_LEFT ? SCIP_SIDETYPE_RIGHT : SCIP_SIDETYPE_LEFT) )
3947  {
3948  assert(conss[c] != NULL); /*lint !e613*/
3949 
3950  /* skip constraints that are not enabled, e.g., because they were already marked for deletion at this node */
3951  if( !SCIPconsIsEnabled(conss[c]) ) /*lint !e613*/
3952  continue;
3953 
3954  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
3955  assert(consdata != NULL);
3956 
3957  if( SCIPisGT(scip, side == SCIP_SIDETYPE_LEFT ? consdata->lhsviol : consdata->rhsviol, SCIPfeastol(scip)) )
3958  {
3959  /* try to generate a cut */
3960  SCIP_CALL( generateCut(scip, conss[c], side, sol, &row, onlyinbounds, minefficacy) ); /*lint !e613*/
3961  if( row == NULL ) /* failed to generate cut */
3962  continue;
3963 
3964  /* if cut is violated sufficiently, then add,
3965  * unless it corresponds to a bound change that is too weak (<eps) to be added
3966  */
3967  efficacy = -SCIPgetRowSolFeasibility(scip, row, sol);
3968  if( SCIPisGT(scip, efficacy, minefficacy) && SCIPisCutApplicable(scip, row) )
3969  {
3970  SCIP_Bool infeasible;
3971 
3972  SCIP_CALL( SCIPaddRow(scip, row, FALSE, &infeasible) );
3973  if ( infeasible )
3974  *cutoff = TRUE;
3975  else
3976  *success = TRUE;
3977  if( bestefficacy != NULL && efficacy > *bestefficacy )
3978  *bestefficacy = efficacy;
3979 
3980  /* notify indicator constraint handler about this cut */
3981  if( conshdlrdata->conshdlrindicator != NULL && !SCIProwIsLocal(row) )
3982  {
3983  SCIP_CALL( SCIPaddRowIndicator(scip, conshdlrdata->conshdlrindicator, row) );
3984  }
3985 
3986  /* mark row as not removable from LP for current node, if in enforcement */
3987  if( inenforcement && !conshdlrdata->enfocutsremovable )
3988  SCIPmarkRowNotRemovableLocal(scip, row);
3989  }
3990 
3991  SCIP_CALL( SCIPreleaseRow (scip, &row) );
3992  }
3993 
3994  /* enforce only useful constraints
3995  * others are only checked and enforced if we are still feasible or have not found a separating cut yet
3996  */
3997  if( c >= nusefulconss && *success )
3998  break;
3999  }
4000 
4001  return SCIP_OKAY;
4002 }
4003 
4004 /** adds linearizations cuts for convex constraints w.r.t. a given reference point to cutpool and sepastore
4005  * 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
4006  * if separatedlpsol is not NULL, but cut does not separate the LP solution, then it is added to the cutpool only
4007  * if separatedlpsol is NULL, then cut is added to cutpool only
4008  */
4009 static
4011  SCIP* scip, /**< SCIP data structure */
4012  SCIP_CONSHDLR* conshdlr, /**< quadratic constraints handler */
4013  SCIP_CONS** conss, /**< constraints */
4014  int nconss, /**< number of constraints */
4015  SCIP_SOL* ref, /**< reference point where to linearize, or NULL for LP solution */
4016  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 */
4017  SCIP_Real minefficacy /**< minimal efficacy of a cut when checking for separation of LP solution */
4018  )
4019 {
4020  SCIP_CONSDATA* consdata;
4021  SCIP_Bool addedtolp;
4022  SCIP_ROW* row;
4023  int c;
4024 
4025  assert(scip != NULL);
4026  assert(conshdlr != NULL);
4027  assert(conss != NULL || nconss == 0);
4028 
4029  if( separatedlpsol != NULL )
4030  *separatedlpsol = FALSE;
4031 
4032  for( c = 0; c < nconss; ++c )
4033  {
4034  assert(conss[c] != NULL); /*lint !e613*/
4035 
4036  if( SCIPconsIsLocal(conss[c]) ) /*lint !e613*/
4037  continue;
4038 
4039  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
4040  assert(consdata != NULL);
4041 
4042  if( !SCIPisGT(scip, SCIPvarGetUbGlobal(consdata->x), -consdata->xoffset) && !SCIPisInfinity(scip, -consdata->lhs) )
4043  {
4044  /* constraint function is concave for x+offset <= 0.0, so can linearize w.r.t. lhs */
4045  consdata->lhsviol = 1.0;
4046  consdata->rhsviol = 0.0;
4047  SCIP_CALL( generateCut(scip, conss[c], SCIP_SIDETYPE_LEFT, ref, &row, FALSE, minefficacy) ); /*lint !e613*/
4048  }
4049  else if( !SCIPisLT(scip, SCIPvarGetLbGlobal(consdata->x), -consdata->xoffset) && !SCIPisInfinity(scip, -consdata->rhs) )
4050  {
4051  /* constraint function is convex for x+offset >= 0.0, so can linearize w.r.t. rhs */
4052  consdata->lhsviol = 0.0;
4053  consdata->rhsviol = 1.0;
4054  SCIP_CALL( generateCut(scip, conss[c], SCIP_SIDETYPE_RIGHT, ref, &row, FALSE, minefficacy) ); /*lint !e613*/
4055  }
4056  else
4057  {
4058  /* sign not fixed or nothing to linearize */
4059  continue;
4060  }
4061 
4062  if( row == NULL )
4063  continue;
4064 
4065  addedtolp = FALSE;
4066 
4067  /* if caller wants, then check if cut separates LP solution and add to sepastore if so */
4068  if( separatedlpsol != NULL )
4069  {
4070  if( -SCIPgetRowLPFeasibility(scip, row) >= minefficacy )
4071  {
4072  SCIP_Bool infeasible;
4073 
4074  *separatedlpsol = TRUE;
4075  addedtolp = TRUE;
4076  SCIP_CALL( SCIPaddRow(scip, row, TRUE, &infeasible) );
4077  assert( ! infeasible );
4078  }
4079  }
4080 
4081  if( !addedtolp && !SCIProwIsLocal(row) )
4082  {
4083  SCIP_CALL( SCIPaddPoolCut(scip, row) );
4084  }
4085 
4086  SCIP_CALL( SCIPreleaseRow(scip, &row) );
4087  }
4088 
4089  return SCIP_OKAY;
4090 }
4091 
4092 /** processes the event that a new primal solution has been found */
4093 static
4094 SCIP_DECL_EVENTEXEC(processNewSolutionEvent)
4096  SCIP_CONSHDLRDATA* conshdlrdata;
4097  SCIP_CONSHDLR* conshdlr;
4098  SCIP_CONS** conss;
4099  int nconss;
4100  SCIP_SOL* sol;
4101 
4102  assert(scip != NULL);
4103  assert(event != NULL);
4104  assert(eventdata != NULL);
4105  assert(eventhdlr != NULL);
4106 
4107  assert((SCIPeventGetType(event) & SCIP_EVENTTYPE_SOLFOUND) != 0);
4108 
4109  conshdlr = (SCIP_CONSHDLR*)eventdata;
4110 
4111  nconss = SCIPconshdlrGetNConss(conshdlr);
4112 
4113  if( nconss == 0 )
4114  return SCIP_OKAY;
4115 
4116  sol = SCIPeventGetSol(event);
4117  assert(sol != NULL);
4118 
4119  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4120  assert(conshdlrdata != NULL);
4121 
4122  /* we are only interested in solution coming from some heuristic other than trysol, but not from the tree
4123  * the reason for ignoring trysol solutions is that they may come from an NLP solve in sepalp, where we already added linearizations,
4124  * or are from the tree, but postprocessed via proposeFeasibleSolution
4125  */
4126  if( SCIPsolGetHeur(sol) == NULL || SCIPsolGetHeur(sol) == conshdlrdata->trysolheur )
4127  return SCIP_OKAY;
4128 
4129  conss = SCIPconshdlrGetConss(conshdlr);
4130  assert(conss != NULL);
4131 
4132  SCIPdebugMsg(scip, "catched new sol event %" SCIP_EVENTTYPE_FORMAT " from heur <%s>; have %d conss\n", SCIPeventGetType(event), SCIPheurGetName(SCIPsolGetHeur(sol)), nconss);
4133 
4134  SCIP_CALL( addLinearizationCuts(scip, conshdlr, conss, nconss, sol, NULL, 0.0) );
4135 
4136  return SCIP_OKAY;
4137 }
4138 
4139 /** given a solution, try to make absolute power constraints feasible by shifting the linear variable z and pass this solution to the trysol heuristic */
4140 static
4142  SCIP* scip, /**< SCIP data structure */
4143  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
4144  SCIP_CONS** conss, /**< constraints to process */
4145  int nconss, /**< number of constraints */
4146  SCIP_SOL* sol /**< solution to process */
4147  )
4148 {
4149  SCIP_CONSDATA* consdata;
4150  SCIP_SOL* newsol;
4151  SCIP_Real xtermval;
4152  SCIP_Real zval;
4153  SCIP_Real viol;
4154  SCIP_Bool solviolbounds;
4155  int c;
4156 
4157  assert(scip != NULL);
4158  assert(conshdlr != NULL);
4159  assert(conss != NULL || nconss == 0);
4160 
4161  /* don't propose new solutions if not in presolve or solving */
4163  return SCIP_OKAY;
4164 
4165  if( sol != NULL )
4166  {
4167  SCIP_CALL( SCIPcreateSolCopy(scip, &newsol, sol) );
4168  }
4169  else
4170  {
4171  SCIP_CALL( SCIPcreateLPSol(scip, &newsol, NULL) );
4172  }
4173  SCIP_CALL( SCIPunlinkSol(scip, newsol) );
4174 
4175  for( c = 0; c < nconss; ++c )
4176  {
4177  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
4178  assert(consdata != NULL);
4179  assert(consdata->z != NULL);
4180  assert(consdata->zcoef != 0.0);
4181 
4182  /* recompute violation w.r.t. current solution */
4183  SCIP_CALL( computeViolation(scip, conshdlr, conss[c], newsol, &viol, &solviolbounds) ); /*lint !e613*/
4184  assert(!solviolbounds);
4185 
4186  /* do nothing if constraint is satisfied */
4187  if( !SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) && !SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
4188  continue;
4189 
4190  /* if violation is at infinity, give up */
4191  if( SCIPisInfinity(scip, MAX(consdata->lhsviol, consdata->rhsviol)) )
4192  break;
4193 
4194  /* @todo could also adjust x while keeping z fixed */
4195 
4196  /* if variable is multiaggregated, then cannot set its solution value, so give up */
4197  if( SCIPvarGetStatus(consdata->z) == SCIP_VARSTATUS_MULTAGGR )
4198  break;
4199 
4200  /* compute value of x-term */
4201  xtermval = SCIPgetSolVal(scip, newsol, consdata->x);
4202  xtermval += consdata->xoffset;
4203  xtermval = SIGN(xtermval) * consdata->power(ABS(xtermval), consdata->exponent);
4204 
4205  /* if left hand side is violated, try to set z such that lhs is active */
4206  if( SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) )
4207  {
4208  assert(!SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip))); /* should only have one side violated (otherwise some variable is at infinity) */
4209 
4210  zval = (consdata->lhs - xtermval)/consdata->zcoef;
4211  /* bad luck: z would get value outside of its domain */
4212  if( SCIPisInfinity(scip, REALABS(zval)) || SCIPisFeasLT(scip, zval, SCIPvarGetLbGlobal(consdata->z)) || SCIPisFeasGT(scip, zval, SCIPvarGetUbGlobal(consdata->z)) )
4213  break;
4214  SCIP_CALL( SCIPsetSolVal(scip, newsol, consdata->z, zval) );
4215  }
4216 
4217  /* if right hand side is violated, try to set z such that rhs is active */
4218  if( SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
4219  {
4220  zval = (consdata->rhs - xtermval)/consdata->zcoef;
4221  /* bad luck: z would get value outside of its domain */
4222  if( SCIPisInfinity(scip, REALABS(zval)) || SCIPisFeasLT(scip, zval, SCIPvarGetLbGlobal(consdata->z)) || SCIPisFeasGT(scip, zval, SCIPvarGetUbGlobal(consdata->z)) )
4223  break;
4224  SCIP_CALL( SCIPsetSolVal(scip, newsol, consdata->z, zval) );
4225  }
4226  }
4227 
4228  /* 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 */
4229  if( c == nconss )
4230  {
4231  SCIP_CONSHDLRDATA* conshdlrdata;
4232 
4233  SCIPdebugMsg(scip, "pass solution with objective val %g to trysol heuristic\n", SCIPgetSolTransObj(scip, newsol));
4234 
4235  conshdlrdata = SCIPconshdlrGetData(conshdlr);
4236  assert(conshdlrdata != NULL);
4237  assert(conshdlrdata->trysolheur != NULL);
4238 
4239  SCIP_CALL( SCIPheurPassSolTrySol(scip, conshdlrdata->trysolheur, newsol) );
4240  }
4241 
4242  SCIP_CALL( SCIPfreeSol(scip, &newsol) );
4243 
4244  return SCIP_OKAY;
4245 }
4246 
4247 /** create a nonlinear row representation of the constraint and stores them in consdata */
4248 static
4250  SCIP* scip, /**< SCIP data structure */
4251  SCIP_CONS* cons /**< absolute power constraint */
4252  )
4253 {
4254  SCIP_CONSDATA* consdata;
4255  SCIP_EXPRTREE* exprtree;
4256  SCIP_QUADELEM quadelem;
4257  SCIP_VAR* linvars[2];
4258  SCIP_Real lincoefs[2];
4259  SCIP_VAR* quadvar;
4260  SCIP_Real constant;
4261  SCIP_Bool expisint;
4262  int sign;
4263  int nlinvars;
4264  int nquadvars;
4265  int nquadelems;
4266  int n;
4267 
4268  assert(scip != NULL);
4269  assert(cons != NULL);
4270 
4271  consdata = SCIPconsGetData(cons);
4272  assert(consdata != NULL);
4273 
4274  if( consdata->nlrow != NULL )
4275  {
4276  SCIP_CALL( SCIPreleaseNlRow(scip, &consdata->nlrow) );
4277  }
4278 
4279  nlinvars = 0;
4280  nquadvars = 0;
4281  nquadelems = 0;
4282  exprtree = NULL;
4283  constant = 0.0;
4284 
4285  /* check if sign of x is fixed */
4286  if( !SCIPisNegative(scip, SCIPvarGetLbGlobal(consdata->x)+consdata->xoffset) )
4287  sign = 1;
4288  else if( !SCIPisPositive(scip, SCIPvarGetUbGlobal(consdata->x)+consdata->xoffset) )
4289  sign = -1;
4290  else
4291  sign = 0;
4292 
4293  /* check if exponent is integral */
4294  expisint = SCIPisIntegral(scip, consdata->exponent);
4295  n = (int)SCIPround(scip, consdata->exponent);
4296 
4297  /* create quadelem or expression tree for nonlinear part sign(x+offset)abs(x+offset)^n */
4298  if( sign != 0 || (expisint && (n % 2 == 1)) )
4299  {
4300  /* sign is fixes or exponent is odd integer */
4301  if( expisint && n == 2 )
4302  {
4303  /* sign of x is clear and exponent is 2.0 -> generate quadratic, linear, and constant term for +/- (x+offset)^n */
4304  assert(sign == -1 || sign == 1);
4305  nquadelems = 1;
4306  quadelem.idx1 = 0;
4307  quadelem.idx2 = 0;
4308  quadelem.coef = (SCIP_Real)sign;
4309  nquadvars = 1;
4310  quadvar = consdata->x;
4311 
4312  if( consdata->xoffset != 0.0 )
4313  {
4314  linvars[0] = consdata->x;
4315  lincoefs[0] = sign * 2.0 * consdata->xoffset;
4316  nlinvars = 1;
4317  constant = sign * consdata->xoffset * consdata->xoffset;
4318  }
4319  }
4320  else
4321  {
4322  /* exponent is odd or sign of x is clear, generate expression tree for +/- (+/-(x+offset))^exponent */
4323  SCIP_EXPR* expr;
4324  SCIP_EXPR* expr2;
4325 
4326  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_VARIDX, 0) ); /* x */
4327  if( consdata->xoffset != 0.0 )
4328  {
4329  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr2, SCIP_EXPR_CONST, consdata->xoffset) );
4330  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_PLUS, expr, expr2) ); /* x + offset */
4331  }
4332  if( sign == -1 && !expisint )
4333  {
4334  /* if exponent is not integer and x is negative, then negate */
4335  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr2, SCIP_EXPR_CONST, -1.0) ); /* -1 */
4336  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_MUL, expr, expr2) ); /* -(x+offset) */
4337  }
4338  /* use intpower for integer exponent and realpower for fractional exponent */
4339  if( expisint )
4340  {
4341  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_INTPOWER, expr, n) ); /* (x+offset)^n */
4342  }
4343  else
4344  {
4345  assert(sign == 1 || sign == -1);
4346  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_REALPOWER, expr, consdata->exponent) ); /* abs(x+offset)^exponent */
4347  }
4348  /* if exponent is even integer, then negate result; if it's an odd integer, then intpower already takes care of correct sign */
4349  if( sign == -1 && !(expisint && n % 2 == 1) )
4350  {
4351  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr2, SCIP_EXPR_CONST, -1.0) ); /* -1 */
4352  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_MUL, expr, expr2) ); /* -abs(x+offset)^exponent */
4353  }
4354  SCIP_CALL( SCIPexprtreeCreate(SCIPblkmem(scip), &exprtree, expr, 1, 0, NULL) );
4355  }
4356  }
4357  else
4358  {
4359  /* exponent is not odd integer and sign of x is not fixed -> generate expression tree for signpower(x+offset, n) */
4360  SCIP_EXPR* expr;
4361  SCIP_EXPR* expr2;
4362 
4363  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_VARIDX, 0) ); /* x */
4364  if( consdata->xoffset != 0.0 )
4365  {
4366  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr2, SCIP_EXPR_CONST, consdata->xoffset) );
4367  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_PLUS, expr, expr2) ); /* x + offset */
4368  }
4369  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_SIGNPOWER, expr, (SCIP_Real)consdata->exponent) ); /* signpower(x+offset, n) */
4370 
4371  SCIP_CALL( SCIPexprtreeCreate(SCIPblkmem(scip), &exprtree, expr, 1, 0, NULL) );
4372  }
4373  assert(exprtree != NULL || nquadelems > 0);
4374 
4375  /* tell expression tree, which is its variable */
4376  if( exprtree != NULL )
4377  {
4378  SCIP_CALL( SCIPexprtreeSetVars(exprtree, 1, &consdata->x) );
4379  }
4380 
4381  assert(nlinvars < 2);
4382  linvars[nlinvars] = consdata->z;
4383  lincoefs[nlinvars] = consdata->zcoef;
4384  ++nlinvars;
4385 
4386  /* create nlrow */
4387  SCIP_CALL( SCIPcreateNlRow(scip, &consdata->nlrow, SCIPconsGetName(cons), constant,
4388  nlinvars, linvars, lincoefs,
4389  nquadvars, &quadvar, nquadelems, &quadelem,
4390  exprtree, consdata->lhs, consdata->rhs,
4392  ) );
4393 
4394  if( exprtree != NULL )
4395  {
4396  SCIP_CALL( SCIPexprtreeFree(&exprtree) );
4397  }
4398 
4399  return SCIP_OKAY;
4400 }
4401 
4402 /** 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 */
4403 static
4404 SCIP_DECL_QUADCONSUPGD(quadconsUpgdAbspower)
4405 { /*lint --e{715}*/
4406  SCIP_QUADVARTERM quadvarterm;
4407  SCIP_VAR* x;
4408  SCIP_VAR* z;
4409  SCIP_Real xoffset;
4410  SCIP_Real zcoef;
4411  SCIP_Real signpowcoef;
4412  SCIP_Real lhs;
4413  SCIP_Real rhs;
4414 
4415  *nupgdconss = 0;
4416 
4417  /* need at least one linear variable */
4418  if( SCIPgetNLinearVarsQuadratic(scip, cons) == 0 )
4419  return SCIP_OKAY;
4420 
4421  /* consider only quadratic constraints with a single square term */
4422  if( SCIPgetNQuadVarTermsQuadratic(scip, cons) != 1 )
4423  return SCIP_OKAY;
4424  assert(SCIPgetNBilinTermsQuadratic(scip, cons) == 0);
4425 
4426  quadvarterm = SCIPgetQuadVarTermsQuadratic(scip, cons)[0];
4427  if( SCIPisZero(scip, quadvarterm.sqrcoef) )
4428  return SCIP_OKAY;
4429 
4430  /* don't upgrade if upgrade would scale the constraint down (divide by |sqrcoef|)
4431  * @todo we could still allow this if we were keeping the scaling factor around for the feasibility check
4432  */
4433  if( REALABS(quadvarterm.sqrcoef) > 1.0 )
4434  return SCIP_OKAY;
4435 
4436  x = quadvarterm.var;
4437  xoffset = quadvarterm.lincoef / (2.0 * quadvarterm.sqrcoef);
4438 
4439  /* check that x has fixed sign */
4440  if( SCIPisNegative(scip, SCIPvarGetLbGlobal(x) + xoffset) && SCIPisPositive(scip, SCIPvarGetUbGlobal(x) + xoffset) )
4441  return SCIP_OKAY;
4442 
4443  /* check whether upgdconss array has enough space to store 1 or 2 constraints */
4444  if( SCIPgetNLinearVarsQuadratic(scip, cons) > 1 )
4445  *nupgdconss = -2;
4446  else
4447  *nupgdconss = -1;
4448  if( -*nupgdconss > upgdconsssize )
4449  return SCIP_OKAY;
4450 
4451  *nupgdconss = 0;
4452 
4453  SCIPdebugMsg(scip, "upgrade quadratic constraint <%s> to absolute power, x = [%g,%g], offset = %g\n", SCIPconsGetName(cons), SCIPvarGetLbGlobal(x), SCIPvarGetUbGlobal(x), xoffset);
4454  SCIPdebugPrintCons(scip, cons, NULL);
4455 
4456  lhs = SCIPgetLhsQuadratic(scip, cons);
4457  rhs = SCIPgetRhsQuadratic(scip, cons);
4458 
4459  /* get z and its coefficient */
4460  if( SCIPgetNLinearVarsQuadratic(scip, cons) > 1 )
4461  {
4462  /* create auxiliary variable and constraint for linear part, since we can handle only at most one variable in cons_signpower */
4463  char name[SCIP_MAXSTRLEN];
4464  SCIP_VAR* auxvar;
4465 
4466  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_linpart", SCIPconsGetName(cons));
4467  SCIP_CALL( SCIPcreateVar(scip, &auxvar, name, -SCIPinfinity(scip), SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS,
4469  SCIP_CALL( SCIPaddVar(scip, auxvar) );
4470 
4471  SCIP_CALL( SCIPcreateConsLinear(scip, &upgdconss[0], name, SCIPgetNLinearVarsQuadratic(scip, cons),
4473  SCIPisInfinity(scip, -lhs) ? -SCIPinfinity(scip) : 0.0,
4474  SCIPisInfinity(scip, rhs) ? SCIPinfinity(scip) : 0.0,
4478  SCIPconsIsStickingAtNode(cons)) );
4479  SCIP_CALL( SCIPaddCoefLinear(scip, upgdconss[*nupgdconss], auxvar, -1.0) );
4480 
4481  z = auxvar;
4482  zcoef = 1.0;
4483 
4484  ++*nupgdconss;
4485 
4486  /* compute and set value of auxvar in debug solution */
4487 #ifdef WITH_DEBUG_SOLUTION
4488  if( SCIPdebugIsMainscip(scip) )
4489  {
4490  SCIP_Real debugval;
4491  SCIP_Real debugvarval;
4492  int i;
4493 
4494  debugval = 0.0;
4495  for( i = 0; i < SCIPgetNLinearVarsQuadratic(scip, cons); ++i )
4496  {
4497  SCIP_CALL( SCIPdebugGetSolVal(scip, SCIPgetLinearVarsQuadratic(scip, cons)[i], &debugvarval) );
4498  debugval += SCIPgetCoefsLinearVarsQuadratic(scip, cons)[i] * debugvarval;
4499  }
4500 
4501  SCIP_CALL( SCIPdebugAddSolVal(scip, auxvar, debugval) );
4502  }
4503 #endif
4504 
4505  SCIP_CALL( SCIPreleaseVar(scip, &auxvar) );
4506  }
4507  else
4508  {
4509  assert(SCIPgetNLinearVarsQuadratic(scip, cons) == 1);
4510  z = SCIPgetLinearVarsQuadratic(scip, cons)[0];
4511  zcoef = SCIPgetCoefsLinearVarsQuadratic(scip, cons)[0];
4512  }
4513 
4514  /* we now have lhs <= sqrcoef * (x + offset)^2 - sqrcoef * offset^2 + zcoef * z <= rhs */
4515 
4516  /* move sqrcoef * offset^2 into lhs and rhs */
4517  if( !SCIPisInfinity(scip, -lhs) )
4518  lhs += quadvarterm.sqrcoef * xoffset * xoffset;
4519  if( !SCIPisInfinity(scip, rhs) )
4520  rhs += quadvarterm.sqrcoef * xoffset * xoffset;
4521 
4522  /* divide by sqrcoef if x+offset > 0 and by -sqrcoef if < 0 */
4523  signpowcoef = quadvarterm.sqrcoef;
4524  if( SCIPisNegative(scip, SCIPvarGetLbGlobal(x) + xoffset) )
4525  signpowcoef = -signpowcoef;
4526  if( signpowcoef > 0.0 )
4527  {
4528  if( !SCIPisInfinity(scip, -lhs) )
4529  lhs /= signpowcoef;
4530  if( !SCIPisInfinity(scip, rhs) )
4531  rhs /= signpowcoef;
4532  }
4533  else
4534  {
4535  SCIP_Real newrhs;
4536 
4537  if( !SCIPisInfinity(scip, -lhs) )
4538  newrhs = lhs / signpowcoef;
4539  else
4540  newrhs = SCIPinfinity(scip);
4541  if( !SCIPisInfinity(scip, rhs) )
4542  lhs = rhs / signpowcoef;
4543  else
4544  lhs = -SCIPinfinity(scip);
4545  rhs = newrhs;
4546  }
4547  zcoef /= signpowcoef;
4548 
4549  /* create the absolute power constraint */
4550  SCIP_CALL( SCIPcreateConsAbspower(scip, &upgdconss[*nupgdconss], SCIPconsGetName(cons), x, z, 2.0,
4551  xoffset, zcoef, lhs, rhs,
4555  SCIPconsIsStickingAtNode(cons)) );
4556  SCIPdebugPrintCons(scip, upgdconss[*nupgdconss], NULL);
4557  ++*nupgdconss;
4558 
4559  return SCIP_OKAY;
4560 }
4561 
4562 /** tries to upgrade a nonlinear constraint into a absolute power constraint */
4563 static
4564 SCIP_DECL_NONLINCONSUPGD(nonlinconsUpgdAbspower)
4566  SCIP_EXPRGRAPH* exprgraph;
4567  SCIP_EXPRGRAPHNODE* node;
4568  SCIP_EXPRGRAPHNODE* child;
4569  SCIP_Real exponent;
4570  SCIP_VAR* x;
4571  SCIP_VAR* z;
4572  SCIP_Real signpowcoef;
4573  SCIP_Real zcoef;
4574  SCIP_Real xoffset;
4575  SCIP_Real constant;
4576  SCIP_Real lhs;
4577  SCIP_Real rhs;
4578 
4579  assert(nupgdconss != NULL);
4580  assert(upgdconss != NULL);
4581 
4582  *nupgdconss = 0;
4583 
4584  /* absolute power needs at least one linear variable (constraint is trivial, otherwise) */
4585  if( SCIPgetNLinearVarsNonlinear(scip, cons) == 0 )
4586  return SCIP_OKAY;
4587 
4588  node = SCIPgetExprgraphNodeNonlinear(scip, cons);
4589 
4590  /* no interest in linear constraints */
4591  if( node == NULL )
4592  return SCIP_OKAY;
4593 
4594  /* need exactly one argument */
4595  if( SCIPexprgraphGetNodeNChildren(node) != 1 )
4596  return SCIP_OKAY;
4597 
4598  constant = 0.0;
4599  signpowcoef = 1.0; /* coefficient of sign(x)abs(x)^n term, to be reformulated away... */
4600 
4601  child = SCIPexprgraphGetNodeChildren(node)[0];
4602 
4603  /* check if node expression fits to absolute power constraint */
4604  switch( SCIPexprgraphGetNodeOperator(node) )
4605  {
4606  case SCIP_EXPR_REALPOWER:
4607  /* realpower with exponent > 1.0 can always be signpower, since it assumes that argument is >= 0.0 */
4608  exponent = SCIPexprgraphGetNodeRealPowerExponent(node);
4609  if( exponent <= 1.0 )
4610  return SCIP_OKAY;
4611 
4612  assert(SCIPexprgraphGetNodeBounds(child).inf >= 0.0);
4613  break;
4614 
4615  case SCIP_EXPR_INTPOWER:
4616  {
4617  /* check if exponent > 1.0 and either odd or even with child having fixed sign */
4618  SCIP_INTERVAL childbounds;
4619 
4621  if( exponent <= 1.0 )
4622  return SCIP_OKAY;
4623 
4624  childbounds = SCIPexprgraphGetNodeBounds(child);
4625  if( (int)exponent % 2 == 0 && childbounds.inf < 0.0 && childbounds.sup > 0.0 )
4626  return SCIP_OKAY;
4627 
4628  /* use x^exponent = -sign(x) |x|^exponent if exponent is even and x always negative */
4629  if( (int)exponent % 2 == 0 && childbounds.inf < 0.0 )
4630  signpowcoef = -1.0;
4631 
4632  break;
4633  }
4634 
4635  case SCIP_EXPR_SQUARE:
4636  {
4637  /* check if child has fixed sign */
4638  SCIP_INTERVAL childbounds;
4639 
4640  childbounds = SCIPexprgraphGetNodeBounds(child);
4641  if( childbounds.inf < 0.0 && childbounds.sup > 0.0 )
4642  return SCIP_OKAY;
4643 
4644  /* use x^2 = -sign(x) |x|^2 if x is always negative */
4645  if( childbounds.inf < 0.0 )
4646  signpowcoef = -1.0;
4647 
4648  exponent = 2.0;
4649  break;
4650  }
4651 
4652  case SCIP_EXPR_SIGNPOWER:
4653  /* check if exponent > 1.0 */
4654  exponent = SCIPexprgraphGetNodeSignPowerExponent(node);
4655  if( exponent <= 1.0 )
4656  return SCIP_OKAY;
4657  break;
4658 
4659  case SCIP_EXPR_POLYNOMIAL:
4660  {
4661  SCIP_EXPRDATA_MONOMIAL* monomial;
4662  SCIP_INTERVAL childbounds;
4663 
4664  /* check if only one univariate monomial with exponent > 1.0 */
4665 
4666  /* if sum of univariate monomials, then this should have been taken care of by exprgraphnodeReformSignpower */
4668  return SCIP_OKAY;
4669  assert(SCIPexprgraphGetNodePolynomialNMonomials(node) == 1); /* assume simplified, i.e., no constant polynomial */
4670 
4671  monomial = SCIPexprgraphGetNodePolynomialMonomials(node)[0];
4672  assert(SCIPexprGetMonomialNFactors(monomial) == 1); /* since we have only one children and assume simplified */
4673 
4674  exponent = SCIPexprGetMonomialExponents(monomial)[0];
4675  if( exponent <= 1.0 )
4676  return SCIP_OKAY;
4677 
4678  /* if exponent is even integer and child has mixed sign, then cannot do
4679  * if exponent is even integer and child is always negative, then can do via multiplication by -1.0 */
4680  childbounds = SCIPexprgraphGetNodeBounds(child);
4681  if( SCIPisIntegral(scip, exponent) && ((int)SCIPround(scip, exponent) % 2 == 0) && childbounds.inf < 0.0 )
4682  {
4683  if( childbounds.sup > 0.0 )
4684  return SCIP_OKAY;
4685  signpowcoef = -1.0;
4686  }
4687 
4688  constant = SCIPexprgraphGetNodePolynomialConstant(node);
4689  signpowcoef *= SCIPexprGetMonomialCoef(monomial);
4690 
4691  break;
4692  }
4693 
4694  default:
4695  return SCIP_OKAY;
4696  } /*lint !e788*/
4697  assert(SCIPexprgraphGetNodeNChildren(node) == 1);
4698 
4699  /* check magnitue of coefficient of z in signpower constraint */
4700  zcoef = 1.0;
4701  if( SCIPgetNLinearVarsNonlinear(scip, cons) == 1 )
4702  zcoef = SCIPgetLinearCoefsNonlinear(scip, cons)[0];
4703  zcoef /= signpowcoef;
4705  {
4706  zcoef /= pow(REALABS(SCIPexprgraphGetNodeLinearCoefs(child)[0]), exponent);
4707  }
4708  if( SCIPisZero(scip, zcoef) )
4709  {
4710  SCIPdebugMsg(scip, "skip upgrade to signpower since |zcoef| = %g would be zero\n", zcoef);
4711  return SCIP_OKAY;
4712  }
4713 
4714  /* count how many constraints we need to add (use negative numbers, for convenience):
4715  * one constraint for absolute power,
4716  * plus one if we need to replace the linear part by single variable,
4717  * plus one if we need to replace the argument of absolute power by a single variable
4718  */
4719  *nupgdconss = -1;
4720 
4722  {
4723  /* if node has known curvature and we would add auxiliary var for child, then don't upgrade
4724  * it's not really necessary, but may introduce more numerical troubles
4725  * @todo maybe still do if child is linear?
4726  */
4728  {
4729  *nupgdconss = 0;
4730  return SCIP_OKAY;
4731  }
4732 
4733  --*nupgdconss;
4734  }
4735 
4736  if( SCIPgetNLinearVarsNonlinear(scip, cons) > 1 )
4737  --*nupgdconss;
4738 
4739  /* request larger upgdconss array */
4740  if( upgdconsssize < -*nupgdconss )
4741  return SCIP_OKAY;
4742 
4743  SCIPdebugMsg(scip, "upgrading constraint <%s>\n", SCIPconsGetName(cons));
4744 
4745  /* start counting at zero again */
4746  *nupgdconss = 0;
4747 
4748  exprgraph = SCIPgetExprgraphNonlinear(scip, SCIPconsGetHdlr(cons));
4749 
4750  lhs = SCIPgetLhsNonlinear(scip, cons);
4751  rhs = SCIPgetRhsNonlinear(scip, cons);
4752 
4753  /* get x and it's offset */
4755  {
4756  x = (SCIP_VAR*)SCIPexprgraphGetNodeVar(exprgraph, child);
4757  xoffset = 0.0;
4758  }
4760  {
4761  SCIP_Real xcoef;
4762 
4764  xcoef = SCIPexprgraphGetNodeLinearCoefs(child)[0];
4765  assert(!SCIPisZero(scip, xcoef));
4766 
4767  signpowcoef *= (xcoef < 0.0 ? -1.0 : 1.0) * pow(REALABS(xcoef), exponent);
4768  xoffset = SCIPexprgraphGetNodeLinearConstant(child) / xcoef;
4769  }
4770  else
4771  {
4772  /* reformulate by adding auxiliary variable and constraint for child */
4773  char name[SCIP_MAXSTRLEN];
4774  SCIP_INTERVAL bounds;
4775  SCIP_VAR* auxvar;
4776  SCIP_Real minusone;
4777 
4778  bounds = SCIPexprgraphGetNodeBounds(child);
4779  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_powerarg", SCIPconsGetName(cons));
4780 
4781  SCIPdebugMsg(scip, "add auxiliary variable and constraint %s for node %p(%d,%d)\n", name, (void*)child, SCIPexprgraphGetNodeDepth(child), SCIPexprgraphGetNodePosition(child));
4782 
4783  SCIP_CALL( SCIPcreateVar(scip, &auxvar, name, SCIPintervalGetInf(bounds), SCIPintervalGetSup(bounds), 0.0,
4785  SCIP_CALL( SCIPaddVar(scip, auxvar) );
4786 
4787  /* create new constraint child == auxvar
4788  * since signpower is monotonic, we need only child <= auxvar or child >= auxvar, if not both sides are finite, and depending on signpowcoef
4789  * i.e., we need child - auxvar <= 0.0 if rhs is finite and signpowcoef > 0.0 or lhs is finite and signpowcoef < 0.0
4790  * and we need 0.0 <= child - auxvar if lhs is finite and signpowcoef > 0.0 or rhs is finite and signpowcoef < 0.0
4791  */
4792  minusone = -1.0;
4793  assert(upgdconsssize > *nupgdconss);
4794  SCIP_CALL( SCIPcreateConsNonlinear2(scip, &upgdconss[*nupgdconss], name, 1, &auxvar, &minusone, child,
4795  ((signpowcoef > 0.0 && !SCIPisInfinity(scip, -lhs)) || (signpowcoef < 0.0 && !SCIPisInfinity(scip, rhs))) ? 0.0 : -SCIPinfinity(scip),
4796  ((signpowcoef > 0.0 && !SCIPisInfinity(scip, rhs)) || (signpowcoef < 0.0 && !SCIPisInfinity(scip, -lhs))) ? 0.0 : SCIPinfinity(scip),
4797  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
4798  ++*nupgdconss;
4799 
4800  /* use auxvar to setup absolute power constraint */
4801  x = auxvar;
4802  xoffset = 0.0;
4803 
4804  /* compute and set value of auxvar in debug solution, if debugging is enabled */
4805  SCIP_CALL( SCIPdebugAddSolVal(scip, auxvar, SCIPexprgraphGetNodeVal(child)) ); /*lint !e506 !e774*/
4806 
4807  SCIP_CALL( SCIPreleaseVar(scip, &auxvar) );
4808  }
4809 
4810  /* get z and its coefficient */
4811  if( SCIPgetNLinearVarsNonlinear(scip, cons) > 1 )
4812  {
4813  /* create auxiliary variable and constraint for linear part, since we can handle only at most one variable in cons_signpower */
4814  char name[SCIP_MAXSTRLEN];
4815  SCIP_VAR* auxvar;
4816 
4817  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_linpart", SCIPconsGetName(cons));
4818  SCIP_CALL( SCIPcreateVar(scip, &auxvar, name, -SCIPinfinity(scip), SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS,
4820  SCIP_CALL( SCIPaddVar(scip, auxvar) );
4821 
4822  assert(upgdconsssize > *nupgdconss);
4823  SCIP_CALL( SCIPcreateConsLinear(scip, &upgdconss[*nupgdconss], name, SCIPgetNLinearVarsNonlinear(scip, cons),
4825  SCIPisInfinity(scip, -lhs) ? -SCIPinfinity(scip) : 0.0,
4826  SCIPisInfinity(scip, rhs) ? SCIPinfinity(scip) : 0.0,
4830  SCIPconsIsStickingAtNode(cons)) );
4831  SCIP_CALL( SCIPaddCoefLinear(scip, upgdconss[*nupgdconss], auxvar, -1.0) );
4832 
4833  z = auxvar;
4834  zcoef = 1.0;
4835 
4836  ++*nupgdconss;
4837 
4838  /* compute and set value of auxvar in debug solution */
4839 #ifdef WITH_DEBUG_SOLUTION
4840  if( SCIPdebugIsMainscip(scip) )
4841  {
4842  SCIP_Real debugval;
4843  SCIP_Real debugvarval;
4844  int i;
4845 
4846  debugval = 0.0;
4847  for( i = 0; i < SCIPgetNLinearVarsNonlinear(scip, cons); ++i )
4848  {
4849  SCIP_CALL( SCIPdebugGetSolVal(scip, SCIPgetLinearVarsNonlinear(scip, cons)[i], &debugvarval) );
4850  debugval += SCIPgetLinearCoefsNonlinear(scip, cons)[i] * debugvarval;
4851  }
4852 
4853  SCIP_CALL( SCIPdebugAddSolVal(scip, auxvar, debugval) );
4854  }
4855 #endif
4856 
4857  SCIP_CALL( SCIPreleaseVar(scip, &auxvar) );
4858  }
4859  else
4860  {
4861  assert(SCIPgetNLinearVarsNonlinear(scip, cons) == 1);
4862  z = SCIPgetLinearVarsNonlinear(scip, cons)[0];
4863  zcoef = SCIPgetLinearCoefsNonlinear(scip, cons)[0];
4864  }
4865 
4866  if( constant != 0.0 )
4867  {
4868  if( !SCIPisInfinity(scip, -lhs) )
4869  lhs -= constant;
4870  if( !SCIPisInfinity(scip, rhs) )
4871  rhs -= constant;
4872  }
4873 
4874  /* divide absolute power constraint by signpowcoef */
4875  if( signpowcoef != 1.0 )
4876  {
4877  zcoef /= signpowcoef;
4878  if( signpowcoef < 0.0 )
4879  {
4880  SCIP_Real newrhs;
4881 
4882  newrhs = SCIPisInfinity(scip, -lhs) ? SCIPinfinity(scip) : lhs/signpowcoef;
4883  lhs = SCIPisInfinity(scip, rhs) ? -SCIPinfinity(scip) : rhs/signpowcoef;
4884  rhs = newrhs;
4885  }
4886  else
4887  {
4888  if( !SCIPisInfinity(scip, -lhs) )
4889  lhs /= signpowcoef;
4890  if( !SCIPisInfinity(scip, rhs) )
4891  rhs /= signpowcoef;
4892  }
4893  }
4894 
4895  /* finally setup a absolute power constraint */
4896 
4897  assert(*nupgdconss < upgdconsssize);
4898  SCIP_CALL( SCIPcreateConsAbspower(scip, &upgdconss[*nupgdconss], SCIPconsGetName(cons),
4899  x, z, exponent, xoffset, zcoef, lhs, rhs,
4903  SCIPconsIsStickingAtNode(cons)) );
4904  ++*nupgdconss;
4905 
4906  return SCIP_OKAY;
4907 }
4908 
4909 /** tries to reformulate a expression graph node via introducing a absolute power constraint
4910  * 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
4911  * if it still has nonlinear parents, then we wait to see if reformulation code move node into auxiliary constraint,
4912  * so we do not add unnessary auxiliary variables for something like an x^2 in an exp(x^2)
4913  * if it has no siblings, then we let the upgrading for nonlinear constraints take care of it,
4914  * 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)
4915  */
4916 static
4917 SCIP_DECL_EXPRGRAPHNODEREFORM(exprgraphnodeReformAbspower)
4919  SCIP_EXPRGRAPHNODE* child;
4920  char name[SCIP_MAXSTRLEN];
4921  SCIP_CONS* cons;
4922  SCIP_Real exponent;
4923  SCIP_VAR* x;
4924  SCIP_VAR* z;
4925  SCIP_Real signpowcoef;
4926  SCIP_Real xoffset;
4927  SCIP_Real constant;
4928 
4929  assert(scip != NULL);
4930  assert(exprgraph != NULL);
4931  assert(node != NULL);
4932  assert(naddcons != NULL);
4933  assert(reformnode != NULL);
4934 
4935  *reformnode = NULL;
4936 
4938  return SCIP_OKAY;
4939 
4940  constant = 0.0;
4941  signpowcoef = 1.0; /* coefficient of sign(x)abs(x)^n term, to be move in from of z... */
4942 
4943  /* check if node expression fits to absolute power constraint */
4944  switch( SCIPexprgraphGetNodeOperator(node) )
4945  {
4946  case SCIP_EXPR_REALPOWER:
4947  /* realpower with exponent > 1.0 can always be absolute power, since it assumes that argument is >= 0.0
4948  * @todo we should also ensure that argument is >= 0.0
4949  */
4950  exponent = SCIPexprgraphGetNodeRealPowerExponent(node);
4951  if( exponent <= 1.0 )
4952  return SCIP_OKAY;
4953 
4954  assert(SCIPexprgraphGetNodeBounds(SCIPexprgraphGetNodeChildren(node)[0]).inf >= 0.0);
4955  break;
4956 
4957  case SCIP_EXPR_INTPOWER:
4958  {
4959  /* check if exponent > 1.0 and either odd or even with child having fixed sign */
4960  SCIP_INTERVAL childbounds;
4961 
4963  if( exponent <= 1.0 )
4964  return SCIP_OKAY;
4965 
4967  if( (int)exponent % 2 == 0 && childbounds.inf < 0.0 && childbounds.sup > 0.0 )
4968  return SCIP_OKAY;
4969 
4970  /* use x^exponent = -sign(x) |x|^exponent if exponent is even and x always negative */
4971  if( (int)exponent % 2 == 0 && childbounds.inf < 0.0 )
4972  signpowcoef = -1.0;
4973 
4974  break;
4975  }
4976 
4977  case SCIP_EXPR_SQUARE:
4978  {
4979  /* check if child has fixed sign */
4980  SCIP_INTERVAL childbounds;
4981 
4983  if( childbounds.inf < 0.0 && childbounds.sup > 0.0 )
4984  return SCIP_OKAY;
4985 
4986  /* use x^2 = -sign(x) |x|^2 if x is always negative */
4987  if( childbounds.inf < 0.0 )
4988  signpowcoef = -1.0;
4989 
4990  exponent = 2.0;
4991  break;
4992  }
4993 
4994  case SCIP_EXPR_SIGNPOWER:
4995  /* check if exponent > 1.0 */
4996  exponent = SCIPexprgraphGetNodeSignPowerExponent(node);
4997  if( exponent <= 1.0 )
4998  return SCIP_OKAY;
4999  break;
5000 
5001  case SCIP_EXPR_POLYNOMIAL:
5002  {
5003  SCIP_EXPRDATA_MONOMIAL* monomial;
5004  SCIP_INTERVAL childbounds;
5005 
5006  /* check if only one univariate monomial with exponent > 1.0 */
5007  if( SCIPexprgraphGetNodeNChildren(node) > 1 )
5008  return SCIP_OKAY;
5009  assert(SCIPexprgraphGetNodeNChildren(node) == 1);
5010 
5012  return SCIP_OKAY;
5013  assert(SCIPexprgraphGetNodePolynomialNMonomials(node) == 1); /* assume simplified, i.e., no constant polynomial */
5014 
5015  monomial = SCIPexprgraphGetNodePolynomialMonomials(node)[0];
5016  assert(SCIPexprGetMonomialNFactors(monomial) == 1); /* since we have only one children and assume simplified */
5017 
5018  exponent = SCIPexprGetMonomialExponents(monomial)[0];
5019  if( exponent <= 1.0 )
5020  return SCIP_OKAY;
5021 
5022  /* if exponent is even integer and child has mixed sign, then cannot do
5023  * if exponent is even integer and child is always negative, then can do via multiplication by -1.0 */
5025  if( SCIPisIntegral(scip, exponent) && ((int)SCIPround(scip, exponent) % 2 == 0) && childbounds.inf < 0.0 )
5026  {
5027  if( childbounds.sup > 0.0 )
5028  return SCIP_OKAY;
5029  signpowcoef = -1.0;
5030  }
5031 
5032  constant = SCIPexprgraphGetNodePolynomialConstant(node);
5033  signpowcoef *= SCIPexprGetMonomialCoef(monomial);
5034 
5035  break;
5036  }
5037 
5038  default:
5039  return SCIP_OKAY;
5040  } /*lint !e788*/
5041  assert(SCIPexprgraphGetNodeNChildren(node) == 1);
5042 
5044  return SCIP_OKAY;
5045  if( !SCIPexprgraphHasNodeSibling(node) )
5046  return SCIP_OKAY;
5047 
5048  SCIPdebugMsg(scip, "reformulate node %p via signpower\n", (void*)node);
5049 
5050  /* get x and its offset */
5051  child = SCIPexprgraphGetNodeChildren(node)[0];
5053  {
5054  x = (SCIP_VAR*)SCIPexprgraphGetNodeVar(exprgraph, child);
5055  xoffset = 0.0;
5056  }
5058  {
5059  SCIP_Real xcoef;
5060 
5062  xcoef = SCIPexprgraphGetNodeLinearCoefs(child)[0];
5063  assert(!SCIPisZero(scip, xcoef));
5064 
5065  signpowcoef *= (xcoef < 0.0 ? -1.0 : 1.0) * pow(REALABS(xcoef), exponent);
5066  xoffset = SCIPexprgraphGetNodeLinearConstant(child) / xcoef;
5067  }
5068  else
5069  {
5070  /* reformulate by adding auxiliary variable and constraint for child */
5071  SCIP_INTERVAL bounds;
5072  SCIP_VAR* auxvar;
5073  SCIP_Real minusone;
5074 
5075  bounds = SCIPexprgraphGetNodeBounds(child);
5076  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "nlreform%dsp", *naddcons);
5077 
5078  SCIPdebugMsg(scip, "add auxiliary variable and constraint %s for node %p(%d,%d)\n", name, (void*)child, SCIPexprgraphGetNodeDepth(child), SCIPexprgraphGetNodePosition(child));
5079 
5080  SCIP_CALL( SCIPcreateVar(scip, &auxvar, name, SCIPintervalGetInf(bounds), SCIPintervalGetSup(bounds), 0.0, SCIP_VARTYPE_CONTINUOUS,
5081  TRUE, TRUE, NULL, NULL, NULL, NULL, NULL) );
5082  SCIP_CALL( SCIPaddVar(scip, auxvar) );
5083 
5084  /* create new constraint child == auxvar */
5085  minusone = -1.0;
5086  SCIP_CALL( SCIPcreateConsNonlinear2(scip, &cons, name, 1, &auxvar, &minusone, child, 0.0, 0.0,
5087  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
5088  SCIP_CALL( SCIPaddCons(scip, cons) );
5089  ++*naddcons;
5090 
5091  /* use auxvar to setup signpower constraint */
5092  x = auxvar;
5093  xoffset = 0.0;
5094 
5095  SCIP_CALL( SCIPdebugAddSolVal(scip, auxvar, SCIPexprgraphGetNodeVal(child)) ); /*lint !e506 !e774*/
5096 
5097  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
5098  SCIP_CALL( SCIPreleaseVar(scip, &auxvar) );
5099  }
5100 
5101  /* create auxiliary variable z and add to expression graph */
5102  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "nlreform%dsp", *naddcons);
5103  SCIP_CALL( SCIPcreateVar(scip, &z, name, -SCIPinfinity(scip), SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS,
5104  TRUE, TRUE, NULL, NULL, NULL, NULL, NULL) );
5105  SCIP_CALL( SCIPaddVar(scip, z) );
5106  SCIP_CALL( SCIPexprgraphAddVars(exprgraph, 1, (void**)&z, reformnode) );
5107 
5108  /* setup a absolute power constraint */
5109  if( REALABS(signpowcoef) * SCIPfeastol(scip) < 1.0 )
5110  {
5111  /* if signpowcoef is not huge (<10^6), then put it into absolute power constraint */
5112  SCIP_CALL( SCIPcreateConsAbspower(scip, &cons, name,
5113  x, z, exponent, xoffset, -1.0/signpowcoef, -constant/signpowcoef, -constant/signpowcoef,
5114  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
5115  SCIP_CALL( SCIPaddCons(scip, cons) );
5116  SCIPdebugPrintCons(scip, cons, NULL);
5117  ++*naddcons;
5118 
5119  /* compute value of z and reformnode and set in debug solution and expression graph, resp. */
5120 #ifdef WITH_DEBUG_SOLUTION
5121  if( SCIPdebugIsMainscip(scip) )
5122  {
5123  SCIP_Real xval;
5124  SCIP_Real zval;
5125 
5126  SCIP_CALL( SCIPdebugGetSolVal(scip, x, &xval) );
5127  zval = signpowcoef * SIGN(xval + xoffset) * pow(REALABS(xval + xoffset), exponent) + constant;
5128 
5129  SCIP_CALL( SCIPdebugAddSolVal(scip, z, zval) );
5130  SCIPexprgraphSetVarNodeValue(*reformnode, zval);
5131  }
5132 #endif
5133  }
5134  else
5135  {
5136  /* if signpowcoef is huge, then avoid very small coefficient of z
5137  * instead create additional node on top of current reformnode */
5138  SCIP_EXPRGRAPHNODE* linnode;
5139 
5140  SCIP_CALL( SCIPcreateConsAbspower(scip, &cons, name,
5141  x, z, exponent, xoffset, -1.0, 0.0, 0.0,
5142  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
5143  SCIP_CALL( SCIPaddCons(scip, cons) );
5144  SCIPdebugPrintCons(scip, cons, NULL);
5145  ++*naddcons;
5146 
5147  /* compute value of z and reformnode and set in debug solution and expression graph, resp. */
5148 #ifdef WITH_DEBUG_SOLUTION
5149  if( SCIPdebugIsMainscip(scip) )
5150  {
5151  SCIP_Real xval;
5152  SCIP_Real zval;
5153 
5154  SCIP_CALL( SCIPdebugGetSolVal(scip, x, &xval) );
5155  zval = SIGN(xval + xoffset) * pow(REALABS(xval + xoffset), exponent);
5156 
5157  SCIP_CALL( SCIPdebugAddSolVal(scip, z, zval) );
5158  SCIPexprgraphSetVarNodeValue(*reformnode, zval);
5159  }
5160 #endif
5161 
5162  SCIP_CALL( SCIPexprgraphCreateNodeLinear(SCIPblkmem(scip), &linnode, 1, &signpowcoef, constant) );
5163  SCIP_CALL( SCIPexprgraphAddNode(exprgraph, linnode, -1, 1, reformnode) );
5164 
5165  *reformnode = linnode;
5166  }
5167 
5168  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
5169  SCIP_CALL( SCIPreleaseVar(scip, &z) );
5170 
5171  return SCIP_OKAY;
5172 }
5173 
5174 /** helper function to enforce constraints */
5175 static
5177  SCIP* scip, /**< SCIP data structure */
5178  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
5179  SCIP_CONS** conss, /**< constraints to process */
5180  int nconss, /**< number of constraints */
5181  int nusefulconss, /**< number of useful (non-obsolete) constraints to process */
5182  SCIP_SOL* sol, /**< solution to enforce (NULL for the LP solution) */
5183  SCIP_Bool solinfeasible, /**< was the solution already declared infeasible by a constraint handler? */
5184  SCIP_RESULT* result /**< pointer to store the result of the enforcing call */
5185  )
5186 {
5187  SCIP_CONSHDLRDATA* conshdlrdata;
5188  SCIP_CONS* maxviolcons;
5189  SCIP_CONSDATA* consdata;
5190  SCIP_Bool success;
5191  SCIP_Bool cutoff;
5192  SCIP_Bool solviolbounds;
5193  SCIP_Real sepaefficacy;
5194  SCIP_Real maxviol;
5195  int nnotify;
5196  int c;
5197 
5198  assert(scip != NULL);
5199  assert(conshdlr != NULL);
5200  assert(conss != NULL || nconss == 0);
5201  assert(result != NULL);
5202 
5203  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5204  assert(conshdlrdata != NULL);
5205 
5206  SCIP_CALL( computeViolations(scip, conshdlr, conss, nconss, sol, &solviolbounds, &maxviolcons) );
5207 
5208  if( maxviolcons == NULL )
5209  {
5210  *result = SCIP_FEASIBLE;
5211  return SCIP_OKAY;
5212  }
5213 
5214  *result = SCIP_INFEASIBLE;
5215 
5216  if( solviolbounds )
5217  {
5218  /* if LP solution violates variable bounds, then this should be because a row was added that
5219  * introduced this variable newly to the LP, in which case it gets value 0.0; the row should
5220  * have been added to resolve an infeasibility, so solinfeasible should be TRUE
5221  * see also issue #627
5222  */
5223  assert(solinfeasible);
5224  /* however, if solinfeasible is actually not TRUE, then better cut off the node to avoid that SCIP
5225  * stops because infeasible cannot be resolved */
5226  /*lint --e{774} */
5227  if( !solinfeasible )
5228  *result = SCIP_CUTOFF;
5229  return SCIP_OKAY;
5230  }
5231 
5232  /* if we are above the 100'th enforcement round for this node, something is strange
5233  * (maybe the LP does not think that the cuts we add are violated, or we do ECP on a high-dimensional convex function)
5234  * 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
5235  * (in optimized more, returning SCIP_INFEASIBLE in *result would be sufficient, but in debug mode this would give an assert in scip.c)
5236  * the reason to wait for 100 rounds is to avoid calls to SCIPisStopped in normal runs, which may be expensive
5237  * we only increment nenforounds until 101 to avoid an overflow
5238  */
5239  if( conshdlrdata->lastenfonode == SCIPgetCurrentNode(scip) )
5240  {
5241  if( conshdlrdata->nenforounds > 100 )
5242  {
5243  if( SCIPisStopped(scip) )
5244  {
5245  SCIP_NODE* child;
5246 
5247  SCIP_CALL( SCIPcreateChild(scip, &child, 1.0, SCIPnodeGetEstimate(SCIPgetCurrentNode(scip))) );
5248  *result = SCIP_BRANCHED;
5249 
5250  return SCIP_OKAY;
5251  }
5252  }
5253  else
5254  ++conshdlrdata->nenforounds;
5255  }
5256  else
5257  {
5258  conshdlrdata->lastenfonode = SCIPgetCurrentNode(scip);
5259  conshdlrdata->nenforounds = 0;
5260  }
5261 
5262  /* run domain propagation for violated constraints */
5263  for( c = 0; c < nconss; ++c )
5264  {
5265  int nchgbds;
5266  int naddconss;
5267 
5268  assert(conss[c] != NULL); /*lint !e613*/
5269 
5270  consdata = SCIPconsGetData(conss[c]); /*lint !e613*/
5271  assert(consdata != NULL);
5272 
5273  if( !SCIPisGT(scip, consdata->lhsviol, SCIPfeastol(scip)) && !SCIPisGT(scip, consdata->rhsviol, SCIPfeastol(scip)) )
5274  continue;
5275 
5276  nchgbds = 0;
5277  naddconss = 0;
5278  SCIP_CALL( propagateCons(scip, conshdlr, conss[c], TRUE, &cutoff, &nchgbds, &naddconss) ); /*lint !e613*/
5279  if( cutoff )
5280  {
5281  *result = SCIP_CUTOFF;
5282  return SCIP_OKAY;
5283  }
5284  if( nchgbds )
5285  *result = SCIP_REDUCEDDOM;
5286  if( naddconss )
5287  *result = SCIP_CONSADDED;
5288  }
5289  if( *result == SCIP_REDUCEDDOM || *result == SCIP_CONSADDED )
5290  return SCIP_OKAY;
5291 
5292  consdata = SCIPconsGetData(maxviolcons);
5293  assert(consdata != NULL);
5294  maxviol = consdata->lhsviol + consdata->rhsviol;
5295  assert(SCIPisGT(scip, maxviol, SCIPfeastol(scip)));
5296 
5297  /* we would like a cut that is efficient enough that it is not redundant in the LP (>lpfeastol)
5298  * however, we also don't want very weak cuts, so try to reach at least feastol (=lpfeastol by default, though)
5299  */
5300  SCIP_CALL( separatePoint(scip, conshdlr, conss, nconss, nusefulconss, sol, SCIPfeastol(scip), TRUE, FALSE, &success,
5301  &cutoff, &sepaefficacy) );
5302  if( cutoff )
5303  {
5304  SCIPdebugMsg(scip, "separation detected cutoff.\n");
5305  *result = SCIP_CUTOFF;
5306  return SCIP_OKAY;
5307  }
5308  if( success )
5309  {
5310  SCIPdebugMsg(scip, "separation succeeded (bestefficacy = %g, minefficacy = %g)\n", sepaefficacy, SCIPfeastol(scip));
5311  *result = SCIP_SEPARATED;
5312  return SCIP_OKAY;
5313  }
5314  SCIPdebugMsg(scip, "separation failed (bestefficacy = %g < %g = minefficacy ); max viol: %g\n", sepaefficacy, SCIPfeastol(scip),
5315  maxviol);
5316 
5317  /* we are not feasible, the whole node is not infeasible, and we cannot find a reasonable cut
5318  * -> collect variables for branching
5319  */
5320  SCIP_CALL( registerBranchingCandidates(scip, conshdlr, conss, nconss, sol, &nnotify) );
5321 
5322  if( nnotify == 0 && !solinfeasible && SCIPfeastol(scip) > SCIPlpfeastol(scip) )
5323  {
5324  /* fallback 1: we also have no branching candidates, so try to find a weak cut */
5325  SCIP_CALL( separatePoint(scip, conshdlr, conss, nconss, nusefulconss, sol, SCIPlpfeastol(scip), TRUE, FALSE,
5326  &success, &cutoff, &sepaefficacy) );
5327  if( cutoff )
5328  {
5329  SCIPdebugMsg(scip, "separation detected cutoff.\n");
5330  *result = SCIP_CUTOFF;
5331  return SCIP_OKAY;
5332  }
5333  if( success )
5334  {
5335  *result = SCIP_SEPARATED;
5336  return SCIP_OKAY;
5337  }
5338  }
5339 
5340