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 namespace shogun
00028 {
00029 enum E_PROB_TYPE
00030 {
00031 E_LINEAR,
00032 E_QP
00033 };
00034
00042 #define IGNORE_IN_CLASSLIST
00043 IGNORE_IN_CLASSLIST class CCplex : public CSGObject
00044 {
00045 public:
00046
00047 CCplex();
00048 virtual ~CCplex();
00049
00051 bool init(E_PROB_TYPE t, int32_t timeout=60);
00052 bool cleanup();
00053
00054
00055
00056 bool setup_subgradientlpm_QP(
00057 float64_t C, CLabels* labels, CSparseFeatures<float64_t>* features,
00058 int32_t* idx_bound, int32_t num_bound, int32_t* w_zero,
00059 int32_t num_zero, float64_t* vee, int32_t num_dim, bool use_bias);
00060
00061 bool setup_lpboost(float64_t C, int32_t num_cols);
00062 bool add_lpboost_constraint(
00063 float64_t factor, TSparseEntry<float64_t>* h, int32_t len,
00064 int32_t ulen, CLabels* label);
00065
00066
00067
00068
00070
00071
00072
00073
00074
00075
00076
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 bool setup_lpm(
00103 float64_t C, CSparseFeatures<float64_t>* x, CLabels* y, bool use_bias);
00104
00105
00106
00107
00108
00109
00110
00111
00112 bool setup_lp(
00113 float64_t* objective, float64_t* constraints_mat, int32_t rows,
00114 int32_t cols, float64_t* rhs, float64_t* lb, float64_t* ub);
00115
00116
00117
00118
00119
00120 bool setup_qp(float64_t* H, int32_t dim);
00121 bool optimize(float64_t* sol, float64_t* lambda=NULL);
00122
00123 bool dense_to_cplex_sparse(
00124 float64_t* H, int32_t rows, int32_t cols, int* &qmatbeg, int* &qmatcnt,
00125 int* &qmatind, double* &qmatval);
00126
00127 inline bool set_time_limit(float64_t seconds)
00128 {
00129 return CPXsetdblparam (env, CPX_PARAM_TILIM, seconds) == 0;
00130 }
00131 inline bool write_problem(char* filename)
00132 {
00133 return CPXwriteprob (env, lp, filename, NULL) == 0;
00134 }
00135
00136 inline bool write_Q(char* filename)
00137 {
00138 #if CPX_VERSION >= 1000 //CPXqpwrite has been deprecated in CPLEX 10
00139 return CPXwriteprob (env, lp, filename, NULL) == 0;
00140 #else
00141 return CPXqpwrite (env, lp, filename) == 0;
00142 #endif
00143 }
00144
00146 inline virtual const char* get_name() const { return "Cplex"; }
00147
00148 protected:
00149 CPXENVptr env;
00150 CPXLPptr lp;
00151 bool lp_initialized;
00152
00153 E_PROB_TYPE problem_type;
00154 };
00155 }
00156 #endif
00157 #endif