/home/coin/SVN-release/OS-2.1.1/Couenne/src/expression/expression.hpp

Go to the documentation of this file.
00001 /* $Id: expression.hpp 217 2009-07-08 17:02:07Z pbelotti $
00002  *
00003  * Name:    expression.hpp
00004  * Author:  Pietro Belotti
00005  * Purpose: definition of the class expression
00006  *
00007  * (C) Carnegie-Mellon University, 2006-08-09.
00008  * This file is licensed under the Common Public License (CPL)
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 class CouenneProblem;
00026 class CouenneCutGenerator;
00027 class CouenneObject;
00028 
00029 class exprAux;
00030 class exprCopy;
00031 class exprVar;
00032 
00033 class DepNode;
00034 class DepGraph;
00035 
00036 class Domain;
00037 
00038 struct compNode;
00039 
00045 
00046 class expression {
00047 
00048  public:
00049 
00051   expression () {}
00052 
00056   expression (const expression &e, Domain *d = NULL) {}
00057 
00059   virtual ~expression () {}
00060 
00062   virtual expression *clone (Domain *d = NULL) const 
00063   {return NULL;}
00064 
00066   virtual inline int Index () const
00067   {return -1;}
00068 
00070   virtual inline int nArgs () const
00071   {return 0;}
00072 
00074   virtual inline expression **ArgList () const
00075   {return NULL;}
00076 
00078   virtual inline void ArgList (expression **al) {}
00079 
00081   virtual inline expression *Argument () const
00082   {return NULL;}
00083 
00085   virtual inline expression **ArgPtr ()
00086   {return NULL;}
00087 
00089   virtual inline enum nodeType Type () const
00090   {return EMPTY;}
00091 
00093   virtual inline expression *Image () const
00094   {return NULL;}
00095 
00098   virtual void Image (expression *image) {}
00099 
00101   virtual inline CouNumber Value () const 
00102   {return 0.;}
00103 
00107   virtual inline const expression *Original () const 
00108   {return this;}
00109 
00111   virtual void print (std::ostream &s  = std::cout,   
00112                       bool             = false) const 
00113   {s << '?';}
00114 
00116   virtual CouNumber operator () () = 0;
00117 
00119   virtual inline CouNumber gradientNorm (const double *x)
00120   {return 0.;}
00121 
00123   virtual expression *differentiate (int);
00124 
00127   virtual int dependsOn (int *ind, int n, enum dig_type type = STOP_AT_AUX);
00128 
00130   inline int dependsOn (int singleton, enum dig_type type = STOP_AT_AUX)
00131   {return dependsOn (&singleton, 1, type);}
00132 
00136   virtual inline int DepList (std::set <int> &deplist, 
00137                               enum dig_type   type = ORIG_ONLY)
00138   {return 0;}
00139 
00141   virtual inline expression *simplify () 
00142   {return NULL;}
00143 
00145   virtual inline int Linearity ()
00146   {return NONLINEAR;}
00147 
00149   virtual inline bool isDefinedInteger ()
00150   {return isInteger ();}
00151 
00153   virtual inline bool isInteger ()
00154   {return false;}
00155 
00157   virtual void getBounds (expression *&, expression *&);
00158 
00160   virtual void getBounds (CouNumber &, CouNumber &);
00161 
00174   virtual inline exprAux *standardize (CouenneProblem *p, bool addAux = true) 
00175   {return NULL;}
00176 
00178   virtual void generateCuts (expression *w, //const OsiSolverInterface &si, 
00179                              OsiCuts &cs, const CouenneCutGenerator *cg,
00180                              t_chg_bounds *chg = NULL, int wind = -1, 
00181                              CouNumber lb = -COUENNE_INFINITY, 
00182                              CouNumber ub =  COUENNE_INFINITY) {}
00183 
00186   virtual enum expr_type code () 
00187   {return COU_EXPRESSION;}
00188 
00190   virtual enum convexity convexity () const
00191   {return NONCONVEX;}
00192 
00194   virtual int compare (expression &);
00195 
00197   virtual int compare (exprCopy   &);
00198 
00202   virtual int rank ()
00203   {return -1;} // return null rank
00204 
00211   virtual bool impliedBound (int, CouNumber *, CouNumber *, t_chg_bounds *)
00212   {return false;}
00213 
00215   virtual inline int Multiplicity ()
00216   {return 1;}
00217 
00221   virtual CouNumber selectBranch (const CouenneObject *obj, 
00222                                   const OsiBranchingInformation *info,
00223                                   expression * &var, 
00224                                   double * &brpts, 
00225                                   double * &brDist, // distance of current LP
00226                                                     // point to new convexifications
00227                                   int &way)
00228   {var = NULL; return 0.;}
00229 
00231   virtual void replace (exprVar *, exprVar *) {}
00232 
00235   virtual void fillDepSet (std::set <DepNode *, compNode> *, DepGraph *) {}
00236 
00238   virtual void linkDomain (Domain *d) {}
00239 
00241   virtual void realign (const CouenneProblem *p) {}
00242 
00244   virtual bool isBijective() const 
00245   {return false;}
00246 
00248   virtual CouNumber inverse (expression *vardep) const
00249   {return -COUENNE_INFINITY;}
00250 
00252   virtual void closestFeasible (expression *varind, expression *vardep,
00253                                 CouNumber& left, CouNumber& right) const;
00254 
00257   virtual bool isCuttable (CouenneProblem *problem, int index) const
00258   {return true;}
00259 
00261   virtual bool isaCopy () const
00262   {return false;}
00263 
00265   virtual expression *Copy () const
00266   {return NULL;}
00267 };
00268 
00269 
00272 inline bool updateBound (register int sign, 
00273                          register CouNumber *dst, 
00274                          register CouNumber src) {
00275 
00276   // meaning: 
00277   //
00278   // if (*dst > src) && (sign > 0) --> dst down to src
00279   // if (*dst < src) && (sign < 0) --> dst up   to src
00280   //
00281   // that is, sign > 0 means we are tightening an UPPER bound
00282   //          sign < 0                            LOWER
00283 
00284   register double delta = (sign > 0) ? (*dst - src) : (src - *dst);
00285 
00286   if (delta > 0.) {
00287     //printf ("%.12g --> %.12g\n", *dst, src);
00288     *dst = src; // tighten
00289     return (delta > COUENNE_EPS); // avoid returning true when improvement is negligible
00290   }
00291 
00292   return false;
00293 }
00294 
00295 
00297 inline int compareExpr (const void *e0, const void *e1)
00298 {return ((*(expression **) e0) -> compare (**(expression **)e1));}
00299 
00300 
00302 inline bool isInteger (CouNumber x)
00303 {return (fabs (COUENNE_round (x) - x) < COUENNE_EPS_INT);}
00304 
00305 
00308 inline expression *getOriginal (expression *e) {
00309 
00310   if (e -> isaCopy ()) return getOriginal (e -> Copy ());
00311   else return e;
00312 }
00313 
00314 #endif

Generated on Mon May 3 03:05:20 2010 by  doxygen 1.4.7