13 #ifndef HERMES_SRC_DPE_LINPROG_H_
14 #define HERMES_SRC_DPE_LINPROG_H_
35 int Get(
int i,
int j) {
return i *
nrow_ + j; }
60 std::vector<double>
ar_;
67 lp_ = glp_create_prob();
68 glp_set_prob_name(
lp_, name);
81 glp_add_rows(
lp_, num_constraints);
82 glp_add_cols(
lp_, num_vars);
88 ar_.emplace_back(0.0);
94 void AddConstraint(
const std::string &base_name,
int op_type,
double lb,
106 ja_.emplace_back(var);
107 ar_.emplace_back(val);
112 double lb,
double ub) {
114 std::string name = base_name + std::to_string(var);
115 glp_set_col_name(
lp_, var, name.c_str());
116 glp_set_col_bnds(
lp_, var, op_type, lb, ub);
125 glp_set_obj_coef(
lp_, var, val);
130 glp_load_matrix(
lp_,
ia_.size() - 1,
ia_.data(),
ja_.data(),
ar_.data());
132 glp_init_smcp(&parm);
133 parm.msg_lev = GLP_MSG_OFF;
134 glp_simplex(
lp_, &parm);
147 return glp_get_col_prim(
lp_, var);
152 std::vector<double> v;
154 for (
int var = 0; var <
num_vars_; ++var) {
double GetVariable(int var)
Definition: linprog.h:145
LinearProgram(const char *name)
Definition: linprog.h:66
~LinearProgram()
Definition: linprog.h:73
void SetVariableBounds(const std::string &base_name, int var, int op_type, double lb, double ub)
Definition: linprog.h:111
void SetObjective(int objective)
Definition: linprog.h:120
double GetSolution()
Definition: linprog.h:142
int num_vars_
Definition: linprog.h:55
glp_prob * lp_
Definition: linprog.h:57
std::vector< double > ar_
Definition: linprog.h:60
void Solve()
Definition: linprog.h:129
std::vector< double > ToVector()
Definition: linprog.h:151
std::vector< int > ia_
Definition: linprog.h:58
size_t cur_constraint_
Definition: linprog.h:61
void SetConstraintCoeff(int var, double val)
Definition: linprog.h:103
size_t result_
Definition: linprog.h:62
std::vector< int > ja_
Definition: linprog.h:59
int num_constraints_
Definition: linprog.h:56
void AddConstraint(const std::string &base_name, int op_type, double lb, double ub)
Definition: linprog.h:94
void SetObjectiveCoeff(int var, double val)
Definition: linprog.h:123
bool IsOptimal()
Definition: linprog.h:139
void DefineDimension(int num_vars, int num_constraints)
Definition: linprog.h:79
Definition: adapter_utils.cc:35
const size_t kDefaultCoeffs
Definition: linprog.h:48
int Get(int i, int j)
Definition: linprog.h:35
int End(int i)
Definition: linprog.h:41
int nrow_
Definition: linprog.h:28
int ncol_
Definition: linprog.h:29
int Begin(int i)
Definition: linprog.h:38
Array2DIdx(int nrow, int ncol)
Definition: linprog.h:32