source: branches/Couenne/Couenne/src/expression/operators/exprBSin.h @ 548

Last change on this file since 548 was 548, checked in by pbelotti, 13 years ago

fixed problem in new convexification cuts for expr{Sin,Cos}. Applying obbt more than once, but obbt disabled due to a bad result in ex2_1_7

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
15
16//  class to compute lower bound of a sine based on the bounds on its
17//  arguments
18
19class exprLBSin: public exprOp {
20
21 public:
22
23  // Constructors, destructor
24  exprLBSin (expression *lb, expression *ub): 
25    exprOp (new expression * [2], 2) {
26    arglist_ [0] = lb;
27    arglist_ [1] = ub;
28  } //< non-leaf expression, with argument list
29
30  // cloning method
31  expression *clone () const
32    {return new exprLBSin  (arglist_ [0] -> clone (), 
33                            arglist_ [1] -> clone ());}
34
35  // function for the evaluation of the expression
36  CouNumber operator () ();
37
38  /// print operator
39  std::string printOp () const
40    {return "LB_Sin";}
41
42  /// print position
43  enum pos printPos () const
44    {return PRE;}
45
46  // output
47  //  void print (std::ostream &out = std::cout)
48  //    {exprOp::print (out, "LB_Sin", PRE);}
49};
50
51
52// compute sum
53
54inline CouNumber exprLBSin::operator () () {
55
56  register CouNumber
57    l = (*(arglist_ [0])) (),
58    u = (*(arglist_ [1])) ();
59
60  CouNumber pi2 = 2 * M_PI;
61 
62  if ((u - l > pi2) ||        // 1) interval spans whole cycle
63      (floor (l/pi2 - 0.75) < // 2) there is a 3/2 pi + 2k pi in between
64       floor (u/pi2 - 0.75))) 
65    return -1.;
66
67  return mymin (sin (l), sin (u));
68}
69
70
71///////////////////////////////////////////////////////////////////////////////
72
73//  class to compute lower bound of a sine based on the bounds on its
74//  arguments
75
76class exprUBSin: public exprOp {
77
78 public:
79
80  // Constructors, destructor
81  exprUBSin (expression *lb, expression *ub): 
82    exprOp (new expression * [2], 2) {
83    arglist_ [0] = lb;
84    arglist_ [1] = ub;
85  } //< non-leaf expression, with argument list
86
87  // cloning method
88  expression *clone () const
89    {return new exprUBSin  (arglist_ [0] -> clone (), 
90                            arglist_ [1] -> clone ());}
91
92  // function for the evaluation of the expression
93  CouNumber operator () ();
94
95  /// print operator
96  std::string printOp () const
97    {return "UB_Sin";}
98
99  /// print position
100  enum pos printPos () const
101    {return PRE;}
102
103  // output
104  //  void print (std::ostream &out = std::cout)
105  //    {exprOp::print (out, "UB_Sin", PRE);}
106};
107
108
109// compute sum
110
111inline CouNumber exprUBSin::operator () () {
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 - 0.25) < // 2) there is a pi/2 + 2k pi in between
121       floor (u/pi2 - 0.25))) 
122    return 1.;
123
124  return mymax (sin (l), sin (u));
125}
126
127#endif
Note: See TracBrowser for help on using the repository browser.