【问题标题】:How to access decision variables: OPL/Cplex && C++如何访问决策变量:OPL/Cplex && C++
【发布时间】:2014-10-16 08:58:13
【问题描述】:

我在我的 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 的初学者, 提前致谢!

【问题讨论】:

    标签: c++ cplex opl


    【解决方案1】:

    您可以在https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014387796&ps=25 找到答案

    让我引用 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  );      
                    }
            }
    

    问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多