1 /* $Id$
2  *
3  * Name:    exprSub.hpp
4  * Author:  Pietro Belotti
5  * Purpose: definition of subtractions
6  *
7  * (C) Carnegie-Mellon University, 2006-10.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #ifndef COUENNE_EXPRSUB_HPP
12 #define COUENNE_EXPRSUB_HPP
13 
14 #include "CouenneExprOp.hpp"
15 #include "CouennePrecisions.hpp"
16 #include "CouenneProblem.hpp"
17 
18 namespace Couenne {
19 
20 /// class for subtraction, \f$ f(x) - g(x) \f$
21 
22 class exprSub: public exprOp {
23 
24  public:
25 
26   /// Constructor
exprSub(expression ** al,int n=2)27   exprSub  (expression **al, int n = 2):
28     exprOp (al, n) {} //< non-leaf expression, with argument list
29 
30   /// Constructor with two explicit elements
exprSub(expression * arg0,expression * arg1)31   exprSub (expression *arg0, expression *arg1):
32     exprOp (arg0, arg1) {}
33 
34   /// Cloning method
clone(Domain * d=NULL) const35   expression *clone (Domain *d = NULL) const
36     {return new exprSub (clonearglist (d), nargs_);}
37 
38   //// Print operator
printOp() const39   std::string printOp () const
40     {return "-";}
41 
42   /// Function for the evaluation of the difference
43   CouNumber operator () ();
44 
45   /// Differentiation
46   expression *differentiate (int index);
47 
48   /// Simplification
49   expression *simplify ();
50 
51   /// Get a measure of "how linear" the expression is (see CouenneTypes.h)
Linearity()52   virtual inline int Linearity () {
53 
54     int lin1 = arglist_ [0] -> Linearity ();
55     int lin2 = arglist_ [1] -> Linearity ();
56 
57     if (lin1 < lin2) return lin2;
58     else             return lin1;
59   }
60 
61   /// Get lower and upper bound of an expression (if any)
62   void getBounds (expression *&, expression *&);
63 
64   /// Get value of lower and upper bound of an expression (if any)
65   void getBounds (CouNumber &lb, CouNumber &ub);
66 
67   /// Reduce expression in standard form, creating additional aux
68   /// variables (and constraints)
69   virtual exprAux *standardize (CouenneProblem *p, bool addAux = true);
70 
71   /// Special version for linear constraints
72   virtual void generateCuts (expression *, //const OsiSolverInterface &,
73 			     OsiCuts &, const CouenneCutGenerator *,
74 			     t_chg_bounds * = NULL, int = -1,
75 			     CouNumber = -COUENNE_INFINITY,
76 			     CouNumber =  COUENNE_INFINITY);
77 
78   /// Code for comparisons
code()79   virtual enum expr_type code () {return COU_EXPRSUB;}
80 
81   /// Implied bound processing
82   bool impliedBound (int, CouNumber *, CouNumber *, t_chg_bounds *, enum auxSign = expression::AUX_EQ);
83 };
84 
85 
86 /// Compute difference
87 
operator ()()88 inline CouNumber exprSub::operator () ()
89 {return ((*(*arglist_)) () - (*(arglist_ [1])) ());}
90 
91 }
92 
93 #endif
94