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

Go to the documentation of this file.
00001 /* $Id: feasibleRegion.cpp 215 2009-07-08 15:43:38Z 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-09.
00009  * This file is licensed under the Common Public License (CPL)
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 "exprGroup.hpp"
00020 #include "exprQuad.hpp"
00021 #include "lqelems.hpp"
00022 
00023 #define TOL 0.
00024 
00026 double CouenneObject::feasibleRegion (OsiSolverInterface *solver, 
00027                                       const OsiBranchingInformation *info) const {
00028   int index = reference_ -> Index ();
00029 
00030   assert (index >= 0);
00031 
00032   double val = info -> solution_ [index];
00033 
00034   // fix that variable to its current value
00035   solver -> setColLower (index, val-TOL);
00036   solver -> setColUpper (index, val+TOL);
00037 
00038   expression *expr = reference_ -> Image ();
00039 
00040   if (!expr) return 0.;
00041 
00042   // fix all variables upon which this auxiliary depends
00043 
00044   // expr is surely nonlinear, so it's useless to check if it is an
00045   // exprAux, w1:=w0
00046 
00047   if (expr -> Type () == UNARY) { // unary function
00048 
00049     index = expr -> Argument () -> Index ();
00050 
00051     if (index >= 0) {
00052       val = info -> solution_ [index];
00053       solver -> setColLower (index, val-TOL);
00054       solver -> setColUpper (index, val+TOL);
00055     }
00056   }
00057   else // n-ary function
00058 
00059     if (expr -> Type () == N_ARY) {
00060 
00061       expression ** args = expr -> ArgList ();
00062       int nargs = expr -> nArgs ();
00063 
00064       for (register int i=0; i < nargs; i++) {
00065 
00066         if ((index = args [i] -> Index()) >= 0) {
00067           val = info -> solution_ [index];
00068           solver -> setColLower (index, val-TOL);
00069           solver -> setColUpper (index, val+TOL);
00070         }
00071       }
00072     }
00073 
00074   // last cases: exprGroup/Quad, must handle the linear/quadratic terms
00075   if ((expr -> code () == COU_EXPRGROUP) ||
00076       (expr -> code () == COU_EXPRQUAD)) {
00077 
00078     exprGroup *e = dynamic_cast <exprGroup *> (expr -> isaCopy () ? 
00079                                                expr -> Copy () : 
00080                                                expr);
00081 
00082     exprGroup::lincoeff &lcoe = e -> lcoeff ();
00083 
00084     for (exprGroup::lincoeff::iterator el = lcoe.begin (); el != lcoe.end (); ++el) {
00085       int index = el -> first -> Index ();
00086       val = info -> solution_ [index];
00087       solver -> setColLower (index, val-TOL);
00088       solver -> setColUpper (index, val+TOL);
00089     }
00090 
00091     // take care of quadratic terms
00092     if (expr -> code () == COU_EXPRQUAD) {
00093 
00094       exprQuad *e = dynamic_cast <exprQuad *> (expr -> isaCopy () ? 
00095                                                expr -> Copy () : 
00096                                                expr);
00097 
00098       exprQuad::sparseQ q = e -> getQ ();
00099 
00100       for (exprQuad::sparseQ::iterator row = q.begin (); 
00101            row != q.end (); ++row) {
00102 
00103         int xind = row -> first -> Index ();
00104 
00105         val = info -> solution_ [xind];
00106         solver -> setColLower (xind, val-TOL);
00107         solver -> setColUpper (xind, val+TOL);
00108 
00109         for (exprQuad::sparseQcol::iterator col = row -> second.begin ();
00110              col != row -> second.end (); ++col) {
00111 
00112           int yind = col -> first -> Index ();
00113 
00114           val = info -> solution_ [yind];
00115           solver -> setColLower (yind, val-TOL);
00116           solver -> setColUpper (yind, val+TOL);
00117         }
00118       }
00119     }
00120   }
00121 
00122   return 0.;
00123 }

Generated on Tue Mar 30 03:04:36 2010 by  doxygen 1.4.7