Changes from stable/2.9/Cbc/src/CbcMipStartIO.cpp at r2187 to trunk/Cbc/src/CbcMipStartIO.cpp at r2013
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Cbc/src/CbcMipStartIO.cpp
r2187 r2013 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()) << printLine << CoinMessageEol; 57 model>messageHandler()>message(CBC_GENERAL, model>messages()) 58 << printLine << CoinMessageEol; 58 59 continue; 59 60 } … … 61 62 { 62 63 sprintf( printLine, "Reading: %s, line %d  Third column in mipstart file should be numeric, ignoring.", fileName, nLine ); 63 model>messageHandler()>message(CBC_GENERAL, model>messages()) << printLine << CoinMessageEol; 64 model>messageHandler()>message(CBC_GENERAL, model>messages()) 65 << printLine << CoinMessageEol; 64 66 continue; 65 67 } 66 68 69 //int idx = atoi( col[0] ); 67 70 char *name = col[1]; 68 71 double value = atof( col[2] ); 72 //double obj = 0.0; 73 // if (nread >= 4) 74 // obj = atof( col[3] ); 69 75 70 76 colValues.push_back( pair<string, double>(string(name),value) ); … … 73 79 74 80 if (colValues.size()) { 75 sprintf( printLine,"MIPStart values read for %d variables.", static_cast<int>(colValues.size()) ); 76 model>messageHandler()>message(CBC_GENERAL, model>messages()) << printLine << CoinMessageEol; 81 sprintf( printLine,"mipstart values read for %d variables.", (int)colValues.size()); 82 model>messageHandler()>message(CBC_GENERAL, model>messages()) 83 << printLine << CoinMessageEol; 77 84 if (colValues.size()<model>getNumCols()) { 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 { 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 { 99 107 sprintf( printLine, "No mipstart solution read from %s", fileName ); 100 model>messageHandler()>message(CBC_GENERAL, model>messages()) << printLine << CoinMessageEol; 108 model>messageHandler()>message(CBC_GENERAL, model>messages()) 109 << printLine << CoinMessageEol; 101 110 return 1; 102 111 } … … 111 120 double *sol, double &obj ) 112 121 { 113 if (!model>getNumCols())114 return 0;115 116 122 int status = 0; 117 123 double compObj = COIN_DBL_MAX; … … 119 125 OsiSolverInterface *lp = model>solver()>clone(); 120 126 map< string, int > colIdx; 121 assert( ( static_cast<int>(colNames.size())) == lp>getNumCols() );127 assert( ((int)colNames.size()) == lp>getNumCols() ); 122 128 /* for fast search of column names */ 123 for ( int i=0 ; (i< static_cast<int>(colNames.size())) ; ++i )129 for ( int i=0 ; (i<(int)colNames.size()) ; ++i ) 124 130 colIdx[colNames[i]] = i; 125 131 … … 129 135 char colNotFound[256] = ""; 130 136 int nContinuousFixed = 0; 131 132 137 #ifndef JUST_FIX_INTEGER 133 138 #define JUST_FIX_INTEGER 0 134 139 #endif 135 136 140 #if JUST_FIX_INTEGER > 1 137 141 // all not mentioned are at zero 138 142 for ( int i=0 ; (i<lp>getNumCols()) ; ++i ) 139 {143 { 140 144 if (lp>isInteger(i)) 141 145 lp>setColBounds( i, 0.0, 0.0 ); 142 }143 #endif 144 for ( int i=0 ; (i< static_cast<int>(colValues.size())) ; ++i )146 } 147 #endif 148 for ( int i=0 ; (i<(int)colValues.size()) ; ++i ) 145 149 { 146 150 map< string, int >::const_iterator mIt = colIdx.find( colValues[i].first ); … … 157 161 #if JUST_FIX_INTEGER 158 162 if (!lp>isInteger(idx)) 159 163 continue; 160 164 #endif 161 165 if (v<1e8) … … 163 167 if (lp>isInteger(idx)) // just to avoid small 164 168 v = floor( v+0.5 ); // fractional garbage 165 else 166 nContinuousFixed++; 167 169 else 170 nContinuousFixed++; 168 171 lp>setColBounds( idx, v, v ); 169 172 ++fixed; … … 174 177 { 175 178 model>messageHandler()>message(CBC_GENERAL, model>messages()) 176 << "Warning: MIPstart solution is not valid, column names do not match, ignoring it."177 179 << "Warning: MIPstart solution is not valid, ignoring it." 180 << CoinMessageEol; 178 181 goto TERMINATE; 179 182 } 180 183 181 if ( notFound >= ( ( static_cast<double>(colNames.size())) * 0.5 ) ) {184 if ( notFound >= ( ((double)colNames.size()) * 0.5 ) ) { 182 185 sprintf( printLine, "Warning: %d column names were not found (e.g. %s) while filling solution.", notFound, colNotFound ); 183 184 186 model>messageHandler()>message(CBC_GENERAL, model>messages()) 187 << printLine << CoinMessageEol; 185 188 } 186 189 #if JUST_FIX_INTEGER … … 189 192 lp>setDblParam(OsiDualObjectiveLimit,COIN_DBL_MAX); 190 193 lp>initialSolve(); 191 192 if ( (lp>isProvenPrimalInfeasible())  (lp>isProvenDualInfeasible()) ) 193 { 194 //lp>writeMps("fixed","mps"); 195 if (!lp>isProvenOptimal()) 196 { 197 model>messageHandler()>message(CBC_GENERAL, model>messages()) 198 << "Warning: mipstart values could not be used to build a solution." << CoinMessageEol; 194 199 if (nContinuousFixed) { 195 model>messageHandler()>message(CBC_GENERAL, model>messages()) 196 << "Trying just fixing integer variables." << CoinMessageEol; 197 int numberColumns = lp>getNumCols(); 198 const double *oldLower = model>solver()>getColLower(); 199 const double *oldUpper = model>solver()>getColUpper(); 200 for ( int i=0 ; i<numberColumns ; ++i ) { 201 if (!lp>isInteger(i)) { 202 lp>setColLower(i,oldLower[i]); 203 lp>setColUpper(i,oldUpper[i]); 204 } 205 } 206 207 lp>initialSolve(); 208 } 209 else 210 { 211 model>messageHandler()>message(CBC_GENERAL, model>messages()) 212 << "Fixing only nonzero variables." << CoinMessageEol; 213 /* unfix all variables which are zero */ 214 int notZeroAnymore = 0; 215 for ( int i=0 ; (i<lp>getNumCols()) ; ++i ) 216 if ( ((fabs(lp>getColLower()[i])) <= 1e8) && (fabs(lp>getColLower()[i]lp>getColUpper()[i]) <= 1e8) ) 217 { 218 const double *oldLower = model>solver()>getColLower(); 219 const double *oldUpper = model>solver()>getColUpper(); 220 lp>setColLower(i,oldLower[i]); 221 lp>setColUpper(i,oldUpper[i]); 222 notZeroAnymore++; 223 } 224 if (notZeroAnymore) 225 lp>initialSolve(); 226 } 227 } 228 229 if (!lp>isProvenOptimal()) 230 { 231 model>messageHandler()>message(CBC_GENERAL, model>messages()) 232 << "Warning: mipstart values could not be used to build a solution." << CoinMessageEol; 233 status = 1; 234 goto TERMINATE; 235 } 236 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 237 222 /* some additional effort is needed to provide an integer solution */ 238 223 if ( lp>getFractionalIndices().size() > 0 ) 239 224 { 240 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()) );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() ); 241 226 model>messageHandler()>message(CBC_GENERAL, model>messages()) 242 227 << printLine << CoinMessageEol; … … 261 246 #else 262 247 CbcModel babModel( *lp ); 263 lp>writeLp("lessFix"); 264 babModel.setLogLevel( 2 ); 265 babModel.setMaximumNodes( 1000 ); 248 babModel.setLogLevel( 0 ); 249 babModel.setMaximumNodes( 500 ); 266 250 babModel.setMaximumSeconds( 60 ); 267 251 babModel.branchAndBound(); … … 279 263 else 280 264 { 281 282 265 model>messageHandler()>message(CBC_GENERAL, model>messages()) 266 << "Warning: mipstart values could not be used to build a solution." << CoinMessageEol; 283 267 status = 1; 284 268 goto TERMINATE; … … 294 278 if ( foundIntegerSol ) 295 279 { 296 sprintf( printLine," MIPStart provided solution with cost %g", compObj);297 model>messageHandler()>message(CBC_GENERAL, model>messages()) 298 280 sprintf( printLine,"mipstart provided solution with cost %g", compObj); 281 model>messageHandler()>message(CBC_GENERAL, model>messages()) 282 << printLine << CoinMessageEol; 299 283 #if 0 300 284 {
Note: See TracChangeset
for help on using the changeset viewer.