Changeset 182 for trunk/CbcStrategy.cpp


Ignore:
Timestamp:
Oct 7, 2005 9:54:36 AM (14 years ago)
Author:
forrest
Message:

more parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CbcStrategy.cpp

    r152 r182  
    246246  model.setNumberBeforeTrust(numberBeforeTrust_);
    247247}
    248 
     248// Default Constructor
     249CbcStrategyDefaultSubTree::CbcStrategyDefaultSubTree(CbcModel * parent ,
     250                                                     bool cutsOnlyAtRoot,
     251                                       int numberStrong,
     252                                       int numberBeforeTrust,
     253                                       int printLevel)
     254  :CbcStrategy(),
     255   parentModel_(parent),
     256   cutsOnlyAtRoot_(cutsOnlyAtRoot),
     257   numberStrong_(numberStrong),
     258   numberBeforeTrust_(numberBeforeTrust),
     259   printLevel_(printLevel)
     260{
     261}
     262
     263
     264// Destructor
     265CbcStrategyDefaultSubTree::~CbcStrategyDefaultSubTree ()
     266{
     267}
     268
     269// Clone
     270CbcStrategy *
     271CbcStrategyDefaultSubTree::clone() const
     272{
     273  return new CbcStrategyDefaultSubTree(*this);
     274}
     275
     276// Copy constructor
     277CbcStrategyDefaultSubTree::CbcStrategyDefaultSubTree(const CbcStrategyDefaultSubTree & rhs)
     278:
     279  CbcStrategy(rhs),
     280  parentModel_(rhs.parentModel_),
     281  cutsOnlyAtRoot_(rhs.cutsOnlyAtRoot_),
     282  numberStrong_(rhs.numberStrong_),
     283  numberBeforeTrust_(rhs.numberBeforeTrust_),
     284  printLevel_(rhs.printLevel_)
     285{
     286  setNested(rhs.getNested());
     287}
     288
     289// Setup cut generators
     290void
     291CbcStrategyDefaultSubTree::setupCutGenerators(CbcModel & model)
     292{
     293  // Set up some cut generators and defaults
     294  // Probing first as gets tight bounds on continuous
     295
     296  CglProbing generator1;
     297  generator1.setUsingObjective(true);
     298  generator1.setMaxPass(1);
     299  // Number of unsatisfied variables to look at
     300  generator1.setMaxProbe(10);
     301  // How far to follow the consequences
     302  generator1.setMaxLook(10);
     303  // Only look at rows with fewer than this number of elements
     304  generator1.setMaxElements(200);
     305  //generator1.setRowCuts(3);
     306
     307  CglGomory generator2;
     308  // try larger limit
     309  generator2.setLimit(300);
     310
     311  CglKnapsackCover generator3;
     312
     313  //CglOddHole generator4;
     314  //generator4.setMinimumViolation(0.005);
     315  //generator4.setMinimumViolationPer(0.00002);
     316  // try larger limit
     317  //generator4.setMaximumEntries(200);
     318
     319  CglClique generator5;
     320  generator5.setStarCliqueReport(false);
     321  generator5.setRowCliqueReport(false);
     322
     323  CglMixedIntegerRounding mixedGen;
     324  CglFlowCover flowGen;
    249325 
     326  // Add in generators
     327  int setting = cutsOnlyAtRoot_ ? -99 : -1;
     328  int numberGenerators = model.numberCutGenerators();
     329  int numberParentGenerators = parentModel_->numberCutGenerators();
     330  int iGenerator;
     331  bool found;
     332  found=false;
     333  for (iGenerator=0;iGenerator<numberParentGenerators;iGenerator++) {
     334    CglCutGenerator * generator = parentModel_->cutGenerator(iGenerator)->generator();
     335    CglProbing * cgl = dynamic_cast<CglProbing *>(generator);
     336    if (cgl) {
     337      found=true;
     338      break;
     339    }
     340  }
     341  if (found) {
     342    found=false;
     343    for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
     344      CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
     345      CglProbing * cgl = dynamic_cast<CglProbing *>(generator);
     346      if (cgl) {
     347        found=true;
     348        break;
     349      }
     350    }
     351    if (!found)
     352      model.addCutGenerator(&generator1,setting,"Probing");
     353  }
     354  found=false;
     355  for (iGenerator=0;iGenerator<numberParentGenerators;iGenerator++) {
     356    CglCutGenerator * generator = parentModel_->cutGenerator(iGenerator)->generator();
     357    CglGomory * cgl = dynamic_cast<CglGomory *>(generator);
     358    if (cgl) {
     359      found=true;
     360      break;
     361    }
     362  }
     363  if (found) {
     364    found=false;
     365    for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
     366      CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
     367      CglGomory * cgl = dynamic_cast<CglGomory *>(generator);
     368      if (cgl) {
     369        found=true;
     370        break;
     371      }
     372    }
     373    if (!found)
     374      model.addCutGenerator(&generator2,setting,"Gomory");
     375  }
     376  found=false;
     377  for (iGenerator=0;iGenerator<numberParentGenerators;iGenerator++) {
     378    CglCutGenerator * generator = parentModel_->cutGenerator(iGenerator)->generator();
     379    CglKnapsackCover * cgl = dynamic_cast<CglKnapsackCover *>(generator);
     380    if (cgl) {
     381      found=true;
     382      break;
     383    }
     384  }
     385  if (found) {
     386    found=false;
     387    for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
     388      CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
     389      CglKnapsackCover * cgl = dynamic_cast<CglKnapsackCover *>(generator);
     390      if (cgl) {
     391        found=true;
     392        break;
     393      }
     394    }
     395    if (!found)
     396      model.addCutGenerator(&generator3,setting,"Knapsack");
     397  }
     398  found=false;
     399  for (iGenerator=0;iGenerator<numberParentGenerators;iGenerator++) {
     400    CglCutGenerator * generator = parentModel_->cutGenerator(iGenerator)->generator();
     401    CglClique * cgl = dynamic_cast<CglClique *>(generator);
     402    if (cgl) {
     403      found=true;
     404      break;
     405    }
     406  }
     407  if (found) {
     408    found=false;
     409    for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
     410      CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
     411      CglClique * cgl = dynamic_cast<CglClique *>(generator);
     412      if (cgl) {
     413        found=true;
     414        break;
     415      }
     416    }
     417    if (!found)
     418      model.addCutGenerator(&generator5,setting,"Clique");
     419  }
     420  found=false;
     421  for (iGenerator=0;iGenerator<numberParentGenerators;iGenerator++) {
     422    CglCutGenerator * generator = parentModel_->cutGenerator(iGenerator)->generator();
     423    CglFlowCover * cgl = dynamic_cast<CglFlowCover *>(generator);
     424    if (cgl) {
     425      found=true;
     426      break;
     427    }
     428  }
     429  if (found) {
     430    found=false;
     431    for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
     432      CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
     433      CglFlowCover * cgl = dynamic_cast<CglFlowCover *>(generator);
     434      if (cgl) {
     435        found=true;
     436        break;
     437      }
     438    }
     439    if (!found)
     440      model.addCutGenerator(&flowGen,setting,"FlowCover");
     441    found=false;
     442  }
     443  for (iGenerator=0;iGenerator<numberParentGenerators;iGenerator++) {
     444    CglCutGenerator * generator = parentModel_->cutGenerator(iGenerator)->generator();
     445    CglMixedIntegerRounding * cgl = dynamic_cast<CglMixedIntegerRounding *>(generator);
     446    if (cgl) {
     447      found=true;
     448      break;
     449    }
     450  }
     451  if (found) {
     452    found=false;
     453    for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
     454      CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
     455      CglMixedIntegerRounding * cgl = dynamic_cast<CglMixedIntegerRounding *>(generator);
     456      if (cgl) {
     457        found=true;
     458        break;
     459      }
     460    }
     461    if (!found)
     462      model.addCutGenerator(&mixedGen,setting,"MixedIntegerRounding");
     463  }
     464  // Say we want timings
     465  int newNumberGenerators = model.numberCutGenerators();
     466  for (iGenerator=numberGenerators;iGenerator<newNumberGenerators;iGenerator++) {
     467    CbcCutGenerator * generator = model.cutGenerator(iGenerator);
     468    generator->setTiming(true);
     469  }
     470  if (model.getNumCols()<500)
     471    model.setMaximumCutPassesAtRoot(-100); // always do 100 if possible
     472  else if (model.getNumCols()<5000)
     473    model.setMaximumCutPassesAtRoot(100); // use minimum drop
     474  else
     475    model.setMaximumCutPassesAtRoot(20);
     476}
     477// Setup heuristics
     478void
     479CbcStrategyDefaultSubTree::setupHeuristics(CbcModel & model)
     480{
     481  // Allow rounding heuristic
     482
     483  CbcRounding heuristic1(model);
     484  int numberHeuristics = model.numberHeuristics();
     485  int iHeuristic;
     486  bool found;
     487  found=false;
     488  for (iHeuristic=0;iHeuristic<numberHeuristics;iHeuristic++) {
     489    CbcHeuristic * heuristic = model.heuristic(iHeuristic);
     490    CbcRounding * cgl = dynamic_cast<CbcRounding *>(heuristic);
     491    if (cgl) {
     492      found=true;
     493      break;
     494    }
     495  }
     496  if (!found)
     497    model.addHeuristic(&heuristic1);
     498}
     499// Do printing stuff
     500void
     501CbcStrategyDefaultSubTree::setupPrinting(CbcModel & model,int modelLogLevel)
     502{
     503  if (!modelLogLevel) {
     504    model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
     505    model.messageHandler()->setLogLevel(0);
     506    model.solver()->messageHandler()->setLogLevel(0);
     507  } else if (modelLogLevel==1) {
     508    model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
     509    model.messageHandler()->setLogLevel(1);
     510    model.solver()->messageHandler()->setLogLevel(0);
     511  } else {
     512    model.messageHandler()->setLogLevel(2);
     513    model.solver()->messageHandler()->setLogLevel(1);
     514    model.setPrintFrequency(50);
     515  }
     516}
     517// Other stuff e.g. strong branching
     518void
     519CbcStrategyDefaultSubTree::setupOther(CbcModel & model)
     520{
     521  model.setNumberStrong(numberStrong_);
     522  model.setNumberBeforeTrust(numberBeforeTrust_);
     523}
     524
     525
     526 
Note: See TracChangeset for help on using the changeset viewer.