Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
LPWrapper.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Alexandra Zerck $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_DATASTRUCTURES_LPWRAPPER_H
36 #define OPENMS_DATASTRUCTURES_LPWRAPPER_H
37 
38 #include <OpenMS/DATASTRUCTURES/String.h> // for String
39 
40 #include <OpenMS/CONCEPT/Types.h>
41 #include <OpenMS/OpenMSConfig.h>
42 #include <OpenMS/config.h>
43 
44 #include <limits>
45 
46 // do NOT include glpk and CoinOr headers here, as they define bad stuff, which ripples through OpenMS then...
47 // include them in LPWrapper.cpp where they do not harm
48 // only declare them here
49 class CoinModel;
50 #define GLP_PROB_DEFINED
51 
52 // depending on the glpk version
53 // define glp_prob as forward or struct
54 #if OPENMS_GLPK_VERSION_MINOR < 48
55 typedef struct
56 {
57  double _opaque_prob[100];
58 } glp_prob;
59 #else
60 class glp_prob;
61 #endif
62 
63 namespace OpenMS
64 {
65 
66  class OPENMS_DLLAPI LPWrapper
67  {
68 public:
72  struct SolverParam
73  {
75  message_level(3), branching_tech(4), backtrack_tech(3),
76  preprocessing_tech(2), enable_feas_pump_heuristic(true), enable_gmi_cuts(true),
77  enable_mir_cuts(true), enable_cov_cuts(true), enable_clq_cuts(true), mip_gap(0.0),
78  time_limit((std::numeric_limits<Int>::max)()), output_freq(5000), output_delay(10000), enable_presolve(true),
79  enable_binarization(true)
80  {
81  }
82 
92  double mip_gap;
97  bool enable_binarization; // only with presolve
98  };
99 
100  enum Type
101  {
102  UNBOUNDED = 1,
106  FIXED
107  };
108 
110  {
111  CONTINUOUS = 1,
113  BINARY
114  };
115 
116  enum Sense
117  {
118  MIN = 1,
119  MAX
120  };
121 
123  {
124  FORMAT_LP = 0,
126  FORMAT_GLPK
127  };
128 
129  enum SOLVER
130  {
131  SOLVER_GLPK = 0
132 #if COINOR_SOLVER == 1
133  , SOLVER_COINOR
134 #endif
135  };
136 
138  {
139  UNDEFINED = 1,
140  OPTIMAL = 5,
141  FEASIBLE = 2,
142  NO_FEASIBLE_SOL = 4
143  };
144 
145  LPWrapper();
146  virtual ~LPWrapper();
147 
148  // problem creation/manipulation
150  Int addRow(std::vector<Int> row_indices, std::vector<double> row_values, const String& name);
152  Int addColumn();
154  Int addColumn(std::vector<Int> column_indices, std::vector<double> column_values, const String& name);
155 
168  Int addRow(std::vector<Int>& row_indices, std::vector<double>& row_values, const String& name, double lower_bound, double upper_bound, Type type);
169 
180  Int addColumn(std::vector<Int>& column_indices, std::vector<double>& column_values, const String& name, double lower_bound, double upper_bound, Type type);
181 
183  void deleteRow(Int index);
185  void setColumnName(Int index, const String& name);
187  String getColumnName(Int index);
189  String getRowName(Int index);
191  Int getRowIndex(const String& name);
193  Int getColumnIndex(const String& name);
195  double getColumnUpperBound(Int index);
197  double getColumnLowerBound(Int index);
199  double getRowUpperBound(Int index);
201  double getRowLowerBound(Int index);
203  void setRowName(Int index, const String& name);
204 
213  void setColumnBounds(Int index, double lower_bound, double upper_bound, Type type);
214 
223  void setRowBounds(Int index, double lower_bound, double upper_bound, Type type);
224 
231  void setColumnType(Int index, VariableType type);
232 
239  VariableType getColumnType(Int index);
240 
242  void setObjective(Int index, double obj_value);
244  double getObjective(Int index);
245 
251  void setObjectiveSense(Sense sense);
252  Sense getObjectiveSense();
253 
255  Int getNumberOfColumns();
257  Int getNumberOfRows();
258 
259  void setElement(Int row_index, Int column_index, double value);
260  double getElement(Int row_index, Int column_index);
261 
262  // problem reading/writing
269  void readProblem(String filename, String format);
270 
277  void writeProblem(const String& filename, const WriteFormat format) const;
278 
289  Int solve(SolverParam& solver_param, const Size verbose_level = 0);
290 
296  SolverStatus getStatus();
297 
298  // solution access
299  double getObjectiveValue();
300  double getColumnValue(Int index);
301 
302  Int getNumberOfNonZeroEntriesInRow(Int idx);
303  void getMatrixRow(Int idx, std::vector<Int>& indexes);
304 
307  void setSolver(const SOLVER s);
308 
310  SOLVER getSolver() const;
311 
312 protected:
313 #if COINOR_SOLVER == 1
314  CoinModel * model_;
315  std::vector<double> solution_;
316 #endif
317 
319 
321 
322 
323  }; // class
324 
325 } // namespace
326 
327 #endif // OPENMS_DATASTRUCTURES_LPWRAPPER_H
bool enable_gmi_cuts
Definition: LPWrapper.h:88
WriteFormat
Definition: LPWrapper.h:122
Int output_freq
Definition: LPWrapper.h:94
A more convenient string class.
Definition: String.h:57
SOLVER
Definition: LPWrapper.h:129
Definition: LPWrapper.h:105
double mip_gap
Definition: LPWrapper.h:92
Definition: LPWrapper.h:104
Definition: LPWrapper.h:125
bool enable_clq_cuts
Definition: LPWrapper.h:91
STL namespace.
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Struct that holds the parameters of the LP solver.
Definition: LPWrapper.h:72
Definition: LPWrapper.h:66
Sense
Definition: LPWrapper.h:116
bool enable_cov_cuts
Definition: LPWrapper.h:90
Int time_limit
Definition: LPWrapper.h:93
Int message_level
Definition: LPWrapper.h:83
Int branching_tech
Definition: LPWrapper.h:84
SolverParam()
Definition: LPWrapper.h:74
bool enable_presolve
Definition: LPWrapper.h:96
Definition: LPWrapper.h:112
SOLVER solver_
Definition: LPWrapper.h:320
Int backtrack_tech
Definition: LPWrapper.h:85
Type
Definition: LPWrapper.h:100
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
SolverStatus
Definition: LPWrapper.h:137
Definition: LPWrapper.h:103
Int preprocessing_tech
Definition: LPWrapper.h:86
glp_prob * lp_problem_
Definition: LPWrapper.h:318
VariableType
Definition: LPWrapper.h:109
int Int
Signed integer type.
Definition: Types.h:103
bool enable_mir_cuts
Definition: LPWrapper.h:89
bool enable_feas_pump_heuristic
Definition: LPWrapper.h:87
Int output_delay
Definition: LPWrapper.h:95
bool enable_binarization
Definition: LPWrapper.h:97
Definition: LPWrapper.h:55

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:01 using doxygen 1.8.13