Changeset 758


Ignore:
Timestamp:
Aug 16, 2007 6:34:37 AM (12 years ago)
Author:
forrest
Message:

fpump - make dj fixing optional

Location:
trunk/Cbc/src
Files:
5 edited

Legend:

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

    r753 r758  
    3434   maximumRetries_(1),
    3535   accumulate_(0),
     36   fixOnReducedCosts_(1),
    3637   roundExpensive_(false)
    3738{
     
    5455   maximumRetries_(1),
    5556   accumulate_(0),
     57   fixOnReducedCosts_(1),
    5658   roundExpensive_(roundExpensive)
    5759{
     
    9092  else
    9193    fprintf(fp,"4  heuristicFPump.setAccumulate(%d);\n",accumulate_);
     94  if (fixOnReducedCosts_!=other.fixOnReducedCosts_)
     95    fprintf(fp,"3  heuristicFPump.setFixOnReducedCosts(%d);\n",fixOnReducedCosts_);
     96  else
     97    fprintf(fp,"4  heuristicFPump.setFixOnReducedCosts(%d);\n",fixOnReducedCosts_);
    9298  if (maximumTime_!=other.maximumTime_)
    9399    fprintf(fp,"3  heuristicFPump.setMaximumTime(%g);\n",maximumTime_);
     
    136142  maximumRetries_(rhs.maximumRetries_),
    137143  accumulate_(rhs.accumulate_),
     144  fixOnReducedCosts_(rhs.fixOnReducedCosts_),
    138145  roundExpensive_(rhs.roundExpensive_)
    139146{
     
    157164    maximumRetries_ = rhs.maximumRetries_;
    158165    accumulate_ = rhs.accumulate_;
     166    fixOnReducedCosts_ = rhs.fixOnReducedCosts_;
    159167    roundExpensive_ = rhs.roundExpensive_;
    160168  }
     
    264272    if (gap>0.0) {
    265273      gap += 100.0*tolerance;
    266       model_->solver()->reducedCostFix(gap);
     274      int nFix=model_->solver()->reducedCostFix(gap);
     275      printf("dj fixing fixed %d variables\n",nFix);
    267276    }
    268277  }
     
    308317      double tolerance;
    309318      solver->getDblParam(OsiDualTolerance,tolerance) ;
    310       if (gap>0.0) {
     319      if (gap>0.0&&(fixOnReducedCosts_==1||(numberTries==1&&fixOnReducedCosts_==2))) {
    311320        gap += 100.0*tolerance;
    312         solver->reducedCostFix(gap);
     321        int nFix=solver->reducedCostFix(gap);
     322        if (nFix) {
     323          sprintf(pumpPrint,"Reduced cost fixing fixed %d variables on pass %d",nFix,numberTries);
     324          model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
     325            << pumpPrint
     326            <<CoinMessageEol;
     327          pumpPrint[0]='\0';
     328        }
    313329      }
    314330    }
  • trunk/Cbc/src/CbcHeuristicFPump.hpp

    r706 r758  
    120120  inline int accumulate() const
    121121  { return accumulate_;}
     122  /**  Set whether to fix variables on known solution
     123       0 - do not fix
     124       1 - fix integers on reduced costs
     125       2 - fix integers on reduced costs but only on entry
     126  */
     127  inline void setFixOnReducedCosts(int value)
     128  { fixOnReducedCosts_=value;}
     129  /// Get reduced cost option
     130  inline int fixOnReducedCosts() const
     131  { return fixOnReducedCosts_;}
    122132
    123133protected:
     
    155165  */
    156166  int accumulate_;
     167  /**  Set whether to fix variables on known solution
     168       0 - do not fix
     169       1 - fix integers on reduced costs
     170       2 - fix integers on reduced costs but only on entry
     171  */
     172  int fixOnReducedCosts_;
    157173  /// If true round to expensive
    158174  bool roundExpensive_;
  • trunk/Cbc/src/CbcModel.cpp

    r751 r758  
    98729872  memcpy(bestSolution_,solution,numberColumns*sizeof(double));
    98739873}
    9874 // Do heuristics at root
     9874/* Do heuristics at root.
     9875   0 - don't delete
     9876   1 - delete
     9877      2 - just delete - don't even use
     9878*/
    98759879void
    9876 CbcModel::doHeuristicsAtRoot(bool deleteHeuristicsAfterwards)
     9880CbcModel::doHeuristicsAtRoot(int deleteHeuristicsAfterwards)
    98779881{
     9882 
    98789883  int numberColumns = getNumCols() ;
    9879   if (deleteHeuristicsAfterwards) {
    9880     assert (!usedInSolution_);
    9881     usedInSolution_ = new int [numberColumns];
    9882     CoinZeroN(usedInSolution_,numberColumns);
    9883   }
    98849884  double * newSolution = new double [numberColumns] ;
    9885   double heuristicValue = getCutoff() ;
    9886   int found = -1; // no solution found
    9887   CbcEventHandler *eventHandler = getEventHandler() ;
    9888   if (eventHandler)
    9889     eventHandler->setModel(this);
    9890  
    9891   currentPassNumber_ = 1; // so root heuristics will run
    98929885  int i;
    9893   for (i = 0;i<numberHeuristics_;i++) {
    9894     // see if heuristic will do anything
    9895     double saveValue = heuristicValue ;
    9896     int ifSol = heuristic_[i]->solution(heuristicValue,
    9897                                         newSolution);
    9898     if (ifSol>0) {
    9899       // better solution found
    9900       found = i ;
    9901       incrementUsed(newSolution);
    9902       // increment number of solutions so other heuristics can test
    9903       numberSolutions_++;
    9904       numberHeuristicSolutions_++;
    9905     } else {
    9906       heuristicValue = saveValue ;
    9907     }
    9908   }
    9909   currentPassNumber_ = 0;
    9910   /*
    9911     Did any of the heuristics turn up a new solution? Record it before we free
    9912     the vector.
    9913   */
    9914   if (found >= 0) {
    9915     // For compiler error on terra cluster!
    9916     if (found<numberHeuristics_)
    9917       lastHeuristic_ = heuristic_[found];
    9918     else
    9919       lastHeuristic_ = heuristic_[0];
    9920     setBestSolution(CBC_ROUNDING,heuristicValue,newSolution) ;
    9921     CbcTreeLocal * tree
    9922       = dynamic_cast<CbcTreeLocal *> (tree_);
    9923     if (tree)
    9924       tree->passInSolution(bestSolution_,heuristicValue);
    9925     if (eventHandler) {
    9926       if (!eventHandler->event(CbcEventHandler::solution)) {
    9927         eventHappened_=true; // exit
     9886  if (deleteHeuristicsAfterwards!=2) {
     9887    if (deleteHeuristicsAfterwards) {
     9888      assert (!usedInSolution_);
     9889      usedInSolution_ = new int [numberColumns];
     9890      CoinZeroN(usedInSolution_,numberColumns);
     9891    }
     9892    double heuristicValue = getCutoff() ;
     9893    int found = -1; // no solution found
     9894    CbcEventHandler *eventHandler = getEventHandler() ;
     9895    if (eventHandler)
     9896      eventHandler->setModel(this);
     9897   
     9898    currentPassNumber_ = 1; // so root heuristics will run
     9899    for (i = 0;i<numberHeuristics_;i++) {
     9900      // see if heuristic will do anything
     9901      double saveValue = heuristicValue ;
     9902      int ifSol = heuristic_[i]->solution(heuristicValue,
     9903                                          newSolution);
     9904      if (ifSol>0) {
     9905        // better solution found
     9906        found = i ;
     9907        incrementUsed(newSolution);
     9908        // increment number of solutions so other heuristics can test
     9909        numberSolutions_++;
     9910        numberHeuristicSolutions_++;
     9911      } else {
     9912        heuristicValue = saveValue ;
     9913      }
     9914    }
     9915    currentPassNumber_ = 0;
     9916    /*
     9917      Did any of the heuristics turn up a new solution? Record it before we free
     9918      the vector.
     9919    */
     9920    if (found >= 0) {
     9921      // For compiler error on terra cluster!
     9922      if (found<numberHeuristics_)
     9923        lastHeuristic_ = heuristic_[found];
     9924      else
     9925        lastHeuristic_ = heuristic_[0];
     9926      setBestSolution(CBC_ROUNDING,heuristicValue,newSolution) ;
     9927      CbcTreeLocal * tree
     9928        = dynamic_cast<CbcTreeLocal *> (tree_);
     9929      if (tree)
     9930        tree->passInSolution(bestSolution_,heuristicValue);
     9931      if (eventHandler) {
     9932        if (!eventHandler->event(CbcEventHandler::solution)) {
     9933          eventHappened_=true; // exit
     9934        }
    99289935      }
    99299936    }
  • trunk/Cbc/src/CbcModel.hpp

    r750 r758  
    16341634  /// Fill in useful estimates
    16351635  void pseudoShadow(double * down, double * up);
    1636   /// Do heuristics at root
    1637   void doHeuristicsAtRoot(bool deleteHeuristicsAfterwards=false);
     1636  /** Do heuristics at root.
     1637      0 - don't delete
     1638      1 - delete
     1639      2 - just delete - don't even use
     1640  */
     1641  void doHeuristicsAtRoot(int deleteHeuristicsAfterwards=0);
    16381642  /// Get the hotstart solution
    16391643  inline const double * hotstartSolution() const
  • trunk/Cbc/src/CbcSolver.cpp

    r755 r758  
    15261526    }
    15271527    heuristic4.setHeuristicName("feasibility pump");
     1528    //#define ROLF
     1529#ifdef ROLF   
     1530    CbcHeuristicFPump pump(*model);
     1531    pump.setMaximumTime(60);
     1532    pump.setMaximumPasses(100);
     1533    pump.setMaximumRetries(1);
     1534    pump.setFixOnReducedCosts(0);
     1535    pump.setHeuristicName("Feasibility pump");
     1536    pump.setFractionSmall(1.0);
     1537    pump.setWhen(13);
     1538    model->addHeuristic(&pump);
     1539#else
    15281540    model->addHeuristic(&heuristic4);
     1541#endif
    15291542  }
    15301543  if (useRounding>=type) {
     
    15631576    // clean copy
    15641577    CbcModel model2(*model);
     1578    // But get rid of heuristics in model
     1579    model->doHeuristicsAtRoot(2);
    15651580    if (logLevel<=1)
    15661581      model2.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
     
    15731588    bool cleanModel = !model2.numberIntegers()&&!model2.numberObjects();
    15741589    model2.findIntegers(false);
    1575     model2.doHeuristicsAtRoot(true);
     1590    model2.doHeuristicsAtRoot(1);
    15761591    if (cleanModel)
    15771592      model2.zapIntegerInformation(false);
     
    36303645                if (!solver2)
    36313646                  break;
     3647                if (model.bestSolution()) {
     3648                  // need to redo - in case no better found in BAB
     3649                  // just get integer part right
     3650                  const int * originalColumns = process.originalColumns();
     3651                  int numberColumns = solver2->getNumCols();
     3652                  double * bestSolution = babModel->bestSolution();
     3653                  const double * oldBestSolution = model.bestSolution();
     3654                  for (int i=0;i<numberColumns;i++) {
     3655                    int jColumn = originalColumns[i];
     3656                    bestSolution[i]=oldBestSolution[jColumn];
     3657                  }
     3658                }
    36323659                //solver2->resolve();
    36333660                if (preProcess==2) {
Note: See TracChangeset for help on using the changeset viewer.