source: branches/Couenne/Couenne/src/include/operators/exprBCos.h @ 521

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

introducing better bounds for sin/cos. Tool for drawing cuts

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