[Top][All Lists]

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

Re: [igraph] Question on max id node

From: Richard Geddes
Subject: Re: [igraph] Question on max id node
Date: Mon, 10 Mar 2008 12:13:53 -0400
User-agent: Thunderbird (X11/20080227)


Here's a working fragment of my code that illustrates my results.  Note the commented line for changing the import function.  When I swap out import functions, my output changes.  My original intent was to be able to observe the value (I think it may be called the 'name') with the highest node id,  setting the attribute handler, and using the igraph_read_graph_ncol() import function seemed to be a reasonable way to do this.   The input file format in both cases is ascii text, one edge per line, each edge represented by 2 tab separated integers which represent vertices.  I'm using the 0.6 version. 
#include <cstdio>
#include <string>
#include <iostream>
#include <igraph.h>

using namespace std;

int main(int argc, char* argv[]) {


        igraph_t graph;
        igraph_matrix_t merges;
        igraph_vector_t modularity;
        double maxq(-999999.0), q_i(0);
        int maxq_join(0), max_id(-1);

        igraph_matrix_init(&merges, 1, 2);

        FILE* input_file;
        input_file = fopen(argv[1], "r");

        //  Here's where I can change the import function
        // igraph_read_graph_ncol(&graph, input_file, NULL, true, false, IGRAPH_UNDIRECTED);
        igraph_read_graph_edgelist(&graph, input_file, 0, false);

        igraph_integer_t node_count(igraph_vcount(&graph));
        igraph_integer_t edge_count(igraph_ecount(&graph));

        // ----- Community (fast greedy)
        igraph_community_fastgreedy(&graph, NULL, &merges, &modularity);

        // ----- print initial modularity
        q_i = (double)igraph_vector_e(&modularity, 0);
        printf("%i\t%i\t%f\t%i\n", -1, -1, q_i, 0);

        // ----- print modularity for subsequent joins
        for (int i = 1; i < igraph_vector_size(&modularity) ; i++) {
           q_i = (double)igraph_vector_e(&modularity, i);
           printf("%i\t%i\t%f\t%i\n", (int)igraph_matrix_e(&merges, i-1, 0),
                   (int)igraph_matrix_e(&merges, i-1, 1), q_i, i);
           if (q_i > maxq) {
              maxq = q_i;
              maxq_join = i;



        printf("max node id:\t%i\n", max_id);
        printf("Node count:\t%i\n", (int)node_count);
        printf("Edge count:\t%i\n", (int)edge_count);
        printf("max q:\t%f\n", maxq);
        printf("max q join:\t%i\n", maxq_join);

        return 0;

Gabor Csardi wrote:
Richard, this is quite strange indeed. I've just tried read_graph_ncol
with various graphs and it seems to work fine. Could you send 
me a small file that reproduces the strange results?

Btw, is this the 0.5 version?


On Sun, Mar 09, 2008 at 06:22:42PM -0400, Richard Geddes wrote:
Well, initially I imported an edgelist with

igraph_read_graph_edgelist(&graph, input_file, 0, false);

and ran

igraph_community_fastgreedy(&graph, NULL, &merges, &modularity);

and got normal results.

Then, to get at the graph attributes,� I attached the C attribute handler:


imported the edgelist with:

igraph_read_graph_ncol(&graph, input_file, NULL true, false,

and ran the community function on the graph and I get different results...

when importing with igraph_read_graph_edgelist, 11 nodes and 19 edges are
reported are reported.. which is correct,
however when importing with the igraph_read_graph_ncol function, 19 nodes and
19 edges are reported.

Am I using igraph_read_graph_ncol correctly?


Richard Geddes wrote:

    Thanks.  Looks like what I was looking for.

    Tamas Nepusz wrote:

        Hi Richard,

            Is there a function that provides the value of the largest node id in
            the imported graph?

        If you are using C (I assume you do), try to attach the C attribute
        handler and then read your graph using igraph_read_graph_ncol (this is
        for the NCOL format which is practically a named edge list). This is
        able to store the vertex names used in the NCOL file as a vertex
        attribute. After that, you can scan the attribute values to find the
        largest one.

        See http://cneurocvs.rmki.kfki.hu/igraph/doc-0.5/html/ch09s02.html for
        the usage of the C attribute handler.

    igraph-help mailing list


igraph-help mailing list


reply via email to

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