Couenne  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CouenneExprPow.hpp
Go to the documentation of this file.
1 /* $Id: CouenneExprPow.hpp 1182 2015-08-17 12:39:40Z stefan $
2  *
3  * Name: CouenneExprPow.hpp
4  * Author: Pietro Belotti
5  * Purpose: definition of powers, specifically with fractional
6  * exponent (odd/even/signed: see appropriate files)
7  *
8  * (C) Carnegie-Mellon University, 2006-11.
9  * This file is licensed under the Eclipse Public License (EPL)
10  */
11 
12 #ifndef COUENNE_EXPRPOW_HPP
13 #define COUENNE_EXPRPOW_HPP
14 
15 #include <math.h>
16 #include <stdio.h>
17 
18 #include "CouenneExprOp.hpp"
19 #include "CouenneExprMul.hpp"
20 #include "CouenneExprClone.hpp"
21 #include "CouenneExprConst.hpp"
22 
23 namespace Couenne {
24 
25 class funtriplet;
26 
27 
29 
30 class exprPow: public exprOp {
31 
32  private:
33 
36 
37  public:
38 
40  exprPow (expression **al, int n = 2, bool signpower = false):
41  exprOp (al, n), issignpower_ (signpower) {} //< non-leaf expression, with argument list
42 
44  exprPow (expression *arg0, expression *arg1, bool signpower = false):
45  exprOp (arg0, arg1), issignpower_ (signpower) {}
46 
48  expression *clone (Domain *d = NULL) const
49  {return new exprPow (clonearglist (d), nargs_, issignpower_);}
50 
52  virtual enum pos printPos () const
53  {return issignpower_ ? PRE : INSIDE ;}
54 
56  virtual std::string printOp () const
57  {return issignpower_ ? "signpower" : "^";}
58 
60  virtual CouNumber operator () ();
61 
63  virtual CouNumber gradientNorm (const double *x);
64 
66  virtual expression *differentiate (int index);
67 
69  virtual expression *simplify ();
70 
72  virtual int Linearity ();
73 
75  virtual bool isInteger ();
76 
78  virtual void getBounds (expression *&, expression *&);
79 
81  virtual void getBounds (CouNumber &lb, CouNumber &ub);
82 
85  virtual exprAux *standardize (CouenneProblem *p, bool addAux = true);
86 
88  virtual void generateCuts (expression *w, //const OsiSolverInterface &si,
89  OsiCuts &cs, const CouenneCutGenerator *cg,
90  t_chg_bounds * = NULL, int = -1,
93 
96  virtual expression *getFixVar ()
97  {return arglist_ [0];}
98 
100  virtual enum expr_type code ()
102 
104  virtual bool impliedBound (int, CouNumber *, CouNumber *, t_chg_bounds *, enum auxSign = expression::AUX_EQ);
105 
108  virtual CouNumber selectBranch (const CouenneObject *obj,
109  const OsiBranchingInformation *info,
110  expression * &var,
111  double * &brpts,
112  double * &brDist, // distance of current LP
113  // point to new convexifications
114  int &way);
115 
117  virtual void closestFeasible (expression *varind,
118  expression *vardep,
119  CouNumber &left,
120  CouNumber &right) const;
121 
124  virtual bool isCuttable (CouenneProblem *problem, int index) const;
125 
127  virtual bool isSignpower () const { return issignpower_; }
128 };
129 
130 
132 
134  CouNumber exponent, bool signpower = false) {
135 
136  double
137  lbase = base,
138  lexponent = exponent,
139  retval = 0.;
140 
141  if (lbase < 0.) {
142 
143  register int rndexp = COUENNE_round (lexponent);
144 
145  if (((fabs (lexponent - rndexp) < COUENNE_EPS) ||
146  ((fabs (lexponent) > COUENNE_EPS) &&
147  (fabs (1. / lexponent - (rndexp = COUENNE_round (1. / lexponent))) < COUENNE_EPS)))) {
148  if ((rndexp % 2) || signpower)
149  retval = (- pow (- lbase, lexponent)); // x^k, x negative, k odd or signed power
150  else retval = pow (- lbase, lexponent); // x^k, x negative, k even or signed power
151  }
152  else retval = 0.; // this is incorrect but avoids nan's
153  }
154  else if (fabs (lbase) >= COUENNE_INFINITY) {
155 
156  if (lbase <= -COUENNE_INFINITY) {
157 
158  register int intk = COUENNE_round (lexponent);
159 
160  if ((fabs (lexponent - intk) < COUENNE_EPS) && (intk % 2 || signpower))
161  retval = (lexponent < 0.) ? 0. : -COUENNE_INFINITY;
162  }
163  else retval = (lexponent < 0.) ? 0. : COUENNE_INFINITY;
164  }
165  else
166  retval = (pow (lbase, lexponent));
167 
168  return (CouNumber) (retval);
169 }
170 
171 
174  // return (currValue_ = safe_pow (base, exponent));
175  return safe_pow ((**arglist_) (), (*(arglist_ [1])) (), issignpower_);
176 }
177 
178 
180 void addPowEnvelope (const CouenneCutGenerator *, OsiCuts &, int, int,
181  CouNumber, CouNumber, CouNumber, CouNumber, CouNumber, int, bool = false);
182 
185 
188 
189 }
190 
191 #endif
Cut Generator for linear convexifications.
virtual CouNumber gradientNorm(const double *x)
return l-2 norm of gradient at given point
virtual CouNumber operator()()
function for the evaluation of the expression
virtual enum pos printPos() const
print operator positioning
#define COUENNE_round(x)
virtual int Linearity()
get a measure of &quot;how linear&quot; the expression is
virtual expression * differentiate(int index)
differentiation
virtual void getBounds(expression *&, expression *&)
Get lower and upper bound of an expression (if any)
pos
position where the operator should be printed when printing the expression
OsiObject for auxiliary variables $w=f(x)$.
CouNumber powNewton(CouNumber, CouNumber, unary_function, unary_function, unary_function)
find proper tangent point to add deepest tangent cut
status of lower/upper bound of a variable, to be checked/modified in bound tightening ...
Power of an expression (binary operator), with constant.
virtual bool isInteger()
is this expression integer?
expression * clone(Domain *d=NULL) const
cloning method
void addPowEnvelope(const CouenneCutGenerator *, OsiCuts &, int, int, CouNumber, CouNumber, CouNumber, CouNumber, CouNumber, int, bool=false)
add upper/lower envelope to power in convex/concave areas
virtual enum expr_type code()
code for comparison
exprPow(expression **al, int n=2, bool signpower=false)
Constructor.
virtual exprAux * standardize(CouenneProblem *p, bool addAux=true)
reduce expression in standard form, creating additional aux variables (and constraints) ...
auxSign
&quot;sign&quot; of the constraint defining an auxiliary.
CouNumber(* unary_function)(CouNumber)
unary function, used in all exprUnary
expression ** clonearglist(Domain *d=NULL) const
clone argument list (for use with clone method)
Class for MINLP problems with symbolic information.
#define COUENNE_EPS
bool issignpower_
do we mean a signed power function: sign(arg0) * |arg0|^arg1 (assumes that arg1 is constant) ...
virtual bool isSignpower() const
return whether this expression corresponds to a signed integer power
expression ** arglist_
argument list is an array of pointers to other expressions
double CouNumber
main number type in Couenne
int nargs_
number of arguments (cardinality of arglist)
virtual CouNumber selectBranch(const CouenneObject *obj, const OsiBranchingInformation *info, expression *&var, double *&brpts, double *&brDist, int &way)
set up branching object by evaluating many branching points for each expression&#39;s arguments ...
general n-ary operator-type expression: requires argument list.
virtual void closestFeasible(expression *varind, expression *vardep, CouNumber &left, CouNumber &right) const
compute $y^{lv}$ and $y^{uv}$ for Violation Transfer algorithm
#define COUENNE_INFINITY
Auxiliary variable.
virtual void generateCuts(expression *w, OsiCuts &cs, const CouenneCutGenerator *cg, t_chg_bounds *=NULL, int=-1, CouNumber=-COUENNE_INFINITY, CouNumber=COUENNE_INFINITY)
generate equality between *this and *w
virtual std::string printOp() const
print operator
expr_type
code returned by the method expression::code()
virtual expression * simplify()
simplification
CouNumber safe_pow(CouNumber base, CouNumber exponent, bool signpower=false)
compute power and check for integer-and-odd inverse exponent
Expression base class.
virtual bool impliedBound(int, CouNumber *, CouNumber *, t_chg_bounds *, enum auxSign=expression::AUX_EQ)
implied bound processing
virtual bool isCuttable(CouenneProblem *problem, int index) const
can this expression be further linearized or are we on its concave (&quot;bad&quot;) side
Define a dynamic point+bounds, with a way to save and restore previous points+bounds through a LIFO s...
virtual expression * getFixVar()
return an index to the variable&#39;s argument that is better fixed in a branching rule for solving a non...
exprPow(expression *arg0, expression *arg1, bool signpower=false)
Constructor with only two arguments.