使用Cplex进行双值排序

时间:2014-08-01 11:40:09

标签: c++ cplex

我正在尝试使用getDuals()获取原始LP的双值向量。我不知道双变量将以什么顺序返回。我在Java中找到了一个使用HashMap的例子。我想知道在使用C ++时是否有任何解决方案。

1 个答案:

答案 0 :(得分:1)

IloCplex :: getDuals期望IloRangeArray作为输入参数和IloNumArray。作为输出参数。 IloRangeArray是ILOG的自定义数组类型。

IloEnv env;
IloModel m(env);

int num_vars = ...;
IloRangeArray constraints(env, num_vars);
//  ...
// populate the constraints
// ...
m.add(constraints);
IloCplex cplex(m);
int retval cplex.solve();
// verify that cplex found a solution
if (!retval) //  ...

IloNumVarArray duals(env);
cplex.getDuals(duals, constraints);

IloRangeArray是ILOG Concert的自定义数组类型,有些感觉有些dated。您可以将IloRange对象存储在任何数据结构中。在这种情况下,要获得双重功能,您需要使用IloCplex::getDual功能。例如,如果您使用了矢量

IloEnv env;
IloModel m(env);

int num_vars = ...;
std::vector<IloRange> constraints(env, num_vars);
//  ...
// populate the constraints and add them to the model;

for (IloRange constr : constraints) 
   m.add(constr);
IloCplex cplex(m);
int retval cplex.solve();
// verify that cplex found a solution
if (!retval)  //  ...


vector<double> duals;
for (IloRange constr: constraints)
    duals.push_back(cplex.getDual(constr);

IloRange对象是句柄,因此可以像智能指针一样对待并存储在大多数标准数据结构中。