source: trunk/CbcStrategy.cpp @ 97

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

for OsiCbc?

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