Originally posted by: SystemAdmin
Answer to question 1: I don't think so. However, if you have to do that frequently it should be easy to write a function that does that.
Answer to question 2: I don't think so either. But it is again easy to define you own operator+ for that purpose if you want to that a lot (untested):
struct SizeMismatchException {
};
IloNumArray2 operator+(IloNumArray2 const& a, IloNumArray2 const& b)
{
if (a.getSize() != b.getSize())
throw SizeMismatchException();
IloNumArray2 c(a.getEnv());
for (IloInt i = 0; i < a.getSize(); ++i) {
IloNumArray const& arow = a[i];
IloNumArray const& brow = b[i];
if (arow.getSize() != brow.getSize()) {
for (IloInt j = 0; j < c.getSize(); ++j)
c[i].end();
c.end();
throw SizeMismatchException();
}
IloNumArray row(c.getEnv());
for (IloInt j = 0; j < arow.getSize(); ++j) {
row.add(arow[j] + brow[j]);
}
c.add(row);
}
return c;
}
A similar operator can be defined for two-dimensional arrays of variables or for vectors.
Answer to question 3: IloNumArray2 is just an IloArray of IloNumArray instances. You can easily append new rows or append elements to rows:
IloNumArray2 A(env);
// Append a row:
// 1. create the new row.
IloNumArray row(env);
...
// 2. append the new row.
A.add(row);
// Append an element to row i:
A[i].add(3.58);
Be careful, IloNumArray2 implements a
dense matrix. If you get large dimensions you may run out of memory. You may want to consider using sparse matrix implementations.
#CPLEXOptimizers#DecisionOptimization