[Lemon-commits] Balazs Dezso: Add CBC support (#204)
Lemon HG
hg at lemon.cs.elte.hu
Mon Apr 6 08:08:21 CEST 2009
details: http://lemon.cs.elte.hu/hg/lemon/rev/3314f58e7b25
changeset: 599:3314f58e7b25
user: Balazs Dezso <deba [at] inf.elte.hu>
date: Wed Apr 01 22:58:58 2009 +0200
description:
Add CBC support (#204)
diffstat:
Makefile.am | 2 +
configure.ac | 2 +
lemon/Makefile.am | 12 +-
lemon/cbc.cc | 460 +++++++++++++++++++++++++++++++++++++++++++++++++++
lemon/cbc.h | 150 ++++++++++++++++
lemon/config.h.in | 3 +
m4/lx_check_cbc.m4 | 73 ++++++++
test/mip_test.cc | 30 ++-
8 files changed, 722 insertions(+), 10 deletions(-)
diffs (truncated from 878 to 300 lines):
diff --git a/Makefile.am b/Makefile.am
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,6 +11,8 @@
m4/lx_check_cplex.m4 \
m4/lx_check_glpk.m4 \
m4/lx_check_soplex.m4 \
+ m4/lx_check_clp.m4 \
+ m4/lx_check_cbc.m4 \
CMakeLists.txt \
cmake/FindGhostscript.cmake \
cmake/FindGLPK.cmake \
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -60,6 +60,7 @@
LX_CHECK_CPLEX
LX_CHECK_SOPLEX
LX_CHECK_CLP
+LX_CHECK_CBC
AM_CONDITIONAL([HAVE_LP], [test x"$lx_lp_found" = x"yes"])
AM_CONDITIONAL([HAVE_MIP], [test x"$lx_mip_found" = x"yes"])
@@ -119,6 +120,7 @@
echo CPLEX support................. : $lx_cplex_found
echo SOPLEX support................ : $lx_soplex_found
echo CLP support................... : $lx_clp_found
+echo CBC support................... : $lx_cbc_found
echo
echo Build additional tools........ : $enable_tools
echo
diff --git a/lemon/Makefile.am b/lemon/Makefile.am
--- a/lemon/Makefile.am
+++ b/lemon/Makefile.am
@@ -12,7 +12,7 @@
lemon/color.cc \
lemon/lp_base.cc \
lemon/lp_skeleton.cc \
- lemon/random.cc \
+ lemon/random.cc \
lemon/bits/windows.cc
@@ -21,13 +21,15 @@
$(GLPK_CFLAGS) \
$(CPLEX_CFLAGS) \
$(SOPLEX_CXXFLAGS) \
- $(CLP_CXXFLAGS)
+ $(CLP_CXXFLAGS) \
+ $(CBC_CXXFLAGS)
lemon_libemon_la_LDFLAGS = \
$(GLPK_LIBS) \
$(CPLEX_LIBS) \
$(SOPLEX_LIBS) \
- $(CLP_LIBS)
+ $(CLP_LIBS) \
+ $(CBC_LIBS)
if HAVE_GLPK
lemon_libemon_la_SOURCES += lemon/glpk.cc
@@ -45,6 +47,10 @@
lemon_libemon_la_SOURCES += lemon/clp.cc
endif
+if HAVE_CBC
+lemon_libemon_la_SOURCES += lemon/cbc.cc
+endif
+
lemon_HEADERS += \
lemon/adaptors.h \
lemon/arg_parser.h \
diff --git a/lemon/cbc.cc b/lemon/cbc.cc
new file mode 100644
--- /dev/null
+++ b/lemon/cbc.cc
@@ -0,0 +1,460 @@
+/* -*- mode: C++; indent-tabs-mode: nil; -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library.
+ *
+ * Copyright (C) 2003-2009
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+///\file
+///\brief Implementation of the CBC MIP solver interface.
+
+#include "cbc.h"
+
+#include <coin/CoinModel.hpp>
+#include <coin/CbcModel.hpp>
+#include <coin/OsiSolverInterface.hpp>
+
+#ifdef COIN_HAS_CLP
+#include "coin/OsiClpSolverInterface.hpp"
+#endif
+#ifdef COIN_HAS_OSL
+#include "coin/OsiOslSolverInterface.hpp"
+#endif
+
+#include "coin/CbcCutGenerator.hpp"
+#include "coin/CbcHeuristicLocal.hpp"
+#include "coin/CbcHeuristicGreedy.hpp"
+#include "coin/CbcHeuristicFPump.hpp"
+#include "coin/CbcHeuristicRINS.hpp"
+
+#include "coin/CglGomory.hpp"
+#include "coin/CglProbing.hpp"
+#include "coin/CglKnapsackCover.hpp"
+#include "coin/CglOddHole.hpp"
+#include "coin/CglClique.hpp"
+#include "coin/CglFlowCover.hpp"
+#include "coin/CglMixedIntegerRounding.hpp"
+
+#include "coin/CbcHeuristic.hpp"
+
+namespace lemon {
+
+ CbcMip::CbcMip() {
+ _prob = new CoinModel();
+ _prob->setProblemName("LEMON");
+ _osi_solver = 0;
+ _cbc_model = 0;
+ }
+
+ CbcMip::CbcMip(const CbcMip& other) {
+ _prob = new CoinModel(*other._prob);
+ _osi_solver = 0;
+ _cbc_model = 0;
+ }
+
+ CbcMip::~CbcMip() {
+ delete _prob;
+ if (_osi_solver) delete _osi_solver;
+ if (_cbc_model) delete _cbc_model;
+ }
+
+ const char* CbcMip::_solverName() const { return "CbcMip"; }
+
+ int CbcMip::_addCol() {
+ _prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0, 0, false);
+ return _prob->numberColumns() - 1;
+ }
+
+ CbcMip* CbcMip::newSolver() const {
+ CbcMip* newlp = new CbcMip;
+ return newlp;
+ }
+
+ CbcMip* CbcMip::cloneSolver() const {
+ CbcMip* copylp = new CbcMip(*this);
+ return copylp;
+ }
+
+ int CbcMip::_addRow() {
+ _prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX);
+ return _prob->numberRows() - 1;
+ }
+
+
+ void CbcMip::_eraseCol(int i) {
+ _prob->deleteColumn(i);
+ }
+
+ void CbcMip::_eraseRow(int i) {
+ _prob->deleteRow(i);
+ }
+
+ void CbcMip::_eraseColId(int i) {
+ cols.eraseIndex(i);
+ }
+
+ void CbcMip::_eraseRowId(int i) {
+ rows.eraseIndex(i);
+ }
+
+ void CbcMip::_getColName(int c, std::string& name) const {
+ name = _prob->getColumnName(c);
+ }
+
+ void CbcMip::_setColName(int c, const std::string& name) {
+ _prob->setColumnName(c, name.c_str());
+ }
+
+ int CbcMip::_colByName(const std::string& name) const {
+ return _prob->column(name.c_str());
+ }
+
+ void CbcMip::_getRowName(int r, std::string& name) const {
+ name = _prob->getRowName(r);
+ }
+
+ void CbcMip::_setRowName(int r, const std::string& name) {
+ _prob->setRowName(r, name.c_str());
+ }
+
+ int CbcMip::_rowByName(const std::string& name) const {
+ return _prob->row(name.c_str());
+ }
+
+ void CbcMip::_setRowCoeffs(int i, ExprIterator b, ExprIterator e) {
+ for (ExprIterator it = b; it != e; ++it) {
+ _prob->setElement(i, it->first, it->second);
+ }
+ }
+
+ void CbcMip::_getRowCoeffs(int ix, InsertIterator b) const {
+ int length = _prob->numberRows();
+
+ std::vector<int> indices(length);
+ std::vector<Value> values(length);
+
+ length = _prob->getRow(ix, &indices[0], &values[0]);
+
+ for (int i = 0; i < length; ++i) {
+ *b = std::make_pair(indices[i], values[i]);
+ ++b;
+ }
+ }
+
+ void CbcMip::_setColCoeffs(int ix, ExprIterator b, ExprIterator e) {
+ for (ExprIterator it = b; it != e; ++it) {
+ _prob->setElement(it->first, ix, it->second);
+ }
+ }
+
+ void CbcMip::_getColCoeffs(int ix, InsertIterator b) const {
+ int length = _prob->numberColumns();
+
+ std::vector<int> indices(length);
+ std::vector<Value> values(length);
+
+ length = _prob->getColumn(ix, &indices[0], &values[0]);
+
+ for (int i = 0; i < length; ++i) {
+ *b = std::make_pair(indices[i], values[i]);
+ ++b;
+ }
+ }
+
+ void CbcMip::_setCoeff(int ix, int jx, Value value) {
+ _prob->setElement(ix, jx, value);
+ }
+
+ CbcMip::Value CbcMip::_getCoeff(int ix, int jx) const {
+ return _prob->getElement(ix, jx);
+ }
+
+
+ void CbcMip::_setColLowerBound(int i, Value lo) {
+ LEMON_ASSERT(lo != INF, "Invalid bound");
+ _prob->setColumnLower(i, lo == - INF ? - COIN_DBL_MAX : lo);
+ }
+
+ CbcMip::Value CbcMip::_getColLowerBound(int i) const {
+ double val = _prob->getColumnLower(i);
+ return val == - COIN_DBL_MAX ? - INF : val;
+ }
+
+ void CbcMip::_setColUpperBound(int i, Value up) {
+ LEMON_ASSERT(up != -INF, "Invalid bound");
+ _prob->setColumnUpper(i, up == INF ? COIN_DBL_MAX : up);
+ }
+
+ CbcMip::Value CbcMip::_getColUpperBound(int i) const {
+ double val = _prob->getColumnUpper(i);
+ return val == COIN_DBL_MAX ? INF : val;
+ }
+
+ void CbcMip::_setRowLowerBound(int i, Value lo) {
+ LEMON_ASSERT(lo != INF, "Invalid bound");
+ _prob->setRowLower(i, lo == - INF ? - COIN_DBL_MAX : lo);
+ }
+
+ CbcMip::Value CbcMip::_getRowLowerBound(int i) const {
+ double val = _prob->getRowLower(i);
+ return val == - COIN_DBL_MAX ? - INF : val;
+ }
+
+ void CbcMip::_setRowUpperBound(int i, Value up) {
+ LEMON_ASSERT(up != -INF, "Invalid bound");
+ _prob->setRowUpper(i, up == INF ? COIN_DBL_MAX : up);
+ }
+
+ CbcMip::Value CbcMip::_getRowUpperBound(int i) const {
+ double val = _prob->getRowUpper(i);
+ return val == COIN_DBL_MAX ? INF : val;
+ }
+
More information about the Lemon-commits
mailing list