12 #include "CoinHelperFunctions.hpp"
17 using namespace Ipopt;
18 using namespace Couenne;
22 double CouenneVTObject::infeasibility (
const OsiBranchingInformation *
info,
int &way)
const {
24 int indexVar = reference_ -> Index ();
25 assert (indexVar >= 0);
30 if (info -> upper_ [indexVar] -
31 info -> lower_ [indexVar] <= tol) {
33 double point = info -> solution_ [reference_ -> Index ()];
34 if (downEstimate_ < point - floor (point)) downEstimate_ = point - floor (point);
35 if (upEstimate_ < ceil (point) - point) upEstimate_ = ceil (point) - point;
36 return intInfeasibility (point,
37 info -> lower_ [indexVar],
38 info -> upper_ [indexVar]);
39 }
else return (upEstimate_ = downEstimate_ = 0.);
43 problem_ -> domain () -> push
44 (problem_ -> nVars (),
52 if (jnlst_ -> ProduceOutput (J_DETAILED,
J_BRANCHING)) {
53 printf (
"VT infeas on ");
54 reference_ -> print ();
55 if (reference_ -> Image ()) {
57 reference_ -> Image () -> print ();
59 const std::set <int> &dependence = problem_ -> Dependence () [indexVar];
60 if (dependence.size () > 0) {
62 for (std::set <int>::const_iterator i = dependence.begin ();
63 i != dependence.end (); ++i) {
64 problem_ -> Var (*i) -> print ();
72 const std::set <int> &dependence = problem_ -> Dependence () [indexVar];
75 xcurr = info -> solution_ [indexVar],
83 if (reference_ -> Type () ==
AUX)
84 fx = (*(reference_ -> Image ())) ();
86 if (dependence.size () == 0) {
95 retval = (reference_ -> Type () ==
AUX) ?
97 (upEstimate_ = downEstimate_ = maxInf = checkInfeasibility (info)) :
101 retval = upEstimate_ = downEstimate_ = maxInf = checkInfeasibility (info);
108 for (std::set <int>::const_iterator i = dependence.begin ();
109 i != dependence.end (); ++i) {
112 assert (obj -> Reference ());
117 infeas = obj -> checkInfeasibility (info);
129 obj -> Reference () -> Image () -> closestFeasible
130 (reference_, obj -> Reference (), left, right);
132 if (left < lFeas) lFeas = left;
133 if (right > rFeas) rFeas = right;
136 if (jnlst_ -> ProduceOutput (J_MATRIX,
J_BRANCHING)) {
138 jnlst_ -> Printf (J_MATRIX,
J_BRANCHING,
"[%g,%g] --> %g - %g = %g (diff = %g - %g = %g): ",
139 left, right, rFeas, lFeas, rFeas - lFeas,
141 (*(ref-> Image ())) () : 0.,
144 (*(ref -> Image ())) () - (*(ref)) () : 0.);
147 {printf (
" := "); ref -> Image() -> print();}
152 if (lFeas < info -> lower_ [indexVar]) lFeas = info -> lower_ [indexVar];
153 if (rFeas > info -> upper_ [indexVar]) rFeas = info -> upper_ [indexVar];
155 retval = rFeas - lFeas;
157 upEstimate_ = rFeas - xcurr;
158 downEstimate_ = xcurr - lFeas;
163 if (upEstimate_ <= tol) upEstimate_ = maxInf;
164 if (downEstimate_ <= tol) downEstimate_ = maxInf;
176 leanLeft = (xcurr - lFeas) / retval;
178 if (leanLeft < threshold) way = 0;
179 else if (leanLeft > 1 - threshold) way = 1;
180 else way = (CoinDrand48 () < 0.5) ? 0 : 1;
188 (indexVar == problem_ -> Obj (0) -> Body () -> Index ()) ? 1. : 0.;
190 for (
int i=0, n_el = info -> columnLength_ [indexVar]; i < n_el; i++) {
192 int indRow = info -> columnStart_ [indexVar] + i;
195 fabs (info -> pi_ [info -> row_ [indRow]] *
196 info -> elementByColumn_ [indRow]);
202 jnlst_ -> Printf (J_MATRIX,
J_BRANCHING,
"+ (pi[%d]=%g) * (el[%d]=%g) [=%g] --> vtd = %g\n",
203 info -> row_ [indRow],
204 info -> pi_ [info -> row_ [indRow]],
206 info -> elementByColumn_ [indRow],
207 info -> pi_ [info -> row_ [indRow]] *
208 info -> elementByColumn_ [indRow],
217 jnlst_ -> Printf (J_MATRIX,
J_BRANCHING,
"return %g * %g + %g * %g + %g * %g --> ",
218 alpha, fabs (retval * vt_delta), beta, retval,
219 1-alpha-beta, leanLeft * (1-leanLeft));
222 alpha * fabs (retval*vt_delta) +
224 (1-alpha-beta) * leanLeft * (1-leanLeft);
226 if (jnlst_ -> ProduceOutput (J_MATRIX,
J_BRANCHING)) {
228 printf (
"vt-delta is %-10g [", retval);
229 reference_ -> print ();
230 if (reference_ -> Image ()) {
232 reference_ -> Image () -> print ();
234 if (dependence.size () > 0) {
236 for (std::set <int>::const_iterator i = dependence.begin ();
237 i != dependence.end (); ++i) {
238 problem_ -> Var (*i) -> print ();
243 }
else printf (
"feasible...\n");
246 problem_ -> domain () -> pop ();
248 if ((retval <= tol) &&
260 #define ALMOST_ZERO 1e-8
266 CoinMax (retval, intInfeasibility (info -> solution_ [indexVar],
267 info -> lower_ [indexVar],
268 info -> upper_ [indexVar])) :
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint * info
OsiObject for auxiliary variables $w=f(x)$.
const Ipopt::EJournalCategory J_BRANCHING(Ipopt::J_USER1)
double CouNumber
main number type in Couenne
bool isInteger(CouNumber x)
is this number integer?