1.1 --- a/lemon/Makefile.am Wed Nov 29 15:01:13 2006 +0000
1.2 +++ b/lemon/Makefile.am Wed Nov 29 17:30:21 2006 +0000
1.3 @@ -15,8 +15,8 @@
1.4 lemon/bits/mingw32_time.cc \
1.5 lemon/random.cc
1.6
1.7 -lemon_libemon_la_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS)
1.8 -lemon_libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS)
1.9 +lemon_libemon_la_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS) $(SOPLEX_CFLAGS)
1.10 +lemon_libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS) $(SOPLEX_CFLAGS)
1.11
1.12 if HAVE_GLPK
1.13 lemon_libemon_la_SOURCES += lemon/lp_glpk.cc
1.14 @@ -28,6 +28,10 @@
1.15 lemon_libemon_la_SOURCES += lemon/mip_cplex.cc
1.16 endif
1.17
1.18 +if HAVE_SOPLEX
1.19 +lemon_libemon_la_SOURCES += lemon/lp_soplex.cc
1.20 +endif
1.21 +
1.22 lemon_HEADERS += \
1.23 lemon/bellman_ford.h \
1.24 lemon/bfs.h \
1.25 @@ -71,6 +75,7 @@
1.26 lemon/lp_cplex.h \
1.27 lemon/lp_glpk.h \
1.28 lemon/lp_skeleton.h \
1.29 + lemon/lp_soplex.h \
1.30 lemon/map_iterator.h \
1.31 lemon/maps.h \
1.32 lemon/matrix_maps.h \
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/lemon/lp_soplex.cc Wed Nov 29 17:30:21 2006 +0000
2.3 @@ -0,0 +1,208 @@
2.4 +/* -*- C++ -*-
2.5 + *
2.6 + * This file is a part of LEMON, a generic C++ optimization library
2.7 + *
2.8 + * Copyright (C) 2003-2006
2.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
2.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
2.11 + *
2.12 + * Permission to use, modify and distribute this software is granted
2.13 + * provided that this copyright notice appears in all copies. For
2.14 + * precise terms see the accompanying LICENSE file.
2.15 + *
2.16 + * This software is provided "AS IS" with no warranty of any kind,
2.17 + * express or implied, and with no claim as to its suitability for any
2.18 + * purpose.
2.19 + *
2.20 + */
2.21 +
2.22 +#include<iostream>
2.23 +#include<lemon/lp_soplex.h>
2.24 +
2.25 +#include <soplex/soplex.h>
2.26 +
2.27 +
2.28 +///\file
2.29 +///\brief Implementation of the LEMON-SOPLEX lp solver interface.
2.30 +namespace lemon {
2.31 +
2.32 + LpSoplex::LpSoplex() : LpSolverBase() {
2.33 + soplex = new soplex::SoPlex;
2.34 + }
2.35 +
2.36 + LpSoplex::~LpSoplex() {
2.37 + delete soplex;
2.38 + }
2.39 +
2.40 + LpSolverBase &LpSoplex::_newLp() {
2.41 + LpSoplex* newlp = new LpSoplex();
2.42 + return *newlp;
2.43 + }
2.44 +
2.45 + LpSolverBase &LpSoplex::_copyLp() {
2.46 + LpSoplex* newlp = new LpSoplex();
2.47 + ((soplex::SPxLP&)*(newlp->soplex)) = *soplex;
2.48 + return *newlp;
2.49 + }
2.50 +
2.51 + int LpSoplex::_addCol() {
2.52 + soplex::LPCol col;
2.53 + soplex->addCol(col);
2.54 +
2.55 + colNames.push_back(std::string());
2.56 + primal.push_back(0.0);
2.57 +
2.58 + return soplex->nCols() - 1;
2.59 + }
2.60 +
2.61 + int LpSoplex::_addRow() {
2.62 + soplex::LPRow row;
2.63 + soplex->addRow(row);
2.64 +
2.65 + dual.push_back(0.0);
2.66 +
2.67 + return soplex->nRows() - 1;
2.68 + }
2.69 +
2.70 +
2.71 + void LpSoplex::_eraseCol(int i) {
2.72 + soplex->removeCol(i);
2.73 + primal[i] = primal.back();
2.74 + primal.pop_back();
2.75 + }
2.76 +
2.77 + void LpSoplex::_eraseRow(int i) {
2.78 + soplex->removeRow(i);
2.79 + dual[i] = dual.back();
2.80 + dual.pop_back();
2.81 + }
2.82 +
2.83 + void LpSoplex::_getColName(int col, std::string &name) {
2.84 + name = colNames[col];
2.85 + }
2.86 +
2.87 + void LpSoplex::_setColName(int col, const std::string &name) {
2.88 + colNames[col] = name;
2.89 + }
2.90 +
2.91 +
2.92 + void LpSoplex::_setRowCoeffs(int i, LpRowIterator b, LpRowIterator e) {
2.93 + for (int j = 0; j < soplex->nCols(); ++j) {
2.94 + soplex->changeElement(i, j, 0.0);
2.95 + }
2.96 + for(LpRowIterator it = b; it != e; ++it) {
2.97 + soplex->changeElement(i, it->first, it->second);
2.98 + }
2.99 + }
2.100 +
2.101 + void LpSoplex::_setColCoeffs(int j, LpColIterator b, LpColIterator e) {
2.102 + for (int i = 0; i < soplex->nRows(); ++i) {
2.103 + soplex->changeElement(i, j, 0.0);
2.104 + }
2.105 + for(LpColIterator it = b; it != e; ++it) {
2.106 + soplex->changeElement(it->first, j, it->second);
2.107 + }
2.108 + }
2.109 +
2.110 + void LpSoplex::_setCoeff(int row, int col, Value value) {
2.111 + soplex->changeElement(row, col, value);
2.112 + }
2.113 +
2.114 + void LpSoplex::_setColLowerBound(int i, Value value) {
2.115 + soplex->changeLower(i, value);
2.116 + }
2.117 +
2.118 + void LpSoplex::_setColUpperBound(int i, Value value) {
2.119 + soplex->changeUpper(i, value);
2.120 + }
2.121 +
2.122 + void LpSoplex::_setRowBounds(int i, Value lb, Value ub) {
2.123 + soplex->changeRange(i, lb, ub);
2.124 + }
2.125 +
2.126 + void LpSoplex::_setObjCoeff(int i, Value obj_coef) {
2.127 + soplex->changeObj(i, obj_coef);
2.128 + }
2.129 +
2.130 + void LpSoplex::_clearObj() {
2.131 + for (int i = 0; i < soplex->nCols(); ++i) {
2.132 + soplex->changeObj(i, 0.0);
2.133 + }
2.134 + }
2.135 +
2.136 + LpSoplex::SolveExitStatus LpSoplex::_solve() {
2.137 + soplex::SPxSolver::Status status = soplex->solve();
2.138 +
2.139 + soplex::Vector pv(primal.size(), &primal[0]);
2.140 + soplex->getPrimal(pv);
2.141 +
2.142 + soplex::Vector dv(dual.size(), &dual[0]);
2.143 + soplex->getDual(dv);
2.144 +
2.145 + switch (status) {
2.146 + case soplex::SPxSolver::OPTIMAL:
2.147 + case soplex::SPxSolver::INFEASIBLE:
2.148 + case soplex::SPxSolver::UNBOUNDED:
2.149 + return SOLVED;
2.150 + default:
2.151 + return UNSOLVED;
2.152 + }
2.153 + }
2.154 +
2.155 + LpSoplex::Value LpSoplex::_getPrimal(int i) {
2.156 + return primal[i];
2.157 + }
2.158 +
2.159 + LpSoplex::Value LpSoplex::_getDual(int i) {
2.160 + return dual[i];
2.161 + }
2.162 +
2.163 + LpSoplex::Value LpSoplex::_getPrimalValue() {
2.164 + return soplex->objValue();
2.165 + }
2.166 +
2.167 + bool LpSoplex::_isBasicCol(int i) {
2.168 + return soplex->getBasisColStatus(i) == soplex::SPxSolver::BASIC;
2.169 + }
2.170 +
2.171 + LpSoplex::SolutionStatus LpSoplex::_getPrimalStatus() {
2.172 + switch (soplex->status()) {
2.173 + case soplex::SPxSolver::OPTIMAL:
2.174 + return OPTIMAL;
2.175 + case soplex::SPxSolver::UNBOUNDED:
2.176 + return INFINITE;
2.177 + case soplex::SPxSolver::INFEASIBLE:
2.178 + return INFEASIBLE;
2.179 + default:
2.180 + return UNDEFINED;
2.181 + }
2.182 + }
2.183 +
2.184 + LpSoplex::SolutionStatus LpSoplex::_getDualStatus() {
2.185 + switch (0) {
2.186 + case 0:
2.187 + return UNDEFINED;
2.188 + return OPTIMAL;
2.189 + return INFEASIBLE;
2.190 + return UNDEFINED;
2.191 + }
2.192 + }
2.193 +
2.194 + LpSoplex::ProblemTypes LpSoplex::_getProblemType() {
2.195 + switch (0) {
2.196 + case 0:
2.197 + return PRIMAL_DUAL_FEASIBLE;
2.198 + return PRIMAL_FEASIBLE_DUAL_INFEASIBLE;
2.199 + return UNKNOWN;
2.200 + }
2.201 + }
2.202 +
2.203 + void LpSoplex::_setMax() {
2.204 + soplex->changeSense(soplex::SPxSolver::MAXIMIZE);
2.205 + }
2.206 + void LpSoplex::_setMin() {
2.207 + soplex->changeSense(soplex::SPxSolver::MINIMIZE);
2.208 + }
2.209 +
2.210 +} //namespace lemon
2.211 +
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/lemon/lp_soplex.h Wed Nov 29 17:30:21 2006 +0000
3.3 @@ -0,0 +1,99 @@
3.4 +/* -*- C++ -*-
3.5 + *
3.6 + * This file is a part of LEMON, a generic C++ optimization library
3.7 + *
3.8 + * Copyright (C) 2003-2006
3.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
3.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
3.11 + *
3.12 + * Permission to use, modify and distribute this software is granted
3.13 + * provided that this copyright notice appears in all copies. For
3.14 + * precise terms see the accompanying LICENSE file.
3.15 + *
3.16 + * This software is provided "AS IS" with no warranty of any kind,
3.17 + * express or implied, and with no claim as to its suitability for any
3.18 + * purpose.
3.19 + *
3.20 + */
3.21 +
3.22 +#ifndef LEMON_LP_SOPLEX_H
3.23 +#define LEMON_LP_SOPLEX_H
3.24 +
3.25 +///\file
3.26 +///\brief Header of the LEMON-SOPLEX lp solver interface.
3.27 +
3.28 +#include <vector>
3.29 +#include <string>
3.30 +
3.31 +#include <lemon/lp_base.h>
3.32 +
3.33 +// Forward declaration
3.34 +namespace soplex {
3.35 + class SoPlex;
3.36 +}
3.37 +
3.38 +namespace lemon {
3.39 +
3.40 + /// \brief Interface for the SOPLEX solver
3.41 + ///
3.42 + /// This class implements an interface for the SOPLEX LP solver.
3.43 + class LpSoplex :virtual public LpSolverBase {
3.44 + protected:
3.45 +
3.46 + soplex::SoPlex* soplex;
3.47 +
3.48 + std::vector<std::string> colNames;
3.49 +
3.50 + std::vector<Value> primal;
3.51 + std::vector<Value> dual;
3.52 +
3.53 +
3.54 + public:
3.55 +
3.56 + typedef LpSolverBase Parent;
3.57 +
3.58 +
3.59 + /// \e
3.60 + LpSoplex();
3.61 + /// \e
3.62 + ~LpSoplex();
3.63 +
3.64 + protected:
3.65 +
3.66 + virtual LpSolverBase &_newLp();
3.67 + virtual LpSolverBase &_copyLp();
3.68 +
3.69 + virtual int _addCol();
3.70 + virtual int _addRow();
3.71 + virtual void _eraseCol(int i);
3.72 + virtual void _eraseRow(int i);
3.73 + virtual void _getColName(int col, std::string & name);
3.74 + virtual void _setColName(int col, const std::string & name);
3.75 + virtual void _setRowCoeffs(int i, LpRowIterator b, LpRowIterator e);
3.76 + virtual void _setColCoeffs(int i, LpColIterator b, LpColIterator e);
3.77 + virtual void _setCoeff(int row, int col, Value value);
3.78 + virtual void _setColLowerBound(int i, Value value);
3.79 + virtual void _setColUpperBound(int i, Value value);
3.80 + virtual void _setRowBounds(int i, Value lower, Value upper);
3.81 + virtual void _setObjCoeff(int i, Value obj_coef);
3.82 + virtual void _clearObj();
3.83 +
3.84 + virtual SolveExitStatus _solve();
3.85 + virtual Value _getPrimal(int i);
3.86 + virtual Value _getDual(int i);
3.87 + virtual Value _getPrimalValue();
3.88 + virtual bool _isBasicCol(int i);
3.89 +
3.90 + virtual SolutionStatus _getPrimalStatus();
3.91 + virtual SolutionStatus _getDualStatus();
3.92 + virtual ProblemTypes _getProblemType();
3.93 +
3.94 +
3.95 + virtual void _setMax();
3.96 + virtual void _setMin();
3.97 +
3.98 + };
3.99 +} //END OF NAMESPACE LEMON
3.100 +
3.101 +#endif //LEMON_LP_SOPLEX_H
3.102 +
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/m4/lx_check_soplex.m4 Wed Nov 29 17:30:21 2006 +0000
4.3 @@ -0,0 +1,71 @@
4.4 +AC_DEFUN([LX_CHECK_SOPLEX],
4.5 +[
4.6 + AC_ARG_WITH([soplex],
4.7 +AS_HELP_STRING([--with-soplex@<:@=PREFIX@:>@], [search for SOPLEX under PREFIX or under the default search paths if PREFIX is not given @<:@default@:>@])
4.8 +AS_HELP_STRING([--without-soplex], [disable checking for SOPLEX]),
4.9 + [], [with_soplex=yes])
4.10 +
4.11 + AC_ARG_WITH([soplex-includedir],
4.12 +AS_HELP_STRING([--with-soplex-includedir=DIR], [search for SOPLEX headers in DIR]),
4.13 + [], [with_soplex_includedir=no])
4.14 +
4.15 + AC_ARG_WITH([soplex-libdir],
4.16 +AS_HELP_STRING([--with-soplex-libdir=DIR], [search for SOPLEX libraries in DIR]),
4.17 + [], [with_soplex_libdir=no])
4.18 +
4.19 + lx_soplex_found=no
4.20 + if test x"$with_soplex" != x"no"; then
4.21 + AC_MSG_CHECKING([for SOPLEX])
4.22 +
4.23 + if test x"$with_soplex_includedir" != x"no"; then
4.24 + SOPLEX_CFLAGS="-I$with_soplex_includedir"
4.25 + elif test x"$with_soplex" != x"yes"; then
4.26 + SOPLEX_CFLAGS="-I$with_soplex/include"
4.27 + fi
4.28 +
4.29 + if test x"$with_soplex_libdir" != x"no"; then
4.30 + SOPLEX_LDFLAGS="-L$with_soplex_libdir"
4.31 + elif test x"$with_soplex" != x"yes"; then
4.32 + SOPLEX_LDFLAGS="-L$with_soplex/lib"
4.33 + fi
4.34 + SOPLEX_LIBS="-lsoplex -lz"
4.35 +
4.36 + lx_save_cxxflags="$CXXFLAGS"
4.37 + lx_save_ldflags="$LDFLAGS"
4.38 + lx_save_libs="$LIBS"
4.39 + CXXFLAGS="$SOPLEX_CFLAGS"
4.40 + LDFLAGS="$SOPLEX_LDFLAGS"
4.41 + LIBS="$SOPLEX_LIBS"
4.42 +
4.43 + lx_soplex_test_prog='
4.44 + #include <soplex/soplex.h>
4.45 +
4.46 + int main(int argc, char* argv[])
4.47 + {
4.48 + soplex::SoPlex soplex;
4.49 + return 0;
4.50 + }'
4.51 +
4.52 + AC_LANG_PUSH(C++)
4.53 + AC_LINK_IFELSE([$lx_soplex_test_prog], [lx_soplex_found=yes], [lx_soplex_found=no])
4.54 + AC_LANG_POP(C++)
4.55 +
4.56 + CXXFLAGS="$lx_save_cxxflags"
4.57 + LDFLAGS="$lx_save_ldflags"
4.58 + LIBS="$lx_save_libs"
4.59 +
4.60 + if test x"$lx_soplex_found" = x"yes"; then
4.61 + AC_DEFINE([HAVE_SOPLEX], [1], [Define to 1 if you have SOPLEX.])
4.62 + AC_MSG_RESULT([yes])
4.63 + else
4.64 + SOPLEX_CFLAGS=""
4.65 + SOPLEX_LDFLAGS=""
4.66 + SOPLEX_LIBS=""
4.67 + AC_MSG_RESULT([no])
4.68 + fi
4.69 + fi
4.70 + SOPLEX_LIBS="$SOPLEX_LDFLAGS $SOPLEX_LIBS"
4.71 + AC_SUBST(SOPLEX_CFLAGS)
4.72 + AC_SUBST(SOPLEX_LIBS)
4.73 + AM_CONDITIONAL([HAVE_SOPLEX], [test x"$lx_soplex_found" = x"yes"])
4.74 +])