[Top][All Lists]

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

[igraph] Segfault in weighted edge betweenness community detection

From: R N
Subject: [igraph] Segfault in weighted edge betweenness community detection
Date: Wed, 25 Apr 2012 19:00:30 +0300


I'm using igraph-0.6 build 2694-20120421. I'm trying to use the edge
betweenness community detection
function with weighted graphs. I tried out a couple of graphs that I
have, with 1000 vertices and ~2200 edges.
The function crashes on both of them if edge weights are used, but
works if the edge weights are not used.
It seems that it crashes at line 866 of file 'heap.c', in function
Is there some (hopefully small) error in igraph or my negligence in using it?

Here are the crashy graphs:

And here is the full proggy that I used.


#include <igraph.h>
#include <string.h>
#include <stdlib.h>

int cd_edge_betweenness (igraph_t *g, igraph_vector_t *weights,
igraph_vector_t *cm, double *Q)

    igraph_vector_t modularity_eb;
    igraph_vector_t eb, edges;

    igraph_vector_init (&modularity_eb, 0);
    igraph_vector_init (&eb, 0);
    igraph_vector_init (&edges, 0);

        0,      // merges
        0,      // bridges
        &modularity_eb, // modularity
        cm,     //membership
    long int i_eb_max_mod = igraph_vector_which_max (&modularity_eb);
    *Q = VECTOR (modularity_eb)[i_eb_max_mod];

    igraph_vector_destroy (&modularity_eb);
    igraph_vector_destroy (&eb);
    igraph_vector_destroy (&edges);

    return 0;

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

  igraph_t g;
  FILE *ifile, *ofile;
  long int i;
  long int num_vertex, num_edge;
  double Q;

  igraph_vector_t gtypes, vtypes, etypes;
  igraph_strvector_t gnames, vnames, enames;

  if (argc < 3)
    printf ("Usage: %s (IN)in.graphml (OUT)comm_membership_file\n", argv[0]);
    return -1;

  ifile=fopen(argv[1], "r");
  if (ifile == 0)
    printf ("File opening error: %s\n", argv[1]);
    return -1;

  ofile = fopen (argv[2], "w");
  if (ofile == 0)
    printf ("File opening error: %s\n", argv[2]);
    return -1;

  igraph_read_graph_graphml (&g, ifile, 0);

  igraph_vector_init(&gtypes, 0);
  igraph_vector_init(&vtypes, 0);
  igraph_vector_init(&etypes, 0);
  igraph_strvector_init(&gnames, 0);
  igraph_strvector_init(&vnames, 0);
  igraph_strvector_init(&enames, 0);

  igraph_cattribute_list(&g, &gnames, &gtypes, &vnames, &vtypes,
                         &enames, &etypes);

  num_vertex = igraph_vcount (&g);
  num_edge = igraph_ecount (&g);

  igraph_vector_t weights;
  igraph_vector_t cm;   // community membership vector

  igraph_vector_init (&weights, num_edge);
  igraph_vector_init (&cm, num_vertex);

  for (i=0; i < num_edge; i++)
    //printf ("%d: Edge id=%s, weight=%f\n", i, EAS (g, "id", i), EAN
(g, "weight", i));
    VECTOR(weights) [i] = EAN (&g, "weight", i);

  int ires = cd_edge_betweenness (&g, &weights, &cm, &Q);

  fprintf (ofile, "# modularity: Q=%g\n", Q);
  for (i = 0; i < num_vertex; ++i)
    fprintf (ofile, "%d\t", (int) VECTOR (cm) [i]);
  fprintf (ofile, "\n");

  igraph_vector_destroy (&weights);
  igraph_vector_destroy (&cm);

  igraph_vector_destroy (&gtypes);
  igraph_vector_destroy (&vtypes);
  igraph_vector_destroy (&etypes);
  igraph_strvector_destroy (&gnames);
  igraph_strvector_destroy (&vnames);
  igraph_strvector_destroy (&enames);


  return 0;

reply via email to

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