gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Add CBC support (#204)
0 5 3
default
8 files changed with 722 insertions and 10 deletions:
↑ Collapse diff ↑
Ignore white space 128 line context
1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2
 *
3
 * This file is a part of LEMON, a generic C++ optimization library.
4
 *
5
 * Copyright (C) 2003-2009
6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8
 *
9
 * Permission to use, modify and distribute this software is granted
10
 * provided that this copyright notice appears in all copies. For
11
 * precise terms see the accompanying LICENSE file.
12
 *
13
 * This software is provided "AS IS" with no warranty of any kind,
14
 * express or implied, and with no claim as to its suitability for any
15
 * purpose.
16
 *
17
 */
18

	
19
///\file
20
///\brief Implementation of the CBC MIP solver interface.
21

	
22
#include "cbc.h"
23

	
24
#include <coin/CoinModel.hpp>
25
#include <coin/CbcModel.hpp>
26
#include <coin/OsiSolverInterface.hpp>
27

	
28
#ifdef COIN_HAS_CLP
29
#include "coin/OsiClpSolverInterface.hpp"
30
#endif
31
#ifdef COIN_HAS_OSL
32
#include "coin/OsiOslSolverInterface.hpp"
33
#endif
34

	
35
#include "coin/CbcCutGenerator.hpp"
36
#include "coin/CbcHeuristicLocal.hpp"
37
#include "coin/CbcHeuristicGreedy.hpp"
38
#include "coin/CbcHeuristicFPump.hpp"
39
#include "coin/CbcHeuristicRINS.hpp"
40

	
41
#include "coin/CglGomory.hpp"
42
#include "coin/CglProbing.hpp"
43
#include "coin/CglKnapsackCover.hpp"
44
#include "coin/CglOddHole.hpp"
45
#include "coin/CglClique.hpp"
46
#include "coin/CglFlowCover.hpp"
47
#include "coin/CglMixedIntegerRounding.hpp"
48

	
49
#include "coin/CbcHeuristic.hpp"
50

	
51
namespace lemon {
52

	
53
  CbcMip::CbcMip() {
54
    _prob = new CoinModel();
55
    _prob->setProblemName("LEMON");
56
    _osi_solver = 0;
57
    _cbc_model = 0;
58
  }
59

	
60
  CbcMip::CbcMip(const CbcMip& other) {
61
    _prob = new CoinModel(*other._prob);
62
    _osi_solver = 0;
63
    _cbc_model = 0;
64
  }
65

	
66
  CbcMip::~CbcMip() {
67
    delete _prob;
68
    if (_osi_solver) delete _osi_solver;
69
    if (_cbc_model) delete _cbc_model;
70
  }
71

	
72
  const char* CbcMip::_solverName() const { return "CbcMip"; }
73

	
74
  int CbcMip::_addCol() {
75
    _prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0, 0, false);
76
    return _prob->numberColumns() - 1;
77
  }
78

	
79
  CbcMip* CbcMip::newSolver() const {
80
    CbcMip* newlp = new CbcMip;
81
    return newlp;
82
  }
83

	
84
  CbcMip* CbcMip::cloneSolver() const {
85
    CbcMip* copylp = new CbcMip(*this);
86
    return copylp;
87
  }
88

	
89
  int CbcMip::_addRow() {
90
    _prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX);
91
    return _prob->numberRows() - 1;
92
  }
93

	
94

	
95
  void CbcMip::_eraseCol(int i) {
96
    _prob->deleteColumn(i);
97
  }
98

	
99
  void CbcMip::_eraseRow(int i) {
100
    _prob->deleteRow(i);
101
  }
102

	
103
  void CbcMip::_eraseColId(int i) {
104
    cols.eraseIndex(i);
105
  }
106

	
107
  void CbcMip::_eraseRowId(int i) {
108
    rows.eraseIndex(i);
109
  }
110

	
111
  void CbcMip::_getColName(int c, std::string& name) const {
112
    name = _prob->getColumnName(c);
113
  }
114

	
115
  void CbcMip::_setColName(int c, const std::string& name) {
116
    _prob->setColumnName(c, name.c_str());
117
  }
118

	
119
  int CbcMip::_colByName(const std::string& name) const {
120
    return _prob->column(name.c_str());
121
  }
122

	
123
  void CbcMip::_getRowName(int r, std::string& name) const {
124
    name = _prob->getRowName(r);
125
  }
126

	
127
  void CbcMip::_setRowName(int r, const std::string& name) {
128
    _prob->setRowName(r, name.c_str());
129
  }
130

	
131
  int CbcMip::_rowByName(const std::string& name) const {
132
    return _prob->row(name.c_str());
133
  }
134

	
135
  void CbcMip::_setRowCoeffs(int i, ExprIterator b, ExprIterator e) {
136
    for (ExprIterator it = b; it != e; ++it) {
137
      _prob->setElement(i, it->first, it->second);
138
    }
139
  }
140

	
141
  void CbcMip::_getRowCoeffs(int ix, InsertIterator b) const {
142
    int length = _prob->numberRows();
143

	
144
    std::vector<int> indices(length);
145
    std::vector<Value> values(length);
146

	
147
    length = _prob->getRow(ix, &indices[0], &values[0]);
148

	
149
    for (int i = 0; i < length; ++i) {
150
      *b = std::make_pair(indices[i], values[i]);
151
      ++b;
152
    }
153
  }
154

	
155
  void CbcMip::_setColCoeffs(int ix, ExprIterator b, ExprIterator e) {
156
    for (ExprIterator it = b; it != e; ++it) {
157
      _prob->setElement(it->first, ix, it->second);
158
    }
159
  }
160

	
161
  void CbcMip::_getColCoeffs(int ix, InsertIterator b) const {
162
    int length = _prob->numberColumns();
163

	
164
    std::vector<int> indices(length);
165
    std::vector<Value> values(length);
166

	
167
    length = _prob->getColumn(ix, &indices[0], &values[0]);
168

	
169
    for (int i = 0; i < length; ++i) {
170
      *b = std::make_pair(indices[i], values[i]);
171
      ++b;
172
    }
173
  }
