conv-exprSum.cpp
Go to the documentation of this file.
1 /* $Id: conv-exprSum.cpp 490 2011-01-14 16:07:12Z pbelotti $
2  *
3  * Name: conv-exprSum.cpp
4  * Author: Pietro Belotti
5  * Purpose: methods to standardize/convexify sum expressions
6  *
7  * (C) Carnegie-Mellon University, 2006-10.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #include "CouenneCutGenerator.hpp"
12 
13 #include "CouenneTypes.hpp"
14 
15 #include "CouenneExprAux.hpp"
16 #include "CouenneExprSum.hpp"
17 #include "CouenneExprConst.hpp"
18 
19 #include "CouenneProblem.hpp"
20 
21 using namespace Couenne;
22 
23 // generate equality between *this and *w
24 void exprSum::generateCuts (expression *w, //const OsiSolverInterface &si,
25  OsiCuts &cs, const CouenneCutGenerator *cg,
26  t_chg_bounds *chg,
27  int wind, CouNumber lb, CouNumber ub) {
28  if (!(cg -> isFirst ()))
29  return;
30 
31  CouNumber *coeff = new CouNumber [nargs_ + 1];
32  int *index = new int [nargs_ + 1];
33  OsiRowCut *cut = new OsiRowCut;
34 
36 
37  int nv = 0;
38 
39  // If this aux is fixed, don't write
40  //
41  // "- w + ax = -b" but just
42  //
43  // "ax = -b+ w0"
44  //
45  // with w0 its constant value
46 
47  CouNumber vlb, vub;
48  w -> getBounds (vlb, vub);
49  bool uselessAux = (vub < vlb + COUENNE_EPS);
50 
51  // TODO: generalize to sign!= ::EQ
52 
53  if (wind < 0 && !uselessAux) {
54  coeff [0] = -1.; index [0] = w -> Index ();
55  nv++;
56  lb = ub = 0;
57  }
58 
59  if (uselessAux)
60  lb = ub = vlb;
61 
63  for (int i=0; i<nargs_; i++) {
64 
65  if (arglist_ [i] -> Type () == CONST) {
66 
67  CouNumber val = arglist_ [i] -> Value ();
68 
69  lb -= val;
70  ub -= val;
71  }
72  else {
73  coeff [nv] = 1.;
74  index [nv++] = arglist_ [i] -> Index ();
75  }
76  }
77 
78  cut -> setRow (nv, index, coeff);
79 
80  delete [] index;
81  delete [] coeff;
82 
83  enum auxSign sign = cg -> Problem () -> Var (w -> Index ()) -> sign ();
84 
85  if (lb > -COUENNE_INFINITY && (sign != expression::AUX_GEQ)) cut -> setLb (lb);
86  if (ub < COUENNE_INFINITY && (sign != expression::AUX_LEQ)) cut -> setUb (ub);
87 
89  cut -> setGloballyValid ();
90 
91  cs.insert (cut);
92  delete cut;
93 }
Cut Generator for linear convexifications.
status of lower/upper bound of a variable, to be checked/modified in bound tightening ...
virtual enum nodeType Type() const
Node type.
virtual int Index() const
Return index of variable (only valid for exprVar and exprAux)
auxSign
&quot;sign&quot; of the constraint defining an auxiliary.
virtual void getBounds(expression *&, expression *&)
Get lower and upper bound of an expression (if any)
Definition: exprSum.cpp:118
#define COUENNE_EPS
virtual void generateCuts(expression *, OsiCuts &, const CouenneCutGenerator *, t_chg_bounds *=NULL, int=-1, CouNumber=-COUENNE_INFINITY, CouNumber=COUENNE_INFINITY)
Special version for linear constraints.
expression ** arglist_
argument list is an array of pointers to other expressions
double CouNumber
main number type in Couenne
int nargs_
number of arguments (cardinality of arglist)
#define COUENNE_INFINITY
Expression base class.
void fint fint fint real fint real real real real real real real real * w
virtual CouNumber Value() const
value (empty)