bug-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-glpk] API: glp_get_num_rows


From: Vijay Patil
Subject: [Bug-glpk] API: glp_get_num_rows
Date: Mon, 11 Aug 2008 12:17:57 +0530

Hi,

I am trying to access constraint coefficient matrix. When I use function glp_get_num_rows, I am getting unexpected number of rows.
In model assign.mod (from standard glpk examples), there are 8 elements in each of set I and set J. So total number of constraints should be 16. But function glp_get_num_rows returns 17. Number of columns are as expected (64).

It seems that, glpk is counting obj. function as a constraint. Is this intentional behaviour? But there is separate function glp_get_obj_func for accessing obj. fun. coefficients.

Am I missing something obvious? I am using glpk 4.29, which I compiled myself. For some reason, instead of installing glpk, I copied libglpk.a and statically linked with my application (code below).

Whenever I get chance, I will try using some other version of the glpk and test against it.

------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "glpk.h"

int main()
{
    glp_prob * lp = NULL;
    int row_cnt = 0, col_cnt = 0, row_nz_cnt;
    int ri, ci;

    lp = lpx_read_model("assign.mod", NULL, NULL);
    assert(lp != NULL);

    row_cnt = glp_get_num_rows(lp);
    col_cnt = glp_get_num_cols(lp);
    printf("row_cnt = %d, col_cnt = %d\n", row_cnt, col_cnt);

    /* Access all matrix coefficients and print. */

    /* Iterate over all rows. ri = 1 to row_cnt. */
    for(ri = 1; ri <= row_cnt; ri++) {

        int * ind = NULL;
        double * val = NULL;

        /* Non-zero coefficient count in the row. */
        row_nz_cnt = glp_get_mat_row(lp, ri, NULL, NULL);
        assert(row_nz_cnt != 0);

        ind = (int*) calloc(row_nz_cnt + 1, sizeof(int));
        val = (double*) calloc(row_nz_cnt + 1, sizeof(double));

        glp_get_mat_row(lp, ri, ind, val);

        /* Print coefficient/value. */
        for(ci = 1; ci <= row_nz_cnt; ci++)
            printf("%5.1lf ", val[ci]);
        printf("\n");

        free(ind); ind = NULL;
        free(val); val = NULL;
    }  

    glp_delete_prob(lp);
    return 0;

}
         
-----------
address@hidden:~/projects/matrix$ ./test
Reading model section from assign.mod...
Reading data section from assign.mod...
77 lines were read
Generating phi...
Generating psi...
Generating obj...
Model has been successfully generated
row_cnt = 17, col_cnt = 64
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
  1.0   1.0   1.0   1.0   1.0   1.0   1.0   1.0
 43.0  37.0  31.0  45.0  17.0   5.0  20.0  26.0  24.0  22.0  40.0  34.0   3.0  38.0  34.0  16.0  46.0  28.0  16.0  14.0  15.0  39.0  19.0  42.0  48.0  12.0  34.0  24.0  18.0  45.0   6.0  21.0  40.0  11.0  22.0  12.0   8.0   7.0  54.0  34.0  37.0  13.0  21.0  26.0  36.0  13.0  32.0  35.0   8.0   4.0  11.0  40.0  41.0  25.0  36.0  12.0  11.0  22.0  26.0   8.0  12.0  20.0  21.0  13.0


--
Vijay Patil

reply via email to

[Prev in Thread] Current Thread [Next in Thread]