174

	
175
  void CbcMip::_setCoeff(int ix, int jx, Value value) {
176
    _prob->setElement(ix, jx, value);
177
  }
178

	
179
  CbcMip::Value CbcMip::_getCoeff(int ix, int jx) const {
180
    return _prob->getElement(ix, jx);
181
  }
182

	
183

	
184
  void CbcMip::_setColLowerBound(int i, Value lo) {
185
    LEMON_ASSERT(lo != INF, "Invalid bound");
186
    _prob->setColumnLower(i, lo == - INF ? - COIN_DBL_MAX : lo);
187
  }
188

	
189
  CbcMip::Value CbcMip::_getColLowerBound(int i) const {
190
    double val = _prob->getColumnLower(i);
191
    return val == - COIN_DBL_MAX ? - INF : val;
192
  }
193

	
194
  void CbcMip::_setColUpperBound(int i, Value up) {
195
    LEMON_ASSERT(up != -INF, "Invalid bound");
196
    _prob->setColumnUpper(i, up == INF ? COIN_DBL_MAX : up);
197
  }
198

	
199
  CbcMip::Value CbcMip::_getColUpperBound(int i) const {
200
    double val = _prob->getColumnUpper(i);
201
    return val == COIN_DBL_MAX ? INF : val;
202
  }
203

	
204
  void CbcMip::_setRowLowerBound(int i, Value lo) {
205
    LEMON_ASSERT(lo != INF, "Invalid bound");
206
    _prob->setRowLower(i, lo == - INF ? - COIN_DBL_MAX : lo);
207
  }
208

	
209
  CbcMip::Value CbcMip::_getRowLowerBound(int i) const {
210
    double val = _prob->getRowLower(i);
211
    return val == - COIN_DBL_MAX ? - INF : val;
212
  }
213

	
214
  void CbcMip::_setRowUpperBound(int i, Value up) {
215
    LEMON_ASSERT(up != -INF, "Invalid bound");
216
    _prob->setRowUpper(i, up == INF ? COIN_DBL_MAX : up);
217
  }
218

	
219
  CbcMip::Value CbcMip::_getRowUpperBound(int i) const {
220
    double val = _prob->getRowUpper(i);
221
    return val == COIN_DBL_MAX ? INF : val;
222
  }
223

	
224
  void CbcMip::_setObjCoeffs(ExprIterator b, ExprIterator e) {
225
    int num = _prob->numberColumns();
226
    for (int i = 0; i < num; ++i) {
227
      _prob->setColumnObjective(i, 0.0);
228
    }
229
    for (ExprIterator it = b; it != e; ++it) {
230
      _prob->setColumnObjective(it->first, it->second);
231
    }
232
  }
233

	
234
  void CbcMip::_getObjCoeffs(InsertIterator b) const {
235
    int num = _prob->numberColumns();
236
    for (int i = 0; i < num; ++i) {
237
      Value coef = _prob->getColumnObjective(i);
238
      if (coef != 0.0) {
239
        *b = std::make_pair(i, coef);
240
        ++b;
241
      }
242
    }
243
  }
244

	
245
  void CbcMip::_setObjCoeff(int i, Value obj_coef) {
246
    _prob->setColumnObjective(i, obj_coef);
247
  }
248

	
249
  CbcMip::Value CbcMip::_getObjCoeff(int i) const {
250
    return _prob->getColumnObjective(i);
251
  }
