igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Question on max id node


From: Gabor Csardi
Subject: Re: [igraph] Question on max id node
Date: Mon, 10 Mar 2008 21:49:30 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

Richard, your program works fine for me. If i use it on this small 
graph:

1               2
2               3
2               4
3               4
4               5
1               5

then reading with 'ncol' results 5 vertices, which is correct ('1', '2',
'3', '4' and '5'), remember that 'ncol' means symbolic vertex names,
and reading as an edge list gives 6 vertices, which is also correct, 
vertices 0-6.

Please send me a file that breaks it. Thanks.

G.

On Mon, Mar 10, 2008 at 12:13:53PM -0400, Richard Geddes wrote:
> G,
> 
> 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_i_set_attribute_table(&igraph_cattribute_table);
> 
>         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_vector_init(&modularity,0);
>         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);
>         fclose(input_file);
> 
>         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;
>            }
>         }
> 
>         igraph_vector_destroy(&modularity);
>         igraph_matrix_destroy(&merges);
> 
>         igraph_destroy(&graph);
> 
>         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?
> 
>     Thanks,
>     G.
> 
>     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:
> 
>         igraph_i_set_attribute_table(&igraph_cattribute_table);
> 
>         imported the edgelist with:
> 
>         igraph_read_graph_ncol(&graph, input_file, NULL true, false,
>         IGRAPH_UNDIRECTED);
> 
>         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?
> 
>         Thanks
>         Richard
> 
>         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
>             address@hidden
>             http://lists.nongnu.org/mailman/listinfo/igraph-help
> 
> 
> 
> 
> 
> 
> 
> 
> 
>         _______________________________________________
>         igraph-help mailing list
>         address@hidden
>         http://lists.nongnu.org/mailman/listinfo/igraph-help
> 
> 
> 
> 
> 
> 
> 

> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help


-- 
Csardi Gabor <address@hidden>    UNIL DGM




reply via email to

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