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

Go to the documentation of this file.
00001 /* $Id: CouenneExprVar.hpp 490 2011-01-14 16:07:12Z pbelotti $
00002  *
00003  * Name:    exprVar.hpp
00004  * Author:  Pietro Belotti
00005  * Purpose: definition of the class exprVar for variables 
00006  *
00007  * (C) Carnegie-Mellon University, 2006-10.
00008  * This file is licensed under the Eclipse Public License (EPL)
00009  */
00010 
00011 #ifndef COUENNE_EXPRVAR_HPP
00012 #define COUENNE_EXPRVAR_HPP
00013 
00014 #include <iostream>
00015 #include <set>
00016 
00017 //#include "CouenneJournalist.hpp"
00018 #include "CouenneTypes.hpp"
00019 #include "CouenneExpression.hpp"
00020 #include "CouenneExprConst.hpp"
00021 #include "CouenneDomain.hpp"
00022 
00023 namespace Ipopt {
00024   template <class T> class SmartPtr;
00025   class OptionsList;
00026   class Journalist;
00027 }
00028 
00029 namespace Bonmin {
00030   class BabSetupBase;
00031 }
00032 
00033 namespace Couenne {
00034 
00035   typedef Ipopt::SmartPtr<Ipopt::Journalist> JnlstPtr;
00036   typedef Ipopt::SmartPtr<const Ipopt::Journalist> ConstJnlstPtr;
00037 
00038 
00039 class CouenneCutGenerator;
00040 
00045 
00046 class exprVar: public expression {
00047 
00048  protected:
00049 
00050   int varIndex_;   
00051   Domain *domain_; 
00052 
00053  public:
00054 
00056   virtual inline enum nodeType Type () const
00057   {return VAR;}
00058 
00060   exprVar (int varIndex, Domain *d = NULL):
00061     varIndex_ (varIndex),
00062     domain_   (d) {}
00063 
00065   virtual ~exprVar () {}
00066 
00068   exprVar (const exprVar &e, Domain *d = NULL):
00069     varIndex_ (e.varIndex_),
00070     domain_   (d) {}
00071 
00073   virtual inline exprVar *clone (Domain *d = NULL) const
00074   {return new exprVar (*this, d);}
00075 
00077   inline int Index () const
00078   {return varIndex_;}
00079 
00080   // Bounds
00081   virtual expression *Lb (); 
00082   virtual expression *Ub (); 
00083 
00084   // Bounds
00085   virtual inline CouNumber &lb () {return domain_ -> lb (varIndex_);} 
00086   virtual inline CouNumber &ub () {return domain_ -> ub (varIndex_);} 
00087 
00089   virtual void print (std::ostream &out = std::cout,
00090                       bool = false) const
00091   {out << "x_" << varIndex_;}
00092 
00094   virtual inline CouNumber operator () () 
00095   {return domain_ -> x (varIndex_);}
00096 
00098   virtual inline CouNumber gradientNorm (const double *x)
00099   {return 1.;}
00100 
00102   virtual inline expression *differentiate (int index) 
00103   {return new exprConst ((index == varIndex_) ? 1. : 0.);}
00104 
00107   virtual inline int DepList (std::set <int> &deplist, 
00108                               enum dig_type type = ORIG_ONLY) {
00109 
00110     if (deplist.find (varIndex_) == deplist.end ()) {
00111       deplist.insert (varIndex_); 
00112       return 1;
00113     }
00114     return 0;
00115   }
00116 
00119   virtual inline void crossBounds () {}
00120 
00122   virtual inline expression *simplify () 
00123   {return NULL;}
00124 
00126   virtual inline int Linearity ()
00127   {return LINEAR;}
00128 
00130   virtual inline bool isDefinedInteger ()
00131   {return false;}
00132 
00134   virtual inline bool isInteger () {
00135 
00136     // we definitely want to be very conservative here. A continuous
00137     // variable is integer if and only if its current value is really
00138     // integer (no round-off) -- see globallib/bearing and term x^(-3.55)
00139 
00140     CouNumber lb = domain_ -> lb (varIndex_);
00141     return (lb == domain_ -> ub (varIndex_)) && (COUENNE_round (lb) == lb);
00142   }
00143 
00145   virtual void getBounds (expression *&, expression *&);
00146 
00148   virtual void getBounds (CouNumber &lb, CouNumber &ub);
00149 
00151   //virtual inline void getBounds (CouNumber &lb, CouNumber &ub) {
00152   //lb = domain_ -> lb (varIndex_);
00153   //ub = domain_ -> ub (varIndex_);
00154   //}
00155 
00157   virtual void generateCuts (//const OsiSolverInterface &, 
00158                              OsiCuts &, const CouenneCutGenerator *, 
00159                              t_chg_bounds * = NULL, int = -1, 
00160                              CouNumber = -COUENNE_INFINITY, 
00161                              CouNumber =  COUENNE_INFINITY) {}
00162 
00164   virtual void generateCuts (expression *w, 
00165                              //const OsiSolverInterface &si, 
00166                              OsiCuts &cs, const CouenneCutGenerator *cg, 
00167                              t_chg_bounds * = NULL, int = -1, 
00168                              CouNumber = -COUENNE_INFINITY, 
00169                              CouNumber =  COUENNE_INFINITY);
00170 
00172   virtual inline enum expr_type code () 
00173   {return COU_EXPRVAR;}
00174 
00176   virtual bool impliedBound (int, CouNumber *, CouNumber *, t_chg_bounds *, enum auxSign = expression::AUX_EQ);
00177 
00179   virtual inline int rank () 
00180   {return 1;}
00181 
00183   virtual void fillDepSet (std::set <DepNode *, compNode> *, DepGraph *);
00184 
00186   virtual inline bool isFixed ()
00187   {return (fabs (lb () - ub ()) < COUENNE_EPS);}
00188 
00190   virtual inline void linkDomain (Domain *d)
00191   {domain_ = d;}
00192 
00194   virtual inline Domain *domain ()
00195   {return domain_;}
00196 
00197   // empty for compatibility
00198   virtual inline void decreaseMult () {}
00199 
00201   virtual inline void zeroMult () {}
00202 
00204   virtual inline void setInteger (bool value) {}
00205 
00207   virtual enum convexity convexity () const
00208   {return AFFINE;}
00209 
00212   virtual CouenneObject *properObject (CouenneCutGenerator *c, 
00213                                        CouenneProblem *p, 
00214                                        Bonmin::BabSetupBase *base, 
00215                                        JnlstPtr jnlst_);
00216 
00218   virtual inline enum auxSign sign () const 
00219   {return expression::AUX_UNDEF;}
00220 };
00221 
00222 }
00223 
00224 #endif

Generated on Thu Nov 10 03:05:44 2011 by  doxygen 1.4.7