Couenne  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CouenneExprBCos.hpp
Go to the documentation of this file.
1 /* $Id: CouenneExprBCos.hpp 748 2011-07-28 16:13:32Z pbelotti $ */
2 /*
3  * Name: exprBCos.hpp
4  * Author: Pietro Belotti
5  * Purpose: definition of operators to compute lower/upper bounds of cosines
6  *
7  * (C) Carnegie-Mellon University, 2006.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #ifndef COUENNE_EXPRBCOS_HPP
12 #define COUENNE_EXPRBCOS_HPP
13 
14 #include "CouenneExprOp.hpp"
15 #include "CoinHelperFunctions.hpp"
16 
17 #include <math.h>
18 #ifndef M_PI
19 # define M_PI 3.14159265358979323846
20 #endif
21 
22 namespace Couenne {
23 
26 
27 class exprLBCos: public exprOp {
28 
29  public:
30 
33  exprOp (new expression * [2], 2) {
34  arglist_ [0] = lb;
35  arglist_ [1] = ub;
36  } //< non-leaf expression, with argument list
37 
39  expression *clone (Domain *d = NULL) const
40  {return new exprLBCos (arglist_ [0] -> clone (d),
41  arglist_ [1] -> clone (d));}
42 
45 
47  enum pos printPos () const
48  {return PRE;}
49 
51  std::string printOp () const
52  {return "LB_Cos";}
53 };
54 
55 
57 
59 
60  register CouNumber
61  l = (*(arglist_ [0])) (),
62  u = (*(arglist_ [1])) ();
63 
64  CouNumber pi2 = 2 * M_PI;
65 
66  if ((u - l >= pi2) || // 1) interval spans whole cycle
67  (floor (l/pi2 - 0.5) < // 2) there is a pi + 2k pi between l and u
68  floor (u/pi2 - 0.5)))
69  return -1.;
70 
71  return CoinMin (cos (l), cos (u));
72 }
73 
74 
76 
79 
80 class exprUBCos: public exprOp {
81 
82  public:
83 
86  exprOp (new expression * [2], 2) {
87  arglist_ [0] = lb;
88  arglist_ [1] = ub;
89  } //< non-leaf expression, with argument list
90 
92  expression *clone (Domain *d = NULL) const
93  {return new exprUBCos (arglist_ [0] -> clone (d),
94  arglist_ [1] -> clone (d));}
95 
98 
100  std::string printOp () const
101  {return "UB_Cos";}
102 
104  enum pos printPos () const
105  {return PRE;}
106 };
107 
108 
110 
112 
113  register CouNumber
114  l = (*(arglist_ [0])) (),
115  u = (*(arglist_ [1])) ();
116 
117  CouNumber pi2 = 2 * M_PI;
118 
119  if ((u - l >= pi2) || // 1) interval spans whole cycle
120  (floor (l/pi2) < // 2) there is a 3/2 pi + 2k pi between l and u
121  floor (u/pi2)))
122  return 1.;
123 
124  return CoinMax (cos (l), cos (u));
125 }
126 
127 }
128 
129 #endif
enum pos printPos() const
print position (PRE, INSIDE, POST)
enum pos printPos() const
print position (PRE, INSIDE, POST)
pos
position where the operator should be printed when printing the expression
exprUBCos(expression *lb, expression *ub)
Constructors, destructor.
#define M_PI
expression * clone(Domain *d=NULL) const
cloning method
expression * clone(Domain *d=NULL) const
cloning method
CouNumber operator()()
function for the evaluation of the expression
class to compute lower bound of a cosine based on the bounds of its arguments
exprLBCos(expression *lb, expression *ub)
Constructors, destructor.
expression ** arglist_
argument list is an array of pointers to other expressions
double CouNumber
main number type in Couenne
std::string printOp() const
print operator
CouNumber operator()()
function for the evaluation of the expression
general n-ary operator-type expression: requires argument list.
Expression base class.
CouExpr & cos(CouExpr &e)
class to compute lower bound of a cosine based on the bounds of its arguments
std::string printOp() const
print operator
Define a dynamic point+bounds, with a way to save and restore previous points+bounds through a LIFO s...