[1271] | 1 | /* $Id: CbcNode.cpp 1432 2010-02-07 19:33:53Z bjarni $ */ |
---|
[2] | 2 | // Copyright (C) 2002, International Business Machines |
---|
| 3 | // Corporation and others. All Rights Reserved. |
---|
| 4 | #if defined(_MSC_VER) |
---|
| 5 | // Turn off compiler warning about long names |
---|
| 6 | # pragma warning(disable:4786) |
---|
| 7 | #endif |
---|
[311] | 8 | |
---|
[325] | 9 | #include "CbcConfig.h" |
---|
[311] | 10 | |
---|
[2] | 11 | #include <string> |
---|
| 12 | //#define CBC_DEBUG 1 |
---|
| 13 | //#define CHECK_CUT_COUNTS |
---|
[135] | 14 | //#define CHECK_NODE |
---|
[687] | 15 | //#define CBC_CHECK_BASIS |
---|
[2] | 16 | #include <cassert> |
---|
| 17 | #include <cfloat> |
---|
| 18 | #define CUTS |
---|
| 19 | #include "OsiSolverInterface.hpp" |
---|
[640] | 20 | #include "OsiChooseVariable.hpp" |
---|
[264] | 21 | #include "OsiAuxInfo.hpp" |
---|
[222] | 22 | #include "OsiSolverBranch.hpp" |
---|
[2] | 23 | #include "CoinWarmStartBasis.hpp" |
---|
[35] | 24 | #include "CoinTime.hpp" |
---|
[2] | 25 | #include "CbcModel.hpp" |
---|
| 26 | #include "CbcNode.hpp" |
---|
[259] | 27 | #include "CbcStatistics.hpp" |
---|
[271] | 28 | #include "CbcStrategy.hpp" |
---|
[2] | 29 | #include "CbcBranchActual.hpp" |
---|
[135] | 30 | #include "CbcBranchDynamic.hpp" |
---|
[2] | 31 | #include "OsiRowCut.hpp" |
---|
| 32 | #include "OsiRowCutDebugger.hpp" |
---|
| 33 | #include "OsiCuts.hpp" |
---|
| 34 | #include "CbcCountRowCut.hpp" |
---|
[165] | 35 | #include "CbcFeasibilityBase.hpp" |
---|
[2] | 36 | #include "CbcMessage.hpp" |
---|
[311] | 37 | #ifdef COIN_HAS_CLP |
---|
[2] | 38 | #include "OsiClpSolverInterface.hpp" |
---|
[122] | 39 | #include "ClpSimplexOther.hpp" |
---|
[277] | 40 | #endif |
---|
[2] | 41 | using namespace std; |
---|
| 42 | #include "CglCutGenerator.hpp" |
---|
[912] | 43 | |
---|
| 44 | |
---|
[2] | 45 | CbcNode::CbcNode() : |
---|
[1286] | 46 | nodeInfo_(NULL), |
---|
| 47 | objectiveValue_(1.0e100), |
---|
| 48 | guessedObjectiveValue_(1.0e100), |
---|
| 49 | sumInfeasibilities_(0.0), |
---|
| 50 | branch_(NULL), |
---|
| 51 | depth_(-1), |
---|
| 52 | numberUnsatisfied_(0), |
---|
| 53 | nodeNumber_(-1), |
---|
| 54 | state_(0) |
---|
[2] | 55 | { |
---|
| 56 | #ifdef CHECK_NODE |
---|
[1286] | 57 | printf("CbcNode %x Constructor\n", this); |
---|
[2] | 58 | #endif |
---|
| 59 | } |
---|
[838] | 60 | // Print |
---|
[1286] | 61 | void |
---|
[838] | 62 | CbcNode::print() const |
---|
| 63 | { |
---|
[1286] | 64 | printf("number %d obj %g depth %d sumun %g nunsat %d state %d\n", |
---|
| 65 | nodeNumber_, objectiveValue_, depth_, sumInfeasibilities_, numberUnsatisfied_, state_); |
---|
[838] | 66 | } |
---|
[2] | 67 | CbcNode::CbcNode(CbcModel * model, |
---|
[1286] | 68 | CbcNode * lastNode) : |
---|
| 69 | nodeInfo_(NULL), |
---|
| 70 | objectiveValue_(1.0e100), |
---|
| 71 | guessedObjectiveValue_(1.0e100), |
---|
| 72 | sumInfeasibilities_(0.0), |
---|
| 73 | branch_(NULL), |
---|
| 74 | depth_(-1), |
---|
| 75 | numberUnsatisfied_(0), |
---|
| 76 | nodeNumber_(-1), |
---|
| 77 | state_(0) |
---|
[2] | 78 | { |
---|
| 79 | #ifdef CHECK_NODE |
---|
[1286] | 80 | printf("CbcNode %x Constructor from model\n", this); |
---|
[2] | 81 | #endif |
---|
[1286] | 82 | model->setObjectiveValue(this, lastNode); |
---|
| 83 | |
---|
| 84 | if (lastNode) { |
---|
| 85 | if (lastNode->nodeInfo_) { |
---|
| 86 | lastNode->nodeInfo_->increment(); |
---|
| 87 | } |
---|
[838] | 88 | } |
---|
[1286] | 89 | nodeNumber_ = model->getNodeCount(); |
---|
[2] | 90 | } |
---|
| 91 | |
---|
[640] | 92 | #define CBC_NEW_CREATEINFO |
---|
| 93 | #ifdef CBC_NEW_CREATEINFO |
---|
[2] | 94 | |
---|
[640] | 95 | /* |
---|
| 96 | New createInfo, with basis manipulation hidden inside mergeBasis. Allows |
---|
| 97 | solvers to override and carry over all information from one basis to |
---|
| 98 | another. |
---|
| 99 | */ |
---|
| 100 | |
---|
[2] | 101 | void |
---|
| 102 | CbcNode::createInfo (CbcModel *model, |
---|
[1286] | 103 | CbcNode *lastNode, |
---|
| 104 | const CoinWarmStartBasis *lastws, |
---|
| 105 | const double *lastLower, const double *lastUpper, |
---|
| 106 | int numberOldActiveCuts, int numberNewCuts) |
---|
| 107 | |
---|
| 108 | { |
---|
| 109 | OsiSolverInterface *solver = model->solver(); |
---|
| 110 | CbcStrategy *strategy = model->strategy(); |
---|
[1271] | 111 | /* |
---|
[1286] | 112 | The root --- no parent. Create full basis and bounds information. |
---|
[1271] | 113 | */ |
---|
[1286] | 114 | if (!lastNode) { |
---|
| 115 | if (!strategy) |
---|
| 116 | nodeInfo_ = new CbcFullNodeInfo(model, solver->getNumRows()); |
---|
| 117 | else |
---|
| 118 | nodeInfo_ = strategy->fullNodeInfo(model, solver->getNumRows()); |
---|
| 119 | } else { |
---|
| 120 | /* |
---|
| 121 | Not the root. Create an edit from the parent's basis & bound information. |
---|
| 122 | This is not quite as straightforward as it seems. We need to reintroduce |
---|
| 123 | cuts we may have dropped out of the basis, in the correct position, because |
---|
| 124 | this whole process is strictly positional. Start by grabbing the current |
---|
| 125 | basis. |
---|
| 126 | */ |
---|
| 127 | bool mustDeleteBasis; |
---|
| 128 | const CoinWarmStartBasis *ws = |
---|
| 129 | dynamic_cast<const CoinWarmStartBasis*>(solver->getPointerToWarmStart(mustDeleteBasis)); |
---|
| 130 | assert(ws != NULL); // make sure not volume |
---|
| 131 | //int numberArtificials = lastws->getNumArtificial(); |
---|
| 132 | int numberColumns = solver->getNumCols(); |
---|
| 133 | int numberRowsAtContinuous = model->numberRowsAtContinuous(); |
---|
| 134 | int currentNumberCuts = model->currentNumberCuts(); |
---|
[640] | 135 | # ifdef CBC_CHECK_BASIS |
---|
[1286] | 136 | std::cout |
---|
| 137 | << "Before expansion: orig " << numberRowsAtContinuous |
---|
| 138 | << ", old " << numberOldActiveCuts |
---|
| 139 | << ", new " << numberNewCuts |
---|
| 140 | << ", current " << currentNumberCuts << "." << std::endl ; |
---|
| 141 | ws->print(); |
---|
[640] | 142 | # endif |
---|
[1286] | 143 | /* |
---|
| 144 | Clone the basis and resize it to hold the structural constraints, plus |
---|
| 145 | all the cuts: old cuts, both active and inactive (currentNumberCuts), |
---|
| 146 | and new cuts (numberNewCuts). This will become the expanded basis. |
---|
| 147 | */ |
---|
| 148 | CoinWarmStartBasis *expanded = |
---|
| 149 | dynamic_cast<CoinWarmStartBasis *>(ws->clone()) ; |
---|
| 150 | int iCompact = numberRowsAtContinuous + numberOldActiveCuts + numberNewCuts ; |
---|
| 151 | // int nPartial = numberRowsAtContinuous+currentNumberCuts; |
---|
| 152 | int iFull = numberRowsAtContinuous + currentNumberCuts + numberNewCuts; |
---|
| 153 | // int maxBasisLength = ((iFull+15)>>4)+((numberColumns+15)>>4); |
---|
| 154 | // printf("l %d full %d\n",maxBasisLength,iFull); |
---|
| 155 | expanded->resize(iFull, numberColumns); |
---|
[640] | 156 | # ifdef CBC_CHECK_BASIS |
---|
[1286] | 157 | std::cout |
---|
| 158 | << "\tFull basis " << iFull << " rows, " |
---|
| 159 | << numberColumns << " columns; compact " |
---|
| 160 | << iCompact << " rows." << std::endl ; |
---|
[640] | 161 | # endif |
---|
[1286] | 162 | /* |
---|
| 163 | Now flesh out the expanded basis. The clone already has the |
---|
| 164 | correct status information for the variables and for the structural |
---|
| 165 | (numberRowsAtContinuous) constraints. Any indices beyond nPartial must be |
---|
| 166 | cuts created while processing this node --- they can be copied en bloc |
---|
| 167 | into the correct position in the expanded basis. The space reserved for |
---|
| 168 | xferRows is a gross overestimate. |
---|
| 169 | */ |
---|
| 170 | CoinWarmStartBasis::XferVec xferRows ; |
---|
| 171 | xferRows.reserve(iFull - numberRowsAtContinuous + 1) ; |
---|
| 172 | if (numberNewCuts) { |
---|
| 173 | xferRows.push_back( |
---|
| 174 | CoinWarmStartBasis::XferEntry(iCompact - numberNewCuts, |
---|
| 175 | iFull - numberNewCuts, numberNewCuts)) ; |
---|
| 176 | } |
---|
| 177 | /* |
---|
| 178 | From nPartial down, record the entries we want to copy from the current |
---|
| 179 | basis (the entries for the active cuts; non-zero in the list returned |
---|
| 180 | by addedCuts). Fill the expanded basis with entries showing a status of |
---|
| 181 | basic for the deactivated (loose) cuts. |
---|
| 182 | */ |
---|
| 183 | CbcCountRowCut **cut = model->addedCuts(); |
---|
| 184 | iFull -= (numberNewCuts + 1) ; |
---|
| 185 | iCompact -= (numberNewCuts + 1) ; |
---|
| 186 | int runLen = 0 ; |
---|
| 187 | CoinWarmStartBasis::XferEntry entry(-1, -1, -1) ; |
---|
| 188 | while (iFull >= numberRowsAtContinuous) { |
---|
| 189 | for ( ; iFull >= numberRowsAtContinuous && |
---|
| 190 | cut[iFull-numberRowsAtContinuous] ; iFull--) |
---|
| 191 | runLen++ ; |
---|
| 192 | if (runLen) { |
---|
| 193 | iCompact -= runLen ; |
---|
| 194 | entry.first = iCompact + 1 ; |
---|
| 195 | entry.second = iFull + 1 ; |
---|
| 196 | entry.third = runLen ; |
---|
| 197 | runLen = 0 ; |
---|
| 198 | xferRows.push_back(entry) ; |
---|
| 199 | } |
---|
| 200 | for ( ; iFull >= numberRowsAtContinuous && |
---|
| 201 | !cut[iFull-numberRowsAtContinuous] ; iFull--) |
---|
| 202 | expanded->setArtifStatus(iFull, CoinWarmStartBasis::basic); |
---|
| 203 | } |
---|
| 204 | /* |
---|
| 205 | Finally, call mergeBasis to copy over entries from the current basis to |
---|
| 206 | the expanded basis. Since we cloned the expanded basis from the active basis |
---|
| 207 | and haven't changed the number of variables, only row status entries need |
---|
| 208 | to be copied. |
---|
| 209 | */ |
---|
| 210 | expanded->mergeBasis(ws, &xferRows, 0) ; |
---|
| 211 | |
---|
[640] | 212 | #ifdef CBC_CHECK_BASIS |
---|
[1286] | 213 | std::cout << "Expanded basis:" << std::endl ; |
---|
| 214 | expanded->print() ; |
---|
| 215 | std::cout << "Diffing against:" << std::endl ; |
---|
| 216 | lastws->print() ; |
---|
| 217 | #endif |
---|
| 218 | assert (expanded->getNumArtificial() >= lastws->getNumArtificial()); |
---|
[1061] | 219 | #ifdef CLP_INVESTIGATE |
---|
[1286] | 220 | if (!expanded->fullBasis()) { |
---|
| 221 | int iFull = numberRowsAtContinuous + currentNumberCuts + numberNewCuts; |
---|
| 222 | printf("cont %d old %d new %d current %d full inc %d full %d\n", |
---|
| 223 | numberRowsAtContinuous, numberOldActiveCuts, numberNewCuts, |
---|
| 224 | currentNumberCuts, iFull, iFull - numberNewCuts); |
---|
| 225 | } |
---|
[1061] | 226 | #endif |
---|
[1286] | 227 | |
---|
| 228 | /* |
---|
| 229 | Now that we have two bases in proper positional correspondence, creating |
---|
| 230 | the actual diff is dead easy. |
---|
| 231 | |
---|
| 232 | Note that we're going to compare the expanded basis here to the stripped |
---|
| 233 | basis (lastws) produced by addCuts. It doesn't affect the correctness (the |
---|
| 234 | diff process has no knowledge of the meaning of an entry) but it does |
---|
| 235 | mean that we'll always generate a whack of diff entries because the expanded |
---|
| 236 | basis is considerably larger than the stripped basis. |
---|
| 237 | */ |
---|
| 238 | CoinWarmStartDiff *basisDiff = expanded->generateDiff(lastws) ; |
---|
| 239 | |
---|
| 240 | /* |
---|
| 241 | Diff the bound vectors. It's assumed the number of structural variables |
---|
| 242 | is not changing. For branching objects that change bounds on integer |
---|
| 243 | variables, we should see at least one bound change as a consequence |
---|
| 244 | of applying the branch that generated this subproblem from its parent. |
---|
| 245 | This need not hold for other types of branching objects (hyperplane |
---|
| 246 | branches, for example). |
---|
| 247 | */ |
---|
| 248 | const double * lower = solver->getColLower(); |
---|
| 249 | const double * upper = solver->getColUpper(); |
---|
| 250 | |
---|
| 251 | double *boundChanges = new double [2*numberColumns] ; |
---|
| 252 | int *variables = new int [2*numberColumns] ; |
---|
| 253 | int numberChangedBounds = 0; |
---|
| 254 | |
---|
| 255 | int i; |
---|
| 256 | for (i = 0; i < numberColumns; i++) { |
---|
| 257 | if (lower[i] != lastLower[i]) { |
---|
| 258 | variables[numberChangedBounds] = i; |
---|
| 259 | boundChanges[numberChangedBounds++] = lower[i]; |
---|
| 260 | } |
---|
| 261 | if (upper[i] != lastUpper[i]) { |
---|
| 262 | variables[numberChangedBounds] = i | 0x80000000; |
---|
| 263 | boundChanges[numberChangedBounds++] = upper[i]; |
---|
| 264 | } |
---|
[640] | 265 | #ifdef CBC_DEBUG |
---|
[1286] | 266 | if (lower[i] != lastLower[i]) { |
---|
| 267 | std::cout |
---|
| 268 | << "lower on " << i << " changed from " |
---|
| 269 | << lastLower[i] << " to " << lower[i] << std::endl ; |
---|
| 270 | } |
---|
| 271 | if (upper[i] != lastUpper[i]) { |
---|
| 272 | std::cout |
---|
| 273 | << "upper on " << i << " changed from " |
---|
| 274 | << lastUpper[i] << " to " << upper[i] << std::endl ; |
---|
| 275 | } |
---|
[640] | 276 | #endif |
---|
[1286] | 277 | } |
---|
[640] | 278 | #ifdef CBC_DEBUG |
---|
[1286] | 279 | std::cout << numberChangedBounds << " changed bounds." << std::endl ; |
---|
[640] | 280 | #endif |
---|
[1286] | 281 | //if (lastNode->branchingObject()->boundBranch()) |
---|
| 282 | //assert (numberChangedBounds); |
---|
| 283 | /* |
---|
| 284 | Hand the lot over to the CbcPartialNodeInfo constructor, then clean up and |
---|
| 285 | return. |
---|
| 286 | */ |
---|
| 287 | if (!strategy) |
---|
| 288 | nodeInfo_ = |
---|
| 289 | new CbcPartialNodeInfo(lastNode->nodeInfo_, this, numberChangedBounds, |
---|
| 290 | variables, boundChanges, basisDiff) ; |
---|
| 291 | else |
---|
| 292 | nodeInfo_ = |
---|
| 293 | strategy->partialNodeInfo(model, lastNode->nodeInfo_, this, |
---|
| 294 | numberChangedBounds, variables, boundChanges, |
---|
| 295 | basisDiff) ; |
---|
| 296 | delete basisDiff ; |
---|
| 297 | delete [] boundChanges; |
---|
| 298 | delete [] variables; |
---|
| 299 | delete expanded ; |
---|
| 300 | if (mustDeleteBasis) |
---|
| 301 | delete ws; |
---|
| 302 | } |
---|
| 303 | // Set node number |
---|
| 304 | nodeInfo_->setNodeNumber(model->getNodeCount2()); |
---|
| 305 | state_ |= 2; // say active |
---|
[640] | 306 | } |
---|
| 307 | |
---|
| 308 | #else // CBC_NEW_CREATEINFO |
---|
| 309 | |
---|
| 310 | /* |
---|
| 311 | Original createInfo, with bare manipulation of basis vectors. Fails if solver |
---|
| 312 | maintains additional information in basis. |
---|
| 313 | */ |
---|
| 314 | |
---|
| 315 | void |
---|
| 316 | CbcNode::createInfo (CbcModel *model, |
---|
[1286] | 317 | CbcNode *lastNode, |
---|
| 318 | const CoinWarmStartBasis *lastws, |
---|
| 319 | const double *lastLower, const double *lastUpper, |
---|
| 320 | int numberOldActiveCuts, int numberNewCuts) |
---|
| 321 | { |
---|
| 322 | OsiSolverInterface * solver = model->solver(); |
---|
| 323 | CbcStrategy * strategy = model->strategy(); |
---|
| 324 | /* |
---|
| 325 | The root --- no parent. Create full basis and bounds information. |
---|
| 326 | */ |
---|
| 327 | if (!lastNode) { |
---|
| 328 | if (!strategy) |
---|
| 329 | nodeInfo_ = new CbcFullNodeInfo(model, solver->getNumRows()); |
---|
| 330 | else |
---|
| 331 | nodeInfo_ = strategy->fullNodeInfo(model, solver->getNumRows()); |
---|
[1271] | 332 | } |
---|
[1286] | 333 | /* |
---|
| 334 | Not the root. Create an edit from the parent's basis & bound information. |
---|
| 335 | This is not quite as straightforward as it seems. We need to reintroduce |
---|
| 336 | cuts we may have dropped out of the basis, in the correct position, because |
---|
| 337 | this whole process is strictly positional. Start by grabbing the current |
---|
| 338 | basis. |
---|
| 339 | */ |
---|
| 340 | else { |
---|
| 341 | bool mustDeleteBasis; |
---|
| 342 | const CoinWarmStartBasis* ws = |
---|
| 343 | dynamic_cast<const CoinWarmStartBasis*>(solver->getPointerToWarmStart(mustDeleteBasis)); |
---|
| 344 | assert(ws != NULL); // make sure not volume |
---|
| 345 | //int numberArtificials = lastws->getNumArtificial(); |
---|
| 346 | int numberColumns = solver->getNumCols(); |
---|
| 347 | |
---|
| 348 | const double * lower = solver->getColLower(); |
---|
| 349 | const double * upper = solver->getColUpper(); |
---|
| 350 | |
---|
| 351 | int i; |
---|
| 352 | /* |
---|
| 353 | Create a clone and resize it to hold all the structural constraints, plus |
---|
| 354 | all the cuts: old cuts, both active and inactive (currentNumberCuts), and |
---|
| 355 | new cuts (numberNewCuts). |
---|
| 356 | |
---|
| 357 | TODO: You'd think that the set of constraints (logicals) in the expanded |
---|
| 358 | basis should match the set represented in lastws. At least, that's |
---|
| 359 | what I thought. But at the point I first looked hard at this bit of |
---|
| 360 | code, it turned out that lastws was the stripped basis produced at |
---|
| 361 | the end of addCuts(), rather than the raw basis handed back by |
---|
| 362 | addCuts1(). The expanded basis here is equivalent to the raw basis of |
---|
| 363 | addCuts1(). I said ``whoa, that's not good, I must have introduced a |
---|
| 364 | bug'' and went back to John's code to see where I'd gone wrong. |
---|
| 365 | And discovered the same `error' in his code. |
---|
| 366 | |
---|
| 367 | After a bit of thought, my conclusion is that correctness is not |
---|
| 368 | affected by whether lastws is the stripped or raw basis. The diffs |
---|
| 369 | have no semantics --- just a set of changes that need to be made |
---|
| 370 | to convert lastws into expanded. I think the only effect is that we |
---|
| 371 | store a lot more diffs (everything in expanded that's not covered by |
---|
| 372 | the stripped basis). But I need to give this more thought. There |
---|
| 373 | may well be some subtle error cases. |
---|
| 374 | |
---|
| 375 | In the mean time, I've twiddled addCuts() to set lastws to the raw |
---|
| 376 | basis. Makes me (Lou) less nervous to compare apples to apples. |
---|
| 377 | */ |
---|
| 378 | CoinWarmStartBasis *expanded = |
---|
| 379 | dynamic_cast<CoinWarmStartBasis *>(ws->clone()) ; |
---|
| 380 | int numberRowsAtContinuous = model->numberRowsAtContinuous(); |
---|
| 381 | int iFull = numberRowsAtContinuous + model->currentNumberCuts() + |
---|
| 382 | numberNewCuts; |
---|
| 383 | //int numberArtificialsNow = iFull; |
---|
| 384 | //int maxBasisLength = ((iFull+15)>>4)+((numberColumns+15)>>4); |
---|
| 385 | //printf("l %d full %d\n",maxBasisLength,iFull); |
---|
| 386 | if (expanded) |
---|
| 387 | expanded->resize(iFull, numberColumns); |
---|
[300] | 388 | #ifdef CBC_CHECK_BASIS |
---|
[1286] | 389 | printf("Before expansion: orig %d, old %d, new %d, current %d\n", |
---|
| 390 | numberRowsAtContinuous, numberOldActiveCuts, numberNewCuts, |
---|
| 391 | model->currentNumberCuts()) ; |
---|
| 392 | ws->print(); |
---|
[2] | 393 | #endif |
---|
[1286] | 394 | /* |
---|
| 395 | Now fill in the expanded basis. Any indices beyond nPartial must |
---|
| 396 | be cuts created while processing this node --- they can be copied directly |
---|
| 397 | into the expanded basis. From nPartial down, pull the status of active cuts |
---|
| 398 | from ws, interleaving with a B entry for the deactivated (loose) cuts. |
---|
| 399 | */ |
---|
| 400 | int numberDropped = model->currentNumberCuts() - numberOldActiveCuts; |
---|
| 401 | int iCompact = iFull - numberDropped; |
---|
| 402 | CbcCountRowCut ** cut = model->addedCuts(); |
---|
| 403 | int nPartial = model->currentNumberCuts() + numberRowsAtContinuous; |
---|
| 404 | iFull--; |
---|
| 405 | for (; iFull >= nPartial; iFull--) { |
---|
| 406 | CoinWarmStartBasis::Status status = ws->getArtifStatus(--iCompact); |
---|
| 407 | //assert (status != CoinWarmStartBasis::basic); // may be permanent cut |
---|
| 408 | expanded->setArtifStatus(iFull, status); |
---|
| 409 | } |
---|
| 410 | for (; iFull >= numberRowsAtContinuous; iFull--) { |
---|
| 411 | if (cut[iFull-numberRowsAtContinuous]) { |
---|
| 412 | CoinWarmStartBasis::Status status = ws->getArtifStatus(--iCompact); |
---|
| 413 | // If no cut generator being used then we may have basic variables |
---|
| 414 | //if (model->getMaximumCutPasses()&& |
---|
| 415 | // status == CoinWarmStartBasis::basic) |
---|
| 416 | //printf("cut basic\n"); |
---|
| 417 | expanded->setArtifStatus(iFull, status); |
---|
| 418 | } else { |
---|
| 419 | expanded->setArtifStatus(iFull, CoinWarmStartBasis::basic); |
---|
| 420 | } |
---|
| 421 | } |
---|
[300] | 422 | #ifdef CBC_CHECK_BASIS |
---|
[1286] | 423 | printf("Expanded basis\n"); |
---|
| 424 | expanded->print() ; |
---|
| 425 | printf("Diffing against\n") ; |
---|
| 426 | lastws->print() ; |
---|
| 427 | #endif |
---|
| 428 | /* |
---|
| 429 | Now that we have two bases in proper positional correspondence, creating |
---|
| 430 | the actual diff is dead easy. |
---|
| 431 | */ |
---|
| 432 | |
---|
| 433 | CoinWarmStartDiff *basisDiff = expanded->generateDiff(lastws) ; |
---|
| 434 | /* |
---|
| 435 | Diff the bound vectors. It's assumed the number of structural variables is |
---|
| 436 | not changing. Assuming that branching objects all involve integer variables, |
---|
| 437 | we should see at least one bound change as a consequence of processing this |
---|
| 438 | subproblem. Different types of branching objects could break this assertion. |
---|
| 439 | Not true at all - we have not applied current branch - JJF. |
---|
| 440 | */ |
---|
| 441 | double *boundChanges = new double [2*numberColumns] ; |
---|
| 442 | int *variables = new int [2*numberColumns] ; |
---|
| 443 | int numberChangedBounds = 0; |
---|
| 444 | for (i = 0; i < numberColumns; i++) { |
---|
| 445 | if (lower[i] != lastLower[i]) { |
---|
| 446 | variables[numberChangedBounds] = i; |
---|
| 447 | boundChanges[numberChangedBounds++] = lower[i]; |
---|
| 448 | } |
---|
| 449 | if (upper[i] != lastUpper[i]) { |
---|
| 450 | variables[numberChangedBounds] = i | 0x80000000; |
---|
| 451 | boundChanges[numberChangedBounds++] = upper[i]; |
---|
| 452 | } |
---|
[1271] | 453 | #ifdef CBC_DEBUG |
---|
[1286] | 454 | if (lower[i] != lastLower[i]) |
---|
| 455 | printf("lower on %d changed from %g to %g\n", |
---|
| 456 | i, lastLower[i], lower[i]); |
---|
| 457 | if (upper[i] != lastUpper[i]) |
---|
| 458 | printf("upper on %d changed from %g to %g\n", |
---|
| 459 | i, lastUpper[i], upper[i]); |
---|
[1271] | 460 | #endif |
---|
[1286] | 461 | } |
---|
[2] | 462 | #ifdef CBC_DEBUG |
---|
[1286] | 463 | printf("%d changed bounds\n", numberChangedBounds) ; |
---|
[2] | 464 | #endif |
---|
[1286] | 465 | //if (lastNode->branchingObject()->boundBranch()) |
---|
| 466 | //assert (numberChangedBounds); |
---|
| 467 | /* |
---|
| 468 | Hand the lot over to the CbcPartialNodeInfo constructor, then clean up and |
---|
| 469 | return. |
---|
| 470 | */ |
---|
| 471 | if (!strategy) |
---|
| 472 | nodeInfo_ = |
---|
| 473 | new CbcPartialNodeInfo(lastNode->nodeInfo_, this, numberChangedBounds, |
---|
| 474 | variables, boundChanges, basisDiff) ; |
---|
| 475 | else |
---|
| 476 | nodeInfo_ = strategy->partialNodeInfo(model, lastNode->nodeInfo_, this, numberChangedBounds, |
---|
| 477 | variables, boundChanges, basisDiff) ; |
---|
| 478 | delete basisDiff ; |
---|
| 479 | delete [] boundChanges; |
---|
| 480 | delete [] variables; |
---|
| 481 | delete expanded ; |
---|
| 482 | if (mustDeleteBasis) |
---|
| 483 | delete ws; |
---|
[2] | 484 | } |
---|
[1286] | 485 | // Set node number |
---|
| 486 | nodeInfo_->setNodeNumber(model->getNodeCount2()); |
---|
| 487 | state_ |= 2; // say active |
---|
[2] | 488 | } |
---|
| 489 | |
---|
[640] | 490 | #endif // CBC_NEW_CREATEINFO |
---|
[2] | 491 | /* |
---|
| 492 | The routine scans through the object list of the model looking for objects |
---|
| 493 | that indicate infeasibility. It tests each object using strong branching |
---|
| 494 | and selects the one with the least objective degradation. A corresponding |
---|
| 495 | branching object is left attached to lastNode. |
---|
[1286] | 496 | |
---|
[2] | 497 | If strong branching is disabled, a candidate object is chosen essentially |
---|
| 498 | at random (whatever object ends up in pos'n 0 of the candidate array). |
---|
[1286] | 499 | |
---|
[2] | 500 | If a branching candidate is found to be monotone, bounds are set to fix the |
---|
| 501 | variable and the routine immediately returns (the caller is expected to |
---|
| 502 | reoptimize). |
---|
[1286] | 503 | |
---|
[2] | 504 | If a branching candidate is found to result in infeasibility in both |
---|
| 505 | directions, the routine immediately returns an indication of infeasibility. |
---|
[1286] | 506 | |
---|
[2] | 507 | Returns: 0 both branch directions are feasible |
---|
[1271] | 508 | -1 branching variable is monotone |
---|
| 509 | -2 infeasible |
---|
[1286] | 510 | |
---|
[2] | 511 | Original comments: |
---|
[1271] | 512 | Here could go cuts etc etc |
---|
| 513 | For now just fix on objective from strong branching. |
---|
[2] | 514 | */ |
---|
| 515 | |
---|
[1286] | 516 | int CbcNode::chooseBranch (CbcModel *model, CbcNode *lastNode, int numberPassesLeft) |
---|
| 517 | |
---|
| 518 | { |
---|
| 519 | if (lastNode) |
---|
| 520 | depth_ = lastNode->depth_ + 1; |
---|
| 521 | else |
---|
| 522 | depth_ = 0; |
---|
| 523 | delete branch_; |
---|
| 524 | branch_ = NULL; |
---|
| 525 | OsiSolverInterface * solver = model->solver(); |
---|
[1133] | 526 | # ifdef COIN_HAS_CLP |
---|
[1286] | 527 | OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (solver); |
---|
| 528 | int saveClpOptions = 0; |
---|
| 529 | if (osiclp) { |
---|
| 530 | // for faster hot start |
---|
| 531 | saveClpOptions = osiclp->specialOptions(); |
---|
| 532 | osiclp->setSpecialOptions(saveClpOptions | 8192); |
---|
| 533 | } |
---|
[1133] | 534 | # else |
---|
[1286] | 535 | OsiSolverInterface *osiclp = NULL ; |
---|
[1133] | 536 | # endif |
---|
[1286] | 537 | double saveObjectiveValue = solver->getObjValue(); |
---|
| 538 | double objectiveValue = CoinMax(solver->getObjSense() * saveObjectiveValue, objectiveValue_); |
---|
| 539 | const double * lower = solver->getColLower(); |
---|
| 540 | const double * upper = solver->getColUpper(); |
---|
| 541 | // See what user thinks |
---|
| 542 | int anyAction = model->problemFeasibility()->feasible(model, 0); |
---|
| 543 | if (anyAction) { |
---|
| 544 | // will return -2 if infeasible , 0 if treat as integer |
---|
| 545 | return anyAction - 1; |
---|
| 546 | } |
---|
| 547 | double integerTolerance = |
---|
| 548 | model->getDblParam(CbcModel::CbcIntegerTolerance); |
---|
| 549 | // point to useful information |
---|
| 550 | OsiBranchingInformation usefulInfo = model->usefulInformation(); |
---|
| 551 | // and modify |
---|
| 552 | usefulInfo.depth_ = depth_; |
---|
| 553 | int i; |
---|
| 554 | bool beforeSolution = model->getSolutionCount() == 0; |
---|
| 555 | int numberStrong = model->numberStrong(); |
---|
| 556 | // switch off strong if hotstart |
---|
| 557 | const double * hotstartSolution = model->hotstartSolution(); |
---|
| 558 | const int * hotstartPriorities = model->hotstartPriorities(); |
---|
| 559 | int numberObjects = model->numberObjects(); |
---|
| 560 | int numberColumns = model->getNumCols(); |
---|
| 561 | double * saveUpper = new double[numberColumns]; |
---|
| 562 | double * saveLower = new double[numberColumns]; |
---|
| 563 | for (i = 0; i < numberColumns; i++) { |
---|
| 564 | saveLower[i] = lower[i]; |
---|
| 565 | saveUpper[i] = upper[i]; |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | // Save solution in case heuristics need good solution later |
---|
| 569 | |
---|
| 570 | double * saveSolution = new double[numberColumns]; |
---|
| 571 | memcpy(saveSolution, solver->getColSolution(), numberColumns*sizeof(double)); |
---|
| 572 | model->reserveCurrentSolution(saveSolution); |
---|
| 573 | if (hotstartSolution) { |
---|
| 574 | numberStrong = 0; |
---|
| 575 | if ((model->moreSpecialOptions()&1024) != 0) { |
---|
| 576 | int nBad = 0; |
---|
| 577 | int nUnsat = 0; |
---|
| 578 | int nDiff = 0; |
---|
| 579 | for (int i = 0; i < numberObjects; i++) { |
---|
| 580 | OsiObject * object = model->modifiableObject(i); |
---|
| 581 | const CbcSimpleInteger * thisOne = dynamic_cast <const CbcSimpleInteger *> (object); |
---|
| 582 | if (thisOne) { |
---|
| 583 | int iColumn = thisOne->columnNumber(); |
---|
| 584 | double targetValue = hotstartSolution[iColumn]; |
---|
| 585 | double value = saveSolution[iColumn]; |
---|
| 586 | if (fabs(value - floor(value + 0.5)) > 1.0e-6) { |
---|
| 587 | nUnsat++; |
---|
| 588 | #ifdef CLP_INVESTIGATE |
---|
| 589 | printf("H %d is %g target %g\n", iColumn, value, targetValue); |
---|
[1271] | 590 | #endif |
---|
[1286] | 591 | } else if (fabs(targetValue - value) > 1.0e-6) { |
---|
| 592 | nDiff++; |
---|
| 593 | } |
---|
| 594 | if (targetValue < saveLower[iColumn] || |
---|
| 595 | targetValue > saveUpper[iColumn]) { |
---|
| 596 | #ifdef CLP_INVESTIGATE |
---|
| 597 | printf("%d has target %g and current bounds %g and %g\n", |
---|
| 598 | iColumn, targetValue, saveLower[iColumn], saveUpper[iColumn]); |
---|
[1271] | 599 | #endif |
---|
[1286] | 600 | nBad++; |
---|
| 601 | } |
---|
| 602 | } |
---|
| 603 | } |
---|
| 604 | #ifdef CLP_INVESTIGATE |
---|
| 605 | printf("Hot %d unsatisfied, %d outside limits, %d different\n", |
---|
| 606 | nUnsat, nBad, nDiff); |
---|
[1271] | 607 | #endif |
---|
[1286] | 608 | if (nBad) { |
---|
| 609 | // switch off as not possible |
---|
| 610 | hotstartSolution = NULL; |
---|
| 611 | model->setHotstartSolution(NULL, NULL); |
---|
| 612 | usefulInfo.hotstartSolution_ = NULL; |
---|
| 613 | } |
---|
| 614 | } |
---|
[1271] | 615 | } |
---|
[1286] | 616 | int numberStrongDone = 0; |
---|
| 617 | int numberUnfinished = 0; |
---|
| 618 | int numberStrongInfeasible = 0; |
---|
| 619 | int numberStrongIterations = 0; |
---|
| 620 | int saveNumberStrong = numberStrong; |
---|
| 621 | bool checkFeasibility = numberObjects > model->numberIntegers(); |
---|
| 622 | int maximumStrong = CoinMax(CoinMin(numberStrong, numberObjects), 1); |
---|
| 623 | /* |
---|
| 624 | Get a branching decision object. Use the default decision criteria unless |
---|
| 625 | the user has loaded a decision method into the model. |
---|
| 626 | */ |
---|
| 627 | CbcBranchDecision *decision = model->branchingMethod(); |
---|
| 628 | CbcDynamicPseudoCostBranchingObject * dynamicBranchingObject = |
---|
| 629 | dynamic_cast<CbcDynamicPseudoCostBranchingObject *>(decision); |
---|
| 630 | if (!decision || dynamicBranchingObject) |
---|
| 631 | decision = new CbcBranchDefaultDecision(); |
---|
| 632 | decision->initialize(model); |
---|
| 633 | CbcStrongInfo * choice = new CbcStrongInfo[maximumStrong]; |
---|
| 634 | // May go round twice if strong branching fixes all local candidates |
---|
| 635 | bool finished = false; |
---|
| 636 | double estimatedDegradation = 0.0; |
---|
| 637 | while (!finished) { |
---|
| 638 | finished = true; |
---|
| 639 | // Some objects may compute an estimate of best solution from here |
---|
| 640 | estimatedDegradation = 0.0; |
---|
| 641 | //int numberIntegerInfeasibilities=0; // without odd ones |
---|
| 642 | numberStrongDone = 0; |
---|
| 643 | numberUnfinished = 0; |
---|
| 644 | numberStrongInfeasible = 0; |
---|
| 645 | numberStrongIterations = 0; |
---|
| 646 | |
---|
| 647 | // We may go round this loop twice (only if we think we have solution) |
---|
| 648 | for (int iPass = 0; iPass < 2; iPass++) { |
---|
| 649 | |
---|
| 650 | // compute current state |
---|
| 651 | //int numberObjectInfeasibilities; // just odd ones |
---|
| 652 | //model->feasibleSolution( |
---|
| 653 | // numberIntegerInfeasibilities, |
---|
| 654 | // numberObjectInfeasibilities); |
---|
| 655 | // Some objects may compute an estimate of best solution from here |
---|
| 656 | estimatedDegradation = 0.0; |
---|
| 657 | numberUnsatisfied_ = 0; |
---|
| 658 | // initialize sum of "infeasibilities" |
---|
| 659 | sumInfeasibilities_ = 0.0; |
---|
| 660 | int bestPriority = COIN_INT_MAX; |
---|
| 661 | /* |
---|
| 662 | Scan for branching objects that indicate infeasibility. Choose the best |
---|
| 663 | maximumStrong candidates, using priority as the first criteria, then |
---|
| 664 | integer infeasibility. |
---|
| 665 | |
---|
| 666 | The algorithm is to fill the choice array with a set of good candidates (by |
---|
| 667 | infeasibility) with priority bestPriority. Finding a candidate with |
---|
| 668 | priority better (less) than bestPriority flushes the choice array. (This |
---|
| 669 | serves as initialization when the first candidate is found.) |
---|
| 670 | |
---|
| 671 | A new candidate is added to choices only if its infeasibility exceeds the |
---|
| 672 | current max infeasibility (mostAway). When a candidate is added, it |
---|
| 673 | replaces the candidate with the smallest infeasibility (tracked by |
---|
| 674 | iSmallest). |
---|
| 675 | */ |
---|
| 676 | int iSmallest = 0; |
---|
| 677 | double mostAway = 1.0e-100; |
---|
| 678 | for (i = 0 ; i < maximumStrong ; i++) |
---|
| 679 | choice[i].possibleBranch = NULL ; |
---|
| 680 | numberStrong = 0; |
---|
| 681 | bool canDoOneHot = false; |
---|
| 682 | for (i = 0; i < numberObjects; i++) { |
---|
| 683 | OsiObject * object = model->modifiableObject(i); |
---|
| 684 | int preferredWay; |
---|
| 685 | double infeasibility = object->infeasibility(&usefulInfo, preferredWay); |
---|
| 686 | int priorityLevel = object->priority(); |
---|
| 687 | if (hotstartSolution) { |
---|
| 688 | // we are doing hot start |
---|
| 689 | const CbcSimpleInteger * thisOne = dynamic_cast <const CbcSimpleInteger *> (object); |
---|
| 690 | if (thisOne) { |
---|
| 691 | int iColumn = thisOne->columnNumber(); |
---|
| 692 | bool canDoThisHot = true; |
---|
| 693 | double targetValue = hotstartSolution[iColumn]; |
---|
| 694 | if (saveUpper[iColumn] > saveLower[iColumn]) { |
---|
| 695 | double value = saveSolution[iColumn]; |
---|
| 696 | if (hotstartPriorities) |
---|
| 697 | priorityLevel = hotstartPriorities[iColumn]; |
---|
| 698 | //double originalLower = thisOne->originalLower(); |
---|
| 699 | //double originalUpper = thisOne->originalUpper(); |
---|
| 700 | // switch off if not possible |
---|
| 701 | if (targetValue >= saveLower[iColumn] && targetValue <= saveUpper[iColumn]) { |
---|
| 702 | /* priority outranks rest always if negative |
---|
| 703 | otherwise can be downgraded if at correct level. |
---|
| 704 | Infeasibility may be increased to choose 1.0 values first. |
---|
| 705 | choose one near wanted value |
---|
| 706 | */ |
---|
| 707 | if (fabs(value - targetValue) > integerTolerance) { |
---|
| 708 | //if (infeasibility>0.01) |
---|
| 709 | //infeasibility = fabs(1.0e6-fabs(value-targetValue)); |
---|
| 710 | //else |
---|
| 711 | infeasibility = fabs(value - targetValue); |
---|
| 712 | //if (targetValue==1.0) |
---|
| 713 | //infeasibility += 1.0; |
---|
| 714 | if (value > targetValue) { |
---|
| 715 | preferredWay = -1; |
---|
| 716 | } else { |
---|
| 717 | preferredWay = 1; |
---|
| 718 | } |
---|
| 719 | priorityLevel = CoinAbs(priorityLevel); |
---|
| 720 | } else if (priorityLevel < 0) { |
---|
| 721 | priorityLevel = CoinAbs(priorityLevel); |
---|
| 722 | if (targetValue == saveLower[iColumn]) { |
---|
| 723 | infeasibility = integerTolerance + 1.0e-12; |
---|
| 724 | preferredWay = -1; |
---|
| 725 | } else if (targetValue == saveUpper[iColumn]) { |
---|
| 726 | infeasibility = integerTolerance + 1.0e-12; |
---|
| 727 | preferredWay = 1; |
---|
| 728 | } else { |
---|
| 729 | // can't |
---|
| 730 | priorityLevel += 10000000; |
---|
| 731 | canDoThisHot = false; |
---|
| 732 | } |
---|
| 733 | } else { |
---|
| 734 | priorityLevel += 10000000; |
---|
| 735 | canDoThisHot = false; |
---|
| 736 | } |
---|
| 737 | } else { |
---|
| 738 | // switch off if not possible |
---|
| 739 | canDoThisHot = false; |
---|
| 740 | } |
---|
| 741 | if (canDoThisHot) |
---|
| 742 | canDoOneHot = true; |
---|
| 743 | } else if (targetValue < saveLower[iColumn] || targetValue > saveUpper[iColumn]) { |
---|
| 744 | } |
---|
| 745 | } else { |
---|
| 746 | priorityLevel += 10000000; |
---|
| 747 | } |
---|
[44] | 748 | } |
---|
[1286] | 749 | if (infeasibility) { |
---|
| 750 | // Increase estimated degradation to solution |
---|
| 751 | estimatedDegradation += CoinMin(object->upEstimate(), object->downEstimate()); |
---|
| 752 | numberUnsatisfied_++; |
---|
| 753 | sumInfeasibilities_ += infeasibility; |
---|
| 754 | // Better priority? Flush choices. |
---|
| 755 | if (priorityLevel < bestPriority) { |
---|
| 756 | int j; |
---|
| 757 | iSmallest = 0; |
---|
| 758 | for (j = 0; j < maximumStrong; j++) { |
---|
| 759 | choice[j].upMovement = 0.0; |
---|
| 760 | delete choice[j].possibleBranch; |
---|
| 761 | choice[j].possibleBranch = NULL; |
---|
| 762 | } |
---|
| 763 | bestPriority = priorityLevel; |
---|
| 764 | mostAway = 1.0e-100; |
---|
| 765 | numberStrong = 0; |
---|
| 766 | } else if (priorityLevel > bestPriority) { |
---|
| 767 | continue; |
---|
| 768 | } |
---|
| 769 | // Check for suitability based on infeasibility. |
---|
| 770 | if (infeasibility > mostAway) { |
---|
| 771 | //add to list |
---|
| 772 | choice[iSmallest].upMovement = infeasibility; |
---|
| 773 | delete choice[iSmallest].possibleBranch; |
---|
| 774 | CbcObject * obj = |
---|
| 775 | dynamic_cast <CbcObject *>(object) ; |
---|
| 776 | assert (obj); |
---|
| 777 | choice[iSmallest].possibleBranch = obj->createCbcBranch(solver, &usefulInfo, preferredWay); |
---|
| 778 | numberStrong = CoinMax(numberStrong, iSmallest + 1); |
---|
| 779 | // Save which object it was |
---|
| 780 | choice[iSmallest].objectNumber = i; |
---|
| 781 | int j; |
---|
| 782 | iSmallest = -1; |
---|
| 783 | mostAway = 1.0e50; |
---|
| 784 | for (j = 0; j < maximumStrong; j++) { |
---|
| 785 | if (choice[j].upMovement < mostAway) { |
---|
| 786 | mostAway = choice[j].upMovement; |
---|
| 787 | iSmallest = j; |
---|
| 788 | } |
---|
| 789 | } |
---|
| 790 | } |
---|
| 791 | } |
---|
[44] | 792 | } |
---|
[1286] | 793 | if (!canDoOneHot && hotstartSolution) { |
---|
| 794 | // switch off as not possible |
---|
| 795 | hotstartSolution = NULL; |
---|
| 796 | model->setHotstartSolution(NULL, NULL); |
---|
| 797 | usefulInfo.hotstartSolution_ = NULL; |
---|
[122] | 798 | } |
---|
[1286] | 799 | if (numberUnsatisfied_) { |
---|
| 800 | // some infeasibilities - go to next steps |
---|
[1271] | 801 | #ifdef CLP_INVESTIGATE |
---|
[1286] | 802 | if (hotstartSolution) { |
---|
| 803 | int k = choice[0].objectNumber; |
---|
| 804 | OsiObject * object = model->modifiableObject(k); |
---|
| 805 | const CbcSimpleInteger * thisOne = dynamic_cast <const CbcSimpleInteger *> (object); |
---|
| 806 | assert (thisOne); |
---|
| 807 | int iColumn = thisOne->columnNumber(); |
---|
| 808 | double targetValue = hotstartSolution[iColumn]; |
---|
| 809 | double value = saveSolution[iColumn]; |
---|
| 810 | printf("Branch on %d has target %g (value %g) and current bounds %g and %g\n", |
---|
| 811 | iColumn, targetValue, value, saveLower[iColumn], saveUpper[iColumn]); |
---|
| 812 | } |
---|
[1271] | 813 | #endif |
---|
[1286] | 814 | break; |
---|
| 815 | } else if (!iPass) { |
---|
| 816 | // looks like a solution - get paranoid |
---|
| 817 | bool roundAgain = false; |
---|
| 818 | // get basis |
---|
| 819 | CoinWarmStartBasis * ws = dynamic_cast<CoinWarmStartBasis*>(solver->getWarmStart()); |
---|
| 820 | if (!ws) |
---|
| 821 | break; |
---|
| 822 | for (i = 0; i < numberColumns; i++) { |
---|
| 823 | double value = saveSolution[i]; |
---|
| 824 | if (value < lower[i]) { |
---|
| 825 | saveSolution[i] = lower[i]; |
---|
| 826 | roundAgain = true; |
---|
| 827 | ws->setStructStatus(i, CoinWarmStartBasis::atLowerBound); |
---|
| 828 | } else if (value > upper[i]) { |
---|
| 829 | saveSolution[i] = upper[i]; |
---|
| 830 | roundAgain = true; |
---|
| 831 | ws->setStructStatus(i, CoinWarmStartBasis::atUpperBound); |
---|
| 832 | } |
---|
| 833 | } |
---|
| 834 | if (roundAgain && saveNumberStrong) { |
---|
| 835 | // restore basis |
---|
| 836 | solver->setWarmStart(ws); |
---|
| 837 | delete ws; |
---|
| 838 | solver->resolve(); |
---|
| 839 | memcpy(saveSolution, solver->getColSolution(), numberColumns*sizeof(double)); |
---|
| 840 | model->reserveCurrentSolution(saveSolution); |
---|
| 841 | if (!solver->isProvenOptimal()) { |
---|
| 842 | // infeasible |
---|
| 843 | anyAction = -2; |
---|
| 844 | break; |
---|
| 845 | } |
---|
| 846 | } else { |
---|
| 847 | delete ws; |
---|
| 848 | break; |
---|
| 849 | } |
---|
| 850 | } |
---|
[44] | 851 | } |
---|
[1286] | 852 | /* Some solvers can do the strong branching calculations faster if |
---|
| 853 | they do them all at once. At present only Clp does for ordinary |
---|
| 854 | integers but I think this coding would be easy to modify |
---|
| 855 | */ |
---|
| 856 | bool allNormal = true; // to say if we can do fast strong branching |
---|
| 857 | // Say which one will be best |
---|
| 858 | int bestChoice = 0; |
---|
| 859 | double worstInfeasibility = 0.0; |
---|
| 860 | for (i = 0; i < numberStrong; i++) { |
---|
| 861 | choice[i].numIntInfeasUp = numberUnsatisfied_; |
---|
| 862 | choice[i].numIntInfeasDown = numberUnsatisfied_; |
---|
| 863 | choice[i].fix = 0; // say not fixed |
---|
| 864 | if (!dynamic_cast <const CbcSimpleInteger *> (model->object(choice[i].objectNumber))) |
---|
| 865 | allNormal = false; // Something odd so lets skip clever fast branching |
---|
| 866 | if ( !model->object(choice[i].objectNumber)->boundBranch()) |
---|
| 867 | numberStrong = 0; // switch off |
---|
| 868 | if ( choice[i].possibleBranch->numberBranches() > 2) |
---|
| 869 | numberStrong = 0; // switch off |
---|
| 870 | // Do best choice in case switched off |
---|
| 871 | if (choice[i].upMovement > worstInfeasibility) { |
---|
| 872 | worstInfeasibility = choice[i].upMovement; |
---|
| 873 | bestChoice = i; |
---|
| 874 | } |
---|
[122] | 875 | } |
---|
[1286] | 876 | // If we have hit max time don't do strong branching |
---|
| 877 | bool hitMaxTime = ( CoinCpuTime() - model->getDblParam(CbcModel::CbcStartSeconds) > |
---|
| 878 | model->getDblParam(CbcModel::CbcMaximumSeconds)); |
---|
| 879 | // also give up if we are looping round too much |
---|
| 880 | if (hitMaxTime || numberPassesLeft <= 0) |
---|
| 881 | numberStrong = 0; |
---|
| 882 | /* |
---|
| 883 | Is strong branching enabled? If so, set up and do it. Otherwise, we'll |
---|
| 884 | fall through to simple branching. |
---|
| 885 | |
---|
| 886 | Setup for strong branching involves saving the current basis (for restoration |
---|
| 887 | afterwards) and setting up for hot starts. |
---|
| 888 | */ |
---|
| 889 | if (numberStrong && saveNumberStrong) { |
---|
| 890 | |
---|
| 891 | bool solveAll = false; // set true to say look at all even if some fixed (experiment) |
---|
| 892 | solveAll = true; |
---|
| 893 | // worth trying if too many times |
---|
| 894 | // Save basis |
---|
| 895 | CoinWarmStart * ws = solver->getWarmStart(); |
---|
| 896 | // save limit |
---|
| 897 | int saveLimit; |
---|
| 898 | solver->getIntParam(OsiMaxNumIterationHotStart, saveLimit); |
---|
| 899 | if (beforeSolution && saveLimit < 100) |
---|
| 900 | solver->setIntParam(OsiMaxNumIterationHotStart, 100); // go to end |
---|
| 901 | # ifdef COIN_HAS_CLP |
---|
| 902 | /* If we are doing all strong branching in one go then we create new arrays |
---|
| 903 | to store information. If clp NULL then doing old way. |
---|
| 904 | Going down - |
---|
| 905 | outputSolution[2*i] is final solution. |
---|
| 906 | outputStuff[2*i] is status (0 - finished, 1 infeas, other unknown |
---|
| 907 | outputStuff[2*i+numberStrong] is number iterations |
---|
| 908 | On entry newUpper[i] is new upper bound, on exit obj change |
---|
| 909 | Going up - |
---|
| 910 | outputSolution[2*i+1] is final solution. |
---|
| 911 | outputStuff[2*i+1] is status (0 - finished, 1 infeas, other unknown |
---|
| 912 | outputStuff[2*i+1+numberStrong] is number iterations |
---|
| 913 | On entry newLower[i] is new lower bound, on exit obj change |
---|
| 914 | */ |
---|
| 915 | ClpSimplex * clp = NULL; |
---|
| 916 | double * newLower = NULL; |
---|
| 917 | double * newUpper = NULL; |
---|
| 918 | double ** outputSolution = NULL; |
---|
| 919 | int * outputStuff = NULL; |
---|
| 920 | // Go back to normal way if user wants it |
---|
| 921 | if (osiclp && (osiclp->specialOptions()&16) != 0 && osiclp->specialOptions() > 0) |
---|
| 922 | allNormal = false; |
---|
| 923 | if (osiclp && !allNormal) { |
---|
| 924 | // say do fast |
---|
| 925 | int easy = 1; |
---|
| 926 | osiclp->setHintParam(OsiDoInBranchAndCut, true, OsiHintDo, &easy) ; |
---|
| 927 | } |
---|
| 928 | if (osiclp && allNormal) { |
---|
| 929 | clp = osiclp->getModelPtr(); |
---|
| 930 | // Clp - do a different way |
---|
| 931 | newLower = new double[numberStrong]; |
---|
| 932 | newUpper = new double[numberStrong]; |
---|
| 933 | outputSolution = new double * [2*numberStrong]; |
---|
| 934 | outputStuff = new int [4*numberStrong]; |
---|
| 935 | int * which = new int[numberStrong]; |
---|
| 936 | int startFinishOptions; |
---|
| 937 | int specialOptions = osiclp->specialOptions(); |
---|
| 938 | int clpOptions = clp->specialOptions(); |
---|
| 939 | int returnCode = 0; |
---|
[122] | 940 | #define CRUNCH |
---|
| 941 | #ifdef CRUNCH |
---|
[1286] | 942 | // Crunch down problem |
---|
| 943 | int numberRows = clp->numberRows(); |
---|
| 944 | // Use dual region |
---|
| 945 | double * rhs = clp->dualRowSolution(); |
---|
| 946 | int * whichRow = new int[3*numberRows]; |
---|
| 947 | int * whichColumn = new int[2*numberColumns]; |
---|
| 948 | int nBound; |
---|
| 949 | ClpSimplex * small = static_cast<ClpSimplexOther *> (clp)->crunch(rhs, whichRow, whichColumn, nBound, true); |
---|
| 950 | if (!small) { |
---|
| 951 | anyAction = -2; |
---|
| 952 | //printf("XXXX Inf by inspection\n"); |
---|
| 953 | delete [] whichColumn; |
---|
| 954 | whichColumn = NULL; |
---|
| 955 | delete [] whichRow; |
---|
| 956 | whichRow = NULL; |
---|
| 957 | break; |
---|
| 958 | } else { |
---|
| 959 | clp = small; |
---|
| 960 | } |
---|
[122] | 961 | #else |
---|
[1286] | 962 | int saveLogLevel = clp->logLevel(); |
---|
| 963 | int saveMaxIts = clp->maximumIterations(); |
---|
[122] | 964 | #endif |
---|
[1286] | 965 | clp->setLogLevel(0); |
---|
| 966 | if ((specialOptions&1) == 0) { |
---|
| 967 | startFinishOptions = 0; |
---|
| 968 | clp->setSpecialOptions(clpOptions | (64 | 1024)); |
---|
| 969 | } else { |
---|
| 970 | startFinishOptions = 1 + 2 + 4; |
---|
| 971 | //startFinishOptions=1+4; // for moment re-factorize |
---|
| 972 | if ((specialOptions&4) == 0) |
---|
| 973 | clp->setSpecialOptions(clpOptions | (64 | 128 | 512 | 1024 | 4096)); |
---|
| 974 | else |
---|
| 975 | clp->setSpecialOptions(clpOptions | (64 | 128 | 512 | 1024 | 2048 | 4096)); |
---|
| 976 | } |
---|
| 977 | // User may want to clean up before strong branching |
---|
| 978 | if ((clp->specialOptions()&32) != 0) { |
---|
| 979 | clp->primal(1); |
---|
| 980 | if (clp->numberIterations()) |
---|
| 981 | model->messageHandler()->message(CBC_ITERATE_STRONG, *model->messagesPointer()) |
---|
| 982 | << clp->numberIterations() |
---|
| 983 | << CoinMessageEol; |
---|
| 984 | } |
---|
| 985 | clp->setMaximumIterations(saveLimit); |
---|
[122] | 986 | #ifdef CRUNCH |
---|
[1286] | 987 | int * backColumn = whichColumn + numberColumns; |
---|
[122] | 988 | #endif |
---|
[1286] | 989 | for (i = 0; i < numberStrong; i++) { |
---|
| 990 | int iObject = choice[i].objectNumber; |
---|
| 991 | const OsiObject * object = model->object(iObject); |
---|
| 992 | const CbcSimpleInteger * simple = static_cast <const CbcSimpleInteger *> (object); |
---|
| 993 | int iSequence = simple->columnNumber(); |
---|
| 994 | newLower[i] = ceil(saveSolution[iSequence]); |
---|
| 995 | newUpper[i] = floor(saveSolution[iSequence]); |
---|
[122] | 996 | #ifdef CRUNCH |
---|
[1286] | 997 | iSequence = backColumn[iSequence]; |
---|
| 998 | assert (iSequence >= 0); |
---|
[122] | 999 | #endif |
---|
[1286] | 1000 | which[i] = iSequence; |
---|
| 1001 | outputSolution[2*i] = new double [numberColumns]; |
---|
| 1002 | outputSolution[2*i+1] = new double [numberColumns]; |
---|
| 1003 | } |
---|
| 1004 | //clp->writeMps("bad"); |
---|
| 1005 | returnCode = clp->strongBranching(numberStrong, which, |
---|
| 1006 | newLower, newUpper, outputSolution, |
---|
| 1007 | outputStuff, outputStuff + 2 * numberStrong, !solveAll, false, |
---|
| 1008 | startFinishOptions); |
---|
[122] | 1009 | #ifndef CRUNCH |
---|
[1286] | 1010 | clp->setSpecialOptions(clpOptions); // restore |
---|
| 1011 | clp->setMaximumIterations(saveMaxIts); |
---|
| 1012 | clp->setLogLevel(saveLogLevel); |
---|
[122] | 1013 | #endif |
---|
[1286] | 1014 | if (returnCode == -2) { |
---|
| 1015 | // bad factorization!!! |
---|
| 1016 | // Doing normal way |
---|
| 1017 | // Mark hot start |
---|
| 1018 | solver->markHotStart(); |
---|
| 1019 | clp = NULL; |
---|
| 1020 | } else { |
---|
[122] | 1021 | #ifdef CRUNCH |
---|
[1286] | 1022 | // extract solution |
---|
| 1023 | //bool checkSol=true; |
---|
| 1024 | for (i = 0; i < numberStrong; i++) { |
---|
| 1025 | int iObject = choice[i].objectNumber; |
---|
| 1026 | const OsiObject * object = model->object(iObject); |
---|
| 1027 | const CbcSimpleInteger * simple = static_cast <const CbcSimpleInteger *> (object); |
---|
| 1028 | int iSequence = simple->columnNumber(); |
---|
| 1029 | which[i] = iSequence; |
---|
| 1030 | double * sol = outputSolution[2*i]; |
---|
| 1031 | double * sol2 = outputSolution[2*i+1]; |
---|
| 1032 | //bool x=true; |
---|
| 1033 | //bool x2=true; |
---|
| 1034 | for (int iColumn = numberColumns - 1; iColumn >= 0; iColumn--) { |
---|
| 1035 | int jColumn = backColumn[iColumn]; |
---|
| 1036 | if (jColumn >= 0) { |
---|
| 1037 | sol[iColumn] = sol[jColumn]; |
---|
| 1038 | sol2[iColumn] = sol2[jColumn]; |
---|
| 1039 | } else { |
---|
| 1040 | sol[iColumn] = saveSolution[iColumn]; |
---|
| 1041 | sol2[iColumn] = saveSolution[iColumn]; |
---|
| 1042 | } |
---|
| 1043 | } |
---|
| 1044 | } |
---|
[122] | 1045 | #endif |
---|
[1286] | 1046 | } |
---|
[122] | 1047 | #ifdef CRUNCH |
---|
[1286] | 1048 | delete [] whichColumn; |
---|
| 1049 | delete [] whichRow; |
---|
| 1050 | delete small; |
---|
[122] | 1051 | #endif |
---|
[1286] | 1052 | delete [] which; |
---|
| 1053 | } else { |
---|
| 1054 | // Doing normal way |
---|
| 1055 | // Mark hot start |
---|
| 1056 | solver->markHotStart(); |
---|
| 1057 | } |
---|
[311] | 1058 | # else /* COIN_HAS_CLP */ |
---|
[1286] | 1059 | |
---|
| 1060 | OsiSolverInterface *clp = NULL ; |
---|
| 1061 | double **outputSolution = NULL ; |
---|
| 1062 | int *outputStuff = NULL ; |
---|
| 1063 | double * newLower = NULL ; |
---|
| 1064 | double * newUpper = NULL ; |
---|
| 1065 | |
---|
| 1066 | solver->markHotStart(); |
---|
| 1067 | |
---|
[311] | 1068 | # endif /* COIN_HAS_CLP */ |
---|
[1286] | 1069 | /* |
---|
| 1070 | Open a loop to do the strong branching LPs. For each candidate variable, |
---|
| 1071 | solve an LP with the variable forced down, then up. If a direction turns |
---|
| 1072 | out to be infeasible or monotonic (i.e., over the dual objective cutoff), |
---|
| 1073 | force the objective change to be big (1.0e100). If we determine the problem |
---|
| 1074 | is infeasible, or find a monotone variable, escape the loop. |
---|
| 1075 | |
---|
| 1076 | TODO: The `restore bounds' part might be better encapsulated as an |
---|
| 1077 | unbranch() method. Branching objects more exotic than simple integers |
---|
| 1078 | or cliques might not restrict themselves to variable bounds. |
---|
| 1079 | |
---|
| 1080 | TODO: Virtuous solvers invalidate the current solution (or give bogus |
---|
| 1081 | results :-) when the bounds are changed out from under them. So we |
---|
| 1082 | need to do all the work associated with finding a new solution before |
---|
| 1083 | restoring the bounds. |
---|
| 1084 | */ |
---|
| 1085 | for (i = 0 ; i < numberStrong ; i++) { |
---|
| 1086 | double objectiveChange ; |
---|
| 1087 | double newObjectiveValue = 1.0e100; |
---|
| 1088 | // status is 0 finished, 1 infeasible and other |
---|
| 1089 | int iStatus; |
---|
| 1090 | /* |
---|
| 1091 | Try the down direction first. (Specify the initial branching alternative as |
---|
| 1092 | down with a call to way(-1). Each subsequent call to branch() performs the |
---|
| 1093 | specified branch and advances the branch object state to the next branch |
---|
| 1094 | alternative.) |
---|
| 1095 | */ |
---|
| 1096 | if (!clp) { |
---|
| 1097 | choice[i].possibleBranch->way(-1) ; |
---|
| 1098 | choice[i].possibleBranch->branch() ; |
---|
| 1099 | bool feasible = true; |
---|
| 1100 | if (checkFeasibility) { |
---|
| 1101 | // check branching did not make infeasible |
---|
| 1102 | int iColumn; |
---|
| 1103 | int numberColumns = solver->getNumCols(); |
---|
| 1104 | const double * columnLower = solver->getColLower(); |
---|
| 1105 | const double * columnUpper = solver->getColUpper(); |
---|
| 1106 | for (iColumn = 0; iColumn < numberColumns; iColumn++) { |
---|
| 1107 | if (columnLower[iColumn] > columnUpper[iColumn] + 1.0e-5) |
---|
| 1108 | feasible = false; |
---|
| 1109 | } |
---|
| 1110 | } |
---|
| 1111 | if (feasible) { |
---|
| 1112 | solver->solveFromHotStart() ; |
---|
| 1113 | numberStrongDone++; |
---|
| 1114 | numberStrongIterations += solver->getIterationCount(); |
---|
| 1115 | /* |
---|
| 1116 | We now have an estimate of objective degradation that we can use for strong |
---|
| 1117 | branching. If we're over the cutoff, the variable is monotone up. |
---|
| 1118 | If we actually made it to optimality, check for a solution, and if we have |
---|
| 1119 | a good one, call setBestSolution to process it. Note that this may reduce the |
---|
| 1120 | cutoff, so we check again to see if we can declare this variable monotone. |
---|
| 1121 | */ |
---|
| 1122 | if (solver->isProvenOptimal()) |
---|
| 1123 | iStatus = 0; // optimal |
---|
| 1124 | else if (solver->isIterationLimitReached() |
---|
| 1125 | && !solver->isDualObjectiveLimitReached()) |
---|
| 1126 | iStatus = 2; // unknown |
---|
| 1127 | else |
---|
| 1128 | iStatus = 1; // infeasible |
---|
| 1129 | newObjectiveValue = solver->getObjSense() * solver->getObjValue(); |
---|
| 1130 | choice[i].numItersDown = solver->getIterationCount(); |
---|
| 1131 | } else { |
---|
| 1132 | iStatus = 1; // infeasible |
---|
| 1133 | newObjectiveValue = 1.0e100; |
---|
| 1134 | choice[i].numItersDown = 0; |
---|
| 1135 | } |
---|
| 1136 | } else { |
---|
| 1137 | iStatus = outputStuff[2*i]; |
---|
| 1138 | choice[i].numItersDown = outputStuff[2*numberStrong+2*i]; |
---|
| 1139 | numberStrongDone++; |
---|
| 1140 | numberStrongIterations += choice[i].numItersDown; |
---|
| 1141 | newObjectiveValue = objectiveValue + newUpper[i]; |
---|
| 1142 | solver->setColSolution(outputSolution[2*i]); |
---|
| 1143 | } |
---|
| 1144 | objectiveChange = CoinMax(newObjectiveValue - objectiveValue_, 0.0); |
---|
| 1145 | if (!iStatus) { |
---|
| 1146 | choice[i].finishedDown = true ; |
---|
| 1147 | if (newObjectiveValue >= model->getCutoff()) { |
---|
| 1148 | objectiveChange = 1.0e100; // say infeasible |
---|
| 1149 | numberStrongInfeasible++; |
---|
| 1150 | } else { |
---|
| 1151 | // See if integer solution |
---|
| 1152 | if (model->feasibleSolution(choice[i].numIntInfeasDown, |
---|
| 1153 | choice[i].numObjInfeasDown) |
---|
| 1154 | && model->problemFeasibility()->feasible(model, -1) >= 0) { |
---|
| 1155 | model->setBestSolution(CBC_STRONGSOL, |
---|
| 1156 | newObjectiveValue, |
---|
| 1157 | solver->getColSolution()) ; |
---|
| 1158 | // only needed for odd solvers |
---|
| 1159 | newObjectiveValue = solver->getObjSense() * solver->getObjValue(); |
---|
| 1160 | objectiveChange = CoinMax(newObjectiveValue - objectiveValue_, 0.0) ; |
---|
| 1161 | model->setLastHeuristic(NULL); |
---|
| 1162 | model->incrementUsed(solver->getColSolution()); |
---|
| 1163 | if (newObjectiveValue >= model->getCutoff()) { // *new* cutoff |
---|
| 1164 | objectiveChange = 1.0e100 ; |
---|
| 1165 | numberStrongInfeasible++; |
---|
| 1166 | } |
---|
| 1167 | } |
---|
| 1168 | } |
---|
| 1169 | } else if (iStatus == 1) { |
---|
| 1170 | objectiveChange = 1.0e100 ; |
---|
| 1171 | numberStrongInfeasible++; |
---|
| 1172 | } else { |
---|
| 1173 | // Can't say much as we did not finish |
---|
| 1174 | choice[i].finishedDown = false ; |
---|
| 1175 | numberUnfinished++; |
---|
| 1176 | } |
---|
| 1177 | choice[i].downMovement = objectiveChange ; |
---|
| 1178 | |
---|
| 1179 | // restore bounds |
---|
| 1180 | if (!clp) { |
---|
| 1181 | for (int j = 0; j < numberColumns; j++) { |
---|
| 1182 | if (saveLower[j] != lower[j]) |
---|
| 1183 | solver->setColLower(j, saveLower[j]); |
---|
| 1184 | if (saveUpper[j] != upper[j]) |
---|
| 1185 | solver->setColUpper(j, saveUpper[j]); |
---|
| 1186 | } |
---|
| 1187 | } |
---|
| 1188 | //printf("Down on %d, status is %d, obj %g its %d cost %g finished %d inf %d infobj %d\n", |
---|
| 1189 | // choice[i].objectNumber,iStatus,newObjectiveValue,choice[i].numItersDown, |
---|
| 1190 | // choice[i].downMovement,choice[i].finishedDown,choice[i].numIntInfeasDown, |
---|
| 1191 | // choice[i].numObjInfeasDown); |
---|
| 1192 | |
---|
| 1193 | // repeat the whole exercise, forcing the variable up |
---|
| 1194 | if (!clp) { |
---|
| 1195 | bool feasible = true; |
---|
| 1196 | // If odd branching then maybe just one possibility |
---|
| 1197 | if (choice[i].possibleBranch->numberBranchesLeft() > 0) { |
---|
| 1198 | choice[i].possibleBranch->branch(); |
---|
| 1199 | if (checkFeasibility) { |
---|
| 1200 | // check branching did not make infeasible |
---|
| 1201 | int iColumn; |
---|
| 1202 | int numberColumns = solver->getNumCols(); |
---|
| 1203 | const double * columnLower = solver->getColLower(); |
---|
| 1204 | const double * columnUpper = solver->getColUpper(); |
---|
| 1205 | for (iColumn = 0; iColumn < numberColumns; iColumn++) { |
---|
| 1206 | if (columnLower[iColumn] > columnUpper[iColumn] + 1.0e-5) |
---|
| 1207 | feasible = false; |
---|
| 1208 | } |
---|
| 1209 | } |
---|
| 1210 | } else { |
---|
| 1211 | // second branch infeasible |
---|
| 1212 | feasible = false; |
---|
| 1213 | } |
---|
| 1214 | if (feasible) { |
---|
| 1215 | solver->solveFromHotStart() ; |
---|
| 1216 | numberStrongDone++; |
---|
| 1217 | numberStrongIterations += solver->getIterationCount(); |
---|
| 1218 | /* |
---|
| 1219 | We now have an estimate of objective degradation that we can use for strong |
---|
| 1220 | branching. If we're over the cutoff, the variable is monotone up. |
---|
| 1221 | If we actually made it to optimality, check for a solution, and if we have |
---|
| 1222 | a good one, call setBestSolution to process it. Note that this may reduce the |
---|
| 1223 | cutoff, so we check again to see if we can declare this variable monotone. |
---|
| 1224 | */ |
---|
| 1225 | if (solver->isProvenOptimal()) |
---|
| 1226 | iStatus = 0; // optimal |
---|
| 1227 | else if (solver->isIterationLimitReached() |
---|
| 1228 | && !solver->isDualObjectiveLimitReached()) |
---|
| 1229 | iStatus = 2; // unknown |
---|
| 1230 | else |
---|
| 1231 | iStatus = 1; // infeasible |
---|
| 1232 | newObjectiveValue = solver->getObjSense() * solver->getObjValue(); |
---|
| 1233 | choice[i].numItersUp = solver->getIterationCount(); |
---|
| 1234 | } else { |
---|
| 1235 | iStatus = 1; // infeasible |
---|
| 1236 | newObjectiveValue = 1.0e100; |
---|
| 1237 | choice[i].numItersDown = 0; |
---|
| 1238 | } |
---|
| 1239 | } else { |
---|
| 1240 | iStatus = outputStuff[2*i+1]; |
---|
| 1241 | choice[i].numItersUp = outputStuff[2*numberStrong+2*i+1]; |
---|
| 1242 | numberStrongDone++; |
---|
| 1243 | numberStrongIterations += choice[i].numItersUp; |
---|
| 1244 | newObjectiveValue = objectiveValue + newLower[i]; |
---|
| 1245 | solver->setColSolution(outputSolution[2*i+1]); |
---|
| 1246 | } |
---|
| 1247 | objectiveChange = CoinMax(newObjectiveValue - objectiveValue_, 0.0); |
---|
| 1248 | if (!iStatus) { |
---|
| 1249 | choice[i].finishedUp = true ; |
---|
| 1250 | if (newObjectiveValue >= model->getCutoff()) { |
---|
| 1251 | objectiveChange = 1.0e100; // say infeasible |
---|
| 1252 | numberStrongInfeasible++; |
---|
| 1253 | } else { |
---|
| 1254 | // See if integer solution |
---|
| 1255 | if (model->feasibleSolution(choice[i].numIntInfeasUp, |
---|
| 1256 | choice[i].numObjInfeasUp) |
---|
| 1257 | && model->problemFeasibility()->feasible(model, -1) >= 0) { |
---|
| 1258 | model->setBestSolution(CBC_STRONGSOL, |
---|
| 1259 | newObjectiveValue, |
---|
| 1260 | solver->getColSolution()) ; |
---|
| 1261 | // only needed for odd solvers |
---|
| 1262 | newObjectiveValue = solver->getObjSense() * solver->getObjValue(); |
---|
| 1263 | objectiveChange = CoinMax(newObjectiveValue - objectiveValue_, 0.0) ; |
---|
| 1264 | model->setLastHeuristic(NULL); |
---|
| 1265 | model->incrementUsed(solver->getColSolution()); |
---|
| 1266 | if (newObjectiveValue >= model->getCutoff()) { // *new* cutoff |
---|
| 1267 | objectiveChange = 1.0e100 ; |
---|
| 1268 | numberStrongInfeasible++; |
---|
| 1269 | } |
---|
| 1270 | } |
---|
| 1271 | } |
---|
| 1272 | } else if (iStatus == 1) { |
---|
| 1273 | objectiveChange = 1.0e100 ; |
---|
| 1274 | numberStrongInfeasible++; |
---|
| 1275 | } else { |
---|
| 1276 | // Can't say much as we did not finish |
---|
| 1277 | choice[i].finishedUp = false ; |
---|
| 1278 | numberUnfinished++; |
---|
| 1279 | } |
---|
| 1280 | choice[i].upMovement = objectiveChange ; |
---|
| 1281 | |
---|
| 1282 | // restore bounds |
---|
| 1283 | if (!clp) { |
---|
| 1284 | for (int j = 0; j < numberColumns; j++) { |
---|
| 1285 | if (saveLower[j] != lower[j]) |
---|
| 1286 | solver->setColLower(j, saveLower[j]); |
---|
| 1287 | if (saveUpper[j] != upper[j]) |
---|
| 1288 | solver->setColUpper(j, saveUpper[j]); |
---|
| 1289 | } |
---|
| 1290 | } |
---|
| 1291 | |
---|
| 1292 | //printf("Up on %d, status is %d, obj %g its %d cost %g finished %d inf %d infobj %d\n", |
---|
| 1293 | // choice[i].objectNumber,iStatus,newObjectiveValue,choice[i].numItersUp, |
---|
| 1294 | // choice[i].upMovement,choice[i].finishedUp,choice[i].numIntInfeasUp, |
---|
| 1295 | // choice[i].numObjInfeasUp); |
---|
| 1296 | |
---|
| 1297 | /* |
---|
| 1298 | End of evaluation for this candidate variable. Possibilities are: |
---|
| 1299 | * Both sides below cutoff; this variable is a candidate for branching. |
---|
| 1300 | * Both sides infeasible or above the objective cutoff: no further action |
---|
| 1301 | here. Break from the evaluation loop and assume the node will be purged |
---|
| 1302 | by the caller. |
---|
| 1303 | * One side below cutoff: Install the branch (i.e., fix the variable). Break |
---|
| 1304 | from the evaluation loop and assume the node will be reoptimised by the |
---|
| 1305 | caller. |
---|
| 1306 | */ |
---|
| 1307 | // reset |
---|
| 1308 | choice[i].possibleBranch->resetNumberBranchesLeft(); |
---|
| 1309 | if (choice[i].upMovement < 1.0e100) { |
---|
| 1310 | if (choice[i].downMovement < 1.0e100) { |
---|
| 1311 | // feasible - no action |
---|
| 1312 | } else { |
---|
| 1313 | // up feasible, down infeasible |
---|
| 1314 | anyAction = -1; |
---|
| 1315 | //printf("Down infeasible for choice %d sequence %d\n",i, |
---|
| 1316 | // model->object(choice[i].objectNumber)->columnNumber()); |
---|
| 1317 | if (!solveAll) { |
---|
| 1318 | choice[i].possibleBranch->way(1); |
---|
| 1319 | choice[i].possibleBranch->branch(); |
---|
| 1320 | break; |
---|
| 1321 | } else { |
---|
| 1322 | choice[i].fix = 1; |
---|
| 1323 | } |
---|
| 1324 | } |
---|
| 1325 | } else { |
---|
| 1326 | if (choice[i].downMovement < 1.0e100) { |
---|
| 1327 | // down feasible, up infeasible |
---|
| 1328 | anyAction = -1; |
---|
| 1329 | //printf("Up infeasible for choice %d sequence %d\n",i, |
---|
| 1330 | // model->object(choice[i].objectNumber)->columnNumber()); |
---|
| 1331 | if (!solveAll) { |
---|
| 1332 | choice[i].possibleBranch->way(-1); |
---|
| 1333 | choice[i].possibleBranch->branch(); |
---|
| 1334 | break; |
---|
| 1335 | } else { |
---|
| 1336 | choice[i].fix = -1; |
---|
| 1337 | } |
---|
| 1338 | } else { |
---|
| 1339 | // neither side feasible |
---|
| 1340 | anyAction = -2; |
---|
| 1341 | //printf("Both infeasible for choice %d sequence %d\n",i, |
---|
| 1342 | // model->object(choice[i].objectNumber)->columnNumber()); |
---|
| 1343 | break; |
---|
| 1344 | } |
---|
| 1345 | } |
---|
| 1346 | bool hitMaxTime = ( CoinCpuTime() - model->getDblParam(CbcModel::CbcStartSeconds) > |
---|
| 1347 | model->getDblParam(CbcModel::CbcMaximumSeconds)); |
---|
| 1348 | if (hitMaxTime) { |
---|
| 1349 | numberStrong = i + 1; |
---|
| 1350 | break; |
---|
| 1351 | } |
---|
| 1352 | } |
---|
| 1353 | if (!clp) { |
---|
| 1354 | // Delete the snapshot |
---|
| 1355 | solver->unmarkHotStart(); |
---|
[122] | 1356 | } else { |
---|
[1286] | 1357 | delete [] newLower; |
---|
| 1358 | delete [] newUpper; |
---|
| 1359 | delete [] outputStuff; |
---|
| 1360 | int i; |
---|
| 1361 | for (i = 0; i < 2*numberStrong; i++) |
---|
| 1362 | delete [] outputSolution[i]; |
---|
| 1363 | delete [] outputSolution; |
---|
[122] | 1364 | } |
---|
[1286] | 1365 | solver->setIntParam(OsiMaxNumIterationHotStart, saveLimit); |
---|
| 1366 | // restore basis |
---|
| 1367 | solver->setWarmStart(ws); |
---|
| 1368 | // Unless infeasible we will carry on |
---|
| 1369 | // But we could fix anyway |
---|
| 1370 | if (anyAction == -1 && solveAll) { |
---|
| 1371 | // apply and take off |
---|
| 1372 | for (i = 0 ; i < numberStrong ; i++) { |
---|
| 1373 | if (choice[i].fix) { |
---|
| 1374 | choice[i].possibleBranch->way(choice[i].fix) ; |
---|
| 1375 | choice[i].possibleBranch->branch() ; |
---|
| 1376 | } |
---|
| 1377 | } |
---|
| 1378 | bool feasible = true; |
---|
| 1379 | if (checkFeasibility) { |
---|
| 1380 | // check branching did not make infeasible |
---|
| 1381 | int iColumn; |
---|
| 1382 | int numberColumns = solver->getNumCols(); |
---|
| 1383 | const double * columnLower = solver->getColLower(); |
---|
| 1384 | const double * columnUpper = solver->getColUpper(); |
---|
| 1385 | for (iColumn = 0; iColumn < numberColumns; iColumn++) { |
---|
| 1386 | if (columnLower[iColumn] > columnUpper[iColumn] + 1.0e-5) |
---|
| 1387 | feasible = false; |
---|
| 1388 | } |
---|
| 1389 | } |
---|
| 1390 | if (feasible) { |
---|
| 1391 | // can do quick optimality check |
---|
| 1392 | int easy = 2; |
---|
| 1393 | solver->setHintParam(OsiDoInBranchAndCut, true, OsiHintDo, &easy) ; |
---|
| 1394 | solver->resolve() ; |
---|
| 1395 | solver->setHintParam(OsiDoInBranchAndCut, true, OsiHintDo, NULL) ; |
---|
| 1396 | feasible = solver->isProvenOptimal(); |
---|
| 1397 | } |
---|
| 1398 | if (feasible) { |
---|
| 1399 | memcpy(saveSolution, solver->getColSolution(), numberColumns*sizeof(double)); |
---|
| 1400 | model->reserveCurrentSolution(saveSolution); |
---|
| 1401 | memcpy(saveLower, solver->getColLower(), numberColumns*sizeof(double)); |
---|
| 1402 | memcpy(saveUpper, solver->getColUpper(), numberColumns*sizeof(double)); |
---|
| 1403 | // Clean up all candidates whih are fixed |
---|
| 1404 | int numberLeft = 0; |
---|
| 1405 | for (i = 0 ; i < numberStrong ; i++) { |
---|
| 1406 | CbcStrongInfo thisChoice = choice[i]; |
---|
| 1407 | choice[i].possibleBranch = NULL; |
---|
| 1408 | const OsiObject * object = model->object(thisChoice.objectNumber); |
---|
| 1409 | int preferredWay; |
---|
| 1410 | double infeasibility = object->infeasibility(&usefulInfo, preferredWay); |
---|
| 1411 | if (!infeasibility) { |
---|
| 1412 | // take out |
---|
| 1413 | delete thisChoice.possibleBranch; |
---|
| 1414 | } else { |
---|
| 1415 | choice[numberLeft++] = thisChoice; |
---|
| 1416 | } |
---|
| 1417 | } |
---|
| 1418 | numberStrong = numberLeft; |
---|
| 1419 | for (; i < maximumStrong; i++) { |
---|
| 1420 | delete choice[i].possibleBranch; |
---|
| 1421 | choice[i].possibleBranch = NULL; |
---|
| 1422 | } |
---|
| 1423 | // If all fixed then round again |
---|
| 1424 | if (!numberLeft) { |
---|
| 1425 | finished = false; |
---|
| 1426 | numberStrong = 0; |
---|
| 1427 | saveNumberStrong = 0; |
---|
| 1428 | maximumStrong = 1; |
---|
| 1429 | } else { |
---|
| 1430 | anyAction = 0; |
---|
| 1431 | } |
---|
| 1432 | // If these two uncommented then different action |
---|
| 1433 | anyAction = -1; |
---|
| 1434 | finished = true; |
---|
| 1435 | //printf("some fixed but continuing %d left\n",numberLeft); |
---|
| 1436 | } else { |
---|
| 1437 | anyAction = -2; // say infeasible |
---|
| 1438 | } |
---|
| 1439 | } |
---|
| 1440 | delete ws; |
---|
| 1441 | int numberNodes = model->getNodeCount(); |
---|
| 1442 | // update number of strong iterations etc |
---|
| 1443 | model->incrementStrongInfo(numberStrongDone, numberStrongIterations, |
---|
| 1444 | anyAction == -2 ? 0 : numberStrongInfeasible, anyAction == -2); |
---|
| 1445 | |
---|
| 1446 | /* |
---|
| 1447 | anyAction >= 0 indicates that strong branching didn't produce any monotone |
---|
| 1448 | variables. Sift through the candidates for the best one. |
---|
| 1449 | |
---|
| 1450 | QUERY: Setting numberNodes looks to be a distributed noop. numberNodes is |
---|
| 1451 | local to this code block. Perhaps should be numberNodes_ from model? |
---|
| 1452 | Unclear what this calculation is doing. |
---|
| 1453 | */ |
---|
| 1454 | if (anyAction >= 0) { |
---|
| 1455 | |
---|
| 1456 | // get average cost per iteration and assume stopped ones |
---|
| 1457 | // would stop after 50% more iterations at average cost??? !!! ??? |
---|
| 1458 | double averageCostPerIteration = 0.0; |
---|
| 1459 | double totalNumberIterations = 1.0; |
---|
| 1460 | int smallestNumberInfeasibilities = COIN_INT_MAX; |
---|
| 1461 | for (i = 0; i < numberStrong; i++) { |
---|
| 1462 | totalNumberIterations += choice[i].numItersDown + |
---|
| 1463 | choice[i].numItersUp ; |
---|
| 1464 | averageCostPerIteration += choice[i].downMovement + |
---|
| 1465 | choice[i].upMovement; |
---|
| 1466 | smallestNumberInfeasibilities = |
---|
| 1467 | CoinMin(CoinMin(choice[i].numIntInfeasDown , |
---|
| 1468 | choice[i].numIntInfeasUp ), |
---|
| 1469 | smallestNumberInfeasibilities); |
---|
| 1470 | } |
---|
| 1471 | //if (smallestNumberInfeasibilities>=numberIntegerInfeasibilities) |
---|
| 1472 | //numberNodes=1000000; // switch off search for better solution |
---|
| 1473 | numberNodes = 1000000; // switch off anyway |
---|
| 1474 | averageCostPerIteration /= totalNumberIterations; |
---|
| 1475 | // all feasible - choose best bet |
---|
| 1476 | |
---|
| 1477 | // New method does all at once so it can be more sophisticated |
---|
| 1478 | // in deciding how to balance actions. |
---|
| 1479 | // But it does need arrays |
---|
| 1480 | double * changeUp = new double [numberStrong]; |
---|
| 1481 | int * numberInfeasibilitiesUp = new int [numberStrong]; |
---|
| 1482 | double * changeDown = new double [numberStrong]; |
---|
| 1483 | int * numberInfeasibilitiesDown = new int [numberStrong]; |
---|
| 1484 | CbcBranchingObject ** objects = new CbcBranchingObject * [ numberStrong]; |
---|
| 1485 | for (i = 0 ; i < numberStrong ; i++) { |
---|
| 1486 | int iColumn = choice[i].possibleBranch->variable() ; |
---|
| 1487 | model->messageHandler()->message(CBC_STRONG, *model->messagesPointer()) |
---|
| 1488 | << i << iColumn |
---|
| 1489 | << choice[i].downMovement << choice[i].numIntInfeasDown |
---|
| 1490 | << choice[i].upMovement << choice[i].numIntInfeasUp |
---|
| 1491 | << choice[i].possibleBranch->value() |
---|
| 1492 | << CoinMessageEol; |
---|
| 1493 | changeUp[i] = choice[i].upMovement; |
---|
| 1494 | numberInfeasibilitiesUp[i] = choice[i].numIntInfeasUp; |
---|
| 1495 | changeDown[i] = choice[i].downMovement; |
---|
| 1496 | numberInfeasibilitiesDown[i] = choice[i].numIntInfeasDown; |
---|
| 1497 | objects[i] = choice[i].possibleBranch; |
---|
| 1498 | } |
---|
| 1499 | int whichObject = decision->bestBranch(objects, numberStrong, numberUnsatisfied_, |
---|
| 1500 | changeUp, numberInfeasibilitiesUp, |
---|
| 1501 | changeDown, numberInfeasibilitiesDown, |
---|
| 1502 | objectiveValue_); |
---|
| 1503 | // move branching object and make sure it will not be deleted |
---|
| 1504 | if (whichObject >= 0) { |
---|
| 1505 | branch_ = objects[whichObject]; |
---|
| 1506 | if (model->messageHandler()->logLevel() > 3) |
---|
| 1507 | printf("Choosing column %d\n", choice[whichObject].possibleBranch->variable()) ; |
---|
| 1508 | choice[whichObject].possibleBranch = NULL; |
---|
| 1509 | } |
---|
| 1510 | delete [] changeUp; |
---|
| 1511 | delete [] numberInfeasibilitiesUp; |
---|
| 1512 | delete [] changeDown; |
---|
| 1513 | delete [] numberInfeasibilitiesDown; |
---|
| 1514 | delete [] objects; |
---|
| 1515 | } |
---|
| 1516 | # ifdef COIN_HAS_CLP |
---|
| 1517 | if (osiclp && !allNormal) { |
---|
| 1518 | // back to normal |
---|
| 1519 | osiclp->setHintParam(OsiDoInBranchAndCut, true, OsiHintDo, NULL) ; |
---|
| 1520 | } |
---|
| 1521 | # endif |
---|
[104] | 1522 | } |
---|
[1286] | 1523 | /* |
---|
| 1524 | Simple branching. Probably just one, but we may have got here |
---|
| 1525 | because of an odd branch e.g. a cut |
---|
| 1526 | */ |
---|
| 1527 | else { |
---|
| 1528 | // not strong |
---|
| 1529 | // C) create branching object |
---|
| 1530 | branch_ = choice[bestChoice].possibleBranch; |
---|
| 1531 | choice[bestChoice].possibleBranch = NULL; |
---|
[122] | 1532 | } |
---|
[2] | 1533 | } |
---|
[1286] | 1534 | // Set guessed solution value |
---|
| 1535 | guessedObjectiveValue_ = objectiveValue_ + estimatedDegradation; |
---|
[122] | 1536 | /* |
---|
[1286] | 1537 | Cleanup, then we're outta here. |
---|
[122] | 1538 | */ |
---|
[1286] | 1539 | if (!model->branchingMethod() || dynamicBranchingObject) |
---|
| 1540 | delete decision; |
---|
| 1541 | |
---|
| 1542 | for (i = 0; i < maximumStrong; i++) |
---|
| 1543 | delete choice[i].possibleBranch; |
---|
| 1544 | delete [] choice; |
---|
| 1545 | delete [] saveLower; |
---|
| 1546 | delete [] saveUpper; |
---|
| 1547 | |
---|
| 1548 | // restore solution |
---|
| 1549 | solver->setColSolution(saveSolution); |
---|
| 1550 | delete [] saveSolution; |
---|
[1133] | 1551 | # ifdef COIN_HAS_CLP |
---|
[1286] | 1552 | if (osiclp) |
---|
| 1553 | osiclp->setSpecialOptions(saveClpOptions); |
---|
[1133] | 1554 | # endif |
---|
[1286] | 1555 | return anyAction; |
---|
[2] | 1556 | } |
---|
| 1557 | |
---|
[135] | 1558 | /* |
---|
| 1559 | Version for dynamic pseudo costs. |
---|
[1286] | 1560 | |
---|
[135] | 1561 | **** For now just return if anything odd |
---|
| 1562 | later allow even if odd |
---|
[1286] | 1563 | |
---|
[135] | 1564 | The routine scans through the object list of the model looking for objects |
---|
| 1565 | that indicate infeasibility. It tests each object using strong branching |
---|
| 1566 | and selects the one with the least objective degradation. A corresponding |
---|
| 1567 | branching object is left attached to lastNode. |
---|
| 1568 | This version gives preference in evaluation to variables which |
---|
| 1569 | have not been evaluated many times. It also uses numberStrong |
---|
| 1570 | to say give up if last few tries have not changed incumbent. |
---|
| 1571 | See Achterberg, Koch and Martin. |
---|
[1286] | 1572 | |
---|
[135] | 1573 | If strong branching is disabled, a candidate object is chosen essentially |
---|
| 1574 | at random (whatever object ends up in pos'n 0 of the candidate array). |
---|
[1286] | 1575 | |
---|
[135] | 1576 | If a branching candidate is found to be monotone, bounds are set to fix the |
---|
| 1577 | variable and the routine immediately returns (the caller is expected to |
---|
| 1578 | reoptimize). |
---|
[1286] | 1579 | |
---|
[135] | 1580 | If a branching candidate is found to result in infeasibility in both |
---|
| 1581 | directions, the routine immediately returns an indication of infeasibility. |
---|
[1286] | 1582 | |
---|
[135] | 1583 | Returns: 0 both branch directions are feasible |
---|
[1271] | 1584 | -1 branching variable is monotone |
---|
| 1585 | -2 infeasible |
---|
| 1586 | -3 Use another method |
---|
[1286] | 1587 | |
---|
[1271] | 1588 | For now just fix on objective from strong branching. |
---|
[135] | 1589 | */ |
---|
| 1590 | |
---|
[222] | 1591 | int CbcNode::chooseDynamicBranch (CbcModel *model, CbcNode *lastNode, |
---|
[1271] | 1592 | OsiSolverBranch * & /*branches*/, |
---|
[1286] | 1593 | int numberPassesLeft) |
---|
| 1594 | |
---|
| 1595 | { |
---|
| 1596 | if (lastNode) |
---|
| 1597 | depth_ = lastNode->depth_ + 1; |
---|
| 1598 | else |
---|
| 1599 | depth_ = 0; |
---|
| 1600 | // Go to other choose if hot start |
---|
| 1601 | if (model->hotstartSolution() && |
---|
| 1602 | (((model->moreSpecialOptions()&1024) == 0) || false)) |
---|
| 1603 | return -3; |
---|
| 1604 | delete branch_; |
---|
| 1605 | branch_ = NULL; |
---|
| 1606 | OsiSolverInterface * solver = model->solver(); |
---|
| 1607 | // get information on solver type |
---|
| 1608 | const OsiAuxInfo * auxInfo = solver->getAuxiliaryInfo(); |
---|
| 1609 | const OsiBabSolver * auxiliaryInfo = dynamic_cast<const OsiBabSolver *> (auxInfo); |
---|
| 1610 | if (!auxiliaryInfo) { |
---|
| 1611 | // use one from CbcModel |
---|
| 1612 | auxiliaryInfo = model->solverCharacteristics(); |
---|
[1271] | 1613 | } |
---|
[1286] | 1614 | int numberObjects = model->numberObjects(); |
---|
| 1615 | // If very odd set of objects then use older chooseBranch |
---|
| 1616 | bool useOldWay = false; |
---|
| 1617 | // point to useful information |
---|
| 1618 | OsiBranchingInformation usefulInfo = model->usefulInformation(); |
---|
| 1619 | if (numberObjects > model->numberIntegers()) { |
---|
| 1620 | for (int i = model->numberIntegers(); i < numberObjects; i++) { |
---|
| 1621 | OsiObject * object = model->modifiableObject(i); |
---|
| 1622 | CbcObject * obj = dynamic_cast <CbcObject *>(object) ; |
---|
| 1623 | if (!obj || !obj->optionalObject()) { |
---|
| 1624 | int preferredWay; |
---|
| 1625 | double infeasibility = object->infeasibility(&usefulInfo, preferredWay); |
---|
| 1626 | if (infeasibility) { |
---|
| 1627 | useOldWay = true; |
---|
| 1628 | break; |
---|
| 1629 | } |
---|
| 1630 | } |
---|
| 1631 | } |
---|
| 1632 | } |
---|
| 1633 | if ((model->specialOptions()&128) != 0) |
---|
| 1634 | useOldWay = false; // allow |
---|
| 1635 | // For now return if not simple |
---|
| 1636 | if (useOldWay) |
---|
| 1637 | return -3; |
---|
| 1638 | // Modify useful info |
---|
| 1639 | usefulInfo.depth_ = depth_; |
---|
| 1640 | if ((model->specialOptions()&128) != 0) { |
---|
| 1641 | // SOS - shadow prices |
---|
| 1642 | int numberRows = solver->getNumRows(); |
---|
| 1643 | const double * pi = usefulInfo.pi_; |
---|
| 1644 | double sumPi = 0.0; |
---|
| 1645 | for (int i = 0; i < numberRows; i++) |
---|
| 1646 | sumPi += fabs(pi[i]); |
---|
| 1647 | sumPi /= static_cast<double> (numberRows); |
---|
| 1648 | // and scale back |
---|
| 1649 | sumPi *= 0.01; |
---|
| 1650 | usefulInfo.defaultDual_ = sumPi; // switch on |
---|
| 1651 | int numberColumns = solver->getNumCols(); |
---|
| 1652 | int size = CoinMax(numberColumns, 2 * numberRows); |
---|
| 1653 | usefulInfo.usefulRegion_ = new double [size]; |
---|
| 1654 | CoinZeroN(usefulInfo.usefulRegion_, size); |
---|
| 1655 | usefulInfo.indexRegion_ = new int [size]; |
---|
| 1656 | // pi may change |
---|
| 1657 | usefulInfo.pi_ = CoinCopyOfArray(usefulInfo.pi_, numberRows); |
---|
| 1658 | } |
---|
| 1659 | assert (auxiliaryInfo); |
---|
| 1660 | double cutoff = model->getCutoff(); |
---|
| 1661 | const double * lower = solver->getColLower(); |
---|
| 1662 | const double * upper = solver->getColUpper(); |
---|
| 1663 | // See if user thinks infeasible |
---|
| 1664 | int anyAction = model->problemFeasibility()->feasible(model, 0); |
---|
| 1665 | if (anyAction) { |
---|
| 1666 | // will return -2 if infeasible , 0 if treat as integer |
---|
| 1667 | return anyAction - 1; |
---|
| 1668 | } |
---|
| 1669 | int i; |
---|
| 1670 | int saveStateOfSearch = model->stateOfSearch() % 10; |
---|
| 1671 | int numberStrong = model->numberStrong(); |
---|
| 1672 | /* Ranging is switched off. |
---|
| 1673 | The idea is that you can find out the effect of one iteration |
---|
| 1674 | on each unsatisfied variable cheaply. Then use this |
---|
| 1675 | if you have not got much else to go on. |
---|
| 1676 | */ |
---|
| 1677 | //#define RANGING |
---|
[259] | 1678 | #ifdef RANGING |
---|
[1286] | 1679 | // must have clp |
---|
[1271] | 1680 | #ifndef COIN_HAS_CLP |
---|
| 1681 | # warning("Ranging switched off as not Clp"); |
---|
| 1682 | #undef RANGING |
---|
| 1683 | #endif |
---|
[1286] | 1684 | // Pass number |
---|
| 1685 | int kPass = 0; |
---|
| 1686 | int numberRows = solver->getNumRows(); |
---|
[259] | 1687 | #endif |
---|
[1286] | 1688 | int numberColumns = model->getNumCols(); |
---|
| 1689 | double * saveUpper = new double[numberColumns]; |
---|
| 1690 | double * saveLower = new double[numberColumns]; |
---|
| 1691 | for (i = 0; i < numberColumns; i++) { |
---|
| 1692 | saveLower[i] = lower[i]; |
---|
| 1693 | saveUpper[i] = upper[i]; |
---|
| 1694 | } |
---|
| 1695 | |
---|
| 1696 | // Save solution in case heuristics need good solution later |
---|
| 1697 | |
---|
| 1698 | double * saveSolution = new double[numberColumns]; |
---|
| 1699 | memcpy(saveSolution, solver->getColSolution(), numberColumns*sizeof(double)); |
---|
| 1700 | model->reserveCurrentSolution(saveSolution); |
---|
| 1701 | const double * hotstartSolution = model->hotstartSolution(); |
---|
| 1702 | const int * hotstartPriorities = model->hotstartPriorities(); |
---|
| 1703 | double integerTolerance = |
---|
| 1704 | model->getDblParam(CbcModel::CbcIntegerTolerance); |
---|
| 1705 | if (hotstartSolution) { |
---|
| 1706 | if ((model->moreSpecialOptions()&1024) != 0) { |
---|
| 1707 | int nBad = 0; |
---|
| 1708 | int nUnsat = 0; |
---|
| 1709 | int nDiff = 0; |
---|
| 1710 | for (int i = 0; i < numberObjects; i++) { |
---|
| 1711 | OsiObject * object = model->modifiableObject(i); |
---|
| 1712 | const CbcSimpleInteger * thisOne = dynamic_cast <const CbcSimpleInteger *> (object); |
---|
| 1713 | if (thisOne) { |
---|
| 1714 | int iColumn = thisOne->columnNumber(); |
---|
| 1715 | double targetValue = hotstartSolution[iColumn]; |
---|
| 1716 | double value = saveSolution[iColumn]; |
---|
| 1717 | if (fabs(value - floor(value + 0.5)) > 1.0e-6) { |
---|
| 1718 | nUnsat++; |
---|
| 1719 | #ifdef CLP_INVESTIGATE |
---|
| 1720 | printf("H %d is %g target %g\n", iColumn, value, targetValue); |
---|
[1271] | 1721 | #endif |
---|
[1286] | 1722 | } else if (fabs(targetValue - value) > 1.0e-6) { |
---|
| 1723 | nDiff++; |
---|
| 1724 | } |
---|
| 1725 | if (targetValue < saveLower[iColumn] || |
---|
| 1726 | targetValue > saveUpper[iColumn]) { |
---|
| 1727 | #ifdef CLP_INVESTIGATE |
---|
| 1728 | printf("%d has target %g and current bounds %g and %g\n", |
---|
| 1729 | iColumn, targetValue, saveLower[iColumn], saveUpper[iColumn]); |
---|
[1271] | 1730 | #endif |
---|
[1286] | 1731 | nBad++; |
---|
| 1732 | } |
---|
| 1733 | } |
---|
| 1734 | } |
---|
| 1735 | #ifdef CLP_INVESTIGATE |
---|
| 1736 | printf("Hot %d unsatisfied, %d outside limits, %d different\n", |
---|
| 1737 | nUnsat, nBad, nDiff); |
---|
[1271] | 1738 | #endif |
---|
[1286] | 1739 | if (nBad) { |
---|
| 1740 | // switch off as not possible |
---|
| 1741 | hotstartSolution = NULL; |
---|
| 1742 | model->setHotstartSolution(NULL, NULL); |
---|
| 1743 | usefulInfo.hotstartSolution_ = NULL; |
---|
| 1744 | } |
---|
| 1745 | } |
---|
[1271] | 1746 | } |
---|
[1286] | 1747 | /* |
---|
| 1748 | Get a branching decision object. Use the default dynamic decision criteria unless |
---|
| 1749 | the user has loaded a decision method into the model. |
---|
| 1750 | */ |
---|
| 1751 | CbcBranchDecision *decision = model->branchingMethod(); |
---|
| 1752 | if (!decision) |
---|
| 1753 | decision = new CbcBranchDynamicDecision(); |
---|
| 1754 | int xMark = 0; |
---|
| 1755 | // Get arrays to sort |
---|
| 1756 | double * sort = new double[numberObjects]; |
---|
| 1757 | int * whichObject = new int[numberObjects]; |
---|
[1271] | 1758 | #ifdef RANGING |
---|
[1286] | 1759 | int xPen = 0; |
---|
| 1760 | int * objectMark = new int[2*numberObjects+1]; |
---|
[1271] | 1761 | #endif |
---|
[1286] | 1762 | // Arrays with movements |
---|
| 1763 | double * upEstimate = new double[numberObjects]; |
---|
| 1764 | double * downEstimate = new double[numberObjects]; |
---|
| 1765 | double estimatedDegradation = 0.0; |
---|
| 1766 | int numberNodes = model->getNodeCount(); |
---|
| 1767 | int saveLogLevel = model->logLevel(); |
---|
[1393] | 1768 | #ifdef JJF_ZERO |
---|
[1286] | 1769 | if ((numberNodes % 500) == 0) { |
---|
| 1770 | model->setLogLevel(6); |
---|
| 1771 | // Get average up and down costs |
---|
| 1772 | double averageUp = 0.0; |
---|
| 1773 | double averageDown = 0.0; |
---|
| 1774 | int numberUp = 0; |
---|
| 1775 | int numberDown = 0; |
---|
| 1776 | int i; |
---|
| 1777 | for ( i = 0; i < numberObjects; i++) { |
---|
| 1778 | OsiObject * object = model->modifiableObject(i); |
---|
| 1779 | CbcSimpleIntegerDynamicPseudoCost * dynamicObject = |
---|
| 1780 | dynamic_cast <CbcSimpleIntegerDynamicPseudoCost *>(object) ; |
---|
| 1781 | assert(dynamicObject); |
---|
| 1782 | int numberUp2 = 0; |
---|
| 1783 | int numberDown2 = 0; |
---|
| 1784 | double up = 0.0; |
---|
| 1785 | double down = 0.0; |
---|
| 1786 | if (dynamicObject->numberTimesUp()) { |
---|
| 1787 | numberUp++; |
---|
| 1788 | averageUp += dynamicObject->upDynamicPseudoCost(); |
---|
| 1789 | numberUp2 += dynamicObject->numberTimesUp(); |
---|
| 1790 | up = dynamicObject->upDynamicPseudoCost(); |
---|
| 1791 | } |
---|
| 1792 | if (dynamicObject->numberTimesDown()) { |
---|
| 1793 | numberDown++; |
---|
| 1794 | averageDown += dynamicObject->downDynamicPseudoCost(); |
---|
| 1795 | numberDown2 += dynamicObject->numberTimesDown(); |
---|
| 1796 | down = dynamicObject->downDynamicPseudoCost(); |
---|
| 1797 | } |
---|
| 1798 | if (numberUp2 || numberDown2) |
---|
| 1799 | printf("col %d - up %d times cost %g, - down %d times cost %g\n", |
---|
| 1800 | dynamicObject->columnNumber(), numberUp2, up, numberDown2, down); |
---|
| 1801 | } |
---|
| 1802 | if (numberUp) |
---|
| 1803 | averageUp /= static_cast<double> (numberUp); |
---|
| 1804 | else |
---|
| 1805 | averageUp = 1.0; |
---|
| 1806 | if (numberDown) |
---|
| 1807 | averageDown /= static_cast<double> (numberDown); |
---|
| 1808 | else |
---|
| 1809 | averageDown = 1.0; |
---|
| 1810 | printf("total - up %d vars average %g, - down %d vars average %g\n", |
---|
| 1811 | numberUp, averageUp, numberDown, averageDown); |
---|
[640] | 1812 | } |
---|
[1271] | 1813 | #endif |
---|
[1286] | 1814 | int numberBeforeTrust = model->numberBeforeTrust(); |
---|
| 1815 | // May go round twice if strong branching fixes all local candidates |
---|
| 1816 | bool finished = false; |
---|
| 1817 | int numberToFix = 0; |
---|
[311] | 1818 | # ifdef COIN_HAS_CLP |
---|
[1286] | 1819 | OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (solver); |
---|
| 1820 | int saveClpOptions = 0; |
---|
| 1821 | if (osiclp) { |
---|
| 1822 | // for faster hot start |
---|
| 1823 | saveClpOptions = osiclp->specialOptions(); |
---|
| 1824 | osiclp->setSpecialOptions(saveClpOptions | 8192); |
---|
| 1825 | } |
---|
[277] | 1826 | # else |
---|
[1286] | 1827 | OsiSolverInterface *osiclp = NULL ; |
---|
[277] | 1828 | # endif |
---|
[1286] | 1829 | //const CglTreeProbingInfo * probingInfo = NULL; //model->probingInfo(); |
---|
| 1830 | // Old code left in with DEPRECATED_STRATEGY |
---|
| 1831 | assert (model->searchStrategy() == -1 || |
---|
| 1832 | model->searchStrategy() == 1 || |
---|
| 1833 | model->searchStrategy() == 2); |
---|
[1271] | 1834 | #ifdef DEPRECATED_STRATEGY |
---|
[1286] | 1835 | int saveSearchStrategy2 = model->searchStrategy(); |
---|
[931] | 1836 | #endif |
---|
[1286] | 1837 | // Get average up and down costs |
---|
| 1838 | { |
---|
| 1839 | double averageUp = 0.0; |
---|
| 1840 | double averageDown = 0.0; |
---|
| 1841 | int numberUp = 0; |
---|
| 1842 | int numberDown = 0; |
---|
| 1843 | int i; |
---|
| 1844 | for ( i = 0; i < numberObjects; i++) { |
---|
| 1845 | OsiObject * object = model->modifiableObject(i); |
---|
| 1846 | CbcSimpleIntegerDynamicPseudoCost * dynamicObject = |
---|
| 1847 | dynamic_cast <CbcSimpleIntegerDynamicPseudoCost *>(object) ; |
---|
| 1848 | if (dynamicObject) { |
---|
| 1849 | if (dynamicObject->numberTimesUp()) { |
---|
| 1850 | numberUp++; |
---|
| 1851 | averageUp += dynamicObject->upDynamicPseudoCost(); |
---|
| 1852 | } |
---|
| 1853 | if (dynamicObject->numberTimesDown()) { |
---|
| 1854 | numberDown++; |
---|
| 1855 | averageDown += dynamicObject->downDynamicPseudoCost(); |
---|
| 1856 | } |
---|
| 1857 | } |
---|
| 1858 | } |
---|
| 1859 | if (numberUp) |
---|
| 1860 | averageUp /= static_cast<double> (numberUp); |
---|
| 1861 | else |
---|
| 1862 | averageUp = 1.0; |
---|
| 1863 | if (numberDown) |
---|
| 1864 | averageDown /= static_cast<double> (numberDown); |
---|
| 1865 | else |
---|
| 1866 | averageDown = 1.0; |
---|
| 1867 | for ( i = 0; i < numberObjects; i++) { |
---|
| 1868 | OsiObject * object = model->modifiableObject(i); |
---|
| 1869 | CbcSimpleIntegerDynamicPseudoCost * dynamicObject = |
---|
| 1870 | dynamic_cast <CbcSimpleIntegerDynamicPseudoCost *>(object) ; |
---|
| 1871 | if (dynamicObject) { |
---|
| 1872 | if (!dynamicObject->numberTimesUp()) |
---|
| 1873 | dynamicObject->setUpDynamicPseudoCost(averageUp); |
---|
| 1874 | if (!dynamicObject->numberTimesDown()) |
---|
| 1875 | dynamicObject->setDownDynamicPseudoCost(averageDown); |
---|
| 1876 | } |
---|
| 1877 | } |
---|
[259] | 1878 | } |
---|
[1286] | 1879 | /* |
---|
| 1880 | 1 strong |
---|
| 1881 | 2 no strong |
---|
| 1882 | 3 strong just before solution |
---|
| 1883 | 4 no strong just before solution |
---|
| 1884 | 5 strong first time or before solution |
---|
| 1885 | 6 strong first time |
---|
| 1886 | */ |
---|
| 1887 | int useShadow = model->moreSpecialOptions() & 7; |
---|
| 1888 | if (useShadow > 2) { |
---|
| 1889 | if (model->getSolutionCount()) { |
---|
| 1890 | if (numberNodes || useShadow < 5) { |
---|
| 1891 | useShadow = 0; |
---|
| 1892 | // zap pseudo shadow prices |
---|
| 1893 | model->pseudoShadow(-1); |
---|
| 1894 | // and switch off |
---|
| 1895 | model->setMoreSpecialOptions(model->moreSpecialOptions()&(~1023)); |
---|
| 1896 | } else { |
---|
| 1897 | useShadow = 1; |
---|
| 1898 | } |
---|
| 1899 | } else if (useShadow < 5) { |
---|
| 1900 | useShadow -= 2; |
---|
| 1901 | } else { |
---|
| 1902 | useShadow = 1; |
---|
| 1903 | } |
---|
[1271] | 1904 | } |
---|
[1286] | 1905 | if (useShadow) { |
---|
| 1906 | // pseudo shadow prices |
---|
| 1907 | model->pseudoShadow((model->moreSpecialOptions() >> 3)&63); |
---|
| 1908 | } |
---|
| 1909 | #ifdef DEPRECATED_STRATEGY |
---|
| 1910 | { // in for tabbing |
---|
| 1911 | } else if (saveSearchStrategy2 < 1999) { |
---|
| 1912 | // pseudo shadow prices |
---|
| 1913 | model->pseudoShadow(NULL, NULL); |
---|
| 1914 | } else if (saveSearchStrategy2 < 2999) { |
---|
| 1915 | // leave old ones |
---|
| 1916 | } else if (saveSearchStrategy2 < 3999) { |
---|
| 1917 | // pseudo shadow prices at root |
---|
| 1918 | if (!numberNodes) |
---|
| 1919 | model->pseudoShadow(NULL, NULL); |
---|
[931] | 1920 | } else { |
---|
[1286] | 1921 | abort(); |
---|
[1271] | 1922 | } |
---|
[1286] | 1923 | if (saveSearchStrategy2 >= 0) |
---|
| 1924 | saveSearchStrategy2 = saveSearchStrategy2 % 1000; |
---|
| 1925 | if (saveSearchStrategy2 == 999) |
---|
| 1926 | saveSearchStrategy2 = -1; |
---|
| 1927 | int saveSearchStrategy = saveSearchStrategy2 < 99 ? saveSearchStrategy2 : saveSearchStrategy2 - 100; |
---|
[1271] | 1928 | #endif //DEPRECATED_STRATEGY |
---|
[1286] | 1929 | int numberNotTrusted = 0; |
---|
| 1930 | int numberStrongDone = 0; |
---|
| 1931 | int numberUnfinished = 0; |
---|
| 1932 | int numberStrongInfeasible = 0; |
---|
| 1933 | int numberStrongIterations = 0; |
---|
| 1934 | // so we can save lots of stuff |
---|
| 1935 | CbcStrongInfo choice; |
---|
| 1936 | CbcDynamicPseudoCostBranchingObject * choiceObject = NULL; |
---|
| 1937 | if (model->allDynamic()) { |
---|
| 1938 | CbcSimpleIntegerDynamicPseudoCost * object = NULL; |
---|
| 1939 | choiceObject = new CbcDynamicPseudoCostBranchingObject(model, 0, -1, 0.5, object); |
---|
| 1940 | } |
---|
| 1941 | choice.possibleBranch = choiceObject; |
---|
| 1942 | numberPassesLeft = CoinMax(numberPassesLeft, 2); |
---|
| 1943 | while (!finished) { |
---|
| 1944 | numberPassesLeft--; |
---|
| 1945 | finished = true; |
---|
| 1946 | decision->initialize(model); |
---|
| 1947 | // Some objects may compute an estimate of best solution from here |
---|
| 1948 | estimatedDegradation = 0.0; |
---|
| 1949 | numberToFix = 0; |
---|
| 1950 | int numberToDo = 0; |
---|
| 1951 | int iBestNot = -1; |
---|
| 1952 | int iBestGot = -1; |
---|
| 1953 | double best = 0.0; |
---|
| 1954 | numberNotTrusted = 0; |
---|
| 1955 | numberStrongDone = 0; |
---|
| 1956 | numberUnfinished = 0; |
---|
| 1957 | numberStrongInfeasible = 0; |
---|
| 1958 | numberStrongIterations = 0; |
---|
[1271] | 1959 | #ifdef RANGING |
---|
[1286] | 1960 | int * which = objectMark + numberObjects + 1; |
---|
| 1961 | int neededPenalties; |
---|
| 1962 | int optionalPenalties; |
---|
[1271] | 1963 | #endif |
---|
[1286] | 1964 | // We may go round this loop three times (only if we think we have solution) |
---|
| 1965 | for (int iPass = 0; iPass < 3; iPass++) { |
---|
| 1966 | |
---|
| 1967 | // Some objects may compute an estimate of best solution from here |
---|
| 1968 | estimatedDegradation = 0.0; |
---|
| 1969 | numberUnsatisfied_ = 0; |
---|
| 1970 | // initialize sum of "infeasibilities" |
---|
| 1971 | sumInfeasibilities_ = 0.0; |
---|
| 1972 | int bestPriority = COIN_INT_MAX; |
---|
[1393] | 1973 | #ifdef JJF_ZERO |
---|
[1286] | 1974 | int number01 = 0; |
---|
| 1975 | const cliqueEntry * entry = NULL; |
---|
| 1976 | const int * toZero = NULL; |
---|
| 1977 | const int * toOne = NULL; |
---|
| 1978 | const int * backward = NULL; |
---|
| 1979 | int numberUnsatisProbed = 0; |
---|
| 1980 | int numberUnsatisNotProbed = 0; // 0-1 |
---|
| 1981 | if (probingInfo) { |
---|
| 1982 | number01 = probingInfo->numberIntegers(); |
---|
| 1983 | entry = probingInfo->fixEntries(); |
---|
| 1984 | toZero = probingInfo->toZero(); |
---|
| 1985 | toOne = probingInfo->toOne(); |
---|
| 1986 | backward = probingInfo->backward(); |
---|
| 1987 | if (!toZero[number01] || number01 < numberObjects || true) { |
---|
| 1988 | // no info |
---|
| 1989 | probingInfo = NULL; |
---|
| 1990 | } |
---|
| 1991 | } |
---|
[1267] | 1992 | #endif |
---|
[1286] | 1993 | /* |
---|
| 1994 | Scan for branching objects that indicate infeasibility. Choose candidates |
---|
| 1995 | using priority as the first criteria, then integer infeasibility. |
---|
| 1996 | |
---|
| 1997 | The algorithm is to fill the array with a set of good candidates (by |
---|
| 1998 | infeasibility) with priority bestPriority. Finding a candidate with |
---|
| 1999 | priority better (less) than bestPriority flushes the choice array. (This |
---|
| 2000 | serves as initialization when the first candidate is found.) |
---|
| 2001 | |
---|
| 2002 | */ |
---|
| 2003 | numberToDo = 0; |
---|
[1271] | 2004 | #ifdef RANGING |
---|
[1286] | 2005 | neededPenalties = 0; |
---|
| 2006 | optionalPenalties = numberObjects; |
---|
[1271] | 2007 | #endif |
---|
[1286] | 2008 | iBestNot = -1; |
---|
| 2009 | double bestNot = 0.0; |
---|
| 2010 | iBestGot = -1; |
---|
| 2011 | best = 0.0; |
---|
| 2012 | /* Problem type as set by user or found by analysis. This will be extended |
---|
| 2013 | 0 - not known |
---|
| 2014 | 1 - Set partitioning <= |
---|
| 2015 | 2 - Set partitioning == |
---|
| 2016 | 3 - Set covering |
---|
| 2017 | 4 - all +- 1 or all +1 and odd |
---|
| 2018 | */ |
---|
| 2019 | int problemType = model->problemType(); |
---|
| 2020 | bool canDoOneHot = false; |
---|
| 2021 | for (i = 0; i < numberObjects; i++) { |
---|
| 2022 | OsiObject * object = model->modifiableObject(i); |
---|
| 2023 | CbcSimpleIntegerDynamicPseudoCost * dynamicObject = |
---|
| 2024 | dynamic_cast <CbcSimpleIntegerDynamicPseudoCost *>(object) ; |
---|
| 2025 | int preferredWay; |
---|
| 2026 | double infeasibility = object->infeasibility(&usefulInfo, preferredWay); |
---|
| 2027 | int priorityLevel = object->priority(); |
---|
| 2028 | if (hotstartSolution) { |
---|
| 2029 | // we are doing hot start |
---|
| 2030 | const CbcSimpleInteger * thisOne = dynamic_cast <const CbcSimpleInteger *> (object); |
---|
| 2031 | if (thisOne) { |
---|
| 2032 | int iColumn = thisOne->columnNumber(); |
---|
| 2033 | bool canDoThisHot = true; |
---|
| 2034 | double targetValue = hotstartSolution[iColumn]; |
---|
| 2035 | if (saveUpper[iColumn] > saveLower[iColumn]) { |
---|
| 2036 | double value = saveSolution[iColumn]; |
---|
| 2037 | if (hotstartPriorities) |
---|
| 2038 | priorityLevel = hotstartPriorities[iColumn]; |
---|
| 2039 | //double originalLower = thisOne->originalLower(); |
---|
| 2040 | //double originalUpper = thisOne->originalUpper(); |
---|
| 2041 | // switch off if not possible |
---|
| 2042 | if (targetValue >= saveLower[iColumn] && targetValue <= saveUpper[iColumn]) { |
---|
| 2043 | /* priority outranks rest always if negative |
---|
| 2044 | otherwise can be downgraded if at correct level. |
---|
| 2045 | Infeasibility may be increased to choose 1.0 values first. |
---|
| 2046 | choose one near wanted value |
---|
| 2047 | */ |
---|
| 2048 | if (fabs(value - targetValue) > integerTolerance) { |
---|
| 2049 | //if (infeasibility>0.01) |
---|
| 2050 | //infeasibility = fabs(1.0e6-fabs(value-targetValue)); |
---|
| 2051 | //else |
---|
| 2052 | infeasibility = fabs(value - targetValue); |
---|
| 2053 | //if (targetValue==1.0) |
---|
| 2054 | //infeasibility += 1.0; |
---|
| 2055 | if (value > targetValue) { |
---|
| 2056 | preferredWay = -1; |
---|
| 2057 | } else { |
---|
| 2058 | preferredWay = 1; |
---|
| 2059 | } |
---|
| 2060 | priorityLevel = CoinAbs(priorityLevel); |
---|
| 2061 | } else if (priorityLevel < 0) { |
---|
| 2062 | priorityLevel = CoinAbs(priorityLevel); |
---|
| 2063 | if (targetValue == saveLower[iColumn]) { |
---|
| 2064 | infeasibility = integerTolerance + 1.0e-12; |
---|
| 2065 | preferredWay = -1; |
---|
| 2066 | } else if (targetValue == saveUpper[iColumn]) { |
---|
| 2067 | infeasibility = integerTolerance + 1.0e-12; |
---|
| 2068 | preferredWay = 1; |
---|
| 2069 | } else { |
---|
| 2070 | // can't |
---|
| 2071 | priorityLevel += 10000000; |
---|
| 2072 | canDoThisHot = false; |
---|
| 2073 | } |
---|
| 2074 | } else { |
---|
| 2075 | priorityLevel += 10000000; |
---|
| 2076 | canDoThisHot = false; |
---|
| 2077 | } |
---|
| 2078 | } else { |
---|
| 2079 | // switch off if not possible |
---|
| 2080 | canDoThisHot = false; |
---|
| 2081 | } |
---|
| 2082 | if (canDoThisHot) |
---|
| 2083 | canDoOneHot = true; |
---|
| 2084 | } else if (targetValue < saveLower[iColumn] || targetValue > saveUpper[iColumn]) { |
---|
| 2085 | } |
---|
| 2086 | } else { |
---|
| 2087 | priorityLevel += 10000000; |
---|
| 2088 | } |
---|
[1271] | 2089 | } |
---|
[259] | 2090 | #define ZERO_ONE 0 |
---|
| 2091 | #define ZERO_FAKE 1.0e20; |
---|
| 2092 | #if ZERO_ONE==1 |
---|
[1286] | 2093 | // branch on 0-1 first (temp) |
---|
| 2094 | if (fabs(saveSolution[dynamicObject->columnNumber()]) < 1.0) |
---|
| 2095 | priorityLevel--; |
---|
[259] | 2096 | #endif |
---|
| 2097 | #if ZERO_ONE==2 |
---|
[1286] | 2098 | if (fabs(saveSolution[dynamicObject->columnNumber()]) < 1.0) |
---|
| 2099 | infeasibility *= ZERO_FAKE; |
---|
[259] | 2100 | #endif |
---|
[1286] | 2101 | if (infeasibility) { |
---|
| 2102 | int iColumn = numberColumns + i; |
---|
| 2103 | bool gotDown = false; |
---|
| 2104 | int numberThisDown = 0; |
---|
| 2105 | bool gotUp = false; |
---|
| 2106 | int numberThisUp = 0; |
---|
| 2107 | double downGuess = object->downEstimate(); |
---|
| 2108 | double upGuess = object->upEstimate(); |
---|
| 2109 | if (dynamicObject) { |
---|
| 2110 | // Use this object's numberBeforeTrust |
---|
| 2111 | int numberBeforeTrust = dynamicObject->numberBeforeTrust(); |
---|
| 2112 | iColumn = dynamicObject->columnNumber(); |
---|
| 2113 | gotDown = false; |
---|
| 2114 | numberThisDown = dynamicObject->numberTimesDown(); |
---|
| 2115 | if (numberThisDown >= numberBeforeTrust) |
---|
| 2116 | gotDown = true; |
---|
| 2117 | gotUp = false; |
---|
| 2118 | numberThisUp = dynamicObject->numberTimesUp(); |
---|
| 2119 | if (numberThisUp >= numberBeforeTrust) |
---|
| 2120 | gotUp = true; |
---|
| 2121 | if (!depth_ && false) { |
---|
| 2122 | // try closest to 0.5 |
---|
| 2123 | double part = saveSolution[iColumn] - floor(saveSolution[iColumn]); |
---|
| 2124 | infeasibility = fabs(0.5 - part); |
---|
| 2125 | } |
---|
| 2126 | if (problemType > 0 && problemType < 4 && false) { |
---|
| 2127 | // try closest to 0.5 |
---|
| 2128 | double part = saveSolution[iColumn] - floor(saveSolution[iColumn]); |
---|
| 2129 | infeasibility = 0.5 - fabs(0.5 - part); |
---|
| 2130 | } |
---|
[1393] | 2131 | #ifdef JJF_ZERO |
---|
[1286] | 2132 | if (probingInfo) { |
---|
| 2133 | int iSeq = backward[iColumn]; |
---|
| 2134 | assert (iSeq >= 0); |
---|
| 2135 | infeasibility = 1.0 + (toZero[iSeq+1] - toZero[iSeq]) + |
---|
| 2136 | 5.0 * CoinMin(toOne[iSeq] - toZero[iSeq], toZero[iSeq+1] - toOne[iSeq]); |
---|
| 2137 | if (toZero[iSeq+1] > toZero[iSeq]) { |
---|
| 2138 | numberUnsatisProbed++; |
---|
| 2139 | } else { |
---|
| 2140 | numberUnsatisNotProbed++; |
---|
| 2141 | } |
---|
| 2142 | } |
---|
[1267] | 2143 | #endif |
---|
[1286] | 2144 | } else { |
---|
| 2145 | // see if SOS |
---|
| 2146 | CbcSOS * sosObject = |
---|
| 2147 | dynamic_cast <CbcSOS *>(object) ; |
---|
| 2148 | if (sosObject) { |
---|
| 2149 | gotDown = false; |
---|
| 2150 | numberThisDown = sosObject->numberTimesDown(); |
---|
| 2151 | if (numberThisDown >= numberBeforeTrust) |
---|
| 2152 | gotDown = true; |
---|
| 2153 | gotUp = false; |
---|
| 2154 | numberThisUp = sosObject->numberTimesUp(); |
---|
| 2155 | if (numberThisUp >= numberBeforeTrust) |
---|
| 2156 | gotUp = true; |
---|
| 2157 | } else { |
---|
| 2158 | gotDown = true; |
---|
| 2159 | numberThisDown = 999999; |
---|
| 2160 | downGuess = 1.0e20; |
---|
| 2161 | gotUp = true; |
---|
| 2162 | numberThisUp = 999999; |
---|
| 2163 | upGuess = 1.0e20; |
---|
| 2164 | numberPassesLeft = 0; |
---|
| 2165 | } |
---|
| 2166 | } |
---|
| 2167 | // Increase estimated degradation to solution |
---|
| 2168 | estimatedDegradation += CoinMin(downGuess, upGuess); |
---|
| 2169 | downEstimate[i] = downGuess; |
---|
| 2170 | upEstimate[i] = upGuess; |
---|
| 2171 | numberUnsatisfied_++; |
---|
| 2172 | sumInfeasibilities_ += infeasibility; |
---|
| 2173 | // Better priority? Flush choices. |
---|
| 2174 | if (priorityLevel < bestPriority) { |
---|
| 2175 | numberToDo = 0; |
---|
| 2176 | bestPriority = priorityLevel; |
---|
| 2177 | iBestGot = -1; |
---|
| 2178 | best = 0.0; |
---|
| 2179 | numberNotTrusted = 0; |
---|
[1271] | 2180 | #ifdef RANGING |
---|
[1286] | 2181 | neededPenalties = 0; |
---|
| 2182 | optionalPenalties = numberObjects; |
---|
[1271] | 2183 | #endif |
---|
[1286] | 2184 | } else if (priorityLevel > bestPriority) { |
---|
| 2185 | continue; |
---|
| 2186 | } |
---|
| 2187 | if (!gotUp || !gotDown) |
---|
| 2188 | numberNotTrusted++; |
---|
| 2189 | // Check for suitability based on infeasibility. |
---|
| 2190 | if ((gotDown && gotUp) && numberStrong > 0) { |
---|
| 2191 | sort[numberToDo] = -infeasibility; |
---|
| 2192 | if (infeasibility > best) { |
---|
| 2193 | best = infeasibility; |
---|
| 2194 | iBestGot = numberToDo; |
---|
| 2195 | } |
---|
[1271] | 2196 | #ifdef RANGING |
---|
[1286] | 2197 | if (dynamicObject) { |
---|
| 2198 | objectMark[--optionalPenalties] = numberToDo; |
---|
| 2199 | which[optionalPenalties] = iColumn; |
---|
| 2200 | } |
---|
[1271] | 2201 | #endif |
---|
[1286] | 2202 | } else { |
---|
[1271] | 2203 | #ifdef RANGING |
---|
[1286] | 2204 | if (dynamicObject) { |
---|
| 2205 | objectMark[neededPenalties] = numberToDo; |
---|
| 2206 | which[neededPenalties++] = iColumn; |
---|
| 2207 | } |
---|
[1271] | 2208 | #endif |
---|
[1286] | 2209 | sort[numberToDo] = -10.0 * infeasibility; |
---|
| 2210 | if (!(numberThisUp + numberThisDown)) |
---|
| 2211 | sort[numberToDo] *= 100.0; // make even more likely |
---|
| 2212 | if (iColumn < numberColumns) { |
---|
| 2213 | double part = saveSolution[iColumn] - floor(saveSolution[iColumn]); |
---|
| 2214 | if (1.0 - fabs(part - 0.5) > bestNot) { |
---|
| 2215 | iBestNot = numberToDo; |
---|
| 2216 | bestNot = 1.0 - fabs(part - 0.5); |
---|
| 2217 | } |
---|
| 2218 | } else { |
---|
| 2219 | // SOS |
---|
| 2220 | if (-sort[numberToDo] > bestNot) { |
---|
| 2221 | iBestNot = numberToDo; |
---|
| 2222 | bestNot = -sort[numberToDo]; |
---|
| 2223 | } |
---|
| 2224 | } |
---|
| 2225 | } |
---|
| 2226 | if (model->messageHandler()->logLevel() > 3) { |
---|
| 2227 | printf("%d (%d) down %d %g up %d %g - infeas %g - sort %g solution %g\n", |
---|
| 2228 | i, iColumn, numberThisDown, object->downEstimate(), numberThisUp, object->upEstimate(), |
---|
| 2229 | infeasibility, sort[numberToDo], saveSolution[iColumn]); |
---|
| 2230 | } |
---|
| 2231 | whichObject[numberToDo++] = i; |
---|
| 2232 | } else { |
---|
| 2233 | // for debug |
---|
| 2234 | downEstimate[i] = -1.0; |
---|
| 2235 | upEstimate[i] = -1.0; |
---|
| 2236 | } |
---|
| 2237 | } |
---|
| 2238 | if (numberUnsatisfied_) { |
---|
| 2239 | //if (probingInfo&&false) |
---|
| 2240 | //printf("nunsat %d, %d probed, %d other 0-1\n",numberUnsatisfied_, |
---|
| 2241 | // numberUnsatisProbed,numberUnsatisNotProbed); |
---|
| 2242 | // some infeasibilities - go to next steps |
---|
| 2243 | if (!canDoOneHot && hotstartSolution) { |
---|
| 2244 | // switch off as not possible |
---|
| 2245 | hotstartSolution = NULL; |
---|
| 2246 | model->setHotstartSolution(NULL, NULL); |
---|
| 2247 | usefulInfo.hotstartSolution_ = NULL; |
---|
| 2248 | } |
---|
| 2249 | break; |
---|
| 2250 | } else if (!iPass) { |
---|
| 2251 | // may just need resolve |
---|
| 2252 | model->resolve(NULL, 11, saveSolution, saveLower, saveUpper); |
---|
| 2253 | //double newObjValue = solver->getObjSense()*solver->getObjValue(); |
---|
| 2254 | //objectiveValue_ = CoinMax(objectiveValue_,newObjValue); |
---|
| 2255 | if (!solver->isProvenOptimal()) { |
---|
| 2256 | // infeasible |
---|
| 2257 | anyAction = -2; |
---|
| 2258 | break; |
---|
| 2259 | } |
---|
[1420] | 2260 | // Double check looks OK - just look at rows with all integers |
---|
| 2261 | if (model->allDynamic()) { |
---|
| 2262 | double * solution = CoinCopyOfArray(saveSolution, numberColumns); |
---|
| 2263 | for (int i = 0; i < numberColumns; i++) { |
---|
| 2264 | if (model->isInteger(i)) |
---|
| 2265 | solution[i] = floor(solution[i] + 0.5); |
---|
| 2266 | } |
---|
| 2267 | int numberRows = solver->getNumRows(); |
---|
| 2268 | double * rowActivity = new double [numberRows]; |
---|
| 2269 | CoinZeroN(rowActivity, numberRows); |
---|
| 2270 | solver->getMatrixByCol()->times(solution, rowActivity); |
---|
| 2271 | //const double * element = model->solver()->getMatrixByCol()->getElements(); |
---|
| 2272 | const int * row = model->solver()->getMatrixByCol()->getIndices(); |
---|
| 2273 | const CoinBigIndex * columnStart = model->solver()->getMatrixByCol()->getVectorStarts(); |
---|
| 2274 | const int * columnLength = model->solver()->getMatrixByCol()->getVectorLengths(); |
---|
| 2275 | int nFree = 0; |
---|
| 2276 | int nFreeNon = 0; |
---|
| 2277 | int nFixedNon = 0; |
---|
| 2278 | double mostAway = 0.0; |
---|
| 2279 | int whichAway = -1; |
---|
| 2280 | const double * columnLower = solver->getColLower(); |
---|
| 2281 | const double * columnUpper = solver->getColUpper(); |
---|
| 2282 | for (int i = 0; i < numberColumns; i++) { |
---|
| 2283 | if (!model->isInteger(i)) { |
---|
| 2284 | // mark rows as flexible |
---|
| 2285 | CoinBigIndex start = columnStart[i]; |
---|
| 2286 | CoinBigIndex end = start + columnLength[i]; |
---|
| 2287 | for (CoinBigIndex j = start; j < end; j++) { |
---|
| 2288 | int iRow = row[j]; |
---|
| 2289 | rowActivity[iRow] = COIN_DBL_MAX; |
---|
| 2290 | } |
---|
| 2291 | } else if (columnLower[i] < columnUpper[i]) { |
---|
| 2292 | if (solution[i] != saveSolution[i]) { |
---|
| 2293 | nFreeNon++; |
---|
| 2294 | if (fabs(solution[i] - saveSolution[i]) > mostAway) { |
---|
| 2295 | mostAway = fabs(solution[i] - saveSolution[i]); |
---|
| 2296 | whichAway = i; |
---|
| 2297 | } |
---|
| 2298 | } else { |
---|
| 2299 | nFree++; |
---|
| 2300 | } |
---|
| 2301 | } else if (solution[i] != saveSolution[i]) { |
---|
| 2302 | nFixedNon++; |
---|
| 2303 | } |
---|
| 2304 | } |
---|
| 2305 | const double * lower = solver->getRowLower(); |
---|
| 2306 | const double * upper = solver->getRowUpper(); |
---|
| 2307 | bool satisfied = true; |
---|
| 2308 | for (int i = 0; i < numberRows; i++) { |
---|
| 2309 | double value = rowActivity[i]; |
---|
| 2310 | if (value != COIN_DBL_MAX) { |
---|
| 2311 | if (value > upper[i] + 1.0e-5 || value < lower[i] - 1.0e-5) { |
---|
| 2312 | satisfied = false; |
---|
| 2313 | } |
---|
| 2314 | } |
---|
| 2315 | } |
---|
| 2316 | delete [] rowActivity; |
---|
| 2317 | delete [] solution; |
---|
| 2318 | if (!satisfied) { |
---|
| 2319 | #ifdef CLP_INVESTIGATE |
---|
| 2320 | printf("%d free ok %d free off target %d fixed off target\n", |
---|
| 2321 | nFree, nFreeNon, nFixedNon); |
---|
| 2322 | #endif |
---|
| 2323 | if (nFreeNon) { |
---|
| 2324 | // try branching on these |
---|
| 2325 | delete branch_; |
---|
| 2326 | for (int i = 0; i < numberObjects; i++) { |
---|
| 2327 | OsiObject * object = model->modifiableObject(i); |
---|
| 2328 | CbcSimpleIntegerDynamicPseudoCost * obj = |
---|
| 2329 | dynamic_cast <CbcSimpleIntegerDynamicPseudoCost *>(object) ; |
---|
| 2330 | assert (obj); |
---|
| 2331 | int iColumn = obj->columnNumber(); |
---|
| 2332 | if (iColumn == whichAway) { |
---|
| 2333 | int preferredWay = (saveSolution[iColumn] > solution[iColumn]) |
---|
| 2334 | ? -1 : +1; |
---|
| 2335 | usefulInfo.integerTolerance_ = 0.0; |
---|
| 2336 | branch_ = obj->createCbcBranch(solver, &usefulInfo, preferredWay); |
---|
| 2337 | break; |
---|
| 2338 | } |
---|
| 2339 | } |
---|
| 2340 | anyAction = 0; |
---|
| 2341 | break; |
---|
| 2342 | } |
---|
| 2343 | } |
---|
| 2344 | } |
---|
[1286] | 2345 | } else if (iPass == 1) { |
---|
| 2346 | // looks like a solution - get paranoid |
---|
| 2347 | bool roundAgain = false; |
---|
| 2348 | // get basis |
---|
| 2349 | CoinWarmStartBasis * ws = dynamic_cast<CoinWarmStartBasis*>(solver->getWarmStart()); |
---|
| 2350 | if (!ws) |
---|
| 2351 | break; |
---|
| 2352 | double tolerance; |
---|
| 2353 | solver->getDblParam(OsiPrimalTolerance, tolerance); |
---|
| 2354 | for (i = 0; i < numberColumns; i++) { |
---|
| 2355 | double value = saveSolution[i]; |
---|
| 2356 | if (value < lower[i] - tolerance) { |
---|
| 2357 | saveSolution[i] = lower[i]; |
---|
| 2358 | roundAgain = true; |
---|
| 2359 | ws->setStructStatus(i, CoinWarmStartBasis::atLowerBound); |
---|
| 2360 | } else if (value > upper[i] + tolerance) { |
---|
| 2361 | saveSolution[i] = upper[i]; |
---|
| 2362 | roundAgain = true; |
---|
| 2363 | ws->setStructStatus(i, CoinWarmStartBasis::atUpperBound); |
---|
| 2364 | } |
---|
| 2365 | } |
---|
| 2366 | if (roundAgain) { |
---|
| 2367 | // restore basis |
---|
| 2368 | solver->setWarmStart(ws); |
---|
| 2369 | solver->setColSolution(saveSolution); |
---|
| 2370 | delete ws; |
---|
| 2371 | bool takeHint; |
---|
| 2372 | OsiHintStrength strength; |
---|
| 2373 | solver->getHintParam(OsiDoDualInResolve, takeHint, strength); |
---|
| 2374 | solver->setHintParam(OsiDoDualInResolve, false, OsiHintDo) ; |
---|
| 2375 | model->resolve(NULL, 11, saveSolution, saveLower, saveUpper); |
---|
| 2376 | //double newObjValue = solver->getObjSense()*solver->getObjValue(); |
---|
| 2377 | //objectiveValue_ = CoinMax(objectiveValue_,newObjValue); |
---|
| 2378 | solver->setHintParam(OsiDoDualInResolve, takeHint, strength) ; |
---|
| 2379 | if (!solver->isProvenOptimal()) { |
---|
| 2380 | // infeasible |
---|
| 2381 | anyAction = -2; |
---|
| 2382 | break; |
---|
| 2383 | } |
---|
| 2384 | } else { |
---|
| 2385 | delete ws; |
---|
| 2386 | break; |
---|
| 2387 | } |
---|
| 2388 | } |
---|
[135] | 2389 | } |
---|
[1286] | 2390 | if (anyAction == -2) { |
---|
| 2391 | break; |
---|
[222] | 2392 | } |
---|
[1286] | 2393 | // skip if solution |
---|
| 2394 | if (!numberUnsatisfied_) |
---|
| 2395 | break; |
---|
| 2396 | int skipAll = (numberNotTrusted == 0 || numberToDo == 1) ? 1 : 0; |
---|
| 2397 | bool doneHotStart = false; |
---|
| 2398 | //DEPRECATED_STRATEGYint searchStrategy = saveSearchStrategy>=0 ? (saveSearchStrategy%10) : -1; |
---|
| 2399 | int searchStrategy = model->searchStrategy(); |
---|
| 2400 | // But adjust depending on ratio of iterations |
---|
| 2401 | if (searchStrategy > 0) { |
---|
| 2402 | if (numberBeforeTrust >= 5 && numberBeforeTrust <= 10) { |
---|
| 2403 | if (searchStrategy != 2) { |
---|
| 2404 | assert (searchStrategy == 1); |
---|
| 2405 | if (depth_ > 5) { |
---|
| 2406 | int numberIterations = model->getIterationCount(); |
---|
| 2407 | int numberStrongIterations = model->numberStrongIterations(); |
---|
| 2408 | if (numberStrongIterations > numberIterations + 10000) { |
---|
| 2409 | searchStrategy = 2; |
---|
| 2410 | skipAll = 1; |
---|
| 2411 | } else if (numberStrongIterations*4 + 1000 < numberIterations) { |
---|
| 2412 | searchStrategy = 3; |
---|
| 2413 | skipAll = 0; |
---|
| 2414 | } |
---|
| 2415 | } else { |
---|
| 2416 | searchStrategy = 3; |
---|
| 2417 | skipAll = 0; |
---|
| 2418 | } |
---|
| 2419 | } |
---|
| 2420 | } |
---|
[135] | 2421 | } |
---|
[1286] | 2422 | // worth trying if too many times |
---|
| 2423 | // Save basis |
---|
| 2424 | CoinWarmStart * ws = NULL; |
---|
| 2425 | // save limit |
---|
| 2426 | int saveLimit = 0; |
---|
| 2427 | solver->getIntParam(OsiMaxNumIterationHotStart, saveLimit); |
---|
| 2428 | if (!numberPassesLeft) |
---|
| 2429 | skipAll = 1; |
---|
| 2430 | if (!skipAll) { |
---|
| 2431 | ws = solver->getWarmStart(); |
---|
| 2432 | int limit = 100; |
---|
| 2433 | if (!saveStateOfSearch && saveLimit < limit && saveLimit == 100) |
---|
| 2434 | solver->setIntParam(OsiMaxNumIterationHotStart, limit); |
---|
| 2435 | } |
---|
| 2436 | // Say which one will be best |
---|
| 2437 | int whichChoice = 0; |
---|
| 2438 | int bestChoice; |
---|
| 2439 | if (iBestGot >= 0) |
---|
| 2440 | bestChoice = iBestGot; |
---|
| 2441 | else |
---|
| 2442 | bestChoice = iBestNot; |
---|
| 2443 | assert (bestChoice >= 0); |
---|
| 2444 | // If we have hit max time don't do strong branching |
---|
| 2445 | bool hitMaxTime = ( CoinCpuTime() - model->getDblParam(CbcModel::CbcStartSeconds) > |
---|
| 2446 | model->getDblParam(CbcModel::CbcMaximumSeconds)); |
---|
| 2447 | // also give up if we are looping round too much |
---|
| 2448 | if (hitMaxTime || numberPassesLeft <= 0 || useShadow == 2) { |
---|
| 2449 | int iObject = whichObject[bestChoice]; |
---|
| 2450 | OsiObject * object = model->modifiableObject(iObject); |
---|
| 2451 | int preferredWay; |
---|
| 2452 | object->infeasibility(&usefulInfo, preferredWay); |
---|
| 2453 | CbcObject * obj = |
---|
| 2454 | dynamic_cast <CbcObject *>(object) ; |
---|
| 2455 | assert (obj); |
---|
| 2456 | branch_ = obj->createCbcBranch(solver, &usefulInfo, preferredWay); |
---|
| 2457 | { |
---|
| 2458 | CbcBranchingObject * branchObj = |
---|
| 2459 | dynamic_cast <CbcBranchingObject *>(branch_) ; |
---|
| 2460 | assert (branchObj); |
---|
| 2461 | branchObj->way(preferredWay); |
---|
| 2462 | } |
---|
| 2463 | delete ws; |
---|
| 2464 | ws = NULL; |
---|
[135] | 2465 | break; |
---|
| 2466 | } else { |
---|
[1286] | 2467 | // say do fast |
---|
| 2468 | int easy = 1; |
---|
| 2469 | if (!skipAll) |
---|
| 2470 | solver->setHintParam(OsiDoInBranchAndCut, true, OsiHintDo, &easy) ; |
---|
| 2471 | int iDo; |
---|
[140] | 2472 | #ifdef RANGING |
---|
[1286] | 2473 | bool useRanging = model->allDynamic() && !skipAll; |
---|
| 2474 | if (useRanging) { |
---|
| 2475 | double currentObjective = solver->getObjValue() * solver->getObjSense(); |
---|
| 2476 | double gap = cutoff - currentObjective; |
---|
| 2477 | // relax a bit |
---|
| 2478 | gap *= 1.0000001; |
---|
| 2479 | gap = CoinMax(1.0e-5, gap); |
---|
| 2480 | // off penalties if too much |
---|
| 2481 | double needed = neededPenalties; |
---|
| 2482 | needed *= numberRows; |
---|
| 2483 | if (numberNodes) { |
---|
| 2484 | if (needed > 1.0e6) { |
---|
| 2485 | neededPenalties = 0; |
---|
| 2486 | } else if (gap < 1.0e5) { |
---|
| 2487 | // maybe allow some not needed |
---|
| 2488 | int extra = static_cast<int> ((1.0e6 - needed) / numberRows); |
---|
| 2489 | int nStored = numberObjects - optionalPenalties; |
---|
| 2490 | extra = CoinMin(extra, nStored); |
---|
| 2491 | for (int i = 0; i < extra; i++) { |
---|
| 2492 | objectMark[neededPenalties] = objectMark[optionalPenalties+i]; |
---|
| 2493 | which[neededPenalties++] = which[optionalPenalties+i];; |
---|
| 2494 | } |
---|
| 2495 | } |
---|
| 2496 | } |
---|
| 2497 | if (osiclp && neededPenalties) { |
---|
| 2498 | assert (!doneHotStart); |
---|
| 2499 | xPen += neededPenalties; |
---|
| 2500 | which--; |
---|
| 2501 | which[0] = neededPenalties; |
---|
| 2502 | osiclp->passInRanges(which); |
---|
| 2503 | // Mark hot start and get ranges |
---|
| 2504 | if (kPass) { |
---|
| 2505 | // until can work out why solution can go funny |
---|
| 2506 | int save = osiclp->specialOptions(); |
---|
| 2507 | osiclp->setSpecialOptions(save | 256); |
---|
| 2508 | solver->markHotStart(); |
---|
| 2509 | osiclp->setSpecialOptions(save); |
---|
| 2510 | } else { |
---|
| 2511 | solver->markHotStart(); |
---|
| 2512 | } |
---|
| 2513 | doneHotStart = true; |
---|
| 2514 | xMark++; |
---|
| 2515 | kPass++; |
---|
| 2516 | osiclp->passInRanges(NULL); |
---|
| 2517 | const double * downCost = osiclp->upRange(); |
---|
| 2518 | const double * upCost = osiclp->downRange(); |
---|
| 2519 | bool problemFeasible = true; |
---|
| 2520 | int numberFixed = 0; |
---|
| 2521 | for (int i = 0; i < neededPenalties; i++) { |
---|
| 2522 | int j = objectMark[i]; |
---|
| 2523 | int iObject = whichObject[j]; |
---|
| 2524 | OsiObject * object = model->modifiableObject(iObject); |
---|
| 2525 | CbcSimpleIntegerDynamicPseudoCost * dynamicObject = |
---|
| 2526 | dynamic_cast <CbcSimpleIntegerDynamicPseudoCost *>(object) ; |
---|
| 2527 | // Use this object's numberBeforeTrust |
---|
| 2528 | int numberBeforeTrust = dynamicObject->numberBeforeTrust(); |
---|
| 2529 | int iSequence = dynamicObject->columnNumber(); |
---|
| 2530 | double value = saveSolution[iSequence]; |
---|
| 2531 | value -= floor(value); |
---|
| 2532 | double upPenalty = CoinMin(upCost[i], 1.0e110) * (1.0 - value); |
---|
| 2533 | double downPenalty = CoinMin(downCost[i], 1.0e110) * value; |
---|
| 2534 | int numberThisDown = dynamicObject->numberTimesDown(); |
---|
| 2535 | int numberThisUp = dynamicObject->numberTimesUp(); |
---|
| 2536 | if (!numberBeforeTrust) { |
---|
| 2537 | // override |
---|
| 2538 | downEstimate[iObject] = downPenalty; |
---|
| 2539 | upEstimate[iObject] = upPenalty; |
---|
| 2540 | double min1 = CoinMin(downEstimate[iObject], |
---|
| 2541 | upEstimate[iObject]); |
---|
| 2542 | double max1 = CoinMax(downEstimate[iObject], |
---|
| 2543 | upEstimate[iObject]); |
---|
| 2544 | min1 = 0.8 * min1 + 0.2 * max1; |
---|
| 2545 | sort[j] = - min1; |
---|
| 2546 | } else if (numberThisDown < numberBeforeTrust || |
---|
| 2547 | numberThisUp < numberBeforeTrust) { |
---|
| 2548 | double invTrust = 1.0 / static_cast<double> (numberBeforeTrust); |
---|
| 2549 | if (numberThisDown < numberBeforeTrust) { |
---|
| 2550 | double fraction = numberThisDown * invTrust; |
---|
| 2551 | downEstimate[iObject] = fraction * downEstimate[iObject] + (1.0 - fraction) * downPenalty; |
---|
| 2552 | } |
---|
| 2553 | if (numberThisUp < numberBeforeTrust) { |
---|
| 2554 | double fraction = numberThisUp * invTrust; |
---|
| 2555 | upEstimate[iObject] = fraction * upEstimate[iObject] + (1.0 - fraction) * upPenalty; |
---|
| 2556 | } |
---|
| 2557 | double min1 = CoinMin(downEstimate[iObject], |
---|
| 2558 | upEstimate[iObject]); |
---|
| 2559 | double max1 = CoinMax(downEstimate[iObject], |
---|
| 2560 | upEstimate[iObject]); |
---|
| 2561 | min1 = 0.8 * min1 + 0.2 * max1; |
---|
| 2562 | min1 *= 10.0; |
---|
| 2563 | if (!(numberThisDown + numberThisUp)) |
---|
| 2564 | min1 *= 100.0; |
---|
| 2565 | sort[j] = - min1; |
---|
| 2566 | } |
---|
| 2567 | if (CoinMax(downPenalty, upPenalty) > gap) { |
---|
| 2568 | printf("gap %g object %d has down range %g, up %g\n", |
---|
| 2569 | gap, i, downPenalty, upPenalty); |
---|
| 2570 | //sort[j] -= 1.0e50; // make more likely to be chosen |
---|
| 2571 | int number; |
---|
| 2572 | if (downPenalty > gap) { |
---|
| 2573 | number = dynamicObject->numberTimesDown(); |
---|
| 2574 | if (upPenalty > gap) |
---|
| 2575 | problemFeasible = false; |
---|
| 2576 | CbcBranchingObject * branch = dynamicObject->createCbcBranch(solver, &usefulInfo, 1); |
---|
| 2577 | //branch->fix(solver,saveLower,saveUpper,1); |
---|
| 2578 | delete branch; |
---|
| 2579 | } else { |
---|
| 2580 | number = dynamicObject->numberTimesUp(); |
---|
| 2581 | CbcBranchingObject * branch = dynamicObject->createCbcBranch(solver, &usefulInfo, 1); |
---|
| 2582 | //branch->fix(solver,saveLower,saveUpper,-1); |
---|
| 2583 | delete branch; |
---|
| 2584 | } |
---|
| 2585 | if (number >= numberBeforeTrust) |
---|
| 2586 | dynamicObject->setNumberBeforeTrust(number + 1); |
---|
| 2587 | numberFixed++; |
---|
| 2588 | } |
---|
| 2589 | if (!numberNodes) |
---|
| 2590 | printf("%d pen down ps %g -> %g up ps %g -> %g\n", |
---|
| 2591 | iObject, downPenalty, downPenalty, upPenalty, upPenalty); |
---|
| 2592 | } |
---|
| 2593 | if (numberFixed && problemFeasible) { |
---|
| 2594 | assert(doneHotStart); |
---|
| 2595 | solver->unmarkHotStart(); |
---|
| 2596 | model->resolve(NULL, 11, saveSolution, saveLower, saveUpper); |
---|
| 2597 | //double newObjValue = solver->getObjSense()*solver->getObjValue(); |
---|
| 2598 | //objectiveValue_ = CoinMax(objectiveValue_,newObjValue); |
---|
| 2599 | solver->markHotStart(); |
---|
| 2600 | problemFeasible = solver->isProvenOptimal(); |
---|
| 2601 | } |
---|
| 2602 | if (!problemFeasible) { |
---|
| 2603 | fprintf(stdout, "both ways infeas on ranging - code needed\n"); |
---|
| 2604 | anyAction = -2; |
---|
| 2605 | if (!choiceObject) { |
---|
| 2606 | delete choice.possibleBranch; |
---|
| 2607 | choice.possibleBranch = NULL; |
---|
| 2608 | } |
---|
| 2609 | //printf("Both infeasible for choice %d sequence %d\n",i, |
---|
| 2610 | // model->object(choice.objectNumber)->columnNumber()); |
---|
| 2611 | // Delete the snapshot |
---|
| 2612 | solver->unmarkHotStart(); |
---|
| 2613 | // back to normal |
---|
| 2614 | solver->setHintParam(OsiDoInBranchAndCut, true, OsiHintDo, NULL) ; |
---|
| 2615 | // restore basis |
---|
| 2616 | solver->setWarmStart(ws); |
---|
| 2617 | doneHotStart = false; |
---|
| 2618 | delete ws; |
---|
| 2619 | ws = NULL; |
---|
| 2620 | break; |
---|
| 2621 | } |
---|
| 2622 | } |
---|
| 2623 | } |
---|
[1271] | 2624 | #endif /* RANGING */ |
---|
[1286] | 2625 | { |
---|
| 2626 | int numberIterations = model->getIterationCount(); |
---|
| 2627 | //numberIterations += (model->numberExtraIterations()>>2); |
---|
| 2628 | const int * strongInfo = model->strongInfo(); |
---|
| 2629 | //int numberDone = strongInfo[0]-strongInfo[3]; |
---|
| 2630 | int numberFixed = strongInfo[1] - strongInfo[4]; |
---|
| 2631 | int numberInfeasible = strongInfo[2] - strongInfo[5]; |
---|
| 2632 | assert (!strongInfo[3]); |
---|
| 2633 | assert (!strongInfo[4]); |
---|
| 2634 | assert (!strongInfo[5]); |
---|
| 2635 | int numberStrongIterations = model->numberStrongIterations(); |
---|
| 2636 | int numberRows = solver->getNumRows(); |
---|
| 2637 | if (numberStrongIterations > numberIterations + CoinMin(100, 10*numberRows) && depth_ >= 4 && numberNodes > 100) { |
---|
| 2638 | if (20*numberInfeasible + 4*numberFixed < numberNodes) { |
---|
| 2639 | // Say never do |
---|
| 2640 | skipAll = -1; |
---|
| 2641 | } |
---|
| 2642 | } |
---|
| 2643 | } |
---|
| 2644 | // make sure best will be first |
---|
| 2645 | if (iBestGot >= 0) |
---|
| 2646 | sort[iBestGot] = -COIN_DBL_MAX; |
---|
| 2647 | // Actions 0 - exit for repeat, 1 resolve and try old choice,2 exit for continue |
---|
| 2648 | if (anyAction) |
---|
| 2649 | numberToDo = 0; // skip as we will be trying again |
---|
| 2650 | // Sort |
---|
| 2651 | CoinSort_2(sort, sort + numberToDo, whichObject); |
---|
| 2652 | // Change in objective opposite infeasible |
---|
| 2653 | double worstFeasible = 0.0; |
---|
| 2654 | // Just first if strong off |
---|
| 2655 | if (!numberStrong) |
---|
| 2656 | numberToDo = CoinMin(numberToDo, 1); |
---|
| 2657 | if (searchStrategy == 2) |
---|
| 2658 | numberToDo = CoinMin(numberToDo, 20); |
---|
| 2659 | iDo = 0; |
---|
| 2660 | int saveLimit2; |
---|
| 2661 | solver->getIntParam(OsiMaxNumIterationHotStart, saveLimit2); |
---|
| 2662 | bool doQuickly = false; // numberToDo>2*numberStrong; |
---|
| 2663 | if (searchStrategy == 2) |
---|
| 2664 | doQuickly = true; |
---|
| 2665 | int numberTest = numberNotTrusted > 0 ? numberStrong : (numberStrong + 1) / 2; |
---|
| 2666 | if (searchStrategy == 3) { |
---|
| 2667 | // Previously decided we need strong |
---|
| 2668 | doQuickly = false; |
---|
| 2669 | numberTest = numberStrong; |
---|
| 2670 | } |
---|
| 2671 | // Try nearly always off |
---|
| 2672 | if (skipAll >= 0) { |
---|
| 2673 | if (searchStrategy < 2) { |
---|
| 2674 | //if ((numberNodes%20)!=0) { |
---|
| 2675 | if ((model->specialOptions()&8) == 0) { |
---|
| 2676 | numberTest = 0; |
---|
| 2677 | doQuickly = true; |
---|
| 2678 | } |
---|
| 2679 | //} else { |
---|
| 2680 | //doQuickly=false; |
---|
| 2681 | //numberTest=2*numberStrong; |
---|
| 2682 | //skipAll=0; |
---|
| 2683 | //} |
---|
| 2684 | } |
---|
| 2685 | } else { |
---|
| 2686 | // Just take first |
---|
| 2687 | doQuickly = true; |
---|
| 2688 | numberTest = 1; |
---|
| 2689 | } |
---|
| 2690 | int testDepth = (skipAll >= 0) ? 8 : 4; |
---|
| 2691 | if (depth_ < testDepth && numberStrong) { |
---|
| 2692 | if (searchStrategy != 2) { |
---|
| 2693 | doQuickly = false; |
---|
| 2694 | int numberRows = solver->getNumRows(); |
---|
| 2695 | // whether to do this or not is important - think |
---|
| 2696 | if (numberRows < 300 || numberRows + numberColumns < 2500) { |
---|
| 2697 | if (depth_ < 7) |
---|
| 2698 | numberStrong = CoinMin(3 * numberStrong, numberToDo); |
---|
| 2699 | if (!depth_) |
---|
| 2700 | numberStrong = CoinMin(6 * numberStrong, numberToDo); |
---|
| 2701 | } |
---|
| 2702 | numberTest = numberStrong; |
---|
| 2703 | skipAll = 0; |
---|
| 2704 | } |
---|
| 2705 | } |
---|
| 2706 | // Do at least 5 strong |
---|
| 2707 | if (numberColumns < 1000 && (depth_ < 15 || numberNodes < 1000000)) |
---|
| 2708 | numberTest = CoinMax(numberTest, 5); |
---|
| 2709 | if ((model->specialOptions()&8) == 0) { |
---|
| 2710 | if (skipAll) { |
---|
| 2711 | numberTest = 0; |
---|
| 2712 | doQuickly = true; |
---|
| 2713 | } |
---|
| 2714 | } else { |
---|
| 2715 | // do 5 as strong is fixing |
---|
| 2716 | numberTest = CoinMax(numberTest, 5); |
---|
| 2717 | } |
---|
| 2718 | // see if switched off |
---|
| 2719 | if (skipAll < 0) { |
---|
| 2720 | numberTest = 0; |
---|
| 2721 | doQuickly = true; |
---|
| 2722 | } |
---|
| 2723 | int realMaxHotIterations = 999999; |
---|
| 2724 | if (skipAll < 0) |
---|
| 2725 | numberToDo = 1; |
---|
[1132] | 2726 | #ifdef DO_ALL_AT_ROOT |
---|
[1286] | 2727 | if (!numberNodes) { |
---|
| 2728 | printf("DOX %d test %d unsat %d - nobj %d\n", |
---|
| 2729 | numberToDo, numberTest, numberUnsatisfied_, |
---|
| 2730 | numberObjects); |
---|
| 2731 | numberTest = numberToDo; |
---|
| 2732 | } |
---|
[1132] | 2733 | #endif |
---|
[1286] | 2734 | for ( iDo = 0; iDo < numberToDo; iDo++) { |
---|
| 2735 | int iObject = whichObject[iDo]; |
---|
| 2736 | OsiObject * object = model->modifiableObject(iObject); |
---|
| 2737 | CbcSimpleIntegerDynamicPseudoCost * dynamicObject = |
---|
| 2738 | dynamic_cast <CbcSimpleIntegerDynamicPseudoCost *>(object) ; |
---|
| 2739 | int iColumn = dynamicObject ? dynamicObject->columnNumber() : numberColumns + iObject; |
---|
| 2740 | int preferredWay; |
---|
| 2741 | double infeasibility = object->infeasibility(&usefulInfo, preferredWay); |
---|
| 2742 | // may have become feasible |
---|
| 2743 | if (!infeasibility) |
---|
| 2744 | continue; |
---|
[1271] | 2745 | #ifndef NDEBUG |
---|
[1286] | 2746 | if (iColumn < numberColumns) { |
---|
| 2747 | const double * solution = model->testSolution(); |
---|
| 2748 | assert (saveSolution[iColumn] == solution[iColumn]); |
---|
| 2749 | } |
---|
[1271] | 2750 | #endif |
---|
[1286] | 2751 | CbcSimpleInteger * obj = |
---|
| 2752 | dynamic_cast <CbcSimpleInteger *>(object) ; |
---|
| 2753 | if (obj) { |
---|
| 2754 | if (choiceObject) { |
---|
| 2755 | obj->fillCreateBranch(choiceObject, &usefulInfo, preferredWay); |
---|
| 2756 | choiceObject->setObject(dynamicObject); |
---|
| 2757 | } else { |
---|
| 2758 | choice.possibleBranch = obj->createCbcBranch(solver, &usefulInfo, preferredWay); |
---|
| 2759 | } |
---|
| 2760 | } else { |
---|
| 2761 | CbcObject * obj = |
---|
| 2762 | dynamic_cast <CbcObject *>(object) ; |
---|
| 2763 | assert (obj); |
---|
| 2764 | choice.possibleBranch = obj->createCbcBranch(solver, &usefulInfo, preferredWay); |
---|
| 2765 | } |
---|
| 2766 | // Save which object it was |
---|
| 2767 | choice.objectNumber = iObject; |
---|
| 2768 | choice.numIntInfeasUp = numberUnsatisfied_; |
---|
| 2769 | choice.numIntInfeasDown = numberUnsatisfied_; |
---|
| 2770 | choice.upMovement = upEstimate[iObject]; |
---|
| 2771 | choice.downMovement = downEstimate[iObject]; |
---|
| 2772 | assert (choice.upMovement >= 0.0); |
---|
| 2773 | assert (choice.downMovement >= 0.0); |
---|
| 2774 | choice.fix = 0; // say not fixed |
---|
| 2775 | // see if can skip strong branching |
---|
| 2776 | int canSkip = choice.possibleBranch->fillStrongInfo(choice); |
---|
| 2777 | if ((numberTest <= 0 || skipAll)) { |
---|
| 2778 | if (iDo > 20) { |
---|
[1132] | 2779 | #ifdef DO_ALL_AT_ROOT |
---|
[1286] | 2780 | if (!numberNodes) |
---|
| 2781 | printf("DOY test %d - iDo %d\n", |
---|
| 2782 | numberTest, iDo); |
---|
[1132] | 2783 | #endif |
---|
[1286] | 2784 | if (!choiceObject) { |
---|
| 2785 | delete choice.possibleBranch; |
---|
| 2786 | choice.possibleBranch = NULL; |
---|
| 2787 | } |
---|
| 2788 | break; // give up anyway |
---|
| 2789 | } |
---|
| 2790 | } |
---|
| 2791 | if (model->messageHandler()->logLevel() > 3 && numberBeforeTrust && dynamicObject) |
---|
| 2792 | dynamicObject->print(1, choice.possibleBranch->value()); |
---|
| 2793 | if (skipAll < 0) |
---|
| 2794 | canSkip = true; |
---|
| 2795 | if (!canSkip) { |
---|
| 2796 | if (!doneHotStart) { |
---|
| 2797 | // Mark hot start |
---|
| 2798 | doneHotStart = true; |
---|
| 2799 | solver->markHotStart(); |
---|
| 2800 | xMark++; |
---|
| 2801 | } |
---|
| 2802 | numberTest--; |
---|
| 2803 | // just do a few |
---|
| 2804 | if (searchStrategy == 2) |
---|
| 2805 | solver->setIntParam(OsiMaxNumIterationHotStart, 10); |
---|
| 2806 | double objectiveChange ; |
---|
| 2807 | double newObjectiveValue = 1.0e100; |
---|
| 2808 | int j; |
---|
| 2809 | // status is 0 finished, 1 infeasible and other |
---|
| 2810 | int iStatus; |
---|
| 2811 | /* |
---|
| 2812 | Try the down direction first. (Specify the initial branching alternative as |
---|
| 2813 | down with a call to way(-1). Each subsequent call to branch() performs the |
---|
| 2814 | specified branch and advances the branch object state to the next branch |
---|
| 2815 | alternative.) |
---|
| 2816 | */ |
---|
| 2817 | choice.possibleBranch->way(-1) ; |
---|
| 2818 | choice.possibleBranch->branch() ; |
---|
| 2819 | solver->solveFromHotStart() ; |
---|
| 2820 | bool needHotStartUpdate = false; |
---|
| 2821 | numberStrongDone++; |
---|
| 2822 | numberStrongIterations += solver->getIterationCount(); |
---|
| 2823 | /* |
---|
| 2824 | We now have an estimate of objective degradation that we can use for strong |
---|
| 2825 | branching. If we're over the cutoff, the variable is monotone up. |
---|
| 2826 | If we actually made it to optimality, check for a solution, and if we have |
---|
| 2827 | a good one, call setBestSolution to process it. Note that this may reduce the |
---|
| 2828 | cutoff, so we check again to see if we can declare this variable monotone. |
---|
| 2829 | */ |
---|
| 2830 | if (solver->isProvenOptimal()) |
---|
| 2831 | iStatus = 0; // optimal |
---|
| 2832 | else if (solver->isIterationLimitReached() |
---|
| 2833 | && !solver->isDualObjectiveLimitReached()) |
---|
| 2834 | iStatus = 2; // unknown |
---|
| 2835 | else |
---|
| 2836 | iStatus = 1; // infeasible |
---|
| 2837 | if (iStatus != 2 && solver->getIterationCount() > |
---|
| 2838 | realMaxHotIterations) |
---|
| 2839 | numberUnfinished++; |
---|
| 2840 | newObjectiveValue = solver->getObjSense() * solver->getObjValue(); |
---|
| 2841 | choice.numItersDown = solver->getIterationCount(); |
---|
| 2842 | objectiveChange = CoinMax(newObjectiveValue - objectiveValue_, 0.0); |
---|
| 2843 | // Update branching information if wanted |
---|
| 2844 | CbcBranchingObject * cbcobj = dynamic_cast<CbcBranchingObject *> (choice.possibleBranch); |
---|
| 2845 | if (cbcobj) { |
---|
| 2846 | CbcObject * object = cbcobj->object(); |
---|
| 2847 | assert (object) ; |
---|
| 2848 | CbcObjectUpdateData update = object->createUpdateInformation(solver, this, cbcobj); |
---|
| 2849 | update.objectNumber_ = choice.objectNumber; |
---|
| 2850 | model->addUpdateInformation(update); |
---|
| 2851 | } else { |
---|
| 2852 | decision->updateInformation( solver, this); |
---|
| 2853 | } |
---|
| 2854 | if (!iStatus) { |
---|
| 2855 | choice.finishedDown = true ; |
---|
| 2856 | if (newObjectiveValue >= cutoff) { |
---|
| 2857 | objectiveChange = 1.0e100; // say infeasible |
---|
| 2858 | numberStrongInfeasible++; |
---|
| 2859 | } else { |
---|
| 2860 | //#define TIGHTEN_BOUNDS |
---|
[1271] | 2861 | #ifdef TIGHTEN_BOUNDS |
---|
[1286] | 2862 | // Can we tighten bounds? |
---|
| 2863 | if (iColumn < numberColumns && cutoff < 1.0e20 |
---|
| 2864 | && objectiveChange > 1.0e-5) { |
---|
| 2865 | double value = saveSolution[iColumn]; |
---|
| 2866 | double down = value - floor(value); |
---|
| 2867 | double changePer = objectiveChange / (down + 1.0e-7); |
---|
| 2868 | double distance = (cutoff - objectiveValue_) / changePer; |
---|
| 2869 | distance += 1.0e-3; |
---|
| 2870 | if (distance < 5.0) { |
---|
| 2871 | double newLower = ceil(value - distance); |
---|
| 2872 | if (newLower > saveLower[iColumn]) { |
---|
| 2873 | //printf("Could increase lower bound on %d from %g to %g\n", |
---|
| 2874 | // iColumn,saveLower[iColumn],newLower); |
---|
| 2875 | saveLower[iColumn] = newLower; |
---|
| 2876 | solver->setColLower(iColumn, newLower); |
---|
| 2877 | } |
---|
| 2878 | } |
---|
| 2879 | } |
---|
[1271] | 2880 | #endif |
---|
[1286] | 2881 | // See if integer solution |
---|
| 2882 | if (model->feasibleSolution(choice.numIntInfeasDown, |
---|
| 2883 | choice.numObjInfeasDown) |
---|
| 2884 | && model->problemFeasibility()->feasible(model, -1) >= 0) { |
---|
| 2885 | if (auxiliaryInfo->solutionAddsCuts()) { |
---|
| 2886 | needHotStartUpdate = true; |
---|
| 2887 | solver->unmarkHotStart(); |
---|
| 2888 | } |
---|
[1409] | 2889 | model->setLogLevel(saveLogLevel); |
---|
[1286] | 2890 | model->setBestSolution(CBC_STRONGSOL, |
---|
| 2891 | newObjectiveValue, |
---|
| 2892 | solver->getColSolution()) ; |
---|
| 2893 | if (needHotStartUpdate) { |
---|
| 2894 | model->resolve(NULL, 11, saveSolution, saveLower, saveUpper); |
---|
| 2895 | newObjectiveValue = solver->getObjSense() * solver->getObjValue(); |
---|
| 2896 | //objectiveValue_ = CoinMax(objectiveValue_,newObjectiveValue); |
---|
| 2897 | objectiveChange = CoinMax(newObjectiveValue - objectiveValue_, 0.0); |
---|
| 2898 | model->feasibleSolution(choice.numIntInfeasDown, |
---|
| 2899 | choice.numObjInfeasDown); |
---|
| 2900 | } |
---|
| 2901 | model->setLastHeuristic(NULL); |
---|
| 2902 | model->incrementUsed(solver->getColSolution()); |
---|
| 2903 | cutoff = model->getCutoff(); |
---|
| 2904 | if (newObjectiveValue >= cutoff) { // *new* cutoff |
---|
| 2905 | objectiveChange = 1.0e100 ; |
---|
| 2906 | numberStrongInfeasible++; |
---|
| 2907 | } |
---|
| 2908 | } |
---|
| 2909 | } |
---|
| 2910 | } else if (iStatus == 1) { |
---|
| 2911 | objectiveChange = 1.0e100 ; |
---|
| 2912 | numberStrongInfeasible++; |
---|
| 2913 | } else { |
---|
| 2914 | // Can't say much as we did not finish |
---|
| 2915 | choice.finishedDown = false ; |
---|
| 2916 | numberUnfinished++; |
---|
| 2917 | } |
---|
| 2918 | choice.downMovement = objectiveChange ; |
---|
| 2919 | |
---|
| 2920 | // restore bounds |
---|
| 2921 | for ( j = 0; j < numberColumns; j++) { |
---|
| 2922 | if (saveLower[j] != lower[j]) |
---|
| 2923 | solver->setColLower(j, saveLower[j]); |
---|
| 2924 | if (saveUpper[j] != upper[j]) |
---|
| 2925 | solver->setColUpper(j, saveUpper[j]); |
---|
| 2926 | } |
---|
| 2927 | if (needHotStartUpdate) { |
---|
| 2928 | needHotStartUpdate = false; |
---|
| 2929 | model->resolve(NULL, 11, saveSolution, saveLower, saveUpper); |
---|
| 2930 | //double newObjValue = solver->getObjSense()*solver->getObjValue(); |
---|
| 2931 | //objectiveValue_ = CoinMax(objectiveValue_,newObjValue); |
---|
| 2932 | //we may again have an integer feasible solution |
---|
| 2933 | int numberIntegerInfeasibilities; |
---|
| 2934 | int numberObjectInfeasibilities; |
---|
| 2935 | if (model->feasibleSolution( |
---|
| 2936 | numberIntegerInfeasibilities, |
---|
| 2937 | numberObjectInfeasibilities)) { |
---|
[307] | 2938 | #ifdef BONMIN |
---|
[1286] | 2939 | //In this case node has become integer feasible, let us exit the loop |
---|
| 2940 | std::cout << "Node has become integer feasible" << std::endl; |
---|
| 2941 | numberUnsatisfied_ = 0; |
---|
| 2942 | break; |
---|
[307] | 2943 | #endif |
---|
[1286] | 2944 | double objValue = solver->getObjValue(); |
---|
[1409] | 2945 | model->setLogLevel(saveLogLevel); |
---|
[1286] | 2946 | model->setBestSolution(CBC_STRONGSOL, |
---|
| 2947 | objValue, |
---|
| 2948 | solver->getColSolution()) ; |
---|
| 2949 | model->resolve(NULL, 11, saveSolution, saveLower, saveUpper); |
---|
| 2950 | //double newObjValue = solver->getObjSense()*solver->getObjValue(); |
---|
| 2951 | //objectiveValue_ = CoinMax(objectiveValue_,newObjValue); |
---|
| 2952 | cutoff = model->getCutoff(); |
---|
| 2953 | } |
---|
| 2954 | solver->markHotStart(); |
---|
| 2955 | } |
---|
[1132] | 2956 | #ifdef DO_ALL_AT_ROOT |
---|
[1286] | 2957 | if (!numberNodes) |
---|
| 2958 | printf("Down on %d, status is %d, obj %g its %d cost %g finished %d inf %d infobj %d\n", |
---|
| 2959 | choice.objectNumber, iStatus, newObjectiveValue, choice.numItersDown, |
---|
| 2960 | choice.downMovement, choice.finishedDown, choice.numIntInfeasDown, |
---|
| 2961 | choice.numObjInfeasDown); |
---|
[1132] | 2962 | #endif |
---|
[1286] | 2963 | |
---|
| 2964 | // repeat the whole exercise, forcing the variable up |
---|
| 2965 | choice.possibleBranch->branch(); |
---|
| 2966 | solver->solveFromHotStart() ; |
---|
| 2967 | numberStrongDone++; |
---|
| 2968 | numberStrongIterations += solver->getIterationCount(); |
---|
| 2969 | /* |
---|
| 2970 | We now have an estimate of objective degradation that we can use for strong |
---|
| 2971 | branching. If we're over the cutoff, the variable is monotone up. |
---|
| 2972 | If we actually made it to optimality, check for a solution, and if we have |
---|
| 2973 | a good one, call setBestSolution to process it. Note that this may reduce the |
---|
| 2974 | cutoff, so we check again to see if we can declare this variable monotone. |
---|
| 2975 | */ |
---|
| 2976 | if (solver->isProvenOptimal()) |
---|
| 2977 | iStatus = 0; // optimal |
---|
| 2978 | else if (solver->isIterationLimitReached() |
---|
| 2979 | && !solver->isDualObjectiveLimitReached()) |
---|
| 2980 | iStatus = 2; // unknown |
---|
| 2981 | else |
---|
| 2982 | iStatus = 1; // infeasible |
---|
| 2983 | if (iStatus != 2 && solver->getIterationCount() > |
---|
| 2984 | realMaxHotIterations) |
---|
| 2985 | numberUnfinished++; |
---|
| 2986 | newObjectiveValue = solver->getObjSense() * solver->getObjValue(); |
---|
| 2987 | choice.numItersUp = solver->getIterationCount(); |
---|
| 2988 | objectiveChange = CoinMax(newObjectiveValue - objectiveValue_, 0.0); |
---|
| 2989 | // Update branching information if wanted |
---|
| 2990 | cbcobj = dynamic_cast<CbcBranchingObject *> (choice.possibleBranch); |
---|
| 2991 | if (cbcobj) { |
---|
| 2992 | CbcObject * object = cbcobj->object(); |
---|
| 2993 | assert (object) ; |
---|
| 2994 | CbcObjectUpdateData update = object->createUpdateInformation(solver, this, cbcobj); |
---|
| 2995 | update.objectNumber_ = choice.objectNumber; |
---|
| 2996 | model->addUpdateInformation(update); |
---|
| 2997 | } else { |
---|
| 2998 | decision->updateInformation( solver, this); |
---|
| 2999 | } |
---|
| 3000 | if (!iStatus) { |
---|
| 3001 | choice.finishedUp = true ; |
---|
| 3002 | if (newObjectiveValue >= cutoff) { |
---|
| 3003 | objectiveChange = 1.0e100; // say infeasible |
---|
| 3004 | numberStrongInfeasible++; |
---|
| 3005 | } else { |
---|
[1271] | 3006 | #ifdef TIGHTEN_BOUNDS |
---|
[1286] | 3007 | // Can we tighten bounds? |
---|
| 3008 | if (iColumn < numberColumns && cutoff < 1.0e20 |
---|
| 3009 | && objectiveChange > 1.0e-5) { |
---|
| 3010 | double value = saveSolution[iColumn]; |
---|
| 3011 | double up = ceil(value) - value; |
---|
| 3012 | double changePer = objectiveChange / (up + 1.0e-7); |
---|
| 3013 | double distance = (cutoff - objectiveValue_) / changePer; |
---|
| 3014 | distance += 1.0e-3; |
---|
| 3015 | if (distance < 5.0) { |
---|
| 3016 | double newUpper = floor(value + distance); |
---|
| 3017 | if (newUpper < saveUpper[iColumn]) { |
---|
| 3018 | //printf("Could decrease upper bound on %d from %g to %g\n", |
---|
| 3019 | // iColumn,saveUpper[iColumn],newUpper); |
---|
| 3020 | saveUpper[iColumn] = newUpper; |
---|
| 3021 | solver->setColUpper(iColumn, newUpper); |
---|
| 3022 | } |
---|
| 3023 | } |
---|
| 3024 | } |
---|
[1271] | 3025 | #endif |
---|
[1286] | 3026 | // See if integer solution |
---|
| 3027 | if (model->feasibleSolution(choice.numIntInfeasUp, |
---|
| 3028 | choice.numObjInfeasUp) |
---|
| 3029 | && model->problemFeasibility()->feasible(model, -1) >= 0) { |
---|
[307] | 3030 | #ifdef BONMIN |
---|
[1286] | 3031 | std::cout << "Node has become integer feasible" << std::endl; |
---|
| 3032 | numberUnsatisfied_ = 0; |
---|
| 3033 | break; |
---|
[307] | 3034 | #endif |
---|
[1286] | 3035 | if (auxiliaryInfo->solutionAddsCuts()) { |
---|
| 3036 | needHotStartUpdate = true; |
---|
| 3037 | solver->unmarkHotStart(); |
---|
| 3038 | } |
---|
[1409] | 3039 | model->setLogLevel(saveLogLevel); |
---|
[1286] | 3040 | model->setBestSolution(CBC_STRONGSOL, |
---|
| 3041 | newObjectiveValue, |
---|
| 3042 | solver->getColSolution()) ; |
---|
| 3043 | if (needHotStartUpdate) { |
---|
| 3044 | model->resolve(NULL, 11, saveSolution, saveLower, saveUpper); |
---|
| 3045 | newObjectiveValue = solver->getObjSense() * solver->getObjValue(); |
---|
| 3046 | //objectiveValue_ = CoinMax(objectiveValue_,newObjectiveValue); |
---|
| 3047 | objectiveChange = CoinMax(newObjectiveValue - objectiveValue_, 0.0); |
---|
| 3048 | model->feasibleSolution(choice.numIntInfeasDown, |
---|
| 3049 | choice.numObjInfeasDown); |
---|
| 3050 | } |
---|
| 3051 | model->setLastHeuristic(NULL); |
---|
| 3052 | model->incrementUsed(solver->getColSolution()); |
---|
| 3053 | cutoff = model->getCutoff(); |
---|
| 3054 | if (newObjectiveValue >= cutoff) { // *new* cutoff |
---|
| 3055 | objectiveChange = 1.0e100 ; |
---|
| 3056 | numberStrongInfeasible++; |
---|
| 3057 | } |
---|
| 3058 | } |
---|
| 3059 | } |
---|
| 3060 | } else if (iStatus == 1) { |
---|
| 3061 | objectiveChange = 1.0e100 ; |
---|
| 3062 | numberStrongInfeasible++; |
---|
| 3063 | } else { |
---|
| 3064 | // Can't say much as we did not finish |
---|
| 3065 | choice.finishedUp = false ; |
---|
| 3066 | numberUnfinished++; |
---|
| 3067 | } |
---|
| 3068 | choice.upMovement = objectiveChange ; |
---|
| 3069 | |
---|
| 3070 | // restore bounds |
---|
| 3071 | for ( j = 0; j < numberColumns; j++) { |
---|
| 3072 | if (saveLower[j] != lower[j]) |
---|
| 3073 | solver->setColLower(j, saveLower[j]); |
---|
| 3074 | if (saveUpper[j] != upper[j]) |
---|
| 3075 | solver->setColUpper(j, saveUpper[j]); |
---|
| 3076 | } |
---|
| 3077 | if (needHotStartUpdate) { |
---|
| 3078 | needHotStartUpdate = false; |
---|
| 3079 | model->resolve(NULL, 11, saveSolution, saveLower, saveUpper); |
---|
| 3080 | //double newObjValue = solver->getObjSense()*solver->getObjValue(); |
---|
| 3081 | //objectiveValue_ = CoinMax(objectiveValue_,newObjValue); |
---|
| 3082 | //we may again have an integer feasible solution |
---|
| 3083 | int numberIntegerInfeasibilities; |
---|
| 3084 | int numberObjectInfeasibilities; |
---|
| 3085 | if (model->feasibleSolution( |
---|
| 3086 | numberIntegerInfeasibilities, |
---|
| 3087 | numberObjectInfeasibilities)) { |
---|
| 3088 | double objValue = solver->getObjValue(); |
---|
[1409] | 3089 | model->setLogLevel(saveLogLevel); |
---|
[1286] | 3090 | model->setBestSolution(CBC_STRONGSOL, |
---|
| 3091 | objValue, |
---|
| 3092 | solver->getColSolution()) ; |
---|
| 3093 | model->resolve(NULL, 11, saveSolution, saveLower, saveUpper); |
---|
| 3094 | //double newObjValue = solver->getObjSense()*solver->getObjValue(); |
---|
| 3095 | //objectiveValue_ = CoinMax(objectiveValue_,newObjValue); |
---|
| 3096 | cutoff = model->getCutoff(); |
---|
| 3097 | } |
---|
| 3098 | solver->markHotStart(); |
---|
| 3099 | } |
---|
| 3100 | |
---|
| 3101 | #ifdef DO_ALL_AT_ROOT |
---|
| 3102 | if (!numberNodes) |
---|
| 3103 | printf("Up on %d, status is %d, obj %g its %d cost %g finished %d inf %d infobj %d\n", |
---|
| 3104 | choice.objectNumber, iStatus, newObjectiveValue, choice.numItersUp, |
---|
| 3105 | choice.upMovement, choice.finishedUp, choice.numIntInfeasUp, |
---|
| 3106 | choice.numObjInfeasUp); |
---|
| 3107 | #endif |
---|
[264] | 3108 | } |
---|
[1286] | 3109 | |
---|
| 3110 | solver->setIntParam(OsiMaxNumIterationHotStart, saveLimit2); |
---|
| 3111 | /* |
---|
| 3112 | End of evaluation for this candidate variable. Possibilities are: |
---|
| 3113 | * Both sides below cutoff; this variable is a candidate for branching. |
---|
| 3114 | * Both sides infeasible or above the objective cutoff: no further action |
---|
| 3115 | here. Break from the evaluation loop and assume the node will be purged |
---|
| 3116 | by the caller. |
---|
| 3117 | * One side below cutoff: Install the branch (i.e., fix the variable). Break |
---|
| 3118 | from the evaluation loop and assume the node will be reoptimised by the |
---|
| 3119 | caller. |
---|
| 3120 | */ |
---|
| 3121 | // reset |
---|
| 3122 | choice.possibleBranch->resetNumberBranchesLeft(); |
---|
| 3123 | if (choice.upMovement < 1.0e100) { |
---|
| 3124 | if (choice.downMovement < 1.0e100) { |
---|
| 3125 | // In case solution coming in was odd |
---|
| 3126 | choice.upMovement = CoinMax(0.0, choice.upMovement); |
---|
| 3127 | choice.downMovement = CoinMax(0.0, choice.downMovement); |
---|
| 3128 | #if ZERO_ONE==2 |
---|
| 3129 | // branch on 0-1 first (temp) |
---|
| 3130 | if (fabs(choice.possibleBranch->value()) < 1.0) { |
---|
| 3131 | choice.upMovement *= ZERO_FAKE; |
---|
| 3132 | choice.downMovement *= ZERO_FAKE; |
---|
| 3133 | } |
---|
| 3134 | #endif |
---|
| 3135 | // feasible - see which best |
---|
| 3136 | if (!canSkip) { |
---|
| 3137 | if (model->messageHandler()->logLevel() > 3) |
---|
| 3138 | printf("sort %g downest %g upest %g ", sort[iDo], downEstimate[iObject], |
---|
| 3139 | upEstimate[iObject]); |
---|
| 3140 | model->messageHandler()->message(CBC_STRONG, *model->messagesPointer()) |
---|
| 3141 | << iObject << iColumn |
---|
| 3142 | << choice.downMovement << choice.numIntInfeasDown |
---|
| 3143 | << choice.upMovement << choice.numIntInfeasUp |
---|
| 3144 | << choice.possibleBranch->value() |
---|
| 3145 | << CoinMessageEol; |
---|
| 3146 | } |
---|
| 3147 | int betterWay; |
---|
| 3148 | { |
---|
| 3149 | CbcBranchingObject * branchObj = |
---|
| 3150 | dynamic_cast <CbcBranchingObject *>(branch_) ; |
---|
| 3151 | if (branch_) |
---|
| 3152 | assert (branchObj); |
---|
| 3153 | betterWay = decision->betterBranch(choice.possibleBranch, |
---|
| 3154 | branchObj, |
---|
| 3155 | choice.upMovement, |
---|
| 3156 | choice.numIntInfeasUp , |
---|
| 3157 | choice.downMovement, |
---|
| 3158 | choice.numIntInfeasDown ); |
---|
| 3159 | } |
---|
| 3160 | if (betterWay) { |
---|
| 3161 | // C) create branching object |
---|
| 3162 | if (choiceObject) { |
---|
| 3163 | delete branch_; |
---|
| 3164 | branch_ = choice.possibleBranch->clone(); |
---|
| 3165 | } else { |
---|
| 3166 | delete branch_; |
---|
| 3167 | branch_ = choice.possibleBranch; |
---|
| 3168 | choice.possibleBranch = NULL; |
---|
| 3169 | } |
---|
| 3170 | { |
---|
| 3171 | CbcBranchingObject * branchObj = |
---|
| 3172 | dynamic_cast <CbcBranchingObject *>(branch_) ; |
---|
| 3173 | assert (branchObj); |
---|
| 3174 | //branchObj->way(preferredWay); |
---|
| 3175 | branchObj->way(betterWay); |
---|
| 3176 | } |
---|
| 3177 | bestChoice = choice.objectNumber; |
---|
| 3178 | whichChoice = iDo; |
---|
| 3179 | if (numberStrong <= 1) { |
---|
| 3180 | delete ws; |
---|
| 3181 | ws = NULL; |
---|
| 3182 | break; |
---|
| 3183 | } |
---|
| 3184 | } else { |
---|
| 3185 | if (!choiceObject) { |
---|
| 3186 | delete choice.possibleBranch; |
---|
| 3187 | choice.possibleBranch = NULL; |
---|
| 3188 | } |
---|
| 3189 | if (iDo >= 2*numberStrong) { |
---|
| 3190 | delete ws; |
---|
| 3191 | ws = NULL; |
---|
| 3192 | break; |
---|
| 3193 | } |
---|
| 3194 | if (!dynamicObject || dynamicObject->numberTimesUp() > 1) { |
---|
| 3195 | if (iDo - whichChoice >= numberStrong) { |
---|
| 3196 | if (!choiceObject) { |
---|
| 3197 | delete choice.possibleBranch; |
---|
| 3198 | choice.possibleBranch = NULL; |
---|
| 3199 | } |
---|
| 3200 | break; // give up |
---|
| 3201 | } |
---|
| 3202 | } else { |
---|
| 3203 | if (iDo - whichChoice >= 2*numberStrong) { |
---|
| 3204 | delete ws; |
---|
| 3205 | ws = NULL; |
---|
| 3206 | if (!choiceObject) { |
---|
| 3207 | delete choice.possibleBranch; |
---|
| 3208 | choice.possibleBranch = NULL; |
---|
| 3209 | } |
---|
| 3210 | break; // give up |
---|
| 3211 | } |
---|
| 3212 | } |
---|
| 3213 | } |
---|
| 3214 | } else { |
---|
| 3215 | // up feasible, down infeasible |
---|
| 3216 | anyAction = -1; |
---|
| 3217 | worstFeasible = CoinMax(worstFeasible, choice.upMovement); |
---|
| 3218 | model->messageHandler()->message(CBC_STRONG, *model->messagesPointer()) |
---|
| 3219 | << iObject << iColumn |
---|
| 3220 | << choice.downMovement << choice.numIntInfeasDown |
---|
| 3221 | << choice.upMovement << choice.numIntInfeasUp |
---|
| 3222 | << choice.possibleBranch->value() |
---|
| 3223 | << CoinMessageEol; |
---|
| 3224 | //printf("Down infeasible for choice %d sequence %d\n",i, |
---|
| 3225 | // model->object(choice.objectNumber)->columnNumber()); |
---|
| 3226 | choice.fix = 1; |
---|
| 3227 | numberToFix++; |
---|
| 3228 | choice.possibleBranch->fix(solver, saveLower, saveUpper, 1); |
---|
| 3229 | if (!choiceObject) { |
---|
[1406] | 3230 | delete choice.possibleBranch; |
---|
[1286] | 3231 | choice.possibleBranch = NULL; |
---|
| 3232 | } else { |
---|
| 3233 | //choiceObject = new CbcDynamicPseudoCostBranchingObject(*choiceObject); |
---|
| 3234 | choice.possibleBranch = choiceObject; |
---|
| 3235 | } |
---|
| 3236 | assert(doneHotStart); |
---|
| 3237 | solver->unmarkHotStart(); |
---|
| 3238 | model->resolve(NULL, 11, saveSolution, saveLower, saveUpper); |
---|
| 3239 | //double newObjValue = solver->getObjSense()*solver->getObjValue(); |
---|
| 3240 | //objectiveValue_ = CoinMax(objectiveValue_,newObjValue); |
---|
| 3241 | solver->markHotStart(); |
---|
| 3242 | // may be infeasible (if other way stopped on iterations) |
---|
| 3243 | if (!solver->isProvenOptimal()) { |
---|
| 3244 | // neither side feasible |
---|
| 3245 | anyAction = -2; |
---|
| 3246 | if (!choiceObject) { |
---|
| 3247 | delete choice.possibleBranch; |
---|
| 3248 | choice.possibleBranch = NULL; |
---|
| 3249 | } |
---|
| 3250 | //printf("Both infeasible for choice %d sequence %d\n",i, |
---|
| 3251 | // model->object(choice.objectNumber)->columnNumber()); |
---|
| 3252 | delete ws; |
---|
| 3253 | ws = NULL; |
---|
| 3254 | break; |
---|
| 3255 | } |
---|
| 3256 | } |
---|
| 3257 | } else { |
---|
| 3258 | if (choice.downMovement < 1.0e100) { |
---|
| 3259 | // down feasible, up infeasible |
---|
| 3260 | anyAction = -1; |
---|
| 3261 | worstFeasible = CoinMax(worstFeasible, choice.downMovement); |
---|
| 3262 | model->messageHandler()->message(CBC_STRONG, *model->messagesPointer()) |
---|
| 3263 | << iObject << iColumn |
---|
| 3264 | << choice.downMovement << choice.numIntInfeasDown |
---|
| 3265 | << choice.upMovement << choice.numIntInfeasUp |
---|
| 3266 | << choice.possibleBranch->value() |
---|
| 3267 | << CoinMessageEol; |
---|
| 3268 | choice.fix = -1; |
---|
| 3269 | numberToFix++; |
---|
| 3270 | choice.possibleBranch->fix(solver, saveLower, saveUpper, -1); |
---|
| 3271 | if (!choiceObject) { |
---|
[1406] | 3272 | delete choice.possibleBranch; |
---|
[1286] | 3273 | choice.possibleBranch = NULL; |
---|
| 3274 | } else { |
---|
| 3275 | //choiceObject = new CbcDynamicPseudoCostBranchingObject(*choiceObject); |
---|
| 3276 | choice.possibleBranch = choiceObject; |
---|
| 3277 | } |
---|
| 3278 | assert(doneHotStart); |
---|
| 3279 | solver->unmarkHotStart(); |
---|
| 3280 | model->resolve(NULL, 11, saveSolution, saveLower, saveUpper); |
---|
| 3281 | //double newObjValue = solver->getObjSense()*solver->getObjValue(); |
---|
| 3282 | //objectiveValue_ = CoinMax(objectiveValue_,newObjValue); |
---|
| 3283 | solver->markHotStart(); |
---|
| 3284 | // may be infeasible (if other way stopped on iterations) |
---|
| 3285 | if (!solver->isProvenOptimal()) { |
---|
| 3286 | // neither side feasible |
---|
| 3287 | anyAction = -2; |
---|
| 3288 | if (!choiceObject) { |
---|
| 3289 | delete choice.possibleBranch; |
---|
| 3290 | choice.possibleBranch = NULL; |
---|
| 3291 | } |
---|
| 3292 | delete ws; |
---|
| 3293 | ws = NULL; |
---|
| 3294 | break; |
---|
| 3295 | } |
---|
| 3296 | } else { |
---|
| 3297 | // neither side feasible |
---|
| 3298 | anyAction = -2; |
---|
| 3299 | if (!choiceObject) { |
---|
| 3300 | delete choice.possibleBranch; |
---|
| 3301 | choice.possibleBranch = NULL; |
---|
| 3302 | } |
---|
| 3303 | delete ws; |
---|
| 3304 | ws = NULL; |
---|
| 3305 | break; |
---|
| 3306 | } |
---|
[264] | 3307 | } |
---|
[1286] | 3308 | // Check max time |
---|
| 3309 | hitMaxTime = ( CoinCpuTime() - model->getDblParam(CbcModel::CbcStartSeconds) > |
---|
| 3310 | model->getDblParam(CbcModel::CbcMaximumSeconds)); |
---|
| 3311 | if (hitMaxTime) { |
---|
| 3312 | // make sure rest are fast |
---|
| 3313 | doQuickly = true; |
---|
| 3314 | for ( int jDo = iDo + 1; jDo < numberToDo; jDo++) { |
---|
| 3315 | int iObject = whichObject[iDo]; |
---|
| 3316 | OsiObject * object = model->modifiableObject(iObject); |
---|
| 3317 | CbcSimpleIntegerDynamicPseudoCost * dynamicObject = |
---|
| 3318 | dynamic_cast <CbcSimpleIntegerDynamicPseudoCost *>(object) ; |
---|
| 3319 | if (dynamicObject) |
---|
| 3320 | dynamicObject->setNumberBeforeTrust(0); |
---|
| 3321 | } |
---|
| 3322 | numberTest = 0; |
---|
[259] | 3323 | } |
---|
[1286] | 3324 | if (!choiceObject) { |
---|
| 3325 | delete choice.possibleBranch; |
---|
| 3326 | } |
---|
[135] | 3327 | } |
---|
[1286] | 3328 | if (model->messageHandler()->logLevel() > 3) { |
---|
| 3329 | if (anyAction == -2) { |
---|
| 3330 | printf("infeasible\n"); |
---|
| 3331 | } else if (anyAction == -1) { |
---|
| 3332 | printf("%d fixed AND choosing %d iDo %d iChosenWhen %d numberToDo %d\n", numberToFix, bestChoice, |
---|
| 3333 | iDo, whichChoice, numberToDo); |
---|
| 3334 | } else { |
---|
| 3335 | int iObject = whichObject[whichChoice]; |
---|
| 3336 | OsiObject * object = model->modifiableObject(iObject); |
---|
| 3337 | CbcSimpleIntegerDynamicPseudoCost * dynamicObject = |
---|
| 3338 | dynamic_cast <CbcSimpleIntegerDynamicPseudoCost *>(object) ; |
---|
| 3339 | if (dynamicObject) { |
---|
| 3340 | int iColumn = dynamicObject->columnNumber(); |
---|
| 3341 | printf("choosing %d (column %d) iChosenWhen %d numberToDo %d\n", bestChoice, |
---|
| 3342 | iColumn, whichChoice, numberToDo); |
---|
| 3343 | } |
---|
| 3344 | } |
---|
[264] | 3345 | } |
---|
[1286] | 3346 | if (doneHotStart) { |
---|
| 3347 | // Delete the snapshot |
---|
| 3348 | solver->unmarkHotStart(); |
---|
| 3349 | // back to normal |
---|
| 3350 | solver->setHintParam(OsiDoInBranchAndCut, true, OsiHintDo, NULL) ; |
---|
| 3351 | // restore basis |
---|
| 3352 | solver->setWarmStart(ws); |
---|
[259] | 3353 | } |
---|
[1286] | 3354 | solver->setIntParam(OsiMaxNumIterationHotStart, saveLimit); |
---|
| 3355 | // Unless infeasible we will carry on |
---|
| 3356 | // But we could fix anyway |
---|
| 3357 | if (numberToFix && !hitMaxTime) { |
---|
| 3358 | if (anyAction != -2) { |
---|
| 3359 | // apply and take off |
---|
| 3360 | bool feasible = true; |
---|
| 3361 | // can do quick optimality check |
---|
| 3362 | int easy = 2; |
---|
| 3363 | solver->setHintParam(OsiDoInBranchAndCut, true, OsiHintDo, &easy) ; |
---|
| 3364 | model->resolve(NULL, 11, saveSolution, saveLower, saveUpper) ; |
---|
| 3365 | //double newObjValue = solver->getObjSense()*solver->getObjValue(); |
---|
| 3366 | //objectiveValue_ = CoinMax(objectiveValue_,newObjValue); |
---|
| 3367 | solver->setHintParam(OsiDoInBranchAndCut, true, OsiHintDo, NULL) ; |
---|
| 3368 | feasible = solver->isProvenOptimal(); |
---|
| 3369 | if (feasible) { |
---|
| 3370 | anyAction = 0; |
---|
| 3371 | // See if candidate still possible |
---|
| 3372 | if (branch_) { |
---|
| 3373 | const OsiObject * object = model->object(bestChoice); |
---|
| |
---|