[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 | |
---|
| 143 | }; |
---|
| 144 | |
---|
[540] | 145 | /// \brief Skeleton class for an LP solver interface |
---|
[459] | 146 | /// |
---|
[540] | 147 | ///This class does nothing, but it can serve as a skeleton when |
---|
| 148 | ///implementing an interface to new solvers. |
---|
| 149 | |
---|
[459] | 150 | ///\ingroup lp_group |
---|
[540] | 151 | class LpSkeleton : public LpSolver, public SkeletonSolverBase { |
---|
[459] | 152 | public: |
---|
[540] | 153 | ///\e |
---|
| 154 | LpSkeleton() : LpSolver(), SkeletonSolverBase() {} |
---|
| 155 | ///\e |
---|
| 156 | virtual LpSkeleton* newSolver() const; |
---|
| 157 | ///\e |
---|
| 158 | virtual LpSkeleton* cloneSolver() const; |
---|
[459] | 159 | protected: |
---|
| 160 | |
---|
| 161 | ///\e |
---|
| 162 | virtual SolveExitStatus _solve(); |
---|
| 163 | |
---|
| 164 | ///\e |
---|
| 165 | virtual Value _getPrimal(int i) const; |
---|
| 166 | ///\e |
---|
| 167 | virtual Value _getDual(int i) const; |
---|
| 168 | |
---|
| 169 | ///\e |
---|
| 170 | virtual Value _getPrimalValue() const; |
---|
| 171 | |
---|
| 172 | ///\e |
---|
| 173 | virtual Value _getPrimalRay(int i) const; |
---|
| 174 | ///\e |
---|
| 175 | virtual Value _getDualRay(int i) const; |
---|
| 176 | |
---|
| 177 | ///\e |
---|
| 178 | virtual ProblemType _getPrimalType() const; |
---|
| 179 | ///\e |
---|
| 180 | virtual ProblemType _getDualType() const; |
---|
| 181 | |
---|
| 182 | ///\e |
---|
| 183 | virtual VarStatus _getColStatus(int i) const; |
---|
| 184 | ///\e |
---|
| 185 | virtual VarStatus _getRowStatus(int i) const; |
---|
| 186 | |
---|
| 187 | ///\e |
---|
| 188 | virtual const char* _solverName() const; |
---|
| 189 | |
---|
| 190 | }; |
---|
| 191 | |
---|
[540] | 192 | /// \brief Skeleton class for a MIP solver interface |
---|
[459] | 193 | /// |
---|
[540] | 194 | ///This class does nothing, but it can serve as a skeleton when |
---|
| 195 | ///implementing an interface to new solvers. |
---|
[459] | 196 | ///\ingroup lp_group |
---|
[540] | 197 | class MipSkeleton : public MipSolver, public SkeletonSolverBase { |
---|
[459] | 198 | public: |
---|
[540] | 199 | ///\e |
---|
| 200 | MipSkeleton() : MipSolver(), SkeletonSolverBase() {} |
---|
| 201 | ///\e |
---|
| 202 | virtual MipSkeleton* newSolver() const; |
---|
| 203 | ///\e |
---|
| 204 | virtual MipSkeleton* cloneSolver() const; |
---|
[459] | 205 | |
---|
| 206 | protected: |
---|
| 207 | ///\e |
---|
[458] | 208 | virtual SolveExitStatus _solve(); |
---|
| 209 | |
---|
| 210 | ///\e |
---|
[459] | 211 | virtual Value _getSol(int i) const; |
---|
[458] | 212 | |
---|
| 213 | ///\e |
---|
[459] | 214 | virtual Value _getSolValue() const; |
---|
[458] | 215 | |
---|
| 216 | ///\e |
---|
[459] | 217 | virtual ProblemType _getType() const; |
---|
[458] | 218 | |
---|
| 219 | ///\e |
---|
[459] | 220 | virtual const char* _solverName() const; |
---|
[458] | 221 | }; |
---|
| 222 | |
---|
| 223 | } //namespace lemon |
---|
| 224 | |
---|
[529] | 225 | #endif |
---|