Originally posted by: glebB
I have a matrix of variables and want to access it both by rows and by columns, e.g., for sum() of each row and each column.
I tried to implement this like this:
typedef IloArray<IloNumVarArray> IntVarMatrix;
IntVarMatrix m(env, Nrows);
IntVarMatrix mT(env, Ncols); // transposed
for (int i=0; i<Nrows; ++i)
m[i] = IloNumVarArray(env, Ncols, 0, 1, ILOBOOL);
// FAILS:
for (int j=0; j<Ncols; ++j)
for (int i=0; i<Nrows; ++i)
mT[j].add( m[i][j] );
... which fails. Instead, now I solved th problem as follows:
for (int j=0; j<Ncols; ++j)
mT[j] = IloNumVarArray(env, Nrows, 0, 1, ILOBOOL);
for (int j=0; j<Ncols; ++j)
for (int i=0; i<Nrows; ++i)
model.add ( mT[j][i] == m[i][j] );
Is there a more efficient way?
#CPLEXOptimizers#DecisionOptimization