source: trunk/CbcStrategy.cpp @ 135

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

starting dynamic pseudo costs

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