Changeset 1424


Ignore:
Timestamp:
Apr 27, 2009 10:53:07 PM (11 years ago)
Author:
pbonami
Message:

Strategy for Lp

Location:
trunk/Bonmin
Files:
9 edited

Legend:

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

    r1410 r1424  
    192192        "if k=-99 generate cuts only at the root node, if k=0 or 100 do not generate cuts.");
    193193    roptions->setOptionExtraInfo("Gomory_cuts",5);
    194 #if 0
     194#if 1
    195195    roptions->AddBoundedIntegerOption("probing_cuts",
    196196        "Frequency (in terms of nodes) for generating probing cuts in branch-and-cut",
     
    223223        "if k=-99 generate cuts only at the root node, if k=0 or 100 do not generate cuts.");
    224224    roptions->setOptionExtraInfo("2mir_cuts",5);
    225     roptions->AddLowerBoundedIntegerOption("flow_covers_cuts",
     225    roptions->AddLowerBoundedIntegerOption("flow_cover_cuts",
    226226        "Frequency (in terms of nodes) for generating flow cover cuts in branch-and-cut",
    227227        -100,-5,
     
    229229        "Cbc may decide to stop generating cuts, if not enough are generated at the root node, "
    230230        "if k=-99 generate cuts only at the root node, if k=0 or 100 do not generate cuts.");
    231     roptions->setOptionExtraInfo("flow_covers_cuts",5);
     231    roptions->setOptionExtraInfo("flow_cover_cuts",5);
    232232    roptions->AddLowerBoundedIntegerOption("lift_and_project_cuts",
    233233        "Frequency (in terms of nodes) for generating lift-and-project cuts in branch-and-cut",
     
    335335      cutGenerators_.push_back(cg);
    336336    }
    337     options_->GetIntegerValue("flow_covers_cuts",freq,prefix_.c_str());
     337    options_->GetIntegerValue("flow_cover_cuts",freq,prefix_.c_str());
    338338    if (freq) {
    339339      CuttingMethod cg;
  • trunk/Bonmin/src/Algorithms/BonSubMipSolver.cpp

    r1422 r1424  
    4141        dynamic_cast<OsiCpxSolverInterface *>(lp_);
    4242#endif
    43     if (strategy) strategy_ = strategy->clone();
     43    if (strategy) {
     44      strategy_ = dynamic_cast<CbcStrategyDefault *>(strategy->clone());
     45      assert(strategy_);
     46    }
    4447  }
    4548  SubMipSolver::~SubMipSolver()
     
    174177  {
    175178    if (clp_) {
    176       CbcStrategyDefault * strat_default = NULL;
    177       if (!strategy_){
    178         strat_default = new CbcStrategyDefault(1,5,5, loglevel);
    179         strat_default->setupPreProcessing();
    180         strategy_ = strat_default;
    181       }
     179      assert(strategy_);
     180      CbcStrategyDefault * strat_default = dynamic_cast<CbcStrategyDefault *>(strategy_->clone());
     181      assert(strat_default);
     182      strat_default->setupPreProcessing();
    182183
    183184      OsiBabSolver empty;
     
    218219      nodeCount_ = cbc_->getNodeCount();
    219220      iterationCount_ = cbc_->getIterationCount();
    220       if(strat_default != NULL){
    221         delete strat_default;
    222         strategy_ = NULL;
    223       }
     221      delete strat_default;
    224222    }
    225223    else {
     
    275273   /** Assign a strategy. */
    276274   void
    277    SubMipSolver::setStrategy(CbcStrategy * strategy)
     275   SubMipSolver::setStrategy(CbcStrategyDefault * strategy)
    278276   {
    279277     if (strategy_) delete strategy_;
    280      strategy_ = strategy->clone();
     278     strategy_ = dynamic_cast<CbcStrategyDefault *>(strategy->clone());
     279     assert(strategy_);
    281280   }
    282281
  • trunk/Bonmin/src/Algorithms/BonSubMipSolver.hpp

    r1407 r1424  
    1818class OsiCpxSolverInterface;
    1919class CbcStrategy;
     20class CbcStrategyDefault;
    2021class CbcModel;
    2122
     
    3637
    3738      /** Assign a strategy. */
    38       void setStrategy(CbcStrategy * strategy);
     39      void setStrategy(CbcStrategyDefault * strategy);
    3940
    4041      /** get the solution found in last local search (return NULL if no solution). */
     
    106107      double * integerSolution_;
    107108      /** Strategy for solving sub mips with cbc. */
    108       CbcStrategy * strategy_;
     109      CbcStrategyDefault * strategy_;
    109110      /** number of nodes in last mip solved.*/
    110111      int nodeCount_;
  • trunk/Bonmin/src/Algorithms/OaGenerators/BonCbcLpStrategy.cpp

    r1101 r1424  
    1818#include "CglClique.hpp"
    1919#include "CglFlowCover.hpp"
    20 #include "CglMixedIntegerRounding.hpp"
     20#include "CglMixedIntegerRounding2.hpp"
    2121#include "CglTwomir.hpp"
    2222#include "CglPreProcess.hpp"
    23 
     23#include "CbcCutGenerator.hpp"
    2424
    2525// Node selection
     
    3131namespace Bonmin
    3232{
    33   CbcOaStrategy::CbcOaStrategy(int migFreq,
    34       int probFreq,
    35       int mirFreq,
    36       int coverFreq,
    37       int minReliability,
    38       int numberStrong,
    39       int nodeSelection,
    40       double intTol,
    41       int logLevel
    42                               ):
    43       CbcStrategy(),
    44       migFreq_(migFreq),
    45       probFreq_(probFreq),
    46       mirFreq_(mirFreq),
    47       coverFreq_(coverFreq),
    48       minReliability_(minReliability),
    49       numberStrong_(numberStrong),
    50       nodeSelection_(nodeSelection),
    51       intTol_(intTol),
    52       logLevel_(logLevel)
     33
     34  CbcStrategyChooseCuts::CbcStrategyChooseCuts():
     35    CbcStrategyDefault(),
     36    genFlag_(63)
    5337  {
    54     setPreProcessState(0);
     38    CoinFillN(gen_freqs_,6,-99);
    5539  }
    5640
    57   CbcStrategy *
    58   CbcOaStrategy::clone () const
     41  CbcStrategyChooseCuts::CbcStrategyChooseCuts(const CbcStrategyChooseCuts &other):
     42    CbcStrategyDefault(other),
     43    genFlag_(other.genFlag_)
    5944  {
    60     return new CbcOaStrategy(migFreq_, probFreq_,  mirFreq_, coverFreq_, minReliability_,
    61         numberStrong_, nodeSelection_, intTol_,
    62         logLevel_);
     45    CoinCopyN(other.gen_freqs_,6,gen_freqs_);
    6346  }
    6447
    65   void
    66   CbcOaStrategy::setupCutGenerators(CbcModel & model)
     48  CbcStrategyChooseCuts::CbcStrategyChooseCuts(BabSetupBase &s,
     49                                               const std::string &prefix):
     50    CbcStrategyDefault(),
     51    genFlag_(0)
    6752  {
    68 
    69     CglGomory miGGen;
    70 
    71     CglProbing probGen;
    72     probGen.setUsingObjective(true);
    73     probGen.setMaxPass(3);
    74     probGen.setMaxProbe(100);
    75     probGen.setMaxLook(50);
    76 
    77     CglKnapsackCover knapsackGen;
    78     CglMixedIntegerRounding mixedGen;
    79 
    80     if (migFreq_ != 0)
    81       model.addCutGenerator(&miGGen,migFreq_,"GMI");
    82     if (probFreq_ != 0)
    83       model.addCutGenerator(&probGen,probFreq_,"Probing");
    84     if (coverFreq_ != 0)
    85       model.addCutGenerator(&knapsackGen,coverFreq_,"covers");
    86     if (mirFreq_ != 0)
    87       model.addCutGenerator(&mixedGen,mirFreq_,"MIR");
    88 
     53    setup(s, prefix);
    8954  }
    9055
    91 /// Setup heuristics
    92   void
    93   CbcOaStrategy::setupHeuristics(CbcModel & model)
    94 {}
     56  void CbcStrategyChooseCuts::setup(BabSetupBase &s,
     57                               const std::string &prefix){
     58    s.options()->GetIntegerValue("number_strong_branch", numberStrong_, prefix);
     59    s.options()->GetIntegerValue("number_before_trust", numberBeforeTrust_, prefix);
    9560
    96 /// Do printing stuff
    97   void
    98   CbcOaStrategy::setupPrinting(CbcModel & model,int modelLogLevel)
    99   {
    100     model.messageHandler()->setLogLevel(logLevel_);
    101     model.solver()->messageHandler()->setLogLevel(0);
    102     model.setPrintFrequency(100);
     61    int k = 0;
     62   
     63    bool set = s.options()->GetIntegerValue("probing_cuts", gen_freqs_[k], prefix);
     64    if(set==0) gen_freqs_[k] = -99;
     65    k++;
     66
     67    s.options()->GetIntegerValue("Gomory_cuts", gen_freqs_[k], prefix);
     68    if(set==0) gen_freqs_[k] = -99;
     69    k++;
     70   
     71    s.options()->GetIntegerValue("cover_cuts", gen_freqs_[k], prefix);
     72    if(set==0) gen_freqs_[k] = -99;
     73    k++;
     74   
     75    s.options()->GetIntegerValue("clique_cuts", gen_freqs_[k], prefix);
     76    if(set==0) gen_freqs_[k] = -99;
     77    k++;
     78   
     79    s.options()->GetIntegerValue("flow_cover_cuts", gen_freqs_[k], prefix);
     80    if(set==0) gen_freqs_[k] = -99;
     81    k++;
     82   
     83    s.options()->GetIntegerValue("mir_cuts", gen_freqs_[k], prefix);
     84    if(set==0) gen_freqs_[k] = -99;
     85    k++;
     86   
    10387  }
    10488
    105 // Other stuff e.g. strong branching
    106   void
    107   CbcOaStrategy::setupOther(CbcModel & model)
    108   {
    109     model.setNumberStrong(numberStrong_);
    110     model.setNumberBeforeTrust(minReliability_);
     89template<class X>
     90bool has_cg(CbcModel &model, const X& gen){
     91  int numberGenerators = model.numberCutGenerators();
     92  for (int iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
     93    CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
     94    X * cgl = dynamic_cast<X *>(generator);
     95    if (cgl) {
     96      return true;
     97    }
     98  }
     99  return false;
     100}
    111101
    112     model.setIntegerTolerance(intTol_);
     102#define ADD_CG(model, gen, setting, name) model.addCutGenerator(&gen,setting, name)
    113103
    114     // Definition of node selection strategy
    115     CbcCompareObjective compare0;
    116     CbcCompareDepth compare1;
    117     CbcCompareDefault compare2;
    118     if (nodeSelection_==0) {
    119       model.setNodeComparison(compare0);
     104  void
     105  CbcStrategyChooseCuts::setupCutGenerators(CbcModel &model){
     106    CglProbing probing;
     107    probing.setUsingObjective(true);
     108    probing.setMaxPass(1);
     109    probing.setMaxPassRoot(1);
     110    // Number of unsatisfied variables to look at
     111    probing.setMaxProbe(10);
     112    // How far to follow the consequences
     113    probing.setMaxLook(10);
     114    // Only look at rows with fewer than this number of elements
     115    probing.setMaxElements(200);
     116    probing.setMaxElementsRoot(300);
     117    //generator1.setRowCuts(3);
     118
     119    CglGomory miG;
     120    // try larger limit
     121    miG.setLimit(300);
     122
     123    CglKnapsackCover cover;
     124
     125    CglClique clique;
     126    clique.setStarCliqueReport(false);
     127    clique.setRowCliqueReport(false);
     128
     129    CglMixedIntegerRounding2 mixedGen;
     130    CglFlowCover flowGen;
     131    int k = 0;
     132
     133    if(gen_freqs_[k]!= 0 && !has_cg(model, probing)){
     134      ADD_CG(model, probing, gen_freqs_[k], "Probing");
    120135    }
    121     else if (nodeSelection_==1) {
    122       model.setNodeComparison(compare1);
     136    k++;
     137
     138    if(gen_freqs_[k]!= 0 && !has_cg(model, miG)){
     139      ADD_CG(model, miG, gen_freqs_[k], "Gomory");
    123140    }
    124     else if (nodeSelection_==2) {
    125       compare2.setWeight(0.0);
    126       model.setNodeComparison(compare2);
     141    k++;
     142   
     143    if(gen_freqs_[k] != 0 && !has_cg(model, cover)){
     144      ADD_CG(model, cover, gen_freqs_[k], "Knapsack");
    127145    }
    128     else if (nodeSelection_==3) {
    129       model.setNodeComparison(compare2);
     146    k++;
     147
     148    if(gen_freqs_[k] != 0 && !has_cg(model, clique)){
     149      ADD_CG(model, clique, gen_freqs_[k], "Clique");
    130150    }
     151    k++;
    131152
     153    if(gen_freqs_[k] != 0 && !has_cg(model, flowGen)){
     154      ADD_CG(model, flowGen, gen_freqs_[k], "FlowCover");
     155    }
     156    k++;
     157
     158    if(gen_freqs_[k] != 0 && !has_cg(model, mixedGen)){
     159      ADD_CG(model, mixedGen, gen_freqs_[k], "MixedIntegerRounding2");
     160    }
    132161  }
    133162
  • trunk/Bonmin/src/Algorithms/OaGenerators/BonCbcLpStrategy.hpp

    r481 r1424  
    1313
    1414#include "CbcStrategy.hpp"
     15#include <string>
     16#include "BonBabSetupBase.hpp"
    1517namespace Bonmin
    1618{
    17   /** A class to pass on a CbcStrategy to OA sub-milp solver.
    18    This class allows to setup GMI, MIR, probing and cover cuts frequency.
    19   Number of variables to strong branch on and minimum number of branches on a variable before its
    20   pseudo-cost is to be trusted.*/
    21   class CbcOaStrategy : public CbcStrategy
    22   {
    23   public:
    24     /// Default constructor
    25     CbcOaStrategy(
    26       int migFreq = -5,
    27       int probFreq = -5,
    28       int mirFreq = -5,
    29       int coverFreq = -5,
    30       int minReliability = 8,
    31       int numberStrong = 20,
    32       int nodeSelection = 0,
    33       double intTol = 1e-05,
    34       int logLevel = 0);
    35     /// Destructor
    36     virtual ~CbcOaStrategy()
    37     {}
    38 
    39     /// Virtual copy constructor
    40     virtual CbcStrategy * clone () const;
    41 
    42     /// Setup cut generators
    43     virtual void setupCutGenerators(CbcModel & model);
    44     /// Setup heuristics
    45     virtual void setupHeuristics(CbcModel & model);
    46     /// Do printing stuff
    47     virtual void setupPrinting(CbcModel & model,int modelLogLevel);
    48     /// Other stuff e.g. strong branching and preprocessing
    49     virtual void setupOther(CbcModel & model);
    50 
    51 
    52   private:
    53     int migFreq_;
    54     int probFreq_;
    55     int mirFreq_;
    56     int coverFreq_;
    57     int minReliability_;
    58     int numberStrong_;
    59     int nodeSelection_;
    60     double intTol_;
    61     int logLevel_;
     19  /** A class to setup default strategy for Cbc specifying which cut generators to use.*/
     20  class CbcStrategyChooseCuts : public CbcStrategyDefault {
     21     public:
     22     /** Default constructor.*/
     23     CbcStrategyChooseCuts();
     24     /** Constructor with a setup. */
     25     CbcStrategyChooseCuts(BabSetupBase &s, const std::string & prefix);
     26     /** Copy constructor.*/
     27     CbcStrategyChooseCuts(const CbcStrategyChooseCuts &other);
     28     /** Virtual copy constructor.*/
     29     CbcStrategy * clone() const{
     30       return new CbcStrategyChooseCuts(*this);
     31     }
     32     /** Setup strategy.*/
     33     void setup(BabSetupBase &s, const std::string &prefix);
     34   
     35     /// Setup cut generators
     36     virtual void setupCutGenerators(CbcModel & model);
     37 
     38     private:
     39    /** Generators frequencies.*/
     40    int gen_freqs_[6];
     41       /** Flag to say which cut generators to use.*/
     42       int genFlag_;
    6243  };
    6344}
  • trunk/Bonmin/src/Algorithms/OaGenerators/BonFpForMinlp.cpp

    r1422 r1424  
    3535    b.options()->GetEnumValue("milp_solver",ivalue,prefix);
    3636    if (ivalue <= 0) {//uses cbc
    37       //nothing to do?
     37      CbcStrategyDefault strategy;
     38      setStrategy(strategy);
    3839    }
    3940    else if (ivalue == 1) {
    40       int nodeS, nStrong, nTrust, mig, mir, probe, cover;
    41               b.options()->GetEnumValue("node_comparison",nodeS,prefix);
    42               b.options()->GetIntegerValue("number_strong_branch",nStrong, prefix);
    43               b.options()->GetIntegerValue("number_before_trust", nTrust, prefix);
    44               b.options()->GetIntegerValue("Gomory_cuts", mig, prefix);
    45 //            b.options()->GetIntegerValue("probing_cuts",probe, prefix);
    46               b.options()->GetIntegerValue("mir_cuts",mir, prefix);
    47               b.options()->GetIntegerValue("cover_cuts",cover,prefix);
    48               probe = 0;             
    49               //printf("Probing to 0\n");
    50               CbcStrategy * strategy =
    51                 new CbcOaStrategy(mig, probe, mir, cover, nTrust,
    52                     nStrong, nodeS, parameters_.cbcIntegerTolerance_, parameters_.subMilpLogLevel_);
    53               setStrategy(*strategy);
    54               delete strategy;
    55 
    56             }
    57             else if (ivalue == 2) {
    58         #ifdef COIN_HAS_CPX
    59               OsiCpxSolverInterface * cpxSolver = new OsiCpxSolverInterface;
    60               b.nonlinearSolver()->extractLinearRelaxation(*cpxSolver);
    61               assignLpInterface(cpxSolver);
    62         #else
    63               std::cerr << "You have set an option to use CPLEX as the milp\n"
    64               << "subsolver in oa decomposition. However, apparently\n"
    65               << "CPLEX is not configured to be used in bonmin.\n"
    66               << "See the manual for configuring CPLEX\n";
    67               throw -1;
    68         #endif
    69             }
    70 
    71             double oaTime;
    72             b.options()->GetNumericValue("time_limit",oaTime,prefix);
    73             parameter().localSearchNodeLimit_ = 1000000;
    74             parameter().maxLocalSearch_ = 100000;
    75             parameter().maxLocalSearchPerNode_ = 10000;
    76             parameter().maxLocalSearchTime_ =
    77             std::min(b.getDoubleParameter(BabSetupBase::MaxTime), oaTime);
    78   }
     41      CbcStrategyChooseCuts strategy(b, prefix);
     42      setStrategy(strategy);
     43    }
     44    else if (ivalue == 2) {
     45#ifdef COIN_HAS_CPX
     46      OsiCpxSolverInterface * cpxSolver = new OsiCpxSolverInterface;
     47      b.nonlinearSolver()->extractLinearRelaxation(*cpxSolver);
     48      assignLpInterface(cpxSolver);
     49#else
     50      std::cerr << "You have set an option to use CPLEX as the milp\n"
     51      << "subsolver in oa decomposition. However, apparently\n"
     52      << "CPLEX is not configured to be used in bonmin.\n"
     53      << "See the manual for configuring CPLEX\n";
     54      throw -1;
     55#endif
     56    }
     57
     58    double oaTime;
     59    b.options()->GetNumericValue("time_limit",oaTime,prefix);
     60    parameter().localSearchNodeLimit_ = 1000000;
     61    parameter().maxLocalSearch_ = 100000;
     62    parameter().maxLocalSearchPerNode_ = 10000;
     63    parameter().maxLocalSearchTime_ =
     64    std::min(b.getDoubleParameter(BabSetupBase::MaxTime), oaTime);
     65  }
     66
    7967  MinlpFeasPump::~MinlpFeasPump()
    8068  {}
  • trunk/Bonmin/src/Algorithms/OaGenerators/BonOACutGenerator2.cpp

    r1422 r1424  
    3535    b.options()->GetEnumValue("milp_solver",ivalue,prefix);
    3636    if (ivalue <= 0) {//uses cbc
    37       //nothing to do?
     37      CbcStrategyDefault strategy;
     38      setStrategy(strategy);
    3839    }
    3940    else if (ivalue == 1) {
    40       int nodeS, nStrong, nTrust, mig, mir, probe, cover;
    41       b.options()->GetEnumValue("node_comparison",nodeS,prefix);
    42       b.options()->GetIntegerValue("number_strong_branch",nStrong,prefix);
    43       b.options()->GetIntegerValue("number_before_trust", nTrust,prefix);
    44       b.options()->GetIntegerValue("Gomory_cuts", mig,prefix);
    45       //b.options()->GetIntegerValue("probing_cuts",probe,prefix);
    46       b.options()->GetIntegerValue("mir_cuts",mir,prefix);
    47       b.options()->GetIntegerValue("cover_cuts",cover,prefix);
    48      
    49       CbcStrategy * strategy =
    50         new CbcOaStrategy(mig, probe, mir, cover, nTrust,
    51             nStrong, nodeS, parameters_.cbcIntegerTolerance_, parameters_.subMilpLogLevel_);
    52       setStrategy(*strategy);
    53       delete strategy;
    54 
     41      CbcStrategyChooseCuts strategy(b, prefix);
     42      setStrategy(strategy);
    5543    }
    5644    else if (ivalue == 2) {
  • trunk/Bonmin/src/Algorithms/QuadCuts/BonLinearCutsGenerator.cpp

    r1405 r1424  
    7777      methods_.push_back(cg);
    7878    }
    79     s.options()->GetIntegerValue("flow_covers_cuts",freq,"bonmin.");
     79    s.options()->GetIntegerValue("flow_cover_cuts",freq,"bonmin.");
    8080    if (freq) {
    8181      Coin::SmartPtr<CuttingMethod> cg = new CuttingMethod;
  • trunk/Bonmin/test/bonmin.opt

    r1408 r1424  
    6666bonmin.clique_cuts                          -5          #Frequency (in terms of nodes) for generating clique cuts in branch-and-cut
    6767bonmin.cover_cuts                           -5          #Frequency (in terms of nodes) for generating cover cuts in branch-and-cut
    68 bonmin.flow_covers_cuts                     -5          #Frequency (in terms of nodes) for generating flow cover cuts in branch-and-cut
     68bonmin.flow_cover_cuts                     -5           #Frequency (in terms of nodes) for generating flow cover cuts in branch-and-cut
    6969bonmin.lift_and_project_cuts                0           #Frequency (in terms of nodes) for generating lift-and-project cuts in branch-and-cut
    7070bonmin.mir_cuts                             -5          #Frequency (in terms of nodes) for generating MIR cuts in branch-and-cut
Note: See TracChangeset for help on using the changeset viewer.