I've just begun using GLPK (version 4.8), and I notice that you give a "zero element not allowed" in glplpx1.c if lpx_set_mat_row, etcetera are called with some zero matrix entries.

In many cases, however, it is convenient for the user not to have to check whether a matrix element is zero before calling GLPK, and it seems to me that this error is unnecessary. In particular, inside lpx_set_mat_row etcetera you could simply check for zero matrix elements and skip them.

I've attached a patch to accomplish this.

Cordially,
Steven G. Johnson

--- glplpx1.c.orig      Tue May 24 18:16:03 2005
+++ glplpx1.c   Tue May 24 18:20:36 2005
@@ -687,8 +687,8 @@
 -- Column indices and numeric values of new row elements must be placed
 -- in locations ind[1], ..., ind[len] and val[1], ..., val[len], where
 -- 0 <= len <= n is new length of i-th row, n is the current number of
--- columns in the problem object. Should note that zero elements as well
--- as elements with identical column indices are not allowed.
+-- columns in the problem object. We should note that
+-- elements with identical column indices are not allowed.
 --
 -- If the parameter len is zero, the both parameters ind and val can be
 -- specified as NULL. */
@@ -728,6 +728,7 @@
             i, len);
       for (k = 1; k <= len; k++)
       {  /* take number j of corresponding column */
+        if (val[k] == 0.0) continue;
          j = ind[k];
          /* obtain pointer to j-th column */
          if (!(1 <= j && j <= lp->n))
@@ -743,9 +744,6 @@
          aij = dmp_get_atom(lp->aij_pool);
          aij->row = row;
          aij->col = col;
-         if (val[k] == 0.0)
-            fault("lpx_set_mat_row: i = %d; ind[%d] = %d; zero element "
-               "not allowed", i, k, j);
          aij->val = val[k];
          /* add the new element to the beginning of i-th row and j-th
             column lists */
@@ -783,8 +781,8 @@
 -- Row indices and numeric values of new column elements must be placed
 -- in locations ind[1], ..., ind[len] and val[1], ..., val[len], where
 -- 0 <= len <= m is new length of j-th column, m is the current number
--- of rows in the problem object. Should note that zero elements as well
--- as elements with identical row indices are not allowed.
+-- of rows in the problem object. We should note that
+-- elements with identical row indices are not allowed.
 --
 -- If the parameter len is zero, the both parameters ind and val can be
 -- specified as NULL. */
@@ -825,6 +823,7 @@
             "h", j, len);
       for (k = 1; k <= len; k++)
       {  /* take number i of corresponding row */
+        if (val[k] == 0.0) continue;
          i = ind[k];
          /* obtain pointer to i-th row */
          if (!(1 <= i && i <= lp->m))
@@ -840,9 +839,6 @@
          aij = dmp_get_atom(lp->aij_pool);
          aij->row = row;
          aij->col = col;
-         if (val[k] == 0.0)
-            fault("lpx_set_mat_col: j = %d; ind[%d] = %d; zero element "
-               "not allowed", j, k, i);
          aij->val = val[k];
          /* add the new element to the beginning of i-th row and j-th
             column lists */
@@ -882,9 +878,9 @@
 -- be specified as triplets (ia[k], ja[k], ar[k]) for k = 1, ..., ne,
 -- where ia[k] is the row index, ja[k] is the column index, ar[k] is a
 -- numeric value of corresponding constraint coefficient. The parameter
--- ne specifies the total number of (non-zero) elements in the matrix
--- to be loaded. Note that coefficients with identical indices as well
--- as zero coefficients are not allowed.
+-- ne specifies the total number of elements in the matrix
+-- to be loaded. Note that coefficients with identical indices
+-- are not allowed.
 --
 -- If the parameter ne is zero, the parameters ia, ja, and ar can be
 -- specified as NULL. */
@@ -905,6 +901,7 @@
             "ents", ne);
       for (k = 1; k <= ne; k++)
       {  /* take indices of new element */
+        if (ar[k] == 0.0) continue;
          i = ia[k], j = ja[k];
          /* obtain pointer to i-th row */
          if (!(1 <= i && i <= lp->m))
@@ -920,9 +917,6 @@
          aij = dmp_get_atom(lp->aij_pool);
          aij->row = row;
          aij->col = col;
-         if (ar[k] == 0.0)
-            fault("lpx_load_matrix: ar[%d] = 0; zero element not allowe"
-               "d", k);
          aij->val = ar[k];
          /* add the new element to the beginning of i-th row list */
          aij->r_prev = NULL;
_______________________________________________
Bug-glpk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-glpk

Reply via email to