00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00042
00043
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;
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
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
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
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 };
00312
00313 }
00314
00315 #endif // OPENMS_DATASTRUCTURES_LPWRAPPER_H