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-2013.
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: Alexandra Zerck $
32 // $Authors: Alexandra Zerck $
33 // --------------------------------------------------------------------------
34 #ifndef OPENMS_DATASTRUCTURES_LPWRAPPER_H
35 #define OPENMS_DATASTRUCTURES_LPWRAPPER_H
36 
37 #include <limits>
38 
40 
41 // do NOT include glpk and CoinOr headers here, as they define bad stuff, which ripples through OpenMS then...
42 // include them in LPWrapper.C where they do not harm
43 // only declare them here
44 class CoinModel;
45 #define GLP_PROB_DEFINED
46 
47 // depending on the glpk version
48 // define glp_prob as forward or struct
49 #if OPENMS_GLPK_VERSION_MINOR < 48
50 typedef struct
51 {
52  double _opaque_prob[100];
53 } glp_prob;
54 #else
55 class glp_prob;
56 #endif
57 
58 namespace OpenMS
59 {
60 
61  class OPENMS_DLLAPI LPWrapper
62  {
63 public:
67  struct SolverParam
68  {
70  message_level(3), branching_tech(4), backtrack_tech(3),
71  preprocessing_tech(2), enable_feas_pump_heuristic(true), enable_gmi_cuts(true),
72  enable_mir_cuts(true), enable_cov_cuts(true), enable_clq_cuts(true), mip_gap(0.0),
73  time_limit((std::numeric_limits<Int>::max)()), output_freq(5000), output_delay(10000), enable_presolve(true),
74  enable_binarization(true)
75  {
76  }
77 
92  bool enable_binarization; // only with presolve
93  };
94 
95  enum Type
96  {
97  UNBOUNDED = 1,
101  FIXED
102  };
103 
105  {
106  CONTINUOUS = 1,
108  BINARY
109  };
110 
111  enum Sense
112  {
113  MIN = 1,
114  MAX
115  };
116 
118  {
119  FORMAT_LP = 0,
121  FORMAT_GLPK
122  };
123 
124  enum SOLVER
125  {
126  SOLVER_GLPK = 0
127 #if COINOR_SOLVER == 1
128  , SOLVER_COINOR
129 #endif
130  };
131 
133  {
134  UNDEFINED = 1,
135  OPTIMAL = 5,
136  FEASIBLE = 2,
137  NO_FEASIBLE_SOL = 4
138  };
139 
140  LPWrapper();
141  virtual ~LPWrapper();
142 
143  // problem creation/manipulation
145  Int addRow(std::vector<Int> row_indices, std::vector<DoubleReal> row_values, const String & name);
147  Int addColumn();
149  Int addColumn(std::vector<Int> column_indices, std::vector<DoubleReal> column_values, const String & name);
150 
163  Int addRow(std::vector<Int> & row_indices, std::vector<DoubleReal> & row_values, const String & name, DoubleReal lower_bound, DoubleReal upper_bound, Type type);
164 
175  Int addColumn(std::vector<Int> & column_indices, std::vector<DoubleReal> & column_values, const String & name, DoubleReal lower_bound, DoubleReal upper_bound, Type type);
176 
178  void deleteRow(Int index);
180  void setColumnName(Int index, const String & name);
182  String getColumnName(Int index);
184  String getRowName(Int index);
186  Int getRowIndex(const String & name);
188  Int getColumnIndex(const String & name);
190  DoubleReal getColumnUpperBound(Int index);
192  DoubleReal getColumnLowerBound(Int index);
194  DoubleReal getRowUpperBound(Int index);
196  DoubleReal getRowLowerBound(Int index);
198  void setRowName(Int index, const String & name);
199 
208  void setColumnBounds(Int index, DoubleReal lower_bound, DoubleReal upper_bound, Type type);
209 
218  void setRowBounds(Int index, DoubleReal lower_bound, DoubleReal upper_bound, Type type);
219 
226  void setColumnType(Int index, VariableType type);
227 
234  VariableType getColumnType(Int index);
235 
237  void setObjective(Int index, DoubleReal obj_value);
239  DoubleReal getObjective(Int index);
240 
246  void setObjectiveSense(Sense sense);
247  Sense getObjectiveSense();
248 
250  Int getNumberOfColumns();
252  Int getNumberOfRows();
253 
254  void setElement(Int row_index, Int column_index, DoubleReal value);
255  DoubleReal getElement(Int row_index, Int column_index);
256 
257  // problem reading/writing
264  void readProblem(String filename, String format);
265 
272  void writeProblem(const String & filename, const WriteFormat format) const;
273 
284  Int solve(SolverParam & solver_param, const Size verbose_level = 0);
285 
291  SolverStatus getStatus();
292 
293  // solution access
294  DoubleReal getObjectiveValue();
295  DoubleReal getColumnValue(Int index);
296 
297  Int getNumberOfNonZeroEntriesInRow(Int idx);
298  void getMatrixRow(Int idx, std::vector<Int> & indexes);
299 
302  void setSolver(const SOLVER s);
303 
305  SOLVER getSolver() const;
306 
307 protected:
308 #if COINOR_SOLVER == 1
309  CoinModel * model_;
310  std::vector<DoubleReal> solution_;
311 #endif
312 
314 
316 
317 
318  }; // class
319 
320 } // namespace
321 
322 #endif // OPENMS_DATASTRUCTURES_LPWRAPPER_H
bool enable_gmi_cuts
Definition: LPWrapper.h:83
WriteFormat
Definition: LPWrapper.h:117
Int output_freq
Definition: LPWrapper.h:89
A more convenient string class.
Definition: String.h:56
SOLVER
Definition: LPWrapper.h:124
Definition: LPWrapper.h:100
Definition: LPWrapper.h:99
Definition: LPWrapper.h:120
bool enable_clq_cuts
Definition: LPWrapper.h:86
Struct that holds the parameters of the LP solver.
Definition: LPWrapper.h:67
Definition: LPWrapper.h:61
Sense
Definition: LPWrapper.h:111
bool enable_cov_cuts
Definition: LPWrapper.h:85
Int time_limit
Definition: LPWrapper.h:88
Int message_level
Definition: LPWrapper.h:78
Int branching_tech
Definition: LPWrapper.h:79
DoubleReal mip_gap
Definition: LPWrapper.h:87
SolverParam()
Definition: LPWrapper.h:69
bool enable_presolve
Definition: LPWrapper.h:91
Definition: LPWrapper.h:107
SOLVER solver_
Definition: LPWrapper.h:315
Int backtrack_tech
Definition: LPWrapper.h:80
Type
Definition: LPWrapper.h:95
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
SolverStatus
Definition: LPWrapper.h:132
Definition: LPWrapper.h:98
Int preprocessing_tech
Definition: LPWrapper.h:81
glp_prob * lp_problem_
Definition: LPWrapper.h:313
VariableType
Definition: LPWrapper.h:104
int Int
Signed integer type.
Definition: Types.h:100
bool enable_mir_cuts
Definition: LPWrapper.h:84
bool enable_feas_pump_heuristic
Definition: LPWrapper.h:82
Int output_delay
Definition: LPWrapper.h:90
bool enable_binarization
Definition: LPWrapper.h:92
Definition: LPWrapper.h:50

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:16 using doxygen 1.8.5