Changeset 961


Ignore:
Timestamp:
Jun 3, 2008 9:19:53 AM (11 years ago)
Author:
forrest
Message:

add multi heuristic

Location:
trunk/Cbc/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/CbcHeuristic.cpp

    r955 r961  
    346346CbcHeuristic::shouldHeurRun_randomChoice()
    347347{
     348  if (!when_)
     349    return false;
    348350  int depth = 0;
    349351  const CbcNode* currentNode = model_->currentNode();
     
    351353    depth = currentNode->depth();
    352354  }
    353 
    354   if(depth != 0) {
     355  // when_ -999 is special marker to force to run
     356  if(depth != 0&&when_!=-999) {
    355357    const double numerator = depth * depth;
    356358    const double denominator = exp(depth * log((double)2));
    357359    double probability = numerator / denominator;
    358360    double randomNumber = randomNumberGenerator_.randomDouble();
    359     if (when_>2&&when_<7) {
     361    if (when_>2&&when_<8) {
    360362      /* JJF adjustments
    361363         3 only at root and if no solution
     
    363365         5 only at depth <4
    364366         6 decay
     367         7 run up to 2 times if solution found 4 otherwise
    365368      */
    366369      switch(when_) {
    367370      case 3:
     371      default:
    368372        if (model_->bestSolution())
    369373          probability=-1.0;
     
    378382        break;
    379383      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          }
    383394          probability = 1.0/howOften_;
    384395          if (model_->bestSolution())
     
    386397        }
    387398        break;
     399      case 7:
     400        if ((model_->bestSolution()&&numRuns_>=2)||numRuns_>=4)
     401          probability=-1.0;
     402        break;
    388403      }
    389404    }
     
    393408    if (model_->getCurrentPassNumber() > 1)
    394409      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
    395419  }
    396420  ++numRuns_;
     
    610634    /* Do not try and produce equality cliques and
    611635       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    }
    613649    if (logLevel<=1)
    614650      process.messageHandler()->setLogLevel(0);
     
    658694          model.solver()->setIntParam(OsiMaxNumIterationHotStart,10);
    659695          model.setMaximumCutPassesAtRoot(CoinMin(20,model_->getMaximumCutPassesAtRoot()));
     696          model.setMaximumCutPasses(CoinMin(10,model_->getMaximumCutPasses()));
    660697        } else {
    661698          model_->messageHandler()->message(CBC_RESTART,model_->messages())
     
    667704            model.cutGenerator(i)->setTiming(true);
    668705          model.setCutoff(cutoff);
     706          // make sure can't do nested search! but allow heuristics
     707          model.setSpecialOptions((model.specialOptions()&(~(512+2048)))|1024);
    669708          bool takeHint;
    670709          OsiHintStrength strength;
     
    678717          model.setStrategy(strategy);
    679718          //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          }
    680725        }
    681726        if (inputSolution_) {
     
    12441289{
    12451290
     1291  numCouldRun_++;
    12461292  // See if to do
    12471293  if (!when()||(when()%10==1&&model_->phase()!=1)||
    12481294      (when()%10==2&&(model_->phase()!=2&&model_->phase()!=3)))
    12491295    return 0; // switched off
     1296  numRuns_++;
    12501297  OsiSolverInterface * solver = model_->solver();
    12511298  double direction = solver->getObjSense();
     
    23032350}
    23042351 
     2352
     2353// Default Constructor
     2354CbcHeuristicJustOne::CbcHeuristicJustOne()
     2355  :CbcHeuristic(),
     2356   probabilities_(NULL),
     2357   heuristic_(NULL),
     2358   numberHeuristics_(0)
     2359{
     2360}
     2361
     2362// Constructor from model
     2363CbcHeuristicJustOne::CbcHeuristicJustOne(CbcModel & model)
     2364  :CbcHeuristic(model),
     2365   probabilities_(NULL),
     2366   heuristic_(NULL),
     2367   numberHeuristics_(0)
     2368{
     2369}
     2370
     2371// Destructor
     2372CbcHeuristicJustOne::~CbcHeuristicJustOne ()
     2373{
     2374  for (int i=0;i<numberHeuristics_;i++)
     2375    delete heuristic_[i];
     2376  delete [] heuristic_;
     2377  delete [] probabilities_;
     2378}
     2379
     2380// Clone
     2381CbcHeuristicJustOne *
     2382CbcHeuristicJustOne::clone() const
     2383{
     2384  return new CbcHeuristicJustOne(*this);
     2385}
     2386
     2387// Create C++ lines to get to current state
     2388void
     2389CbcHeuristicJustOne::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
     2399CbcHeuristicJustOne::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
     2415CbcHeuristicJustOne &
     2416CbcHeuristicJustOne::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
     2438int
     2439CbcHeuristicJustOne::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
     2472void
     2473CbcHeuristicJustOne::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)
     2480void
     2481CbcHeuristicJustOne::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)
     2488void
     2489CbcHeuristicJustOne::validate()
     2490{
     2491  CbcHeuristic::validate();
     2492  for (int i=0;i<numberHeuristics_;i++)
     2493    heuristic_[i]->validate();
     2494}
     2495// Adds an heuristic with probability
     2496void
     2497CbcHeuristicJustOne::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
     2514void
     2515CbcHeuristicJustOne::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  
    454454};
    455455
     456/** Just One class - this chooses one at random
     457 */
     458
     459class CbcHeuristicJustOne : public CbcHeuristic {
     460public:
     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();
     514protected:
     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
    456528#endif
  • trunk/Cbc/src/CbcHeuristicDive.cpp

    r955 r961  
    168168}
    169169
    170 // See if dive fractional will give better solution
     170// See if diving will give better solution
    171171// Sets value of solution
    172172// Returns 1 if solution, 0 if not
     
    585585  if (model_&&when()<10) {
    586586    if (model_->numberIntegers()!=
    587         model_->numberObjects())
     587        model_->numberObjects()&&(model_->numberObjects()||
     588                                  (model_->specialOptions()&1024)==0))
    588589      setWhen(0);
    589590  }
     
    744745
    745746{
    746   //return 0; //temp
     747  return 0; // temp
    747748#if 0
    748749  if(!solverCharacteristics_->reducedCostsAccurate())
  • trunk/Cbc/src/CbcHeuristicDive.hpp

    r944 r961  
    119119
    120120};
    121 
    122121#endif
  • trunk/Cbc/src/CbcHeuristicFPump.cpp

    r955 r961  
    194194                         double * betterSolution)
    195195{
     196  numCouldRun_++;
    196197  double incomingObjective = solutionValue;
    197198#define LEN_PRINT 200
     
    283284    return 0;
    284285  }
     286  numRuns_++;
    285287  if (cutoff<1.0e50&&false) {
    286288    // Fix on djs
  • trunk/Cbc/src/CbcHeuristicGreedy.cpp

    r954 r961  
    104104                         double * betterSolution)
    105105{
     106  numCouldRun_++;
    106107  if (!model_)
    107108    return 0;
     
    136137    return 0; // switched off
    137138
     139  numRuns_++;
    138140  assert (numberRows==matrix_.getNumRows());
    139141  int iRow, iColumn;
     
    506508                         double * betterSolution)
    507509{
     510  numCouldRun_++;
    508511  if (!model_)
    509512    return 0;
     
    538541  if (!numberRows)
    539542    return 0; // switched off
     543  numRuns_++;
    540544
    541545  assert (numberRows==matrix_.getNumRows());
  • trunk/Cbc/src/CbcHeuristicLocal.cpp

    r904 r961  
    127127                            const int * keep)
    128128{
     129  numCouldRun_++;
    129130  // See if to do
    130131  if (!when()||(when()==1&&model_->phase()!=1))
     
    176177{
    177178
     179  numCouldRun_++;
    178180  if (numberSolutions_==model_->getSolutionCount())
    179181    return 0;
     
    203205  double newSolutionValue = model_->getObjValue()*direction;
    204206  int returnCode = 0;
    205 
     207  numRuns_++;
    206208  // Column copy
    207209  const double * element = matrix_.getElements();
  • trunk/Cbc/src/CbcHeuristicRINS.cpp

    r904 r961  
    137137                         double * betterSolution)
    138138{
     139  numCouldRun_++;
    139140  int returnCode=0;
    140141  const double * bestSolution = model_->bestSolution();
     
    211212      if (returnCode<0)
    212213        returnCode=0; // returned on size
     214      else
     215        numRuns_++;
    213216      if ((returnCode&1)!=0)
    214217        numberSuccesses_++;
     
    315318  int numberFixed=0;
    316319  int numberTightened=0;
     320  int numberAtBound=0;
    317321
    318322  for (i=0;i<numberIntegers;i++) {
     
    325329    if (fabs(value-floor(value+0.5))<1.0e-8) {
    326330      value = floor(value+0.5);
     331      if (value==lower||value==upper)
     332        numberAtBound++;
    327333      newSolver->setColLower(iColumn,value);
    328334      newSolver->setColUpper(iColumn,value);
     
    346352      // could add cut
    347353      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
    349358    } else {
    350359      //printf("\n");
  • trunk/Cbc/src/CbcModel.cpp

    r955 r961  
    15131513  OsiObject ** saveObjects=NULL;
    15141514  maximumRows_ = numberRowsAtContinuous_;
     1515  currentDepth_=0;
    15151516  workingBasis_.resize(maximumRows_,numberColumns);
    15161517/*
     
    16671668 // Save copy of solver
    16681669 OsiSolverInterface * saveSolver = NULL;
    1669  if (!parentModel_&&(specialOptions_&512)!=0)
     1670 if (!parentModel_&&(specialOptions_&(512+2048))!=0)
    16701671   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 }
    16711780/*
    16721781  We've taken the continuous relaxation as far as we can. Time to branch.
     
    38623971  maximumWhich_(1000),
    38633972  maximumRows_(0),
     3973  currentDepth_(0),
    38643974  whichGenerator_(NULL),
    38653975  maximumStatistics_(0),
     
    40074117  maximumWhich_(1000),
    40084118  maximumRows_(0),
     4119  currentDepth_(0),
    40094120  whichGenerator_(NULL),
    40104121  maximumStatistics_(0),
     
    42384349  maximumWhich_(rhs.maximumWhich_),
    42394350  maximumRows_(0),
     4351  currentDepth_(0),
    42404352  whichGenerator_(NULL),
    42414353  maximumStatistics_(0),
     
    45774689      whichGenerator_ = CoinCopyOfArray(rhs.whichGenerator_,maximumWhich_);
    45784690    maximumRows_=0;
     4691    currentDepth_ = 0;
    45794692    workingBasis_ = CoinWarmStartBasis();
    45804693    for (i=0;i<maximumStatistics_;i++)
     
    53045417  printf("Starting bounds at node %d\n",numberNodes_);
    53055418#endif
     5419  currentDepth_=nNode;
    53065420  while (nNode) {
    53075421    --nNode;
  • trunk/Cbc/src/CbcModel.hpp

    r954 r961  
    736736  inline int problemType() const
    737737  { return problemType_;}
     738  /// Current depth
     739  inline int currentDepth() const
     740  { return currentDepth_;}
    738741
    739742  /// Set how often to scan global cuts
     
    21112114  /// Maximum number of rows
    21122115  int maximumRows_;
     2116  /// Current depth
     2117  int currentDepth_;
    21132118  /// Work basis for temporary use
    21142119  CoinWarmStartBasis workingBasis_;
  • trunk/Cbc/src/CbcSolver.cpp

    r955 r961  
    729729      int numberColumns = babModel_->getNumCols();
    730730      if (babModel_->bestSolution())
    731         model_.setBestSolution(babModel_->bestSolution(),numberColumns,babModel_->getObjValue());
     731        model_.setBestSolution(babModel_->bestSolution(),numberColumns,babModel_->getMinimizationObjValue());
    732732      OsiClpSolverInterface * clpSolver1 = dynamic_cast< OsiClpSolverInterface*> (babModel_->solver());
    733733      ClpSimplex * lpSolver1 = clpSolver1->getModelPtr();
     
    32343234  int useRINS = parameters_[whichParam(RINS,numberParameters_,parameters_)].currentOptionAsInteger();
    32353235  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();
    32373237  // FPump done first as it only works if no solution
    32383238  int kType = (type<3) ? type : 1;
     
    33643364    heuristic6.setFractionSmall(0.5);
    33653365    heuristic6.setFeasibilityPumpOptions(1008003);
    3366     int nodes []={-2,-1,200,1000};
     3366    int nodes []={-2,0,200,1000,10000};
    33673367    heuristic6.setNumberNodes(nodes[useRENS]);
    33683368    model->addHeuristic(&heuristic6) ;
     
    33803380    anyToDo=true;
    33813381  }
    3382   // change later?
     3382  int useDIVING=0;
    33833383  {
    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();
    33933390  }
     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 
    33943422  if (useDIVING>=kType) {
    33953423    int diveOptions=parameters_[whichParam(DIVEOPT,numberParameters_,parameters_)].intValue();
    3396     if (diveOptions<3||diveOptions>6)
     3424    if (diveOptions<0||diveOptions>10)
    33973425      diveOptions=2;
    33983426    if ((useDIVING&1)!=0) {
     
    44184446                      <<CoinMessageEol;
    44194447                    generalMessageHandler->message(CLP_GENERAL,generalMessages)
     4448                      <<"Possible restart after 100 nodes if can fix many"
     4449                      <<CoinMessageEol;
     4450                    generalMessageHandler->message(CLP_GENERAL,generalMessages)
    44204451                      <<"extra options - -diving C -diveopt 3 -rins on -tune 6 -probing on -passf 30!"
    44214452                      <<CoinMessageEol;
     
    44314462                  parameters_[iParam].setIntValue(6);
    44324463                  tunePreProcess=6;
    4433                   iParam = whichParam(DIVINGA,numberParameters_,parameters_);
    4434                   parameters_[iParam].setCurrentOption("C");
     4464                  iParam = whichParam(DIVINGC,numberParameters_,parameters_);
     4465                  parameters_[iParam].setCurrentOption("on");
    44354466                  iParam = whichParam(RINS,numberParameters_,parameters_);
    44364467                  parameters_[iParam].setCurrentOption("on");
     
    46854716              break;
    46864717            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:
    46884725            case COMBINE:
    46894726            case LOCALTREE:
     
    61526189                probingGen.setMaxProbeRoot(123);
    61536190                probingGen.setMaxProbe(123);
     6191                probingGen.setMaxLookRoot(20);
    61546192                if (probingAction==5||probingAction==7)
    61556193                  probingGen.setRowCuts(-3); // strengthening etc just at root
    61566194                if (probingAction==6||probingAction==7) {
    61576195                  // Number of unsatisfied variables to look at
    6158                   probingGen.setMaxProbe(1000);
    6159                   probingGen.setMaxProbeRoot(1000);
     6196                  probingGen.setMaxProbeRoot(babModel_->solver()->getNumCols());
     6197                  probingGen.setMaxProbe(babModel_->solver()->getNumCols());
    61606198                  // How far to follow the consequences
    61616199                  probingGen.setMaxLook(50);
     
    62116249                switches[numberGenerators++]=1;
    62126250              }
    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                }
    62146261                babModel_->addCutGenerator(&twomirGen,translate[twomirAction],"TwoMirCuts");
    62156262                switches[numberGenerators++]=1;
     
    63336380                  // try reduced model
    63346381                  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);
    63356386                }
    63366387                {
     
    63556406                      lpSolver->setSpecialOptions(lpSolver->specialOptions()|256);
    63566407                  }
    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                  }
    63596415                  // go faster stripes
    63606416                  if( moreMipOptions >=999999) {
     
    65016557                      }
    65026558                      babModel_->setNumberObjects(n);
     6559                      numberOldObjects=n;
    65036560                      babModel_->zapIntegerInformation();
    65046561                    }
     
    73357392                  int extra1 = parameters_[whichParam(EXTRA1,numberParameters_,parameters_)].intValue();
    73367393                  if (extra1!=-1) {
    7337                     if (extra1<10000) {
     7394                    if (extra1<19000) {
    73387395                      babModel_->setSearchStrategy(extra1);
    73397396                      printf("XXXXX searchStrategy %d\n",extra1);
    73407397                    } else {
    7341                       babModel_->setNumberAnalyzeIterations(extra1);
     7398                      int n=extra1-20000;
     7399                      if (!n)
     7400                        n--;
     7401                      babModel_->setNumberAnalyzeIterations(n);
    73427402                      printf("XXXXX analyze %d\n",extra1);
    73437403                    }
     
    73997459#endif
    74007460#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
    74017473                void printHistory(const char * file);
    74027474                printHistory("branch.log");
     
    74657537                stuff[3]=parameters_[whichParam(DEXTRA4,numberParameters_,parameters_)].doubleValue();
    74667538                stuff[4]=parameters_[whichParam(DENSE,numberParameters_,parameters_)].intValue();
    7467                 stuff[5]=parameters_[whichParam(EXTRA2,numberParameters_,parameters_)].intValue();
     7539                stuff[5]=parameters_[whichParam(EXTRA1,numberParameters_,parameters_)].intValue();
    74687540                stuff[6]=parameters_[whichParam(EXTRA3,numberParameters_,parameters_)].intValue();
    74697541                stuff[7]=parameters_[whichParam(EXTRA4,numberParameters_,parameters_)].intValue();
     
    75277599                for (iGenerator=0;iGenerator<babModel_->numberHeuristics();iGenerator++) {
    75287600                  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                }
    75397613#endif
    75407614              }
     
    75647638#if NEW_STYLE_SOLVER==0
    75657639                if (returnMode==1)
    7566                   model_.setBestSolution(bestSolution,n,babModel_->getObjValue());
    7567 #endif
    7568                 babModel_->setBestSolution(bestSolution,n,babModel_->getObjValue());
     7640                  model_.setBestSolution(bestSolution,n,babModel_->getMinimizationObjValue());
     7641#endif
     7642                babModel_->setBestSolution(bestSolution,n,babModel_->getMinimizationObjValue());
    75697643#if NEW_STYLE_SOLVER==0
    75707644                // and put back in very original solver
     
    95539627    OsiClpSolverInterface * clpSolver = dynamic_cast< OsiClpSolverInterface*> (model_.solver());
    95549628    ClpSimplex * lpSolver = clpSolver->getModelPtr();
    9555     if (lpSolver0!=lpSolver)
     9629    if (lpSolver0!=lpSolver&&lpSolver!=originalSolver->getModelPtr())
    95569630      lpSolver->moveInfo(*lpSolver0);
    95579631    //babModel_->setModelOwnsSolver(false);
  • trunk/Cbc/src/unitTestClp.cpp

    r955 r961  
    8181                    double * stuff)
    8282{
     83  // Stop Windows popup
     84  WindowsErrorPopupBlocker();
    8385  unsigned int m ;
    8486
Note: See TracChangeset for help on using the changeset viewer.