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

Go to the documentation of this file.
00001 /* $Id: CouenneComplObject.cpp 694 2011-06-18 20:13:17Z stefan $
00002  *
00003  * Name:    CouenneComplObject.cpp
00004  * Authors: Pietro Belotti, Lehigh University
00005  * Purpose: Implementation of branching rules for complementarity constraints
00006  *
00007  * (C) Carnegie-Mellon University, 2008-09.
00008  * This file is licensed under the Eclipse Public License (EPL)
00009  */
00010 
00011 #include "CouenneComplObject.hpp"
00012 #include "CouenneComplBranchingObject.hpp"
00013 
00014 using namespace Ipopt;
00015 using namespace Couenne;
00016 
00018 CouenneComplObject::CouenneComplObject (CouenneCutGenerator *c,
00019                                         CouenneProblem *p, 
00020                                         exprVar *ref, Bonmin::BabSetupBase *base, JnlstPtr jnlst,
00021                                         int sign):
00022   CouenneObject (c, p, ref, base, jnlst),
00023   sign_ (sign) {
00024   jnlst -> Printf (J_DETAILED, J_BRANCHING, 
00025                    "[created Complementarity constraint object with sign %d]\n", sign);
00026 }
00027 
00028 
00030 CouenneComplObject::CouenneComplObject (exprVar *ref, Bonmin::BabSetupBase *base, JnlstPtr jnlst,
00031                                         int sign):
00032   CouenneObject (ref, base, jnlst),
00033   sign_ (sign) {}
00034 
00035 
00037 CouenneComplObject::CouenneComplObject (const CouenneComplObject &src): 
00038   CouenneObject (src),
00039   sign_ (src.sign_) {}
00040 
00041 
00044 double CouenneComplObject::infeasibility (const OsiBranchingInformation *info, int &way) const {
00045 
00046   expression **arglist = reference_ -> Image () -> ArgList ();
00047 
00048   int index0 = arglist [0] -> Index (),
00049       index1 = arglist [1] -> Index ();
00050 
00051   if (sign_) { // it is a xy <= 0 or a xy >= 0 object
00052 
00053     CouNumber 
00054       x0 = info -> solution_ [index0],
00055       x1 = info -> solution_ [index1],
00056       prod = x0*x1;
00057 
00058     if (sign_ < 0) {
00059 
00060       if (prod <= 0) return 0; // object feasible
00061 
00062       way = (x1<=x0); // zero if closer to second orthant (prefer to
00063                       // branch on "more feasible" variable)
00064 
00065     } else {
00066 
00067       if (prod >= 0) return 0; // object feasible
00068 
00069       way = (x1<=-x0); // zero if closer to second orthant (prefer to
00070                        // branch on "more feasible" variable)
00071     }
00072 
00073     // if x1 < x0, it is preferrable to branch with x1=0 instead of x0=0
00074     // as this is closer to the point
00075     //way = (x1 < x0) ? 1 : 0;
00076     return fabs (prod);
00077 
00078   } else { // it is a xy=0 object, use old infeasibility
00079 
00080     CouNumber 
00081       x0 = fabs (info -> solution_ [index0]),
00082       x1 = fabs (info -> solution_ [index1]);
00083 
00084     // if x1 < x0, it is preferrable to branch with x1=0 instead of x0=0
00085     // as this is closer to the point
00086     way = (x1 < x0) ? 1 : 0;
00087 
00088     return x0 * x1;
00089   }
00090 }
00091 
00092 
00095 double CouenneComplObject::checkInfeasibility (const OsiBranchingInformation * info) const {
00096 
00097   expression **arglist = reference_ -> Image () -> ArgList ();
00098 
00099   int index0 = arglist [0] -> Index (),
00100       index1 = arglist [1] -> Index ();
00101 
00102   CouNumber
00103     x0 = info -> solution_ [index0],
00104     x1 = info -> solution_ [index1],
00105     prod = x0*x1;
00106 
00107   if (!sign_)
00108     return fabs (prod);
00109   else return
00110          ((sign_ < 0) && (prod >= 0)) ||
00111          ((sign_ > 0) && (prod <= 0)) ? fabs (prod) : 0.;
00112 }
00113 
00114 
00117 OsiBranchingObject *CouenneComplObject::createBranch (OsiSolverInterface *solver, 
00118                                                       const OsiBranchingInformation *info, 
00119                                                       int way) const {
00120 
00121   expression **args = reference_ -> Image () -> ArgList ();
00122 
00123   /*  printf ("creating CCobj: %d %d.%d\n", reference_ -> Index (), 
00124           args [0] -> Index (),
00125           args [1] -> Index ());*/
00126 
00127   return new CouenneComplBranchingObject (solver, this, jnlst_,
00128                                           cutGen_,
00129                                           problem_,
00130                                           args [0],
00131                                           args [1], 
00132                                           way, 0, doFBBT_, doConvCuts_, sign_);
00133 }

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