Changeset 747


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

max times and fix bug in fpump

Location:
trunk/Cbc/src
Files:
5 edited

Legend:

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

    r741 r747  
    191191      model.setMaximumCutPassesAtRoot(CoinMin(20,model_->getMaximumCutPassesAtRoot()));
    192192      model.setParentModel(*model_);
     193      model.setOriginalColumns(process.originalColumns());
    193194      model.branchAndBound();
    194195      if (logLevel>1)
  • trunk/Cbc/src/CbcHeuristicFPump.cpp

    r738 r747  
    1717#include "CoinWarmStartBasis.hpp"
    1818#include "CoinTime.hpp"
     19#include "CbcEventHandler.hpp"
    1920
    2021
     
    273274  int numberTries=0;
    274275  CoinWarmStartBasis bestBasis;
    275   while (true) {
     276  bool exitAll=false;
     277  double saveBestObjective = model_->getMinimizationObjValue();
     278  while (!exitAll) {
    276279    int numberPasses=0;
    277280    numberTries++;
     
    358361    while (!finished) {
    359362      returnCode=0;
     363      if (model_->getCurrentSeconds()>model_->getMaximumSeconds()) {
     364        exitAll=true;
     365        break;
     366      }
    360367      // see what changed
    361368      if (usedColumn) {
     
    391398        newLineNeeded=false;
    392399        if (newSolutionValue<solutionValue) {
    393           double saveValue = newSolutionValue;
     400          double saveValue = solutionValue;
    394401          if (!doGeneral) {
    395402            int numberLeft=0;
     
    412419                returnCode &= ~2;
    413420              }
     421              if (returnCode!=1)
     422                newSolutionValue=saveValue;
    414423            }
    415424          }
    416425          if (returnCode&&newSolutionValue<saveValue) {
    417426            memcpy(betterSolution,newSolution,numberColumns*sizeof(double));
     427            solutionFound=true;
    418428            CoinWarmStartBasis * basis =
    419429              dynamic_cast<CoinWarmStartBasis *>(solver->getWarmStart()) ;
     
    421431              bestBasis = * basis;
    422432              delete basis;
     433              CbcEventHandler * handler = model_->getEventHandler();
     434              if (handler) {
     435                double * saveOldSolution = CoinCopyOfArray(model_->bestSolution(),numberColumns);
     436                double saveObjectiveValue = model_->getMinimizationObjValue();
     437                model_->setBestSolution(betterSolution,numberColumns,newSolutionValue);
     438                int action = handler->event(CbcEventHandler::heuristicSolution);
     439                if (saveOldSolution) {
     440                  model_->setBestSolution(saveOldSolution,numberColumns,saveObjectiveValue);
     441                  delete [] saveOldSolution;
     442                }
     443                if (!action||model_->getCurrentSeconds()>model_->getMaximumSeconds()) {
     444                  exitAll=true; // exit
     445                  break;
     446                }
     447              }
    423448            }
    424449            if ((accumulate_&1)!=0)
     
    434459            pumpPrint[0]='\0';
    435460          } else {
    436             sprintf(pumpPrint+strlen(pumpPrint)," - not improved by mini branch and bound");
     461            sprintf(pumpPrint+strlen(pumpPrint)," - mini branch and bound could not fix general integers");
    437462            model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
    438463              << pumpPrint
     
    565590              CoinWarmStartBasis * basis =
    566591                dynamic_cast<CoinWarmStartBasis *>(solver->getWarmStart()) ;
     592              solutionFound=true;
    567593              if (basis) {
    568594                bestBasis = * basis;
    569595                delete basis;
     596                CbcEventHandler * handler = model_->getEventHandler();
     597                if (handler) {
     598                  double * saveOldSolution = CoinCopyOfArray(model_->bestSolution(),numberColumns);
     599                  double saveObjectiveValue = model_->getMinimizationObjValue();
     600                  model_->setBestSolution(betterSolution,numberColumns,newSolutionValue);
     601                  int action = handler->event(CbcEventHandler::heuristicSolution);
     602                  if (saveOldSolution) {
     603                    model_->setBestSolution(saveOldSolution,numberColumns,saveObjectiveValue);
     604                    delete [] saveOldSolution;
     605                  }
     606                  if (!action||model_->getCurrentSeconds()>model_->getMaximumSeconds()) {
     607                    exitAll=true; // exit
     608                    break;
     609                  }
     610                }
    570611              }
    571612              if ((accumulate_&1)!=0)
     
    689730      scaleFactor *= weightFactor_;
    690731    } // END WHILE
    691     if (!solutionFound) {
     732    if (!solutionFound)
    692733      sprintf(pumpPrint+strlen(pumpPrint),"No solution found this major pass");
     734    if (strlen(pumpPrint)) {
    693735      model_->messageHandler()->message(CBC_FPUMP1,model_->messages())
    694736        << pumpPrint
     
    701743    delete [] oldSolution;
    702744    delete [] saveObjective;
    703     if (usedColumn) {
     745    if (usedColumn&&!exitAll) {
    704746      OsiSolverInterface * newSolver = model_->continuousSolver()->clone();
    705747      const double * colLower = newSolver->getColLower();
     
    829871          bestBasis = * basis;
    830872          delete basis;
     873          CbcEventHandler * handler = model_->getEventHandler();
     874          if (handler) {
     875            double * saveOldSolution = CoinCopyOfArray(model_->bestSolution(),numberColumns);
     876            double saveObjectiveValue = model_->getMinimizationObjValue();
     877            model_->setBestSolution(betterSolution,numberColumns,newSolutionValue);
     878            int action = handler->event(CbcEventHandler::heuristicSolution);
     879            if (saveOldSolution) {
     880              model_->setBestSolution(saveOldSolution,numberColumns,saveObjectiveValue);
     881              delete [] saveOldSolution;
     882            }
     883            if (!action||model_->getCurrentSeconds()>model_->getMaximumSeconds()) {
     884              exitAll=true; // exit
     885              break;
     886            }
     887          }
    831888        }
    832889      } else {
     
    842899    if (solutionFound) finalReturnCode=1;
    843900    cutoff = CoinMin(cutoff,solutionValue);
    844     if (numberTries>=maximumRetries_||!solutionFound) {
     901    if (numberTries>=maximumRetries_||!solutionFound||exitAll) {
    845902      break;
    846903    } else if (absoluteIncrement_>0.0||relativeIncrement_>0.0) {
     
    912969  if (bestBasis.getNumStructural())
    913970    model_->setBestSolutionBasis(bestBasis);
     971  model_->setMinimizationObjValue(saveBestObjective);
    914972  return finalReturnCode;
    915973}
  • trunk/Cbc/src/CbcModel.cpp

    r741 r747  
    513513  strongInfo_[2]=0;
    514514  numberStrongIterations_ = 0;
     515  // Initialize random seed
     516  CoinSeedRandom(1234567);
    515517#ifndef NDEBUG
    516518  {
     
    1008710089  }
    1008810090}
     10091// Set original columns as created by preprocessing
     10092void
     10093CbcModel::setOriginalColumns(const int * originalColumns)
     10094{
     10095  int numberColumns = getNumCols();
     10096  delete [] originalColumns_;
     10097  originalColumns_ = CoinCopyOfArray(originalColumns,numberColumns);
     10098}
    1008910099// Set the cut modifier method
    1009010100void
  • trunk/Cbc/src/CbcModel.hpp

    r738 r747  
    732732  inline int howOftenGlobalScan() const
    733733  { return howOftenGlobalScan_;}
    734   /// Original columns as created by integerPresolve
     734  /// Original columns as created by integerPresolve or preprocessing
    735735  inline int * originalColumns() const
    736736  { return originalColumns_;}
     737  /// Set original columns as created by preprocessing
     738  void setOriginalColumns(const int * originalColumns) ;
    737739
    738740  /** Set the print frequency.
     
    19661968  bool ownObjects_;
    19671969 
    1968   /// Original columns as created by integerPresolve
     1970  /// Original columns as created by integerPresolve or preprocessing
    19691971  int * originalColumns_;
    19701972  /// How often to scan global cuts
  • trunk/Cbc/src/CbcSolver.cpp

    r738 r747  
    34093409                    solver2->setHintParam(OsiDoInBranchAndCut,false,OsiHintDo) ;
    34103410                }
     3411                babModel->setOriginalColumns(process.originalColumns());
    34113412#ifdef COIN_HAS_ASL
    34123413                if (!solver2&&usingAmpl) {
Note: See TracChangeset for help on using the changeset viewer.