Changeset 1536


Ignore:
Timestamp:
Jan 13, 2010 6:39:15 PM (10 years ago)
Author:
pbonami
Message:

Port Claudia's code to trunk

Location:
trunk/Bonmin/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Bonmin/src/Algorithms/BonSubMipSolver.cpp

    r1424 r1536  
    1818#ifdef COIN_HAS_CPX
    1919#include "OsiCpxSolverInterface.hpp"
     20
     21#define CHECK_CPX_STAT(a,b) if(b) throw CoinError("Error in CPLEX call",__FILE__,a);
     22
    2023#endif
    2124
     
    7477
    7578 void
    76  SubMipSolver::find_good_sol(double cutoff, int loglevel, double max_time,
    77                                     int max_node){
     79 SubMipSolver::find_good_sol(double cutoff, int loglevel, double max_time){
    7880
    7981     if(clp_){
     
    98100      cbc_->setLogLevel(loglevel);
    99101      cbc_->solver()->messageHandler()->setLogLevel(0);
    100       cbc_->setMaximumNodes(max_node);
    101102      cbc_->setMaximumSeconds(max_time);
    102103      cbc_->setMaximumSolutions(1);
     
    137138        CPXENVptr env = cpx_->getEnvironmentPtr();
    138139        CPXLPptr cpxlp = cpx_->getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL);
    139         CPXsetintparam(env, CPX_PARAM_NODELIM, max_node);
    140140        CPXsetdblparam(env, CPX_PARAM_TILIM, max_time);
    141141        CPXsetdblparam(env, CPX_PARAM_CUTUP, cutoff);
     
    173173
    174174  void
    175   SubMipSolver::optimize(double cutoff, int loglevel, double maxTime,
    176       int maxNodes)
     175  SubMipSolver::optimize(double cutoff, int loglevel, double maxTime)
    177176  {
    178177    if (clp_) {
     
    196195      cbc_->setLogLevel(loglevel);
    197196      cbc_->solver()->messageHandler()->setLogLevel(0);
    198       cbc_->setMaximumNodes(maxNodes);
    199197      cbc_->setMaximumSeconds(maxTime);
    200198      cbc_->setCutoff(cutoff);
     
    226224      if (cpx_) {
    227225        CPXENVptr env = cpx_->getEnvironmentPtr();
    228         CPXsetintparam(env, CPX_PARAM_NODELIM, maxNodes);
    229226        CPXsetdblparam(env, CPX_PARAM_TILIM, maxTime);
    230227        CPXsetdblparam(env, CPX_PARAM_CUTUP, cutoff);
  • trunk/Bonmin/src/Algorithms/BonSubMipSolver.hpp

    r1424 r1536  
    5252      void find_good_sol(double cutoff,
    5353          int loglevel,
    54           double maxTime,
    55           int maxNodes);
     54          double maxTime);
    5655
    5756      /** update cutoff and optimize MIP. */
    5857      void optimize(double cutoff,
    5958          int loglevel,
    60           double maxTime,
    61           int maxNodes);
     59          double maxTime);
    6260
    6361      /** Returns lower bound. */
  • trunk/Bonmin/src/Algorithms/Branching/BonLpBranchingSolver.hpp

    r1407 r1536  
    1717
    1818  public:
    19 
    20 #if 0
    21     /// Constructor from solver (so we can set up arrays etc)
    22     LpBranchingSolver (OsiTMINLPInterface * solver);
    23 #endif
    2419
    2520    /// Constructor from setup
  • trunk/Bonmin/src/Algorithms/OaGenerators/BonFpForMinlp.cpp

    r1514 r1536  
    2121#include "BonSolverHelp.hpp"
    2222
     23#include <climits>
    2324
    2425namespace Bonmin
     
    5859    double oaTime;
    5960    b.options()->GetNumericValue("time_limit",oaTime,prefix);
     61    parameter().maxLocalSearch_ = INT_MAX;
    6062    b.options()->GetIntegerValue("solution_limit", parameter().maxSols_,prefix);
    61     parameter().localSearchNodeLimit_ = 1000000;
    62     parameter().maxLocalSearch_ = 100000;
    63     parameter().maxLocalSearchPerNode_ = 10000;
    6463    parameter().maxLocalSearchTime_ =
    6564    std::min(b.getDoubleParameter(BabSetupBase::MaxTime), oaTime);
     
    7776  {
    7877    return (nLocalSearch_<parameters_.maxLocalSearch_ &&
    79         parameters_.localSearchNodeLimit_ > 0 &&
    8078        CoinCpuTime() - timeBegin_ < parameters_.maxLocalSearchTime_ &&
    8179        numSols_ < parameters_.maxSols_);
     
    9088  {
    9189
    92     bool interuptOnLimit = false;
    93     double lastPeriodicLog = CoinCpuTime();
     90    //bool interuptOnLimit = false;
     91    //double lastPeriodicLog = CoinCpuTime();
    9492
    9593    const int numcols = nlp_->getNumCols();
     
    127125      subMip->find_good_sol(DBL_MAX, parameters_.subMilpLogLevel_,
    128126      //subMip->optimize(DBL_MAX, parameters_.subMilpLogLevel_,
    129           (parameters_.maxLocalSearchTime_ + timeBegin_ - CoinCpuTime()) /* time limit */,
    130           parameters_.localSearchNodeLimit_);
     127          (parameters_.maxLocalSearchTime_ + timeBegin_ - CoinCpuTime()) /* time limit */);
    131128
    132129      milpOptimal = subMip -> optimal();
     
    151148
    152149      //after a prescribed elapsed time give some branch_information to user
    153       double time = CoinCpuTime();
     150      //double time = CoinCpuTime();
    154151
    155152
     
    226223      //do we perform a new local search ?
    227224      if (nLocalSearch_ < parameters_.maxLocalSearch_ &&
    228           numberPasses < parameters_.maxLocalSearchPerNode_ &&
    229           parameters_.localSearchNodeLimit_ > 0 && numSols_ < parameters_.maxSols_) {
     225          numSols_ < parameters_.maxSols_) {
    230226
    231227        /** do we have a subMip? if not create a new one. */
     
    239235        subMip->find_good_sol(DBL_MAX, parameters_.subMilpLogLevel_,
    240236        //subMip->optimize(DBL_MAX, parameters_.subMilpLogLevel_,
    241                          parameters_.maxLocalSearchTime_ + timeBegin_ - CoinCpuTime(),
    242                          parameters_.localSearchNodeLimit_);
     237                         parameters_.maxLocalSearchTime_ + timeBegin_ - CoinCpuTime());
    243238        milpOptimal = subMip -> optimal();
    244239        colsol = subMip->getLastSolution();
  • trunk/Bonmin/src/Algorithms/OaGenerators/BonOACutGenerator2.cpp

    r1511 r1536  
    2121#include "BonSolverHelp.hpp"
    2222
     23#include <climits>
    2324
    2425namespace Bonmin
     
    6263    parameter().maxLocalSearchTime_ =
    6364    std::min(b.getDoubleParameter(BabSetupBase::MaxTime), oaTime);
     65    parameter().maxLocalSearch_ = INT_MAX;
    6466    b.options()->GetIntegerValue("solution_limit", parameter().maxSols_,prefix);
    65     parameter().localSearchNodeLimit_ = 1000000;
    66     parameter().maxLocalSearch_ = 100000;
    67     parameter().maxLocalSearchPerNode_ = 10000;
    6867  }
    6968  OACutGenerator2::~OACutGenerator2()
     
    7574  {
    7675    return (nLocalSearch_<parameters_.maxLocalSearch_ &&
    77         parameters_.localSearchNodeLimit_ > 0 &&
    78         CoinCpuTime() - timeBegin_ < parameters_.maxLocalSearchTime_ &&
    79         numSols_ < parameters_.maxSols_);
     76            CoinCpuTime() - timeBegin_ < parameters_.maxLocalSearchTime_);
    8077  }
    8178  /// virtual method which performs the OA algorithm by modifying lp and nlp.
     
    8885  {
    8986
    90     bool interuptOnLimit = false;
    9187    double lastPeriodicLog = CoinCpuTime();
    9288
     
    108104    {
    109105      subMip->find_good_sol(cutoff, parameters_.subMilpLogLevel_,
    110           (parameters_.maxLocalSearchTime_ + timeBegin_ - CoinCpuTime()) /* time limit */,
    111           parameters_.localSearchNodeLimit_);
     106          (parameters_.maxLocalSearchTime_ + timeBegin_ - CoinCpuTime()));
    112107      milpBound = subMip->lowBound();
    113108      milpOptimal = subMip->optimal();
     
    211206      if (feasible && !isInteger &&
    212207          nLocalSearch_ < parameters_.maxLocalSearch_ &&
    213           numberPasses < parameters_.maxLocalSearchPerNode_ &&
    214           parameters_.localSearchNodeLimit_ > 0 && numSols_ < parameters_.maxSols_) {
     208          numSols_ < parameters_.maxSols_) {
    215209
    216210        /** do we have a subMip? if not create a new one. */
     
    220214
    221215        subMip->find_good_sol(cutoff, parameters_.subMilpLogLevel_,
    222             parameters_.maxLocalSearchTime_ + timeBegin_ - CoinCpuTime(),
    223             parameters_.localSearchNodeLimit_);
     216            parameters_.maxLocalSearchTime_ + timeBegin_ - CoinCpuTime()
     217            );
    224218
    225219        milpBound = subMip->lowBound();
  • trunk/Bonmin/src/Algorithms/OaGenerators/BonOaDecBase.cpp

    r1510 r1536  
    2323#ifdef COIN_HAS_CPX
    2424#include "OsiCpxSolverInterface.hpp"
     25
     26#define CHECK_CPX_STAT(a,b) if(b) throw CoinError("Error in CPLEX call",__FILE__,a);
     27
    2528#endif
    2629#include "BonCbc.hpp"
     
    117120      cbcCutoffIncrement_(1e-06),
    118121      cbcIntegerTolerance_(1e-05),
    119       localSearchNodeLimit_(0),
    120       maxLocalSearchPerNode_(0),
    121122      maxLocalSearch_(0),
    122123      maxLocalSearchTime_(3600),
     
    140141      cbcCutoffIncrement_(other.cbcCutoffIncrement_),
    141142      cbcIntegerTolerance_(other.cbcIntegerTolerance_),
    142       localSearchNodeLimit_(other.localSearchNodeLimit_),
    143       maxLocalSearchPerNode_(other.maxLocalSearchPerNode_),
    144143      maxLocalSearch_(other.maxLocalSearch_),
    145144      maxLocalSearchTime_(other.maxLocalSearchTime_),
  • trunk/Bonmin/src/Algorithms/OaGenerators/BonOaDecBase.hpp

    r1510 r1536  
    172172      /// integer tolerance (has to be the same as Cbc's)
    173173      double cbcIntegerTolerance_;
    174       ///Max number of nodes for local search
    175       int localSearchNodeLimit_;
    176       ///Max number of local searches per node
    177       int maxLocalSearchPerNode_;
    178174      ///Total max number of local searches
    179175      int maxLocalSearch_;
  • trunk/Bonmin/src/Algorithms/OaGenerators/BonOaFeasChecker.cpp

    r1511 r1536  
    7676
    7777      const double * toCut = (parameter().addOnlyViolated_)?
    78           colsol:NULL;
     78                             colsol:NULL;
    7979      if(cut_count_ <= maximum_oa_cuts_ && type_ == OA)
    8080        nlp_->getOuterApproximation(cs, nlpSol, 1, toCut,
  • trunk/Bonmin/src/CbcBonmin/BonCbc.cpp

    r1512 r1536  
    470470      }
    471471
     472       //Added by Claudia
     473       OsiTMINLPInterface * nlpSolver = dynamic_cast<OsiTMINLPInterface *>(model_.solver());
     474       if(nlpSolver && nlpSolver->getNewCutoffDecr()!=COIN_DBL_MAX)
     475          model_.setDblParam(CbcModel::CbcCutoffIncrement, nlpSolver->getNewCutoffDecr());
     476
    472477    model_.solver()->resolve();
    473478
  • trunk/Bonmin/src/Interfaces/Ampl/BonAmplTMINLP.cpp

    r1489 r1536  
    6464      :
    6565      TMINLP(),
     66      appName_(),
    6667      upperBoundingObj_(-1),
    6768      ampl_tnlp_(NULL),
     
    8889      :
    8990      TMINLP(),
     91      appName_(),
    9092      upperBoundingObj_(-1),
    9193      ampl_tnlp_(NULL),
     
    669671      solve_result_num = 220;
    670672    }
     673    else if (status == TMINLP::CONTINUOUS_UNBOUNDED) {
     674      status_str = "\t\"Finished\"";
     675      message = "\n" + appName_ +" Continuous relaxation is unbounded.";
     676      solve_result_num = 300;
     677    }
    671678    else if (status == TMINLP::LIMIT_EXCEEDED) {
    672679      status_str = "\t\"Not finished\"";
     
    688695    else {
    689696      std::cout<<status_str<<message<<std::endl;
    690       std::ofstream of("bonmin.sol");
     697      std::string fName = appName_ + ".sol";
     698      std::ofstream of(fName.c_str());
    691699      for (int i = 0 ; i < n ; i++) {
    692700        of<<i<<"\t"<<x[i]<<std::endl;
     
    765773
    766774
     775
    767776  /** This method to returns the value of an alternative objective function for
    768777  upper bounding (if one has been declared by using the prefix UBObj).*/
  • trunk/Bonmin/src/Interfaces/Ampl/BonAmplTMINLP.hpp

    r1489 r1536  
    212212    virtual void getLinearPartOfObjective(double * obj);
    213213
     214
    214215    /** Do we have an alternate objective for upper bounding?*/
    215216    virtual bool hasUpperBoundingObjective()
     
    277278    void operator=(const AmplTMINLP&);
    278279    //@}
    279 
    280280     /** Name of application.*/
    281281    std::string appName_;
  • trunk/Bonmin/src/Interfaces/BonOsiTMINLPInterface.cpp

    r1512 r1536  
    151151
    152152
     153  roptions->AddStringOption2("dynamic_def_cutoff_decr",
     154      "Do you want to define the parameter cutoff_decr dynamically?",
     155      "no",
     156      "no", "No, define it statically",
     157      "yes","Yes, define it dynamically");
     158  roptions->setOptionExtraInfo("dynamic_def_cutoff_decr",8);
     159
     160  roptions->AddLowerBoundedNumberOption("coeff_var_threshold",
     161      "Coefficient of variation threshold (for dynamic definition of cutoff_decr).",
     162      0.0,
     163      false,
     164      0.1,
     165      "Coefficient of variation threshold (for dynamic definition of cutoff_decr).");
     166  roptions->setOptionExtraInfo("coeff_var_threshold",8);
     167 
     168  roptions->AddNumberOption("first_perc_for_cutoff_decr",
     169      "The percentage used when, the coeff of variance is smaller than the threshold, to compute the cutoff_decr dynamically.",
     170      -0.02,
     171      "The percentage used when, the coeff of variance is smaller than the threshold, to compute the cutoff_decr dynamically.");
     172  roptions->setOptionExtraInfo("first_perc_for_cutoff_decr",8);
     173
     174  roptions->AddNumberOption("second_perc_for_cutoff_decr",
     175      "The percentage used when, the coeff of variance is greater than the threshold, to compute the cutoff_decr dynamically.",
     176      -0.05,
     177      "The percentage used when, the coeff of variance is greater than the threshold, to compute the cutoff_decr dynamically.");
     178  roptions->setOptionExtraInfo("second_perc_for_cutoff_decr",8);
    153179
    154180  }
     
    362388    cutStrengthener_(NULL),
    363389    oaMessages_(),
    364     oaHandler_(NULL)
     390    oaHandler_(NULL),
     391    newCutoffDecr(COIN_DBL_MAX),
     392    dynamicCutOff_(0),
     393    coeff_var_threshold_(0.1),
     394    first_perc_for_cutoff_decr_(-0.02),
     395    second_perc_for_cutoff_decr_(-0.05)
     396
    365397{
    366398   oaHandler_ = new OaMessageHandler;
     
    526558    oaMessages_(),
    527559    oaHandler_(NULL),
    528     strong_branching_solver_(source.strong_branching_solver_)
     560    newCutoffDecr(source.newCutoffDecr),
     561    strong_branching_solver_(source.strong_branching_solver_),
     562    dynamicCutOff_(source.dynamicCutOff_),
     563    coeff_var_threshold_(source.coeff_var_threshold_),
     564    first_perc_for_cutoff_decr_(source.first_perc_for_cutoff_decr_),
     565    second_perc_for_cutoff_decr_(source.second_perc_for_cutoff_decr_)
    529566{
    530567   if(0 && defaultHandler()){
     
    643680      infty_ = rhs.infty_;
    644681      exposeWarmStart_ = rhs.exposeWarmStart_;
     682      newCutoffDecr = rhs.newCutoffDecr;
    645683
    646684    }
     
    683721    strong_branching_solver_ = rhs.strong_branching_solver_;
    684722
     723    dynamicCutOff_ = rhs.dynamicCutOff_;
     724    coeff_var_threshold_ = rhs.coeff_var_threshold_;
     725    first_perc_for_cutoff_decr_ = rhs.first_perc_for_cutoff_decr_;
     726    second_perc_for_cutoff_decr_ = rhs.second_perc_for_cutoff_decr_;
     727
    685728    freeCachedData();
    686729  }
     
    778821  warmstart_ = NULL;
    779822 
     823  double * of_current = (numsolve > 0) ? new double[numsolve]: NULL;
     824  int num_failed, num_infeas;
     825  double mean, std_dev, var_coeff;
     826  double min = DBL_MAX;
     827  double max = -DBL_MAX;
     828
    780829  Coin::SmartPtr<SimpleReferencedPtr<CoinWarmStart> > ws_backup = NULL;
    781830  if(!exposeWarmStart_ && keepWarmStart){
     
    803852    <<1
    804853    <<CoinMessageEol;
     854
     855  num_failed = 0;
     856  num_infeas = 0;
     857  mean = 0;
     858
    805859  for(int f = 0; f < numsolve ; f++) {
    806860    messageHandler()->message(WARNING_RESOLVING,
     
    828882    <<c<<f+1<<statusAsString()<<getObjValue()<<app_->IterationCount()<<app_->CPUTime()<<"resolve cost"<<CoinMessageEol;
    829883
    830 
    831     if(isProvenOptimal())
     884    if(isAbandoned()) {
     885      num_failed++;
     886    }
     887    else if(isProvenPrimalInfeasible()) {
     888       num_infeas++;
     889    }
     890
     891    else if(isProvenOptimal())
    832892      messageHandler()->message(SOLUTION_FOUND,
    833893          messages_)
     
    844904      <<f+2
    845905      <<CoinMessageEol;
    846   }
     906
     907  if(of_current != NULL){
     908    if(isProvenOptimal())
     909    {
     910      of_current[f] = getObjValue();
     911      mean=mean+of_current[f];
     912      if (of_current[f] < min)
     913         min = of_current[f];
     914      else if (of_current[f] > max)
     915         max = of_current[f];
     916    }
     917    else
     918    {
     919      of_current[f] = 0;
     920    }
     921  }
     922}
     923
     924
     925  if(of_current != NULL){
     926     //calculate the mean
     927     mean=mean/(numsolve-num_failed-num_infeas);
     928     
     929     std_dev = 0;
     930     
     931     //calculate the std deviation
     932     for(int i=0; i<numsolve; i++)
     933     {
     934       if(of_current[i]!=0)
     935         std_dev=std_dev+pow(of_current[i]-mean,2);
     936     }
     937     std_dev=pow((std_dev/(numsolve-num_failed-num_infeas)),0.5);
     938     
     939     //calculate coeff of variation
     940     var_coeff=std_dev/mean;
     941  }
     942
     943
     944
    847945  setColSolution(point());
    848946  setRowPrice(point() + getNumCols());
    849947  app_->enableWarmStart();
     948
     949
     950  if(dynamicCutOff_)
     951  {
     952     if(var_coeff<0.1)
     953     {
     954        setNewCutoffDecr(mean*first_perc_for_cutoff_decr_);
     955     }
     956     else
     957     {
     958        setNewCutoffDecr(mean*second_perc_for_cutoff_decr_);
     959     }
     960  }
     961     
    850962
    851963  optimizationStatus_ = app_->ReOptimizeTNLP(GetRawPtr(problem_to_optimize_));
  • trunk/Bonmin/src/Interfaces/BonOsiTMINLPInterface.hpp

    r1512 r1536  
    240240    hasContinuedAfterNlpFailure_ = true;
    241241  }
     242
     243
     244  //Added by Claudia
     245 
     246  double getNewCutoffDecr()
     247  {
     248    return newCutoffDecr;
     249  }
     250
     251  void setNewCutoffDecr(double d)
     252  {
     253    newCutoffDecr = d;
     254  }
     255
     256
    242257  /// Did we continue on a failure
    243258  bool hasContinuedOnAFailure()
     
    11551170  /// Number of times problem will be resolved in case of a failure
    11561171  int numRetryUnsolved_;
     1172
     1173
     1174  //Added by Claudia
     1175  /// Dynamic cutOff_
     1176  int dynamicCutOff_;
     1177  /// coeff_var_threshold_
     1178  double coeff_var_threshold_;
     1179  /// first_perc_for_cutoff_decr_
     1180  double first_perc_for_cutoff_decr_;
     1181  /// second_perc_for_cutoff_decr_
     1182  double second_perc_for_cutoff_decr_;
     1183 
     1184
    11571185  /** Messages specific to an OsiTMINLPInterface. */
    11581186  Messages messages_;
     
    12211249  OaMessageHandler * oaHandler_;
    12221250  //@}
     1251
     1252  double newCutoffDecr;
    12231253protected:
    12241254  /** Facilitator to create an application. */
Note: See TracChangeset for help on using the changeset viewer.