Changeset 395


Ignore:
Timestamp:
Jul 3, 2006 7:07:32 AM (13 years ago)
Author:
forrest
Message:

for cut generators

Location:
trunk/Cbc/src
Files:
5 edited

Legend:

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

    r310 r395  
    2929    atSolution_(false),
    3030    whenInfeasible_(false),
     31    mustCallAgain_(false),
     32    switchedOff_(false),
    3133    timing_(false),
    3234    timeInCutGenerator_(0.0),
     
    4749    depthCutGenerator_(whatDepth),
    4850    depthCutGeneratorInSub_(whatDepthInSub),
     51    mustCallAgain_(false),
     52    switchedOff_(false),
    4953    timing_(false),
    5054    timeInCutGenerator_(0.0),
     
    8488  atSolution_=rhs.atSolution_;
    8589  whenInfeasible_=rhs.whenInfeasible_;
     90  mustCallAgain_ = rhs.mustCallAgain_;
     91  switchedOff_ = rhs.switchedOff_;
    8692  timing_ = rhs.timing_;
    8793  timeInCutGenerator_ = rhs.timeInCutGenerator_;
     
    111117    atSolution_=rhs.atSolution_;
    112118    whenInfeasible_=rhs.whenInfeasible_;
     119    mustCallAgain_ = rhs.mustCallAgain_;
     120    switchedOff_ = rhs.switchedOff_;
    113121    timing_ = rhs.timing_;
    114122    timeInCutGenerator_ = rhs.timeInCutGenerator_;
  • trunk/Cbc/src/CbcCutGenerator.hpp

    r259 r395  
    215215  inline bool needsOptimalBasis() const
    216216  { return generator_->needsOptimalBasis();};
     217  /// Whether generator MUST be called again if any cuts (i.e. ignore break from loop)
     218  inline bool mustCallAgain() const
     219  { return mustCallAgain_;};
     220  /// Set whether generator MUST be called again if any cuts (i.e. ignore break from loop)
     221  inline void setMustCallAgain(bool yesNo)
     222  { mustCallAgain_=yesNo;};
     223  /// Whether generator switched off for moment
     224  inline bool switchedOff() const
     225  { return switchedOff_;};
     226  /// Set whether generator switched off for moment
     227  inline void setSwitchedOff(bool yesNo)
     228  { switchedOff_=yesNo;};
    217229  //@}
    218230 
     
    258270  /// Whether to call generator when a subproblem is found to be infeasible
    259271  bool whenInfeasible_;
     272  /// Whether generator MUST be called again if any cuts (i.e. ignore break from loop)
     273  bool mustCallAgain_;
     274  /// Temporary switch off marker
     275  bool switchedOff_;
    260276  /// Whether call generator being timed
    261277  bool timing_;
  • trunk/Cbc/src/CbcModel.cpp

    r391 r395  
    619619*/
    620620  synchronizeModel() ;
    621   assert (!solverCharacteristics_);
    622   OsiBabSolver * solverCharacteristics = dynamic_cast<OsiBabSolver *> (solver_->getAuxiliaryInfo());
    623   if (solverCharacteristics) {
    624     solverCharacteristics_ = solverCharacteristics;
    625   } else {
    626     // replace in solver
    627     OsiBabSolver defaultC;
    628     solver_->setAuxiliaryInfo(&defaultC);
    629     solverCharacteristics_ = dynamic_cast<OsiBabSolver *> (solver_->getAuxiliaryInfo());
     621  if (!solverCharacteristics_) {
     622    OsiBabSolver * solverCharacteristics = dynamic_cast<OsiBabSolver *> (solver_->getAuxiliaryInfo());
     623    if (solverCharacteristics) {
     624      solverCharacteristics_ = solverCharacteristics;
     625    } else {
     626      // replace in solver
     627      OsiBabSolver defaultC;
     628      solver_->setAuxiliaryInfo(&defaultC);
     629      solverCharacteristics_ = dynamic_cast<OsiBabSolver *> (solver_->getAuxiliaryInfo());
     630    }
    630631  }
    631632  solverCharacteristics_->setSolver(solver_);
     
    641642  bool feasible;
    642643  // If NLP then we assume already solved outside branchAndbound
    643   if (!solverCharacteristics_->solverType()) {
     644  if (!solverCharacteristics_->solverType()||solverCharacteristics_->solverType()==4) {
    644645    feasible=resolve(NULL,0) != 0 ;
    645646  } else {
     
    831832    // replace solverType
    832833    if(solverCharacteristics_->tryCuts())  {
     834
    833835      if (numberUnsatisfied)   {
    834836        feasible = solveWithCuts(cuts,maximumCutPassesAtRoot_,
    835837                                 NULL);
    836       } else if (solverCharacteristics_->solutionAddsCuts()) {
     838      } else if (solverCharacteristics_->solutionAddsCuts()||
     839                 solverCharacteristics_->alwaysTryCutsAtRootNode()) {
    837840        // may generate cuts and turn the solution
    838841        //to an infeasible one
     
    18961899  public methods.
    18971900*/
    1898   if (bestSolution_&&solverCharacteristics_->solverType()<2)
     1901  if (bestSolution_&&(solverCharacteristics_->solverType()<2||solverCharacteristics_->solverType()==4))
    18991902  { setCutoff(1.0e50) ; // As best solution should be worse than cutoff
    19001903    phase_=5;
     
    36783681  currentPassNumber_ = 0 ;
    36793682  double primalTolerance = 1.0e-7 ;
     3683  // We may need to keep going on
     3684  bool keepGoing=false;
    36803685/*
    36813686  Begin cut generation loop. Cuts generated during each iteration are
     
    36943699  { currentPassNumber_++ ;
    36953700    numberTries-- ;
     3701    if (numberTries<0&&keepGoing) {
     3702      // switch off all normal ones
     3703      for (int i = 0;i<numberCutGenerators_;i++) {
     3704        if (!generator_[i]->mustCallAgain())
     3705          generator_[i]->setSwitchedOff(true);
     3706      }
     3707    }
     3708    keepGoing=false;
    36963709    OsiCuts theseCuts ;
    36973710/*
     
    37883801        if (generator_[i]->needsOptimalBasis()&&!solver_->basisIsAvailable())
    37893802          generate=false;
     3803        if (generator_[i]->switchedOff())
     3804          generate=false;;
    37903805        if (generate) {
    37913806          bool mustResolve =
    37923807            generator_[i]->generateCuts(theseCuts,fullScan,node) ;
     3808          if(numberRowCutsBefore < theseCuts.sizeRowCuts() &&
     3809             generator_[i]->mustCallAgain())
     3810            keepGoing=true; // say must go round
    37933811#ifdef CBC_DEBUG
    37943812          {
     
    41784196        lastNumberCuts = numberNewCuts_ ;
    41794197        if (direction*solver_->getObjValue() < lastObjective+minimumDrop &&
    4180             currentPassNumber_ >= 3)
     4198            currentPassNumber_ >= 3 && !keepGoing)
    41814199          { numberTries = 0 ; }
    41824200        if (numberRowCuts+numberColumnCuts == 0 || cutIterations == 0)
     
    42044222      numberTries = 0 ;
    42054223    }
    4206   } while (numberTries>0) ;
     4224  } while (numberTries>0||keepGoing) ;
     4225  {
     4226    // switch on
     4227    for (int i = 0;i<numberCutGenerators_;i++)
     4228      generator_[i]->setSwitchedOff(false);
     4229  }
    42074230  //check feasibility.
    42084231  //If solution seems to be integer feasible calling setBestSolution
     
    76337656  return CoinCpuTime()-getDblParam(CbcStartSeconds);
    76347657}
     7658/*
     7659   For advanced applications you may wish to modify the behavior of Cbc
     7660   e.g. if the solver is a NLP solver then you may not have an exact
     7661   optimum solution at each step.  Information could be built into
     7662   OsiSolverInterface but this is an alternative so that that interface
     7663   does not have to be changed.  If something similar is useful to
     7664   enough solvers then it could be migrated.
     7665   You can also pass in by using solver->setAuxiliaryInfo.
     7666   You should do that if solver is odd - if solver is normal simplex
     7667   then use this
     7668*/
     7669void
     7670CbcModel::passInSolverCharacteristics(OsiBabSolver * solverCharacteristics)
     7671{
     7672  solverCharacteristics_ = solverCharacteristics;
     7673}
    76357674// Create C++ lines to get to current state
    76367675void
  • trunk/Cbc/src/CbcModel.hpp

    r356 r395  
    12481248      does not have to be changed.  If something similar is useful to
    12491249      enough solvers then it could be migrated
     1250      You can also pass in by using solver->setAuxiliaryInfo.
     1251      You should do that if solver is odd - if solver is normal simplex
     1252      then use this.
     1253      NOTE - characteristics are not cloned
    12501254  */
    12511255  void passInSolverCharacteristics(OsiBabSolver * solverCharacteristics);
     1256  /// Get solver characteristics
     1257  inline const OsiBabSolver * solverCharacteristics() const
     1258  { return solverCharacteristics_;};
    12521259  //@}
    12531260 
  • trunk/Cbc/src/CbcNode.cpp

    r356 r395  
    18871887  const OsiAuxInfo * auxInfo = solver->getAuxiliaryInfo();
    18881888  const OsiBabSolver * auxiliaryInfo = dynamic_cast<const OsiBabSolver *> (auxInfo);
     1889  if (!auxiliaryInfo) {
     1890    // use one from CbcModel
     1891    auxiliaryInfo = model->solverCharacteristics();
     1892  }
     1893  assert (auxiliaryInfo);
    18891894  //assert(objectiveValue_ == solver->getObjSense()*solver->getObjValue());
    18901895  double cutoff =model->getCutoff();
Note: See TracChangeset for help on using the changeset viewer.