00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "CglCutGenerator.hpp"
00012 #include "CouenneCutGenerator.hpp"
00013 #include "CouenneProblem.hpp"
00014 #include "CouenneProblemElem.hpp"
00015 #include "CouenneExprVar.hpp"
00016
00017 using namespace Ipopt;
00018 using namespace Couenne;
00019
00020 #define OBBT_EPS 1e-3
00021
00022
00023
00024
00025
00026 int obbt_supplement (const OsiSolverInterface *csi,
00027 int index,
00028 int sense);
00029
00031 static bool obbt_updateBound (OsiSolverInterface *csi,
00032 int sense,
00033 CouNumber &bound,
00034 bool isint) {
00035
00036
00037
00038
00039
00040
00041
00042 csi -> setDblParam (OsiDualObjectiveLimit, COIN_DBL_MAX);
00043 csi -> setDblParam (OsiPrimalObjectiveLimit, (sense==1) ? bound : -bound);
00044
00045
00047
00048
00049 csi -> resolve ();
00050
00052
00053 if (csi -> isProvenOptimal ()) {
00054
00055 double opt = csi -> getObjValue ();
00056
00057 if (sense > 0)
00058 {if (opt > bound + OBBT_EPS) {bound = (isint ? ceil (opt - COUENNE_EPS) : opt); return true;}}
00059 else {if ((opt=-opt) < bound - OBBT_EPS) {bound = (isint ? floor (opt + COUENNE_EPS) : opt); return true;}}
00060 }
00061
00062 return false;
00063 }
00064
00065
00067
00068 int CouenneProblem::obbt_iter (OsiSolverInterface *csi,
00069 t_chg_bounds *chg_bds,
00070 const CoinWarmStart *warmstart,
00071 Bonmin::BabInfo *babInfo,
00072 double *objcoe,
00073 int sense,
00074 int index) const {
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 CouNumber *knownOptimum = optimum_;
00089
00090 if (optimum_) {
00091
00092 for (int i=nVars(); i--; knownOptimum++)
00093
00094 if (*knownOptimum < Lb (i) ||
00095 *knownOptimum > Ub (i)) {
00096
00097 knownOptimum = NULL;
00098 break;
00099 }
00100
00101 if (knownOptimum)
00102 knownOptimum -= nVars ();
00103 }
00104
00105 std::set <int> deplist;
00106 int deplistsize;
00107
00108 bool issimple = false;
00109
00110 exprVar *var = Var (index);
00111
00112 int
00113 objind = Obj (0) -> Body () -> Index (),
00114 ncols = csi -> getNumCols (),
00115 nImprov = 0;
00116
00117 if ((var -> Type () == AUX) &&
00118 ((deplistsize = var -> Image () -> DepList (deplist, STOP_AT_AUX)) <= 1)) {
00119
00120 if (!deplistsize) {
00121
00122 CouNumber value = (*(var -> Image ())) ();
00123
00124 if (csi -> getColLower () [index] < value - COUENNE_EPS) {
00125 csi -> setColLower (index, value);
00126 chg_bds [index].setLowerBits(t_chg_bounds::CHANGED | t_chg_bounds::EXACT);
00127 }
00128 else chg_bds [index].setLowerBits(t_chg_bounds::EXACT);
00129
00130 if (csi -> getColUpper () [index] > value + COUENNE_EPS) {
00131 csi -> setColUpper (index, value);
00132 chg_bds [index].setUpperBits(t_chg_bounds::CHANGED | t_chg_bounds::EXACT);
00133 }
00134 else chg_bds [index].setUpperBits(t_chg_bounds::EXACT);
00135
00136 issimple = true;
00137
00138 } else {
00139
00140
00141 int indInd = *(deplist.begin ());
00142
00143
00144
00145
00146 if
00147 ((((chg_bds [indInd].lower() & t_chg_bounds::EXACT) &&
00148 (chg_bds [indInd].upper() & t_chg_bounds::EXACT)) ||
00149
00150
00151 (var -> Image () -> Linearity () <= LINEAR)) &&
00152 (var -> sign () == expression::AUX_EQ)) {
00153
00154 issimple = true;
00155
00156 CouNumber lb, ub;
00157 var -> Image () -> getBounds (lb, ub);
00158
00159 if (lb < Lb (index)) lb = Lb (index);
00160 if (ub > Ub (index)) ub = Ub (index);
00161
00162 if (var -> isInteger ()) {
00163 lb = ceil (lb - COUENNE_EPS);
00164 ub = floor (ub + COUENNE_EPS);
00165 }
00166
00167 if (lb > csi -> getColLower () [index] + COUENNE_EPS) {
00168 csi -> setColLower (index, lb);
00169 Lb (index) = lb;
00170 chg_bds [index].setLowerBits(t_chg_bounds::CHANGED | t_chg_bounds::EXACT);
00171 } else chg_bds [index].setLowerBits(t_chg_bounds::EXACT);
00172
00173 if (ub < csi -> getColUpper () [index] - COUENNE_EPS) {
00174 csi -> setColUpper (index, ub);
00175 Ub (index) = ub;
00176 chg_bds [index].setUpperBits(t_chg_bounds::CHANGED | t_chg_bounds::EXACT);
00177 } else chg_bds [index].setUpperBits(t_chg_bounds::EXACT);
00178 }
00179 }
00180 }
00181
00182
00183 if (!issimple &&
00184 ((Var (index) -> Type () == VAR) ||
00185 (Var (index) -> Multiplicity () > 0)) &&
00186 (Lb (index) < Ub (index) - COUENNE_EPS) &&
00187
00188 ((index != objind)
00189
00190 || ((sense == 1) && !(chg_bds [index].lower() & t_chg_bounds::EXACT))
00191 )) {
00192
00193
00194 bool isInt = (Var (index) -> isInteger ());
00195
00196 objcoe [index] = sense;
00197
00198 csi -> setObjective (objcoe);
00199 csi -> setObjSense (1);
00200
00201
00202 #if 0
00203 for (int iv=0; iv<csi->getNumCols (); iv++) {
00204 if (fabs (csi -> getColLower () [iv]) > 1e7) csi -> setColLower (iv, -1e14);
00205 if (fabs (csi -> getColUpper () [iv]) > 1e7) csi -> setColUpper (iv, 1e14);
00206 }
00207 #endif
00208
00209 CouNumber &bound =
00210 (sense == 1) ?
00211 (Lb (index)) :
00212 (Ub (index));
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 csi -> setWarmStart (warmstart);
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 bool has_updated = false;
00257
00258 if (obbt_updateBound (csi, sense, bound, isInt)) {
00259
00260 has_updated = true;
00261
00262 if (knownOptimum) {
00263 if (sense == 1) {
00264 if (bound > COUENNE_EPS + knownOptimum [index])
00265 Jnlst()->Printf(J_STRONGWARNING, J_BOUNDTIGHTENING,
00266 "#### OBBT cuts optimum at x%d: lb = %g, opt = %g, new lb = %g\n",
00267 index, Lb (index), knownOptimum [index], bound);
00268 } else {
00269 if (bound < -COUENNE_EPS + knownOptimum [index])
00270 Jnlst()->Printf(J_STRONGWARNING, J_BOUNDTIGHTENING,
00271 "#### OBBT cuts optimum at x%d: ub = %g, opt = %g, new ub = %g\n",
00272 index, Ub (index), knownOptimum [index], bound);
00273 }
00274 }
00275
00276 if (sense == 1) {if (bound > Lb (index)) Lb (index) = bound;}
00277 else {if (bound < Ub (index)) Ub (index) = bound;}
00278
00279
00280
00281 if (sense==1)
00282 if (csi -> getColLower () [index] < bound - COUENNE_EPS) {
00283 Jnlst()->Printf(J_DETAILED, J_BOUNDTIGHTENING,"l_%d: %g --> %g\n",
00284 index, csi -> getColLower () [index], bound);
00285 csi -> setColLower (index, bound);
00286 chg_bds [index].setLowerBits(t_chg_bounds::CHANGED | t_chg_bounds::EXACT);
00287 } else chg_bds [index].setLowerBits(t_chg_bounds::EXACT);
00288 else
00289 if (csi -> getColUpper () [index] > bound + COUENNE_EPS) {
00290 Jnlst()->Printf(J_DETAILED, J_BOUNDTIGHTENING,"u_%d: %g --> %g\n",
00291 index, csi -> getColUpper () [index], bound);
00292 csi -> setColUpper (index, bound);
00293 chg_bds [index].setUpperBits(t_chg_bounds::CHANGED | t_chg_bounds::EXACT);
00294 } else chg_bds [index].setUpperBits(t_chg_bounds::EXACT);
00295
00296
00297
00298
00299
00300
00301 #if 0
00302
00303
00304 CouNumber *redcost = NULL;
00305
00306
00307
00308
00309
00310 for (int j=0; j<ncols; j++)
00311 if ((j!=index) && (j!=objind)) {
00312
00313
00314
00315
00316
00317
00318
00319 if (!(chg_bds [j].lower & EXACT)) {
00320 }
00321
00322 if (!(chg_bds [j].upper & EXACT)) {
00323 }
00324 }
00325 #endif
00326
00327
00328
00329
00330
00331 Jnlst()->Printf(J_DETAILED, J_BOUNDTIGHTENING,
00332 " OBBT: x_%d: [%g, %g]\n", index,
00333 csi -> getColLower () [index],
00334 csi -> getColUpper () [index]);
00335
00336
00337
00338
00339 if (doFBBT_ && !(btCore (chg_bds))) {
00340 Jnlst () -> Printf (J_DETAILED, J_BOUNDTIGHTENING,
00341 "node is infeasible after post-OBBT tightening\n");
00342 return -1;
00343 }
00344
00345 nImprov++;
00346 }
00347
00348
00349
00350
00351 const double *sol = csi -> getColSolution ();
00352
00353 for (int j=0; j<ncols; j++)
00354 if ((j!=index) && (j!=objind)) {
00355
00356 if (sol [j] <= Lb (j) + COUENNE_EPS) {
00357
00358
00359
00360
00361 chg_bds [j].setLowerBits(t_chg_bounds::EXACT);
00362 }
00363
00364 if (sol [j] >= Ub (j) - COUENNE_EPS) {
00365
00366
00367
00368
00369 chg_bds [j].setUpperBits(t_chg_bounds::EXACT);
00370 }
00371 }
00372
00373
00374
00375 int result = obbt_supplement (csi, index, sense);
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 objcoe [index] = 0;
00389 }
00390
00391 if (nImprov && jnlst_ -> ProduceOutput (J_ITERSUMMARY, J_BOUNDTIGHTENING)) {
00392 Jnlst () -> Printf (J_ITERSUMMARY, J_BOUNDTIGHTENING, "OBBT: tightened ", nImprov);
00393 Var (index) -> print ();
00394 Jnlst () -> Printf (J_ITERSUMMARY, J_BOUNDTIGHTENING, "\n");
00395 }
00396
00397 return nImprov;
00398 }