00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "CoinHelperFunctions.hpp"
00012 #include "CouenneProblem.hpp"
00013 #include "CouenneProblemElem.hpp"
00014
00015 using namespace Couenne;
00016
00017
00018
00019 int CouenneProblem::testIntFix (int index,
00020 CouNumber xFrac,
00021 enum fixType *fixed,
00022 CouNumber *xInt,
00023 CouNumber *dualL, CouNumber *dualR,
00024 CouNumber *olb, CouNumber *oub,
00025 bool patient) const {
00026 int
00027 ncols = nVars (),
00028 retval = 0,
00029 objind = Obj (0) -> Body () -> Index ();
00030
00031
00032 t_chg_bounds *f_chg = new t_chg_bounds [ncols];
00033
00034 double
00035 *llb = new double [ncols], *lub = new double [ncols],
00036 *rlb = new double [ncols], *rub = new double [ncols];
00037
00038
00039
00040 Lb (index) = Ub (index) = floor (xFrac);
00041
00042
00043
00044
00045
00046
00047
00048 f_chg [index].setLower (t_chg_bounds::CHANGED);
00049 f_chg [index].setUpper (t_chg_bounds::CHANGED);
00050
00051 bool feasLeft = btCore (f_chg);
00052
00053 dualL [index] = Lb (objind);
00054
00055
00056 CoinCopyN (Lb (), ncols, llb);
00057 CoinCopyN (Ub (), ncols, lub);
00058
00059
00060 CoinCopyN (olb, ncols, Lb ());
00061 CoinCopyN (oub, ncols, Ub ());
00062
00063
00064
00065 Lb (index) = Ub (index) = ceil (xFrac);
00066
00067 for (int j = 0; j<ncols; j++) {
00068 f_chg [j].setLower (t_chg_bounds::UNCHANGED);
00069 f_chg [j].setUpper (t_chg_bounds::UNCHANGED);
00070 }
00071
00072 f_chg [index].setLower (t_chg_bounds::CHANGED);
00073 f_chg [index].setUpper (t_chg_bounds::CHANGED);
00074
00075 bool feasRight = btCore (f_chg);
00076
00077 dualR [index] = Lb (objind);
00078
00079
00080 CoinCopyN (Lb (), ncols, rlb);
00081 CoinCopyN (Ub (), ncols, rub);
00082
00083
00084 CoinCopyN (olb, ncols, Lb ());
00085 CoinCopyN (oub, ncols, Ub ());
00086
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 if (!feasLeft)
00103
00104 if (!feasRight) {
00105
00106 jnlst_ -> Printf (Ipopt::J_MOREVECTOR, J_NLPHEURISTIC,
00107 "test on %d -> Infeasible.\n ", index);
00108 retval = -1;
00109
00110 } else {
00111
00112
00113 jnlst_ -> Printf (Ipopt::J_MOREVECTOR, J_NLPHEURISTIC,
00114 "test on %d -> Right feasible, fix to %g.\n", index, ceil (xFrac));
00115
00116 fixed [index] = FIXED;
00117 Lb (index) = Ub (index) = olb [index] = oub [index] = xInt [index] = ceil (xFrac);
00118
00119 retval++;
00120
00121
00122
00123 for (int j=0; j<ncols; j++) if (index != j) {
00124
00125 olb [j] = Lb (j) = CoinMax (Lb (j), rlb [j]);
00126 oub [j] = Ub (j) = CoinMin (Ub (j), rub [j]);
00127
00128 if (Lb (j) > Ub (j) + COUENNE_EPS)
00129 retval = -1;
00130 }
00131 }
00132 else if (!feasRight) {
00133
00134
00135 jnlst_ -> Printf (Ipopt::J_MOREVECTOR, J_NLPHEURISTIC,
00136 "test on %d -> Left feasible, fix to %g.\n", index, floor (xFrac));
00137
00138 fixed [index] = FIXED;
00139 Lb (index) = Ub (index) = olb [index] = oub [index] = xInt [index] = floor (xFrac);
00140
00141 retval++;
00142
00143
00144
00145 for (int j=0; j<ncols; j++) if (index != j) {
00146
00147 olb [j] = Lb (j) = CoinMax (Lb (j), llb [j]);
00148 oub [j] = Ub (j) = CoinMin (Ub (j), lub [j]);
00149
00150 if (Lb (j) > Ub (j) + COUENNE_EPS) {
00151 retval = -1;
00152 break;
00153 }
00154 }
00155 } else {
00156
00157
00158 for (int j=0; j<ncols; j++) {
00159
00160 olb [j] = Lb (j) = CoinMax (Lb (j), CoinMin (llb [j], rlb [j]));
00161 oub [j] = Ub (j) = CoinMin (Ub (j), CoinMax (lub [j], rub [j]));
00162
00163 if (Lb (j) > Ub (j) + COUENNE_EPS) {
00164 retval = -1;
00165 break;
00166 }
00167 }
00168
00169 if ((retval >= 0) && !patient) {
00170
00171 fixed [index] = FIXED;
00172
00173 Lb (index) = Ub (index) = olb [index] = oub [index] = xInt [index] =
00174 ((dualL [index] < dualR [index] - COUENNE_EPS) ? floor (xFrac) :
00175 (dualL [index] > dualR [index] + COUENNE_EPS) ? ceil (xFrac) :
00176 ((CoinDrand48 () < 0.5) ? floor (xFrac) : ceil (xFrac)));
00177
00178 jnlst_ -> Printf (Ipopt::J_MOREVECTOR, J_NLPHEURISTIC,
00179 "test on %d -> Both feasible, lost patience, fixed to %g.\n",
00180 index, xInt [index]);
00181
00182
00183 retval++;
00184
00185 } else if (retval >= 0) jnlst_ -> Printf (Ipopt::J_MOREVECTOR, J_NLPHEURISTIC,
00186 "test on %d -> Both feasible, skip this turn.\n", index);
00187 }
00188
00189 delete [] f_chg;
00190
00191 delete [] llb; delete [] lub;
00192 delete [] rlb; delete [] rub;
00193
00194 return retval;
00195 }