252

	
253
  CbcMip::SolveExitStatus CbcMip::_solve() {
254

	
255
    if (_osi_solver) {
256
      delete _osi_solver;
257
    }
258
#ifdef COIN_HAS_CLP
259
    _osi_solver = new OsiClpSolverInterface();
260
#elif COIN_HAS_OSL
261
    _osi_solver = new OsiOslSolverInterface();
262
#else
263
#error Cannot instantiate Osi solver
264
#endif
265

	
266
    _osi_solver->loadFromCoinModel(*_prob);
267

	
268
    if (_cbc_model) {
269
      delete _cbc_model;
270
    }
271
    _cbc_model= new CbcModel(*_osi_solver);
272

	
273
    switch (_message_level) {
274
    case MESSAGE_NO_OUTPUT:
275
      _osi_solver->messageHandler()->setLogLevel(0);
276
      _cbc_model->setLogLevel(0);
277
      break;
278
    case MESSAGE_ERROR_MESSAGE:
279
      _osi_solver->messageHandler()->setLogLevel(1);
280
      _cbc_model->setLogLevel(1);
281
      break;
282
    case MESSAGE_NORMAL_OUTPUT:
283
      _osi_solver->messageHandler()->setLogLevel(2);
284
      _cbc_model->setLogLevel(2);
285
      break;
286
    case MESSAGE_FULL_OUTPUT:
287
      _osi_solver->messageHandler()->setLogLevel(3);
288
      _cbc_model->setLogLevel(3);
289
      break;
290
    }
291

	
292
    _cbc_model->initialSolve();
293
    _cbc_model->solver()->setHintParam(OsiDoReducePrint, true, OsiHintTry);
294

	
295
    if (!_cbc_model->isInitialSolveAbandoned() &&
296
        _cbc_model->isInitialSolveProvenOptimal() &&
297
        !_cbc_model->isInitialSolveProvenPrimalInfeasible() &&
298
        !_cbc_model->isInitialSolveProvenDualInfeasible()) {
299

	
300
      CglProbing generator1;
301
      generator1.setUsingObjective(true);
302
      generator1.setMaxPass(3);
303
      generator1.setMaxProbe(100);
304
      generator1.setMaxLook(50);
305
      generator1.setRowCuts(3);
306
      _cbc_model->addCutGenerator(&generator1, -1, "Probing");
307

	
308
      CglGomory generator2;
309
      generator2.setLimit(300);
310
      _cbc_model->addCutGenerator(&generator2, -1, "Gomory");
311

	
312
      CglKnapsackCover generator3;
313
      _cbc_model->addCutGenerator(&generator3, -1, "Knapsack");
314

	
315
      CglOddHole generator4;
316
      generator4.setMinimumViolation(0.005);
317
      generator4.setMinimumViolationPer(0.00002);
318
      generator4.setMaximumEntries(200);
319
      _cbc_model->addCutGenerator(&generator4, -1, "OddHole");
320

	
321
      CglClique generator5;
322
      generator5.setStarCliqueReport(false);
323
      generator5.setRowCliqueReport(false);
324
      _cbc_model->addCutGenerator(&generator5, -1, "Clique");
325

	
326
      CglMixedIntegerRounding mixedGen;
327
      _cbc_model->addCutGenerator(&mixedGen, -1, "MixedIntegerRounding");
328

	
329
      CglFlowCover flowGen;
330
      _cbc_model->addCutGenerator(&flowGen, -1, "FlowCover");
331

	
332
#ifdef COIN_HAS_CLP
333
      OsiClpSolverInterface* osiclp =
334
        dynamic_cast<OsiClpSolverInterface*>(_cbc_model->solver());
335
      if (osiclp->getNumRows() < 300 && osiclp->getNumCols() < 500) {
336
        osiclp->setupForRepeatedUse(2, 0);
337
      }
338
#endif
339

	
340
      CbcRounding heuristic1(*_cbc_model);
341
      heuristic1.setWhen(3);
342
      _cbc_model->addHeuristic(&heuristic1);
343

	
344
      CbcHeuristicLocal heuristic2(*_cbc_model);
345
      heuristic2.setWhen(3);
346
      _cbc_model->addHeuristic(&heuristic2);
347

	
348
      CbcHeuristicGreedyCover heuristic3(*_cbc_model);
349
      heuristic3.setAlgorithm(11);
350
      heuristic3.setWhen(3);
351
      _cbc_model->addHeuristic(&heuristic3);
352

	
353
      CbcHeuristicFPump heuristic4(*_cbc_model);
354
      heuristic4.setWhen(3);
355
      _cbc_model->addHeuristic(&heuristic4);
356

	
357
      CbcHeuristicRINS heuristic5(*_cbc_model);
358
      heuristic5.setWhen(3);
359
      _cbc_model->addHeuristic(&heuristic5);
360

	
361
      if (_cbc_model->getNumCols() < 500) {
362
        _cbc_model->setMaximumCutPassesAtRoot(-100);
363
      } else if (_cbc_model->getNumCols() < 5000) {
364
        _cbc_model->setMaximumCutPassesAtRoot(100);
365
      } else {
366
        _cbc_model->setMaximumCutPassesAtRoot(20);
367
      }
368

	
369
      if (_cbc_model->getNumCols() < 5000) {
370
        _cbc_model->setNumberStrong(10);
371
      }
372

	
373
      _cbc_model->solver()->setIntParam(OsiMaxNumIterationHotStart, 100);
374
      _cbc_model->branchAndBound();
375
    }
376

	
377
    if (_cbc_model->isAbandoned()) {
378
      return UNSOLVED;
379
    } else {
380
      return SOLVED;
381
    }
382
  }
383

	
384
  CbcMip::Value CbcMip::_getSol(int i) const {
385
    return _cbc_model->getColSolution()[i];
386
  }
387

	
388
  CbcMip::Value CbcMip::_getSolValue() const {
389
    return _cbc_model->getObjValue();
390
  }
391

	
392
  CbcMip::ProblemType CbcMip::_getType() const {
393
    if (_cbc_model->isProvenOptimal()) {
394
      return OPTIMAL;
395
    } else if (_cbc_model->isContinuousUnbounded()) {
396
      return UNBOUNDED;
397
    }
398
    return FEASIBLE;
399
  }
400

	
401
  void CbcMip::_setSense(Sense sense) {
402
    switch (sense) {
403
    case MIN:
404
      _prob->setOptimizationDirection(1.0);
405
      break;
406
    case MAX:
407
      _prob->setOptimizationDirection(- 1.0);
408
      break;
409
    }
410
  }
411

	
412
  CbcMip::Sense CbcMip::_getSense() const {
413
    if (_prob->optimizationDirection() > 0.0) {
414
      return MIN;
415
    } else if (_prob->optimizationDirection() < 0.0) {
416
      return MAX;
417
    } else {
418
      LEMON_ASSERT(false, "Wrong sense");
419
      return CbcMip::Sense();
420
    }
421
  }
422

	
423
  void CbcMip::_setColType(int i, CbcMip::ColTypes col_type) {
424
    switch (col_type){
425
    case INTEGER:
426
      _prob->setInteger(i);
427
      break;
428
    case REAL:
429
      _prob->setContinuous(i);
430
      break;
431
    default:;
432
      LEMON_ASSERT(false, "Wrong sense");
433
    }
434
  }
435

	
436
  CbcMip::ColTypes CbcMip::_getColType(int i) const {
437
    return _prob->getColumnIsInteger(i) ? INTEGER : REAL;
438
  }
439

	
440
  void CbcMip::_clear() {
441
    delete _prob;
442
    if (_osi_solver) {
443
      delete _osi_solver;
444
      _osi_solver = 0;
445
    }
446
    if (_cbc_model) {
447
      delete _cbc_model;
448
      _cbc_model = 0;
449
    }
450

	
451
    _prob = new CoinModel();
452
    rows.clear();
453
    cols.clear();
454
  }
455

	
456
  void CbcMip::messageLevel(MessageLevel m) {
457
    _message_level = m;
458
  }
459

	
460
} //END OF NAMESPACE LEMON
Ignore white space 128 line context
1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2
 *
3
 * This file is a part of LEMON, a generic C++ optimization library.
4
 *
5
 * Copyright (C) 2003-2009
6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8
 *
