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