0
votes

I am using OPL/Cplex libraries in my c++ code,

In my file.mod I decalred this decision variable: dvar int+ x[nodes][nodes][1..nb_max][lambdas];

Now I that Cplex solved the model I successfully recuperate the objective value as follows:

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

My question is how can I recuperate the multidimentional array "x"? I tried with

IloIntVar x = opl.getElement("x").asIntVar; IloIntVar xvar =x.get(0);//first item

but the following errors occur!

error: conversion from '' to non-scalar type 'IloIntVar' requested error: 'class IloIntVar' has no member named 'get'

I am really a beginner in OPL, Thanks in advance!

1

1 Answers

0
votes

you have an answer to this at https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014387796&ps=25

Let me quote David Gravot from ROSTUDEL

dvar float+ Commande[Items,Periodes];

Now, in my JAVA code, I wrote the following to access all solution values for these variables as following :

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

regards