- Timestamp:
- Aug 14, 2007 6:36:36 AM (12 years ago)
- Location:
- trunk/Cbc/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cbc/src/CbcHeuristicFPump.cpp
r747 r750 491 491 if (matched) break; 492 492 } 493 int numberPerturbed=0; 493 494 if (matched || numberPasses%100 == 0) { 494 495 // perturbation 495 496 sprintf(pumpPrint+strlen(pumpPrint)," perturbation applied"); 496 497 newLineNeeded=true; 498 double factorX[10]={0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0}; 499 double factor=1.0; 500 double target=-1.0; 501 double * randomX = new double [numberIntegers]; 502 for (i=0;i<numberIntegers;i++) 503 randomX[i] = max(0.0,CoinDrand48()-0.3); 504 for (int k=0;k<10;k++) { 505 #ifdef COIN_DEVELOP 506 printf("kpass %d\n",k); 507 #endif 508 int numberX[10]={0,0,0,0,0,0,0,0,0,0}; 509 for (i=0;i<numberIntegers;i++) { 510 int iColumn = integerVariable[i]; 511 double value = randomX[i]; 512 double difference = fabs(solution[iColumn]-newSolution[iColumn]); 513 for (int j=0;j<10;j++) { 514 if (difference+value*factorX[j]>0.5) 515 numberX[j]++; 516 } 517 } 518 if (target<0.0) { 519 if (numberX[9]<=200) 520 break; // not very many changes 521 target=CoinMax(200.0,0.05*numberX[9]); 522 } 523 int iX=-1; 524 int iBand=-1; 525 for (i=0;i<10;i++) { 526 #ifdef COIN_DEVELOP 527 printf("** %d changed at %g\n",numberX[i],factorX[i]); 528 #endif 529 if (numberX[i]>=target&&numberX[i]<2.0*target&&iX<0) 530 iX=i; 531 if (iBand<0&&numberX[i]>target) { 532 iBand=i; 533 factor=factorX[i]; 534 } 535 } 536 if (iX>=0) { 537 factor=factorX[iX]; 538 break; 539 } else { 540 assert (iBand>=0); 541 double hi = factor; 542 double lo = (iBand>0) ? factorX[iBand-1] : 0.0; 543 double diff = (hi-lo)/9.0; 544 for (i=0;i<10;i++) { 545 factorX[i]=lo; 546 lo += diff; 547 } 548 } 549 } 497 550 for (i=0;i<numberIntegers;i++) { 498 551 int iColumn = integerVariable[i]; 499 double value = max(0.0,CoinDrand48()-0.3);552 double value = randomX[i]; 500 553 double difference = fabs(solution[iColumn]-newSolution[iColumn]); 501 if (difference+value>0.5) { 554 if (difference+value*factor>0.5) { 555 numberPerturbed++; 502 556 if (newSolution[iColumn]<lower[iColumn]+primalTolerance) { 503 557 newSolution[iColumn] += 1.0; … … 513 567 } 514 568 } 569 delete [] randomX; 515 570 } else { 516 571 for (j=NUMBER_OLD-1;j>0;j--) { … … 523 578 double offset=0.0; 524 579 double costValue = (1.0-scaleFactor)*solver->getObjSense(); 525 580 int numberChanged=0; 581 const double * oldObjective = solver->getObjCoefficients(); 526 582 for (i=0;i<numberColumns;i++) { 527 583 // below so we can keep original code and allow for objective … … 535 591 continue; 536 592 } 593 double newValue=0.0; 537 594 if (newSolution[iColumn]<lower[iColumn]+primalTolerance) { 538 solver->setObjCoeff(iColumn,costValue+scaleFactor*saveObjective[iColumn]);595 newValue = costValue+scaleFactor*saveObjective[iColumn]; 539 596 } else { 540 597 if (newSolution[iColumn]>upper[iColumn]-primalTolerance) { 541 solver->setObjCoeff(iColumn,-costValue+scaleFactor*saveObjective[iColumn]); 542 } else { 543 solver->setObjCoeff(iColumn,0.0); 544 } 545 } 598 newValue = -costValue+scaleFactor*saveObjective[iColumn]; 599 } 600 } 601 if (newValue!=oldObjective[iColumn]) 602 numberChanged++; 603 solver->setObjCoeff(iColumn,newValue); 546 604 offset += costValue*newSolution[iColumn]; 547 605 } … … 625 683 solver->setWarmStart(&dummy); 626 684 } 685 #ifdef COIN_DEVELOP 686 printf("%d perturbed out of %d columns (%d changed)\n",numberPerturbed,numberColumns,numberChanged); 687 #endif 688 bool takeHint; 689 OsiHintStrength strength; 690 solver->getHintParam(OsiDoDualInResolve,takeHint,strength); 691 if (numberPerturbed>numberColumns) 692 solver->setHintParam(OsiDoDualInResolve,true); // dual may be better 627 693 solver->resolve(); 694 solver->setHintParam(OsiDoDualInResolve,takeHint); 695 #ifdef COIN_DEVELOP 696 printf("took %d iterations\n",solver->getIterationCount()); 697 #endif 628 698 assert (solver->isProvenOptimal()); 629 699 // in case very dubious solver -
trunk/Cbc/src/CbcModel.cpp
r747 r750 940 940 */ 941 941 bestObjective_ = CoinMin(bestObjective_,1.0e50) ; 942 numberSolutions_ = 0 ; 943 stateOfSearch_=0; 944 numberHeuristicSolutions_ = 0 ; 942 if (!bestSolution_) { 943 numberSolutions_ = 0 ; 944 numberHeuristicSolutions_ = 0 ; 945 } 946 stateOfSearch_ = 0; 945 947 // Everything is minimization 946 948 { … … 1086 1088 numberDJFixed_=0.0; 1087 1089 // Do heuristics 1088 { 1089 double * newSolution = new double [numberColumns] ; 1090 double heuristicValue = getCutoff() ; 1091 int found = -1; // no solution found 1092 1093 currentPassNumber_ = 1; // so root heuristics will run 1094 int i; 1095 for (i = 0;i<numberHeuristics_;i++) { 1096 // see if heuristic will do anything 1097 double saveValue = heuristicValue ; 1098 int ifSol = heuristic_[i]->solution(heuristicValue, 1099 newSolution); 1100 if (ifSol>0) { 1101 // better solution found 1102 found = i ; 1103 incrementUsed(newSolution); 1104 // increment number of solutions so other heuristics can test 1105 numberSolutions_++; 1106 numberHeuristicSolutions_++; 1107 } else { 1108 heuristicValue = saveValue ; 1109 } 1110 } 1111 currentPassNumber_ = 0; 1112 /* 1113 Did any of the heuristics turn up a new solution? Record it before we free 1114 the vector. 1115 */ 1116 if (found >= 0) { 1117 // For compiler error on terra cluster! 1118 if (found<numberHeuristics_) 1119 lastHeuristic_ = heuristic_[found]; 1120 else 1121 lastHeuristic_ = heuristic_[0]; 1122 setBestSolution(CBC_ROUNDING,heuristicValue,newSolution) ; 1123 CbcTreeLocal * tree 1124 = dynamic_cast<CbcTreeLocal *> (tree_); 1125 if (tree) 1126 tree->passInSolution(bestSolution_,heuristicValue); 1127 for (i = 0;i<numberHeuristics_;i++) { 1128 // delete FPump 1129 CbcHeuristicFPump * pump 1130 = dynamic_cast<CbcHeuristicFPump *> (heuristic_[i]); 1131 if (pump) { 1132 delete pump; 1133 numberHeuristics_ --; 1134 for (int j=i;j<numberHeuristics_;j++) 1135 heuristic_[j] = heuristic_[j+1]; 1136 } 1137 } 1138 if (eventHandler) { 1139 if (!eventHandler->event(CbcEventHandler::solution)) { 1140 eventHappened_=true; // exit 1141 } 1142 } 1143 } 1144 delete [] newSolution ; 1145 } 1090 doHeuristicsAtRoot(); 1146 1091 statistics_ = NULL; 1147 1092 // Do on switch … … 9922 9867 memcpy(bestSolution_,solution,numberColumns*sizeof(double)); 9923 9868 } 9869 // Do heuristics at root 9870 void 9871 CbcModel::doHeuristicsAtRoot(bool deleteHeuristicsAfterwards) 9872 { 9873 int numberColumns = getNumCols() ; 9874 if (deleteHeuristicsAfterwards) { 9875 assert (!usedInSolution_); 9876 usedInSolution_ = new int [numberColumns]; 9877 CoinZeroN(usedInSolution_,numberColumns); 9878 } 9879 double * newSolution = new double [numberColumns] ; 9880 double heuristicValue = getCutoff() ; 9881 int found = -1; // no solution found 9882 CbcEventHandler *eventHandler = getEventHandler() ; 9883 if (eventHandler) 9884 eventHandler->setModel(this); 9885 9886 currentPassNumber_ = 1; // so root heuristics will run 9887 int i; 9888 for (i = 0;i<numberHeuristics_;i++) { 9889 // see if heuristic will do anything 9890 double saveValue = heuristicValue ; 9891 int ifSol = heuristic_[i]->solution(heuristicValue, 9892 newSolution); 9893 if (ifSol>0) { 9894 // better solution found 9895 found = i ; 9896 incrementUsed(newSolution); 9897 // increment number of solutions so other heuristics can test 9898 numberSolutions_++; 9899 numberHeuristicSolutions_++; 9900 } else { 9901 heuristicValue = saveValue ; 9902 } 9903 } 9904 currentPassNumber_ = 0; 9905 /* 9906 Did any of the heuristics turn up a new solution? Record it before we free 9907 the vector. 9908 */ 9909 if (found >= 0) { 9910 // For compiler error on terra cluster! 9911 if (found<numberHeuristics_) 9912 lastHeuristic_ = heuristic_[found]; 9913 else 9914 lastHeuristic_ = heuristic_[0]; 9915 setBestSolution(CBC_ROUNDING,heuristicValue,newSolution) ; 9916 CbcTreeLocal * tree 9917 = dynamic_cast<CbcTreeLocal *> (tree_); 9918 if (tree) 9919 tree->passInSolution(bestSolution_,heuristicValue); 9920 if (eventHandler) { 9921 if (!eventHandler->event(CbcEventHandler::solution)) { 9922 eventHappened_=true; // exit 9923 } 9924 } 9925 } 9926 if (!deleteHeuristicsAfterwards) { 9927 for (i = 0;i<numberHeuristics_;i++) { 9928 // delete FPump 9929 CbcHeuristicFPump * pump 9930 = dynamic_cast<CbcHeuristicFPump *> (heuristic_[i]); 9931 if (pump) { 9932 delete pump; 9933 numberHeuristics_ --; 9934 for (int j=i;j<numberHeuristics_;j++) 9935 heuristic_[j] = heuristic_[j+1]; 9936 } 9937 } 9938 } else { 9939 // delete all 9940 for (i = 0;i<numberHeuristics_;i++) 9941 delete heuristic_[i]; 9942 numberHeuristics_=0; 9943 delete [] heuristic_; 9944 heuristic_=NULL; 9945 delete [] usedInSolution_; 9946 usedInSolution_ = NULL; 9947 } 9948 delete [] newSolution ; 9949 } 9950 // Zap integer information in problem (may leave object info) 9951 void 9952 CbcModel::zapIntegerInformation(bool leaveObjects) 9953 { 9954 numberIntegers_ = 0; 9955 delete [] integerVariable_; 9956 integerVariable_ = NULL; 9957 if (!leaveObjects&&ownObjects_) { 9958 int i; 9959 for (i=0;i<numberObjects_;i++) 9960 delete object_[i]; 9961 delete [] object_; 9962 numberObjects_=0; 9963 object_=NULL; 9964 } 9965 } 9924 9966 // Create C++ lines to get to current state 9925 9967 void -
trunk/Cbc/src/CbcModel.hpp
r747 r750 1106 1106 /// Get number of heuristic solutions 1107 1107 inline int getNumberHeuristicSolutions() const { return numberHeuristicSolutions_;} 1108 /// Set number of heuristic solutions 1109 inline void setNumberHeuristicSolutions(int value) { numberHeuristicSolutions_=value;} 1108 1110 1109 1111 /// Set objective function sense (1 for min (default), -1 for max,) … … 1507 1509 { return continuousSolver_;} 1508 1510 1511 /// Create solver with continuous state 1512 inline void createContinuousSolver() 1513 { continuousSolver_ = solver_->clone();} 1514 /// Clear solver with continuous state 1515 inline void clearContinuousSolver() 1516 { delete continuousSolver_; continuousSolver_ = NULL;} 1517 1509 1518 /// A copy of the solver, taken at constructor or by saveReferenceSolver 1510 1519 inline OsiSolverInterface * referenceSolver() const … … 1619 1628 */ 1620 1629 void convertToDynamic(); 1630 /// Zap integer information in problem (may leave object info) 1631 void zapIntegerInformation(bool leaveObjects=true); 1621 1632 /// Use cliques for pseudocost information - return nonzero if infeasible 1622 1633 int cliquePseudoCosts(int doStatistics); 1623 1634 /// Fill in useful estimates 1624 1635 void pseudoShadow(double * down, double * up); 1625 1636 /// Do heuristics at root 1637 void doHeuristicsAtRoot(bool deleteHeuristicsAfterwards=false); 1626 1638 /// Get the hotstart solution 1627 1639 inline const double * hotstartSolution() const -
trunk/Cbc/src/CbcSolver.cpp
r747 r750 40 40 #include "OsiRowCutDebugger.hpp" 41 41 #include "OsiChooseVariable.hpp" 42 #include "OsiAuxInfo.hpp" 42 43 //#define USER_HAS_FAKE_CLP 43 44 //#define USER_HAS_FAKE_CBC … … 1431 1432 parameters[whichParam(COMBINE,numberParameters,parameters)].setCurrentOption("on"); 1432 1433 parameters[whichParam(RINS,numberParameters,parameters)].setCurrentOption("off"); 1434 parameters[whichParam(LOCALTREE,numberParameters,parameters)].setCurrentOption("off"); 1433 1435 parameters[whichParam(COSTSTRATEGY,numberParameters,parameters)].setCurrentOption("off"); 1434 1436 } 1437 /* 1 - add heuristics to model 1438 2 - do heuristics (and set cutoff and best solution) 1439 3 - for miplib test so skip some 1440 */ 1441 static int doHeuristics(CbcModel * model,int type) 1442 { 1443 bool anyToDo=false; 1444 int logLevel = parameters[whichParam(LOGLEVEL,numberParameters,parameters)].intValue(); 1445 int useFpump = parameters[whichParam(FPUMP,numberParameters,parameters)].currentOptionAsInteger(); 1446 int useRounding = parameters[whichParam(ROUNDING,numberParameters,parameters)].currentOptionAsInteger(); 1447 int useGreedy = parameters[whichParam(GREEDY,numberParameters,parameters)].currentOptionAsInteger(); 1448 int useCombine = parameters[whichParam(COMBINE,numberParameters,parameters)].currentOptionAsInteger(); 1449 int useRINS = parameters[whichParam(RINS,numberParameters,parameters)].currentOptionAsInteger(); 1450 // FPump done first as it only works if no solution 1451 int kType = (type<3) ? type : 1; 1452 if (useFpump>=kType) { 1453 anyToDo=true; 1454 CbcHeuristicFPump heuristic4(*model); 1455 heuristic4.setFractionSmall(0.6); 1456 heuristic4.setMaximumPasses(parameters[whichParam(FPUMPITS,numberParameters,parameters)].intValue()); 1457 int pumpTune=parameters[whichParam(FPUMPTUNE,numberParameters,parameters)].intValue(); 1458 if (pumpTune>0) { 1459 /* 1460 >=10000000 for using obj 1461 >=1000000 use as accumulate switch 1462 >=1000 use index+1 as number of large loops 1463 >=100 use 0.05 objvalue as increment 1464 >=10 use +0.1 objvalue for cutoff (add) 1465 1 == fix ints at bounds, 2 fix all integral ints, 3 and continuous at bounds 1466 4 and static continuous, 5 as 3 but no internal integers 1467 6 as 3 but all slack basis! 1468 */ 1469 double value = model->solver()->getObjSense()*model->solver()->getObjValue(); 1470 int w = pumpTune/10; 1471 int c = w % 10; 1472 w /= 10; 1473 int i = w % 10; 1474 w /= 10; 1475 int r = w; 1476 int accumulate = r/1000; 1477 r -= 1000*accumulate; 1478 if (accumulate>=10) { 1479 int which = accumulate/10; 1480 accumulate -= 10*which; 1481 which--; 1482 // weights and factors 1483 double weight[]={0.1,0.1,0.5,0.5,1.0,1.0,5.0,5.0}; 1484 double factor[] = {0.1,0.5,0.1,0.5,0.1,0.5,0.1,0.5}; 1485 heuristic4.setInitialWeight(weight[which]); 1486 heuristic4.setWeightFactor(factor[which]); 1487 } 1488 // fake cutoff 1489 if (logLevel>1) 1490 printf("Setting "); 1491 if (c) { 1492 double cutoff; 1493 model->solver()->getDblParam(OsiDualObjectiveLimit,cutoff); 1494 cutoff = CoinMin(cutoff,value + 0.1*fabs(value)*c); 1495 double dextra1 = parameters[whichParam(DEXTRA1,numberParameters,parameters)].doubleValue(); 1496 if (dextra1) 1497 cutoff=dextra1; 1498 heuristic4.setFakeCutoff(cutoff); 1499 if (logLevel>1) 1500 printf("fake cutoff of %g ",cutoff); 1501 } 1502 if (i||r) { 1503 // also set increment 1504 double increment = (0.01*i+0.005)*(fabs(value)+1.0e-12); 1505 double dextra2 = parameters[whichParam(DEXTRA2,numberParameters,parameters)].doubleValue(); 1506 if (dextra2) 1507 increment = dextra2; 1508 heuristic4.setAbsoluteIncrement(increment); 1509 heuristic4.setAccumulate(accumulate); 1510 heuristic4.setMaximumRetries(r+1); 1511 if (logLevel>1) { 1512 if (i) 1513 printf("increment of %g ",heuristic4.absoluteIncrement()); 1514 if (accumulate) 1515 printf("accumulate of %d ",accumulate); 1516 printf("%d retries ",r+2); 1517 } 1518 } 1519 pumpTune = pumpTune%100; 1520 if (logLevel>1) 1521 printf("and setting when to %d\n",pumpTune+10); 1522 if (pumpTune==6) 1523 pumpTune =13; 1524 heuristic4.setWhen(pumpTune+10); 1525 } 1526 heuristic4.setHeuristicName("feasibility pump"); 1527 model->addHeuristic(&heuristic4); 1528 } 1529 if (useRounding>=type) { 1530 CbcRounding heuristic1(*model); 1531 heuristic1.setHeuristicName("rounding"); 1532 model->addHeuristic(&heuristic1) ; 1533 anyToDo=true; 1534 } 1535 if (useCombine>=type) { 1536 CbcHeuristicLocal heuristic2(*model); 1537 heuristic2.setHeuristicName("combine solutions"); 1538 heuristic2.setFractionSmall(0.6); 1539 heuristic2.setSearchType(1); 1540 model->addHeuristic(&heuristic2); 1541 anyToDo=true; 1542 } 1543 if (useGreedy>=type) { 1544 CbcHeuristicGreedyCover heuristic3(*model); 1545 heuristic3.setHeuristicName("greedy cover"); 1546 CbcHeuristicGreedyEquality heuristic3a(*model); 1547 heuristic3a.setHeuristicName("greedy equality"); 1548 model->addHeuristic(&heuristic3); 1549 model->addHeuristic(&heuristic3a); 1550 anyToDo=true; 1551 } 1552 if (useRINS>=kType) { 1553 CbcHeuristicRINS heuristic5(*model); 1554 heuristic5.setHeuristicName("RINS"); 1555 heuristic5.setFractionSmall(0.6); 1556 model->addHeuristic(&heuristic5) ; 1557 anyToDo=true; 1558 } 1559 if (type==2&&anyToDo) { 1560 // Do heuristics 1561 // clean copy 1562 CbcModel model2(*model); 1563 if (logLevel<=1) 1564 model2.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry); 1565 OsiBabSolver defaultC; 1566 //solver_->setAuxiliaryInfo(&defaultC); 1567 model2.passInSolverCharacteristics(&defaultC); 1568 // Save bounds 1569 int numberColumns = model2.solver()->getNumCols(); 1570 model2.createContinuousSolver(); 1571 bool cleanModel = !model2.numberIntegers()&&!model2.numberObjects(); 1572 model2.findIntegers(false); 1573 model2.doHeuristicsAtRoot(true); 1574 if (cleanModel) 1575 model2.zapIntegerInformation(false); 1576 if (model2.bestSolution()) { 1577 double value = model2.getMinimizationObjValue(); 1578 model->setCutoff(value); 1579 model->setBestSolution(model2.bestSolution(),numberColumns,value); 1580 model->setSolutionCount(1); 1581 model->setNumberHeuristicSolutions(1); 1582 } 1583 return 0; 1584 } else { 1585 return 0; 1586 } 1587 } 1435 1588 /* Meaning of whereFrom: 1436 1589 1 after initial solve by dualsimplex etc … … 1439 1592 4 just after branchAndBound (before postprocessing) 1440 1593 5 after postprocessing 1594 6 after a user called heuristic phase 1441 1595 */ 1442 1596 int CbcMain1 (int argc, const char *argv[], … … 1476 1630 } 1477 1631 CbcModel * babModel = NULL; 1632 double time0; 1478 1633 { 1479 1634 double time1 = CoinCpuTime(),time2; 1635 time0=time1; 1480 1636 bool goodModel=(originalSolver->getNumCols()) ? true : false; 1481 1637 … … 1811 1967 bool storedCuts = false; 1812 1968 1813 bool useRounding=true;1814 bool useFpump=true;1815 bool useGreedy=true;1816 bool useCombine=true;1817 bool useLocalTree=false;1818 bool useRINS=false;1819 1969 int useCosts=0; 1820 1970 // don't use input solution … … 1857 2007 // next command 1858 2008 field=CoinReadGetCommand(argc,argv); 2009 // Reset time 2010 time1 = CoinCpuTime(); 1859 2011 // adjust field if has odd trailing characters 1860 2012 char temp [200]; … … 2120 2272 cutPassInTree = value; 2121 2273 else if (parameters[iParam].type()==FPUMPITS) 2122 { useFpump = true;parameters[iParam].setIntValue(value);}2274 { parameters[iParam].setIntValue(value);} 2123 2275 else if (parameters[iParam].type()==STRONGBRANCHING|| 2124 2276 parameters[iParam].type()==NUMBERBEFORE) … … 2314 2466 case ROUNDING: 2315 2467 defaultSettings=false; // user knows what she is doing 2316 useRounding = action;2317 2468 break; 2318 2469 case FPUMP: 2319 2470 defaultSettings=false; // user knows what she is doing 2320 useFpump=action;2321 2471 break; 2322 2472 case RINS: 2323 useRINS=action;2324 2473 break; 2325 2474 case CUTSSTRATEGY: … … 2349 2498 break; 2350 2499 case HEURISTICSTRATEGY: 2351 useRounding = action;2352 useGreedy = action;2353 useCombine = action;2354 //useLocalTree = action;2355 useFpump=action;2356 2500 parameters[whichParam(ROUNDING,numberParameters,parameters)].setCurrentOption(action); 2357 2501 parameters[whichParam(GREEDY,numberParameters,parameters)].setCurrentOption(action); … … 2362 2506 case GREEDY: 2363 2507 defaultSettings=false; // user knows what she is doing 2364 useGreedy = action;2365 2508 break; 2366 2509 case COMBINE: 2367 2510 defaultSettings=false; // user knows what she is doing 2368 useCombine = action;2369 2511 break; 2370 2512 case LOCALTREE: 2371 2513 defaultSettings=false; // user knows what she is doing 2372 useLocalTree = action;2373 2514 break; 2374 2515 case COSTSTRATEGY: … … 2440 2581 //printf("dualize %d\n",dualize); 2441 2582 model2 = ((ClpSimplexOther *) model2)->dualOfModel(); 2442 sprintf(generalPrint,"Dual of model has %d rows and %d columns \n",2583 sprintf(generalPrint,"Dual of model has %d rows and %d columns", 2443 2584 model2->numberRows(),model2->numberColumns()); 2444 2585 generalMessageHandler->message(CLP_GENERAL,generalMessages) … … 2458 2599 if (preSolve<=100) { 2459 2600 presolveType=ClpSolve::presolveNumber; 2460 sprintf(generalPrint,"Doing %d presolve passes - picking up non-costed slacks \n",2601 sprintf(generalPrint,"Doing %d presolve passes - picking up non-costed slacks", 2461 2602 preSolve); 2462 2603 generalMessageHandler->message(CLP_GENERAL,generalMessages) … … 2467 2608 preSolve -=100; 2468 2609 presolveType=ClpSolve::presolveNumberCost; 2469 sprintf(generalPrint,"Doing %d presolve passes - picking up costed slacks \n",2610 sprintf(generalPrint,"Doing %d presolve passes - picking up costed slacks", 2470 2611 preSolve); 2471 2612 generalMessageHandler->message(CLP_GENERAL,generalMessages) … … 2815 2956 int nOut = numberRows-clpSolver->getNumRows(); 2816 2957 if (nOut&&!noPrinting) 2817 sprintf(generalPrint,"%d rows eliminated \n",nOut);2958 sprintf(generalPrint,"%d rows eliminated",nOut); 2818 2959 generalMessageHandler->message(CLP_GENERAL,generalMessages) 2819 2960 << generalPrint … … 2842 2983 } else { 2843 2984 std::cout<<"** Current model not valid"<<std::endl; 2985 } 2986 break; 2987 case DOHEURISTIC: 2988 if (goodModel) { 2989 // Actually do heuristics 2990 doHeuristics(&model,2); 2991 if (model.bestSolution()) { 2992 model.setProblemStatus(1); 2993 model.setSecondaryStatus(6); 2994 } 2995 int returnCode=callBack(&model,6); 2996 if (returnCode) { 2997 // exit if user wants 2998 delete babModel; 2999 return returnCode; 3000 } 2844 3001 } 2845 3002 break; … … 3409 3566 solver2->setHintParam(OsiDoInBranchAndCut,false,OsiHintDo) ; 3410 3567 } 3411 babModel->setOriginalColumns(process.originalColumns());3412 3568 #ifdef COIN_HAS_ASL 3413 3569 if (!solver2&&usingAmpl) { … … 3423 3579 if (!noPrinting) { 3424 3580 if (!solver2) { 3425 sprintf(generalPrint,"Pre-processing says infeasible or unbounded \n");3581 sprintf(generalPrint,"Pre-processing says infeasible or unbounded"); 3426 3582 generalMessageHandler->message(CLP_GENERAL,generalMessages) 3427 3583 << generalPrint … … 3459 3615 solver2 = solver2->clone(); 3460 3616 babModel->assignSolver(solver2); 3617 babModel->setOriginalColumns(process.originalColumns()); 3461 3618 babModel->initialSolve(); 3462 3619 babModel->setMaximumSeconds(timeLeft-(CoinCpuTime()-time1)); … … 3598 3755 delete [] dsort; 3599 3756 } 3600 // FPump done first as it only works if no solution 3601 CbcHeuristicFPump heuristic4(*babModel); 3602 heuristic4.setFractionSmall(0.6); 3603 if (useFpump) { 3604 heuristic4.setMaximumPasses(parameters[whichParam(FPUMPITS,numberParameters,parameters)].intValue()); 3605 int pumpTune=parameters[whichParam(FPUMPTUNE,numberParameters,parameters)].intValue(); 3606 if (pumpTune>0) { 3607 /* 3608 >=10000000 for using obj 3609 >=1000000 use as accumulate switch 3610 >=1000 use index+1 as number of large loops 3611 >=100 use 0.05 objvalue as increment 3612 >=10 use +0.1 objvalue for cutoff (add) 3613 1 == fix ints at bounds, 2 fix all integral ints, 3 and continuous at bounds 3614 4 and static continuous, 5 as 3 but no internal integers 3615 6 as 3 but all slack basis! 3616 */ 3617 int logLevel = parameters[log].intValue(); 3618 double value = babModel->solver()->getObjSense()*babModel->solver()->getObjValue(); 3619 int w = pumpTune/10; 3620 int c = w % 10; 3621 w /= 10; 3622 int i = w % 10; 3623 w /= 10; 3624 int r = w; 3625 int accumulate = r/1000; 3626 r -= 1000*accumulate; 3627 if (accumulate>=10) { 3628 int which = accumulate/10; 3629 accumulate -= 10*which; 3630 which--; 3631 // weights and factors 3632 double weight[]={0.1,0.1,0.5,0.5,1.0,1.0,5.0,5.0}; 3633 double factor[] = {0.1,0.5,0.1,0.5,0.1,0.5,0.1,0.5}; 3634 heuristic4.setInitialWeight(weight[which]); 3635 heuristic4.setWeightFactor(factor[which]); 3636 } 3637 // fake cutoff 3638 if (logLevel>1) 3639 printf("Setting "); 3640 if (c) { 3641 double cutoff; 3642 babModel->solver()->getDblParam(OsiDualObjectiveLimit,cutoff); 3643 cutoff = CoinMin(cutoff,value + 0.1*fabs(value)*c); 3644 double dextra1 = parameters[whichParam(DEXTRA1,numberParameters,parameters)].doubleValue(); 3645 if (dextra1) 3646 cutoff=dextra1; 3647 heuristic4.setFakeCutoff(cutoff); 3648 if (logLevel>1) 3649 printf("fake cutoff of %g ",cutoff); 3650 } 3651 if (i||r) { 3652 // also set increment 3653 double increment = (0.01*i+0.005)*(fabs(value)+1.0e-12); 3654 double dextra2 = parameters[whichParam(DEXTRA2,numberParameters,parameters)].doubleValue(); 3655 if (dextra2) 3656 increment = dextra2; 3657 heuristic4.setAbsoluteIncrement(increment); 3658 heuristic4.setAccumulate(accumulate); 3659 heuristic4.setMaximumRetries(r+1); 3660 if (logLevel>1) { 3661 if (i) 3662 printf("increment of %g ",heuristic4.absoluteIncrement()); 3663 if (accumulate) 3664 printf("accumulate of %d ",accumulate); 3665 printf("%d retries ",r+2); 3666 } 3667 } 3668 pumpTune = pumpTune%100; 3669 if (logLevel>1) 3670 printf("and setting when to %d\n",pumpTune+10); 3671 if (pumpTune==6) 3672 pumpTune =13; 3673 heuristic4.setWhen(pumpTune+10); 3674 } 3675 heuristic4.setHeuristicName("feasibility pump"); 3676 babModel->addHeuristic(&heuristic4); 3677 } 3757 // Set up heuristics 3758 doHeuristics(babModel,(!miplib) ? 1 : 3); 3678 3759 if (!miplib) { 3679 CbcRounding heuristic1(*babModel); 3680 heuristic1.setHeuristicName("rounding"); 3681 if (useRounding) 3682 babModel->addHeuristic(&heuristic1) ; 3683 CbcHeuristicLocal heuristic2(*babModel); 3684 heuristic2.setHeuristicName("combine solutions"); 3685 heuristic2.setFractionSmall(0.6); 3686 heuristic2.setSearchType(1); 3687 if (useCombine) 3688 babModel->addHeuristic(&heuristic2); 3689 CbcHeuristicGreedyCover heuristic3(*babModel); 3690 heuristic3.setHeuristicName("greedy cover"); 3691 CbcHeuristicGreedyEquality heuristic3a(*babModel); 3692 heuristic3a.setHeuristicName("greedy equality"); 3693 if (useGreedy) { 3694 babModel->addHeuristic(&heuristic3); 3695 babModel->addHeuristic(&heuristic3a); 3696 } 3697 if (useLocalTree) { 3760 if(parameters[whichParam(LOCALTREE,numberParameters,parameters)].currentOptionAsInteger()) { 3698 3761 CbcTreeLocal localTree(babModel,NULL,10,0,0,10000,2000); 3699 3762 babModel->passInTreeHandler(localTree); 3700 3763 } 3701 3764 } 3702 CbcHeuristicRINS heuristic5(*babModel);3703 heuristic5.setHeuristicName("RINS");3704 heuristic5.setFractionSmall(0.6);3705 if (useRINS)3706 babModel->addHeuristic(&heuristic5) ;3707 3765 if (type==MIPLIB) { 3708 3766 if (babModel->numberStrong()==5&&babModel->numberBeforeTrust()==5) … … 3843 3901 int mipOptions = parameters[whichParam(MIPOPTIONS,numberParameters,parameters)].intValue()%10000; 3844 3902 if (mipOptions!=(1)) { 3845 sprintf(generalPrint,"mip options %d \n",mipOptions);3903 sprintf(generalPrint,"mip options %d",mipOptions); 3846 3904 generalMessageHandler->message(CLP_GENERAL,generalMessages) 3847 3905 << generalPrint … … 3864 3922 int moreMipOptions = parameters[whichParam(MOREMIPOPTIONS,numberParameters,parameters)].intValue(); 3865 3923 if (moreMipOptions>=0) { 3866 sprintf(generalPrint,"more mip options %d \n",moreMipOptions);3924 sprintf(generalPrint,"more mip options %d",moreMipOptions); 3867 3925 generalMessageHandler->message(CLP_GENERAL,generalMessages) 3868 3926 << generalPrint … … 3995 4053 } 3996 4054 babModel->setNumberObjects(n); 4055 babModel->zapIntegerInformation(); 3997 4056 } 3998 4057 int nMissing=0; … … 4048 4107 } 4049 4108 if (nMissing) { 4050 sprintf(generalPrint,"%d SOS variables vanished due to pre processing? - check validity? \n",nMissing);4109 sprintf(generalPrint,"%d SOS variables vanished due to pre processing? - check validity?",nMissing); 4051 4110 generalMessageHandler->message(CLP_GENERAL,generalMessages) 4052 4111 << generalPrint … … 4109 4168 delete [] back; 4110 4169 if (nMissing) { 4111 sprintf(generalPrint,"%d SOS variables vanished due to pre processing? - check validity? \n",nMissing);4170 sprintf(generalPrint,"%d SOS variables vanished due to pre processing? - check validity?",nMissing); 4112 4171 generalMessageHandler->message(CLP_GENERAL,generalMessages) 4113 4172 << generalPrint … … 4278 4337 delete [] back; 4279 4338 if (nMissing) { 4280 sprintf(generalPrint,"%d SOS variables vanished due to pre processing? - check validity? \n",nMissing);4339 sprintf(generalPrint,"%d SOS variables vanished due to pre processing? - check validity?",nMissing); 4281 4340 generalMessageHandler->message(CLP_GENERAL,generalMessages) 4282 4341 << generalPrint … … 4450 4509 } 4451 4510 if (testOsiOptions>=0) { 4452 sprintf(generalPrint,"Testing OsiObject options %d \n",testOsiOptions);4511 sprintf(generalPrint,"Testing OsiObject options %d",testOsiOptions); 4453 4512 generalMessageHandler->message(CLP_GENERAL,generalMessages) 4454 4513 << generalPrint … … 4765 4824 babModel->makeGlobalCut(rowCutPointer); 4766 4825 } 4767 } 4826 } 4768 4827 // If defaults then increase trust for small models 4769 4828 if (!strongChanged) { … … 5350 5409 if (dualize) { 5351 5410 model2 = ((ClpSimplexOther *) model2)->dualOfModel(); 5352 sprintf(generalPrint,"Dual of model has %d rows and %d columns \n",5411 sprintf(generalPrint,"Dual of model has %d rows and %d columns", 5353 5412 model2->numberRows(),model2->numberColumns()); 5354 5413 generalMessageHandler->message(CLP_GENERAL,generalMessages) … … 6610 6669 #endif 6611 6670 model.solver()->setWarmStart(NULL); 6671 sprintf(generalPrint,"Total time %.2f",CoinCpuTime()-time0); 6672 generalMessageHandler->message(CLP_GENERAL,generalMessages) 6673 << generalPrint 6674 <<CoinMessageEol; 6612 6675 return 0; 6613 6676 }
Note: See TracChangeset
for help on using the changeset viewer.