source: trunk/Cbc/src/CbcStrategy.cpp @ 356

Last change on this file since 356 was 356, checked in by ladanyi, 14 years ago

finishing conversion to svn

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.7 KB
Line 
1// Copyright (C) 2005, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#if defined(_MSC_VER)
4// Turn off compiler warning about long names
5#  pragma warning(disable:4786)
6#endif
7
8#include "CbcConfig.h"
9
10#include <cassert>
11#include <cmath>
12#include <cfloat>
13
14#include "OsiSolverInterface.hpp"
15#ifdef COIN_HAS_CLP
16#include "OsiClpSolverInterface.hpp"
17#endif
18#include "CbcModel.hpp"
19#include "CbcMessage.hpp"
20#include "CbcStrategy.hpp"
21#include "CbcCutGenerator.hpp"
22#include "CbcBranchActual.hpp"
23#include "CbcNode.hpp"
24#include "CoinWarmStart.hpp"
25#include "CglPreProcess.hpp"
26// Cuts
27
28#include "CglGomory.hpp"
29#include "CglProbing.hpp"
30#include "CglKnapsackCover.hpp"
31#include "CglOddHole.hpp"
32#include "CglClique.hpp"
33#include "CglFlowCover.hpp"
34#include "CglMixedIntegerRounding2.hpp"
35
36// Heuristics
37
38#include "CbcHeuristic.hpp"
39
40// Default Constructor
41CbcStrategy::CbcStrategy() 
42  :depth_(0),
43   preProcessState_(0),
44   process_(NULL)
45{
46}
47
48// Destructor
49CbcStrategy::~CbcStrategy ()
50{
51  delete process_;
52}
53// Delete pre-processing object to save memory
54void 
55CbcStrategy::deletePreProcess()
56{ 
57  delete process_;
58  process_=NULL;
59}
60// Return a new Full node information pointer (descendant of CbcFullNodeInfo)
61CbcNodeInfo * 
62CbcStrategy::fullNodeInfo(CbcModel * model,int numberRowsAtContinuous) const
63{
64  return new CbcFullNodeInfo(model,numberRowsAtContinuous);
65}
66// Return a new Partial node information pointer (descendant of CbcPartialNodeInfo)
67CbcNodeInfo * 
68CbcStrategy::partialNodeInfo(CbcModel * model, CbcNodeInfo * parent, CbcNode * owner,
69                             int numberChangedBounds,const int * variables,
70                             const double * boundChanges,
71                             const CoinWarmStartDiff *basisDiff) const
72{
73  return new CbcPartialNodeInfo(parent, owner, numberChangedBounds, variables,
74                            boundChanges,basisDiff);
75}
76/* After a CbcModel::resolve this can return a status
77   -1 no effect
78   0 treat as optimal
79   1 as 0 but do not do any more resolves (i.e. no more cuts)
80   2 treat as infeasible
81*/
82int
83CbcStrategy::status(CbcModel * model, CbcNodeInfo * parent,int whereFrom)
84{
85  return -1;
86}
87
88// Default Constructor
89CbcStrategyDefault::CbcStrategyDefault(bool cutsOnlyAtRoot,
90                                       int numberStrong,
91                                       int numberBeforeTrust,
92                                       int printLevel)
93  :CbcStrategy(),
94   cutsOnlyAtRoot_(cutsOnlyAtRoot),
95   numberStrong_(numberStrong),
96   numberBeforeTrust_(numberBeforeTrust),
97   printLevel_(printLevel),
98   desiredPreProcess_(0),
99   preProcessPasses_(0)
100{
101}
102
103
104// Destructor
105CbcStrategyDefault::~CbcStrategyDefault ()
106{
107}
108
109// Clone
110CbcStrategy *
111CbcStrategyDefault::clone() const
112{
113  return new CbcStrategyDefault(*this);
114}
115
116// Copy constructor
117CbcStrategyDefault::CbcStrategyDefault(const CbcStrategyDefault & rhs)
118:
119  CbcStrategy(rhs),
120  cutsOnlyAtRoot_(rhs.cutsOnlyAtRoot_),
121  numberStrong_(rhs.numberStrong_),
122  numberBeforeTrust_(rhs.numberBeforeTrust_),
123  printLevel_(rhs.printLevel_),
124  desiredPreProcess_(rhs.desiredPreProcess_),
125  preProcessPasses_(rhs.preProcessPasses_)
126{
127  setNested(rhs.getNested());
128}
129
130// Setup cut generators
131void 
132CbcStrategyDefault::setupCutGenerators(CbcModel & model)
133{
134  // Set up some cut generators and defaults
135  // Probing first as gets tight bounds on continuous
136
137  CglProbing generator1;
138  generator1.setUsingObjective(true);
139  generator1.setMaxPass(1);
140  // Number of unsatisfied variables to look at
141  generator1.setMaxProbe(10);
142  // How far to follow the consequences
143  generator1.setMaxLook(10);
144  // Only look at rows with fewer than this number of elements
145  generator1.setMaxElements(200);
146  //generator1.setRowCuts(3);
147
148  CglGomory generator2;
149  // try larger limit
150  generator2.setLimit(300);
151
152  CglKnapsackCover generator3;
153
154  //CglOddHole generator4;
155  //generator4.setMinimumViolation(0.005);
156  //generator4.setMinimumViolationPer(0.00002);
157  // try larger limit
158  //generator4.setMaximumEntries(200);
159
160  CglClique generator5;
161  generator5.setStarCliqueReport(false);
162  generator5.setRowCliqueReport(false);
163
164  CglMixedIntegerRounding2 mixedGen;
165  CglFlowCover flowGen;
166 
167  // Add in generators
168  int setting = cutsOnlyAtRoot_ ? -99 : -1;
169  int numberGenerators = model.numberCutGenerators();
170  int iGenerator;
171  bool found;
172  found=false;
173  for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
174    CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
175    CglProbing * cgl = dynamic_cast<CglProbing *>(generator);
176    if (cgl) {
177      found=true;
178      break;
179    }
180  }
181  if (!found)
182    model.addCutGenerator(&generator1,setting,"Probing");
183  found=false;
184  for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
185    CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
186    CglGomory * cgl = dynamic_cast<CglGomory *>(generator);
187    if (cgl) {
188      found=true;
189      break;
190    }
191  }
192  if (!found)
193  model.addCutGenerator(&generator2,setting,"Gomory");
194  found=false;
195  for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
196    CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
197    CglKnapsackCover * cgl = dynamic_cast<CglKnapsackCover *>(generator);
198    if (cgl) {
199      found=true;
200      break;
201    }
202  }
203  if (!found)
204    model.addCutGenerator(&generator3,setting,"Knapsack");
205  //model.addCutGenerator(&generator4,setting,"OddHole");
206  found=false;
207  for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
208    CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
209    CglClique * cgl = dynamic_cast<CglClique *>(generator);
210    if (cgl) {
211      found=true;
212      break;
213    }
214  }
215  if (!found)
216    model.addCutGenerator(&generator5,setting,"Clique");
217  found=false;
218  for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
219    CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
220    CglFlowCover * cgl = dynamic_cast<CglFlowCover *>(generator);
221    if (cgl) {
222      found=true;
223      break;
224    }
225  }
226  if (!found)
227    model.addCutGenerator(&flowGen,setting,"FlowCover");
228  found=false;
229  for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
230    CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
231    CglMixedIntegerRounding2 * cgl = dynamic_cast<CglMixedIntegerRounding2 *>(generator);
232    if (cgl) {
233      found=true;
234      break;
235    }
236  }
237  if (!found)
238    model.addCutGenerator(&mixedGen,setting,"MixedIntegerRounding2");
239  // Say we want timings
240  int newNumberGenerators = model.numberCutGenerators();
241  for (iGenerator=numberGenerators;iGenerator<newNumberGenerators;iGenerator++) {
242    CbcCutGenerator * generator = model.cutGenerator(iGenerator);
243    generator->setTiming(true);
244  }
245  if (model.getNumCols()<500)
246    model.setMaximumCutPassesAtRoot(-100); // always do 100 if possible
247  else if (model.getNumCols()<5000)
248    model.setMaximumCutPassesAtRoot(100); // use minimum drop
249  else
250    model.setMaximumCutPassesAtRoot(20);
251}
252// Setup heuristics
253void 
254CbcStrategyDefault::setupHeuristics(CbcModel & model)
255{
256  // Allow rounding heuristic
257
258  CbcRounding heuristic1(model);
259  int numberHeuristics = model.numberHeuristics();
260  int iHeuristic;
261  bool found;
262  found=false;
263  for (iHeuristic=0;iHeuristic<numberHeuristics;iHeuristic++) {
264    CbcHeuristic * heuristic = model.heuristic(iHeuristic);
265    CbcRounding * cgl = dynamic_cast<CbcRounding *>(heuristic);
266    if (cgl) {
267      found=true;
268      break;
269    }
270  }
271  if (!found)
272    model.addHeuristic(&heuristic1);
273}
274// Do printing stuff
275void 
276CbcStrategyDefault::setupPrinting(CbcModel & model,int modelLogLevel)
277{
278  if (!modelLogLevel) {
279    model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
280    model.messageHandler()->setLogLevel(0);
281    model.solver()->messageHandler()->setLogLevel(0);
282  } else if (modelLogLevel==1) {
283    model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
284    model.messageHandler()->setLogLevel(1);
285    model.solver()->messageHandler()->setLogLevel(0);
286  } else {
287    model.messageHandler()->setLogLevel(2);
288    model.solver()->messageHandler()->setLogLevel(1);
289    model.setPrintFrequency(50);
290  }
291}
292// Other stuff e.g. strong branching
293void 
294CbcStrategyDefault::setupOther(CbcModel & model)
295{
296  // See if preprocessing wanted
297  if (desiredPreProcess_) {
298    delete process_;
299    // solver_ should have been cloned outside
300    CglPreProcess * process = new CglPreProcess();
301    OsiSolverInterface * solver = model.solver();
302    int logLevel = model.messageHandler()->logLevel();
303#ifdef COIN_HAS_CLP
304    OsiClpSolverInterface * clpSolver = dynamic_cast< OsiClpSolverInterface*> (solver);
305    ClpSimplex * lpSolver=NULL;
306    if (clpSolver) {
307      if (clpSolver->messageHandler()->logLevel())
308        clpSolver->messageHandler()->setLogLevel(1);
309      if (logLevel>-1)
310        clpSolver->messageHandler()->setLogLevel(CoinMin(logLevel,clpSolver->messageHandler()->logLevel()));
311      lpSolver = clpSolver->getModelPtr();
312      /// If user left factorization frequency then compute
313      lpSolver->defaultFactorizationFrequency();
314    }
315#endif
316    // Tell solver we are in Branch and Cut
317    solver->setHintParam(OsiDoInBranchAndCut,true,OsiHintDo) ;
318    // Default set of cut generators
319    CglProbing generator1;
320    generator1.setUsingObjective(true);
321    generator1.setMaxPass(3);
322    generator1.setMaxProbeRoot(solver->getNumCols());
323    generator1.setMaxElements(100);
324    generator1.setMaxLookRoot(50);
325    generator1.setRowCuts(3);
326    //generator1.messageHandler()->setLogLevel(logLevel);
327    process->messageHandler()->setLogLevel(logLevel);
328    // Add in generators
329    process->addCutGenerator(&generator1);
330    int translate[]={9999,0,2,3};
331    OsiSolverInterface * solver2 = 
332      process->preProcessNonDefault(*solver,
333                                    translate[desiredPreProcess_],preProcessPasses_);
334    // Tell solver we are not in Branch and Cut
335    solver->setHintParam(OsiDoInBranchAndCut,false,OsiHintDo) ;
336    if (solver2)
337      solver2->setHintParam(OsiDoInBranchAndCut,false,OsiHintDo) ;
338    bool feasible=true;
339    if (!solver2) {
340      feasible = false;
341      //printf("Pre-processing says infeasible\n");
342      delete process;
343      preProcessState_=-1;
344      process_=NULL;
345    } else {
346      // now tighten bounds
347#ifdef COIN_HAS_CLP
348      if (clpSolver) {
349        // model has changed
350        solver = model.solver();
351        OsiClpSolverInterface * clpSolver = dynamic_cast< OsiClpSolverInterface*> (solver);
352        ClpSimplex * lpSolver = clpSolver->getModelPtr();
353        if (lpSolver->tightenPrimalBounds()==0) {
354          lpSolver->dual();
355        } else {
356          feasible = false;
357        }
358      }
359#endif
360      if (feasible) {
361        preProcessState_=1;
362        process_=process;
363        /* Note that original solver will be kept (with false)
364           and that final solver will also be kept.
365           This is for post-processing
366        */
367        OsiSolverInterface * solver3 = solver2->clone();
368        model.assignSolver(solver3,false);
369        if (process_->numberSOS()) {
370          int numberSOS = process_->numberSOS();
371          int numberIntegers = model.numberIntegers();
372          /* model may not have created objects
373             If none then create
374             NOTE - put back to original column numbers as
375             CbcModel will pack down ALL as it doesn't know where from
376          */
377          bool someObjects = model.numberObjects()>0;
378          if (!numberIntegers||!model.numberObjects()) {
379            model.findIntegers(true);
380            numberIntegers = model.numberIntegers();
381          }
382          CbcObject ** oldObjects = model.objects();
383          // Do sets and priorities
384          CbcObject ** objects = new CbcObject * [numberSOS];
385          // set old objects to have low priority
386          int numberOldObjects = model.numberObjects();
387          int numberColumns = model.getNumCols();
388          for (int iObj = 0;iObj<numberOldObjects;iObj++) {
389            int oldPriority = oldObjects[iObj]->priority();
390            oldObjects[iObj]->setPriority(numberColumns+oldPriority);
391          }
392          const int * starts = process_->startSOS();
393          const int * which = process_->whichSOS();
394          const int * type = process_->typeSOS();
395          const double * weight = process_->weightSOS();
396          int iSOS;
397          for (iSOS =0;iSOS<numberSOS;iSOS++) {
398            int iStart = starts[iSOS];
399            int n=starts[iSOS+1]-iStart;
400            objects[iSOS] = new CbcSOS(&model,n,which+iStart,weight+iStart,
401                                       iSOS,type[iSOS]);
402            // branch on long sets first
403            objects[iSOS]->setPriority(numberColumns-n);
404          }
405          model.addObjects(numberSOS,objects);
406          for (iSOS=0;iSOS<numberSOS;iSOS++)
407            delete objects[iSOS];
408          delete [] objects;
409          if (!someObjects) {
410            // put back old column numbers
411            const int * originalColumns = process_->originalColumns();
412            // use reverse lookup to fake it
413            int n=originalColumns[numberColumns-1]+1;
414            int * fake = new int[n];
415            int i;
416            for ( i=0;i<n;i++)
417              fake[i]=-1;
418            for (i=0;i<numberColumns;i++)
419              fake[originalColumns[i]]=i;
420            for (int iObject=0;iObject<model.numberObjects();iObject++) {
421              // redo ids etc
422              model.modifiableObject(iObject)->redoSequenceEtc(&model,n,fake);
423            }
424            delete [] fake;
425          }
426        }
427      } else {
428        //printf("Pre-processing says infeasible\n");
429        delete process;
430        preProcessState_=-1;
431        process_=NULL;
432      }
433    }
434  }
435  model.setNumberStrong(numberStrong_);
436  model.setNumberBeforeTrust(numberBeforeTrust_);
437}
438// Create C++ lines to get to current state
439void 
440CbcStrategyDefault::generateCpp( FILE * fp) 
441{
442  fprintf(fp,"0#include \"CbcStrategy.hpp\"\n");
443  fprintf(fp,"3  CbcStrategyDefault strategy(%s,%d,%d,%d);\n",
444          cutsOnlyAtRoot_ ? "true" : "false",
445          numberStrong_,
446          numberBeforeTrust_,
447          printLevel_);
448  fprintf(fp,"3  strategy.setupPreProcessing(%d,%d);\n",
449          desiredPreProcess_,preProcessPasses_);
450}
451// Default Constructor
452CbcStrategyDefaultSubTree::CbcStrategyDefaultSubTree(CbcModel * parent ,
453                                                     bool cutsOnlyAtRoot,
454                                       int numberStrong,
455                                       int numberBeforeTrust,
456                                       int printLevel)
457  :CbcStrategy(),
458   parentModel_(parent),
459   cutsOnlyAtRoot_(cutsOnlyAtRoot),
460   numberStrong_(numberStrong),
461   numberBeforeTrust_(numberBeforeTrust),
462   printLevel_(printLevel)
463{
464}
465
466
467// Destructor
468CbcStrategyDefaultSubTree::~CbcStrategyDefaultSubTree ()
469{
470}
471
472// Clone
473CbcStrategy *
474CbcStrategyDefaultSubTree::clone() const
475{
476  return new CbcStrategyDefaultSubTree(*this);
477}
478
479// Copy constructor
480CbcStrategyDefaultSubTree::CbcStrategyDefaultSubTree(const CbcStrategyDefaultSubTree & rhs)
481:
482  CbcStrategy(rhs),
483  parentModel_(rhs.parentModel_),
484  cutsOnlyAtRoot_(rhs.cutsOnlyAtRoot_),
485  numberStrong_(rhs.numberStrong_),
486  numberBeforeTrust_(rhs.numberBeforeTrust_),
487  printLevel_(rhs.printLevel_)
488{
489  setNested(rhs.getNested());
490}
491
492// Setup cut generators
493void 
494CbcStrategyDefaultSubTree::setupCutGenerators(CbcModel & model)
495{
496  // Set up some cut generators and defaults
497  // Probing first as gets tight bounds on continuous
498
499  CglProbing generator1;
500  generator1.setUsingObjective(true);
501  generator1.setMaxPass(1);
502  // Number of unsatisfied variables to look at
503  generator1.setMaxProbe(10);
504  // How far to follow the consequences
505  generator1.setMaxLook(10);
506  // Only look at rows with fewer than this number of elements
507  generator1.setMaxElements(200);
508  //generator1.setRowCuts(3);
509
510  CglGomory generator2;
511  // try larger limit
512  generator2.setLimit(300);
513
514  CglKnapsackCover generator3;
515
516  //CglOddHole generator4;
517  //generator4.setMinimumViolation(0.005);
518  //generator4.setMinimumViolationPer(0.00002);
519  // try larger limit
520  //generator4.setMaximumEntries(200);
521
522  CglClique generator5;
523  generator5.setStarCliqueReport(false);
524  generator5.setRowCliqueReport(false);
525
526  CglMixedIntegerRounding2 mixedGen;
527  CglFlowCover flowGen;
528 
529  // Add in generators
530  int setting = cutsOnlyAtRoot_ ? -99 : -1;
531  int numberGenerators = model.numberCutGenerators();
532  int numberParentGenerators = parentModel_->numberCutGenerators();
533  int iGenerator;
534  bool found;
535  found=false;
536  int howOften=0;
537  for (iGenerator=0;iGenerator<numberParentGenerators;iGenerator++) {
538    CglCutGenerator * generator = parentModel_->cutGenerator(iGenerator)->generator();
539    CglProbing * cgl = dynamic_cast<CglProbing *>(generator);
540    if (cgl) {
541      found=true;
542      howOften = parentModel_->cutGenerator(iGenerator)->howOften();
543      break;
544    }
545  }
546  if (found&&howOften>=0) {
547    found=false;
548    for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
549      CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
550      CglProbing * cgl = dynamic_cast<CglProbing *>(generator);
551      if (cgl) {
552        found=true;
553        break;
554      }
555    }
556    if (!found)
557      model.addCutGenerator(&generator1,setting,"Probing");
558  }
559  found=false;
560  for (iGenerator=0;iGenerator<numberParentGenerators;iGenerator++) {
561    CglCutGenerator * generator = parentModel_->cutGenerator(iGenerator)->generator();
562    CglGomory * cgl = dynamic_cast<CglGomory *>(generator);
563    if (cgl) {
564      found=true;
565      howOften = parentModel_->cutGenerator(iGenerator)->howOften();
566      break;
567    }
568  }
569  if (found&&howOften>=0) {
570    found=false;
571    for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
572      CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
573      CglGomory * cgl = dynamic_cast<CglGomory *>(generator);
574      if (cgl) {
575        found=true;
576        break;
577      }
578    }
579    if (!found)
580      model.addCutGenerator(&generator2,setting,"Gomory");
581  }
582  found=false;
583  for (iGenerator=0;iGenerator<numberParentGenerators;iGenerator++) {
584    CglCutGenerator * generator = parentModel_->cutGenerator(iGenerator)->generator();
585    CglKnapsackCover * cgl = dynamic_cast<CglKnapsackCover *>(generator);
586    if (cgl) {
587      found=true;
588      howOften = parentModel_->cutGenerator(iGenerator)->howOften();
589      break;
590    }
591  }
592  if (found&&howOften>=0) {
593    found=false;
594    for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
595      CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
596      CglKnapsackCover * cgl = dynamic_cast<CglKnapsackCover *>(generator);
597      if (cgl) {
598        found=true;
599        break;
600      }
601    }
602    if (!found)
603      model.addCutGenerator(&generator3,setting,"Knapsack");
604  }
605  found=false;
606  for (iGenerator=0;iGenerator<numberParentGenerators;iGenerator++) {
607    CglCutGenerator * generator = parentModel_->cutGenerator(iGenerator)->generator();
608    CglClique * cgl = dynamic_cast<CglClique *>(generator);
609    if (cgl) {
610      found=true;
611      howOften = parentModel_->cutGenerator(iGenerator)->howOften();
612      break;
613    }
614  }
615  if (found&&howOften>=0) {
616    found=false;
617    for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
618      CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
619      CglClique * cgl = dynamic_cast<CglClique *>(generator);
620      if (cgl) {
621        found=true;
622        break;
623      }
624    }
625    if (!found)
626      model.addCutGenerator(&generator5,setting,"Clique");
627  }
628  found=false;
629  for (iGenerator=0;iGenerator<numberParentGenerators;iGenerator++) {
630    CglCutGenerator * generator = parentModel_->cutGenerator(iGenerator)->generator();
631    CglFlowCover * cgl = dynamic_cast<CglFlowCover *>(generator);
632    if (cgl) {
633      found=true;
634      howOften = parentModel_->cutGenerator(iGenerator)->howOften();
635      break;
636    }
637  }
638  if (found&&howOften>=0) {
639    found=false;
640    for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
641      CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
642      CglFlowCover * cgl = dynamic_cast<CglFlowCover *>(generator);
643      if (cgl) {
644        found=true;
645        break;
646      }
647    }
648    if (!found)
649      model.addCutGenerator(&flowGen,setting,"FlowCover");
650    found=false;
651  }
652  for (iGenerator=0;iGenerator<numberParentGenerators;iGenerator++) {
653    CglCutGenerator * generator = parentModel_->cutGenerator(iGenerator)->generator();
654    CglMixedIntegerRounding2 * cgl = dynamic_cast<CglMixedIntegerRounding2 *>(generator);
655    if (cgl) {
656      found=true;
657      howOften = parentModel_->cutGenerator(iGenerator)->howOften();
658      break;
659    }
660  }
661  if (found&&howOften>=0) {
662    found=false;
663    for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
664      CglCutGenerator * generator = model.cutGenerator(iGenerator)->generator();
665      CglMixedIntegerRounding2 * cgl = dynamic_cast<CglMixedIntegerRounding2 *>(generator);
666      if (cgl) {
667        found=true;
668        break;
669      }
670    }
671    if (!found)
672      model.addCutGenerator(&mixedGen,setting,"MixedIntegerRounding2");
673  }
674#if 0
675  // Say we want timings
676  int newNumberGenerators = model.numberCutGenerators();
677  for (iGenerator=numberGenerators;iGenerator<newNumberGenerators;iGenerator++) {
678    CbcCutGenerator * generator = model.cutGenerator(iGenerator);
679    generator->setTiming(true);
680  }
681#endif
682  if (model.getNumCols()<500)
683    model.setMaximumCutPassesAtRoot(-100); // always do 100 if possible
684  else if (model.getNumCols()<5000)
685    model.setMaximumCutPassesAtRoot(100); // use minimum drop
686  else
687    model.setMaximumCutPassesAtRoot(20);
688}
689// Setup heuristics
690void 
691CbcStrategyDefaultSubTree::setupHeuristics(CbcModel & model)
692{
693  // Allow rounding heuristic
694
695  CbcRounding heuristic1(model);
696  int numberHeuristics = model.numberHeuristics();
697  int iHeuristic;
698  bool found;
699  found=false;
700  for (iHeuristic=0;iHeuristic<numberHeuristics;iHeuristic++) {
701    CbcHeuristic * heuristic = model.heuristic(iHeuristic);
702    CbcRounding * cgl = dynamic_cast<CbcRounding *>(heuristic);
703    if (cgl) {
704      found=true;
705      break;
706    }
707  }
708  if (!found)
709    model.addHeuristic(&heuristic1);
710}
711// Do printing stuff
712void 
713CbcStrategyDefaultSubTree::setupPrinting(CbcModel & model,int modelLogLevel)
714{
715  if (!modelLogLevel) {
716    model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
717    model.messageHandler()->setLogLevel(0);
718    model.solver()->messageHandler()->setLogLevel(0);
719  } else if (modelLogLevel==1) {
720    model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
721    model.messageHandler()->setLogLevel(1);
722    model.solver()->messageHandler()->setLogLevel(0);
723  } else {
724    model.messageHandler()->setLogLevel(2);
725    model.solver()->messageHandler()->setLogLevel(1);
726    model.setPrintFrequency(50);
727  }
728}
729// Other stuff e.g. strong branching
730void 
731CbcStrategyDefaultSubTree::setupOther(CbcModel & model)
732{
733  model.setNumberStrong(numberStrong_);
734  model.setNumberBeforeTrust(numberBeforeTrust_);
735}
736
737
738 
Note: See TracBrowser for help on using the repository browser.