9
 * Permission to use, modify and distribute this software is granted
10
 * provided that this copyright notice appears in all copies. For
11
 * precise terms see the accompanying LICENSE file.
12
 *
13
 * This software is provided "AS IS" with no warranty of any kind,
14
 * express or implied, and with no claim as to its suitability for any
15
 * purpose.
16
 *
17
 */
18

	
19
// -*- C++ -*-
20
#ifndef LEMON_CBC_H
21
#define LEMON_CBC_H
22

	
23
///\file
24
///\brief Header of the LEMON-CBC mip solver interface.
25
///\ingroup lp_group
26

	
27
#include <lemon/lp_base.h>
28

	
29
class CoinModel;
30
class OsiSolverInterface;
31
class CbcModel;
32

	
33
namespace lemon {
34

	
35
  /// \brief Interface for the CBC MIP solver
36
  ///
37
  /// This class implements an interface for the CBC MIP solver.
38
  ///\ingroup lp_group
39
  class CbcMip : public MipSolver {
40
  protected:
41

	
42
    CoinModel *_prob;
43
    OsiSolverInterface *_osi_solver;
44
    CbcModel *_cbc_model;
45

	
46
  public:
47

	
48
    /// \e
49
    CbcMip();
50
    /// \e
51
    CbcMip(const CbcMip&);
52
    /// \e
53
    ~CbcMip();
54
    /// \e
55
    virtual CbcMip* newSolver() const;
56
    /// \e
57
    virtual CbcMip* cloneSolver() const;
58

	
59
  protected:
60

	
61
    virtual const char* _solverName() const;
62

	
63
    virtual int _addCol();
64
    virtual int _addRow();
65

	
66
    virtual void _eraseCol(int i);
67
    virtual void _eraseRow(int i);
68

	
69
    virtual void _eraseColId(int i);
70
    virtual void _eraseRowId(int i);
71

	
72
    virtual void _getColName(int col, std::string& name) const;
73
    virtual void _setColName(int col, const std::string& name);
74
    virtual int _colByName(const std::string& name) const;
75

	
76
    virtual void _getRowName(int row, std::string& name) const;
77
    virtual void _setRowName(int row, const std::string& name);
78
    virtual int _rowByName(const std::string& name) const;
79

	
80
    virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
81
    virtual void _getRowCoeffs(int i, InsertIterator b) const;
82

	
83
    virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
84
    virtual void _getColCoeffs(int i, InsertIterator b) const;
85

	
86
    virtual void _setCoeff(int row, int col, Value value);
87
    virtual Value _getCoeff(int row, int col) const;
88

	
89
    virtual void _setColLowerBound(int i, Value value);
90
    virtual Value _getColLowerBound(int i) const;
91
    virtual void _setColUpperBound(int i, Value value);
92
    virtual Value _getColUpperBound(int i) const;
93

	
94
    virtual void _setRowLowerBound(int i, Value value);
95
    virtual Value _getRowLowerBound(int i) const;
96
    virtual void _setRowUpperBound(int i, Value value);
97
    virtual Value _getRowUpperBound(int i) const;
98

	
99
    virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
100
    virtual void _getObjCoeffs(InsertIterator b) const;
101

	
102
    virtual void _setObjCoeff(int i, Value obj_coef);
103
    virtual Value _getObjCoeff(int i) const;
104

	
105
    virtual void _setSense(Sense sense);
106
    virtual Sense _getSense() const;
107

	
108
    virtual ColTypes _getColType(int col) const;
109
    virtual void _setColType(int col, ColTypes col_type);
110

	
111
    virtual SolveExitStatus _solve();
112
    virtual ProblemType _getType() const;
113
    virtual Value _getSol(int i) const;
114
    virtual Value _getSolValue() const;
115

	
116
    virtual void _clear();
117

	
118
  public:
119

	
120
    ///Enum for \c messageLevel() parameter
121
    enum MessageLevel {
122
      /// no output (default value)
123
      MESSAGE_NO_OUTPUT = 0,
124
      /// error messages only
125
      MESSAGE_ERROR_MESSAGE = 1,
126
      /// normal output
127
      MESSAGE_NORMAL_OUTPUT = 2,
128
      /// full output (includes informational messages)
129
      MESSAGE_FULL_OUTPUT = 3
130
    };
131

	
132
  private:
133

	
134
    MessageLevel _message_level;
135

	
136
  public:
137

	
138
    ///Set the verbosity of the messages
139

	
140
    ///Set the verbosity of the messages
141
    ///
142
    ///\param m is the level of the messages output by the solver routines.
143
    void messageLevel(MessageLevel m);
144

	
145

	
146
  };
147

	
148
}
149

	
150
#endif
Ignore white space 128 line context
1
AC_DEFUN([LX_CHECK_CBC],
2
[
3
  AC_ARG_WITH([cbc],
4
AS_HELP_STRING([--with-cbc@<:@=PREFIX@:>@], [search for CBC under PREFIX or under the default search paths if PREFIX is not given @<:@default@:>@])
5
AS_HELP_STRING([--without-cbc], [disable checking for CBC]),
6
              [], [with_cbc=yes])
7

	
8
  AC_ARG_WITH([cbc-includedir],
9
AS_HELP_STRING([--with-cbc-includedir=DIR], [search for CBC headers in DIR]),
10
              [], [with_cbc_includedir=no])
11

	
12
  AC_ARG_WITH([cbc-libdir],
13
AS_HELP_STRING([--with-cbc-libdir=DIR], [search for CBC libraries in DIR]),
14
              [], [with_cbc_libdir=no])
15

	
16
  lx_cbc_found=no
17
  if test x"$with_cbc" != x"no"; then
18
    AC_MSG_CHECKING([for CBC])
19

	
20
    if test x"$with_cbc_includedir" != x"no"; then
21
      CBC_CXXFLAGS="-I$with_cbc_includedir"
22
    elif test x"$with_cbc" != x"yes"; then
23
      CBC_CXXFLAGS="-I$with_cbc/include"
24
    fi
25

	
26
    if test x"$with_cbc_libdir" != x"no"; then
27
      CBC_LDFLAGS="-L$with_cbc_libdir"
28
    elif test x"$with_cbc" != x"yes"; then
29
      CBC_LDFLAGS="-L$with_cbc/lib"
30
    fi
31
    CBC_LIBS="-lOsi -lCbc -lOsiCbc -lCbcSolver -lClp -lOsiClp -lCoinUtils -lVol -lOsiVol -lCgl -lm -llapack -lblas"
32

	
33
    lx_save_cxxflags="$CXXFLAGS"
34
    lx_save_ldflags="$LDFLAGS"
35
    lx_save_libs="$LIBS"
36
    CXXFLAGS="$CBC_CXXFLAGS"
37
    LDFLAGS="$CBC_LDFLAGS"
38
    LIBS="$CBC_LIBS"
39

	
40
    lx_cbc_test_prog='
41
      #include <coin/CbcModel.hpp>
42

	
43
      int main(int argc, char** argv)
44
      {
45
        CbcModel cbc;
46
        return 0;
47
      }'
48

	
49
    AC_LANG_PUSH(C++)
50
    AC_LINK_IFELSE([$lx_cbc_test_prog], [lx_cbc_found=yes], [lx_cbc_found=no])
51
    AC_LANG_POP(C++)
52

	
53
    CXXFLAGS="$lx_save_cxxflags"
54
    LDFLAGS="$lx_save_ldflags"
55
    LIBS="$lx_save_libs"
56

	
57
    if test x"$lx_cbc_found" = x"yes"; then
58
      AC_DEFINE([HAVE_CBC], [1], [Define to 1 if you have CBC.])
59
      lx_lp_found=yes
60
      AC_DEFINE([HAVE_LP], [1], [Define to 1 if you have any LP solver.])
61
      AC_MSG_RESULT([yes])
62
    else
63
      CBC_CXXFLAGS=""
64
      CBC_LDFLAGS=""
65
      CBC_LIBS=""
66
      AC_MSG_RESULT([no])
67
    fi
68
  fi
69
  CBC_LIBS="$CBC_LDFLAGS $CBC_LIBS"
70
  AC_SUBST(CBC_CXXFLAGS)
71
  AC_SUBST(CBC_LIBS)
72
  AM_CONDITIONAL([HAVE_CBC], [test x"$lx_cbc_found" = x"yes"])
73
])
Ignore white space 128 line context
1 1
ACLOCAL_AMFLAGS = -I m4
2 2

	
3 3
AM_CXXFLAGS = $(WARNINGCXXFLAGS)
4 4

	
5 5
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_builddir)
6 6
LDADD = $(top_builddir)/lemon/libemon.la
7 7

	
8 8
EXTRA_DIST = \
9 9
	AUTHORS \
