1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/lemon/lp_glpk.h Tue Dec 02 21:40:33 2008 +0100
1.3 @@ -0,0 +1,139 @@
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_LP_GLPK_H
1.23 +#define LEMON_LP_GLPK_H
1.24 +
1.25 +///\file
1.26 +///\brief Header of the LEMON-GLPK lp solver interface.
1.27 +///\ingroup lp_group
1.28 +
1.29 +#include <lemon/lp_base.h>
1.30 +
1.31 +// forward declaration
1.32 +#ifndef _GLP_PROB
1.33 +#define _GLP_PROB
1.34 +typedef struct { double _prob; } glp_prob;
1.35 +/* LP/MIP problem object */
1.36 +#endif
1.37 +
1.38 +namespace lemon {
1.39 +
1.40 +
1.41 + /// \brief Interface for the GLPK LP solver
1.42 + ///
1.43 + /// This class implements an interface for the GLPK LP solver.
1.44 + ///\ingroup lp_group
1.45 + class LpGlpk : virtual public LpSolverBase {
1.46 + protected:
1.47 +
1.48 + typedef glp_prob LPX;
1.49 + glp_prob* lp;
1.50 + bool solved;
1.51 +
1.52 + public:
1.53 +
1.54 + typedef LpSolverBase Parent;
1.55 +
1.56 + LpGlpk();
1.57 + LpGlpk(const LpGlpk &);
1.58 + ~LpGlpk();
1.59 +
1.60 + protected:
1.61 + virtual LpSolverBase* _newLp();
1.62 + virtual LpSolverBase* _copyLp();
1.63 +
1.64 + virtual int _addCol();
1.65 + virtual int _addRow();
1.66 + virtual void _eraseCol(int i);
1.67 + virtual void _eraseRow(int i);
1.68 + virtual void _getColName(int col, std::string & name) const;
1.69 + virtual void _setColName(int col, const std::string & name);
1.70 + virtual int _colByName(const std::string& name) const;
1.71 + virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e);
1.72 + virtual void _getRowCoeffs(int i, RowIterator b) const;
1.73 + virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e);
1.74 + virtual void _getColCoeffs(int i, ColIterator b) const;
1.75 + virtual void _setCoeff(int row, int col, Value value);
1.76 + virtual Value _getCoeff(int row, int col) const;
1.77 +
1.78 + virtual void _setColLowerBound(int i, Value value);
1.79 + virtual Value _getColLowerBound(int i) const;
1.80 + virtual void _setColUpperBound(int i, Value value);
1.81 + virtual Value _getColUpperBound(int i) const;
1.82 +
1.83 + virtual void _setRowBounds(int i, Value lower, Value upper);
1.84 + virtual void _getRowBounds(int i, Value &lb, Value &ub) const;
1.85 + virtual void _setObjCoeff(int i, Value obj_coef);
1.86 + virtual Value _getObjCoeff(int i) const;
1.87 + virtual void _clearObj();
1.88 +
1.89 + ///\e
1.90 +
1.91 + ///\todo It should be clarified
1.92 + ///
1.93 + virtual SolveExitStatus _solve();
1.94 + virtual Value _getPrimal(int i) const;
1.95 + virtual Value _getDual(int i) const;
1.96 + virtual Value _getPrimalValue() const;
1.97 + virtual bool _isBasicCol(int i) const;
1.98 + ///\e
1.99 +
1.100 + ///\todo It should be clarified
1.101 + ///
1.102 + virtual SolutionStatus _getPrimalStatus() const;
1.103 + virtual SolutionStatus _getDualStatus() const;
1.104 + virtual ProblemTypes _getProblemType() const;
1.105 +
1.106 + virtual void _setMax();
1.107 + virtual void _setMin();
1.108 +
1.109 + virtual bool _isMax() const;
1.110 +
1.111 + public:
1.112 + ///Set the verbosity of the messages
1.113 +
1.114 + ///Set the verbosity of the messages
1.115 + ///
1.116 + ///\param m is the level of the messages output by the solver routines.
1.117 + ///The possible values are:
1.118 + ///- 0 --- no output (default value)
1.119 + ///- 1 --- error messages only
1.120 + ///- 2 --- normal output
1.121 + ///- 3 --- full output (includes informational messages)
1.122 + void messageLevel(int m);
1.123 + ///Turns on or off the presolver
1.124 +
1.125 + ///Turns on (\c b is \c true) or off (\c b is \c false) the presolver
1.126 + ///
1.127 + ///The presolver is off by default.
1.128 + void presolver(bool b);
1.129 +
1.130 + ///Pointer to the underlying GLPK data structure.
1.131 + LPX *lpx() {return lp;}
1.132 +
1.133 + ///Returns the constraint identifier understood by GLPK.
1.134 + int lpxRow(Row r) { return _lpId(r); }
1.135 +
1.136 + ///Returns the variable identifier understood by GLPK.
1.137 + int lpxCol(Col c) { return _lpId(c); }
1.138 + };
1.139 +} //END OF NAMESPACE LEMON
1.140 +
1.141 +#endif //LEMON_LP_GLPK_H
1.142 +