00001
00002
00003
00004
00005
00006
00007
00008
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_) {
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;
00061
00062 way = (x1<=x0);
00063
00064
00065 } else {
00066
00067 if (prod >= 0) return 0;
00068
00069 way = (x1<=-x0);
00070
00071 }
00072
00073
00074
00075
00076 return fabs (prod);
00077
00078 } else {
00079
00080 CouNumber
00081 x0 = fabs (info -> solution_ [index0]),
00082 x1 = fabs (info -> solution_ [index1]);
00083
00084
00085
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
00124
00125
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 }