10 10
	LICENSE \
11 11
	m4/lx_check_cplex.m4 \
12 12
	m4/lx_check_glpk.m4 \
13 13
	m4/lx_check_soplex.m4 \
14
	m4/lx_check_clp.m4 \
15
	m4/lx_check_cbc.m4 \
14 16
	CMakeLists.txt \
15 17
	cmake/FindGhostscript.cmake \
16 18
	cmake/FindGLPK.cmake \
17 19
	cmake/version.cmake.in \
18 20
	cmake/version.cmake \
19 21
	cmake/nsis/lemon.ico \
20 22
	cmake/nsis/uninstall.ico
21 23

	
22 24
pkgconfigdir = $(libdir)/pkgconfig
23 25
lemondir = $(pkgincludedir)
24 26
bitsdir = $(lemondir)/bits
25 27
conceptdir = $(lemondir)/concepts
26 28
pkgconfig_DATA =
27 29
lib_LTLIBRARIES =
28 30
lemon_HEADERS =
29 31
bits_HEADERS =
30 32
concept_HEADERS =
31 33
noinst_HEADERS =
32 34
noinst_PROGRAMS =
33 35
bin_PROGRAMS =
34 36
check_PROGRAMS =
35 37
dist_bin_SCRIPTS =
36 38
TESTS =
37 39
XFAIL_TESTS =
38 40

	
39 41
include lemon/Makefile.am
40 42
include test/Makefile.am
41 43
include doc/Makefile.am
42 44
include tools/Makefile.am
43 45

	
44 46
DIST_SUBDIRS = demo
45 47

	
46 48
demo:
47 49
	$(MAKE) $(AM_MAKEFLAGS) -C demo
48 50

	
49 51
MRPROPERFILES = \
50 52
	aclocal.m4 \
51 53
	config.h.in \
52 54
	config.h.in~ \
53 55
	configure \
54 56
	Makefile.in \
55 57
	build-aux/config.guess \
56 58
	build-aux/config.sub \
57 59
	build-aux/depcomp \
58 60
	build-aux/install-sh \
59 61
	build-aux/ltmain.sh \
60 62
	build-aux/missing \
61 63
	doc/doxygen.log
62 64

	
63 65
mrproper:
64 66
	$(MAKE) $(AM_MAKEFLAGS) maintainer-clean
65 67
	-rm -f $(MRPROPERFILES)
66 68

	
67 69
dist-bz2: dist
68 70
	zcat $(PACKAGE)-$(VERSION).tar.gz | \
69 71
	bzip2 --best -c > $(PACKAGE)-$(VERSION).tar.bz2
70 72

	
71 73
distcheck-bz2: distcheck
72 74
	zcat $(PACKAGE)-$(VERSION).tar.gz | \
73 75
	bzip2 --best -c > $(PACKAGE)-$(VERSION).tar.bz2
74 76

	
75 77
.PHONY: demo mrproper dist-bz2 distcheck-bz2
Ignore white space 128 line context
1 1
dnl Process this file with autoconf to produce a configure script.
2 2

	
3 3
dnl Version information.
4 4
m4_define([lemon_version_number],
5 5
	[m4_normalize(esyscmd([echo ${LEMON_VERSION}]))])
