exprCos.cpp
Go to the documentation of this file.
1 /* $Id: exprCos.cpp 748 2011-07-28 16:13:32Z pbelotti $
2  *
3  * Name: exprCos.cpp
4  * Author: Pietro Belotti
5  * Purpose: methods for cosines
6  *
7  * (C) Carnegie-Mellon University, 2006-09.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #include <math.h>
12 
13 #include "CouenneExprCos.hpp"
14 #include "CouenneExprSin.hpp"
15 #include "CouenneExprBCos.hpp"
16 #include "CouenneExprOpp.hpp"
17 #include "CouenneExprMul.hpp"
18 #include "CouenneExprClone.hpp"
19 
20 using namespace Couenne;
21 
22 static const CouNumber
23  pi = M_PI,
24  pi2 = M_PI * 2.,
25  pih = M_PI / 2.;
26 
27 
28 // return an expression -sin (argument), the derivative of cos (argument)
30 
31  return new exprOpp (new exprMul (new exprSin (new exprClone (argument_)),
32  argument_ -> differentiate (index)));
33 }
34 
35 
36 // compute bounds of sin x given bounds of x
38 
39  expression *xl, *xu;
40  argument_ -> getBounds (xl, xu);
41 
42  lb = new exprLBCos (xl, xu);
43  ub = new exprUBCos (new exprClone (xl), new exprClone (xu));
44 }
45 
46 // compute value of bounds of cos x given bounds of x
48 
49  CouNumber l, u;
50  argument_ -> getBounds (l, u);
51 
52  if ((u - l >= pi2) || // 1) interval spans whole cycle
53  (floor (l/pi2 - 0.5) < // 2) there is a pi + 2k pi between l and u
54  floor (u/pi2 - 0.5)))
55  lb = -1.;
56  else lb = CoinMin (cos (l), cos (u));
57 
58  if ((u - l >= pi2) || // 1) interval spans whole cycle
59  (floor (l/pi2) < // 2) there is a 3/2 pi + 2k pi between l and u
60  floor (u/pi2)))
61  ub = 1.;
62  else ub = CoinMax (cos (l), cos (u));
63 }
64 
65 
68  CouNumber& left, CouNumber& right) const
69 {
70  CouNumber curr = (*varind)();
71  int period = (int)(curr/pi2);
72  CouNumber curr_noperiod = curr - pi2*period;
73  CouNumber inv = acos((*vardep)());
74 
75  if (curr_noperiod < inv) {
76  left = pi2*period - inv;
77  right = pi2*period + inv;
78  }
79  else if (curr_noperiod < pi2-inv) {
80  left = pi2*period + inv;
81  right = pi2*(period+1) - inv;
82  }
83  else {
84  left = pi2*(period+1) - inv;
85  right = pi2*(period+1) + inv;
86  }
87 }
#define M_PI
class opposite,
void getBounds(expression *&, expression *&)
Get lower and upper bound of an expression (if any)
Definition: exprCos.cpp:37
expression * argument_
single argument taken by this expression
static const CouNumber pih
Definition: exprSin.cpp:24
CouNumber inv(register CouNumber arg)
the operator itself
virtual void closestFeasible(expression *varind, expression *vardep, CouNumber &left, CouNumber &right) const
closest feasible points in function in both directions
Definition: exprCos.cpp:67
class to compute lower bound of a cosine based on the bounds of its arguments
expression clone (points to another expression)
static int
Definition: OSdtoa.cpp:2173
static const CouNumber pi
Definition: exprSin.cpp:22
double CouNumber
main number type in Couenne
expression * differentiate(int index)
obtain derivative of expression
Definition: exprCos.cpp:29
Expression base class.
CouExpr & cos(CouExpr &e)
class to compute lower bound of a cosine based on the bounds of its arguments
static const CouNumber pi2
Definition: exprSin.cpp:23
class for multiplications,