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

Go to the documentation of this file.
00001 /* $Id: CouenneComplObject.cpp 268 2009-10-22 03:41:03Z pbelotti $
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 Common Public License (CPL)
00009  */
00010 
00011 #include "CouenneComplObject.hpp"
00012 #include "CouenneComplBranchingObject.hpp"
00013 
00014 
00016 CouenneComplObject::CouenneComplObject (CouenneCutGenerator *c,
00017                                         CouenneProblem *p, 
00018                                         exprVar *ref, Bonmin::BabSetupBase *base, JnlstPtr jnlst,
00019                                         int sign):
00020   CouenneObject (c, p, ref, base, jnlst),
00021   sign_ (sign) {
00022   jnlst -> Printf (J_DETAILED, J_BRANCHING, 
00023                    "[created Complementarity constraint object with sign %d]\n", sign);
00024 }
00025 
00026 
00028 CouenneComplObject::CouenneComplObject (exprVar *ref, Bonmin::BabSetupBase *base, JnlstPtr jnlst,
00029                                         int sign):
00030   CouenneObject (ref, base, jnlst),
00031   sign_ (sign) {}
00032 
00033 
00035 CouenneComplObject::CouenneComplObject (const CouenneComplObject &src): 
00036   CouenneObject (src),
00037   sign_ (src.sign_) {}
00038 
00039 
00042 double CouenneComplObject::infeasibility (const OsiBranchingInformation *info, int &way) const {
00043 
00044   expression **arglist = reference_ -> Image () -> ArgList ();
00045 
00046   int index0 = arglist [0] -> Index (),
00047       index1 = arglist [1] -> Index ();
00048 
00049   if (sign_) { // it is a xy <= 0 or a xy >= 0 object
00050 
00051     CouNumber 
00052       x0 = info -> solution_ [index0],
00053       x1 = info -> solution_ [index1],
00054       prod = x0*x1;
00055 
00056     if (sign_ < 0) {
00057 
00058       if (prod <= 0) return 0; // object feasible
00059 
00060       way = (x1<=x0); // zero if closer to second orthant (prefer to
00061                       // branch on "more feasible" variable)
00062 
00063     } else {
00064 
00065       if (prod >= 0) return 0; // object feasible
00066 
00067       way = (x1<=-x0); // zero if closer to second orthant (prefer to
00068                        // branch on "more feasible" variable)
00069     }
00070 
00071     // if x1 < x0, it is preferrable to branch with x1=0 instead of x0=0
00072     // as this is closer to the point
00073     //way = (x1 < x0) ? 1 : 0;
00074     return fabs (prod);
00075 
00076   } else { // it is a xy=0 object, use old infeasibility
00077 
00078     CouNumber 
00079       x0 = fabs (info -> solution_ [index0]),
00080       x1 = fabs (info -> solution_ [index1]);
00081 
00082     // if x1 < x0, it is preferrable to branch with x1=0 instead of x0=0
00083     // as this is closer to the point
00084     way = (x1 < x0) ? 1 : 0;
00085 
00086     return x0 * x1;
00087   }
00088 }
00089 
00090 
00093 double CouenneComplObject::checkInfeasibility (const OsiBranchingInformation * info) const {
00094 
00095   expression **arglist = reference_ -> Image () -> ArgList ();
00096 
00097   int index0 = arglist [0] -> Index (),
00098       index1 = arglist [1] -> Index ();
00099 
00100   CouNumber
00101     x0 = info -> solution_ [index0],
00102     x1 = info -> solution_ [index1],
00103     prod = x0*x1;
00104 
00105   if (!sign_)
00106     return fabs (prod);
00107   else return
00108          ((sign_ < 0) && (prod >= 0)) ||
00109          ((sign_ > 0) && (prod <= 0)) ? fabs (prod) : 0.;
00110 }
00111 
00112 
00115 OsiBranchingObject *CouenneComplObject::createBranch (OsiSolverInterface *solver, 
00116                                                       const OsiBranchingInformation *info, 
00117                                                       int way) const {
00118 
00119   expression **args = reference_ -> Image () -> ArgList ();
00120 
00121   /*  printf ("creating CCobj: %d %d.%d\n", reference_ -> Index (), 
00122           args [0] -> Index (),
00123           args [1] -> Index ());*/
00124 
00125   return new CouenneComplBranchingObject (solver, this, jnlst_,
00126                                           cutGen_,
00127                                           problem_,
00128                                           args [0],
00129                                           args [1], 
00130                                           way, 0, doFBBT_, doConvCuts_, sign_);
00131 }

Generated on Mon May 3 03:05:18 2010 by  doxygen 1.4.7