# CouenneExprVar.hpp

Go to the documentation of this file.

    00001 /* $Id: CouenneExprVar.hpp 911 2012-10-28 19:50:15Z 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 "CouenneTypes.hpp"
    00018 #include "CouenneExpression.hpp"
    00019 #include "CouenneExprConst.hpp"
    00020 #include "CouenneDomain.hpp"
    00021
    00022 namespace Ipopt {
    00023   template <class T> class SmartPtr;
    00024   class OptionsList;
    00025   class Journalist;
    00026 }
    00027
    00028 namespace Bonmin {
    00029   class BabSetupBase;
    00030 }
    00031
    00032 namespace Couenne {
    00033
    00034   typedef Ipopt::SmartPtr<Ipopt::Journalist> JnlstPtr;
    00035   typedef Ipopt::SmartPtr<const Ipopt::Journalist> ConstJnlstPtr;
    00036
    00037
    00038 class CouenneCutGenerator;
    00039
    00044
    00045 class exprVar: public expression {
    00046
    00047  protected:
    00048
    00049   int varIndex_;
    00050   Domain *domain_;
    00051
    00052  public:
    00053
    00055   virtual inline enum nodeType Type () const
    00056   {return VAR;}
    00057
    00059   exprVar (int varIndex, Domain *d = NULL):
    00060     varIndex_ (varIndex),
    00061     domain_   (d) {}
    00062
    00064   virtual ~exprVar () {}
    00065
    00067   exprVar (const exprVar &e, Domain *d = NULL):
    00068     varIndex_ (e.varIndex_),
    00069     domain_   (d) {}
    00070
    00072   virtual inline exprVar *clone (Domain *d = NULL) const
    00073   {return new exprVar (*this, d);}
    00074
    00076   inline int Index () const
    00077   {return varIndex_;}
    00078
    00079   // Bounds
    00080   virtual expression *Lb ();
    00081   virtual expression *Ub ();
    00082
    00083   // Bounds
    00084   virtual inline CouNumber &lb () {return domain_ -> lb (varIndex_);}
    00085   virtual inline CouNumber &ub () {return domain_ -> ub (varIndex_);}
    00086
    00088   virtual void print (std::ostream &out = std::cout,
    00089                       bool = false) const
    00090   {out << "x_" << varIndex_;}
    00091
    00093   virtual inline CouNumber operator () ()
    00094   {return domain_ -> x (varIndex_);}
    00095
    00097   virtual inline CouNumber gradientNorm (const double *x)
    00098   {return 1.;}
    00099
    00101   virtual inline expression *differentiate (int index)
    00102   {return new exprConst ((index == varIndex_) ? 1. : 0.);}
    00103
    00106   virtual inline int DepList (std::set <int> &deplist,
    00107                               enum dig_type type = ORIG_ONLY) {
    00108
    00109     if (deplist.find (varIndex_) == deplist.end ()) {
    00110       deplist.insert (varIndex_);
    00111       return 1;
    00112     }
    00113     return 0;
    00114   }
    00115
    00118   virtual inline void crossBounds () {}
    00119
    00121   virtual inline expression *simplify ()
    00122   {return NULL;}
    00123
    00125   virtual inline int Linearity ()
    00126   {return LINEAR;}
    00127
    00129   virtual inline bool isDefinedInteger ()
    00130   {return false;}
    00131
    00133   virtual inline bool isInteger () {
    00134
    00135     // we definitely want to be very conservative here. A continuous
    00136     // variable is integer if and only if its current value is really
    00137     // integer (no round-off) -- see globallib/bearing and term x^(-3.55)
    00138
    00139     CouNumber lb = domain_ -> lb (varIndex_);
    00140     return (lb == domain_ -> ub (varIndex_)) && (COUENNE_round (lb) == lb);
    00141   }
    00142
    00144   virtual void getBounds (expression *&, expression *&);
    00145
    00147   virtual void getBounds (CouNumber &lb, CouNumber &ub);
    00148
    00150   //virtual inline void getBounds (CouNumber &lb, CouNumber &ub) {
    00151   //lb = domain_ -> lb (varIndex_);
    00152   //ub = domain_ -> ub (varIndex_);
    00153   //}
    00154
    00156   virtual void generateCuts (//const OsiSolverInterface &,
    00157                              OsiCuts &, const CouenneCutGenerator *,
    00158                              t_chg_bounds * = NULL, int = -1,
    00159                              CouNumber = -COUENNE_INFINITY,
    00160                              CouNumber =  COUENNE_INFINITY) {}
    00161
    00163   virtual void generateCuts (expression *w,
    00164                              //const OsiSolverInterface &si,
    00165                              OsiCuts &cs, const CouenneCutGenerator *cg,
    00166                              t_chg_bounds * = NULL, int = -1,
    00167                              CouNumber = -COUENNE_INFINITY,
    00168                              CouNumber =  COUENNE_INFINITY);
    00169
    00171   virtual inline enum expr_type code ()
    00172   {return COU_EXPRVAR;}
    00173
    00175   virtual bool impliedBound (int, CouNumber *, CouNumber *, t_chg_bounds *, enum auxSign = expression::AUX_EQ);
    00176
    00178   virtual inline int rank ()
    00179   {return 1;}
    00180
    00182   virtual void fillDepSet (std::set <DepNode *, compNode> *, DepGraph *);
    00183
    00185   virtual inline bool isFixed ()
    00186   {return (fabs (lb () - ub ()) < COUENNE_EPS);}
    00187
    00189   virtual inline void linkDomain (Domain *d)
    00190   {domain_ = d;}
    00191
    00193   virtual inline Domain *domain ()
    00194   {return domain_;}
    00195
    00196   // empty for compatibility
    00197   virtual inline void decreaseMult () {}
    00198
    00200   virtual inline void zeroMult () {}
    00201
    00203   virtual inline void setInteger (bool value) {}
    00204
    00206   virtual enum convexity convexity () const
    00207   {return AFFINE;}
    00208
    00211   virtual CouenneObject *properObject (CouenneCutGenerator *c,
    00212                                        CouenneProblem *p,
    00213                                        Bonmin::BabSetupBase *base,
    00214                                        JnlstPtr jnlst_);
    00215
    00217   virtual inline enum auxSign sign () const
    00218   {return expression::AUX_UNDEF;}
    00219 };
    00220
    00221 }
    00222
    00223 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines