/home/coin/SVN-release/OS-2.4.1/Couenne/src/expression/operators/exprOpp.cpp

Go to the documentation of this file.
00001 /* $Id: exprOpp.cpp 614 2011-06-08 14:20:39Z pbelotti $
00002  *
00003  * Name:    exprOpp.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: definition of the opposite -f(x) of a function
00006  *
00007  * (C) Carnegie-Mellon University, 2006-10.
00008  * This file is licensed under the Eclipse Public License (EPL)
00009  */
00010 
00011 #include "CouenneExprOpp.hpp"
00012 #include "CouenneExprConst.hpp"
00013 #include "CouenneConfig.h"
00014 #include "CoinHelperFunctions.hpp"
00015 #include "CoinFinite.hpp"
00016 
00017 using namespace Couenne;
00018 
00019 // find bounds of -x given bounds on x
00020 void exprOpp::getBounds (expression *&lb, expression *&ub) {
00021 
00022   expression *lba, *uba;
00023   argument_ -> getBounds (lba, uba);
00024 
00025   lb = new exprOpp (uba);
00026   ub = new exprOpp (lba);
00027 }
00028 
00029 
00030 // find bounds of -x given bounds on x
00031 void exprOpp::getBounds (CouNumber &lb, CouNumber &ub) {
00032 
00033   CouNumber lba, uba;
00034   argument_ -> getBounds (lba, uba);
00035 
00036   lb = -uba;
00037   ub = -lba;
00038 }
00039 
00040 
00041 // differentiation
00042 inline expression *exprOpp::differentiate (int index) 
00043 {return new exprOpp (argument_ -> differentiate (index));}
00044 
00045 
00048 bool exprOpp::impliedBound (int wind, CouNumber *l, CouNumber *u, t_chg_bounds *chg, enum auxSign sign) {
00049 
00050   int ind = argument_ -> Index ();
00051 
00052   bool 
00053     res    = false, 
00054     argInt = argument_ -> isInteger ();
00055 
00056   CouNumber 
00057     wl = sign == expression::AUX_GEQ ? -COIN_DBL_MAX : l [wind],
00058     wu = sign == expression::AUX_LEQ ?  COIN_DBL_MAX : u [wind];
00059 
00060   if (updateBound (-1, l + ind, argInt ? ceil  (- wu - COUENNE_EPS) : - wu)) {
00061     res = true; 
00062     chg [ind].setLower(t_chg_bounds::CHANGED);
00063   }
00064 
00065   if (updateBound ( 1, u + ind, argInt ? floor (- wl + COUENNE_EPS) : - wl)) {
00066     res = true; 
00067     chg [ind].setUpper(t_chg_bounds::CHANGED);
00068   }
00069 
00070   return res;
00071 }
00072 
00073 
00075 
00076 expression *exprOpp::simplify () {
00077 
00078   expression *subst = exprUnary::simplify (); // simplify what's inside first
00079 
00080   if (subst)
00081     return subst;
00082 
00083   // check if this is a -(-f(x))
00084   if (argument_ -> code () == COU_EXPROPP) {
00085     // leak. don't clone, use exprClone
00086     expression *ret = argument_ -> Argument () -> clone ();
00087     delete argument_;
00088     argument_ = NULL;
00089     return ret;
00090   }
00091 
00092   // check if this is a -(const)
00093   if (argument_ -> Type () == CONST) {
00094     expression *ret = new exprConst (- argument_ -> Value ());
00095     delete argument_;
00096     argument_ = NULL;
00097     return ret;
00098   }
00099 
00100   return NULL;
00101 }
00102 
00103 // print 
00104 void exprOpp::print (std::ostream &out, 
00105                        bool descend) const {
00106 
00107   //if (printPos () == PRE)  out << printOp ();
00108   out << "(-"; 
00109   argument_ -> print (out, descend); 
00110   out << ")";
00111   //if (printPos () == POST) out << printOp ();
00112 }

Generated on Thu Nov 10 03:05:44 2011 by  doxygen 1.4.7