source: branches/Couenne/Couenne/src/expression/exprAux.h @ 534

Last change on this file since 534 was 534, checked in by pbelotti, 13 years ago

moved include files to make them doxygenable. Introduced three-way branching, with fixed intervals for now. Added check for small bound interval within all generateCuts()

File size: 4.3 KB
Line 
1/*
2 * Name:    exprAux.h
3 * Author:  Pietro Belotti
4 * Purpose: definition of the auxiliary variable class (used in
5 *          standardization and convexification)
6 *
7 * (C) Pietro Belotti. This file is licensed under the Common Public License (CPL)
8 */
9
10#ifndef COUENNE_EXPRAUX_H
11#define COUENNE_EXPRAUX_H
12
13#include <iostream>
14#include <exprVar.h>
15#include <exprBound.h>
16#include <exprMax.h>
17#include <exprMin.h>
18#include <CouenneTypes.h>
19#include <CglCutGenerator.hpp>
20
21
22/// expression base class
23
24class exprAux: public exprVar {
25
26 protected:
27
28  /// The expression associated with this auxiliary variable
29  expression *image_;
30
31  /// bounds determined by the associated expression's bounds and the
32  /// relative constraint's bound
33  expression *lb_;
34  expression *ub_;
35
36  /// used in rank-based branching variable choice: original variables
37  /// have rank 1; auxiliary w=f(x) has rank r(w) = r(x)+1; finally,
38  /// auxiliary w=f(x1,x2...,xk) has rank r(w) = 1+max{r(xi):i=1..k}.
39  int rank_;
40
41  /// number of appearances of this aux in the formulation. The more
42  /// times it occurs in the formulation, the more implication its
43  /// branching has on other variables
44  int multiplicity_;
45
46 public:
47
48  /// Node type
49  inline enum nodeType Type () 
50    {return AUX;}
51
52  /// Constructor
53  exprAux (expression *, int, int);
54
55  /// Destructor
56  ~exprAux () {
57    delete image_; 
58    delete lb_; 
59    delete ub_;
60  }
61
62  /// copy constructor
63  exprAux (const exprAux &e):
64    exprVar       (e.varIndex_),
65    image_        (e.image_ -> clone ()),
66    //    lb_           (e.lb_    -> clone ()),
67    //    ub_           (e.ub_    -> clone ()),
68    rank_         (e.rank_),
69    multiplicity_ (e.multiplicity_) {
70
71    image_ -> getBounds (lb_, ub_);
72    // getBounds (lb_, ub_);
73
74    lb_ = new exprMax (lb_, new exprLowerBound (varIndex_));
75    ub_ = new exprMin (ub_, new exprUpperBound (varIndex_));
76  }
77
78  /// cloning method
79  virtual exprAux *clone () const
80    {return new exprAux (*this);}
81
82  /// Bound get
83  expression *Lb () {return lb_;}
84  expression *Ub () {return ub_;}
85
86  /// I/O
87  void print (std::ostream &out) const
88    {out << "w_" << varIndex_;}
89
90  /// The expression associated with this auxiliary variable
91  inline expression *Image () const
92    {return image_;}
93
94  /// Null function for evaluating the expression
95  inline CouNumber operator () () 
96    {return (currValue_ = expression::Variable (varIndex_));}
97
98  /// Differentiation
99  inline expression *differentiate (int index) 
100    {return image_ -> differentiate (index);}
101
102  /// Dependence on variable set
103  inline bool dependsOn (int *indices, int num) 
104    {return image_ -> dependsOn (indices, num);}
105
106  /// Get a measure of "how linear" the expression is (see CouenneTypes.h)
107  inline int Linearity ()
108    {return LINEAR;}
109    /*return image_ -> Linearity ();*/
110
111  /// Get lower and upper bound of an expression (if any)
112  inline void getBounds (expression *&lb, expression *&ub) {
113
114    /// this replaces the previous
115    ///
116    ///    image_ -> getBounds (lb0, ub0);
117    ///
118    /// which created large expression trees, now useless since all
119    /// auxiliaries are standardized.
120
121    lb = new exprLowerBound (varIndex_);
122    ub = new exprUpperBound (varIndex_);
123  }
124
125  /// set bounds depending on both branching rules and propagated
126  /// bounds. To be used after standardization
127  inline void crossBounds () {
128
129    expression *l0, *u0;
130
131    image_ -> getBounds (l0, u0);
132    //image_ -> getBounds (lb_, ub_);
133
134    lb_ = new exprMax (lb_, l0);
135    ub_ = new exprMin (ub_, u0);
136  }
137
138  /// generate cuts for expression associated with this auxiliary
139  void generateCuts (const OsiSolverInterface &, 
140                     OsiCuts &, const CouenneCutGenerator *);
141
142  /// used in rank-based branching variable choice
143  virtual inline int rank (CouenneProblem *p = NULL)
144    {return rank_;} 
145
146  /// Tell this variable appears once more
147  inline void increaseMult () {++multiplicity_;}
148
149  /// Tell this variable appears once less (standardized within
150  /// exprSum, for instance)
151  inline void decreaseMult () {--multiplicity_;}
152
153  /// How many times this variable appears
154  inline int Multiplicity () {return multiplicity_;}
155};
156
157/// allow to draw function within intervals and cuts introduced
158void draw_cuts (OsiCuts &, const CouenneCutGenerator *, 
159                int, expression *, expression *);
160
161#endif
Note: See TracBrowser for help on using the repository browser.