我在我的 c++ 代码中使用 OPL/Cplex 库,
在我的 file.mod 中,我标记了这个决策变量: dvar int+ x[nodes][nodes][1..nb_max][lambdas];
现在我那个 Cplex 解决了我成功恢复目标值的模型如下:
try {
IloCplex cplex(env);
cplex.setOut(env.getNullStream());
IloOplErrorHandler handler(env,cout);
IloOplModelSource modelSource(env, "file.mod");
IloOplSettings settings(env,handler);
IloOplModelDefinition def(modelSource,settings);
IloOplModel opl(def,cplex);
IloOplDataSource dataSource(env, "file2.dat");
opl.addDataSource(dataSource);
opl.generate();
if ( cplex.solve() ) {
cout<< opl.getCplex().getObjValue()<< endl;
}
}
我的问题是如何恢复多维数组“x”?我试过了
IloIntVar x = opl.getElement("x").asIntVar; IloIntVar xvar =x.get(0);//第一项
但出现以下错误!
错误:从“”转换为非标量类型“IloIntVar”请求错误:“IloIntVar 类”没有名为“get”的成员
我真的是OPL的初学者,在此先感谢!