/home/coin/SVN-release/OS-2.4.1/Couenne/src/branch/feasibleRegion.cpp

Go to the documentation of this file.
00001 /* $Id: feasibleRegion.cpp 490 2011-01-14 16:07:12Z pbelotti $
00002  *
00003  * Name:    feasibleRegion.cpp
00004  * Authors: Pierre Bonami, IBM Corp.
00005  *          Pietro Belotti, Carnegie Mellon University
00006  * Purpose: Implement feasibleRegion() method of CouenneObject class
00007  *
00008  * (C) Carnegie-Mellon University, 2006-10.
00009  * This file is licensed under the Eclipse Public License (EPL)
00010  */
00011 
00012 #include "CoinHelperFunctions.hpp"
00013 
00014 #include "CouenneProblem.hpp"
00015 #include "CouenneObject.hpp"
00016 #include "CouenneBranchingObject.hpp"
00017 #include "CouenneThreeWayBranchObj.hpp"
00018 
00019 #include "CouenneExprGroup.hpp"
00020 #include "CouenneExprQuad.hpp"
00021 #include "CouenneLQelems.hpp"
00022 
00023 using namespace Couenne;
00024 
00025 #define TOL 0.
00026 
00028 double CouenneObject::feasibleRegion (OsiSolverInterface *solver, 
00029                                       const OsiBranchingInformation *info) const {
00030   int index = reference_ -> Index ();
00031 
00032   assert (index >= 0);
00033 
00034   double val = info -> solution_ [index];
00035 
00036   // fix that variable to its current value
00037   solver -> setColLower (index, val-TOL);
00038   solver -> setColUpper (index, val+TOL);
00039 
00040   expression *expr = reference_ -> Image ();
00041 
00042   if (!expr) return 0.;
00043 
00044   // fix all variables upon which this auxiliary depends
00045 
00046   // expr is surely nonlinear, so it's useless to check if it is an
00047   // exprAux, w1:=w0
00048 
00049   if (expr -> Type () == UNARY) { // unary function
00050 
00051     index = expr -> Argument () -> Index ();
00052 
00053     if (index >= 0) {
00054       val = info -> solution_ [index];
00055       solver -> setColLower (index, val-TOL);
00056       solver -> setColUpper (index, val+TOL);
00057     }
00058   }
00059   else // n-ary function
00060 
00061     if (expr -> Type () == N_ARY) {
00062 
00063       expression ** args = expr -> ArgList ();
00064       int nargs = expr -> nArgs ();
00065 
00066       for (register int i=0; i < nargs; i++) {
00067 
00068         if ((index = args [i] -> Index()) >= 0) {
00069           val = info -> solution_ [index];
00070           solver -> setColLower (index, val-TOL);
00071           solver -> setColUpper (index, val+TOL);
00072         }
00073       }
00074     }
00075 
00076   // last cases: exprGroup/Quad, must handle the linear/quadratic terms
00077   if ((expr -> code () == COU_EXPRGROUP) ||
00078       (expr -> code () == COU_EXPRQUAD)) {
00079 
00080     exprGroup *e = dynamic_cast <exprGroup *> (expr -> isaCopy () ? 
00081                                                expr -> Copy () : 
00082                                                expr);
00083 
00084     exprGroup::lincoeff &lcoe = e -> lcoeff ();
00085 
00086     for (exprGroup::lincoeff::iterator el = lcoe.begin (); el != lcoe.end (); ++el) {
00087       int index = el -> first -> Index ();
00088       val = info -> solution_ [index];
00089       solver -> setColLower (index, val-TOL);
00090       solver -> setColUpper (index, val+TOL);
00091     }
00092 
00093     // take care of quadratic terms
00094     if (expr -> code () == COU_EXPRQUAD) {
00095 
00096       exprQuad *e = dynamic_cast <exprQuad *> (expr -> isaCopy () ? 
00097                                                expr -> Copy () : 
00098                                                expr);
00099 
00100       exprQuad::sparseQ q = e -> getQ ();
00101 
00102       for (exprQuad::sparseQ::iterator row = q.begin (); 
00103            row != q.end (); ++row) {
00104 
00105         int xind = row -> first -> Index ();
00106 
00107         val = info -> solution_ [xind];
00108         solver -> setColLower (xind, val-TOL);
00109         solver -> setColUpper (xind, val+TOL);
00110 
00111         for (exprQuad::sparseQcol::iterator col = row -> second.begin ();
00112              col != row -> second.end (); ++col) {
00113 
00114           int yind = col -> first -> Index ();
00115 
00116           val = info -> solution_ [yind];
00117           solver -> setColLower (yind, val-TOL);
00118           solver -> setColUpper (yind, val+TOL);
00119         }
00120       }
00121     }
00122   }
00123 
00124   return 0.;
00125 }

Generated on Thu Nov 10 03:05:43 2011 by  doxygen 1.4.7