Couenne
0.5.8
src
expression
operators
bounds
CouenneExprBMul.hpp
Go to the documentation of this file.
1
/* $Id: CouenneExprBMul.hpp 591 2011-05-31 17:03:03Z pbelotti $
2
*
3
* Name: exprBMul.hpp
4
* Author: Pietro Belotti
5
* Purpose: definition of operators to compute lower/upper bounds of multiplications
6
*
7
* (C) Carnegie-Mellon University, 2006.
8
* This file is licensed under the Eclipse Public License (EPL)
9
*/
10
11
#ifndef COUENNE_EXPRBMUL_H
12
#define COUENNE_EXPRBMUL_H
13
14
#include "
CouenneExprOp.hpp
"
15
#include "
CouenneConfig.h
"
16
#include "
CoinHelperFunctions.hpp
"
17
#include "
CoinFinite.hpp
"
18
19
namespace
Couenne
{
20
21
#define MUL_ZERO 1e-20
22
#define MUL_INF sqrt (COIN_DBL_MAX)
23
25
inline
CouNumber
safeProd
(
register
CouNumber
a,
register
CouNumber
b) {
26
27
if
(a >
MUL_INF
)
return
(b < -
MUL_ZERO
) ? -
COIN_DBL_MAX
: (b >
MUL_ZERO
) ?
COIN_DBL_MAX
: 0.;
28
if
(a < -
MUL_INF
)
return
(b < -
MUL_ZERO
) ?
COIN_DBL_MAX
: (b >
MUL_ZERO
) ? -
COIN_DBL_MAX
: 0.;
29
30
if
(b >
MUL_INF
)
return
(a < -
MUL_ZERO
) ? -
COIN_DBL_MAX
: (a >
MUL_ZERO
) ?
COIN_DBL_MAX
: 0.;
31
if
(b < -
MUL_INF
)
return
(a < -
MUL_ZERO
) ?
COIN_DBL_MAX
: (a >
MUL_ZERO
) ? -
COIN_DBL_MAX
: 0.;
32
33
return
a*b;
34
}
35
36
39
40
class
exprLBMul
:
public
exprOp
{
41
42
public
:
43
45
exprLBMul
(
expression
**al,
int
n):
46
exprOp
(al, n) {}
//< non-leaf expression, with argument list
47
49
expression
*
clone
(
Domain
*d = NULL)
const
50
{
return
new
exprLBMul
(
clonearglist
(d),
nargs_
);}
51
53
CouNumber
operator ()
();
54
56
enum
pos
printPos
()
const
57
{
return
PRE
;}
58
60
std::string
printOp
()
const
61
{
return
"LB_Mul"
;}
62
};
63
64
66
67
inline
CouNumber
exprLBMul::operator ()
() {
68
69
register
CouNumber
n = (*(
arglist_
[0])) ();
70
register
CouNumber
N = (*(
arglist_
[1])) ();
71
register
CouNumber
d = (*(
arglist_
[2])) ();
72
register
CouNumber
D = (*(
arglist_
[3])) ();
73
74
if
(d>=0)
75
if
(n>=0)
return
safeProd
(n,d);
76
else
return
safeProd
(n,D);
77
else
// d <= 0
78
if
(N>0) {
79
CouNumber
Nd =
safeProd
(N,d), nD;
80
if
(n<0 && D>0 &&
81
(Nd > (nD =
safeProd
(n,D))))
return
nD;
82
else
return
Nd;
83
}
84
else
85
if
(D>0)
return
safeProd
(n,D);
86
else
return
safeProd
(N,D);
87
}
88
89
92
93
class
exprUBMul
:
public
exprOp
{
94
95
public
:
96
98
exprUBMul
(
expression
**al,
int
n):
99
exprOp
(al, n) {}
//< non-leaf expression, with argument list
100
102
expression
*
clone
(
Domain
*d = NULL)
const
103
{
return
new
exprUBMul
(
clonearglist
(d),
nargs_
);}
104
106
CouNumber
operator ()
();
107
109
enum
pos
printPos
()
const
110
{
return
PRE
;}
111
113
std::string
printOp
()
const
114
{
return
"UB_Mul"
;}
115
};
116
117
119
120
inline
CouNumber
exprUBMul::operator ()
() {
121
122
// exprOp:: operator () ();
123
124
register
CouNumber
n = (*(
arglist_
[0])) ();
125
register
CouNumber
N = (*(
arglist_
[1])) ();
126
register
CouNumber
d = (*(
arglist_
[2])) ();
127
register
CouNumber
D = (*(
arglist_
[3])) ();
128
129
if
(d>0)
130
if
(N<0)
return
safeProd
(N,d);
131
else
return
safeProd
(N,D);
132
else
// d <= 0
133
if
(n<0) {
134
CouNumber
nd =
safeProd
(n,d), ND;
135
if
(N>0 && D>0 &&
136
((ND =
safeProd
(N,D)) > nd))
return
ND;
137
else
return
nd;
138
}
139
else
140
if
(D>0)
return
safeProd
(N,D);
141
else
return
safeProd
(n,D);
142
}
143
144
}
145
146
#endif
Couenne::exprUBMul::printPos
enum pos printPos() const
print position (PRE, INSIDE, POST)
Definition:
CouenneExprBMul.hpp:109
COIN_DBL_MAX
const double COIN_DBL_MAX
Couenne::exprOp::nargs_
int nargs_
number of arguments (cardinality of arglist)
Definition:
CouenneExprOp.hpp:36
Couenne::exprOp
general n-ary operator-type expression: requires argument list.
Definition:
CouenneExprOp.hpp:31
Couenne::exprUBMul::clone
expression * clone(Domain *d=NULL) const
cloning method
Definition:
CouenneExprBMul.hpp:102
Couenne::pos
pos
position where the operator should be printed when printing the expression
Definition:
CouenneTypes.hpp:30
Couenne::exprUBMul::operator()
CouNumber operator()()
function for the evaluation of the expression
Definition:
CouenneExprBMul.hpp:120
Couenne::exprOp::clonearglist
expression ** clonearglist(Domain *d=NULL) const
clone argument list (for use with clone method)
Definition:
CouenneExprOp.hpp:97
CouenneConfig.h
Couenne::exprUBMul::printOp
std::string printOp() const
print operator
Definition:
CouenneExprBMul.hpp:113
MUL_ZERO
#define MUL_ZERO
Definition:
CouenneExprBMul.hpp:21
Couenne
general include file for different compilers
Definition:
CouenneAggrProbing.hpp:24
Couenne::PRE
@ PRE
Definition:
CouenneTypes.hpp:30
Couenne::exprLBMul::printOp
std::string printOp() const
print operator
Definition:
CouenneExprBMul.hpp:60
Couenne::exprLBMul
class to compute lower bound of a product based on the bounds of both factors
Definition:
CouenneExprBMul.hpp:40
CoinFinite.hpp
Couenne::CouNumber
double CouNumber
main number type in Couenne
Definition:
CouenneTypes.hpp:100
Couenne::exprLBMul::printPos
enum pos printPos() const
print position (PRE, INSIDE, POST)
Definition:
CouenneExprBMul.hpp:56
Couenne::safeProd
CouNumber safeProd(register CouNumber a, register CouNumber b)
product that avoids NaN's
Definition:
CouenneExprBMul.hpp:25
MUL_INF
#define MUL_INF
Definition:
CouenneExprBMul.hpp:22
Couenne::exprLBMul::exprLBMul
exprLBMul(expression **al, int n)
Constructors, destructor.
Definition:
CouenneExprBMul.hpp:45
Couenne::exprUBMul
class to compute upper bound of a product based on the bounds of both factors
Definition:
CouenneExprBMul.hpp:93
Couenne::exprLBMul::operator()
CouNumber operator()()
function for the evaluation of the expression
Definition:
CouenneExprBMul.hpp:67
Couenne::exprUBMul::exprUBMul
exprUBMul(expression **al, int n)
Constructors, destructor.
Definition:
CouenneExprBMul.hpp:98
CoinHelperFunctions.hpp
CouenneExprOp.hpp
Couenne::exprOp::arglist_
expression ** arglist_
argument list is an array of pointers to other expressions
Definition:
CouenneExprOp.hpp:35
Couenne::exprLBMul::clone
expression * clone(Domain *d=NULL) const
cloning method
Definition:
CouenneExprBMul.hpp:49
Couenne::expression
Expression base class.
Definition:
CouenneExpression.hpp:48
Couenne::Domain
Define a dynamic point+bounds, with a way to save and restore previous points+bounds through a LIFO s...
Definition:
CouenneDomain.hpp:104
Generated by
1.8.17