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

Go to the documentation of this file.
00001 /* $Id: exprOpp.cpp 154 2009-06-16 18:52:53Z 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-09.
00008  * This file is licensed under the Common Public License (CPL)
00009  */
00010 
00011 #include "exprOpp.hpp"
00012 #include "exprConst.hpp"
00013 
00014 
00015 // find bounds of -x given bounds on x
00016 void exprOpp::getBounds (expression *&lb, expression *&ub) {
00017 
00018   expression *lba, *uba;
00019   argument_ -> getBounds (lba, uba);
00020 
00021   lb = new exprOpp (uba);
00022   ub = new exprOpp (lba);
00023 }
00024 
00025 
00026 // find bounds of -x given bounds on x
00027 void exprOpp::getBounds (CouNumber &lb, CouNumber &ub) {
00028 
00029   CouNumber lba, uba;
00030   argument_ -> getBounds (lba, uba);
00031 
00032   lb = -uba;
00033   ub = -lba;
00034 }
00035 
00036 
00037 // differentiation
00038 inline expression *exprOpp::differentiate (int index) 
00039 {return new exprOpp (argument_ -> differentiate (index));}
00040 
00041 
00044 bool exprOpp::impliedBound (int wind, CouNumber *l, CouNumber *u, t_chg_bounds *chg) {
00045 
00046   int ind = argument_ -> Index ();
00047 
00048   bool 
00049     res    = false, 
00050     argInt = argument_ -> isInteger ();
00051 
00052   if (updateBound (-1, l + ind, argInt ? ceil  (- u [wind] - COUENNE_EPS) : - u [wind])) {
00053     res = true; 
00054     chg [ind].setLower(t_chg_bounds::CHANGED);
00055   }
00056 
00057   if (updateBound ( 1, u + ind, argInt ? floor (- l [wind] + COUENNE_EPS) : - l [wind])) {
00058     res = true; 
00059     chg [ind].setUpper(t_chg_bounds::CHANGED);
00060   }
00061 
00062   return res;
00063 }
00064 
00065 
00067 
00068 expression *exprOpp::simplify () {
00069 
00070   exprUnary::simplify (); // simplify what's inside first
00071 
00072   // check if this is a -(-f(x))
00073   if (argument_ -> code () == COU_EXPROPP) {
00074     expression *ret = argument_ -> Argument () -> clone ();
00075     delete argument_;
00076     return ret;
00077   }
00078 
00079   // check if this is a -(const)
00080   if (argument_ -> Type () == CONST) {
00081     expression *ret = new exprConst (- argument_ -> Value ());
00082     delete argument_;
00083     return ret;
00084   }
00085 
00086   return NULL;
00087 }
00088 
00089 // print 
00090 void exprOpp::print (std::ostream &out, 
00091                        bool descend) const {
00092 
00093   //if (printPos () == PRE)  out << printOp ();
00094   out << "(-"; 
00095   argument_ -> print (out, descend); 
00096   out << ")";
00097   //if (printPos () == POST) out << printOp ();
00098 }

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