6 6
dnl m4_define([lemon_version_number], [])
7 7
m4_define([lemon_hg_path], [m4_normalize(esyscmd([./scripts/chg-len.py]))])
8 8
m4_define([lemon_hg_revision], [m4_normalize(esyscmd([hg id -i]))])
9 9
m4_define([lemon_version], [ifelse(lemon_version_number(),
10 10
			   [],
11 11
			   [lemon_hg_path().lemon_hg_revision()],
12 12
			   [lemon_version_number()])])
13 13

	
14 14
AC_PREREQ([2.59])
15 15
AC_INIT([LEMON], [lemon_version()], [lemon-user@lemon.cs.elte.hu], [lemon])
16 16
AC_CONFIG_AUX_DIR([build-aux])
17 17
AC_CONFIG_MACRO_DIR([m4])
18 18
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects nostdinc])
19 19
AC_CONFIG_SRCDIR([lemon/list_graph.h])
20 20
AC_CONFIG_HEADERS([config.h lemon/config.h])
21 21

	
22 22
dnl Do compilation tests using the C++ compiler.
23 23
AC_LANG([C++])
24 24

	
25 25
dnl Check the existence of long long type.
26 26
AC_CHECK_TYPE(long long, [long_long_found=yes], [long_long_found=no])
27 27
if test x"$long_long_found" = x"yes"; then
28 28
  AC_DEFINE([HAVE_LONG_LONG], [1], [Define to 1 if you have long long.])
