Changeset 2186
- Timestamp:
- May 5, 2015 8:53:14 AM (6 years ago)
- Location:
- stable/2.9/Cbc
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
stable/2.9/Cbc
- Property svn:mergeinfo changed
/trunk/Cbc merged: 2113,2120-2122,2125-2126,2128,2133,2137,2144,2146,2151-2152
- Property svn:mergeinfo changed
-
stable/2.9/Cbc/src
- Property svn:mergeinfo changed
/trunk/Cbc/src merged: 2113,2122,2125,2128,2133,2137,2144,2146,2151-2152
- Property svn:mergeinfo changed
-
stable/2.9/Cbc/src/CbcCutGenerator.cpp
r2174 r2186 677 677 if (debugger && debugger->onOptimalPath(*solver)) { 678 678 if(debugger->invalidCut(*thisCut)) { 679 #if CGL_DEBUG>1 680 const double * optimal = debugger->optimalSolution(); 681 CoinPackedVector rpv = thisCut->row(); 682 const int n = rpv.getNumElements(); 683 const int * indices = rpv.getIndices(); 684 const double * elements = rpv.getElements(); 685 686 double lb=thisCut->lb(); 687 double ub=thisCut->ub(); 688 double sum=0.0; 689 690 for (int k=0; k<n; k++){ 691 int column=indices[k]; 692 sum += optimal[column]*elements[k]; 693 } 694 // is it nearly violated 695 if (sum >ub - 1.0e-8 ||sum < lb + 1.0e-8) { 696 double violation=CoinMax(sum-ub,lb-sum); 697 std::cout<<generatorName_<<" cut with "<<n 698 <<" coefficients, nearly cuts off known solutions by "<<violation 699 <<", lo="<<lb<<", ub="<<ub<<std::endl; 700 for (int k=0; k<n; k++){ 701 int column=indices[k]; 702 std::cout<<"( "<<column<<" , "<<elements[k]<<" ) "; 703 if ((k%4)==3) 704 std::cout <<std::endl; 705 } 706 std::cout <<std::endl; 707 std::cout <<"Non zero solution values are"<<std::endl; 708 int j=0; 709 for (int k=0; k<n; k++){ 710 int column=indices[k]; 711 if (fabs(optimal[column])>1.0e-9) { 712 std::cout<<"( "<<column<<" , "<<optimal[column]<<" ) "; 713 if ((j%4)==3) 714 std::cout <<std::endl; 715 j++; 716 } 717 } 718 std::cout <<std::endl; 719 } 720 #endif 721 assert(!debugger->invalidCut(*thisCut)); 722 if(debugger->invalidCut(*thisCut)) 679 723 abort(); 680 724 } -
stable/2.9/Cbc/src/CbcHeuristicFPump.cpp
r2094 r2186 2139 2139 double value = newSolver->getObjValue() * newSolver->getObjSense(); 2140 2140 if (value < newSolutionValue) { 2141 //newSolver->writeMps("query","mps");2141 //newSolver->writeMpsNative("query.mps", NULL, NULL, 2); 2142 2142 #ifdef JJF_ZERO 2143 2143 { … … 2209 2209 << pumpPrint 2210 2210 << CoinMessageEol; 2211 //newSolver->writeMpsNative("query2.mps", NULL, NULL, 2); 2211 2212 newSolutionValue = value; 2212 2213 memcpy(betterSolution, newSolver->getColSolution(), numberColumns*sizeof(double)); -
stable/2.9/Cbc/src/CbcMipStartIO.cpp
r2013 r2186 55 55 { 56 56 sprintf( printLine, "Reading: %s, line %d - first column in mipstart file should be numeric, ignoring.", fileName, nLine ); 57 model->messageHandler()->message(CBC_GENERAL, model->messages()) 58 << printLine << CoinMessageEol; 57 model->messageHandler()->message(CBC_GENERAL, model->messages()) << printLine << CoinMessageEol; 59 58 continue; 60 59 } … … 62 61 { 63 62 sprintf( printLine, "Reading: %s, line %d - Third column in mipstart file should be numeric, ignoring.", fileName, nLine ); 64 model->messageHandler()->message(CBC_GENERAL, model->messages()) 65 << printLine << CoinMessageEol; 63 model->messageHandler()->message(CBC_GENERAL, model->messages()) << printLine << CoinMessageEol; 66 64 continue; 67 65 } 68 66 69 //int idx = atoi( col[0] );70 67 char *name = col[1]; 71 68 double value = atof( col[2] ); 72 //double obj = 0.0;73 // if (nread >= 4)74 // obj = atof( col[3] );75 69 76 70 colValues.push_back( pair<string, double>(string(name),value) ); … … 79 73 80 74 if (colValues.size()) { 81 sprintf( printLine,"mipstart values read for %d variables.", (int)colValues.size()); 82 model->messageHandler()->message(CBC_GENERAL, model->messages()) 83 << printLine << CoinMessageEol; 75 sprintf( printLine,"MIPStart values read for %d variables.", static_cast<int>(colValues.size()) ); 76 model->messageHandler()->message(CBC_GENERAL, model->messages()) << printLine << CoinMessageEol; 84 77 if (colValues.size()<model->getNumCols()) { 85 int numberColumns = model->getNumCols(); 86 OsiSolverInterface * solver = model->solver(); 87 vector< pair< string, double > > fullValues; 88 /* for fast search of column names */ 89 map< string, int > colIdx; 90 for (int i=0;i<numberColumns;i++) { 91 fullValues.push_back( pair<string, double>(solver->getColName(i),0.0) ); 92 colIdx[solver->getColName(i)] = i; 93 } 94 for ( int i=0 ; (i<(int)colValues.size()) ; ++i ) 95 { 96 map< string, int >::const_iterator mIt = colIdx.find( colValues[i].first ); 97 if ( mIt != colIdx.end() ) { 98 const int idx = mIt->second; 99 double v = colValues[i].second; 100 fullValues[idx].second=v; 101 } 102 } 103 colValues=fullValues; 104 } 105 } else 106 { 78 int numberColumns = model->getNumCols(); 79 OsiSolverInterface *solver = model->solver(); 80 vector< pair< string, double > > fullValues; 81 /* for fast search of column names */ 82 map< string, int > colIdx; 83 for (int i=0;i<numberColumns;i++) { 84 fullValues.push_back( pair<string, double>(solver->getColName(i),0.0) ); 85 colIdx[solver->getColName(i)] = i; 86 } 87 for ( int i=0 ; (i<static_cast<int>(colValues.size())) ; ++i ) { 88 map< string, int >::const_iterator mIt = colIdx.find( colValues[i].first ); 89 if ( mIt != colIdx.end() ) { 90 const int idx = mIt->second; 91 double v = colValues[i].second; 92 fullValues[idx].second=v; 93 } 94 } 95 colValues=fullValues; 96 } 97 } 98 else { 107 99 sprintf( printLine, "No mipstart solution read from %s", fileName ); 108 model->messageHandler()->message(CBC_GENERAL, model->messages()) 109 << printLine << CoinMessageEol; 100 model->messageHandler()->message(CBC_GENERAL, model->messages()) << printLine << CoinMessageEol; 110 101 return 1; 111 102 } … … 125 116 OsiSolverInterface *lp = model->solver()->clone(); 126 117 map< string, int > colIdx; 127 assert( ( (int)colNames.size()) == lp->getNumCols() );118 assert( (static_cast<int>(colNames.size())) == lp->getNumCols() ); 128 119 /* for fast search of column names */ 129 for ( int i=0 ; (i< (int)colNames.size()) ; ++i )120 for ( int i=0 ; (i<static_cast<int>(colNames.size())) ; ++i ) 130 121 colIdx[colNames[i]] = i; 131 122 … … 135 126 char colNotFound[256] = ""; 136 127 int nContinuousFixed = 0; 128 137 129 #ifndef JUST_FIX_INTEGER 138 130 #define JUST_FIX_INTEGER 0 139 131 #endif 132 140 133 #if JUST_FIX_INTEGER > 1 141 134 // all not mentioned are at zero 142 135 for ( int i=0 ; (i<lp->getNumCols()) ; ++i ) 143 136 { 144 137 if (lp->isInteger(i)) 145 138 lp->setColBounds( i, 0.0, 0.0 ); 146 }147 #endif 148 for ( int i=0 ; (i< (int)colValues.size()) ; ++i )139 } 140 #endif 141 for ( int i=0 ; (i<static_cast<int>(colValues.size())) ; ++i ) 149 142 { 150 143 map< string, int >::const_iterator mIt = colIdx.find( colValues[i].first ); … … 161 154 #if JUST_FIX_INTEGER 162 155 if (!lp->isInteger(idx)) 163 156 continue; 164 157 #endif 165 158 if (v<1e-8) … … 167 160 if (lp->isInteger(idx)) // just to avoid small 168 161 v = floor( v+0.5 ); // fractional garbage 169 else 170 nContinuousFixed++; 162 else 163 nContinuousFixed++; 164 171 165 lp->setColBounds( idx, v, v ); 172 166 ++fixed; … … 177 171 { 178 172 model->messageHandler()->message(CBC_GENERAL, model->messages()) 179 << "Warning: MIPstart solution is not valid, ignoring it."180 173 << "Warning: MIPstart solution is not valid, column names do not match, ignoring it." 174 << CoinMessageEol; 181 175 goto TERMINATE; 182 176 } 183 177 184 if ( notFound >= ( ( (double)colNames.size()) * 0.5 ) ) {178 if ( notFound >= ( (static_cast<double>(colNames.size())) * 0.5 ) ) { 185 179 sprintf( printLine, "Warning: %d column names were not found (e.g. %s) while filling solution.", notFound, colNotFound ); 186 model->messageHandler()->message(CBC_GENERAL, model->messages())187 180 model->messageHandler()->message(CBC_GENERAL, model->messages()) 181 << printLine << CoinMessageEol; 188 182 } 189 183 #if JUST_FIX_INTEGER … … 192 186 lp->setDblParam(OsiDualObjectiveLimit,COIN_DBL_MAX); 193 187 lp->initialSolve(); 194 //lp->writeMps("fixed","mps"); 188 189 if ( (lp->isProvenPrimalInfeasible()) || (lp->isProvenDualInfeasible()) ) 190 { 191 if (nContinuousFixed) { 192 model->messageHandler()->message(CBC_GENERAL, model->messages()) 193 << "Trying just fixing integer variables." << CoinMessageEol; 194 int numberColumns = lp->getNumCols(); 195 const double *oldLower = model->solver()->getColLower(); 196 const double *oldUpper = model->solver()->getColUpper(); 197 for ( int i=0 ; i<numberColumns ; ++i ) { 198 if (!lp->isInteger(i)) { 199 lp->setColLower(i,oldLower[i]); 200 lp->setColUpper(i,oldUpper[i]); 201 } 202 } 203 204 lp->initialSolve(); 205 } 206 else 207 { 208 model->messageHandler()->message(CBC_GENERAL, model->messages()) 209 << "Fixing only non-zero variables." << CoinMessageEol; 210 /* unfix all variables which are zero */ 211 int notZeroAnymore = 0; 212 for ( int i=0 ; (i<lp->getNumCols()) ; ++i ) 213 if ( ((fabs(lp->getColLower()[i])) <= 1e-8) && (fabs(lp->getColLower()[i]-lp->getColUpper()[i]) <= 1e-8) ) 214 { 215 const double *oldLower = model->solver()->getColLower(); 216 const double *oldUpper = model->solver()->getColUpper(); 217 lp->setColLower(i,oldLower[i]); 218 lp->setColUpper(i,oldUpper[i]); 219 notZeroAnymore++; 220 } 221 if (notZeroAnymore) 222 lp->initialSolve(); 223 } 224 } 225 195 226 if (!lp->isProvenOptimal()) 196 227 { 197 228 model->messageHandler()->message(CBC_GENERAL, model->messages()) 198 << "Warning: mipstart values could not be used to build a solution." << CoinMessageEol; 199 if (nContinuousFixed) { 200 model->messageHandler()->message(CBC_GENERAL, model->messages()) 201 << "Trying just fixing integer variables." << CoinMessageEol; 202 int numberColumns = lp->getNumCols(); 203 const double * oldLower = model->solver()->getColLower(); 204 const double * oldUpper = model->solver()->getColUpper(); 205 for ( int i=0 ; i<numberColumns ; ++i ) { 206 if (!lp->isInteger(i)) { 207 lp->setColLower(i,oldLower[i]); 208 lp->setColUpper(i,oldUpper[i]); 209 } 210 } 211 lp->initialSolve(); 212 if (!lp->isProvenOptimal()) 213 model->messageHandler()->message(CBC_GENERAL, model->messages()) 214 << "Still no good." << CoinMessageEol; 215 } 216 if (!lp->isProvenOptimal()) { 217 status = 1; 218 goto TERMINATE; 219 } 220 } 221 229 << "Warning: mipstart values could not be used to build a solution." << CoinMessageEol; 230 status = 1; 231 goto TERMINATE; 232 } 233 222 234 /* some additional effort is needed to provide an integer solution */ 223 235 if ( lp->getFractionalIndices().size() > 0 ) 224 236 { 225 sprintf( printLine,"MIPStart solution provided values for %d of %d integer variables, %d variables are still fractional.", fixed, lp->getNumIntegers(), (int)lp->getFractionalIndices().size() );237 sprintf( printLine,"MIPStart solution provided values for %d of %d integer variables, %d variables are still fractional.", fixed, lp->getNumIntegers(), static_cast<int>(lp->getFractionalIndices().size()) ); 226 238 model->messageHandler()->message(CBC_GENERAL, model->messages()) 227 239 << printLine << CoinMessageEol; … … 246 258 #else 247 259 CbcModel babModel( *lp ); 248 babModel.setLogLevel( 0 ); 249 babModel.setMaximumNodes( 500 ); 260 lp->writeLp("lessFix"); 261 babModel.setLogLevel( 2 ); 262 babModel.setMaximumNodes( 1000 ); 250 263 babModel.setMaximumSeconds( 60 ); 251 264 babModel.branchAndBound(); … … 263 276 else 264 277 { 265 266 278 model->messageHandler()->message(CBC_GENERAL, model->messages()) 279 << "Warning: mipstart values could not be used to build a solution." << CoinMessageEol; 267 280 status = 1; 268 281 goto TERMINATE; … … 278 291 if ( foundIntegerSol ) 279 292 { 280 sprintf( printLine," mipstart provided solution with cost %g", compObj);293 sprintf( printLine,"MIPStart provided solution with cost %g", compObj); 281 294 model->messageHandler()->message(CBC_GENERAL, model->messages()) 282 295 << printLine << CoinMessageEol; 283 296 #if 0 284 297 { -
stable/2.9/Cbc/src/CbcModel.cpp
r2165 r2186 7092 7092 if (name) 7093 7093 heuristic_[where]->setHeuristicName(name) ; 7094 #ifndef SAME_HEURISTIC_SEED 7094 7095 heuristic_[where]->setSeed(987654321 + where); 7096 #else 7097 heuristic_[where]->setSeed(987654321); 7098 #endif 7095 7099 numberHeuristics_++ ; 7096 7100 } … … 7852 7856 feasible = false; // pretend infeasible 7853 7857 } 7858 //#define CHECK_KNOWN_SOLUTION 7859 #ifdef CHECK_KNOWN_SOLUTION 7860 if (onOptimalPath && (solver_->isDualObjectiveLimitReached()|| 7861 !feasible)) { 7862 printf("help 1\n"); 7863 } 7864 #endif 7854 7865 /* 7855 7866 NEW_UPDATE_OBJECT is defined to 0 when unthreaded (CBC_THREAD undefined), 2 … … 9224 9235 } 9225 9236 // add in any active cuts if at root node (for multiple solvers) 9237 #ifdef CHECK_KNOWN_SOLUTION 9238 if (onOptimalPath && (solver_->isDualObjectiveLimitReached()|| 9239 !feasible)) { 9240 printf("help 2\n"); 9241 } 9242 #endif 9226 9243 if (!numberNodes_) { 9227 9244 for (i = 0; i < numberCutGenerators_; i++) … … 9625 9642 } 9626 9643 #endif 9644 #ifdef CHECK_KNOWN_SOLUTION 9645 if (onOptimalPath && (solver_->isDualObjectiveLimitReached()|| 9646 !feasible)) { 9647 printf("help\n"); 9648 } 9649 #endif 9627 9650 #ifdef CBC_DEBUG 9628 9651 if (onOptimalPath && !solver_->isDualObjectiveLimitReached()) … … 9983 10006 const CoinWarmStartBasis* ws ; 9984 10007 CoinWarmStartBasis::Status status ; 10008 //#define COIN_HAS_CLP_KEEP_STATUS 10009 #ifdef COIN_HAS_CLP_KEEP_STATUS 10010 int problemStatus=-1; 10011 OsiClpSolverInterface * clpSolver 10012 = dynamic_cast<OsiClpSolverInterface *> (solver_); 10013 if (clpSolver) 10014 problemStatus=clpSolver->getModelPtr()->status(); 10015 #endif 9985 10016 bool needPurge = true ; 9986 10017 /* … … 10136 10167 } 10137 10168 10169 #ifdef COIN_HAS_CLP_KEEP_STATUS 10170 // need to check further that only zero duals dropped 10171 if (clpSolver) // status may have got to -1 10172 clpSolver->getModelPtr()->setProblemStatus(problemStatus); 10173 #endif 10138 10174 /* 10139 10175 Clean up and return. … … 14319 14355 } 14320 14356 } 14357 #ifdef CHECK_KNOWN_SOLUTION 14358 bool onOptimalPath = false; 14359 if ((specialOptions_&1) != 0) { 14360 const OsiRowCutDebugger *debugger = solver_->getRowCutDebugger() ; 14361 if (debugger) { 14362 onOptimalPath = true; 14363 printf("On optimal path before resolve\n") ; 14364 } 14365 } 14366 #endif 14321 14367 clpSolver->resolve(); 14368 #ifdef CHECK_KNOWN_SOLUTION 14369 if ((specialOptions_&1) != 0&&onOptimalPath) { 14370 const OsiRowCutDebugger *debugger = solver_->getRowCutDebugger() ; 14371 if (debugger) { 14372 printf("On optimal path after resolve\n") ; 14373 } else { 14374 solver_->writeMpsNative("badSolve.mps", NULL, NULL, 2); 14375 printf("NOT on optimal path after resolve\n") ; 14376 } 14377 } 14378 #endif 14322 14379 if (!numberNodes_) { 14323 14380 double error = CoinMax(clpSimplex->largestDualError(), -
stable/2.9/Cbc/src/CbcSolver.cpp
r2180 r2186 8457 8457 fileName = directory + field; 8458 8458 } 8459 sprintf(generalPrint,"will open mipstart file %s.",fileName.c_str() ); 8460 generalMessageHandler->message(CLP_GENERAL, generalMessages) 8461 << generalPrint 8462 << CoinMessageEol; 8459 sprintf(generalPrint,"opening mipstart file %s.",fileName.c_str() ); 8460 generalMessageHandler->message(CLP_GENERAL, generalMessages) << generalPrint << CoinMessageEol; 8463 8461 double msObj; 8464 8462 readMIPStart( &model_, fileName.c_str(), mipStart, msObj ); 8465 8466 8467 8468 8469 8470 8471 8472 8463 // copy to before preprocess if has .before. 8464 if (strstr(fileName.c_str(),".before.")) { 8465 mipStartBefore = mipStart; 8466 sprintf(generalPrint,"file %s will be used before preprocessing.",fileName.c_str() ); 8467 generalMessageHandler->message(CLP_GENERAL, generalMessages) 8468 << generalPrint 8469 << CoinMessageEol; 8470 } 8473 8471 } else { 8474 8475 8472 sprintf(generalPrint, "** Current model not valid"); 8473 printGeneralMessage(model_,generalPrint); 8476 8474 } 8477 8475 break;
Note: See TracChangeset
for help on using the changeset viewer.