help-glpk
[Top][All Lists]
Advanced

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

[Help-glpk] column index inconsistency


From: Somsubhra Sharangi
Subject: [Help-glpk] column index inconsistency
Date: Sun, 14 Feb 2010 16:57:32 -0800

Hi,

When I try to set and get the columns of a row the columns index changes.
In the attached code i am adding a row with 4 columns and then retrieving the same.
For the code attached below, the output looks like :

3.0*x1 5.0*x2 7.0*x3 9.0*x4
9.0*x4 7.0*x3 5.0*x2 3.0*x1

While the <index, coeff> pairs are same the contents of the input and output array has changed.
I am assuming such a basic thing is probably not a bug.
What is the proper way to use the API so that my set and get arrays contain the same value.


regards,
Som
=======================================
    int N = 4;
    glp_prob *primal=glp_create_prob();
    glp_add_cols(primal,N);
    double row_cf[] = {3.0,5.0,7.0,9.0};
    int set_indx[N+1],get_indx[N+1];
    double set_coef[N+1],get_coef[N+1];
   
    for(int i=0,j=1;i<N;i++,j++){
        set_indx[j]=j;
        set_coef[j] = row_cf[i];
    }

    for(int c=1;c<=N;c++)
        printf("%3.1f*x%d ",set_coef[c],set_indx[c]);   
    printf("\n");

    int next_row=glp_add_rows(primal,1);
    glp_set_mat_row(primal, next_row, N, set_indx, set_coef);

    glp_get_mat_row(primal, next_row, get_indx, get_coef);
   
    for(int c=1;c<=N;c++)
        printf("%3.1f*x%d ",get_coef[c],get_indx[c]);
    printf("\n");
=====================================================

reply via email to

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