1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/lemon/clp.h Thu Nov 05 15:50:01 2009 +0100
1.3 @@ -0,0 +1,164 @@
1.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library.
1.7 + *
1.8 + * Copyright (C) 2003-2008
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +#ifndef LEMON_CLP_H
1.23 +#define LEMON_CLP_H
1.24 +
1.25 +///\file
1.26 +///\brief Header of the LEMON-CLP lp solver interface.
1.27 +
1.28 +#include <vector>
1.29 +#include <string>
1.30 +
1.31 +#include <lemon/lp_base.h>
1.32 +
1.33 +class ClpSimplex;
1.34 +
1.35 +namespace lemon {
1.36 +
1.37 + /// \ingroup lp_group
1.38 + ///
1.39 + /// \brief Interface for the CLP solver
1.40 + ///
1.41 + /// This class implements an interface for the Clp LP solver. The
1.42 + /// Clp library is an object oriented lp solver library developed at
1.43 + /// the IBM. The CLP is part of the COIN-OR package and it can be
1.44 + /// used with Common Public License.
1.45 + class ClpLp : public LpSolver {
1.46 + protected:
1.47 +
1.48 + ClpSimplex* _prob;
1.49 +
1.50 + std::map<std::string, int> _col_names_ref;
1.51 + std::map<std::string, int> _row_names_ref;
1.52 +
1.53 + public:
1.54 +
1.55 + /// \e
1.56 + ClpLp();
1.57 + /// \e
1.58 + ClpLp(const ClpLp&);
1.59 + /// \e
1.60 + ~ClpLp();
1.61 +
1.62 + /// \e
1.63 + virtual ClpLp* newSolver() const;
1.64 + /// \e
1.65 + virtual ClpLp* cloneSolver() const;
1.66 +
1.67 + protected:
1.68 +
1.69 + mutable double* _primal_ray;
1.70 + mutable double* _dual_ray;
1.71 +
1.72 + void _init_temporals();
1.73 + void _clear_temporals();
1.74 +
1.75 + protected:
1.76 +
1.77 + virtual const char* _solverName() const;
1.78 +
1.79 + virtual int _addCol();
1.80 + virtual int _addRow();
1.81 + virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
1.82 +
1.83 + virtual void _eraseCol(int i);
1.84 + virtual void _eraseRow(int i);
1.85 +
1.86 + virtual void _eraseColId(int i);
1.87 + virtual void _eraseRowId(int i);
1.88 +
1.89 + virtual void _getColName(int col, std::string& name) const;
1.90 + virtual void _setColName(int col, const std::string& name);
1.91 + virtual int _colByName(const std::string& name) const;
1.92 +
1.93 + virtual void _getRowName(int row, std::string& name) const;
1.94 + virtual void _setRowName(int row, const std::string& name);
1.95 + virtual int _rowByName(const std::string& name) const;
1.96 +
1.97 + virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
1.98 + virtual void _getRowCoeffs(int i, InsertIterator b) const;
1.99 +
1.100 + virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
1.101 + virtual void _getColCoeffs(int i, InsertIterator b) const;
1.102 +
1.103 + virtual void _setCoeff(int row, int col, Value value);
1.104 + virtual Value _getCoeff(int row, int col) const;
1.105 +
1.106 + virtual void _setColLowerBound(int i, Value value);
1.107 + virtual Value _getColLowerBound(int i) const;
1.108 + virtual void _setColUpperBound(int i, Value value);
1.109 + virtual Value _getColUpperBound(int i) const;
1.110 +
1.111 + virtual void _setRowLowerBound(int i, Value value);
1.112 + virtual Value _getRowLowerBound(int i) const;
1.113 + virtual void _setRowUpperBound(int i, Value value);
1.114 + virtual Value _getRowUpperBound(int i) const;
1.115 +
1.116 + virtual void _setObjCoeffs(ExprIterator, ExprIterator);
1.117 + virtual void _getObjCoeffs(InsertIterator) const;
1.118 +
1.119 + virtual void _setObjCoeff(int i, Value obj_coef);
1.120 + virtual Value _getObjCoeff(int i) const;
1.121 +
1.122 + virtual void _setSense(Sense sense);
1.123 + virtual Sense _getSense() const;
1.124 +
1.125 + virtual SolveExitStatus _solve();
1.126 +
1.127 + virtual Value _getPrimal(int i) const;
1.128 + virtual Value _getDual(int i) const;
1.129 +
1.130 + virtual Value _getPrimalValue() const;
1.131 +
1.132 + virtual Value _getPrimalRay(int i) const;
1.133 + virtual Value _getDualRay(int i) const;
1.134 +
1.135 + virtual VarStatus _getColStatus(int i) const;
1.136 + virtual VarStatus _getRowStatus(int i) const;
1.137 +
1.138 + virtual ProblemType _getPrimalType() const;
1.139 + virtual ProblemType _getDualType() const;
1.140 +
1.141 + virtual void _clear();
1.142 +
1.143 + virtual void _messageLevel(MessageLevel);
1.144 +
1.145 + public:
1.146 +
1.147 + ///Solves LP with primal simplex method.
1.148 + SolveExitStatus solvePrimal();
1.149 +
1.150 + ///Solves LP with dual simplex method.
1.151 + SolveExitStatus solveDual();
1.152 +
1.153 + ///Solves LP with barrier method.
1.154 + SolveExitStatus solveBarrier();
1.155 +
1.156 + ///Returns the constraint identifier understood by CLP.
1.157 + int clpRow(Row r) const { return rows(id(r)); }
1.158 +
1.159 + ///Returns the variable identifier understood by CLP.
1.160 + int clpCol(Col c) const { return cols(id(c)); }
1.161 +
1.162 + };
1.163 +
1.164 +} //END OF NAMESPACE LEMON
1.165 +
1.166 +#endif //LEMON_CLP_H
1.167 +