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 | |
---|
19 | #ifndef LEMON_LP_SKELETON_H |
---|
20 | #define LEMON_LP_SKELETON_H |
---|
21 | |
---|
22 | #include <lemon/lp_base.h> |
---|
23 | |
---|
24 | ///\file |
---|
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. |
---|
29 | namespace lemon { |
---|
30 | |
---|
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. |
---|
35 | class SkeletonSolverBase : public virtual LpBase { |
---|
36 | int col_num,row_num; |
---|
37 | |
---|
38 | protected: |
---|
39 | |
---|
40 | SkeletonSolverBase() |
---|
41 | : col_num(-1), row_num(-1) {} |
---|
42 | |
---|
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); |
---|
51 | |
---|
52 | /// \e |
---|
53 | virtual void _getColName(int col, std::string& name) const; |
---|
54 | /// \e |
---|
55 | virtual void _setColName(int col, const std::string& name); |
---|
56 | /// \e |
---|
57 | virtual int _colByName(const std::string& name) const; |
---|
58 | |
---|
59 | /// \e |
---|
60 | virtual void _getRowName(int row, std::string& name) const; |
---|
61 | /// \e |
---|
62 | virtual void _setRowName(int row, const std::string& name); |
---|
63 | /// \e |
---|
64 | virtual int _rowByName(const std::string& name) const; |
---|
65 | |
---|
66 | /// \e |
---|
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; |
---|
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 | |
---|
103 | /// The lower bound of a constraint (row) have to be given by an |
---|
104 | /// extended number of type Value, i.e. a finite number of type |
---|
105 | /// Value or -\ref INF. |
---|
106 | virtual void _setRowLowerBound(int i, Value value); |
---|
107 | /// \e |
---|
108 | |
---|
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; |
---|
113 | |
---|
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); |
---|
118 | /// \e |
---|
119 | |
---|
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; |
---|
124 | |
---|
125 | /// \e |
---|
126 | virtual void _setObjCoeffs(ExprIterator b, ExprIterator e); |
---|
127 | /// \e |
---|
128 | virtual void _getObjCoeffs(InsertIterator b) const; |
---|
129 | |
---|
130 | /// \e |
---|
131 | virtual void _setObjCoeff(int i, Value obj_coef); |
---|
132 | /// \e |
---|
133 | virtual Value _getObjCoeff(int i) const; |
---|
134 | |
---|
135 | ///\e |
---|
136 | virtual void _setSense(Sense); |
---|
137 | ///\e |
---|
138 | virtual Sense _getSense() const; |
---|
139 | |
---|
140 | ///\e |
---|
141 | virtual void _clear(); |
---|
142 | |
---|
143 | }; |
---|
144 | |
---|
145 | /// \brief Skeleton class for an LP solver interface |
---|
146 | /// |
---|
147 | ///This class does nothing, but it can serve as a skeleton when |
---|
148 | ///implementing an interface to new solvers. |
---|
149 | |
---|
150 | ///\ingroup lp_group |
---|
151 | class LpSkeleton : public LpSolver, public SkeletonSolverBase { |
---|
152 | public: |
---|
153 | ///\e |
---|
154 | LpSkeleton() : LpSolver(), SkeletonSolverBase() {} |
---|
155 | ///\e |
---|
156 | virtual LpSkeleton* newSolver() const; |
---|
157 | ///\e |
---|
158 | virtual LpSkeleton* cloneSolver() const; |
---|
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 | |
---|
192 | /// \brief Skeleton class for a MIP solver interface |
---|
193 | /// |
---|
194 | ///This class does nothing, but it can serve as a skeleton when |
---|
195 | ///implementing an interface to new solvers. |
---|
196 | ///\ingroup lp_group |
---|
197 | class MipSkeleton : public MipSolver, public SkeletonSolverBase { |
---|
198 | public: |
---|
199 | ///\e |
---|
200 | MipSkeleton() : MipSolver(), SkeletonSolverBase() {} |
---|
201 | ///\e |
---|
202 | virtual MipSkeleton* newSolver() const; |
---|
203 | ///\e |
---|
204 | virtual MipSkeleton* cloneSolver() const; |
---|
205 | |
---|
206 | protected: |
---|
207 | ///\e |
---|
208 | |
---|
209 | ///\bug Wrong interface |
---|
210 | /// |
---|
211 | virtual SolveExitStatus _solve(); |
---|
212 | |
---|
213 | ///\e |
---|
214 | |
---|
215 | ///\bug Wrong interface |
---|
216 | /// |
---|
217 | virtual Value _getSol(int i) const; |
---|
218 | |
---|
219 | ///\e |
---|
220 | |
---|
221 | ///\bug Wrong interface |
---|
222 | /// |
---|
223 | virtual Value _getSolValue() const; |
---|
224 | |
---|
225 | ///\e |
---|
226 | |
---|
227 | ///\bug Wrong interface |
---|
228 | /// |
---|
229 | virtual ProblemType _getType() const; |
---|
230 | |
---|
231 | ///\e |
---|
232 | virtual const char* _solverName() const; |
---|
233 | }; |
---|
234 | |
---|
235 | } //namespace lemon |
---|
236 | |
---|
237 | #endif |
---|