feasibleRegion.cpp
Go to the documentation of this file.
1 /* $Id: feasibleRegion.cpp 490 2011-01-14 16:07:12Z pbelotti $
2  *
3  * Name: feasibleRegion.cpp
4  * Authors: Pierre Bonami, IBM Corp.
5  * Pietro Belotti, Carnegie Mellon University
6  * Purpose: Implement feasibleRegion() method of CouenneObject class
7  *
8  * (C) Carnegie-Mellon University, 2006-10.
9  * This file is licensed under the Eclipse Public License (EPL)
10  */
11 
12 #include "CoinHelperFunctions.hpp"
13 
14 #include "CouenneProblem.hpp"
15 #include "CouenneObject.hpp"
18 
19 #include "CouenneExprGroup.hpp"
20 #include "CouenneExprQuad.hpp"
21 #include "CouenneLQelems.hpp"
22 
23 using namespace Couenne;
24 
25 #define TOL 0.
26 
28 double CouenneObject::feasibleRegion (OsiSolverInterface *solver,
29  const OsiBranchingInformation *info) const {
30  int index = reference_ -> Index ();
31 
32  assert (index >= 0);
33 
34  double val = info -> solution_ [index];
35 
36  // fix that variable to its current value
37  solver -> setColLower (index, val-TOL);
38  solver -> setColUpper (index, val+TOL);
39 
40  expression *expr = reference_ -> Image ();
41 
42  if (!expr) return 0.;
43 
44  // fix all variables upon which this auxiliary depends
45 
46  // expr is surely nonlinear, so it's useless to check if it is an
47  // exprAux, w1:=w0
48 
49  if (expr -> Type () == UNARY) { // unary function
50 
51  index = expr -> Argument () -> Index ();
52 
53  if (index >= 0) {
54  val = info -> solution_ [index];
55  solver -> setColLower (index, val-TOL);
56  solver -> setColUpper (index, val+TOL);
57  }
58  }
59  else // n-ary function
60 
61  if (expr -> Type () == N_ARY) {
62 
63  expression ** args = expr -> ArgList ();
64  int nargs = expr -> nArgs ();
65 
66  for (register int i=0; i < nargs; i++) {
67 
68  if ((index = args [i] -> Index()) >= 0) {
69  val = info -> solution_ [index];
70  solver -> setColLower (index, val-TOL);
71  solver -> setColUpper (index, val+TOL);
72  }
73  }
74  }
75 
76  // last cases: exprGroup/Quad, must handle the linear/quadratic terms
77  if ((expr -> code () == COU_EXPRGROUP) ||
78  (expr -> code () == COU_EXPRQUAD)) {
79 
80  exprGroup *e = dynamic_cast <exprGroup *> (expr -> isaCopy () ?
81  expr -> Copy () :
82  expr);
83 
84  exprGroup::lincoeff &lcoe = e -> lcoeff ();
85 
86  for (exprGroup::lincoeff::iterator el = lcoe.begin (); el != lcoe.end (); ++el) {
87  int index = el -> first -> Index ();
88  val = info -> solution_ [index];
89  solver -> setColLower (index, val-TOL);
90  solver -> setColUpper (index, val+TOL);
91  }
92 
93  // take care of quadratic terms
94  if (expr -> code () == COU_EXPRQUAD) {
95 
96  exprQuad *e = dynamic_cast <exprQuad *> (expr -> isaCopy () ?
97  expr -> Copy () :
98  expr);
99 
100  exprQuad::sparseQ q = e -> getQ ();
101 
102  for (exprQuad::sparseQ::iterator row = q.begin ();
103  row != q.end (); ++row) {
104 
105  int xind = row -> first -> Index ();
106 
107  val = info -> solution_ [xind];
108  solver -> setColLower (xind, val-TOL);
109  solver -> setColUpper (xind, val+TOL);
110 
111  for (exprQuad::sparseQcol::iterator col = row -> second.begin ();
112  col != row -> second.end (); ++col) {
113 
114  int yind = col -> first -> Index ();
115 
116  val = info -> solution_ [yind];
117  solver -> setColLower (yind, val-TOL);
118  solver -> setColUpper (yind, val+TOL);
119  }
120  }
121  }
122  }
123 
124  return 0.;
125 }
class Group, with constant, linear and nonlinear terms:
std::vector< std::pair< exprVar *, sparseQcol > > sparseQ
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint * info
exprVar * reference_
The (auxiliary) variable this branching object refers to.
void fint fint fint real fint real real real real real real real real real * e
#define TOL
std::vector< std::pair< exprVar *, CouNumber > > lincoeff
class exprQuad, with constant, linear and quadratic terms
Expression base class.
virtual double feasibleRegion(OsiSolverInterface *, const OsiBranchingInformation *) const
fix (one of the) arguments of reference auxiliary variable