COIN-OR::LEMON - Graph Library

Ticket #204: 8c2913a5830a.patch

File 8c2913a5830a.patch, 23.1 KB (added by Balazs Dezso, 16 years ago)

CBC interface

  • Makefile.am

    # HG changeset patch
    # User Balazs Dezso <deba@inf.elte.hu>
    # Date 1238619538 -7200
    # Node ID 8c2913a5830ad845204942710402e1ccd87b361d
    # Parent  fc9e366e6759193639870b0673b5f8b618899185
    Add CBC support
    
    diff -r fc9e366e6759 -r 8c2913a5830a Makefile.am
    a b  
    1111        m4/lx_check_cplex.m4 \
    1212        m4/lx_check_glpk.m4 \
    1313        m4/lx_check_soplex.m4 \
     14        m4/lx_check_clp.m4 \
     15        m4/lx_check_cbc.m4 \
    1416        CMakeLists.txt \
    1517        cmake/FindGhostscript.cmake \
    1618        cmake/FindGLPK.cmake \
  • configure.ac

    diff -r fc9e366e6759 -r 8c2913a5830a configure.ac
    a b  
    6060LX_CHECK_CPLEX
    6161LX_CHECK_SOPLEX
    6262LX_CHECK_CLP
     63LX_CHECK_CBC
    6364
    6465AM_CONDITIONAL([HAVE_LP], [test x"$lx_lp_found" = x"yes"])
    6566AM_CONDITIONAL([HAVE_MIP], [test x"$lx_mip_found" = x"yes"])
     
    131132echo CPLEX support................. : $lx_cplex_found
    132133echo SOPLEX support................ : $lx_soplex_found
    133134echo CLP support................... : $lx_clp_found
     135echo CBC support................... : $lx_cbc_found
    134136echo
    135137echo Build demo programs........... : $enable_demo
    136138echo Build additional tools........ : $enable_tools
  • lemon/Makefile.am

    diff -r fc9e366e6759 -r 8c2913a5830a lemon/Makefile.am
    a b  
    1212        lemon/color.cc \
    1313        lemon/lp_base.cc \
    1414        lemon/lp_skeleton.cc \
    15         lemon/random.cc \
     15        lemon/random.cc \
    1616        lemon/bits/windows.cc
    1717
    1818
     
    2121        $(GLPK_CFLAGS) \
    2222        $(CPLEX_CFLAGS) \
    2323        $(SOPLEX_CXXFLAGS) \
    24         $(CLP_CXXFLAGS)
     24        $(CLP_CXXFLAGS) \
     25        $(CBC_CXXFLAGS)
    2526
    2627lemon_libemon_la_LDFLAGS = \
    2728        $(GLPK_LIBS) \
    2829        $(CPLEX_LIBS) \
    2930        $(SOPLEX_LIBS) \
    30         $(CLP_LIBS)
     31        $(CLP_LIBS) \
     32        $(CBC_LIBS)
    3133
    3234if HAVE_GLPK
    3335lemon_libemon_la_SOURCES += lemon/glpk.cc
     
    4547lemon_libemon_la_SOURCES += lemon/clp.cc
    4648endif
    4749
     50if HAVE_CBC
     51lemon_libemon_la_SOURCES += lemon/cbc.cc
     52endif
     53
    4854lemon_HEADERS += \
    4955        lemon/adaptors.h \
    5056        lemon/arg_parser.h \
  • new file lemon/cbc.cc

    diff -r fc9e366e6759 -r 8c2913a5830a lemon/cbc.cc
    - +  
     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
     51namespace 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
  • new file lemon/cbc.h

    diff -r fc9e366e6759 -r 8c2913a5830a lemon/cbc.h
    - +  
     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
     29class CoinModel;
     30class OsiSolverInterface;
     31class CbcModel;
     32
     33namespace 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
  • lemon/config.h.in

    diff -r fc9e366e6759 -r 8c2913a5830a lemon/config.h.in
    a b  
    1818
    1919/* Define to 1 if you have CLP */
    2020#undef HAVE_CLP
     21
     22/* Define to 1 if you have CBC */
     23#undef HAVE_CBC
  • new file m4/lx_check_cbc.m4

    diff -r fc9e366e6759 -r 8c2913a5830a m4/lx_check_cbc.m4
    - +  
     1AC_DEFUN([LX_CHECK_CBC],
     2[
     3  AC_ARG_WITH([cbc],
     4AS_HELP_STRING([--with-cbc@<:@=PREFIX@:>@], [search for CBC under PREFIX or under the default search paths if PREFIX is not given @<:@default@:>@])
     5AS_HELP_STRING([--without-cbc], [disable checking for CBC]),
     6              [], [with_cbc=yes])
     7
     8  AC_ARG_WITH([cbc-includedir],
     9AS_HELP_STRING([--with-cbc-includedir=DIR], [search for CBC headers in DIR]),
     10              [], [with_cbc_includedir=no])
     11
     12  AC_ARG_WITH([cbc-libdir],
     13AS_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])
  • test/mip_test.cc

    diff -r fc9e366e6759 -r 8c2913a5830a test/mip_test.cc
    a b  
    1818
    1919#include "test_tools.h"
    2020
    21 
    2221#ifdef HAVE_CONFIG_H
    2322#include <lemon/config.h>
    2423#endif
     
    3130#include <lemon/glpk.h>
    3231#endif
    3332
     33#ifdef HAVE_CBC
     34#include <lemon/cbc.h>
     35#endif
     36
    3437
    3538using namespace lemon;
    3639
     
    5760
    5861void aTest(MipSolver& mip)
    5962{
    60  //The following example is very simple
     63  //The following example is very simple
    6164
    6265
    6366  typedef MipSolver::Row Row;
    6467  typedef MipSolver::Col Col;
    6568
    6669
    67 
    6870  Col x1 = mip.addCol();
    6971  Col x2 = mip.addCol();
    7072
     
    7476
    7577  mip.max();
    7678
    77 
    7879  //Unconstrained optimization
    7980  mip.solve();
    8081  //Check it out!
    8182
    8283  //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);
    8586
    8687  //Nonnegativity of the variable x1
    8788  mip.colLowerBound(x1, 0);
    8889
     90
    8991  //Maximization of x1
    9092  //over the triangle with vertices (0,0),(4/5,2/5),(0,2)
    9193  double expected_opt=4.0/5.0;
    9294  solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
    9395
     96
    9497  //Restrict x2 to integer
    9598  mip.colType(x2,MipSolver::INTEGER);
    9699  expected_opt=1.0/2.0;
     
    102105  expected_opt=0;
    103106  solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
    104107
    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);
    106113
    107114}
    108115
     116
    109117template<class MIP>
    110118void cloneTest()
    111119{
     
    144152  }
    145153#endif
    146154
     155#ifdef HAVE_CBC
     156  {
     157    CbcMip mip1;
     158    aTest(mip1);
     159    cloneTest<CbcMip>();
     160  }
     161#endif
     162
    147163  return 0;
    148164
    149165}