OpenMS  2.5.0
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-2020.
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 #pragma once
36 
37 #include <OpenMS/DATASTRUCTURES/String.h> // for String
38 
39 #include <OpenMS/CONCEPT/Types.h>
40 #include <OpenMS/OpenMSConfig.h>
41 #include <OpenMS/config.h>
42 
43 #include <limits>
44 
45 // do NOT include glpk and CoinOr headers here, as they define bad stuff, which ripples through OpenMS then...
46 // include them in LPWrapper.cpp where they do not harm
47 // only declare them here
48 class CoinModel;
49 
50 #ifndef GLP_PROB_DEFINED
51 #define GLP_PROB_DEFINED
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 #endif
63 
64 namespace OpenMS
65 {
66 
67  class OPENMS_DLLAPI LPWrapper
68  {
69 public:
73  struct SolverParam
74  {
76  message_level(3), branching_tech(4), backtrack_tech(3),
77  preprocessing_tech(2), enable_feas_pump_heuristic(true), enable_gmi_cuts(true),
78  enable_mir_cuts(true), enable_cov_cuts(true), enable_clq_cuts(true), mip_gap(0.0),
79  time_limit((std::numeric_limits<Int>::max)()), output_freq(5000), output_delay(10000), enable_presolve(true),
80  enable_binarization(true)
81  {
82  }
83 
93  double mip_gap;
99  };
100 
101  enum Type
102  {
103  UNBOUNDED = 1,
107  FIXED
108  };
109 
111  {
112  CONTINUOUS = 1,
114  BINARY
115  };
116 
117  enum Sense
118  {
119  MIN = 1,
121  };
122 
124  {
125  FORMAT_LP = 0,
127  FORMAT_GLPK
128  };
129 
130  enum SOLVER
131  {
132  SOLVER_GLPK = 0
133 #if COINOR_SOLVER == 1
134  , SOLVER_COINOR
135 #endif
136  };
137 
139  {
140  UNDEFINED = 1,
141  OPTIMAL = 5,
142  FEASIBLE = 2,
143  NO_FEASIBLE_SOL = 4
144  };
145 
146  LPWrapper();
147  virtual ~LPWrapper();
148 
149  // problem creation/manipulation
151  Int addRow(const std::vector<Int>& row_indices, const std::vector<double>& row_values, const String& name);
153  Int addColumn();
155  Int addColumn(const std::vector<Int>& column_indices, const std::vector<double>& column_values, const String& name);
156 
169  Int addRow(const std::vector<Int>& row_indices, const std::vector<double>& row_values,
170  const String& name, double lower_bound, double upper_bound, Type type);
171 
182  Int addColumn(const std::vector<Int>& column_indices, const std::vector<double>& column_values, const String& name, double lower_bound, double upper_bound, Type type);
183 
185  void deleteRow(Int index);
187  void setColumnName(Int index, const String& name);
189  String getColumnName(Int index);
191  String getRowName(Int index);
193  Int getRowIndex(const String& name);
195  Int getColumnIndex(const String& name);
197  double getColumnUpperBound(Int index);
199  double getColumnLowerBound(Int index);
201  double getRowUpperBound(Int index);
203  double getRowLowerBound(Int index);
205  void setRowName(Int index, const String& name);
206 
215  void setColumnBounds(Int index, double lower_bound, double upper_bound, Type type);
216 
225  void setRowBounds(Int index, double lower_bound, double upper_bound, Type type);
226 
233  void setColumnType(Int index, VariableType type);
234 
241  VariableType getColumnType(Int index);
242 
244  void setObjective(Int index, double obj_value);
246  double getObjective(Int index);
247 
253  void setObjectiveSense(Sense sense);
254  Sense getObjectiveSense();
255 
257  Int getNumberOfColumns();
259  Int getNumberOfRows();
260 
261  void setElement(Int row_index, Int column_index, double value);
262  double getElement(Int row_index, Int column_index);
263 
264  // problem reading/writing
271  void readProblem(const String& filename, const String& format);
272 
279  void writeProblem(const String& filename, const WriteFormat format) const;
280 
291  Int solve(SolverParam& solver_param, const Size verbose_level = 0);
292 
298  SolverStatus getStatus();
299 
300  // solution access
301  double getObjectiveValue();
302  double getColumnValue(Int index);
303 
304  Int getNumberOfNonZeroEntriesInRow(Int idx);
305  void getMatrixRow(Int idx, std::vector<Int>& indexes);
306 
309  void setSolver(const SOLVER s);
310 
312  SOLVER getSolver() const;
313 
314 protected:
315 #if COINOR_SOLVER == 1
316  CoinModel * model_ = nullptr;
317  std::vector<double> solution_;
318 #endif
319 
320  glp_prob * lp_problem_ = nullptr;
321 
323 
324 
325  }; // class
326 
327 } // namespace
328 
OpenMS::MSDataWritingConsumer
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:88
OpenMS::LPWrapper::LOWER_BOUND_ONLY
Definition: LPWrapper.h:104
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:144
OpenMS::Param::copy
Param copy(const String &prefix, bool remove_prefix=false) const
Returns a new Param object containing all entries that start with prefix.
OpenMS::LPWrapper::SolverParam::enable_gmi_cuts
bool enable_gmi_cuts
Definition: LPWrapper.h:89
OpenMS::Exception::IllegalArgument
A method or algorithm argument contains illegal values.
Definition: Exception.h:648
OpenMS::LPWrapper::Type
Type
Definition: LPWrapper.h:101
OpenMS::LPWrapper::SolverStatus
SolverStatus
Definition: LPWrapper.h:138
OpenMS::LPWrapper::SolverParam::output_freq
Int output_freq
Definition: LPWrapper.h:95
Types.h
OpenMS::LPWrapper::SolverParam::enable_clq_cuts
bool enable_clq_cuts
Definition: LPWrapper.h:92
OpenMS::LPWrapper::SolverParam::enable_feas_pump_heuristic
bool enable_feas_pump_heuristic
Definition: LPWrapper.h:88
OpenMS::IndexedMzMLFileLoader
A class to load an indexedmzML file.
Definition: IndexedMzMLFileLoader.h:53
OpenMS::MzMLFile::store
void store(const String &filename, const PeakMap &map) const
Stores a map in an MzML file.
OpenMS::MzMLFile
File adapter for MzML files.
Definition: MzMLFile.h:55
OpenMS::String
A more convenient string class.
Definition: String.h:58
MzMLFile.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::PeakPickerHiRes::pickExperiment
void pickExperiment(const PeakMap &input, PeakMap &output, const bool check_spectrum_type=true) const
Applies the peak-picking algorithm to a map (MSExperiment). This method picks peaks for each scan in ...
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::ListUtils::contains
static bool contains(const std::vector< T > &container, const E &elem)
Checks whether the element elem is contained in the given container.
Definition: ListUtils.h:146
OpenMS::LPWrapper
Definition: LPWrapper.h:67
OpenMS::LPWrapper::SolverParam::mip_gap
double mip_gap
Definition: LPWrapper.h:93
OpenMS::LPWrapper::SolverParam::message_level
Int message_level
Definition: LPWrapper.h:84
OpenMS::LPWrapper::WriteFormat
WriteFormat
Definition: LPWrapper.h:123
OpenMS::LPWrapper::SolverParam::SolverParam
SolverParam()
Definition: LPWrapper.h:75
OpenMS::LPWrapper::SolverParam::enable_cov_cuts
bool enable_cov_cuts
Definition: LPWrapper.h:91
OpenMS::MSSpectrum::getMSLevel
UInt getMSLevel() const
Returns the MS level.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::PeakPickerHiRes
This class implements a fast peak-picking algorithm best suited for high resolution MS data (FT-ICR-M...
Definition: PeakPickerHiRes.h:73
OpenMS::LPWrapper::SolverParam::time_limit
Int time_limit
Definition: LPWrapper.h:94
OpenMS::LPWrapper::DOUBLE_BOUNDED
Definition: LPWrapper.h:106
int
OpenMS::OnDiscMSExperiment
Representation of a mass spectrometry experiment on disk.
Definition: OnDiscMSExperiment.h:68
OpenMS::IndexedMzMLFileLoader::load
bool load(const String &filename, OnDiscPeakMap &exp)
Load a file.
Definition: IndexedMzMLFileLoader.h:82
OpenMS::DataProcessing::PEAK_PICKING
Peak picking (conversion from raw to peak data)
Definition: DataProcessing.h:67
OpenMS::LPWrapper::SolverParam::branching_tech
Int branching_tech
Definition: LPWrapper.h:85
OpenMS::LPWrapper::SolverParam::backtrack_tech
Int backtrack_tech
Definition: LPWrapper.h:86
OpenMS::IntensityAveragingMethod::MIN
OpenMS::LPWrapper::UPPER_BOUND_ONLY
Definition: LPWrapper.h:105
OpenMS::LPWrapper::SolverParam
Struct that holds the parameters of the LP solver.
Definition: LPWrapper.h:73
OpenMS::DefaultParamHandler::setParameters
void setParameters(const Param &param)
Sets the parameters.
OpenMS::DefaultParamHandler::getDefaults
const Param & getDefaults() const
Non-mutable access to the default parameters.
OpenMS::LPWrapper::SolverParam::enable_presolve
bool enable_presolve
Definition: LPWrapper.h:97
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:73
MSExperiment.h
OpenMS::LPWrapper::Sense
Sense
Definition: LPWrapper.h:117
OpenMS::MzMLFile::transform
void transform(const String &filename_in, Interfaces::IMSDataConsumer *consumer, bool skip_full_count=false, bool skip_first_pass=false)
Transforms a map while loading using the supplied MSDataConsumer.
OpenMS::LPWrapper::VariableType
VariableType
Definition: LPWrapper.h:110
OpenMS::MSChromatogram
The representation of a chromatogram.
Definition: MSChromatogram.h:54
OpenMS::LPWrapper::INTEGER
Definition: LPWrapper.h:113
String.h
OpenMS::IntensityAveragingMethod::MAX
OpenMS::LPWrapper::SOLVER
SOLVER
Definition: LPWrapper.h:130
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:73
OpenMS::LPWrapper::SolverParam::enable_mir_cuts
bool enable_mir_cuts
Definition: LPWrapper.h:90
OpenMS::LPWrapper::solver_
SOLVER solver_
Definition: LPWrapper.h:322
OpenMS::LPWrapper::SolverParam::preprocessing_tech
Int preprocessing_tech
Definition: LPWrapper.h:87
OpenMS::LPWrapper::FORMAT_MPS
Definition: LPWrapper.h:126
PeakPickerHiRes.h
MSDataWritingConsumer.h
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
OnDiscMSExperiment.h
glp_prob
Definition: LPWrapper.h:55
IndexedMzMLFileLoader.h
OpenMS::LPWrapper::SolverParam::output_delay
Int output_delay
Definition: LPWrapper.h:96
OpenMS::LPWrapper::SolverParam::enable_binarization
bool enable_binarization
only with presolve
Definition: LPWrapper.h:98
OpenMS::ProgressLogger::setLogType
void setLogType(LogType type) const
Sets the progress log that should be used. The default type is NONE!
TOPPBase.h