29 29
fi
30 30

	
31 31
dnl Checks for programs.
32 32
AC_PROG_CXX
33 33
AC_PROG_CXXCPP
34 34
AC_PROG_INSTALL
35 35
AC_DISABLE_SHARED
36 36
AC_PROG_LIBTOOL
37 37

	
38 38
AC_CHECK_PROG([doxygen_found],[doxygen],[yes],[no])
39 39
AC_CHECK_PROG([gs_found],[gs],[yes],[no])
40 40

	
41 41
dnl Detect Intel compiler.
42 42
AC_MSG_CHECKING([whether we are using the Intel C++ compiler])
43 43
AC_COMPILE_IFELSE([#ifndef __INTEL_COMPILER
44 44
choke me
45 45
#endif], [ICC=[yes]], [ICC=[no]])
46 46
if test x"$ICC" = x"yes"; then
47 47
  AC_MSG_RESULT([yes])
48 48
else
49 49
  AC_MSG_RESULT([no])
50 50
fi
51 51

	
52 52
dnl Set custom compiler flags when using g++.
53 53
if test "$GXX" = yes -a "$ICC" = no; then
54 54
  WARNINGCXXFLAGS="-Wall -W -Wall -W -Wunused -Wformat=2 -Wctor-dtor-privacy -Wnon-virtual-dtor -Wno-char-subscripts -Wwrite-strings -Wno-char-subscripts -Wreturn-type -Wcast-qual -Wcast-align -Wsign-promo -Woverloaded-virtual -ansi -fno-strict-aliasing -Wold-style-cast -Wno-unknown-pragmas"
55 55
fi
56 56
AC_SUBST([WARNINGCXXFLAGS])
57 57

	
58 58
dnl Checks for libraries.
59 59
LX_CHECK_GLPK
60 60
LX_CHECK_CPLEX
61 61
LX_CHECK_SOPLEX
62 62
LX_CHECK_CLP
63
LX_CHECK_CBC
63 64

	
64 65
AM_CONDITIONAL([HAVE_LP], [test x"$lx_lp_found" = x"yes"])
65 66
AM_CONDITIONAL([HAVE_MIP], [test x"$lx_mip_found" = x"yes"])
66 67

	
67 68
dnl Disable/enable building the binary tools.
68 69
AC_ARG_ENABLE([tools],
69 70
AS_HELP_STRING([--enable-tools], [build additional tools @<:@default@:>@])
70 71
AS_HELP_STRING([--disable-tools], [do not build additional tools]),
71 72
              [], [enable_tools=yes])
72 73
AC_MSG_CHECKING([whether to build the additional tools])
73 74
if test x"$enable_tools" != x"no"; then
74 75
  AC_MSG_RESULT([yes])
75 76
else
76 77
  AC_MSG_RESULT([no])
77 78
fi
78 79
AM_CONDITIONAL([WANT_TOOLS], [test x"$enable_tools" != x"no"])
79 80

	
80 81
dnl Checks for header files.
81 82
AC_CHECK_HEADERS(limits.h sys/time.h sys/times.h unistd.h)
82 83

	
83 84
dnl Checks for typedefs, structures, and compiler characteristics.
84 85
AC_C_CONST
85 86
AC_C_INLINE
86 87
AC_TYPE_SIZE_T
87 88
AC_HEADER_TIME
88 89
AC_STRUCT_TM
89 90

	
90 91
dnl Checks for library functions.
91 92
AC_HEADER_STDC
92 93
AC_CHECK_FUNCS(gettimeofday times ctime_r)
93 94

	
94 95
dnl Add dependencies on files generated by configure.
95 96
AC_SUBST([CONFIG_STATUS_DEPENDENCIES],
96 97
  ['$(top_srcdir)/doc/Doxyfile.in $(top_srcdir)/lemon/lemon.pc.in $(top_srcdir)/cmake/version.cmake.in'])
97 98

	
98 99
AC_CONFIG_FILES([
99 100
Makefile
100 101
demo/Makefile
101 102
cmake/version.cmake
102 103
doc/Doxyfile
103 104
lemon/lemon.pc
104 105
])
105 106

	
106 107
AC_OUTPUT
107 108

	
108 109
echo
109 110
echo '****************************** SUMMARY ******************************'
110 111
echo
111 112
echo Package version............... : $PACKAGE-$VERSION
112 113
echo
113 114
echo C++ compiler.................. : $CXX
114 115
echo C++ compiles flags............ : $WARNINGCXXFLAGS $CXXFLAGS
115 116
echo
116 117
echo Compiler supports long long... : $long_long_found
117 118
echo
118 119
echo GLPK support.................. : $lx_glpk_found
119 120
echo CPLEX support................. : $lx_cplex_found
120 121
echo SOPLEX support................ : $lx_soplex_found
121 122
echo CLP support................... : $lx_clp_found
123
echo CBC support................... : $lx_cbc_found
122 124
echo
123 125
echo Build additional tools........ : $enable_tools
124 126
echo
125 127
echo The packace will be installed in
126 128
echo -n '  '
127 129
echo $prefix.
128 130
echo
129 131
echo '*********************************************************************'
130 132

	
131 133
echo
132 134
echo Configure complete, now type \'make\' and then \'make install\'.
133 135
echo
Ignore white space 128 line context
1 1
EXTRA_DIST += \
2 2
	lemon/lemon.pc.in \
3 3
	lemon/CMakeLists.txt
4 4

	
5 5
pkgconfig_DATA += lemon/lemon.pc
6 6

	
7 7
lib_LTLIBRARIES += lemon/libemon.la
8 8

	
9 9
lemon_libemon_la_SOURCES = \
10 10
	lemon/arg_parser.cc \
11 11
	lemon/base.cc \
12 12
	lemon/color.cc \
13 13
	lemon/lp_base.cc \
14 14
	lemon/lp_skeleton.cc \
15
        lemon/random.cc \
15
	lemon/random.cc \
16 16
	lemon/bits/windows.cc
17 17

	
18 18

	
19 19
lemon_libemon_la_CXXFLAGS = \
20 20
	$(AM_CXXFLAGS) \
21 21
	$(GLPK_CFLAGS) \
22 22
	$(CPLEX_CFLAGS) \
23 23
	$(SOPLEX_CXXFLAGS) \
24
	$(CLP_CXXFLAGS)
24
	$(CLP_CXXFLAGS) \
25
	$(CBC_CXXFLAGS)
25 26

	
26 27
lemon_libemon_la_LDFLAGS = \
27 28
	$(GLPK_LIBS) \
28 29
	$(CPLEX_LIBS) \
29 30
	$(SOPLEX_LIBS) \
30
	$(CLP_LIBS)
31
	$(CLP_LIBS) \
32
	$(CBC_LIBS)
31 33

	
32 34
if HAVE_GLPK
33 35
lemon_libemon_la_SOURCES += lemon/glpk.cc
34 36
endif
35 37

	
36 38
if HAVE_CPLEX
37 39
lemon_libemon_la_SOURCES += lemon/cplex.cc
38 40
endif
39 41

	
40 42
if HAVE_SOPLEX
41 43
lemon_libemon_la_SOURCES += lemon/soplex.cc
42 44
endif
43 45

	
44 46
if HAVE_CLP
45 47
lemon_libemon_la_SOURCES += lemon/clp.cc
46 48
endif
47 49

	
50
if HAVE_CBC
51
lemon_libemon_la_SOURCES += lemon/cbc.cc
52
endif
53

	
48 54
lemon_HEADERS += \
49 55
	lemon/adaptors.h \
50 56
	lemon/arg_parser.h \
51 57
	lemon/assert.h \
52 58
	lemon/bfs.h \
53 59
	lemon/bin_heap.h \
54 60
	lemon/circulation.h \
55 61
	lemon/clp.h \
56 62
	lemon/color.h \
57 63
	lemon/concept_check.h \
58 64
	lemon/connectivity.h \
59 65
	lemon/counter.h \
60 66
	lemon/core.h \
61 67
	lemon/cplex.h \
62 68
	lemon/dfs.h \
63 69
	lemon/dijkstra.h \
64 70
	lemon/dim2.h \
65 71
	lemon/dimacs.h \
66 72
	lemon/edge_set.h \
67 73
	lemon/elevator.h \
68 74
	lemon/error.h \
69 75
	lemon/euler.h \
70 76
	lemon/full_graph.h \
71 77
	lemon/glpk.h \
72 78
	lemon/gomory_hu.h \
73 79
	lemon/graph_to_eps.h \
74 80
	lemon/grid_graph.h \
75 81
	lemon/hypercube_graph.h \
76 82
	lemon/kruskal.h \
77 83
	lemon/hao_orlin.h \
78 84
	lemon/lgf_reader.h \
79 85
	lemon/lgf_writer.h \
80 86
	lemon/list_graph.h \
81 87
	lemon/lp.h \
82 88
	lemon/lp_base.h \
83 89
	lemon/lp_skeleton.h \
84 90
	lemon/list_graph.h \
85 91
	lemon/maps.h \
86 92
	lemon/math.h \
87 93
	lemon/max_matching.h \
88 94
	lemon/min_cost_arborescence.h \
89 95
	lemon/nauty_reader.h \
90 96
	lemon/path.h \
91 97
	lemon/preflow.h \
92 98
	lemon/radix_sort.h \
93 99
	lemon/random.h \
94 100
	lemon/smart_graph.h \
95 101
	lemon/soplex.h \
96 102
	lemon/suurballe.h \
97 103
	lemon/time_measure.h \
98 104
	lemon/tolerance.h \
99 105
	lemon/unionfind.h \
100 106
	lemon/bits/windows.h
101 107

	
102 108
bits_HEADERS += \
103 109
	lemon/bits/alteration_notifier.h \
104 110
	lemon/bits/array_map.h \
105 111
	lemon/bits/base_extender.h \
106 112
	lemon/bits/bezier.h \
107 113
	lemon/bits/default_map.h \
108 114
	lemon/bits/edge_set_extender.h \
109 115
	lemon/bits/enable_if.h \
110 116
	lemon/bits/graph_adaptor_extender.h \
111 117
	lemon/bits/graph_extender.h \
Ignore white space 128 line context
1 1
/* Define to 1 if you have long long */
2 2
#undef HAVE_LONG_LONG
3 3

	
4 4
/* Define to 1 if you have any LP solver. */
5 5
#undef HAVE_LP
6 6

	
7 7
/* Define to 1 if you have any MIP solver. */
8 8
#undef HAVE_MIP
9 9

	
10 10
/* Define to 1 if you have CPLEX. */
11 11
#undef HAVE_CPLEX
12 12

	
13 13
/* Define to 1 if you have GLPK. */
14 14
#undef HAVE_GLPK
15 15

	
16 16
/* Define to 1 if you have SOPLEX */
17 17
#undef HAVE_SOPLEX
18 18

	
19 19
/* Define to 1 if you have CLP */
20 20
#undef HAVE_CLP
21

	
22
/* Define to 1 if you have CBC */
23
#undef HAVE_CBC
Ignore white space 128 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
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
#include "test_tools.h"
20 20

	
21

	
22 21
#ifdef HAVE_CONFIG_H
23 22
#include <lemon/config.h>
24 23
#endif
25 24

	
26 25
#ifdef HAVE_CPLEX
27 26
#include <lemon/cplex.h>
28 27
#endif
29 28

	
30 29
#ifdef HAVE_GLPK
31 30
#include <lemon/glpk.h>
32 31
#endif
33 32

	
33
#ifdef HAVE_CBC
34
#include <lemon/cbc.h>
35
#endif
36

	
34 37

	
35 38
using namespace lemon;
36 39

	
37 40
void solveAndCheck(MipSolver& mip, MipSolver::ProblemType stat,
38 41
                   double exp_opt) {
39 42
  using std::string;
40 43

	
41 44
  mip.solve();
42 45
  //int decimal,sign;
43 46
  std::ostringstream buf;
44 47
  buf << "Type should be: " << int(stat)<<" and it is "<<int(mip.type());
45 48

	
46 49

	
47 50
  //  itoa(stat,buf1, 10);
48 51
  check(mip.type()==stat, buf.str());
49 52

	
50 53
  if (stat ==  MipSolver::OPTIMAL) {
51 54
    std::ostringstream sbuf;
52 55
    buf << "Wrong optimal value: the right optimum is " << exp_opt;
53 56
    check(std::abs(mip.solValue()-exp_opt) < 1e-3, sbuf.str());
54 57
    //+ecvt(exp_opt,2)
55 58
  }
56 59
}
57 60

	
58 61
void aTest(MipSolver& mip)
59 62
{
60
 //The following example is very simple
63
  //The following example is very simple
61 64

	
62 65

	
63 66
  typedef MipSolver::Row Row;
64 67
  typedef MipSolver::Col Col;
65 68

	
66 69

	
67

	
68 70
  Col x1 = mip.addCol();
69 71
  Col x2 = mip.addCol();
70 72

	
71 73

	
72 74
  //Objective function
73 75
  mip.obj(x1);
74 76

	
75 77
  mip.max();
76 78

	
77

	
78 79
  //Unconstrained optimization
79 80
  mip.solve();
80 81
  //Check it out!
81 82

	
82 83
  //Constraints
83
  mip.addRow(2*x1+x2 <=2);
84
  mip.addRow(x1-2*x2 <=0);
84
  mip.addRow(2 * x1 + x2 <= 2);
85
  Row y2 = mip.addRow(x1 - 2 * x2 <= 0);
85 86

	
86 87
  //Nonnegativity of the variable x1
87 88
  mip.colLowerBound(x1, 0);
88 89

	
90

	
89 91
  //Maximization of x1
90 92
  //over the triangle with vertices (0,0),(4/5,2/5),(0,2)
91 93
  double expected_opt=4.0/5.0;
92 94
  solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
93 95

	
96

	
94 97
  //Restrict x2 to integer
95 98
  mip.colType(x2,MipSolver::INTEGER);
96 99
  expected_opt=1.0/2.0;
97 100
  solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
98 101

	
99 102

	
100 103
  //Restrict both to integer
101 104
  mip.colType(x1,MipSolver::INTEGER);
102 105
  expected_opt=0;
103 106
  solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
104 107

	
105

	
108
  //Erase a variable
109
  mip.erase(x2);
110
  mip.rowUpperBound(y2, 8);
111
  expected_opt=1;
112
  solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
106 113

	
107 114
}
108 115

	
116

	
109 117
template<class MIP>
110 118
void cloneTest()
111 119
{
112 120

	
113 121
  MIP* mip = new MIP();
114 122
  MIP* mipnew = mip->newSolver();
115 123
  MIP* mipclone = mip->cloneSolver();
116 124
  delete mip;
117 125
  delete mipnew;
118 126
  delete mipclone;
119 127
}
120 128

	
121 129
int main()
122 130
{
123 131

	
124 132
#ifdef HAVE_GLPK
125 133
  {
126 134
    GlpkMip mip1;
127 135
    aTest(mip1);
128 136
    cloneTest<GlpkMip>();
129 137
  }
130 138
#endif
131 139

	
132 140
#ifdef HAVE_CPLEX
133 141
  try {
134 142
    CplexMip mip2;
135 143
    aTest(mip2);
136 144
    cloneTest<CplexMip>();
137 145
  } catch (CplexEnv::LicenseError& error) {
138 146
#ifdef LEMON_FORCE_CPLEX_CHECK
139 147
    check(false, error.what());
140 148
#else
141 149
    std::cerr << error.what() << std::endl;
142 150
    std::cerr << "Cplex license check failed, lp check skipped" << std::endl;
143 151
#endif
144 152
  }
145 153
#endif
146 154

	
155
#ifdef HAVE_CBC
156
  {
157
    CbcMip mip1;
158
    aTest(mip1);
159
    cloneTest<CbcMip>();
160
  }
161
#endif
162

	
147 163
  return 0;
148 164

	
149 165
}
0 comments (0 inline)