CouenneExpression.hpp

Go to the documentation of this file.
00001 /* $Id: CouenneExpression.hpp 846 2012-05-07 14:10:50Z pbelotti $
00002  *
00003  * Name:    expression.hpp
00004  * Author:  Pietro Belotti
00005  * Purpose: definition of the class expression
00006  *
00007  * (C) Carnegie-Mellon University, 2006-10.
00008  * This file is licensed under the Eclipse Public License (EPL)
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, //const OsiSolverInterface &si, 
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;} // return null rank
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, // distance of current LP
00233                                                     // point to new convexifications
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   // meaning: 
00284   //
00285   // if (*dst > src) && (sign > 0) --> dst down to src
00286   // if (*dst < src) && (sign < 0) --> dst up   to src
00287   //
00288   // that is, sign > 0 means we are tightening an UPPER bound
00289   //          sign < 0                            LOWER
00290 
00291   register double delta = (sign > 0) ? (*dst - src) : (src - *dst);
00292 
00293   if (delta > 0.) {
00294     //printf ("%.12g --> %.12g\n", *dst, src);
00295     *dst = src; // tighten
00296     return (delta > COUENNE_EPS); // avoid returning true when improvement is negligible
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 
00323 inline expression *Simplified (expression *complicated) {
00324 
00325   expression *simpler = complicated -> simplify ();
00326 
00327   if (simpler) {
00328     delete complicated;
00329     return simpler;
00330   } else return complicated;
00331 }
00332 
00333 }
00334 
00335 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 19 Dec 2013 for Couenne by  doxygen 1.6.1