Ignore:
Timestamp:
Sep 25, 2006 2:22:16 PM (13 years ago)
Author:
forrest
Message:

extend fpump heuristic and allow more probing

File:
1 edited

Legend:

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

    r356 r435  
    120120 
    121121  int numberColumns = model_->getNumCols();
     122  char * usedColumn = NULL;
     123  double * lastSolution=NULL;
     124  bool fixContinuous=false;
     125  bool fixInternal=false;
     126  if (when_>=11&&when_<=13) {
     127    fixInternal = when_ >11;
     128    fixContinuous = when_==13;
     129    when_=1;
     130    usedColumn = new char [numberColumns];
     131    memset(usedColumn,0,numberColumns);
     132    lastSolution = CoinCopyOfArray(solver->getColSolution(),numberColumns);
     133  }
    122134  int numberIntegers = model_->numberIntegers();
    123135  const int * integerVariable = model_->integerVariable();
     
    175187// 5. MAIN WHILE LOOP
    176188  int numberPasses=0;
     189  double newSolutionValue=COIN_DBL_MAX;
    177190  bool newLineNeeded=false;
    178191  while (!finished) {
    179192    returnCode=0;
     193    // see what changed
     194    if (usedColumn) {
     195      const double * solution = solver->getColSolution();
     196      for (i=0;i<numberColumns;i++) {
     197        if (fabs(solution[i]-lastSolution[i])>1.0e-8)
     198          usedColumn[i]=1;
     199        lastSolution[i]=solution[i];
     200      }
     201    }
    180202    if (numberPasses>=maximumPasses_) {
    181203      break;
     
    194216      // Compute using dot product
    195217      solver->setDblParam(OsiObjOffset,saveOffset);
    196       double newSolutionValue = direction*solver->OsiSolverInterface::getObjValue();
     218      newSolutionValue = direction*solver->OsiSolverInterface::getObjValue();
    197219      if (model_->logLevel())
    198220        printf(" - solution found\n");
     
    294316      solver->resolve();
    295317      if (model_->logLevel())
    296         printf("\npass %3d: obj. %10.5lf --> ", numberPasses,solver->getObjValue());
     318        printf("\npass %3d: obj. %10.5f --> ", numberPasses,solver->getObjValue());
    297319      newLineNeeded=true;
    298320
     
    302324    printf(" - no solution found\n");
    303325  delete solver;
    304   delete [] newSolution;
    305326  for ( j=0;j<NUMBER_OLD;j++)
    306327    delete [] oldSolution[j];
    307328  delete [] oldSolution;
    308329  delete [] saveObjective;
     330  if (usedColumn) {
     331    OsiSolverInterface * newSolver = model_->continuousSolver()->clone();
     332    const double * colLower = newSolver->getColLower();
     333    const double * colUpper = newSolver->getColUpper();
     334    int i;
     335    int nFix=0;
     336    int nFixI=0;
     337    int nFixC=0;
     338    for (i=0;i<numberIntegers;i++) {
     339      int iColumn=integerVariable[i];
     340      const CbcObject * object = model_->object(i);
     341      const CbcSimpleInteger * integerObject =
     342        dynamic_cast<const  CbcSimpleInteger *> (object);
     343      assert(integerObject);
     344      // get original bounds
     345      double originalLower = integerObject->originalLowerBound();
     346      assert(colLower[iColumn]==originalLower);
     347      newSolver->setColLower(iColumn,CoinMax(colLower[iColumn],originalLower));
     348      double originalUpper = integerObject->originalUpperBound();
     349      assert(colUpper[iColumn]==originalUpper);
     350      newSolver->setColUpper(iColumn,CoinMin(colUpper[iColumn],originalUpper));
     351      if (!usedColumn[iColumn]) {
     352        double value=lastSolution[iColumn];
     353        double nearest = floor(value+0.5);
     354        if (fabs(value-nearest)<1.0e-7) {
     355          if (nearest==colLower[iColumn]) {
     356            newSolver->setColUpper(iColumn,colLower[iColumn]);
     357            nFix++;
     358          } else if (nearest==colUpper[iColumn]) {
     359            newSolver->setColLower(iColumn,colUpper[iColumn]);
     360            nFix++;
     361          } else if (fixInternal) {
     362            newSolver->setColLower(iColumn,nearest);
     363            newSolver->setColUpper(iColumn,nearest);
     364            nFix++;
     365            nFixI++;
     366          }
     367        }
     368      }
     369    }
     370    if (fixContinuous) {
     371      for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     372        if (!newSolver->isInteger(iColumn)&&!usedColumn[iColumn]) {
     373          double value=lastSolution[iColumn];
     374          if (value<colLower[iColumn]+1.0e-8) {
     375            newSolver->setColUpper(iColumn,colLower[iColumn]);
     376            nFix++;
     377            nFixC++;
     378          } else if (value>colUpper[iColumn]-1.0e-8) {
     379            newSolver->setColLower(iColumn,colUpper[iColumn]);
     380            nFix++;
     381            nFixC++;
     382          }
     383        }
     384      }
     385    }
     386    newSolver->initialSolve();
     387    assert (newSolver->isProvenOptimal());
     388    printf("%d integers at bound fixed, %d internal and %d continuous\n",
     389           nFix,nFixI,nFixC);
     390    double saveValue = newSolutionValue;
     391    returnCode = smallBranchAndBound(newSolver,200,newSolution,newSolutionValue,
     392                                     newSolutionValue,"CbcHeuristicLocalAfterFPump");
     393    if (returnCode) {
     394      printf("old sol of %g new of %g\n",saveValue,newSolutionValue);
     395      memcpy(betterSolution,newSolution,numberColumns*sizeof(double));
     396      solutionValue=newSolutionValue;
     397    }
     398    delete newSolver;
     399    delete [] usedColumn;
     400    delete [] lastSolution;
     401  }
     402  delete [] newSolution;
    309403  return returnCode;
    310404}
Note: See TracChangeset for help on using the changeset viewer.