Changeset 435 for branches/devel


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

extend fpump heuristic and allow more probing

Location:
branches/devel/Cbc/src
Files:
3 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}
  • branches/devel/Cbc/src/CbcModel.cpp

    r426 r435  
    61526152  if (!solverCharacteristics_->solutionAddsCuts()) {
    61536153    // Can trust solution
    6154     double cutoff = CoinMin(getCutoff(),bestObjective_) ;
     6154    double cutoff = getCutoff();
     6155    if (cutoff<1.0e30)
     6156      cutoff = CoinMin(cutoff,bestObjective_) ;
    61556157   
    61566158    /*
  • branches/devel/Cbc/src/CoinSolve.cpp

    r427 r435  
    15251525              basisHasValues=1;
    15261526              if (dualize) {
    1527                 ((ClpSimplexOther *) lpSolver)->restoreFromDual(model2);
     1527                int returnCode=((ClpSimplexOther *) lpSolver)->restoreFromDual(model2);
    15281528                delete model2;
     1529                if (returnCode)
     1530                  lpSolver->primal(1);
    15291531                model2=lpSolver;
    15301532              }
     
    20552057              if (useFpump) {
    20562058                heuristic4.setMaximumPasses(parameters[whichParam(FPUMPITS,numberParameters,parameters)].intValue());
     2059                if (doIdiot>10&&doIdiot<14) {
     2060                  heuristic4.setWhen(doIdiot);
     2061                  doIdiot=-1;
     2062                }
    20572063                babModel->addHeuristic(&heuristic4);
    20582064              }
     
    20832089                if (probingAction==5)
    20842090                  probingGen.setRowCuts(-3); // strengthening etc just at root
     2091                if (probingAction==4) {
     2092                  // Number of unsatisfied variables to look at
     2093                  probingGen.setMaxProbe(1000);
     2094                  probingGen.setMaxProbeRoot(1000);
     2095                  // How far to follow the consequences
     2096                  probingGen.setMaxLook(50);
     2097                  probingGen.setMaxLookRoot(50);
     2098                }
    20852099                babModel->addCutGenerator(&probingGen,translate[probingAction],"Probing");
    20862100                switches[numberGenerators++]=0;
     
    44954509    strcpy(line[numberLines++],"5    std::cout<<\"processed model has \"<<solver2->getNumRows()");
    44964510    strcpy(line[numberLines++],"5            <<\" rows, \"<<solver2->getNumCols()");
    4497     strcpy(line[numberLines++],"5            <<\" and \"<<solver2->getNumElements()<<std::endl;");
     4511    strcpy(line[numberLines++],"5            <<\" columns and \"<<solver2->getNumElements()");
     4512    strcpy(line[numberLines++],"5            <<\" elements\"<<solver2->getNumElements()<<std::endl;");
    44984513    strcpy(line[numberLines++],"5  }");
    44994514    strcpy(line[numberLines++],"5  // we have to keep solver2 so pass clone");
Note: See TracChangeset for help on using the changeset viewer.