Couenne  0.5.7
CouenneExprBDiv.hpp
Go to the documentation of this file.
1 /* $Id: CouenneExprBDiv.hpp 490 2011-01-14 16:07:12Z pbelotti $ */
2 /*
3  * Name: exprBDiv.hpp
4  * Author: Pietro Belotti
5  * Purpose: definition of operators to compute lower/upper bounds of divisions
6  *
7  * (C) Carnegie-Mellon University, 2006.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #ifndef COUENNE_EXPRBDIV_H
12 #define COUENNE_EXPRBDIV_H
13 
14 #include "CouenneExprOp.hpp"
15 
16 namespace Couenne {
17 
19 static inline CouNumber safeDiv (register CouNumber a, register CouNumber b, int sign) {
20 
21  if (fabs (a) < COUENNE_EPS) return 0;
22  // if (fabs (b) < COUENNE_EPS)) return 0;
23  // else return 0
24 
25  if (fabs (b) < COUENNE_EPS) return ((sign < 0) ? -COUENNE_INFINITY : COUENNE_INFINITY);
26 
27  if (a > COUENNE_INFINITY) return ((sign < 0) ? -COUENNE_INFINITY : COUENNE_INFINITY);
28  if (a < -COUENNE_INFINITY) return ((sign < 0) ? -COUENNE_INFINITY : COUENNE_INFINITY);
29 
30  return a/b;
31 }
32 
33 
36 
37 class exprLBDiv: public exprOp {
38 
39  public:
40 
42  exprLBDiv (expression **al, int n):
43  exprOp (al, n) {} //< non-leaf expression, with argument list
44 
46  expression *clone (Domain *d = NULL) const
47  {return new exprLBDiv (clonearglist (d), nargs_);}
48 
51 
53  enum pos printPos () const
54  {return PRE;}
55 
57  std::string printOp () const
58  {return "LB_Div";}
59 };
60 
61 
63 
65 
66  register CouNumber n = (*(arglist_ [0])) ();
67  register CouNumber N = (*(arglist_ [1])) ();
68  register CouNumber d = (*(arglist_ [2])) ();
69  register CouNumber D = (*(arglist_ [3])) ();
70  // (n,N,d,D) lb
71  if (d > 0) // (?,?,+,+)
72  if (n > 0) return safeDiv (n,D,-1); // (+,+,+,+) --> n/D
73  else return safeDiv (n,d,-1); // (-,?,+,+) --> n/d
74  else { // d <= 0
75  if (D > 0) return - COUENNE_INFINITY; // (?,?,-,+) --> unbounded
76  else if (N > 0) return safeDiv (N,D,-1); // (?,+,-,-) --> N/D
77  else return safeDiv (N,d,-1); // (-,-,-,-) --> N/d
78  }
79 }
80 
81 
84 
85 class exprUBDiv: public exprOp {
86 
87  public:
88 
90  exprUBDiv (expression **al, int n):
91  exprOp (al, n) {} //< non-leaf expression, with argument list
92 
94  expression *clone (Domain *d = NULL) const
95  {return new exprUBDiv (clonearglist (d), nargs_);}
96 
99 
101  enum pos printPos () const
102  {return PRE;}
103 
105  std::string printOp () const
106  {return "UB_Div";}
107 };
108 
109 
111 
113 
114  register CouNumber n = (*(arglist_ [0])) ();
115  register CouNumber N = (*(arglist_ [1])) ();
116  register CouNumber d = (*(arglist_ [2])) ();
117  register CouNumber D = (*(arglist_ [3])) ();
118 
119  if (d > 0) // (n,N,d,D) lb
120  if (N < 0) return safeDiv (N,D,1); // (-,-,+,+) --> N/D
121  else return safeDiv (N,d,1); // (?,+,+,+) --> N/d
122  else { // d <= 0
123  if (D > 0) return + COUENNE_INFINITY; // (?,?,-,+) --> unbounded
124  else if (n < 0) return safeDiv (n,D,1); // (-,?,-,-) --> n/D
125  else return safeDiv (n,d,1); // (+,+,-,-) --> n/d
126  }
127 }
128 
129 }
130 
131 #endif
expression ** arglist_
argument list is an array of pointers to other expressions
#define COUENNE_INFINITY
pos
position where the operator should be printed when printing the expression
expression * clone(Domain *d=NULL) const
cloning method
class to compute lower bound of a fraction based on the bounds of both numerator and denominator
int nargs_
number of arguments (cardinality of arglist)
general n-ary operator-type expression: requires argument list.
double CouNumber
main number type in Couenne
#define COUENNE_EPS
exprUBDiv(expression **al, int n)
Constructors, destructor.
expression ** clonearglist(Domain *d=NULL) const
clone argument list (for use with clone method)
class to compute upper bound of a fraction based on the bounds of both numerator and denominator
exprLBDiv(expression **al, int n)
Constructors, destructor.
enum pos printPos() const
print position (PRE, INSIDE, POST)
Define a dynamic point+bounds, with a way to save and restore previous points+bounds through a LIFO s...
enum pos printPos() const
print position (PRE, INSIDE, POST)
CouNumber operator()()
function for the evaluation of the expression
expression * clone(Domain *d=NULL) const
cloning method
Expression base class.
CouNumber operator()()
function for the evaluation of the expression
static CouNumber safeDiv(register CouNumber a, register CouNumber b, int sign)
division that avoids NaN's and considers a sign when returning infinity
std::string printOp() const
print operator
general include file for different compilers
std::string printOp() const
print operator