Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

LPWrapper.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Alexandra Zerck $
00032 // $Authors: Alexandra Zerck $
00033 // --------------------------------------------------------------------------
00034 #ifndef OPENMS_DATASTRUCTURES_LPWRAPPER_H
00035 #define OPENMS_DATASTRUCTURES_LPWRAPPER_H
00036 
00037 #include <limits>
00038 
00039 #include <OpenMS/DATASTRUCTURES/String.h>
00040 
00041 // do NOT include glpk and CoinOr headers here, as they define bad stuff, which ripples through OpenMS then...
00042 // include them in LPWrapper.C where they do not harm
00043 // only declare them here
00044 class CoinModel;
00045 #define GLP_PROB_DEFINED
00046 typedef struct
00047 {
00048   double _opaque_prob[100];
00049 } glp_prob;
00050 
00051 namespace OpenMS
00052 {
00053 
00054   class OPENMS_DLLAPI LPWrapper
00055   {
00056 public:
00060     struct SolverParam
00061     {
00062       SolverParam() :
00063         message_level(3), branching_tech(4), backtrack_tech(3),
00064         preprocessing_tech(2), enable_feas_pump_heuristic(true), enable_gmi_cuts(true),
00065         enable_mir_cuts(true), enable_cov_cuts(true), enable_clq_cuts(true), mip_gap(0.0),
00066         time_limit((std::numeric_limits<Int>::max)()), output_freq(5000), output_delay(10000), enable_presolve(true),
00067         enable_binarization(true)
00068       {
00069       }
00070 
00071       Int message_level;
00072       Int branching_tech;
00073       Int backtrack_tech;
00074       Int preprocessing_tech;
00075       bool enable_feas_pump_heuristic;
00076       bool enable_gmi_cuts;
00077       bool enable_mir_cuts;
00078       bool enable_cov_cuts;
00079       bool enable_clq_cuts;
00080       DoubleReal mip_gap;
00081       Int time_limit;
00082       Int output_freq;
00083       Int output_delay;
00084       bool enable_presolve;
00085       bool enable_binarization; // only with presolve
00086     };
00087 
00088     enum Type
00089     {
00090       UNBOUNDED = 1,
00091       LOWER_BOUND_ONLY,
00092       UPPER_BOUND_ONLY,
00093       DOUBLE_BOUNDED,
00094       FIXED
00095     };
00096 
00097     enum VariableType
00098     {
00099       CONTINUOUS = 1,
00100       INTEGER,
00101       BINARY
00102     };
00103 
00104     enum Sense
00105     {
00106       MIN = 1,
00107       MAX
00108     };
00109 
00110     enum WriteFormat
00111     {
00112       FORMAT_LP = 0,
00113       FORMAT_MPS,
00114       FORMAT_GLPK
00115     };
00116 
00117     enum SOLVER
00118     {
00119       SOLVER_GLPK = 0
00120 #if COINOR_SOLVER == 1
00121       , SOLVER_COINOR
00122 #endif
00123     };
00124 
00125     enum SolverStatus
00126     {
00127       UNDEFINED = 1,
00128       OPTIMAL = 5,
00129       FEASIBLE = 2,
00130       NO_FEASIBLE_SOL = 4
00131     };
00132 
00133     LPWrapper();
00134     virtual ~LPWrapper();
00135 
00136     // problem creation/manipulation
00138     Int addRow(std::vector<Int> row_indices, std::vector<DoubleReal> row_values, const String & name);
00140     Int addColumn();
00142     Int addColumn(std::vector<Int> column_indices, std::vector<DoubleReal> column_values, const String & name);
00143 
00156     Int addRow(std::vector<Int> & row_indices, std::vector<DoubleReal> & row_values, const String & name, DoubleReal lower_bound, DoubleReal upper_bound, Type type);
00157 
00168     Int addColumn(std::vector<Int> & column_indices, std::vector<DoubleReal> & column_values, const String & name, DoubleReal lower_bound, DoubleReal upper_bound, Type type);
00169 
00171     void deleteRow(Int index);
00173     void setColumnName(Int index, const String & name);
00175     String getColumnName(Int index);
00177     String getRowName(Int index);
00179     Int getRowIndex(const String & name);
00181     Int getColumnIndex(const String & name);
00183     DoubleReal getColumnUpperBound(Int index);
00185     DoubleReal getColumnLowerBound(Int index);
00187     DoubleReal getRowUpperBound(Int index);
00189     DoubleReal getRowLowerBound(Int index);
00191     void setRowName(Int index, const String & name);
00192 
00201     void setColumnBounds(Int index, DoubleReal lower_bound, DoubleReal upper_bound, Type type);
00202 
00211     void setRowBounds(Int index, DoubleReal lower_bound, DoubleReal upper_bound, Type type);
00212 
00219     void setColumnType(Int index, VariableType type);
00220 
00227     VariableType getColumnType(Int index);
00228 
00230     void setObjective(Int index, DoubleReal obj_value);
00232     DoubleReal getObjective(Int index);
00233 
00239     void setObjectiveSense(Sense sense);
00240     Sense getObjectiveSense();
00241 
00243     Int getNumberOfColumns();
00245     Int getNumberOfRows();
00246 
00247     void setElement(Int row_index, Int column_index, DoubleReal value);
00248     DoubleReal getElement(Int row_index, Int column_index);
00249 
00250     // problem reading/writing
00257     void readProblem(String filename, String format);
00258 
00265     void writeProblem(const String & filename, const WriteFormat format) const;
00266 
00277     Int solve(SolverParam & solver_param, const Size verbose_level = 0);
00278 
00284     SolverStatus getStatus();
00285 
00286     // solution access
00287     DoubleReal getObjectiveValue();
00288     DoubleReal getColumnValue(Int index);
00289 
00290     Int getNumberOfNonZeroEntriesInRow(Int idx);
00291     void getMatrixRow(Int idx, std::vector<Int> & indexes);
00292 
00295     void setSolver(const SOLVER s);
00296 
00298     SOLVER getSolver() const;
00299 
00300 protected:
00301 #if COINOR_SOLVER == 1
00302     CoinModel * model_;
00303     std::vector<DoubleReal> solution_;
00304 #endif
00305 
00306     glp_prob * lp_problem_;
00307 
00308     SOLVER solver_;
00309 
00310 
00311   }; // class
00312 
00313 } // namespace
00314 
00315 #endif // OPENMS_DATASTRUCTURES_LPWRAPPER_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:40 using doxygen 1.7.1