//添加变量思路
add_var_XX(IloModel f_model, IloNumVarArray f_var, IloRangeArray f_cons, data_input *f_data);
//添加变量
{
//获取环境
IloEnv f_env = f_model.getEnv();
//向环境中添加变量
//IloNumVar(const IloEnv env, IloNum lb=0, IloNum ub=IloInfinity, IloNumVar::Type type=Float, const char * name=0)
f_var.add(IloNumVar(f_env, lp, up, ILOFLOAT));
//统计当前变量位置,采用分段数组,统计位置,个数一个意思
num_cal(XX, current_num, start_index, m_var_num);
}
//添加约束条件思路
add_con_dtm_powerbalance(IloModel f_model, IloNumVarArray f_var, IloRangeArray f_cons, data_input *f_data);
{
//获取环境变量
IloEnv f_env = f_model.getEnv();
//此处往往需要统计出变量个数,方便下一步的添加
//定义表达式
IloExpr f_expr1(f_env);
//表达式的表述
for (index_j = 0; index_j < _num; index_j++)
{
f_expr1 += f_var[i];//从变量中提取
}
//范围
//IloRange(const IloEnv env, IloNum lhs, const IloNumExprArg expr, IloNum rhs=IloInfinity, const char * name=0)
IloRange temp_range1(f_env, lp, f_expr1, up);
//添加约束
f_cons.add(temp_range1);
//模型添加约束
f_model.add(f_cons);
}
<pre name="code" class="cpp">//定义cplex 对象
IloCplex cplex(env);
//set_cplex_parameters(cplex, ptrdata);
//gen_callback_cuts(env, cplex, var, ptrdata, ptrluc);
//向cplex 对象中添加模型
cplex.extract(mip_model);
//cplex 调用求解函数
cplex.solve();
//获得结果
IloNumArray vals(env);
cplex.getValues(vals, var);
void set_cplex_parameters(IloCplex f_cplex, data_input *f_data)
{
// setting parameters
f_cplex.setParam(IloCplex::EpGap, ii);
f_cplex.setParam(IloCplex::EpInt, ii);
f_cplex.setParam(IloCplex::TiLim, ii);
f_cplex.setParam(IloCplex::AggInd, 0);
f_cplex.setParam(IloCplex::AggInd, 0);
f_cplex.setParam(IloCplex::Threads, 1);
f_cplex.setParam(IloCplex::MIPSearch, IloCplex::Traditional);
}