Couenne 0.5.8
Loading...
Searching...
No Matches
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"
16
17#include <math.h>
18#ifndef M_PI
19# define M_PI 3.14159265358979323846
20#endif
21
22namespace Couenne {
23
26
27class 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
80class 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
T CoinMin(const T x1, const T x2)
T CoinMax(const T x1, const T x2)
#define M_PI
Define a dynamic point+bounds, with a way to save and restore previous points+bounds through a LIFO s...
class to compute lower bound of a cosine based on the bounds of its arguments
std::string printOp() const
print operator
exprLBCos(expression *lb, expression *ub)
Constructors, destructor.
CouNumber operator()()
function for the evaluation of the expression
enum pos printPos() const
print position (PRE, INSIDE, POST)
expression * clone(Domain *d=NULL) const
cloning method
general n-ary operator-type expression: requires argument list.
expression ** arglist_
argument list is an array of pointers to other expressions
class to compute lower bound of a cosine based on the bounds of its arguments
enum pos printPos() const
print position (PRE, INSIDE, POST)
CouNumber operator()()
function for the evaluation of the expression
exprUBCos(expression *lb, expression *ub)
Constructors, destructor.
expression * clone(Domain *d=NULL) const
cloning method
std::string printOp() const
print operator
Expression base class.
general include file for different compilers
pos
position where the operator should be printed when printing the expression
CouExpr & cos(CouExpr &e)
double CouNumber
main number type in Couenne