00001
00002
00003
00004
00005
00006
00007
00008
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
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
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
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 ();
00079
00080 if (subst)
00081 return subst;
00082
00083
00084 if (argument_ -> code () == COU_EXPROPP) {
00085
00086 expression *ret = argument_ -> Argument () -> clone ();
00087 delete argument_;
00088 argument_ = NULL;
00089 return ret;
00090 }
00091
00092
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
00104 void exprOpp::print (std::ostream &out,
00105 bool descend) const {
00106
00107
00108 out << "(-";
00109 argument_ -> print (out, descend);
00110 out << ")";
00111
00112 }