[458] | 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-2008 |
---|
| 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 | |
---|
[529] | 19 | #ifndef LEMON_LP_SKELETON_H |
---|
| 20 | #define LEMON_LP_SKELETON_H |
---|
[458] | 21 | |
---|
| 22 | #include <lemon/lp_base.h> |
---|
| 23 | |
---|
| 24 | ///\file |
---|
[540] | 25 | ///\brief Skeleton file to implement LP/MIP solver interfaces |
---|
| 26 | /// |
---|
| 27 | ///The classes in this file do nothing, but they can serve as skeletons when |
---|
| 28 | ///implementing an interface to new solvers. |
---|
[458] | 29 | namespace lemon { |
---|
| 30 | |
---|
[540] | 31 | ///A skeleton class to implement LP/MIP solver base interface |
---|
| 32 | |
---|
| 33 | ///This class does nothing, but it can serve as a skeleton when |
---|
| 34 | ///implementing an interface to new solvers. |
---|
[459] | 35 | class SkeletonSolverBase : public virtual LpBase { |
---|
[458] | 36 | int col_num,row_num; |
---|
| 37 | |
---|
| 38 | protected: |
---|
| 39 | |
---|
[459] | 40 | SkeletonSolverBase() |
---|
| 41 | : col_num(-1), row_num(-1) {} |
---|
| 42 | |
---|
[458] | 43 | /// \e |
---|
| 44 | virtual int _addCol(); |
---|
| 45 | /// \e |
---|
| 46 | virtual int _addRow(); |
---|
| 47 | /// \e |
---|
| 48 | virtual void _eraseCol(int i); |
---|
| 49 | /// \e |
---|
| 50 | virtual void _eraseRow(int i); |
---|
[459] | 51 | |
---|
[458] | 52 | /// \e |
---|
[459] | 53 | virtual void _getColName(int col, std::string& name) const; |
---|
[458] | 54 | /// \e |
---|
[459] | 55 | virtual void _setColName(int col, const std::string& name); |
---|
[458] | 56 | /// \e |
---|
| 57 | virtual int _colByName(const std::string& name) const; |
---|
| 58 | |
---|
| 59 | /// \e |
---|
[459] | 60 | virtual void _getRowName(int row, std::string& name) const; |
---|
[458] | 61 | /// \e |
---|
[459] | 62 | virtual void _setRowName(int row, const std::string& name); |
---|
[458] | 63 | /// \e |
---|
[459] | 64 | virtual int _rowByName(const std::string& name) const; |
---|
| 65 | |
---|
[458] | 66 | /// \e |
---|
[459] | 67 | virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e); |
---|
| 68 | /// \e |
---|
| 69 | virtual void _getRowCoeffs(int i, InsertIterator b) const; |
---|
| 70 | /// \e |
---|
| 71 | virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e); |
---|
| 72 | /// \e |
---|
| 73 | virtual void _getColCoeffs(int i, InsertIterator b) const; |
---|
[458] | 74 | |
---|
| 75 | /// Set one element of the coefficient matrix |
---|
| 76 | virtual void _setCoeff(int row, int col, Value value); |
---|
| 77 | |
---|
| 78 | /// Get one element of the coefficient matrix |
---|
| 79 | virtual Value _getCoeff(int row, int col) const; |
---|
| 80 | |
---|
| 81 | /// The lower bound of a variable (column) have to be given by an |
---|
| 82 | /// extended number of type Value, i.e. a finite number of type |
---|
| 83 | /// Value or -\ref INF. |
---|
| 84 | virtual void _setColLowerBound(int i, Value value); |
---|
| 85 | /// \e |
---|
| 86 | |
---|
| 87 | /// The lower bound of a variable (column) is an |
---|
| 88 | /// extended number of type Value, i.e. a finite number of type |
---|
| 89 | /// Value or -\ref INF. |
---|
| 90 | virtual Value _getColLowerBound(int i) const; |
---|
| 91 | |
---|
| 92 | /// The upper bound of a variable (column) have to be given by an |
---|
| 93 | /// extended number of type Value, i.e. a finite number of type |
---|
| 94 | /// Value or \ref INF. |
---|
| 95 | virtual void _setColUpperBound(int i, Value value); |
---|
| 96 | /// \e |
---|
| 97 | |
---|
| 98 | /// The upper bound of a variable (column) is an |
---|
| 99 | /// extended number of type Value, i.e. a finite number of type |
---|
| 100 | /// Value or \ref INF. |
---|
| 101 | virtual Value _getColUpperBound(int i) const; |
---|
| 102 | |
---|
[459] | 103 | /// The lower bound of a constraint (row) have to be given by an |
---|
[458] | 104 | /// extended number of type Value, i.e. a finite number of type |
---|
[459] | 105 | /// Value or -\ref INF. |
---|
| 106 | virtual void _setRowLowerBound(int i, Value value); |
---|
[458] | 107 | /// \e |
---|
| 108 | |
---|
[459] | 109 | /// The lower bound of a constraint (row) is an |
---|
| 110 | /// extended number of type Value, i.e. a finite number of type |
---|
| 111 | /// Value or -\ref INF. |
---|
| 112 | virtual Value _getRowLowerBound(int i) const; |
---|
[458] | 113 | |
---|
[459] | 114 | /// The upper bound of a constraint (row) have to be given by an |
---|
| 115 | /// extended number of type Value, i.e. a finite number of type |
---|
| 116 | /// Value or \ref INF. |
---|
| 117 | virtual void _setRowUpperBound(int i, Value value); |
---|
[458] | 118 | /// \e |
---|
| 119 | |
---|
[459] | 120 | /// The upper bound of a constraint (row) is an |
---|
| 121 | /// extended number of type Value, i.e. a finite number of type |
---|
| 122 | /// Value or \ref INF. |
---|
| 123 | virtual Value _getRowUpperBound(int i) const; |
---|
[458] | 124 | |
---|
| 125 | /// \e |
---|
[459] | 126 | virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
---|
| 127 | /// \e |
---|
| 128 | virtual void _getObjCoeffs(InsertIterator b) const; |
---|
| 129 | |
---|
[458] | 130 | /// \e |
---|
| 131 | virtual void _setObjCoeff(int i, Value obj_coef); |
---|
| 132 | /// \e |
---|
| 133 | virtual Value _getObjCoeff(int i) const; |
---|
| 134 | |
---|
| 135 | ///\e |
---|
[459] | 136 | virtual void _setSense(Sense); |
---|
| 137 | ///\e |
---|
| 138 | virtual Sense _getSense() const; |
---|
| 139 | |
---|
| 140 | ///\e |
---|
| 141 | virtual void _clear(); |
---|
| 142 | |
---|
[576] | 143 | ///\e |
---|
| 144 | virtual void _messageLevel(MessageLevel); |
---|
[459] | 145 | }; |
---|
| 146 | |
---|
[540] | 147 | /// \brief Skeleton class for an LP solver interface |
---|
[459] | 148 | /// |
---|
[540] | 149 | ///This class does nothing, but it can serve as a skeleton when |
---|
| 150 | ///implementing an interface to new solvers. |
---|
| 151 | |
---|
[459] | 152 | ///\ingroup lp_group |
---|
[540] | 153 | class LpSkeleton : public LpSolver, public SkeletonSolverBase { |
---|
[459] | 154 | public: |
---|
[540] | 155 | ///\e |
---|
| 156 | LpSkeleton() : LpSolver(), SkeletonSolverBase() {} |
---|
| 157 | ///\e |
---|
| 158 | virtual LpSkeleton* newSolver() const; |
---|
| 159 | ///\e |
---|
| 160 | virtual LpSkeleton* cloneSolver() const; |
---|
[459] | 161 | protected: |
---|
| 162 | |
---|
| 163 | ///\e |
---|
| 164 | virtual SolveExitStatus _solve(); |
---|
| 165 | |
---|
| 166 | ///\e |
---|
| 167 | virtual Value _getPrimal(int i) const; |
---|
| 168 | ///\e |
---|
| 169 | virtual Value _getDual(int i) const; |
---|
| 170 | |
---|
| 171 | ///\e |
---|
| 172 | virtual Value _getPrimalValue() const; |
---|
| 173 | |
---|
| 174 | ///\e |
---|
| 175 | virtual Value _getPrimalRay(int i) const; |
---|
| 176 | ///\e |
---|
| 177 | virtual Value _getDualRay(int i) const; |
---|
| 178 | |
---|
| 179 | ///\e |
---|
| 180 | virtual ProblemType _getPrimalType() const; |
---|
| 181 | ///\e |
---|
| 182 | virtual ProblemType _getDualType() const; |
---|
| 183 | |
---|
| 184 | ///\e |
---|
| 185 | virtual VarStatus _getColStatus(int i) const; |
---|
| 186 | ///\e |
---|
| 187 | virtual VarStatus _getRowStatus(int i) const; |
---|
| 188 | |
---|
| 189 | ///\e |
---|
| 190 | virtual const char* _solverName() const; |
---|
| 191 | |
---|
| 192 | }; |
---|
| 193 | |
---|
[540] | 194 | /// \brief Skeleton class for a MIP solver interface |
---|
[459] | 195 | /// |
---|
[540] | 196 | ///This class does nothing, but it can serve as a skeleton when |
---|
| 197 | ///implementing an interface to new solvers. |
---|
[459] | 198 | ///\ingroup lp_group |
---|
[540] | 199 | class MipSkeleton : public MipSolver, public SkeletonSolverBase { |
---|
[459] | 200 | public: |
---|
[540] | 201 | ///\e |
---|
| 202 | MipSkeleton() : MipSolver(), SkeletonSolverBase() {} |
---|
| 203 | ///\e |
---|
| 204 | virtual MipSkeleton* newSolver() const; |
---|
| 205 | ///\e |
---|
| 206 | virtual MipSkeleton* cloneSolver() const; |
---|
[459] | 207 | |
---|
| 208 | protected: |
---|
| 209 | ///\e |
---|
[458] | 210 | virtual SolveExitStatus _solve(); |
---|
| 211 | |
---|
| 212 | ///\e |
---|
[459] | 213 | virtual Value _getSol(int i) const; |
---|
[458] | 214 | |
---|
| 215 | ///\e |
---|
[459] | 216 | virtual Value _getSolValue() const; |
---|
[458] | 217 | |
---|
| 218 | ///\e |
---|
[459] | 219 | virtual ProblemType _getType() const; |
---|
[458] | 220 | |
---|
| 221 | ///\e |
---|
[459] | 222 | virtual const char* _solverName() const; |
---|
[458] | 223 | }; |
---|
| 224 | |
---|
| 225 | } //namespace lemon |
---|
| 226 | |
---|
[529] | 227 | #endif |
---|