help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] Visualize Matrix A (in Ax = b)


From: Vijay Patil
Subject: Re: [Help-glpk] Visualize Matrix A (in Ax = b)
Date: Tue, 12 Aug 2008 18:22:50 +0530


On Tue, Aug 12, 2008 at 12:49 AM, Andrew Makhorin <address@hidden> wrote:
> Few days back, there was a discussion on the mailing list about
> sparse and dense constraint coefficient matrices. I thought it would
> be nice to be able to visualize matrix A and "see" how much sparse it
> is. This might help verify, understand and debug LP/MIP models created
> using MathProg.

Glpk includes some internal routines for such purpose (see glpspm.c),
in particular, spm_show_mat to write the sparse matrix pattern in bitmap
format. However, I do not know if it is reasonable to carry out such
routines on api level.


I just played around these functions, seems to be working fine. For small matrices the BMP images would be too small. For 10 X 10 matrix, it would 10 X 10 pixel image.

Did you create these functions and structures like SPM to debug in initial stages of GLPK development?

--------------------------------------------------------------------------------
/* Matrix Visualisation. Create 300x300 pixel BMP file.
 * Vijay Patil
 * */

#include<stdio.h>
#include<stdlib.h>
#include "glpspm.h"

#define ROWCNT 300
#define COLCNT 300

int main(void)
{
    SPM * matrix = NULL;   
    int ri, ci;

    matrix = spm_create_mat(ROWCNT, COLCNT);
    for(ri = 1; ri <= ROWCNT; ri++) {
        for(ci = 1; ci <= COLCNT; ci++) {
            if(ri == ci)
                spm_new_elem(matrix, ri, ci, 1.0); // WHITE
            else if(ri == COLCNT - ci)
                spm_new_elem(matrix, ri, ci, -1.0); // CYAN
            else if(ri == ROWCNT/2)
                spm_new_elem(matrix, ri, ci, 0.0); // GREEN

            // Other cells should be BLACK
        }
    }

    spm_show_mat(matrix, "matrix.bmp");
    system("gimp -s matrix.bmp &");

    spm_delete_mat(matrix);

    return 0;
}



--
Vijay Patil

Attachment: matrix.bmp
Description: Windows bitmap


reply via email to

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