- Timestamp:
- Jun 3, 2008 9:19:53 AM (13 years ago)
- Location:
- trunk/Cbc/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cbc/src/CbcHeuristic.cpp
r955 r961 346 346 CbcHeuristic::shouldHeurRun_randomChoice() 347 347 { 348 if (!when_) 349 return false; 348 350 int depth = 0; 349 351 const CbcNode* currentNode = model_->currentNode(); … … 351 353 depth = currentNode->depth(); 352 354 } 353 354 if(depth != 0 ) {355 // when_ -999 is special marker to force to run 356 if(depth != 0&&when_!=-999) { 355 357 const double numerator = depth * depth; 356 358 const double denominator = exp(depth * log((double)2)); 357 359 double probability = numerator / denominator; 358 360 double randomNumber = randomNumberGenerator_.randomDouble(); 359 if (when_>2&&when_< 7) {361 if (when_>2&&when_<8) { 360 362 /* JJF adjustments 361 363 3 only at root and if no solution … … 363 365 5 only at depth <4 364 366 6 decay 367 7 run up to 2 times if solution found 4 otherwise 365 368 */ 366 369 switch(when_) { 367 370 case 3: 371 default: 368 372 if (model_->bestSolution()) 369 373 probability=-1.0; … … 378 382 break; 379 383 case 6: 380 if (depth>=4) { 381 if (numberSolutionsFound_*howOften_<numCouldRun_) 382 howOften_ = (int) (howOften_*1.1); 384 if (depth>=3) { 385 if ((numCouldRun_%howOften_)==0&& 386 numberSolutionsFound_*howOften_<numCouldRun_) { 387 int old=howOften_; 388 howOften_ = CoinMin(CoinMax((int) (howOften_*1.1),howOften_+1),10000); 389 #ifdef COIN_DEVELOP 390 printf("Howoften changed from %d to %d for %s\n", 391 old,howOften_,heuristicName_.c_str()); 392 #endif 393 } 383 394 probability = 1.0/howOften_; 384 395 if (model_->bestSolution()) … … 386 397 } 387 398 break; 399 case 7: 400 if ((model_->bestSolution()&&numRuns_>=2)||numRuns_>=4) 401 probability=-1.0; 402 break; 388 403 } 389 404 } … … 393 408 if (model_->getCurrentPassNumber() > 1) 394 409 return false; 410 #ifdef COIN_DEVELOP 411 printf("Running %s, random %g probability %g\n", 412 heuristicName_.c_str(),randomNumber,probability); 413 #endif 414 } else { 415 #ifdef COIN_DEVELOP 416 printf("Running %s, depth %d when %d\n", 417 heuristicName_.c_str(),depth,when_); 418 #endif 395 419 } 396 420 ++numRuns_; … … 610 634 /* Do not try and produce equality cliques and 611 635 do up to 2 passes (normally) 5 if restart */ 612 int numberPasses= (numberNodes<0) ? 5 : 2; 636 int numberPasses= 2; 637 if (numberNodes<0) { 638 numberPasses = 5; 639 // Say some rows cuts 640 int numberRows = solver->getNumRows(); 641 if (numberNodes_<numberRows) { 642 char * type = new char[numberRows]; 643 memset(type,0,numberNodes_); 644 memset(type+numberNodes_,1,numberRows-numberNodes_); 645 process.passInRowTypes(type,numberRows); 646 delete [] type; 647 } 648 } 613 649 if (logLevel<=1) 614 650 process.messageHandler()->setLogLevel(0); … … 658 694 model.solver()->setIntParam(OsiMaxNumIterationHotStart,10); 659 695 model.setMaximumCutPassesAtRoot(CoinMin(20,model_->getMaximumCutPassesAtRoot())); 696 model.setMaximumCutPasses(CoinMin(10,model_->getMaximumCutPasses())); 660 697 } else { 661 698 model_->messageHandler()->message(CBC_RESTART,model_->messages()) … … 667 704 model.cutGenerator(i)->setTiming(true); 668 705 model.setCutoff(cutoff); 706 // make sure can't do nested search! but allow heuristics 707 model.setSpecialOptions((model.specialOptions()&(~(512+2048)))|1024); 669 708 bool takeHint; 670 709 OsiHintStrength strength; … … 678 717 model.setStrategy(strategy); 679 718 //model.solver()->writeMps("crunched"); 719 int numberCuts = process.cuts().sizeRowCuts(); 720 if (numberCuts) { 721 // add in cuts 722 CglStored cuts = process.cuts(); 723 model.addCutGenerator(&cuts,1,"Stored from first"); 724 } 680 725 } 681 726 if (inputSolution_) { … … 1244 1289 { 1245 1290 1291 numCouldRun_++; 1246 1292 // See if to do 1247 1293 if (!when()||(when()%10==1&&model_->phase()!=1)|| 1248 1294 (when()%10==2&&(model_->phase()!=2&&model_->phase()!=3))) 1249 1295 return 0; // switched off 1296 numRuns_++; 1250 1297 OsiSolverInterface * solver = model_->solver(); 1251 1298 double direction = solver->getObjSense(); … … 2303 2350 } 2304 2351 2352 2353 // Default Constructor 2354 CbcHeuristicJustOne::CbcHeuristicJustOne() 2355 :CbcHeuristic(), 2356 probabilities_(NULL), 2357 heuristic_(NULL), 2358 numberHeuristics_(0) 2359 { 2360 } 2361 2362 // Constructor from model 2363 CbcHeuristicJustOne::CbcHeuristicJustOne(CbcModel & model) 2364 :CbcHeuristic(model), 2365 probabilities_(NULL), 2366 heuristic_(NULL), 2367 numberHeuristics_(0) 2368 { 2369 } 2370 2371 // Destructor 2372 CbcHeuristicJustOne::~CbcHeuristicJustOne () 2373 { 2374 for (int i=0;i<numberHeuristics_;i++) 2375 delete heuristic_[i]; 2376 delete [] heuristic_; 2377 delete [] probabilities_; 2378 } 2379 2380 // Clone 2381 CbcHeuristicJustOne * 2382 CbcHeuristicJustOne::clone() const 2383 { 2384 return new CbcHeuristicJustOne(*this); 2385 } 2386 2387 // Create C++ lines to get to current state 2388 void 2389 CbcHeuristicJustOne::generateCpp( FILE * fp) 2390 { 2391 CbcHeuristicJustOne other; 2392 fprintf(fp,"0#include \"CbcHeuristicJustOne.hpp\"\n"); 2393 fprintf(fp,"3 CbcHeuristicJustOne heuristicJustOne(*cbcModel);\n"); 2394 CbcHeuristic::generateCpp(fp,"heuristicJustOne"); 2395 fprintf(fp,"3 cbcModel->addHeuristic(&heuristicJustOne);\n"); 2396 } 2397 2398 // Copy constructor 2399 CbcHeuristicJustOne::CbcHeuristicJustOne(const CbcHeuristicJustOne & rhs) 2400 : 2401 CbcHeuristic(rhs), 2402 probabilities_(NULL), 2403 heuristic_(NULL), 2404 numberHeuristics_(rhs.numberHeuristics_) 2405 { 2406 if (numberHeuristics_) { 2407 probabilities_ = CoinCopyOfArray(rhs.probabilities_,numberHeuristics_); 2408 heuristic_ = new CbcHeuristic * [numberHeuristics_]; 2409 for (int i=0;i<numberHeuristics_;i++) 2410 heuristic_[i]=rhs.heuristic_[i]->clone(); 2411 } 2412 } 2413 2414 // Assignment operator 2415 CbcHeuristicJustOne & 2416 CbcHeuristicJustOne::operator=( const CbcHeuristicJustOne& rhs) 2417 { 2418 if (this!=&rhs) { 2419 CbcHeuristic::operator=(rhs); 2420 for (int i=0;i<numberHeuristics_;i++) 2421 delete heuristic_[i]; 2422 delete [] heuristic_; 2423 delete [] probabilities_; 2424 probabilities_=NULL; 2425 heuristic_ = NULL; 2426 numberHeuristics_=rhs.numberHeuristics_; 2427 if (numberHeuristics_) { 2428 probabilities_ = CoinCopyOfArray(rhs.probabilities_,numberHeuristics_); 2429 heuristic_ = new CbcHeuristic * [numberHeuristics_]; 2430 for (int i=0;i<numberHeuristics_;i++) 2431 heuristic_[i]=rhs.heuristic_[i]->clone(); 2432 } 2433 } 2434 return *this; 2435 } 2436 // Sets value of solution 2437 // Returns 1 if solution, 0 if not 2438 int 2439 CbcHeuristicJustOne::solution(double & solutionValue, 2440 double * betterSolution) 2441 { 2442 #ifdef DIVE_DEBUG 2443 std::cout<<"solutionValue = "<<solutionValue<<std::endl; 2444 #endif 2445 ++numCouldRun_; 2446 2447 // test if the heuristic can run 2448 if(!shouldHeurRun_randomChoice()||!numberHeuristics_) 2449 return 0; 2450 double randomNumber = randomNumberGenerator_.randomDouble(); 2451 int i; 2452 for (i=0;i<numberHeuristics_;i++) { 2453 if (randomNumber<probabilities_[i]) 2454 break; 2455 } 2456 assert (i<numberHeuristics_); 2457 int returnCode; 2458 //model_->unsetDivingHasRun(); 2459 #ifdef COIN_DEVELOP 2460 printf("JustOne running %s\n", 2461 heuristic_[i]->heuristicName()); 2462 #endif 2463 returnCode = heuristic_[i]->solution(solutionValue,betterSolution); 2464 #ifdef COIN_DEVELOP 2465 if (returnCode) 2466 printf("JustOne running %s found solution\n", 2467 heuristic_[i]->heuristicName()); 2468 #endif 2469 return returnCode; 2470 } 2471 // Resets stuff if model changes 2472 void 2473 CbcHeuristicJustOne::resetModel(CbcModel * model) 2474 { 2475 CbcHeuristic::resetModel(model); 2476 for (int i=0;i<numberHeuristics_;i++) 2477 heuristic_[i]->resetModel(model); 2478 } 2479 // update model (This is needed if cliques update matrix etc) 2480 void 2481 CbcHeuristicJustOne::setModel(CbcModel * model) 2482 { 2483 CbcHeuristic::setModel(model); 2484 for (int i=0;i<numberHeuristics_;i++) 2485 heuristic_[i]->setModel(model); 2486 } 2487 // Validate model i.e. sets when_ to 0 if necessary (may be NULL) 2488 void 2489 CbcHeuristicJustOne::validate() 2490 { 2491 CbcHeuristic::validate(); 2492 for (int i=0;i<numberHeuristics_;i++) 2493 heuristic_[i]->validate(); 2494 } 2495 // Adds an heuristic with probability 2496 void 2497 CbcHeuristicJustOne::addHeuristic(const CbcHeuristic * heuristic, double probability) 2498 { 2499 CbcHeuristic * thisOne = heuristic->clone(); 2500 thisOne->setWhen(-999); 2501 CbcHeuristic ** tempH = CoinCopyOfArrayPartial(heuristic_,numberHeuristics_+1, 2502 numberHeuristics_); 2503 delete [] heuristic_; 2504 heuristic_ = tempH; 2505 heuristic_[numberHeuristics_]=thisOne; 2506 double * tempP = CoinCopyOfArrayPartial(probabilities_,numberHeuristics_+1, 2507 numberHeuristics_); 2508 delete [] probabilities_; 2509 probabilities_ = tempP; 2510 probabilities_[numberHeuristics_]=probability; 2511 numberHeuristics_++; 2512 } 2513 // Normalize probabilities 2514 void 2515 CbcHeuristicJustOne::normalizeProbabilities() 2516 { 2517 double sum=0.0; 2518 for (int i=0;i<numberHeuristics_;i++) 2519 sum += probabilities_[i]; 2520 double multiplier = 1.0/sum; 2521 sum=0.0; 2522 for (int i=0;i<numberHeuristics_;i++) { 2523 sum += probabilities_[i]; 2524 probabilities_[i] = sum*multiplier; 2525 } 2526 assert (fabs(probabilities_[numberHeuristics_-1]-1.0)<1.0e-5); 2527 probabilities_[numberHeuristics_-1] = 1.000001; 2528 } -
trunk/Cbc/src/CbcHeuristic.hpp
r940 r961 454 454 }; 455 455 456 /** Just One class - this chooses one at random 457 */ 458 459 class CbcHeuristicJustOne : public CbcHeuristic { 460 public: 461 462 // Default Constructor 463 CbcHeuristicJustOne (); 464 465 // Constructor with model - assumed before cuts 466 CbcHeuristicJustOne (CbcModel & model); 467 468 // Copy constructor 469 CbcHeuristicJustOne ( const CbcHeuristicJustOne &); 470 471 // Destructor 472 ~CbcHeuristicJustOne (); 473 474 /// Clone 475 virtual CbcHeuristicJustOne * clone() const; 476 477 /// Assignment operator 478 CbcHeuristicJustOne & operator=(const CbcHeuristicJustOne& rhs); 479 480 /// Create C++ lines to get to current state 481 virtual void generateCpp( FILE * fp) ; 482 483 /** returns 0 if no solution, 1 if valid solution 484 with better objective value than one passed in 485 Sets solution values if good, sets objective value (only if good) 486 This is called after cuts have been added - so can not add cuts 487 This does Fractional Diving 488 */ 489 virtual int solution(double & objectiveValue, 490 double * newSolution); 491 /// Resets stuff if model changes 492 virtual void resetModel(CbcModel * model); 493 494 /// update model (This is needed if cliques update matrix etc) 495 virtual void setModel(CbcModel * model); 496 /// Selects the next variable to branch on 497 /** Returns true if all the fractional variables can be trivially 498 rounded. Returns false, if there is at least one fractional variable 499 that is not trivially roundable. In this case, the bestColumn 500 returned will not be trivially roundable. 501 This is dummy as never called 502 */ 503 virtual bool selectVariableToBranch(OsiSolverInterface* solver, 504 const double* newSolution, 505 int& bestColumn, 506 int& bestRound) 507 { return true;} 508 /// Validate model i.e. sets when_ to 0 if necessary (may be NULL) 509 virtual void validate(); 510 /// Adds an heuristic with probability 511 void addHeuristic(const CbcHeuristic * heuristic, double probability); 512 /// Normalize probabilities 513 void normalizeProbabilities(); 514 protected: 515 // Data 516 517 // Probability of running a heuristic 518 double * probabilities_; 519 520 // Heuristics 521 CbcHeuristic ** heuristic_; 522 523 // Number of heuristics 524 int numberHeuristics_; 525 526 }; 527 456 528 #endif -
trunk/Cbc/src/CbcHeuristicDive.cpp
r955 r961 168 168 } 169 169 170 // See if div e fractionalwill give better solution170 // See if diving will give better solution 171 171 // Sets value of solution 172 172 // Returns 1 if solution, 0 if not … … 585 585 if (model_&&when()<10) { 586 586 if (model_->numberIntegers()!= 587 model_->numberObjects()) 587 model_->numberObjects()&&(model_->numberObjects()|| 588 (model_->specialOptions()&1024)==0)) 588 589 setWhen(0); 589 590 } … … 744 745 745 746 { 746 //return 0; //temp747 return 0; // temp 747 748 #if 0 748 749 if(!solverCharacteristics_->reducedCostsAccurate()) -
trunk/Cbc/src/CbcHeuristicDive.hpp
r944 r961 119 119 120 120 }; 121 122 121 #endif -
trunk/Cbc/src/CbcHeuristicFPump.cpp
r955 r961 194 194 double * betterSolution) 195 195 { 196 numCouldRun_++; 196 197 double incomingObjective = solutionValue; 197 198 #define LEN_PRINT 200 … … 283 284 return 0; 284 285 } 286 numRuns_++; 285 287 if (cutoff<1.0e50&&false) { 286 288 // Fix on djs -
trunk/Cbc/src/CbcHeuristicGreedy.cpp
r954 r961 104 104 double * betterSolution) 105 105 { 106 numCouldRun_++; 106 107 if (!model_) 107 108 return 0; … … 136 137 return 0; // switched off 137 138 139 numRuns_++; 138 140 assert (numberRows==matrix_.getNumRows()); 139 141 int iRow, iColumn; … … 506 508 double * betterSolution) 507 509 { 510 numCouldRun_++; 508 511 if (!model_) 509 512 return 0; … … 538 541 if (!numberRows) 539 542 return 0; // switched off 543 numRuns_++; 540 544 541 545 assert (numberRows==matrix_.getNumRows()); -
trunk/Cbc/src/CbcHeuristicLocal.cpp
r904 r961 127 127 const int * keep) 128 128 { 129 numCouldRun_++; 129 130 // See if to do 130 131 if (!when()||(when()==1&&model_->phase()!=1)) … … 176 177 { 177 178 179 numCouldRun_++; 178 180 if (numberSolutions_==model_->getSolutionCount()) 179 181 return 0; … … 203 205 double newSolutionValue = model_->getObjValue()*direction; 204 206 int returnCode = 0; 205 207 numRuns_++; 206 208 // Column copy 207 209 const double * element = matrix_.getElements(); -
trunk/Cbc/src/CbcHeuristicRINS.cpp
r904 r961 137 137 double * betterSolution) 138 138 { 139 numCouldRun_++; 139 140 int returnCode=0; 140 141 const double * bestSolution = model_->bestSolution(); … … 211 212 if (returnCode<0) 212 213 returnCode=0; // returned on size 214 else 215 numRuns_++; 213 216 if ((returnCode&1)!=0) 214 217 numberSuccesses_++; … … 315 318 int numberFixed=0; 316 319 int numberTightened=0; 320 int numberAtBound=0; 317 321 318 322 for (i=0;i<numberIntegers;i++) { … … 325 329 if (fabs(value-floor(value+0.5))<1.0e-8) { 326 330 value = floor(value+0.5); 331 if (value==lower||value==upper) 332 numberAtBound++; 327 333 newSolver->setColLower(iColumn,value); 328 334 newSolver->setColUpper(iColumn,value); … … 346 352 // could add cut 347 353 returnCode &= ~2; 348 //printf("could add cut with %d elements (if all 0-1)\n",nFix); 354 #ifdef COIN_DEVELOP 355 if (!numberTightened&&numberFixed==numberAtBound) 356 printf("could add cut with %d elements\n",numberFixed); 357 #endif 349 358 } else { 350 359 //printf("\n"); -
trunk/Cbc/src/CbcModel.cpp
r955 r961 1513 1513 OsiObject ** saveObjects=NULL; 1514 1514 maximumRows_ = numberRowsAtContinuous_; 1515 currentDepth_=0; 1515 1516 workingBasis_.resize(maximumRows_,numberColumns); 1516 1517 /* … … 1667 1668 // Save copy of solver 1668 1669 OsiSolverInterface * saveSolver = NULL; 1669 if (!parentModel_&&(specialOptions_& 512)!=0)1670 if (!parentModel_&&(specialOptions_&(512+2048))!=0) 1670 1671 saveSolver = solver_->clone(); 1672 if (!parentModel_&&(specialOptions_&2048)!=0) { 1673 // See if worth trying reduction 1674 bool tryNewSearch=solverCharacteristics_->reducedCostsAccurate(); 1675 int numberColumns = getNumCols(); 1676 if (tryNewSearch) { 1677 double cutoff = getCutoff() ; 1678 saveSolver->resolve(); 1679 double direction = saveSolver->getObjSense() ; 1680 double gap = cutoff - saveSolver->getObjValue()*direction ; 1681 double tolerance; 1682 saveSolver->getDblParam(OsiDualTolerance,tolerance) ; 1683 if (gap<=0.0) 1684 gap = tolerance; 1685 gap += 100.0*tolerance; 1686 double integerTolerance = getDblParam(CbcIntegerTolerance) ; 1687 1688 const double *lower = saveSolver->getColLower() ; 1689 const double *upper = saveSolver->getColUpper() ; 1690 const double *solution = saveSolver->getColSolution() ; 1691 const double *reducedCost = saveSolver->getReducedCost() ; 1692 1693 int numberFixed = 0 ; 1694 int numberFixed2=0; 1695 for (int i = 0 ; i < numberIntegers_ ; i++) { 1696 int iColumn = integerVariable_[i] ; 1697 double djValue = direction*reducedCost[iColumn] ; 1698 if (upper[iColumn]-lower[iColumn] > integerTolerance) { 1699 if (solution[iColumn] < lower[iColumn]+integerTolerance && djValue > gap) { 1700 saveSolver->setColUpper(iColumn,lower[iColumn]) ; 1701 numberFixed++ ; 1702 } else if (solution[iColumn] > upper[iColumn]-integerTolerance && -djValue > gap) { 1703 saveSolver->setColLower(iColumn,upper[iColumn]) ; 1704 numberFixed++ ; 1705 } 1706 } else { 1707 numberFixed2++; 1708 } 1709 } 1710 #ifdef COIN_DEVELOP 1711 if ((specialOptions_&1)!=0) { 1712 const OsiRowCutDebugger *debugger = saveSolver->getRowCutDebugger() ; 1713 if (debugger) { 1714 printf("Contains optimal\n") ; 1715 saveSolver->writeMps("reduced"); 1716 } else { 1717 abort(); 1718 } 1719 } 1720 printf("Restart could fix %d integers (%d already fixed)\n", 1721 numberFixed+numberFixed2,numberFixed2); 1722 #endif 1723 numberFixed += numberFixed2; 1724 if (numberFixed*20<numberColumns) 1725 tryNewSearch=false; 1726 } 1727 if (tryNewSearch) { 1728 // back to solver without cuts? 1729 #if 0 1730 OsiSolverInterface * solver2 = continuousSolver_->clone(); 1731 #else 1732 OsiSolverInterface * solver2 = saveSolver->clone(); 1733 #endif 1734 const double *lower = saveSolver->getColLower() ; 1735 const double *upper = saveSolver->getColUpper() ; 1736 for (int i = 0 ; i < numberIntegers_ ; i++) { 1737 int iColumn = integerVariable_[i] ; 1738 solver2->setColLower(iColumn,lower[iColumn]); 1739 solver2->setColUpper(iColumn,upper[iColumn]); 1740 } 1741 // swap 1742 delete saveSolver; 1743 saveSolver=solver2; 1744 double * newSolution = new double[numberColumns]; 1745 double objectiveValue=cutoff; 1746 CbcSerendipity heuristic(*this); 1747 if (bestSolution_) 1748 heuristic.setInputSolution(bestSolution_,bestObjective_); 1749 heuristic.setFractionSmall(0.9); 1750 heuristic.setFeasibilityPumpOptions(1008013); 1751 // Use numberNodes to say how many are original rows 1752 heuristic.setNumberNodes(continuousSolver_->getNumRows()); 1753 if (continuousSolver_->getNumRows()< 1754 solver_->getNumRows()) 1755 printf("%d rows added ZZZZZ\n", 1756 solver_->getNumRows()-continuousSolver_->getNumRows()); 1757 int returnCode= heuristic.smallBranchAndBound(saveSolver, 1758 -1,newSolution, 1759 objectiveValue, 1760 cutoff,"Reduce"); 1761 if (returnCode==-1) { 1762 #ifdef COIN_DEVELOP 1763 printf("Restart - not small enough to do search after fixing\n"); 1764 #endif 1765 delete [] newSolution; 1766 } else { 1767 assert (returnCode>=0); 1768 if ((returnCode&1)!=0) { 1769 // increment number of solutions so other heuristics can test 1770 numberSolutions_++; 1771 numberHeuristicSolutions_++; 1772 lastHeuristic_ = NULL; 1773 setBestSolution(CBC_ROUNDING,objectiveValue,newSolution) ; 1774 } 1775 delete [] newSolution; 1776 feasible=false; // stop search 1777 } 1778 } 1779 } 1671 1780 /* 1672 1781 We've taken the continuous relaxation as far as we can. Time to branch. … … 3862 3971 maximumWhich_(1000), 3863 3972 maximumRows_(0), 3973 currentDepth_(0), 3864 3974 whichGenerator_(NULL), 3865 3975 maximumStatistics_(0), … … 4007 4117 maximumWhich_(1000), 4008 4118 maximumRows_(0), 4119 currentDepth_(0), 4009 4120 whichGenerator_(NULL), 4010 4121 maximumStatistics_(0), … … 4238 4349 maximumWhich_(rhs.maximumWhich_), 4239 4350 maximumRows_(0), 4351 currentDepth_(0), 4240 4352 whichGenerator_(NULL), 4241 4353 maximumStatistics_(0), … … 4577 4689 whichGenerator_ = CoinCopyOfArray(rhs.whichGenerator_,maximumWhich_); 4578 4690 maximumRows_=0; 4691 currentDepth_ = 0; 4579 4692 workingBasis_ = CoinWarmStartBasis(); 4580 4693 for (i=0;i<maximumStatistics_;i++) … … 5304 5417 printf("Starting bounds at node %d\n",numberNodes_); 5305 5418 #endif 5419 currentDepth_=nNode; 5306 5420 while (nNode) { 5307 5421 --nNode; -
trunk/Cbc/src/CbcModel.hpp
r954 r961 736 736 inline int problemType() const 737 737 { return problemType_;} 738 /// Current depth 739 inline int currentDepth() const 740 { return currentDepth_;} 738 741 739 742 /// Set how often to scan global cuts … … 2111 2114 /// Maximum number of rows 2112 2115 int maximumRows_; 2116 /// Current depth 2117 int currentDepth_; 2113 2118 /// Work basis for temporary use 2114 2119 CoinWarmStartBasis workingBasis_; -
trunk/Cbc/src/CbcSolver.cpp
r955 r961 729 729 int numberColumns = babModel_->getNumCols(); 730 730 if (babModel_->bestSolution()) 731 model_.setBestSolution(babModel_->bestSolution(),numberColumns,babModel_->get ObjValue());731 model_.setBestSolution(babModel_->bestSolution(),numberColumns,babModel_->getMinimizationObjValue()); 732 732 OsiClpSolverInterface * clpSolver1 = dynamic_cast< OsiClpSolverInterface*> (babModel_->solver()); 733 733 ClpSimplex * lpSolver1 = clpSolver1->getModelPtr(); … … 3234 3234 int useRINS = parameters_[whichParam(RINS,numberParameters_,parameters_)].currentOptionAsInteger(); 3235 3235 int useRENS = parameters_[whichParam(RENS,numberParameters_,parameters_)].currentOptionAsInteger(); 3236 int useDIVING = parameters_[whichParam(DIVINGA,numberParameters_,parameters_)].currentOptionAsInteger();3236 int useDIVING2 = parameters_[whichParam(DIVINGS,numberParameters_,parameters_)].currentOptionAsInteger(); 3237 3237 // FPump done first as it only works if no solution 3238 3238 int kType = (type<3) ? type : 1; … … 3364 3364 heuristic6.setFractionSmall(0.5); 3365 3365 heuristic6.setFeasibilityPumpOptions(1008003); 3366 int nodes []={-2, -1,200,1000};3366 int nodes []={-2,0,200,1000,10000}; 3367 3367 heuristic6.setNumberNodes(nodes[useRENS]); 3368 3368 model->addHeuristic(&heuristic6) ; … … 3380 3380 anyToDo=true; 3381 3381 } 3382 // change later?3382 int useDIVING=0; 3383 3383 { 3384 int useDiving2=0; 3385 useDiving2 |= 1*parameters_[whichParam(DIVINGV,numberParameters_,parameters_)].currentOptionAsInteger(); 3386 useDiving2 |= 2*parameters_[whichParam(DIVINGG,numberParameters_,parameters_)].currentOptionAsInteger(); 3387 useDiving2 |= 4*parameters_[whichParam(DIVINGF,numberParameters_,parameters_)].currentOptionAsInteger(); 3388 useDiving2 |= 8*parameters_[whichParam(DIVINGC,numberParameters_,parameters_)].currentOptionAsInteger(); 3389 useDiving2 |= 16*parameters_[whichParam(DIVINGL,numberParameters_,parameters_)].currentOptionAsInteger(); 3390 useDiving2 |= 32*parameters_[whichParam(DIVINGP,numberParameters_,parameters_)].currentOptionAsInteger(); 3391 if (useDiving2) 3392 useDIVING=useDiving2; 3384 useDIVING |= 1*parameters_[whichParam(DIVINGV,numberParameters_,parameters_)].currentOptionAsInteger(); 3385 useDIVING |= 2*parameters_[whichParam(DIVINGG,numberParameters_,parameters_)].currentOptionAsInteger(); 3386 useDIVING |= 4*parameters_[whichParam(DIVINGF,numberParameters_,parameters_)].currentOptionAsInteger(); 3387 useDIVING |= 8*parameters_[whichParam(DIVINGC,numberParameters_,parameters_)].currentOptionAsInteger(); 3388 useDIVING |= 16*parameters_[whichParam(DIVINGL,numberParameters_,parameters_)].currentOptionAsInteger(); 3389 useDIVING |= 32*parameters_[whichParam(DIVINGP,numberParameters_,parameters_)].currentOptionAsInteger(); 3393 3390 } 3391 if (useDIVING2>=kType) { 3392 int diveOptions=parameters_[whichParam(DIVEOPT,numberParameters_,parameters_)].intValue(); 3393 if (diveOptions<0||diveOptions>10) 3394 diveOptions=2; 3395 CbcHeuristicJustOne heuristicJustOne(*model); 3396 heuristicJustOne.setHeuristicName("DiveAny"); 3397 heuristicJustOne.setWhen(diveOptions); 3398 // add in others 3399 CbcHeuristicDiveCoefficient heuristicDC(*model); 3400 heuristicDC.setHeuristicName("DiveCoefficient"); 3401 heuristicJustOne.addHeuristic(&heuristicDC,1.0) ; 3402 CbcHeuristicDiveFractional heuristicDF(*model); 3403 heuristicDF.setHeuristicName("DiveFractional"); 3404 heuristicJustOne.addHeuristic(&heuristicDF,1.0) ; 3405 CbcHeuristicDiveGuided heuristicDG(*model); 3406 heuristicDG.setHeuristicName("DiveGuided"); 3407 heuristicJustOne.addHeuristic(&heuristicDG,1.0) ; 3408 CbcHeuristicDiveLineSearch heuristicDL(*model); 3409 heuristicDL.setHeuristicName("DiveLineSearch"); 3410 heuristicJustOne.addHeuristic(&heuristicDL,1.0) ; 3411 CbcHeuristicDivePseudoCost heuristicDP(*model); 3412 heuristicDP.setHeuristicName("DivePseudoCost"); 3413 heuristicJustOne.addHeuristic(&heuristicDP,1.0) ; 3414 CbcHeuristicDiveVectorLength heuristicDV(*model); 3415 heuristicDV.setHeuristicName("DiveVectorLength"); 3416 heuristicJustOne.addHeuristic(&heuristicDV,1.0) ; 3417 // Now normalize probabilities 3418 heuristicJustOne.normalizeProbabilities(); 3419 model->addHeuristic(&heuristicJustOne) ; 3420 } 3421 3394 3422 if (useDIVING>=kType) { 3395 3423 int diveOptions=parameters_[whichParam(DIVEOPT,numberParameters_,parameters_)].intValue(); 3396 if (diveOptions< 3||diveOptions>6)3424 if (diveOptions<0||diveOptions>10) 3397 3425 diveOptions=2; 3398 3426 if ((useDIVING&1)!=0) { … … 4418 4446 <<CoinMessageEol; 4419 4447 generalMessageHandler->message(CLP_GENERAL,generalMessages) 4448 <<"Possible restart after 100 nodes if can fix many" 4449 <<CoinMessageEol; 4450 generalMessageHandler->message(CLP_GENERAL,generalMessages) 4420 4451 <<"extra options - -diving C -diveopt 3 -rins on -tune 6 -probing on -passf 30!" 4421 4452 <<CoinMessageEol; … … 4431 4462 parameters_[iParam].setIntValue(6); 4432 4463 tunePreProcess=6; 4433 iParam = whichParam(DIVING A,numberParameters_,parameters_);4434 parameters_[iParam].setCurrentOption(" C");4464 iParam = whichParam(DIVINGC,numberParameters_,parameters_); 4465 parameters_[iParam].setCurrentOption("on"); 4435 4466 iParam = whichParam(RINS,numberParameters_,parameters_); 4436 4467 parameters_[iParam].setCurrentOption("on"); … … 4685 4716 break; 4686 4717 case GREEDY: 4687 case DIVINGA: 4718 case DIVINGS: 4719 case DIVINGC: 4720 case DIVINGF: 4721 case DIVINGG: 4722 case DIVINGL: 4723 case DIVINGP: 4724 case DIVINGV: 4688 4725 case COMBINE: 4689 4726 case LOCALTREE: … … 6152 6189 probingGen.setMaxProbeRoot(123); 6153 6190 probingGen.setMaxProbe(123); 6191 probingGen.setMaxLookRoot(20); 6154 6192 if (probingAction==5||probingAction==7) 6155 6193 probingGen.setRowCuts(-3); // strengthening etc just at root 6156 6194 if (probingAction==6||probingAction==7) { 6157 6195 // Number of unsatisfied variables to look at 6158 probingGen.setMaxProbe (1000);6159 probingGen.setMaxProbe Root(1000);6196 probingGen.setMaxProbeRoot(babModel_->solver()->getNumCols()); 6197 probingGen.setMaxProbe(babModel_->solver()->getNumCols()); 6160 6198 // How far to follow the consequences 6161 6199 probingGen.setMaxLook(50); … … 6211 6249 switches[numberGenerators++]=1; 6212 6250 } 6213 if (twomirAction&&!complicatedInteger) { 6251 if (twomirAction&&(complicatedInteger!=1|| 6252 (twomirAction==1||twomirAction>=4))) { 6253 // try larger limit 6254 int numberColumns = babModel_->getNumCols(); 6255 if (twomirAction==5) { 6256 twomirAction=4; 6257 twomirGen.setMaxElements(numberColumns); 6258 } else if (numberColumns>5000&&twomirAction==4) { 6259 twomirGen.setMaxElements(2000); 6260 } 6214 6261 babModel_->addCutGenerator(&twomirGen,translate[twomirAction],"TwoMirCuts"); 6215 6262 switches[numberGenerators++]=1; … … 6333 6380 // try reduced model 6334 6381 babModel_->setSpecialOptions(babModel_->specialOptions()|512); 6382 } else if (parameters_[whichParam(EXPERIMENT,numberParameters_, 6383 parameters_)].intValue()==3) { 6384 // try reduced model at root 6385 babModel_->setSpecialOptions(babModel_->specialOptions()|2048); 6335 6386 } 6336 6387 { … … 6355 6406 lpSolver->setSpecialOptions(lpSolver->specialOptions()|256); 6356 6407 } 6357 if (((moreMipOptions+1)%1000000)!=0) 6358 babModel_->setSearchStrategy(moreMipOptions%1000000); 6408 if (moreMipOptions<10000&&moreMipOptions) { 6409 if (((moreMipOptions+1)%1000000)!=0) 6410 babModel_->setSearchStrategy(moreMipOptions%1000000); 6411 } else if (moreMipOptions<100000) { 6412 // try reduced model 6413 babModel_->setSpecialOptions(babModel_->specialOptions()|512); 6414 } 6359 6415 // go faster stripes 6360 6416 if( moreMipOptions >=999999) { … … 6501 6557 } 6502 6558 babModel_->setNumberObjects(n); 6559 numberOldObjects=n; 6503 6560 babModel_->zapIntegerInformation(); 6504 6561 } … … 7335 7392 int extra1 = parameters_[whichParam(EXTRA1,numberParameters_,parameters_)].intValue(); 7336 7393 if (extra1!=-1) { 7337 if (extra1<1 0000) {7394 if (extra1<19000) { 7338 7395 babModel_->setSearchStrategy(extra1); 7339 7396 printf("XXXXX searchStrategy %d\n",extra1); 7340 7397 } else { 7341 babModel_->setNumberAnalyzeIterations(extra1); 7398 int n=extra1-20000; 7399 if (!n) 7400 n--; 7401 babModel_->setNumberAnalyzeIterations(n); 7342 7402 printf("XXXXX analyze %d\n",extra1); 7343 7403 } … … 7399 7459 #endif 7400 7460 #ifdef COIN_DEVELOP 7461 #if 1 7462 { 7463 int numberColumns = babModel_->getNumCols(); 7464 const double * solution = babModel_->bestSolution(); 7465 if (solution) { 7466 for (int i=0;i<numberColumns;i++) { 7467 if (solution[i]) 7468 printf("SOL %d %.18g\n",i,solution[i]); 7469 } 7470 } 7471 } 7472 #endif 7401 7473 void printHistory(const char * file); 7402 7474 printHistory("branch.log"); … … 7465 7537 stuff[3]=parameters_[whichParam(DEXTRA4,numberParameters_,parameters_)].doubleValue(); 7466 7538 stuff[4]=parameters_[whichParam(DENSE,numberParameters_,parameters_)].intValue(); 7467 stuff[5]=parameters_[whichParam(EXTRA 2,numberParameters_,parameters_)].intValue();7539 stuff[5]=parameters_[whichParam(EXTRA1,numberParameters_,parameters_)].intValue(); 7468 7540 stuff[6]=parameters_[whichParam(EXTRA3,numberParameters_,parameters_)].intValue(); 7469 7541 stuff[7]=parameters_[whichParam(EXTRA4,numberParameters_,parameters_)].intValue(); … … 7527 7599 for (iGenerator=0;iGenerator<babModel_->numberHeuristics();iGenerator++) { 7528 7600 CbcHeuristic * heuristic = babModel_->heuristic(iGenerator); 7529 // Need to bring others inline 7530 sprintf(generalPrint,"%s was tried %d times out of %d and created %d solutions\n", 7531 heuristic->heuristicName(), 7532 heuristic->numRuns(), 7533 heuristic->numCouldRun(), 7534 heuristic->numberSolutionsFound()); 7535 generalMessageHandler->message(CLP_GENERAL,generalMessages) 7536 << generalPrint 7537 <<CoinMessageEol; 7538 } 7601 if (heuristic->numRuns()) { 7602 // Need to bring others inline 7603 sprintf(generalPrint,"%s was tried %d times out of %d and created %d solutions\n", 7604 heuristic->heuristicName(), 7605 heuristic->numRuns(), 7606 heuristic->numCouldRun(), 7607 heuristic->numberSolutionsFound()); 7608 generalMessageHandler->message(CLP_GENERAL,generalMessages) 7609 << generalPrint 7610 <<CoinMessageEol; 7611 } 7612 } 7539 7613 #endif 7540 7614 } … … 7564 7638 #if NEW_STYLE_SOLVER==0 7565 7639 if (returnMode==1) 7566 model_.setBestSolution(bestSolution,n,babModel_->get ObjValue());7567 #endif 7568 babModel_->setBestSolution(bestSolution,n,babModel_->get ObjValue());7640 model_.setBestSolution(bestSolution,n,babModel_->getMinimizationObjValue()); 7641 #endif 7642 babModel_->setBestSolution(bestSolution,n,babModel_->getMinimizationObjValue()); 7569 7643 #if NEW_STYLE_SOLVER==0 7570 7644 // and put back in very original solver … … 9553 9627 OsiClpSolverInterface * clpSolver = dynamic_cast< OsiClpSolverInterface*> (model_.solver()); 9554 9628 ClpSimplex * lpSolver = clpSolver->getModelPtr(); 9555 if (lpSolver0!=lpSolver )9629 if (lpSolver0!=lpSolver&&lpSolver!=originalSolver->getModelPtr()) 9556 9630 lpSolver->moveInfo(*lpSolver0); 9557 9631 //babModel_->setModelOwnsSolver(false); -
trunk/Cbc/src/unitTestClp.cpp
r955 r961 81 81 double * stuff) 82 82 { 83 // Stop Windows popup 84 WindowsErrorPopupBlocker(); 83 85 unsigned int m ; 84 86
Note: See TracChangeset
for help on using the changeset viewer.