/home/coin/SVN-release/OS-2.0.1/Couenne/src/expression/operators/exprCos.cpp

Go to the documentation of this file.
00001 /* $Id$ 
00002  *
00003  * Name:    exprCos.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: methods for cosines
00006  *
00007  * (C) Carnegie-Mellon University, 2006-09.
00008  * This file is licensed under the Common Public License (CPL)
00009  */
00010 
00011 #include <math.h>
00012 
00013 #include "exprCos.hpp"
00014 #include "exprSin.hpp"
00015 #include "exprBCos.hpp"
00016 #include "exprOpp.hpp"
00017 #include "exprMul.hpp"
00018 #include "exprClone.hpp"
00019 
00020 
00021 static const CouNumber 
00022   pi  = M_PI,
00023   pi2 = M_PI * 2.,
00024   pih = M_PI / 2.;
00025 
00026 
00027 // return an expression -sin (argument), the derivative of cos (argument)
00028 expression *exprCos::differentiate (int index) {
00029 
00030   return new exprOpp (new exprMul (new exprSin (new exprClone (argument_)),
00031                                    argument_ -> differentiate (index)));
00032 }
00033 
00034 
00035 // compute bounds of sin x given bounds of x 
00036 void exprCos::getBounds (expression *&lb, expression *&ub) {
00037 
00038   expression *xl, *xu;
00039   argument_ -> getBounds (xl, xu);
00040 
00041   lb = new exprLBCos (xl, xu);
00042   ub = new exprUBCos (new exprClone (xl), new exprClone (xu));
00043 }
00044 
00045 // compute value of bounds of cos x given bounds of x 
00046 void exprCos::getBounds (CouNumber &lb, CouNumber &ub) {
00047 
00048   CouNumber l, u;
00049   argument_ -> getBounds (l, u);
00050 
00051   if ((u - l > pi2) ||       // 1) interval spans whole cycle
00052       (floor (l/pi2 - 0.5) < // 2) there is a pi + 2k pi between l and u
00053        floor (u/pi2 - 0.5))) 
00054     lb = -1.;
00055   else lb = CoinMin (cos (l), cos (u));
00056 
00057   if ((u - l > pi2) || // 1) interval spans whole cycle
00058       (floor (l/pi2) < // 2) there is a 3/2 pi + 2k pi between l and u
00059        floor (u/pi2))) 
00060     ub = 1.;
00061   else ub = CoinMax (cos (l), cos (u));
00062 }
00063 
00064 
00066 void exprCos::closestFeasible (expression *varind, expression *vardep,
00067                                CouNumber& left, CouNumber& right) const
00068 {
00069   CouNumber curr = (*varind)();
00070   int period = (int)(curr/pi2);
00071   CouNumber curr_noperiod = curr - pi2*period;
00072   CouNumber inv = acos((*vardep)());
00073 
00074   if (curr_noperiod < inv) {
00075     left = pi2*period - inv;
00076     right = pi2*period + inv;
00077   }
00078   else if (curr_noperiod < pi2-inv) {
00079     left = pi2*period + inv;
00080     right = pi2*(period+1) - inv;
00081   }
00082   else {
00083     left = pi2*(period+1) - inv;
00084     right = pi2*(period+1) + inv;
00085   }
00086 }

Generated on Thu Oct 8 03:02:56 2009 by  doxygen 1.4.7