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 dualBound = objind >= 0 ? Lb (objind) : Obj (0) -> Body () -> Value ();
00038
00039
00040
00041 Lb (index) = Ub (index) = floor (xFrac);
00042
00043
00044
00045
00046
00047
00048
00049 f_chg [index].setLower (t_chg_bounds::CHANGED);
00050 f_chg [index].setUpper (t_chg_bounds::CHANGED);
00051
00052 bool feasLeft = btCore (f_chg);
00053
00054 dualL [index] = dualBound;
00055
00056
00057 CoinCopyN (Lb (), ncols, llb);
00058 CoinCopyN (Ub (), ncols, lub);
00059
00060
00061 CoinCopyN (olb, ncols, Lb ());
00062 CoinCopyN (oub, ncols, Ub ());
00063
00064
00065
00066 Lb (index) = Ub (index) = ceil (xFrac);
00067
00068 for (int j = 0; j<ncols; j++) {
00069 f_chg [j].setLower (t_chg_bounds::UNCHANGED);
00070 f_chg [j].setUpper (t_chg_bounds::UNCHANGED);
00071 }
00072
00073 f_chg [index].setLower (t_chg_bounds::CHANGED);
00074 f_chg [index].setUpper (t_chg_bounds::CHANGED);
00075
00076 bool feasRight = btCore (f_chg);
00077
00078 dualR [index] = dualBound;
00079
00080
00081 CoinCopyN (Lb (), ncols, rlb);
00082 CoinCopyN (Ub (), ncols, rub);
00083
00084
00085 CoinCopyN (olb, ncols, Lb ());
00086 CoinCopyN (oub, ncols, Ub ());
00087
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 if (!feasLeft)
00104
00105 if (!feasRight) {
00106
00107 jnlst_ -> Printf (Ipopt::J_MOREVECTOR, J_NLPHEURISTIC,
00108 "test on %d -> Infeasible.\n ", index);
00109 retval = -1;
00110
00111 } else {
00112
00113
00114 jnlst_ -> Printf (Ipopt::J_MOREVECTOR, J_NLPHEURISTIC,
00115 "test on %d -> Right feasible, fix to %g.\n", index, ceil (xFrac));
00116
00117 fixed [index] = FIXED;
00118 Lb (index) = Ub (index) = olb [index] = oub [index] = xInt [index] = ceil (xFrac);
00119
00120 retval++;
00121
00122
00123
00124 for (int j=0; j<ncols; j++) if (index != j) {
00125
00126 olb [j] = Lb (j) = CoinMax (Lb (j), rlb [j]);
00127 oub [j] = Ub (j) = CoinMin (Ub (j), rub [j]);
00128
00129 if (Lb (j) > Ub (j) + COUENNE_EPS)
00130 retval = -1;
00131 }
00132 }
00133 else if (!feasRight) {
00134
00135
00136 jnlst_ -> Printf (Ipopt::J_MOREVECTOR, J_NLPHEURISTIC,
00137 "test on %d -> Left feasible, fix to %g.\n", index, floor (xFrac));
00138
00139 fixed [index] = FIXED;
00140 Lb (index) = Ub (index) = olb [index] = oub [index] = xInt [index] = floor (xFrac);
00141
00142 retval++;
00143
00144
00145
00146 for (int j=0; j<ncols; j++) if (index != j) {
00147
00148 olb [j] = Lb (j) = CoinMax (Lb (j), llb [j]);
00149 oub [j] = Ub (j) = CoinMin (Ub (j), lub [j]);
00150
00151 if (Lb (j) > Ub (j) + COUENNE_EPS) {
00152 retval = -1;
00153 break;
00154 }
00155 }
00156 } else {
00157
00158
00159 for (int j=0; j<ncols; j++) {
00160
00161 olb [j] = Lb (j) = CoinMax (Lb (j), CoinMin (llb [j], rlb [j]));
00162 oub [j] = Ub (j) = CoinMin (Ub (j), CoinMax (lub [j], rub [j]));
00163
00164 if (Lb (j) > Ub (j) + COUENNE_EPS) {
00165 retval = -1;
00166 break;
00167 }
00168 }
00169
00170 if ((retval >= 0) && !patient) {
00171
00172 fixed [index] = FIXED;
00173
00174 Lb (index) = Ub (index) = olb [index] = oub [index] = xInt [index] =
00175 ((dualL [index] < dualR [index] - COUENNE_EPS) ? floor (xFrac) :
00176 (dualL [index] > dualR [index] + COUENNE_EPS) ? ceil (xFrac) :
00177 ((CoinDrand48 () < 0.5) ? floor (xFrac) : ceil (xFrac)));
00178
00179 jnlst_ -> Printf (Ipopt::J_MOREVECTOR, J_NLPHEURISTIC,
00180 "test on %d -> Both feasible, lost patience, fixed to %g.\n",
00181 index, xInt [index]);
00182
00183
00184 retval++;
00185
00186 } else if (retval >= 0) jnlst_ -> Printf (Ipopt::J_MOREVECTOR, J_NLPHEURISTIC,
00187 "test on %d -> Both feasible, skip this turn.\n", index);
00188 }
00189
00190 delete [] f_chg;
00191
00192 delete [] llb; delete [] lub;
00193 delete [] rlb; delete [] rub;
00194
00195 return retval;
00196 }