Cplex.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef CCPLEX_H__
00012 #define CCPLEX_H__
00013
00014 #include "lib/config.h"
00015
00016 #ifdef USE_CPLEX
00017 extern "C" {
00018 #include <ilcplex/cplex.h>
00019 }
00020
00021 #include "lib/common.h"
00022 #include "base/SGObject.h"
00023
00024 #include "features/SparseFeatures.h"
00025 #include "features/Labels.h"
00026
00027 enum E_PROB_TYPE
00028 {
00029 E_LINEAR,
00030 E_QP
00031 };
00032
00039 class CCplex : public CSGObject
00040 {
00041 public:
00042
00043 CCplex();
00044 ~CCplex();
00045
00047 bool init(E_PROB_TYPE t, int32_t timeout=60);
00048 bool cleanup();
00049
00050
00051
00052 bool setup_subgradientlpm_QP(
00053 float64_t C, CLabels* labels, CSparseFeatures<float64_t>* features,
00054 int32_t* idx_bound, int32_t num_bound, int32_t* w_zero,
00055 int32_t num_zero, float64_t* vee, int32_t num_dim, bool use_bias);
00056
00057 bool setup_lpboost(float64_t C, int32_t num_cols);
00058 bool add_lpboost_constraint(
00059 float64_t factor, TSparseEntry<float64_t>* h, int32_t len,
00060 int32_t ulen, CLabels* label);
00061
00098 bool setup_lpm(
00099 float64_t C, CSparseFeatures<float64_t>* x, CLabels* y, bool use_bias);
00100
00108 bool setup_lp(
00109 float64_t* objective, float64_t* constraints_mat, int32_t rows,
00110 int32_t cols, float64_t* rhs, float64_t* lb, float64_t* ub);
00111
00112
00116 bool setup_qp(float64_t* H, int32_t dim);
00117 bool optimize(float64_t* sol, float64_t* lambda=NULL);
00118
00119 bool dense_to_cplex_sparse(
00120 float64_t* H, int32_t rows, int32_t cols, int* &qmatbeg, int* &qmatcnt,
00121 int* &qmatind, double* &qmatval);
00122
00123 inline bool set_time_limit(float64_t seconds)
00124 {
00125 return CPXsetdblparam (env, CPX_PARAM_TILIM, seconds) == 0;
00126 }
00127 inline bool write_problem(char* filename)
00128 {
00129 return CPXwriteprob (env, lp, filename, NULL) == 0;
00130 }
00131
00132 inline bool write_Q(char* filename)
00133 {
00134 #if CPX_VERSION >= 1000 //CPXqpwrite has been deprecated in CPLEX 10
00135 return CPXwriteprob (env, lp, filename, NULL) == 0;
00136 #else
00137 return CPXqpwrite (env, lp, filename) == 0;
00138 #endif
00139 }
00140 protected:
00141 CPXENVptr env;
00142 CPXLPptr lp;
00143 bool lp_initialized;
00144
00145 E_PROB_TYPE problem_type;
00146 };
00147 #endif
00148 #endif