Ignore:
Timestamp:
Jul 15, 2007 5:28:33 PM (12 years ago)
Author:
forrest
Message:

add threaded to trunk

File:
1 edited

Legend:

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

    r640 r687  
    175175                         double * betterSolution)
    176176{
     177#define LEN_PRINT 132
     178  char pumpPrint[LEN_PRINT];
     179  pumpPrint[0]='\0';
    177180  if (!when()||(when()==1&&model_->phase()!=1))
    178181    return 0; // switched off
     
    364367      }
    365368      if (maximumTime_>0.0&&CoinCpuTime()>=startTime_+maximumTime_) break;
    366       numberPasses++;
    367369      memcpy(newSolution,solution,numberColumns*sizeof(double));
    368370      int flip;
    369       returnCode = rounds(solver,newSolution,saveObjective,numberIntegers,integerVariable,
    370                           roundExpensive_,defaultRounding_,&flip);
     371      returnCode = rounds(solver, newSolution,saveObjective,numberIntegers,integerVariable,
     372                          pumpPrint,numberPasses,roundExpensive_,defaultRounding_,&flip);
     373      numberPasses++;
    371374      if (returnCode) {
    372375        // SOLUTION IS INTEGER
     
    382385          newSolutionValue += saveObjective[i]*newSolution[i];
    383386        newSolutionValue *= direction;
    384         if (model_->logLevel())
    385           printf(" - solution found of %g",newSolutionValue);
     387        sprintf(pumpPrint+strlen(pumpPrint)," - solution found of %g",newSolutionValue);
    386388        newLineNeeded=false;
    387389        if (newSolutionValue<solutionValue) {
     
    416418            solutionFound=true;
    417419            if (general&&saveValue!=newSolutionValue)
    418               printf(" - cleaned solution of %g\n",solutionValue);
    419             else
    420               printf("\n");
     420              sprintf(pumpPrint+strlen(pumpPrint)," - cleaned solution of %g",solutionValue);
     421            if (pumpPrint[0]!='\0')
     422              model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
     423                << pumpPrint
     424                <<CoinMessageEol;
     425            pumpPrint[0]='\0';
    421426          } else {
    422           if (model_->logLevel())
    423             printf(" - not good enough after small branch and bound\n");
     427            sprintf(pumpPrint+strlen(pumpPrint)," - not good enough after mini branch and bound");
     428            model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
     429              << pumpPrint
     430              <<CoinMessageEol;
     431            pumpPrint[0]='\0';
    424432          }
    425433        } else {
    426           if (model_->logLevel())
    427             printf(" - not good enough\n");
     434          sprintf(pumpPrint+strlen(pumpPrint)," - not good enough");
     435          model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
     436            << pumpPrint
     437            <<CoinMessageEol;
     438          pumpPrint[0]='\0';
    428439          newLineNeeded=false;
    429440          returnCode=0;
     
    448459        if (matched || numberPasses%100 == 0) {
    449460          // perturbation
    450           if (model_->logLevel())
    451             printf("Perturbation applied");
     461          sprintf(pumpPrint+strlen(pumpPrint)," perturbation applied");
    452462          newLineNeeded=true;
    453463          for (i=0;i<numberIntegers;i++) {
     
    531541          memcpy(newSolution,solution,numberColumns*sizeof(double));
    532542          int flip;
    533           returnCode = rounds(solver,newSolution,saveObjective,numberIntegers,integerVariable,
    534                               roundExpensive_,defaultRounding_,&flip);
     543          returnCode = rounds(solver, newSolution,saveObjective,numberIntegers,integerVariable,
     544                              pumpPrint,numberPasses,roundExpensive_,defaultRounding_,&flip);
     545          numberPasses++;
    535546          if (returnCode) {
    536547            // solution - but may not be better
     
    540551              newSolutionValue += saveObjective[i]*newSolution[i];
    541552            newSolutionValue *= direction;
    542             if (model_->logLevel())
    543               printf(" - intermediate solution found of %g",newSolutionValue);
     553            sprintf(pumpPrint+strlen(pumpPrint)," - intermediate solution found of %g",newSolutionValue);
    544554            if (newSolutionValue<solutionValue) {
    545555              memcpy(betterSolution,newSolution,numberColumns*sizeof(double));
     
    636646          }
    637647        }
    638         if (model_->logLevel())
    639           printf("\npass %3d: obj. %10.5f --> ", numberPasses+totalNumberPasses,solver->getObjValue());
     648        if (pumpPrint[0]!='\0')
     649          model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
     650            << pumpPrint
     651            <<CoinMessageEol;
     652        pumpPrint[0]='\0';
     653        sprintf(pumpPrint+strlen(pumpPrint),"Pass %3d: obj. %10.5f --> ", numberPasses+totalNumberPasses,solver->getObjValue());
    640654        if (closestSolution&&solver->getObjValue()<closestObjectiveValue) {
    641655          int i;
     
    656670      scaleFactor *= weightFactor_;
    657671    } // END WHILE
    658     if (newLineNeeded&&model_->logLevel())
    659       printf(" - no solution found\n");
     672    if (!solutionFound) {
     673      sprintf(pumpPrint+strlen(pumpPrint),"No solution found this major pass");
     674      model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
     675        << pumpPrint
     676        <<CoinMessageEol;
     677      pumpPrint[0]='\0';
     678    }
    660679    delete solver;
    661680    for ( j=0;j<NUMBER_OLD;j++)
     
    724743      newSolver->initialSolve();
    725744      if (!newSolver->isProvenOptimal()) {
    726         newSolver->writeMps("bad.mps");
     745        //newSolver->writeMps("bad.mps");
    727746        assert (newSolver->isProvenOptimal());
    728747        break;
    729748      }
    730       printf("%d integers at bound fixed and %d continuous",
     749      sprintf(pumpPrint+strlen(pumpPrint),"Before mini branch and bound, %d integers at bound fixed and %d continuous",
    731750             nFix,nFixC);
    732       if (nFixC2+nFixI==0)
    733         printf("\n");
    734       else
    735         printf(" of which %d were internal integer and %d internal continuous\n",
    736              nFixI,nFixC2);
     751      if (nFixC2+nFixI!=0)
     752        sprintf(pumpPrint+strlen(pumpPrint)," of which %d were internal integer and %d internal continuous",
     753                nFixI,nFixC2);
     754      model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
     755        << pumpPrint
     756        <<CoinMessageEol;
     757      pumpPrint[0]='\0';
    737758      double saveValue = newSolutionValue;
    738759      returnCode = smallBranchAndBound(newSolver,numberNodes_,newSolution,newSolutionValue,
    739                                        newSolutionValue,"CbcHeuristicLocalAfterFPump");
     760                                       cutoff,"CbcHeuristicLocalAfterFPump");
    740761      if ((returnCode&2)!=0) {
    741762        // could add cut
     
    743764      }
    744765      if (returnCode) {
    745         printf("old sol of %g new of %g\n",saveValue,newSolutionValue);
     766        sprintf(pumpPrint+strlen(pumpPrint),"Mini branch and bound improved solution from %g to %g",saveValue,newSolutionValue);
     767        model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
     768          << pumpPrint
     769          <<CoinMessageEol;
     770        pumpPrint[0]='\0';
    746771        memcpy(betterSolution,newSolution,numberColumns*sizeof(double));
    747772        if (fixContinuous) {
     
    763788            double value = newSolver->getObjValue()*newSolver->getObjSense();
    764789            if (value<newSolutionValue) {
    765               printf("freeing continuous gives a solution of %g\n", value);
     790              sprintf(pumpPrint+strlen(pumpPrint),"Freeing continuous variables gives a solution of %g", value);
     791              model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
     792                << pumpPrint
     793                <<CoinMessageEol;
     794              pumpPrint[0]='\0';
    766795              newSolutionValue=value;
    767796              memcpy(betterSolution,newSolver->getColSolution(),numberColumns*sizeof(double));
    768797            }
    769798          } else {
    770             newSolver->writeMps("bad3.mps");
     799            //newSolver->writeMps("bad3.mps");
    771800          }
    772801        }
     
    786815      double gap = relativeIncrement_*fabs(solutionValue);
    787816      cutoff -= CoinMax(CoinMax(gap,absoluteIncrement_),model_->getCutoffIncrement());
    788       printf("round again with cutoff of %g\n",cutoff);
     817      sprintf(pumpPrint+strlen(pumpPrint),"Round again with cutoff of %g",cutoff);
     818      model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
     819        << pumpPrint
     820        <<CoinMessageEol;
     821      pumpPrint[0]='\0';
    789822      if ((accumulate_&3)<2&&usedColumn)
    790823        memset(usedColumn,0,numberColumns);
    791       totalNumberPasses += numberPasses;
     824      totalNumberPasses += numberPasses-1;
    792825    } else {
    793826      break;
     
    817850    newSolver->addRow(numberIntegersOrig,closestSolution,
    818851                      lastSolution,-COIN_DBL_MAX,rhs+10.0);
    819     double saveValue = newSolutionValue;
     852    //double saveValue = newSolutionValue;
    820853    //newSolver->writeMps("sub");
    821854    int returnCode = smallBranchAndBound(newSolver,numberNodes_,newSolution,newSolutionValue,
     
    857890                          const double * objective,
    858891                          int numberIntegers, const int * integerVariable,
     892                          char * pumpPrint, int & iter,
    859893                          bool roundExpensive, double downValue, int *flip)
    860894{
     
    865899  int i;
    866900
    867   static int iter = 0;
    868901  int numberColumns = model_->getNumCols();
    869902  // tmp contains the current obj coefficients
     
    905938
    906939  if (nnv > nn) nnv = nn;
    907   if (iter != 0&&model_->logLevel())
    908     printf("up = %5d , down = %5d", flip_up, flip_down); fflush(stdout);
     940  if (iter != 0)
     941    sprintf(pumpPrint+strlen(pumpPrint),"up = %5d , down = %5d", flip_up, flip_down);
    909942  *flip = flip_up + flip_down;
    910943  delete [] tmp;
     
    913946  const double * columnUpper = solver->getColUpper();
    914947  if (*flip == 0 && iter != 0) {
    915     if(model_->logLevel())
    916       printf(" -- rand = %4d (%4d) ", nnv, nn);
     948    sprintf(pumpPrint+strlen(pumpPrint)," -- rand = %4d (%4d) ", nnv, nn);
    917949     for (i = 0; i < nnv; i++) {
    918950       // was solution[list[i]] = 1. - solution[list[i]]; but does that work for 7>=x>=6
     
    930962     }
    931963     *flip = nnv;
    932   } else if (model_->logLevel()) {
    933     printf(" ");
     964  } else {
     965    //sprintf(pumpPrint+strlen(pumpPrint)," ");
    934966  }
    935967  delete [] list; delete [] val;
    936   iter++;
     968  //iter++;
    937969   
    938970  const double * rowLower = solver->getRowLower();
Note: See TracChangeset for help on using the changeset viewer.