c++multidimensional-arraycplexilog

How to define a 3D decision variable in C++ (using CPLEX concert technology)?


I have to define a decision variable a[kij] which must be binary in nature

indices i = {0,1,2,3...9}

j={0,1,2,3...9}

k= {0,1,2}

N_CARTONS=10

N_C=3

have written this much code so far

 // Define a
IloArray<IloNumVarArray> a(env, N_C);

for (k = 0; k < N_C; k++)
{
    a[k] = IloNumVarArray(env, N_C);
    
    for (i = 0; i < N_CARTONS; i++)
    {
        a[k][i] = IloNumVar(env, 0, 1, ILOBOOL);
        
    }
}

How to introduce index 'j'?


Solution

  • You could use the IloArray<> template to build an array with as many dimensions as your compiler will allow.

    As said in technote How do I create and use a multi dimensional IloNumVarArray?

    And full example in CPLEX distribution : facility.cpp

    Or you could also write simply

    int N_CARTONS=10;
    int N_C=3;
    
    range i=0..N_CARTONS-1;
    range j=0..N_CARTONS-1;
    range k=0..N_C-1;
    
    dvar float a[k][i][j];
    

    in OPL and then use the OPL concert C++ API to call OPL from C++