| ... |
... |
@@ -4,54 +4,49 @@
|
| 4 |
4 |
*
|
| 5 |
5 |
* Copyright (C) 2003-2009
|
| 6 |
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
| 7 |
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
| 8 |
8 |
*
|
| 9 |
9 |
* Permission to use, modify and distribute this software is granted
|
| 10 |
10 |
* provided that this copyright notice appears in all copies. For
|
| 11 |
11 |
* precise terms see the accompanying LICENSE file.
|
| 12 |
12 |
*
|
| 13 |
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
| 14 |
14 |
* express or implied, and with no claim as to its suitability for any
|
| 15 |
15 |
* purpose.
|
| 16 |
16 |
*
|
| 17 |
17 |
*/
|
| 18 |
18 |
|
| 19 |
19 |
///\file
|
| 20 |
20 |
///\brief Implementation of the CBC MIP solver interface.
|
| 21 |
21 |
|
| 22 |
22 |
#include "cbc.h"
|
| 23 |
23 |
|
| 24 |
24 |
#include <coin/CoinModel.hpp>
|
| 25 |
25 |
#include <coin/CbcModel.hpp>
|
| 26 |
26 |
#include <coin/OsiSolverInterface.hpp>
|
| 27 |
27 |
|
| 28 |
|
#ifdef COIN_HAS_CLP
|
| 29 |
28 |
#include "coin/OsiClpSolverInterface.hpp"
|
| 30 |
|
#endif
|
| 31 |
|
#ifdef COIN_HAS_OSL
|
| 32 |
|
#include "coin/OsiOslSolverInterface.hpp"
|
| 33 |
|
#endif
|
| 34 |
29 |
|
| 35 |
30 |
#include "coin/CbcCutGenerator.hpp"
|
| 36 |
31 |
#include "coin/CbcHeuristicLocal.hpp"
|
| 37 |
32 |
#include "coin/CbcHeuristicGreedy.hpp"
|
| 38 |
33 |
#include "coin/CbcHeuristicFPump.hpp"
|
| 39 |
34 |
#include "coin/CbcHeuristicRINS.hpp"
|
| 40 |
35 |
|
| 41 |
36 |
#include "coin/CglGomory.hpp"
|
| 42 |
37 |
#include "coin/CglProbing.hpp"
|
| 43 |
38 |
#include "coin/CglKnapsackCover.hpp"
|
| 44 |
39 |
#include "coin/CglOddHole.hpp"
|
| 45 |
40 |
#include "coin/CglClique.hpp"
|
| 46 |
41 |
#include "coin/CglFlowCover.hpp"
|
| 47 |
42 |
#include "coin/CglMixedIntegerRounding.hpp"
|
| 48 |
43 |
|
| 49 |
44 |
#include "coin/CbcHeuristic.hpp"
|
| 50 |
45 |
|
| 51 |
46 |
namespace lemon {
|
| 52 |
47 |
|
| 53 |
48 |
CbcMip::CbcMip() {
|
| 54 |
49 |
_prob = new CoinModel();
|
| 55 |
50 |
_prob->setProblemName("LEMON");
|
| 56 |
51 |
_osi_solver = 0;
|
| 57 |
52 |
_cbc_model = 0;
|
| ... |
... |
@@ -237,55 +232,49 @@
|
| 237 |
232 |
void CbcMip::_getObjCoeffs(InsertIterator b) const {
|
| 238 |
233 |
int num = _prob->numberColumns();
|
| 239 |
234 |
for (int i = 0; i < num; ++i) {
|
| 240 |
235 |
Value coef = _prob->getColumnObjective(i);
|
| 241 |
236 |
if (coef != 0.0) {
|
| 242 |
237 |
*b = std::make_pair(i, coef);
|
| 243 |
238 |
++b;
|
| 244 |
239 |
}
|
| 245 |
240 |
}
|
| 246 |
241 |
}
|
| 247 |
242 |
|
| 248 |
243 |
void CbcMip::_setObjCoeff(int i, Value obj_coef) {
|
| 249 |
244 |
_prob->setColumnObjective(i, obj_coef);
|
| 250 |
245 |
}
|
| 251 |
246 |
|
| 252 |
247 |
CbcMip::Value CbcMip::_getObjCoeff(int i) const {
|
| 253 |
248 |
return _prob->getColumnObjective(i);
|
| 254 |
249 |
}
|
| 255 |
250 |
|
| 256 |
251 |
CbcMip::SolveExitStatus CbcMip::_solve() {
|
| 257 |
252 |
|
| 258 |
253 |
if (_osi_solver) {
|
| 259 |
254 |
delete _osi_solver;
|
| 260 |
255 |
}
|
| 261 |
|
#ifdef COIN_HAS_CLP
|
| 262 |
256 |
_osi_solver = new OsiClpSolverInterface();
|
| 263 |
|
#elif COIN_HAS_OSL
|
| 264 |
|
_osi_solver = new OsiOslSolverInterface();
|
| 265 |
|
#else
|
| 266 |
|
#error Cannot instantiate Osi solver
|
| 267 |
|
#endif
|
| 268 |
257 |
|
| 269 |
258 |
_osi_solver->loadFromCoinModel(*_prob);
|
| 270 |
259 |
|
| 271 |
260 |
if (_cbc_model) {
|
| 272 |
261 |
delete _cbc_model;
|
| 273 |
262 |
}
|
| 274 |
263 |
_cbc_model= new CbcModel(*_osi_solver);
|
| 275 |
264 |
|
| 276 |
265 |
_osi_solver->messageHandler()->setLogLevel(_message_level);
|
| 277 |
266 |
_cbc_model->setLogLevel(_message_level);
|
| 278 |
267 |
|
| 279 |
268 |
_cbc_model->initialSolve();
|
| 280 |
269 |
_cbc_model->solver()->setHintParam(OsiDoReducePrint, true, OsiHintTry);
|
| 281 |
270 |
|
| 282 |
271 |
if (!_cbc_model->isInitialSolveAbandoned() &&
|
| 283 |
272 |
_cbc_model->isInitialSolveProvenOptimal() &&
|
| 284 |
273 |
!_cbc_model->isInitialSolveProvenPrimalInfeasible() &&
|
| 285 |
274 |
!_cbc_model->isInitialSolveProvenDualInfeasible()) {
|
| 286 |
275 |
|
| 287 |
276 |
CglProbing generator1;
|
| 288 |
277 |
generator1.setUsingObjective(true);
|
| 289 |
278 |
generator1.setMaxPass(3);
|
| 290 |
279 |
generator1.setMaxProbe(100);
|
| 291 |
280 |
generator1.setMaxLook(50);
|
| ... |
... |
@@ -295,55 +284,53 @@
|
| 295 |
284 |
CglGomory generator2;
|
| 296 |
285 |
generator2.setLimit(300);
|
| 297 |
286 |
_cbc_model->addCutGenerator(&generator2, -1, "Gomory");
|
| 298 |
287 |
|
| 299 |
288 |
CglKnapsackCover generator3;
|
| 300 |
289 |
_cbc_model->addCutGenerator(&generator3, -1, "Knapsack");
|
| 301 |
290 |
|
| 302 |
291 |
CglOddHole generator4;
|
| 303 |
292 |
generator4.setMinimumViolation(0.005);
|
| 304 |
293 |
generator4.setMinimumViolationPer(0.00002);
|
| 305 |
294 |
generator4.setMaximumEntries(200);
|
| 306 |
295 |
_cbc_model->addCutGenerator(&generator4, -1, "OddHole");
|
| 307 |
296 |
|
| 308 |
297 |
CglClique generator5;
|
| 309 |
298 |
generator5.setStarCliqueReport(false);
|
| 310 |
299 |
generator5.setRowCliqueReport(false);
|
| 311 |
300 |
_cbc_model->addCutGenerator(&generator5, -1, "Clique");
|
| 312 |
301 |
|
| 313 |
302 |
CglMixedIntegerRounding mixedGen;
|
| 314 |
303 |
_cbc_model->addCutGenerator(&mixedGen, -1, "MixedIntegerRounding");
|
| 315 |
304 |
|
| 316 |
305 |
CglFlowCover flowGen;
|
| 317 |
306 |
_cbc_model->addCutGenerator(&flowGen, -1, "FlowCover");
|
| 318 |
307 |
|
| 319 |
|
#ifdef COIN_HAS_CLP
|
| 320 |
308 |
OsiClpSolverInterface* osiclp =
|
| 321 |
309 |
dynamic_cast<OsiClpSolverInterface*>(_cbc_model->solver());
|
| 322 |
310 |
if (osiclp->getNumRows() < 300 && osiclp->getNumCols() < 500) {
|
| 323 |
311 |
osiclp->setupForRepeatedUse(2, 0);
|
| 324 |
312 |
}
|
| 325 |
|
#endif
|
| 326 |
313 |
|
| 327 |
314 |
CbcRounding heuristic1(*_cbc_model);
|
| 328 |
315 |
heuristic1.setWhen(3);
|
| 329 |
316 |
_cbc_model->addHeuristic(&heuristic1);
|
| 330 |
317 |
|
| 331 |
318 |
CbcHeuristicLocal heuristic2(*_cbc_model);
|
| 332 |
319 |
heuristic2.setWhen(3);
|
| 333 |
320 |
_cbc_model->addHeuristic(&heuristic2);
|
| 334 |
321 |
|
| 335 |
322 |
CbcHeuristicGreedyCover heuristic3(*_cbc_model);
|
| 336 |
323 |
heuristic3.setAlgorithm(11);
|
| 337 |
324 |
heuristic3.setWhen(3);
|
| 338 |
325 |
_cbc_model->addHeuristic(&heuristic3);
|
| 339 |
326 |
|
| 340 |
327 |
CbcHeuristicFPump heuristic4(*_cbc_model);
|
| 341 |
328 |
heuristic4.setWhen(3);
|
| 342 |
329 |
_cbc_model->addHeuristic(&heuristic4);
|
| 343 |
330 |
|
| 344 |
331 |
CbcHeuristicRINS heuristic5(*_cbc_model);
|
| 345 |
332 |
heuristic5.setWhen(3);
|
| 346 |
333 |
_cbc_model->addHeuristic(&heuristic5);
|
| 347 |
334 |
|
| 348 |
335 |
if (_cbc_model->getNumCols() < 500) {
|
| 349 |
336 |
_cbc_model->setMaximumCutPassesAtRoot(-100);
|