Originally posted by: SystemAdmin
I don't see why counting the number of non-zeroes in a row is such a big issue for you.
Assume you have the number of columns in variable 'cols' and the row in 'row':
int cols = ...;
double *row = ...;
int i, nzs = 0;
double *compressed = malloc(sizeof(*compressed) * cols);
if ( !compressed ) {
/* Out of memory. */
...
}
for (i = 0; i < cols; ++i) {
if ( fabs(row[i]) > 0.0 =
compressed[nzs++] = row[i];
}
After that you have the non-zeroes in 'compressed' and the number of non-zeroes in 'nzs'.
I guess most people store their matrices in compressed form and so don't have the issue
of reading a dense matrix.
You can also try to pass the dense row to CPXaddrows(). I think the zeroes in the row
won't do any harm to CPLEX. It is just a big waste of space unless the matrix is dense.
#CPLEXOptimizers#DecisionOptimization