source: branches/Couenne/Couenne/src/expression/operators/exprBSin.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:    exprBSin.h
3 * Author:  Pietro Belotti
4 * Purpose: definition of operators to compute lower/upper bounds of sines
5 *
6 * (C) Pietro Belotti 2006. This file is licensed under the Common Public License (CPL)
7 */
8
9#ifndef COUENNE_EXPRBSIN_H
10#define COUENNE_EXPRBSIN_H
11
12#include <exprOp.h>
13#include <math.h>
14#ifndef M_PI
15# define M_PI 3.14159265358979323846
16#endif
17
18//  class to compute lower bound of a sine based on the bounds on its
19//  arguments
20
21class exprLBSin: public exprOp {
22
23 public:
24
25  // Constructors, destructor
26  exprLBSin (expression *lb, expression *ub): 
27    exprOp (new expression * [2], 2) {
28    arglist_ [0] = lb;
29    arglist_ [1] = ub;
30  } //< non-leaf expression, with argument list
31
32  // cloning method
33  expression *clone () const
34    {return new exprLBSin  (arglist_ [0] -> clone (), 
35                            arglist_ [1] -> clone ());}
36
37  // function for the evaluation of the expression
38  CouNumber operator () ();
39
40  /// print operator
41  std::string printOp () const
42    {return "LB_Sin";}
43
44  /// print position
45  enum pos printPos () const
46    {return PRE;}
47
48  // output
49  //  void print (std::ostream &out = std::cout)
50  //    {exprOp::print (out, "LB_Sin", PRE);}
51};
52
53
54// compute sum
55
56inline CouNumber exprLBSin::operator () () {
57
58  register CouNumber
59    l = (*(arglist_ [0])) (),
60    u = (*(arglist_ [1])) ();
61
62  CouNumber pi2 = 2 * M_PI;
63 
64  if ((u - l > pi2) ||        // 1) interval spans whole cycle
65      (floor (l/pi2 - 0.75) < // 2) there is a 3/2 pi + 2k pi in between
66       floor (u/pi2 - 0.75))) 
67    return -1.;
68
69  return mymin (sin (l), sin (u));
70}
71
72
73///////////////////////////////////////////////////////////////////////////////
74
75//  class to compute lower bound of a sine based on the bounds on its
76//  arguments
77
78class exprUBSin: public exprOp {
79
80 public:
81
82  // Constructors, destructor
83  exprUBSin (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 exprUBSin  (arglist_ [0] -> clone (), 
92                            arglist_ [1] -> clone ());}
93
94  // function for the evaluation of the expression
95  CouNumber operator () ();
96
97  /// print operator
98  std::string printOp () const
99    {return "UB_Sin";}
100
101  /// print position
102  enum pos printPos () const
103    {return PRE;}
104
105  // output
106  //  void print (std::ostream &out = std::cout)
107  //    {exprOp::print (out, "UB_Sin", PRE);}
108};
109
110
111// compute sum
112
113inline CouNumber exprUBSin::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 - 0.25) < // 2) there is a pi/2 + 2k pi in between
123       floor (u/pi2 - 0.25))) 
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.