Changeset 1569 for trunk/Cbc/src/CbcHeuristicRENS.cpp
 Timestamp:
 Jan 3, 2011 9:00:42 AM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Cbc/src/CbcHeuristicRENS.cpp
r1564 r1569 90 90 91 91 const double * currentSolution = solver>getColSolution(); 92 OsiSolverInterface * newSolver = cloneBut(3); // was model_>continuousSolver()>clone(); 93 newSolver>resolve(); 94 double direction = newSolver>getObjSense(); 95 double cutoff=model_>getCutoff(); 96 //newSolver>getDblParam(OsiDualObjectiveLimit, cutoff); 97 //cutoff *= direction; 98 double gap = cutoff  newSolver>getObjValue() * direction ; 99 double tolerance; 100 newSolver>getDblParam(OsiDualTolerance, tolerance) ; 101 if (gap > 0.0  !newSolver>isProvenOptimal()) { 102 gap += 100.0 * tolerance; 103 int nFix = newSolver>reducedCostFix(gap); 104 if (nFix) { 105 char line [200]; 106 sprintf(line, "Reduced cost fixing fixed %d variables", nFix); 107 model_>messageHandler()>message(CBC_FPUMP1, model_>messages()) 108 << line 109 << CoinMessageEol; 110 } 111 } else { 112 return 0; // finished? 113 } 92 114 int numberColumns = solver>getNumCols(); 93 115 double * dj = CoinCopyOfArray(solver>getReducedCost(),numberColumns); 94 OsiSolverInterface * newSolver = cloneBut(3); // was model_>continuousSolver()>clone();95 double direction = newSolver>getObjSense();96 116 int type = rensType_&15; 97 117 double djTolerance = (type!=1) ? 1.0e30 : 1.0e4; … … 99 119 const double * colUpper = newSolver>getColUpper(); 100 120 int numberFixed = 0; 101 if ( (type&7)==3) {121 if (type==3) { 102 122 double total=0.0; 103 123 int n=0; … … 117 137 delete basis; 118 138 } 119 } else if ((type&7)==4) { 120 double * sort = new double [numberColumns]; 121 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 122 sort[iColumn]=1.0e30; 123 if (colUpper[iColumn]>colLower[iColumn]) { 124 sort[iColumn] = fabs(dj[iColumn]); 125 } 126 } 127 std::sort(sort,sort+numberColumns); 128 int last = static_cast<int>(numberColumns*fractionSmall_); 129 djTolerance = sort[last]; 130 delete [] sort; 131 } else if ((type&7)==5(type&7)==6) { 139 } else if (type>=5&&type<=10) { 140 /* 5 fix sets at one 141 6 fix on dj but leave unfixed SOS slacks 142 7 fix sets at one but use pi 143 8 fix all at zero but leave unfixed SOS slacks 144 9 as 8 but only fix all at zero if just one in set nonzero 145 10 as 7 but pi other way 146 */ 132 147 // SOS type fixing 133 bool fixSets = (type &7)==5;148 bool fixSets = (type==5)(type==7)(type==10); 134 149 CoinWarmStartBasis * basis = 135 150 dynamic_cast<CoinWarmStartBasis *>(solver>getWarmStart()) ; … … 160 175 j < columnStart[iColumn] + columnLength[iColumn]; j++) { 161 176 int iRow = row[j]; 162 bestDj[iRow]=1.0e30; 177 if (bestDj[iRow]<1.0e30) { 178 if (element[j] != 1.0) 179 bestDj[iRow]=1.0e30; 180 else 181 bestDj[iRow]=1.0e25; 182 } 163 183 } 164 184 } else if ( basis>getStructStatus(iColumn) != … … 167 187 j < columnStart[iColumn] + columnLength[iColumn]; j++) { 168 188 int iRow = row[j]; 169 if (bestDj[iRow]<1.0e 30) {189 if (bestDj[iRow]<1.0e25) { 170 190 if (element[j] != 1.0) 171 191 bestDj[iRow]=1.0e30; … … 179 199 int nSOS=0; 180 200 double * sort = new double [numberRows]; 201 const double * pi = newSolver>getRowPrice(); 181 202 for (int i=0;i<numberRows;i++) { 182 203 if (bestDj[i]<1.0e30) { 183 sort[nSOS++]=bestDj[i]; 204 if (type==5) 205 sort[nSOS++]=bestDj[i]; 206 else if (type==7) 207 sort[nSOS++]=fabs(pi[i]); 208 else 209 sort[nSOS++]=fabs(pi[i]); 184 210 } 185 211 } … … 197 223 j < columnStart[iColumn] + columnLength[iColumn]; j++) { 198 224 int iRow = row[j]; 199 if (bestDj[iRow]<1.0e30&&bestDj[iRow]>=tolerance) { 225 double useDj; 226 if (type==5) 227 useDj = bestDj[iRow]; 228 else if (type==7) 229 useDj= fabs(pi[iRow]); 230 else 231 useDj= fabs(pi[iRow]); 232 if (bestDj[iRow]<1.0e30&&useDj>=tolerance) { 200 233 numberFixed++; 201 234 if (currentSolution[iColumn]<=1.0e6) … … 212 245 dj[iColumn] *= 0.000001; 213 246 } 247 } else if (type==8type==9) { 248 if (currentSolution[iColumn]<=1.0e6) { 249 if (type==8) { 250 dj[iColumn] *= 1.0e6; 251 } else { 252 bool fix=false; 253 for (j = columnStart[iColumn]; 254 j < columnStart[iColumn] + columnLength[iColumn]; j++) { 255 int iRow = row[j]; 256 if (bestDj[iRow]<1.0e25) { 257 fix=true; 258 break; 259 } 260 } 261 if (fix) { 262 dj[iColumn] *= 1.0e6; 263 } 264 } 265 } else { 266 dj[iColumn] *= 0.000001; 267 } 214 268 } 215 269 } … … 218 272 if (fixSets) 219 273 djTolerance = 1.0e30; 220 else221 djTolerance = tolerance;222 274 } 223 275 delete basis; … … 225 277 delete [] bestDj; 226 278 } 279 } 280 // Do dj to get right number 281 if (type==4type==6type>7) { 282 double * sort = new double [numberColumns]; 283 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 284 sort[iColumn]=1.0e30; 285 if (colUpper[iColumn]>colLower[iColumn]) { 286 sort[iColumn] = fabs(dj[iColumn]); 287 } 288 } 289 std::sort(sort,sort+numberColumns); 290 int last = static_cast<int>(numberColumns*fractionSmall_); 291 djTolerance = CoinMax(sort[last],1.0e5); 292 delete [] sort; 227 293 } 228 294
Note: See TracChangeset
for help on using the changeset viewer.