/usr/include/shogun/mathematics/Cplex.h is in libshogun-dev 3.2.0-7.3build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | /*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2006-2009 Soeren Sonnenburg
* Copyright (C) 2006-2009 Fraunhofer Institute FIRST and Max-Planck-Society
*/
#ifndef CCPLEX_H__
#define CCPLEX_H__
#include <shogun/lib/config.h>
#ifdef USE_CPLEX
extern "C" {
#include <ilcplex/cplex.h>
}
#include <shogun/lib/common.h>
#include <shogun/base/SGObject.h>
#include <shogun/features/SparseFeatures.h>
#include <shogun/labels/BinaryLabels.h>
namespace shogun
{
enum E_PROB_TYPE
{
E_LINEAR,
E_QP
};
/** @brief Class CCplex to encapsulate access to the commercial cplex general
* purpose optimizer.
*
* This class takes care of obtaining and releasing cplex licenses and sets up
* a number of optimization problems that are used in shogun, like for Multiple
* Kernel Learning, Linear Programming Machines and Linear Programming Boosting.
*/
class CCplex : public CSGObject
{
public:
CCplex();
virtual ~CCplex();
/// init cplex with problem type t and retry timeout 60 seconds
bool init(E_PROB_TYPE t, int32_t timeout=60);
bool cleanup();
// A = [ E Z_w Z_x ] dim(A)=(num_dim+1, num_dim+1 + num_zero + num_bound)
// (+1 for bias!)
bool setup_subgradientlpm_QP(
float64_t C, CBinaryLabels* labels, CSparseFeatures<float64_t>* features,
int32_t* idx_bound, int32_t num_bound, int32_t* w_zero,
int32_t num_zero, float64_t* vee, int32_t num_dim, bool use_bias);
bool setup_lpboost(float64_t C, int32_t num_cols);
bool add_lpboost_constraint(
float64_t factor, SGSparseVectorEntry<float64_t>* h, int32_t len,
int32_t ulen, CBinaryLabels* label);
// given N sparse inputs x_i, and corresponding labels y_i i=0...N-1
// create the following 1-norm SVM problem & transfer to cplex
//
/////////////////////////////////////////////////////////////////
// min_w sum_{i=0}^N ( w^+_i + w^-_i) + C \sum_{i=0}^N \xi_i
// w=[w^+ w^-]
// b, xi
//
// -y_i((w^+-w^-)^T x_i + b)-xi_i <= -1
// xi_i >= 0
// w_i >= 0 forall i=1...N
/////////////////////////////////////////////////////////////////
// min f^x
// Ax <= b
// -x <= 0
//
// lb= [ -inf, //b
// 2*dims [0], //w
// num_train [0] //xi
// ]
//
// ub= [ inf, //b
// 2*dims [inf], //w
// num_train [inf] //xi
// ]
//
// f= [0,2*dim[1], num_train*C]
// A= [-y', // b
// -y_ix_i // w_+
// +y_ix_i // w_-
// -1 //xi
// ]
//
// dim(A)=(n,1+2*dim+n)
//
// b = -1 -1 -1 -1 ...
bool setup_lpm(
float64_t C, CSparseFeatures<float64_t>* x, CBinaryLabels* y, bool use_bias);
// call this to setup linear part
//
// setup lp, to minimize
// objective[0]*x_0 ... objective[cols-1]*x_{cols-1}
// w.r.t. x
// s.t. constraint_mat*x <= rhs
// lb[i] <= x[i] <= ub[i] for all i
bool setup_lp(
float64_t* objective, float64_t* constraints_mat, int32_t rows,
int32_t cols, float64_t* rhs, float64_t* lb, float64_t* ub);
// call this to setup quadratic part H
// x'*H*x
// call setup_lp before (to setup the linear part / linear constraints)
bool setup_qp(float64_t* H, int32_t dim);
bool optimize(float64_t* sol, float64_t* lambda=NULL);
bool dense_to_cplex_sparse(
float64_t* H, int32_t rows, int32_t cols, int* &qmatbeg, int* &qmatcnt,
int* &qmatind, double* &qmatval);
inline bool set_time_limit(float64_t seconds)
{
return CPXsetdblparam (env, CPX_PARAM_TILIM, seconds) == 0;
}
inline bool write_problem(char* filename)
{
return CPXwriteprob (env, lp, filename, NULL) == 0;
}
inline bool write_Q(char* filename)
{
#if CPX_VERSION >= 1000 //CPXqpwrite has been deprecated in CPLEX 10
return CPXwriteprob (env, lp, filename, NULL) == 0;
#else
return CPXqpwrite (env, lp, filename) == 0;
#endif
}
/** @return object name */
virtual const char* get_name() const { return "Cplex"; }
protected:
CPXENVptr env;
CPXLPptr lp;
bool lp_initialized;
E_PROB_TYPE problem_type;
};
}
#endif
#endif
|