Couenne  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CouenneExprVar.hpp
Go to the documentation of this file.
1 /* $Id: CouenneExprVar.hpp 911 2012-10-28 19:50:15Z pbelotti $
2  *
3  * Name: exprVar.hpp
4  * Author: Pietro Belotti
5  * Purpose: definition of the class exprVar for variables
6  *
7  * (C) Carnegie-Mellon University, 2006-10.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #ifndef COUENNE_EXPRVAR_HPP
12 #define COUENNE_EXPRVAR_HPP
13 
14 #include <iostream>
15 #include <set>
16 
17 #include "CouenneTypes.hpp"
18 #include "CouenneExpression.hpp"
19 #include "CouenneExprConst.hpp"
20 #include "CouenneDomain.hpp"
21 
22 namespace Ipopt {
23  template <class T> class SmartPtr;
24  class OptionsList;
25  class Journalist;
26 }
27 
28 namespace Bonmin {
29  class BabSetupBase;
30 }
31 
32 namespace Couenne {
33 
36 
37 
39 
44 
45 class exprVar: public expression {
46 
47  protected:
48 
49  int varIndex_;
51 
52  public:
53 
55  virtual inline enum nodeType Type () const
56  {return VAR;}
57 
59  exprVar (int varIndex, Domain *d = NULL):
60  varIndex_ (varIndex),
61  domain_ (d) {}
62 
64  virtual ~exprVar () {}
65 
67  exprVar (const exprVar &e, Domain *d = NULL):
68  varIndex_ (e.varIndex_),
69  domain_ (d) {}
70 
72  virtual inline exprVar *clone (Domain *d = NULL) const
73  {return new exprVar (*this, d);}
74 
76  inline int Index () const
77  {return varIndex_;}
78 
79  // Bounds
80  virtual expression *Lb ();
81  virtual expression *Ub ();
82 
83  // Bounds
84  virtual inline CouNumber &lb () {return domain_ -> lb (varIndex_);}
85  virtual inline CouNumber &ub () {return domain_ -> ub (varIndex_);}
86 
88  virtual void print (std::ostream &out = std::cout,
89  bool = false) const
90  {out << "x_" << varIndex_;}
91 
93  virtual inline CouNumber operator () ()
94  {return domain_ -> x (varIndex_);}
95 
97  virtual inline CouNumber gradientNorm (const double *x)
98  {return 1.;}
99 
101  virtual inline expression *differentiate (int index)
102  {return new exprConst ((index == varIndex_) ? 1. : 0.);}
103 
106  virtual inline int DepList (std::set <int> &deplist,
107  enum dig_type type = ORIG_ONLY) {
108 
109  if (deplist.find (varIndex_) == deplist.end ()) {
110  deplist.insert (varIndex_);
111  return 1;
112  }
113  return 0;
114  }
115 
118  virtual inline void crossBounds () {}
119 
121  virtual inline expression *simplify ()
122  {return NULL;}
123 
125  virtual inline int Linearity ()
126  {return LINEAR;}
127 
129  virtual inline bool isDefinedInteger ()
130  {return false;}
131 
133  virtual inline bool isInteger () {
134 
135  // we definitely want to be very conservative here. A continuous
136  // variable is integer if and only if its current value is really
137  // integer (no round-off) -- see globallib/bearing and term x^(-3.55)
138 
140  return (lb == domain_ -> ub (varIndex_)) && (COUENNE_round (lb) == lb);
141  }
142 
144  virtual void getBounds (expression *&, expression *&);
145 
147  virtual void getBounds (CouNumber &lb, CouNumber &ub);
148 
150  //virtual inline void getBounds (CouNumber &lb, CouNumber &ub) {
151  //lb = domain_ -> lb (varIndex_);
152  //ub = domain_ -> ub (varIndex_);
153  //}
154 
156  virtual void generateCuts (//const OsiSolverInterface &,
157  OsiCuts &, const CouenneCutGenerator *,
158  t_chg_bounds * = NULL, int = -1,
161 
163  virtual void generateCuts (expression *w,
164  //const OsiSolverInterface &si,
165  OsiCuts &cs, const CouenneCutGenerator *cg,
166  t_chg_bounds * = NULL, int = -1,
169 
171  virtual inline enum expr_type code ()
172  {return COU_EXPRVAR;}
173 
175  virtual bool impliedBound (int, CouNumber *, CouNumber *, t_chg_bounds *, enum auxSign = expression::AUX_EQ);
176 
178  virtual inline int rank ()
179  {return 1;}
180 
182  virtual void fillDepSet (std::set <DepNode *, compNode> *, DepGraph *);
183 
185  virtual inline bool isFixed ()
186  {return (fabs (lb () - ub ()) < COUENNE_EPS);}
187 
189  virtual inline void linkDomain (Domain *d)
190  {domain_ = d;}
191 
193  virtual inline Domain *domain ()
194  {return domain_;}
195 
196  // empty for compatibility
197  virtual inline void decreaseMult () {}
198 
200  virtual inline void zeroMult () {}
201 
203  virtual inline void setInteger (bool value) {}
204 
206  virtual enum convexity convexity () const
207  {return AFFINE;}
208 
212  CouenneProblem *p,
213  Bonmin::BabSetupBase *base,
214  JnlstPtr jnlst_);
215 
217  virtual inline enum auxSign sign () const
218  {return expression::AUX_UNDEF;}
219 };
220 
221 }
222 
223 #endif
Cut Generator for linear convexifications.
virtual bool isInteger()
is this variable integer?
virtual CouNumber gradientNorm(const double *x)
return l-2 norm of gradient at given point
virtual void decreaseMult()
virtual bool isFixed()
is this variable fixed?
#define COUENNE_round(x)
virtual void linkDomain(Domain *d)
link this variable to a domain
virtual expression * simplify()
simplify
OsiObject for auxiliary variables $w=f(x)$.
virtual void zeroMult()
Disable variable (empty for compatibility with exprAux)
status of lower/upper bound of a variable, to be checked/modified in bound tightening ...
virtual expression * differentiate(int index)
differentiation
virtual enum expr_type code()
code for comparison
virtual enum convexity convexity() const
either CONVEX, CONCAVE, AFFINE, or NONCONVEX
Domain * domain_
Pointer to a descriptor of the current point/bounds.
Ipopt::SmartPtr< const Ipopt::Journalist > ConstJnlstPtr
virtual void print(std::ostream &out=std::cout, bool=false) const
print
constant-type operator
virtual bool impliedBound(int, CouNumber *, CouNumber *, t_chg_bounds *, enum auxSign=expression::AUX_EQ)
implied bound processing
virtual expression * Lb()
Get lower bound expression.
virtual CouenneObject * properObject(CouenneCutGenerator *c, CouenneProblem *p, Bonmin::BabSetupBase *base, JnlstPtr jnlst_)
return proper object to handle expression associated with this variable (NULL if this is not an auxil...
auxSign
&quot;sign&quot; of the constraint defining an auxiliary.
virtual int rank()
rank of an original variable is always one
virtual CouNumber & ub()
Get/set upper bound value.
exprVar(int varIndex, Domain *d=NULL)
Constructor.
Class for MINLP problems with symbolic information.
#define COUENNE_EPS
virtual expression * Ub()
Get upper bound expression.
virtual Domain * domain()
return pointer to variable domain
virtual bool isDefinedInteger()
is this expression defined as an integer?
convexity
convexity type of an expression
double CouNumber
main number type in Couenne
int Index() const
Get variable index in problem.
nodeType
type of a node in an expression tree
virtual enum nodeType Type() const
Node type.
virtual void crossBounds()
set bounds depending on both branching rules and propagated bounds.
#define COUENNE_INFINITY
Dependence graph.
dig_type
type of digging when filling the dependence list
virtual void setInteger(bool value)
Set this variable as integer (empty for compatibility with exprAux)
virtual void fillDepSet(std::set< DepNode *, compNode > *, DepGraph *)
update dependence set with index of this variable
virtual enum auxSign sign() const
return its sign in the definition constraint
variable-type operator
expr_type
code returned by the method expression::code()
virtual void getBounds(expression *&, expression *&)
Get expressions of lower and upper bound of an expression (if any)
Expression base class.
Ipopt::SmartPtr< Ipopt::Journalist > JnlstPtr
virtual ~exprVar()
destructor
virtual exprVar * clone(Domain *d=NULL) const
Cloning method.
int varIndex_
The index of the variable.
virtual CouNumber operator()()
return the value of the variable
virtual int DepList(std::set< int > &deplist, enum dig_type type=ORIG_ONLY)
fill in the set with all indices of variables appearing in the expression
exprVar(const exprVar &e, Domain *d=NULL)
Copy constructor.
virtual void generateCuts(OsiCuts &, const CouenneCutGenerator *, t_chg_bounds *=NULL, int=-1, CouNumber=-COUENNE_INFINITY, CouNumber=COUENNE_INFINITY)
Get values of lower and upper bound of an expression (if any)
virtual int Linearity()
get a measure of &quot;how linear&quot; the expression is (see CouenneTypes.hpp)
Define a dynamic point+bounds, with a way to save and restore previous points+bounds through a LIFO s...
virtual CouNumber & lb()
Get/set lower bound value.