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