source: trunk/CbcStrategy.cpp @ 116

Last change on this file since 116 was 116, checked in by forrest, 15 years ago

decided odd hole too slow

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 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#include <cassert>
8#include <cmath>
9#include <cfloat>
10
11#include "OsiSolverInterface.hpp"
12#include "CbcModel.hpp"
13#include "CbcMessage.hpp"
14#include "CbcStrategy.hpp"
15#include "CbcCutGenerator.hpp"
16// Cuts
17
18#include "CglGomory.hpp"
19#include "CglProbing.hpp"
20#include "CglKnapsackCover.hpp"
21#include "CglOddHole.hpp"
22#include "CglClique.hpp"
23#include "CglFlowCover.hpp"
24#include "CglMixedIntegerRounding.hpp"
25
26// Heuristics
27
28#include "CbcHeuristic.hpp"
29
30// Default Constructor
31CbcStrategy::CbcStrategy() 
32  :depth_(0)
33{
34}
35
36// Destructor
37CbcStrategy::~CbcStrategy ()
38{
39}
40
41// Default Constructor
42CbcStrategyDefault::CbcStrategyDefault(bool cutsOnlyAtRoot,
43                                       int numberStrong,
44                                       int printLevel)
45  :CbcStrategy(),
46   cutsOnlyAtRoot_(cutsOnlyAtRoot),
47   numberStrong_(numberStrong),
48   printLevel_(printLevel)
49{
50}
51
52
53// Destructor
54CbcStrategyDefault::~CbcStrategyDefault ()
55{
56}
57
58// Clone
59CbcStrategy *
60CbcStrategyDefault::clone() const
61{
62  return new CbcStrategyDefault(*this);
63}
64
65// Copy constructor
66CbcStrategyDefault::CbcStrategyDefault(const CbcStrategyDefault & rhs)
67:
68  CbcStrategy(rhs),
69  cutsOnlyAtRoot_(rhs.cutsOnlyAtRoot_),
70  numberStrong_(rhs.numberStrong_),
71  printLevel_(rhs.printLevel_)
72{
73  setNested(rhs.getNested());
74}
75
76// Setup cut generators
77void 
78CbcStrategyDefault::setupCutGenerators(CbcModel & model)
79{
80  // Set up some cut generators and defaults
81  // Probing first as gets tight bounds on continuous
82
83  CglProbing generator1;
84  generator1.setUsingObjective(true);
85  generator1.setMaxPass(3);
86  // Number of unsatisfied variables to look at
87  generator1.setMaxProbe(10);
88  // How far to follow the consequences
89  generator1.setMaxLook(50);
90  // Only look at rows with fewer than this number of elements
91  generator1.setMaxElements(200);
92  generator1.setRowCuts(3);
93
94  CglGomory generator2;
95  // try larger limit
96  generator2.setLimit(300);
97
98  CglKnapsackCover generator3;
99
100  //CglOddHole generator4;
101  //generator4.setMinimumViolation(0.005);
102  //generator4.setMinimumViolationPer(0.00002);
103  // try larger limit
104  //generator4.setMaximumEntries(200);
105
106  CglClique generator5;
107  generator5.setStarCliqueReport(false);
108  generator5.setRowCliqueReport(false);
109
110  CglMixedIntegerRounding mixedGen;
111  CglFlowCover flowGen;
112 
113  // Add in generators
114  int setting = cutsOnlyAtRoot_ ? -99 : -1;
115
116  model.addCutGenerator(&generator1,setting,"Probing");
117  model.addCutGenerator(&generator2,setting,"Gomory");
118  model.addCutGenerator(&generator3,setting,"Knapsack");
119  //model.addCutGenerator(&generator4,setting,"OddHole");
120  model.addCutGenerator(&generator5,setting,"Clique");
121  model.addCutGenerator(&flowGen,setting,"FlowCover");
122  model.addCutGenerator(&mixedGen,setting,"MixedIntegerRounding");
123  // Say we want timings
124  int numberGenerators = model.numberCutGenerators();
125  int iGenerator;
126  for (iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
127    CbcCutGenerator * generator = model.cutGenerator(iGenerator);
128    generator->setTiming(true);
129  }
130  if (model.getNumCols()<500)
131    model.setMaximumCutPassesAtRoot(-100); // always do 100 if possible
132  else if (model.getNumCols()<5000)
133    model.setMaximumCutPassesAtRoot(100); // use minimum drop
134  else
135    model.setMaximumCutPassesAtRoot(20);
136}
137// Setup heuristics
138void 
139CbcStrategyDefault::setupHeuristics(CbcModel & model)
140{
141  // Allow rounding heuristic
142
143  CbcRounding heuristic1(model);
144  model.addHeuristic(&heuristic1);
145}
146// Do printing stuff
147void 
148CbcStrategyDefault::setupPrinting(CbcModel & model)
149{
150  if (!printLevel_) {
151    model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
152    model.messageHandler()->setLogLevel(1);
153    model.solver()->messageHandler()->setLogLevel(0);
154  } else {
155    model.messageHandler()->setLogLevel(2);
156    model.solver()->messageHandler()->setLogLevel(1);
157    model.setPrintFrequency(50);
158  }
159}
160// Other stuff e.g. strong branching
161void 
162CbcStrategyDefault::setupOther(CbcModel & model)
163{
164  model.setNumberStrong(numberStrong_);
165}
166
167 
Note: See TracBrowser for help on using the repository browser.