我在c++代码中使用了OPL/Cplex库,
在我的file.mod中,我去掉了这个决策变量: dvar int+ xnodes1..nb_max;
现在我知道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’的转换请求错误:'class IloIntVar‘没有名为'get’的成员
我是一个真正的OPL初学者,提前谢谢!
发布于 2014-10-20 19:43:42
让我引用来自ROSTUDEL的David Gravot
dvar float+ Commande[Items,Periodes];现在,在我的JAVA代码中,我编写了以下代码来访问这些变量的所有解决方案值,如下所示:
IloNumMap commandesMap = opl.getElement("Commande").asNumMap();
for(int i=0;i<params.getNbItems();i++) {
for(int t=0;t<params.getNbPeriodes();t++) {
double solValue = commandesMap.getSub(i+1).get(t+1);
log.info("at item "+(i+1)+" periode "+(t+1)+" : "+solValue );
}
}问候
https://stackoverflow.com/questions/26400220
复制相似问题