0

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' への変換が要求されました エラー: 'class IloIntVar' には 'get' という名前のメンバーがありません

私は OPL の初心者です。よろしくお願いします。

4

1 に答える 1

0

これに対する回答はhttps://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014387796&ps=25にあります。

ROSTUDEL の David Gravo 氏の言葉を引用させてください。

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  );      
                }
        }

よろしく

于 2014-10-20T11:43:42.413 に答える