source: branches/Couenne/Couenne/src/expression/operators/exprBCos.h @ 582

Last change on this file since 582 was 582, checked in by andreasw, 12 years ago

minor changes to make code compile with MSVC++; reran autotools

File size: 2.8 KB
Line 
1/*
2 * Name:    exprBCos.h
3 * Author:  Pietro Belotti
4 * Purpose: definition of operators to compute lower/upper bounds of cosines
5 *
6 * (C) Pietro Belotti 2006. This file is licensed under the Common Public License (CPL)
7 */
8
9#ifndef COUENNE_EXPRBCOS_H
10#define COUENNE_EXPRBCOS_H
11
12#include <exprOp.h>
13#include <math.h>
14#ifndef M_PI
15# define M_PI 3.14159265358979323846
16#endif
17
18
19//  class to compute lower bound of a cosine based on the bounds of
20//  its arguments
21
22class exprLBCos: public exprOp {
23
24 public:
25
26  // Constructors, destructor
27  exprLBCos (expression *lb, expression *ub): 
28    exprOp (new expression * [2], 2) {
29    arglist_ [0] = lb;
30    arglist_ [1] = ub;
31  } //< non-leaf expression, with argument list
32
33  // cloning method
34  expression *clone () const
35    {return new exprLBCos (arglist_ [0] -> clone (), 
36                           arglist_ [1] -> clone ());}
37
38  // function for the evaluation of the expression
39  CouNumber operator () ();
40
41  /// print position (PRE, INSIDE, POST)
42  enum pos printPos () const
43    {return PRE;}
44
45  /// print operator
46  std::string printOp () 
47    {return "LB_Cos";}
48
49  // output
50  //  void print (std::ostream &out = std::cout)
51  //  {exprOp::print (out, "LB_Cos", PRE);}
52};
53
54
55// compute sum
56
57inline CouNumber exprLBCos::operator () () {
58
59  register CouNumber
60    l = (*(arglist_ [0])) (),
61    u = (*(arglist_ [1])) ();
62
63  CouNumber pi2 = 2 * M_PI;
64 
65  if ((u - l > pi2) ||       // 1) interval spans whole cycle
66      (floor (l/pi2 - 0.5) < // 2) there is a pi + 2k pi in between
67       floor (u/pi2 - 0.5))) 
68    return -1;
69
70  return mymin (sin (l), sin (u));
71}
72
73///////////////////////////////////////////////////////////////////////////////
74
75//  class to compute lower bound of a cosine based on the bounds of
76//  its arguments
77
78class exprUBCos: public exprOp {
79
80 public:
81
82  // Constructors, destructor
83  exprUBCos (expression *lb, expression *ub): 
84    exprOp (new expression * [2], 2) {
85    arglist_ [0] = lb;
86    arglist_ [1] = ub;
87  } //< non-leaf expression, with argument list
88
89  // cloning method
90  expression *clone () const
91    {return new exprUBCos (arglist_ [0] -> clone (), 
92                           arglist_ [1] -> clone ());}
93
94  // function for the evaluation of the expression
95  CouNumber operator () ();
96
97  /// print position (PRE, INSIDE, POST)
98  virtual enum pos printPos () 
99    {return PRE;}
100
101  /// print operator
102  virtual const std::string printOp () 
103    {return "UB_Cos";}
104
105  // output
106  //  void print (std::ostream &out = std::cout)
107  //  {exprOp::print (out, "UB_Cos", PRE);}
108};
109
110
111// compute sum
112
113inline CouNumber exprUBCos::operator () () {
114
115  register CouNumber
116    l = (*(arglist_ [0])) (),
117    u = (*(arglist_ [1])) ();
118
119  CouNumber pi2 = 2 * M_PI;
120
121  if ((u - l > pi2) || // 1) interval spans whole cycle
122      (floor (l/pi2) < // 2) there is a 3/2 pi + 2k pi in between
123       floor (u/pi2))) 
124    return 1;
125
126  return mymax (sin (l), sin (u));
127}
128
129#endif
Note: See TracBrowser for help on using the repository browser.