CouenneExpression.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef COUENNE_EXPRESSION_HPP
00012 #define COUENNE_EXPRESSION_HPP
00013
00014 #include <iostream>
00015 #include <set>
00016 #include <vector>
00017
00018 #include "CouennePrecisions.hpp"
00019 #include "CouenneTypes.hpp"
00020
00021 class OsiBranchingInformation;
00022 class OsiSolverInterface;
00023 class OsiCuts;
00024
00025 namespace Couenne {
00026
00027 class CouenneProblem;
00028 class CouenneCutGenerator;
00029 class CouenneObject;
00030
00031 class exprAux;
00032 class exprCopy;
00033 class exprVar;
00034
00035 class DepNode;
00036 class DepGraph;
00037
00038 class Domain;
00039
00040 struct compNode;
00041
00047
00048 class expression {
00049
00050 public:
00051
00055 enum auxSign {AUX_UNDEF=-2, AUX_LEQ=-1, AUX_EQ, AUX_GEQ};
00056
00058 expression () {}
00059
00063 expression (const expression &e, Domain *d = NULL) {}
00064
00066 virtual ~expression () {}
00067
00069 virtual expression *clone (Domain *d = NULL) const
00070 {return NULL;}
00071
00073 virtual inline int Index () const
00074 {return -1;}
00075
00077 virtual inline int nArgs () const
00078 {return 0;}
00079
00081 virtual inline expression **ArgList () const
00082 {return NULL;}
00083
00085 virtual inline void ArgList (expression **al) {}
00086
00088 virtual inline expression *Argument () const
00089 {return NULL;}
00090
00092 virtual inline expression **ArgPtr ()
00093 {return NULL;}
00094
00096 virtual inline enum nodeType Type () const
00097 {return EMPTY;}
00098
00100 virtual inline expression *Image () const
00101 {return NULL;}
00102
00105 virtual void Image (expression *image) {}
00106
00108 virtual inline CouNumber Value () const
00109 {return 0.;}
00110
00114 virtual inline const expression *Original () const
00115 {return this;}
00116
00118 virtual void print (std::ostream &s = std::cout,
00119 bool = false) const
00120 {s << '?';}
00121
00123 virtual CouNumber operator () () = 0;
00124
00126 virtual inline CouNumber gradientNorm (const double *x)
00127 {return 0.;}
00128
00130 virtual expression *differentiate (int);
00131
00134 virtual int dependsOn (int *ind, int n, enum dig_type type = STOP_AT_AUX);
00135
00137 inline int dependsOn (int singleton, enum dig_type type = STOP_AT_AUX)
00138 {return dependsOn (&singleton, 1, type);}
00139
00143 virtual inline int DepList (std::set <int> &deplist,
00144 enum dig_type type = ORIG_ONLY)
00145 {return 0;}
00146
00148 virtual inline expression *simplify ()
00149 {return NULL;}
00150
00152 virtual inline int Linearity ()
00153 {return NONLINEAR;}
00154
00156 virtual inline bool isDefinedInteger ()
00157 {return isInteger ();}
00158
00160 virtual inline bool isInteger ()
00161 {return false;}
00162
00164 virtual void getBounds (expression *&, expression *&);
00165
00167 virtual void getBounds (CouNumber &, CouNumber &);
00168
00181 virtual inline exprAux *standardize (CouenneProblem *p, bool addAux = true)
00182 {return NULL;}
00183
00185 virtual void generateCuts (expression *w,
00186 OsiCuts &cs, const CouenneCutGenerator *cg,
00187 t_chg_bounds *chg = NULL, int wind = -1,
00188 CouNumber lb = -COUENNE_INFINITY,
00189 CouNumber ub = COUENNE_INFINITY) {}
00190
00193 virtual enum expr_type code ()
00194 {return COU_EXPRESSION;}
00195
00197 virtual enum convexity convexity () const
00198 {return NONCONVEX;}
00199
00201 virtual int compare (expression &);
00202
00204 virtual int compare (exprCopy &);
00205
00209 virtual int rank ()
00210 {return -1;}
00211
00218 virtual bool impliedBound (int, CouNumber *, CouNumber *, t_chg_bounds *, enum auxSign = expression::AUX_EQ)
00219 {return false;}
00220
00222 virtual inline int Multiplicity ()
00223 {return 1;}
00224
00228 virtual CouNumber selectBranch (const CouenneObject *obj,
00229 const OsiBranchingInformation *info,
00230 expression * &var,
00231 double * &brpts,
00232 double * &brDist,
00233
00234 int &way)
00235 {var = NULL; return 0.;}
00236
00238 virtual void replace (exprVar *, exprVar *) {}
00239
00242 virtual void fillDepSet (std::set <DepNode *, compNode> *, DepGraph *) {}
00243
00245 virtual void linkDomain (Domain *d) {}
00246
00248 virtual void realign (const CouenneProblem *p) {}
00249
00251 virtual bool isBijective() const
00252 {return false;}
00253
00255 virtual CouNumber inverse (expression *vardep) const
00256 {return -COUENNE_INFINITY;}
00257
00259 virtual void closestFeasible (expression *varind, expression *vardep,
00260 CouNumber& left, CouNumber& right) const;
00261
00264 virtual bool isCuttable (CouenneProblem *problem, int index) const
00265 {return true;}
00266
00268 virtual bool isaCopy () const
00269 {return false;}
00270
00272 virtual expression *Copy () const
00273 {return NULL;}
00274 };
00275
00276
00279 inline bool updateBound (register int sign,
00280 register CouNumber *dst,
00281 register CouNumber src) {
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 register double delta = (sign > 0) ? (*dst - src) : (src - *dst);
00292
00293 if (delta > 0.) {
00294
00295 *dst = src;
00296 return (delta > COUENNE_EPS);
00297 }
00298
00299 return false;
00300 }
00301
00302
00304 inline int compareExpr (const void *e0, const void *e1)
00305 {return ((*(expression **) e0) -> compare (**(expression **)e1));}
00306
00307
00309 inline bool isInteger (CouNumber x)
00310 {return (fabs (COUENNE_round (x) - x) < COUENNE_EPS_INT);}
00311
00312
00315 inline expression *getOriginal (expression *e) {
00316
00317 if (e -> isaCopy ()) return getOriginal (e -> Copy ());
00318 else return e;
00319 }
00320
00321 }
00322
00323 #endif