Changeset 143


Ignore:
Timestamp:
Jun 5, 2005 4:09:15 AM (15 years ago)
Author:
forrest
Message:

event handler

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/CbcMessage.cpp

    r84 r143  
    2020  {CBC_MAXTIME,20,1,"Exiting on maximum time"},
    2121  {CBC_MAXSOLS,19,1,"Exiting on maximum solutions"},
     22  {CBC_EVENT,27,1,"Exiting on user event"},
    2223  {CBC_SOLUTION,4,1,"Integer solution of %g found after %d iterations and %d nodes"},
    2324  {CBC_END,5,1,"Partial search - best objective %g (best possible %g), took %d iterations and %d nodes"},
  • trunk/CbcModel.cpp

    r141 r143  
    3636// include Presolve from Clp
    3737#include "ClpPresolve.hpp"
    38 // Temporary
    3938#include "OsiClpSolverInterface.hpp"
     39#include "ClpEventHandler.hpp"
    4040#endif
    4141
     
    386386    strategy_->setupOther(*this);
    387387  }
     388  bool eventHappened=false;
     389  ClpEventHandler * eventHandler=NULL;
     390#ifdef COIN_USE_CLP
     391 {
     392   OsiClpSolverInterface * clpSolver
     393     = dynamic_cast<OsiClpSolverInterface *> (solver_);
     394   if (clpSolver) {
     395     ClpSimplex * clpSimplex = clpSolver->getModelPtr();
     396     eventHandler = clpSimplex->eventHandler();
     397   }
     398 }
     399#endif
    388400  if (!nodeCompare_)
    389401    nodeCompare_=new CbcCompareDefault();;
     
    753765  while (!tree_->empty())
    754766  { if (cutoff > getCutoff()) {
     767    if (eventHandler) {
     768      if (!eventHandler->event(ClpEventHandler::solution)) {
     769        eventHappened=true; // exit
     770      }
     771    }
    755772      // Do from deepest
    756773      tree_->cleanTree(this, getCutoff(),bestPossibleObjective_) ;
     
    787804        << numberNodes_<< nNodes<< bestObjective_<< bestPossibleObjective_
    788805        << CoinMessageEol ;
     806      if (eventHandler) {
     807        if (!eventHandler->event(ClpEventHandler::treeStatus)) {
     808          eventHappened=true; // exit
     809        }
     810      }
    789811    }
    790812    // If no solution but many nodes - signal change in strategy
     
    911933          numberSolutions_ < intParam_[CbcMaxNumSol] &&
    912934          totalTime < dblParam_[CbcMaximumSeconds] &&
    913           !stoppedOnGap)
     935          !stoppedOnGap&&!eventHappened)
    914936      {
    915937/*
     
    928950*/
    929951        if (onOptimalPath)
    930         assert (feasible);
     952          assert (feasible);
    931953        if (feasible)
    932954        { newNode = new CbcNode ;
     
    946968              anyAction = newNode->chooseBranch(this,node,numberPassesLeft) ;
    947969            } else {
    948               anyAction = newNode->chooseDynamicBranch(this,node,numberPassesLeft) ;
     970              anyAction = newNode->chooseDynamicBranch(this,NULL,numberPassesLeft) ;
    949971              if (anyAction==-3)
    950972                anyAction = newNode->chooseBranch(this,node,numberPassesLeft) ; // dynamic did nothing
    951973            }
    952             //if (onOptimalPath)
    953             //assert (anyAction!=-2); // can be useful but gives false positives on strong
     974            if (onOptimalPath)
     975              assert (anyAction!=-2); // can be useful but gives false positives on strong
    954976            numberPassesLeft--;
    955977            if (numberPassesLeft<=-1) {
     
    10361058        Clearly I need to look more carefully.
    10371059*/
     1060        if (eventHandler) {
     1061          if (!eventHandler->event(ClpEventHandler::node)) {
     1062            eventHappened=true; // exit
     1063          }
     1064        }
    10381065        assert (!newNode || newNode->objectiveValue() <= getCutoff()) ;
    10391066        if (newNode)
     
    11301157          status_ = 1 ; }
    11311158        else
     1159        if (eventHappened)
     1160        { handler_->message(CBC_EVENT,messages_) << CoinMessageEol ;
     1161          status_ = 5 ; }
     1162        else
    11321163        { handler_->message(CBC_MAXSOLS,messages_) << CoinMessageEol ;
    11331164          status_ = 1 ; }
     
    13171348  numberStrong_(5),
    13181349  numberBeforeTrust_(0),
     1350  numberPenalties_(20),
     1351  penaltyScaleFactor_(3.0),
    13191352  numberInfeasibleNodes_(0),
    13201353  problemType_(0),
     
    13971430  numberStrong_(5),
    13981431  numberBeforeTrust_(0),
     1432  numberPenalties_(20),
     1433  penaltyScaleFactor_(3.0),
    13991434  numberInfeasibleNodes_(0),
    14001435  problemType_(0),
     
    15641599  numberStrong_(rhs.numberStrong_),
    15651600  numberBeforeTrust_(rhs.numberBeforeTrust_),
     1601  numberPenalties_(rhs.numberPenalties_),
     1602  penaltyScaleFactor_(penaltyScaleFactor_),
    15661603  numberInfeasibleNodes_(rhs.numberInfeasibleNodes_),
    15671604  problemType_(rhs.problemType_),
     
    17871824    numberStrong_ = rhs.numberStrong_;
    17881825    numberBeforeTrust_ = rhs.numberBeforeTrust_;
     1826    numberPenalties_ = rhs.numberPenalties_;
     1827    penaltyScaleFactor_ = penaltyScaleFactor_;
    17891828    numberInfeasibleNodes_ = rhs.numberInfeasibleNodes_;
    17901829    problemType_ = rhs.problemType_;
     
    20212060  } else {
    20222061    numberBeforeTrust_=number;
    2023     numberStrong_ = CoinMax(numberStrong_,1);
     2062    //numberStrong_ = CoinMax(numberStrong_,1);
     2063  }
     2064}
     2065void
     2066CbcModel::setNumberPenalties(int number)
     2067{
     2068  if (number<=0) {
     2069    numberPenalties_=0;
     2070  } else {
     2071    numberPenalties_=number;
     2072  }
     2073}
     2074void
     2075CbcModel::setPenaltyScaleFactor(double value)
     2076{
     2077  if (value<=0) {
     2078    penaltyScaleFactor_=3.0;
     2079  } else {
     2080    penaltyScaleFactor_=value;
    20242081  }
    20252082}
     
    24372494  sumChangeObjective1_ += solver_->getObjValue()*solver_->getObjSense()
    24382495    - objectiveValue ;
     2496  if ( CoinCpuTime()-dblParam_[CbcStartSeconds] > dblParam_[CbcMaximumSeconds] )
     2497    numberTries=0; // exit
    24392498  //if ((numberNodes_%100)==0)
    24402499  //printf("XXa sum obj changed by %g\n",sumChangeObjective1_);
     
    28872946                          "solveWithCuts","CbcModel") ; } }
    28882947      feasible = resolve() ;
     2948      if ( CoinCpuTime()-dblParam_[CbcStartSeconds] > dblParam_[CbcMaximumSeconds] )
     2949        numberTries=0; // exit
    28892950#     ifdef CBC_DEBUG
    28902951      printf("Obj value after cuts %g %d rows\n",solver_->getObjValue(),
     
    29252986    if (feasible)
    29262987    { int cutIterations = solver_->getIterationCount() ;
    2927       takeOffCuts(cuts,whichGenerator,numberOldActiveCuts,numberNewCuts,resolveAfterTakeOffCuts_) ;
    2928       if (solver_->isDualObjectiveLimitReached()&&resolveAfterTakeOffCuts_)
    2929       { feasible = false ;
     2988      if (numberOldActiveCuts+numberNewCuts) {
     2989        takeOffCuts(cuts,whichGenerator,numberOldActiveCuts,
     2990                    numberNewCuts,resolveAfterTakeOffCuts_) ;
     2991        if (solver_->isDualObjectiveLimitReached()&&resolveAfterTakeOffCuts_)
     2992          { feasible = false ;
    29302993#       ifdef CBC_DEBUG
    2931         double z = solver_->getObjValue() ;
    2932         double cut = getCutoff() ;
    2933         printf("Lost feasibility by %g in takeOffCuts; z = %g, cutoff = %g\n",
    2934                z-cut,z,cut) ;
     2994          double z = solver_->getObjValue() ;
     2995          double cut = getCutoff() ;
     2996          printf("Lost feasibility by %g in takeOffCuts; z = %g, cutoff = %g\n",
     2997                 z-cut,z,cut) ;
    29352998#       endif
     2999          }
    29363000      }
    29373001      if (feasible)
    2938       { numberRowsAtStart = numberOldActiveCuts+numberRowsAtContinuous_ ;
    2939         lastNumberCuts = numberNewCuts ;
    2940         if (direction*solver_->getObjValue() < lastObjective+minimumDrop &&
    2941             currentPassNumber_ >= 3)
    2942         { numberTries = 0 ; }
    2943         if (numberRowCuts+numberColumnCuts == 0 || cutIterations == 0)
    2944         { break ; }
    2945         if (numberTries > 0)
    2946         { reducedCostFix() ;
     3002        { numberRowsAtStart = numberOldActiveCuts+numberRowsAtContinuous_ ;
     3003        lastNumberCuts = numberNewCuts ;
     3004        if (direction*solver_->getObjValue() < lastObjective+minimumDrop &&
     3005            currentPassNumber_ >= 3)
     3006          { numberTries = 0 ; }
     3007        if (numberRowCuts+numberColumnCuts == 0 || cutIterations == 0)
     3008          { break ; }
     3009        if (numberTries > 0)
     3010          { reducedCostFix() ;
    29473011          lastObjective = direction*solver_->getObjValue() ;
    29483012          lower = solver_->getColLower() ;
     
    29693033    }
    29703034  } while (numberTries>0) ;
     3035  // Reduced cost fix at end
     3036  //reducedCostFix();
    29713037  // If at root node do heuristics
    29723038  if (!numberNodes_) {
     
    31103176        // update size of problem
    31113177        numberRowsAtContinuous_ = solver_->getNumRows() ;
     3178        //#ifdef COIN_USE_CLP
     3179#if 0
     3180        OsiClpSolverInterface * clpSolver
     3181          = dynamic_cast<OsiClpSolverInterface *> (solver_);
     3182        if (clpSolver) {
     3183          // Maybe solver might like to know only column bounds will change
     3184          int options = clpSolver->specialOptions();
     3185          clpSolver->setSpecialOptions(options|128);
     3186          clpSolver->synchronizeModel();
     3187        }
     3188#endif
    31123189      } else {
    31133190#ifdef COIN_USE_CLP
     
    31173194        // make sure factorization can't carry over
    31183195          int options = clpSolver->specialOptions();
    3119           if (options>=0)
    3120             clpSolver->setSpecialOptions(clpSolver->specialOptions()&(~8));
     3196          clpSolver->setSpecialOptions(options&(~8));
    31213197        }
    31223198#endif
  • trunk/include/CbcMessage.hpp

    r84 r143  
    2525  CBC_MAXTIME,
    2626  CBC_MAXSOLS,
     27  CBC_EVENT,
    2728  CBC_SOLUTION,
    2829  CBC_END,
  • trunk/include/CbcModel.hpp

    r137 r143  
    552552  inline int numberBeforeTrust() const
    553553  { return numberBeforeTrust_;};
     554  /** Set the number of variables for which to compute penalties
     555      in dynamic strong branching.
     556
     557    A value of 0 disables penalties.
     558  */
     559  void setNumberPenalties(int number);
     560  /** get the number of variables for which to compute penalties
     561      in dynamic strong branching. */
     562  inline int numberPenalties() const
     563  { return numberPenalties_;};
     564  /** Get scale factor to make penalties match strong.
     565      Should/will be computed */
     566  inline double penaltyScaleFactor() const
     567  { return penaltyScaleFactor_;};
     568  /** Set scale factor to make penalties match strong.
     569      Should/will be computed */
     570  void setPenaltyScaleFactor(double value);
    554571  /** Problem type as set by user or found by analysis.  This will be extended
    555572      0 - not known
     
    557574      2 - Set partitioning ==
    558575      3 - Set covering
     576      4 - all +- 1 or all +1 and odd
    559577  */
    560578  void inline setProblemType(int number)
     
    13891407      in dynamic strong branching. (0 off) */
    13901408  int numberBeforeTrust_;
     1409  /** The number of variable sfor which to compute penalties
     1410      in dynamic strong branching. (0 off) */
     1411  int numberPenalties_;
     1412  /** Scale factor to make penalties match strong.
     1413      Should/will be computed */
     1414  double penaltyScaleFactor_;
    13911415  /// Number of nodes infeasible by normal branching (before cuts)
    13921416  int numberInfeasibleNodes_;
Note: See TracChangeset for help on using the changeset viewer.