Ignore:
Timestamp:
Oct 9, 2006 4:19:31 PM (14 years ago)
Author:
forrest
Message:

for local tree search and feasibility pump

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Cbc/src/CbcHeuristicFPump.cpp

    r439 r441  
    2929   maximumPasses_(100),
    3030   maximumRetries_(1),
     31   accumulate_(0),
    3132   roundExpensive_(false)
    3233{
     
    4647   maximumPasses_(100),
    4748   maximumRetries_(1),
     49   accumulate_(0),
    4850   roundExpensive_(roundExpensive)
    4951{
     
    7779  else
    7880    fprintf(fp,"4  heuristicFPump.setMaximumRetries(%d);\n",maximumRetries_);
     81  if (accumulate_!=other.accumulate_)
     82    fprintf(fp,"3  heuristicFPump.setAccumulate(%d);\n",accumulate_);
     83  else
     84    fprintf(fp,"4  heuristicFPump.setAccumulate(%d);\n",accumulate_);
    7985  if (maximumTime_!=other.maximumTime_)
    8086    fprintf(fp,"3  heuristicFPump.setMaximumTime(%g);\n",maximumTime_);
     
    108114  maximumPasses_(rhs.maximumPasses_),
    109115  maximumRetries_(rhs.maximumRetries_),
     116  accumulate_(rhs.accumulate_),
    110117  roundExpensive_(rhs.roundExpensive_)
    111118{
     
    150157  char * usedColumn = NULL;
    151158  double * lastSolution=NULL;
    152   bool fixContinuous=false;
     159  int fixContinuous=0;
    153160  bool fixInternal=false;
    154   if (when_>=11&&when_<=13) {
    155     fixInternal = when_ >11;
    156     fixContinuous = when_==13;
     161  if (when_>=11&&when_<=15) {
     162    fixInternal = when_ >11&&when_<15;
     163    if (when_<13)
     164      fixContinuous = 0;
     165    else if (when_!=14)
     166      fixContinuous=1;
     167    else
     168      fixContinuous=2;
    157169    when_=1;
    158170    usedColumn = new char [numberColumns];
     
    314326          if (returnCode) {
    315327            memcpy(betterSolution,newSolution,numberColumns*sizeof(double));
     328            if ((accumulate_&1)!=0)
     329              model_->incrementUsed(betterSolution); // for local search
    316330            solutionValue=newSolutionValue;
    317331            solutionFound=true;
     
    438452            if (newSolutionValue<solutionValue) {
    439453              memcpy(betterSolution,newSolution,numberColumns*sizeof(double));
     454              if ((accumulate_&1)!=0)
     455                model_->incrementUsed(betterSolution); // for local search
    440456              solutionValue=newSolutionValue;
    441457              solutionFound=true;
     
    468484      int nFixI=0;
    469485      int nFixC=0;
     486      int nFixC2=0;
    470487      for (i=0;i<numberIntegers;i++) {
    471488        int iColumn=integerVariable[i];
     
    507524              newSolver->setColLower(iColumn,colUpper[iColumn]);
    508525              nFixC++;
     526            } else if (fixContinuous==2) {
     527              newSolver->setColLower(iColumn,value);
     528              newSolver->setColUpper(iColumn,value);
     529              nFixC++;
     530              nFixC2++;
    509531            }
    510532          }
     
    517539        break;
    518540      }
    519       printf("%d integers at bound fixed (of which %d were internal) and %d continuous\n",
    520              nFix,nFixI,nFixC);
     541      printf("%d integers at bound fixed and %d continuous",
     542             nFix,nFixC);
     543      if (nFixC2+nFixI==0)
     544        printf("\n");
     545      else
     546        printf("of which %d were internal integer and %d internal continuous\n",
     547             nFixI,nFixC2);
    521548      double saveValue = newSolutionValue;
    522549      returnCode = smallBranchAndBound(newSolver,200,newSolution,newSolutionValue,
     
    525552        printf("old sol of %g new of %g\n",saveValue,newSolutionValue);
    526553        memcpy(betterSolution,newSolution,numberColumns*sizeof(double));
     554        if (fixContinuous) {
     555          // may be able to do even better
     556          const double * lower = model_->solver()->getColLower();
     557          const double * upper = model_->solver()->getColUpper();
     558          for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     559            if (newSolver->isInteger(iColumn)) {
     560              double value=floor(newSolution[iColumn]+0.5);
     561              newSolver->setColLower(iColumn,value);
     562              newSolver->setColUpper(iColumn,value);
     563            } else {
     564              newSolver->setColLower(iColumn,lower[iColumn]);
     565              newSolver->setColUpper(iColumn,upper[iColumn]);
     566            }
     567          }
     568          newSolver->initialSolve();
     569          if (newSolver->isProvenOptimal()) {
     570            double value = newSolver->getObjValue()*newSolver->getObjSense();
     571            if (value<newSolutionValue) {
     572              printf("freeing continuous gives a solution of %g\n", value);
     573              newSolutionValue=value;
     574              memcpy(betterSolution,newSolver->getColSolution(),numberColumns*sizeof(double));
     575            }
     576          } else {
     577            newSolver->writeMps("bad3.mps");
     578          }
     579        }
     580        if ((accumulate_&1)!=0)
     581          model_->incrementUsed(betterSolution); // for local search
    527582        solutionValue=newSolutionValue;
    528583        solutionFound=true;
     
    532587    if (solutionFound) finalReturnCode=1;
    533588    cutoff = CoinMin(cutoff,solutionValue);
    534     if (numberTries>=CoinAbs(maximumRetries_)||!solutionFound) {
     589    if (numberTries>=maximumRetries_||!solutionFound) {
    535590      break;
    536591    } else if (absoluteIncrement_>0.0||relativeIncrement_>0.0) {
     
    539594      cutoff -= CoinMax(CoinMax(gap,absoluteIncrement_),model_->getCutoffIncrement());
    540595      printf("round again with cutoff of %g\n",cutoff);
    541       if (maximumRetries_<0)
     596      if (accumulate_<2)
    542597        memset(usedColumn,0,numberColumns);
    543598      totalNumberPasses += numberPasses;
Note: See TracChangeset for help on using the changeset viewer.