Esempio n. 1
0
igraph_bool_t check_ev(const igraph_matrix_t *A, 
		       const igraph_vector_t *values_real,
		       const igraph_vector_t *values_imag,
		       const igraph_matrix_t *vectors_left, 
		       const igraph_matrix_t *vectors_right, 
		       igraph_real_t tol) {

  int n=igraph_matrix_nrow(A);
  igraph_vector_t v_real, v_imag;
  igraph_vector_t AV_real, AV_imag, lv_real, lv_imag;
  igraph_vector_t null;
  int i;
  
  if (igraph_matrix_ncol(A)             != n) { return 1; }
  if (igraph_vector_size(values_real)   != n) { return 1; }
  if (igraph_vector_size(values_imag)   != n) { return 1; }
  if (igraph_matrix_nrow(vectors_left)  != n) { return 1; }
  if (igraph_matrix_ncol(vectors_left)  != n) { return 1; }
  if (igraph_matrix_nrow(vectors_right) != n) { return 1; }
  if (igraph_matrix_ncol(vectors_right) != n) { return 1; }

  igraph_vector_init(&AV_real, n);
  igraph_vector_init(&AV_imag, n);
  igraph_vector_init(&lv_real, n);
  igraph_vector_init(&lv_imag, n);
  igraph_vector_init(&null, n);
  igraph_vector_null(&null);

  for (i=0; i<n; i++) {
    if (VECTOR(*values_imag)[i]==0.0) {
      igraph_vector_view(&v_real, &MATRIX(*vectors_right, 0, i), n);
      igraph_vector_view(&v_imag, VECTOR(null), n);
    } else if (VECTOR(*values_imag)[i] > 0.0) {
      igraph_vector_view(&v_real, &MATRIX(*vectors_right, 0, i), n);
      igraph_vector_view(&v_imag, &MATRIX(*vectors_right, 0, i+1), n);
    } else if (VECTOR(*values_imag)[i] < 0.0) {
      igraph_vector_view(&v_real, &MATRIX(*vectors_right, 0, i-1), n);
      igraph_vector_view(&v_imag, &MATRIX(*vectors_right, 0, i), n);
      igraph_vector_scale(&v_imag, -1.0);
    }
    real_cplx_mult(A, &v_real, &v_imag, &AV_real, &AV_imag);
    sc_cplx_cplx_mult(VECTOR(*values_real)[i], VECTOR(*values_imag)[i],
		      &v_real, &v_imag, &lv_real, &lv_imag);
    
    if (igraph_vector_maxdifference(&AV_real, &lv_real) > tol ||
	igraph_vector_maxdifference(&AV_imag, &lv_imag) > tol) {
      igraph_vector_print(&AV_real); igraph_vector_print(&AV_imag);
      igraph_vector_print(&lv_real); igraph_vector_print(&lv_imag);      
      return 1;
    }
  }

  igraph_vector_destroy(&null);
  igraph_vector_destroy(&AV_imag);
  igraph_vector_destroy(&AV_real);
  igraph_vector_destroy(&lv_imag);
  igraph_vector_destroy(&lv_real);
  
  return 0;
}
Esempio n. 2
0
int main() {
  
  igraph_t g;
  igraph_vector_t v1, v2;
  int ret;
  
  /* simple use */
  igraph_vector_init(&v1, 8);
  VECTOR(v1)[0]=0; VECTOR(v1)[1]=1;
  VECTOR(v1)[2]=1; VECTOR(v1)[3]=2;
  VECTOR(v1)[4]=2; VECTOR(v1)[5]=3;
  VECTOR(v1)[6]=2; VECTOR(v1)[7]=2;
  igraph_create(&g, &v1, 0, 0);
  if (igraph_vcount(&g) != 4) {
    return 1;
  }
  igraph_vector_init(&v2, 0);
  igraph_get_edgelist(&g, &v2, 0);
  igraph_vector_sort(&v1);
  igraph_vector_sort(&v2);
  if (!igraph_vector_all_e(&v1, &v2)) {
    return 2;
  }
  igraph_destroy(&g);
  
  /* higher number of vertices */
  igraph_create(&g, &v1, 10, 0);
  if (igraph_vcount(&g) != 10) {
    return 1;
  }
  igraph_get_edgelist(&g, &v2, 0);
  igraph_vector_sort(&v1);
  igraph_vector_sort(&v2);
  if (!igraph_vector_all_e(&v1, &v2)) {
    return 3;
  }
  igraph_destroy(&g);

  /* error: IGRAPH_EINVEVECTOR */
  igraph_set_error_handler(igraph_error_handler_ignore);
  igraph_vector_resize(&v1, 9);
  VECTOR(v1)[8]=0;
  ret=igraph_create(&g, &v1, 0, 0);
  if (ret != IGRAPH_EINVEVECTOR) {
    return 4;
  }
  
  /* error: IGRAPH_EINVVID */
  igraph_vector_resize(&v1, 8);
  VECTOR(v1)[7]=-1;
  ret=igraph_create(&g, &v1, 10, 1);
  if (ret != IGRAPH_EINVVID) {
    return 5;
  }
  igraph_vector_destroy(&v1);
  igraph_vector_destroy(&v2);

  return 0;
}
Bitvector GraphRepresentation::calculateFID(string &source, string &destination) {
    int vertex_id;
    Bitvector result(dm->fid_len * 8);
    igraph_vs_t vs;
    igraph_vector_ptr_t res;
    igraph_vector_t to_vector;
    igraph_vector_t *temp_v;
    igraph_integer_t eid;

    /*find the vertex id in the reverse index*/
    int from = (*reverse_node_index.find(source)).second;
    igraph_vector_init(&to_vector, 1);
    VECTOR(to_vector)[0] = (*reverse_node_index.find(destination)).second;
    /*initialize the sequence*/
    igraph_vs_vector(&vs, &to_vector);
    /*initialize the vector that contains pointers*/
    igraph_vector_ptr_init(&res, 1);
    temp_v = (igraph_vector_t *) VECTOR(res)[0];
    temp_v = (igraph_vector_t *) malloc(sizeof (igraph_vector_t));
    VECTOR(res)[0] = temp_v;
    igraph_vector_init(temp_v, 1);
    /*run the shortest path algorithm from "from"*/
    igraph_get_shortest_paths(&igraph, &res, from, vs, IGRAPH_OUT);
    /*check the shortest path to each destination*/
    temp_v = (igraph_vector_t *) VECTOR(res)[0];
    //click_chatter("Shortest path from %s to %s", igraph_cattribute_VAS(&graph, "NODEID", from), igraph_cattribute_VAS(&graph, "NODEID", VECTOR(*temp_v)[igraph_vector_size(temp_v) - 1]));

    /*now let's "or" the FIDs for each link in the shortest path*/
    for (int j = 0; j < igraph_vector_size(temp_v) - 1; j++) {
        igraph_get_eid(&igraph, &eid, VECTOR(*temp_v)[j], VECTOR(*temp_v)[j + 1], true);
        //click_chatter("node %s -> node %s", igraph_cattribute_VAS(&graph, "NODEID", VECTOR(*temp_v)[j]), igraph_cattribute_VAS(&graph, "NODEID", VECTOR(*temp_v)[j + 1]));
        //click_chatter("link: %s", igraph_cattribute_EAS(&graph, "LID", eid));
        string LID(igraph_cattribute_EAS(&igraph, "LID", eid), dm->fid_len * 8);
        for (int k = 0; k < dm->fid_len * 8; k++) {
            if (LID[k] == '1') {
                (result)[ dm->fid_len * 8 - k - 1].operator |=(true);
            }
        }
        //click_chatter("FID of the shortest path: %s", result.to_string().c_str());
    }
    /*now for all destinations "or" the internal linkID*/
    vertex_id = (*reverse_node_index.find(destination)).second;
    string iLID(igraph_cattribute_VAS(&igraph, "iLID", vertex_id));
    //click_chatter("internal link for node %s: %s", igraph_cattribute_VAS(&graph, "NODEID", vertex_id), iLID.c_str());
    for (int k = 0; k < dm->fid_len * 8; k++) {
        if (iLID[k] == '1') {
            (result)[ dm->fid_len * 8 - k - 1].operator |=(true);
        }
    }

    igraph_vector_destroy((igraph_vector_t *) VECTOR(res)[0]);

    igraph_vector_destroy(&to_vector);
    igraph_vector_ptr_destroy_all(&res);
    igraph_vs_destroy(&vs);

    return result;
}
int main() {
  
  igraph_t g;
  igraph_vector_t v, weights;
  long int i;
  igraph_real_t value;
  igraph_arpack_options_t options;
  
  igraph_star(&g, 100, IGRAPH_STAR_UNDIRECTED, 0);

  igraph_arpack_options_init(&options);
  igraph_vector_init(&v, 0);
  igraph_eigenvector_centrality(&g, &v, &value, /*directed=*/ 0, 
				/*scale=*/0, /*weights=*/0, 
				&options);

  if (options.info != 0) {
    return 1;
  }

  for (i=0; i<igraph_vector_size(&v); i++) {
    printf(" %.3f", fabs(VECTOR(v)[i]));
  }
  printf("\n");
  
  igraph_destroy(&g);

  /* Special cases: check for empty graph */
  igraph_empty(&g, 10, 0);
  igraph_eigenvector_centrality(&g, &v, &value, 0, 0, 0, &options);
  if (value != 0.0) {
    return 1;
  }
  for (i=0; i<igraph_vector_size(&v); i++) {
    printf(" %.2f", fabs(VECTOR(v)[i]));
  }
  printf("\n");
  igraph_destroy(&g);

  /* Special cases: check for full graph, zero weights */
  igraph_full(&g, 10, 0, 0);
  igraph_vector_init(&weights, 45);
  igraph_vector_fill(&weights, 0);
  igraph_eigenvector_centrality(&g, &v, &value, 0, 0, &weights, &options);
  igraph_vector_destroy(&weights);
  if (value != 0.0) {
    return 2;
  }
  for (i=0; i<igraph_vector_size(&v); i++) {
    printf(" %.2f", fabs(VECTOR(v)[i]));
  }
  printf("\n");
  igraph_destroy(&g);

  igraph_vector_destroy(&v);

  return 0;
}
Esempio n. 5
0
int main() {
  igraph_t karate;
  igraph_vector_t parents, weights;

  igraph_rng_seed(igraph_rng_default(), 42);
  
  igraph_small(&karate, 34, IGRAPH_UNDIRECTED,
               0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,10,0,11,0,12,0,13,
               0,17,0,19,0,21,0,31,
               1,2,1,3,1,7,1,13,1,17,1,19,1,21,1,30,
               2,3,2,7,2,27,2,28,2,32,2,9,2,8,2,13,
               3,7,3,12,3,13,
               4,6,4,10,
               5,6,5,10,5,16,
               6,16,
               8,30,8,32,8,33,
               9,33,
               13,33,
               14,32,14,33,
               15,32,15,33,
               18,32,18,33,
               19,33,
               20,32,20,33,
               22,32,22,33,
               23,25,23,27,23,32,23,33,23,29,
               24,25,24,27,24,31,
               25,31,
               26,29,26,33,
               27,33,
               28,31,28,33,
               29,32,29,33,
               30,32,30,33,
               31,32,31,33,
               32,33,
               -1);
  
  igraph_vector_init(&parents, 0);
  igraph_vector_init(&weights, 0);
  igraph_hrg_consensus(&karate, &parents, &weights, /* hrg= */ 0, 
		       /* start= */ 0, /* num_samples= */ 100);

  /* Check */
  igraph_vector_print(&parents);
  igraph_vector_print(&weights);

  igraph_vector_destroy(&parents);
  igraph_vector_destroy(&weights);
  igraph_destroy(&karate);

#ifdef __APPLE__
  return 0;
#else
  return 77;
#endif
}
Esempio n. 6
0
VALUE cIGraph_community_edge_betweenness(VALUE self, VALUE directed){

  igraph_t *graph;

  igraph_vector_t result_vec;
  igraph_vector_t edge_betw_vec;
  igraph_vector_t bridges_vec;
  igraph_matrix_t *merges = malloc(sizeof(igraph_matrix_t));
  igraph_bool_t   directed_b = 0;

  int i;

  VALUE result_a, edge_betw_a, bridges_a, res;

  if(directed)
    directed_b = 1;

  Data_Get_Struct(self, igraph_t, graph);

  igraph_matrix_init(merges,0,0);
  igraph_vector_init(&result_vec,0);
  igraph_vector_init(&edge_betw_vec,0);
  igraph_vector_init(&bridges_vec,0);

  igraph_community_edge_betweenness(graph,
				    &result_vec,&edge_betw_vec,
				    merges,&bridges_vec,directed_b);

  result_a = rb_ary_new();
  for(i=0;i<igraph_vector_size(&result_vec);i++){
    rb_ary_push(result_a,INT2NUM(VECTOR(result_vec)[i]));
  }
  edge_betw_a = rb_ary_new();
  for(i=0;i<igraph_vector_size(&edge_betw_vec);i++){
    rb_ary_push(edge_betw_a,INT2NUM(VECTOR(edge_betw_vec)[i]));
  }
  bridges_a = rb_ary_new();
  for(i=0;i<igraph_vector_size(&bridges_vec);i++){
    rb_ary_push(bridges_a,INT2NUM(VECTOR(bridges_vec)[i]));
  }

  res = rb_ary_new3(4,
		    Data_Wrap_Struct(cIGraphMatrix, 0, 
				     cIGraph_matrix_free, merges),
		    result_a, edge_betw_a, bridges_a);

  igraph_vector_destroy(&result_vec);
  igraph_vector_destroy(&edge_betw_vec);
  igraph_vector_destroy(&bridges_vec);

  return res;

}
int main() {
  
  igraph_t graph, ring;
  igraph_vector_t order,order_out, father,dist;
  long int i;
  
  igraph_ring(&ring, 10, /*directed=*/ 0, /*mutual=*/ 0, /*circular=*/ 1);
  igraph_disjoint_union(&graph, &ring, &ring);
  igraph_destroy(&ring);
  
  igraph_vector_init(&order, 0);
  igraph_vector_init(&order_out, 0);
  igraph_vector_init(&father, 0);
  igraph_vector_init(&dist, 0);
  
  igraph_dfsd(&graph, /*root=*/0, /*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1,&order,&order_out,&father,&dist, 
       /*in_callback=*/ 0,/*out_callback*/0, /*extra=*/ 0);
  
  igraph_vector_print(&order);
  igraph_vector_print(&order_out);
  igraph_vector_print(&father);
  igraph_vector_print(&dist);

  igraph_vector_destroy(&order);
  igraph_vector_destroy(&order_out);
  igraph_vector_destroy(&father);
  igraph_vector_destroy(&dist);

  /* Test the callback */

  igraph_dfsd(&graph, /*root=*/ 0,/*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1,0, 0, 0, 0,&dfs_callback,0, 0);
  printf("\n");
  
  igraph_dfsd(&graph, /*root=*/ 0,/*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1,0, 0, 0, 0,0,&dfs_callback, 0);
  printf("\n");
  /* Test different roots */

  igraph_dfsd(&graph, /*root=*/ 2,/*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1, 0, 0, 0, 0,&dfs_callback,0, 0);
  printf("\n");

  igraph_dfsd(&graph, /*root=*/ 2,/*neimode=*/ IGRAPH_OUT, 
       /*unreachable=*/ 1, 0, 0, 0, 0,0,&dfs_callback,0);
  printf("\n");
  igraph_destroy(&graph);
  
  return 0;
}
Esempio n. 8
0
/* call-seq:
 *   graph.constraint(vs,weights) -> Array
 *
 * Returns an Array of constraint measures for the vertices 
 * in the graph. Weights is an Array of weight measures for each edge.
 */
VALUE cIGraph_constraint(int argc, VALUE *argv, VALUE self){

  igraph_t *graph;
  igraph_vs_t vids;
  igraph_vector_t vidv;
  igraph_vector_t res;
  igraph_vector_t wght;
  int i;
  VALUE constraints = rb_ary_new();
  VALUE vs, weights;

  rb_scan_args(argc,argv,"11",&vs, &weights);

  //vector to hold the results of the degree calculations
  IGRAPH_FINALLY(igraph_vector_destroy, &res);
  IGRAPH_FINALLY(igraph_vector_destroy, &wght);
  IGRAPH_FINALLY(igraph_vector_destroy, &vidv);
  IGRAPH_CHECK(igraph_vector_init(&res,0));
  IGRAPH_CHECK(igraph_vector_init(&wght,0));

  Data_Get_Struct(self, igraph_t, graph);

  //Convert an array of vertices to a vector of vertex ids
  IGRAPH_CHECK(igraph_vector_init_int(&vidv,0));
  cIGraph_vertex_arr_to_id_vec(self,vs,&vidv);
  //create vertex selector from the vecotr of ids
  igraph_vs_vector(&vids,&vidv);

  if(weights == Qnil){
    IGRAPH_CHECK(igraph_constraint(graph,&res,vids,NULL));
  } else {
    for(i=0;i<RARRAY_LEN(weights);i++){
      IGRAPH_CHECK(igraph_vector_push_back(&wght,NUM2DBL(RARRAY_PTR(weights)[i])));
    }
    IGRAPH_CHECK(igraph_constraint(graph,&res,vids,&wght));
  }

  for(i=0;i<igraph_vector_size(&res);i++){
    rb_ary_push(constraints,rb_float_new(VECTOR(res)[i]));
  }

  igraph_vector_destroy(&vidv);
  igraph_vector_destroy(&res);
  igraph_vector_destroy(&wght);
  igraph_vs_destroy(&vids);

  IGRAPH_FINALLY_CLEAN(3);

  return constraints;

}
Esempio n. 9
0
int cliques_load_unordered_maximal_cliques_list(cliques *c, const char *path) {
    FILE *input;
    igraph_vector_t *k_clique_v;
    int size, node_id;
    int max_size=0,cur_size=0;
    if (c == NULL || path == NULL)
        return -1;

    if ((input = fopen(path, "r")) == NULL)
        return -2;

    k_clique_v = (igraph_vector_t*) malloc(sizeof (igraph_vector_t));
    igraph_vector_init(k_clique_v, 0);
    // read the file and compute the maximum size
    // of the cliques
    while (fscanf(input, "%i", &node_id) != EOF) {
      if (node_id == -1){
	if(cur_size > max_size)
	  max_size = cur_size;
        cur_size=0;
      } else
        cur_size++;
    }

    // initialize cliques structure internal vectors
    // according to the size of the maximum clique
    if((cliques_init_member_vectors(c, max_size)) < 0)
      return -3;

    // reset the file position indicator to the beginning of the file
    fseek(input, 0L, SEEK_SET);
    // load maximal cliques from the file


    while (fscanf(input, "%i", &node_id) != EOF) {
      if (node_id != -1){
        igraph_vector_push_back(k_clique_v, node_id);
      }else {
        size = igraph_vector_size(k_clique_v);
        igraph_vector_sort(k_clique_v);
        igraph_vector_ptr_push_back(VECTOR(c->maximal_cliques_v_ptr)[size], k_clique_v);
        
        k_clique_v = (igraph_vector_t*) malloc(sizeof (igraph_vector_t));
        igraph_vector_init(k_clique_v, 0);
      }
    }
    cliques_order_cliques_by_decreasing_k(c, NULL);
    igraph_vector_destroy(k_clique_v);
    return 0;
}
int main() {
  
  igraph_t g;
  igraph_vector_t edges, eb;
  long int i;
  long int no_of_edges;

  /* Zachary Karate club */
  igraph_small(&g, 0, IGRAPH_UNDIRECTED, 
	       0,  1,  0,  2,  0,  3,  0,  4,  0,  5,
	       0,  6,  0,  7,  0,  8,  0, 10,  0, 11,
	       0, 12,  0, 13,  0, 17,  0, 19,  0, 21,
	       0, 31,  1,  2,  1,  3,  1,  7,  1, 13,
	       1, 17,  1, 19,  1, 21,  1, 30,  2,  3,
	       2,  7,  2,  8,  2,  9,  2, 13,  2, 27,
	       2, 28,  2, 32,  3,  7,  3, 12,  3, 13,
	       4,  6,  4, 10,  5,  6,  5, 10,  5, 16,
	       6, 16,  8, 30,  8, 32,  8, 33,  9, 33,
	       13, 33, 14, 32, 14, 33, 15, 32, 15, 33,
	       18, 32, 18, 33, 19, 33, 20, 32, 20, 33,
	       22, 32, 22, 33, 23, 25, 23, 27, 23, 29,
	       23, 32, 23, 33, 24, 25, 24, 27, 24, 31,
	       25, 31, 26, 29, 26, 33, 27, 33, 28, 31,
	       28, 33, 29, 32, 29, 33, 30, 32, 30, 33,
	       31, 32, 31, 33, 32, 33,
	       -1);  
  
  igraph_vector_init(&edges, 0);
  igraph_vector_init(&eb, 0);
  igraph_community_edge_betweenness(&g, &edges, &eb, 0 /*merges */,
				    0 /*bridges */,
				    IGRAPH_UNDIRECTED);
  
  no_of_edges=igraph_ecount(&g);
  for (i=0; i<no_of_edges; i++) {
    printf("%li ", (long int)VECTOR(edges)[i]);
  }
  printf("\n");
  
  for (i=0; i<no_of_edges; i++) {
    printf("%.2f ", VECTOR(eb)[i]);
  }
  printf("\n");

  igraph_vector_destroy(&eb);
  igraph_vector_destroy(&edges);
  igraph_destroy(&g);
  
  return 0;
}
int main() {

  igraph_t g;
  igraph_vector_t eb; 

  igraph_small(&g, 0, IGRAPH_UNDIRECTED, 
	       0,  1,  0,  2,  0,  3,  0,  4,  0,  5,
	       0,  6,  0,  7,  0,  8,  0, 10,  0, 11,
	       0, 12,  0, 13,  0, 17,  0, 19,  0, 21,
	       0, 31,  1,  2,  1,  3,  1,  7,  1, 13,
	       1, 17,  1, 19,  1, 21,  1, 30,  2,  3,
	       2,  7,  2,  8,  2,  9,  2, 13,  2, 27,
	       2, 28,  2, 32,  3,  7,  3, 12,  3, 13,
	       4,  6,  4, 10,  5,  6,  5, 10,  5, 16,
	       6, 16,  8, 30,  8, 32,  8, 33,  9, 33,
	       13, 33, 14, 32, 14, 33, 15, 32, 15, 33,
	       18, 32, 18, 33, 19, 33, 20, 32, 20, 33,
	       22, 32, 22, 33, 23, 25, 23, 27, 23, 29,
	       23, 32, 23, 33, 24, 25, 24, 27, 24, 31,
	       25, 31, 26, 29, 26, 33, 27, 33, 28, 31,
	       28, 33, 29, 32, 29, 33, 30, 32, 30, 33,
	       31, 32, 31, 33, 32, 33,
	       -1);
  
  igraph_vector_init(&eb, igraph_ecount(&g));
  igraph_edge_betweenness(&g, &eb, IGRAPH_UNDIRECTED);
  print_vector(&eb, stdout);
  igraph_vector_destroy(&eb);
  igraph_destroy(&g);

  igraph_small(&g, 0, IGRAPH_UNDIRECTED,
    0, 1, 0, 2, 0, 3, 1, 4, -1);
  igraph_vector_init(&eb, igraph_ecount(&g));
  igraph_edge_betweenness_estimate(&g, &eb, IGRAPH_UNDIRECTED, 2);
  print_vector(&eb, stdout);
  igraph_vector_destroy(&eb);
  igraph_destroy(&g);

  igraph_small(&g, 0, IGRAPH_UNDIRECTED,
    0, 1, 0, 3, 1, 2, 1, 4, 2, 5, 3, 4, 3, 6, 4, 5, 4, 7, 5, 8,
    6, 7, 7, 8, -1);
  igraph_vector_init(&eb, igraph_ecount(&g));
  igraph_edge_betweenness_estimate(&g, &eb, IGRAPH_UNDIRECTED, 2);
  print_vector(&eb, stdout);
  igraph_vector_destroy(&eb);
  igraph_destroy(&g);

  return 0;
}
Esempio n. 12
0
int main() {
  
  igraph_matrix_t A;
  igraph_matrix_t vectors_left, vectors_right;
  igraph_vector_t values_real, values_imag;
  int i, j;
  int info=1;
  int ilo, ihi;
  igraph_real_t abnrm;
  
  igraph_rng_seed(igraph_rng_default(), 42);
  
  igraph_matrix_init(&A, DIM, DIM);
  igraph_matrix_init(&vectors_left, 0, 0);
  igraph_matrix_init(&vectors_right, 0, 0);
  igraph_vector_init(&values_real, 0);
  igraph_vector_init(&values_imag, 0);

  for (i=0; i<DIM; i++) {
    for (j=0; j<DIM; j++) {
      MATRIX(A, i, j) = igraph_rng_get_integer(igraph_rng_default(), 1, 10);
    }
  }
  
  igraph_lapack_dgeevx(IGRAPH_LAPACK_DGEEVX_BALANCE_BOTH,
		       &A, &values_real, &values_imag, 
		       &vectors_left, &vectors_right, &ilo, &ihi,
		       /*scale=*/ 0, &abnrm, /*rconde=*/ 0, 
		       /*rcondv=*/ 0, &info);

  if (check_ev(&A, &values_real, &values_imag, 
	       &vectors_left, &vectors_right, /*tol=*/ 1e-8)) {
    return 1;
  }
  
  /* igraph_matrix_print(&A); */
  /* igraph_vector_print(&values_real); */
  /* igraph_vector_print(&values_imag); */
  /* igraph_matrix_print(&vectors_left); */
  /* igraph_matrix_print(&vectors_right); */
  
  igraph_vector_destroy(&values_imag);
  igraph_vector_destroy(&values_real);
  igraph_matrix_destroy(&vectors_right);
  igraph_matrix_destroy(&vectors_left);
  igraph_matrix_destroy(&A);

  return 0;
}
Esempio n. 13
0
int main() {
    igraph_t graph;
    igraph_vector_t walk, weights;
    igraph_integer_t ec, i;

    igraph_rng_seed(igraph_rng_default(), 137);

    igraph_vector_init(&walk, 0);
    igraph_vector_init(&weights, 0);

    /* This directed graph has loop edges.
       It also has multi-edges when considered as undirected. */
    igraph_de_bruijn(&graph, 3, 2);
    ec = igraph_ecount(&graph);

    /* unweighted, directed */
    igraph_random_edge_walk(&graph, NULL, &walk, 0, IGRAPH_OUT, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
    assert(igraph_vector_size(&walk) == 1000);

    /* unweighted, undirected */
    igraph_random_edge_walk(&graph, NULL, &walk, 0, IGRAPH_ALL, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
    assert(igraph_vector_size(&walk) == 1000);

    igraph_vector_resize(&weights, ec);
    for (i=0; i < ec; ++i)
        VECTOR(weights)[i] = igraph_rng_get_unif01(igraph_rng_default());

    /* weighted, directed */
    igraph_random_edge_walk(&graph, &weights, &walk, 0, IGRAPH_OUT, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
    assert(igraph_vector_size(&walk) == 1000);

    /* weighted, undirecetd */
    igraph_random_edge_walk(&graph, &weights, &walk, 0, IGRAPH_ALL, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
    assert(igraph_vector_size(&walk) == 1000);

    igraph_destroy(&graph);

    /* 1-vertex graph, should get stuck */
    igraph_empty(&graph, 1, /* directed = */ 0);
    igraph_random_edge_walk(&graph, NULL, &walk, 0, IGRAPH_OUT, 1000, IGRAPH_RANDOM_WALK_STUCK_RETURN);
    assert(igraph_vector_size(&walk) == 0);
    igraph_destroy(&graph);

    igraph_vector_destroy(&weights);
    igraph_vector_destroy(&walk);

    return 0;
}
int main() {
  
  igraph_t g;
  igraph_integer_t result;
  igraph_vector_t edges, res;
  igraph_vs_t vids;
  long i, n;
  
  igraph_tree(&g, 10, 3, IGRAPH_TREE_OUT);
  igraph_rewire(&g, 1000, IGRAPH_REWIRING_SIMPLE);
  
  n=igraph_vcount(&g);
  igraph_vector_init(&res, 0);
  igraph_degree(&g, &res, igraph_vss_all(), IGRAPH_IN, 0);
  for (i=0; i<n; i++)
    printf("%ld ", (long)igraph_vector_e(&res, i));
  printf("\n");
  
  igraph_degree(&g, &res, igraph_vss_all(), IGRAPH_OUT, 0);
  for (i=0; i<n; i++)
    printf("%ld ", (long)igraph_vector_e(&res, i));
  printf("\n");
    
  igraph_destroy(&g);
  igraph_vector_destroy(&res);
  
  return 0;
}
static PyObject *ignp_fun_degreeList( PyObject *self, PyObject *args ) {
    long int i;
    igraph_t *g;
    PyArrayObject *py_deg;
    PyObject *x_obj;
    igraph_vector_t v;
    igraph_vector_init(&v, 0);
    PyObject* mem_addr_o;
    long int mem_addr;
    
    
    if (!PyArg_ParseTuple(args, "OO!",
                           &x_obj,
                           &PyArray_Type, &py_deg
                        )) {
        return NULL;
    }
    mem_addr_o = PyObject_CallMethod(x_obj, "_raw_pointer", "()");
    mem_addr = PyInt_AsLong(mem_addr_o);
    Py_DECREF(mem_addr_o);
    if (mem_addr == -1) { 
        printf("PyInt to Long Failed");
        return NULL;
    }
    g = (igraph_t*) mem_addr;

    igraph_degree(g, &v, igraph_vss_all(), IGRAPH_ALL, IGRAPH_NO_LOOPS);
    
    for (i = 0; i<igraph_vector_size(&v); i++) {
        deg(i) = VECTOR(v)[ i ];
    }
    
    igraph_vector_destroy(&v);
    Py_RETURN_NONE;
} 
int main() {
  
  igraph_t g;
  igraph_vector_t result;
  long i;
  
  igraph_vector_init(&result, 0);

  igraph_small(&g, 7, 0, 0,1,0,2,0,3,1,2,1,3,2,3,3,4,4,5,4,6,5,6, -1);
  igraph_convergence_degree(&g, &result, 0, 0);
  for (i=0; i<igraph_ecount(&g); i++)
    printf("%.4f ", (float)igraph_vector_e(&result, i));
  printf("\n");
  igraph_destroy(&g);

  igraph_small(&g, 6, 1, 1,0,2,0,3,0,4,0,0,5, -1);
  igraph_convergence_degree(&g, &result, 0, 0);
  for (i=0; i<igraph_ecount(&g); i++)
    printf("%.4f ", (float)igraph_vector_e(&result, i));
  printf("\n");
  igraph_destroy(&g);

  igraph_vector_destroy(&result);
  
  return 0;
}
int main() {
  
  igraph_t g;
  igraph_vs_t vertices;
  igraph_vector_t result;
  long int i;
  
  igraph_vs_seq(&vertices, 1, 101);
  igraph_barabasi_game(&g, 100000, /*power=*/ 1, 3, 0, 0, /*A=*/ 1,
		       IGRAPH_DIRECTED, IGRAPH_BARABASI_BAG, 
		       /*start_from=*/ 0);
  igraph_vector_init(&result, 0);
  
  for (i=0; i<1; i++) {
    igraph_transitivity_local_undirected2(&g, &result, igraph_vss_all(),
			IGRAPH_TRANSITIVITY_NAN);
  }

  for (i=0; i<1; i++) {
    igraph_transitivity_local_undirected4(&g, &result, igraph_vss_all(),
			IGRAPH_TRANSITIVITY_NAN);
  }
  
/*   for (i=0; i<igraph_vector_size(&result); i++) { */
/*     printf("%f ", VECTOR(result)[i]); */
/*   } */
/*   printf("\n"); */
  
  igraph_vector_destroy(&result);
  igraph_vs_destroy(&vertices);
  igraph_destroy(&g);
  
  return 0;
}
Esempio n. 18
0
int main() {
  igraph_t g;
  igraph_vector_t v, v2;
  
  igraph_vector_init(&v, 0);
  igraph_vector_init(&v2, 0);
  igraph_ring(&g, 10, /*directed=*/ 0, /*mutual=*/ 0, /*circular=*/ 1);
  igraph_avg_nearest_neighbor_degree(&g, igraph_vss_all(), &v, &v2, 
				     /*weights=*/ 0);
  
  igraph_destroy(&g);
  igraph_vector_destroy(&v);
  igraph_vector_destroy(&v2);
  
  return 0;
}
Esempio n. 19
0
int igraph_adjlist_init(const igraph_t *graph, igraph_adjlist_t *al, 
			  igraph_neimode_t mode) {
  long int i;

  if (mode != IGRAPH_IN && mode != IGRAPH_OUT && mode != IGRAPH_ALL) {
    IGRAPH_ERROR("Cannot create adjlist view", IGRAPH_EINVMODE);
  }

  if (!igraph_is_directed(graph)) { mode=IGRAPH_ALL; }

  al->length=igraph_vcount(graph);
  al->adjs=igraph_Calloc(al->length, igraph_vector_t);
  if (al->adjs == 0) {
    IGRAPH_ERROR("Cannot create adjlist view", IGRAPH_ENOMEM);
  }

  IGRAPH_FINALLY(igraph_adjlist_destroy, al);
  for (i=0; i<al->length; i++) {
    IGRAPH_ALLOW_INTERRUPTION();
    IGRAPH_CHECK(igraph_vector_init(&al->adjs[i], 0));
    IGRAPH_CHECK(igraph_neighbors(graph, &al->adjs[i], i, mode));
  }

  IGRAPH_FINALLY_CLEAN(1);
  return 0;
}
Esempio n. 20
0
igraph_vector_t *igraph_lazy_adjlist_get_real(igraph_lazy_adjlist_t *al,
						igraph_integer_t pno) {
  long int no=pno;
  int ret;
  if (al->adjs[no] == 0) {
    al->adjs[no] = igraph_Calloc(1, igraph_vector_t);
    if (al->adjs[no] == 0) {
      igraph_error("Lazy adjlist failed", __FILE__, __LINE__, 
		   IGRAPH_ENOMEM);
    }
    ret=igraph_vector_init(al->adjs[no], 0);
    if (ret != 0) {
      igraph_error("", __FILE__, __LINE__, ret);
    }
    ret=igraph_neighbors(al->graph, al->adjs[no], no, al->mode);
    if (ret != 0) {
      igraph_error("", __FILE__, __LINE__, ret);
    }

    if (al->simplify == IGRAPH_SIMPLIFY) {
      igraph_vector_t *v=al->adjs[no];
      long int i, p=0, n=igraph_vector_size(v);
      for (i=0; i<n; i++) {
	if (VECTOR(*v)[i] != no && 
	    (i==n-1 || VECTOR(*v)[i+1] != VECTOR(*v)[i])) {
	  VECTOR(*v)[p]=VECTOR(*v)[i];
	  p++;
	}
      }
      igraph_vector_resize(v, p);
    }
  }
  
  return al->adjs[no];
}
int main() {

  igraph_t g;
  igraph_vector_ptr_t vecs;
  long int i;
  igraph_vs_t vs;

  igraph_ring(&g, 10, IGRAPH_DIRECTED, 0, 1);
  
  igraph_vector_ptr_init(&vecs, 5);
  for (i=0; i<igraph_vector_ptr_size(&vecs); i++) {
    VECTOR(vecs)[i] = calloc(1, sizeof(igraph_vector_t));
    igraph_vector_init(VECTOR(vecs)[i], 0);
  }
  igraph_vs_vector_small(&vs, 1, 3, 5, 2, 1,  -1);
  
  igraph_get_shortest_paths(&g, &vecs, 0, vs, IGRAPH_OUT);
  
  for (i=0; i<igraph_vector_ptr_size(&vecs); i++) {
    print_vector(VECTOR(vecs)[i]);
    igraph_vector_destroy(VECTOR(vecs)[i]);
    free(VECTOR(vecs)[i]);
  }
  igraph_vector_ptr_destroy(&vecs);
  igraph_vs_destroy(&vs);
  igraph_destroy(&g);
  
  return 0;
}
/* call-seq:
 *   IGraph::GenerateRandom.preference_game(nodes,types,type_dist,pref_matrixdirected,loops) -> IGraph
 *
 * Generates a graph with vertex types and connection preferences
 *
 * This is practically the nongrowing variant of igraph_establishment_game.
 * A given number of vertices are generated. Every vertex is assigned to a
 * vertex type according to the given type probabilities. Finally, every
 * vertex pair is evaluated and an edge is created between them with a
 * probability depending on the types of the vertices involved.
 *
 * nodes: The number of vertices in the graph.
 *
 * types: The number of vertex types.
 *
 * type_dist: Vector giving the distribution of vertex types.
 *
 * pref_matrix: IGraphMatrix giving the connection probabilities for
 * different vertex types.
 *
 * directed: Logical, whether to generate a directed graph. If undirected
 * graphs are requested, only the lower left triangle of the preference
 * matrix is considered.
 *
 * loops: Logical, whether loop edges are allowed.
 */
VALUE cIGraph_preference_game(VALUE self, VALUE nodes, VALUE types, VALUE type_dist, VALUE pref_matrix, VALUE directed, VALUE loops) {

    igraph_t *graph;
    VALUE new_graph;
    igraph_vector_t type_distv;
    igraph_matrix_t *pref_matrixm;
    int i;

    new_graph = cIGraph_alloc(cIGraph);
    Data_Get_Struct(new_graph, igraph_t, graph);

    Data_Get_Struct(pref_matrix, igraph_matrix_t, pref_matrixm);

    igraph_vector_init(&type_distv,0);

    for(i=0; i<RARRAY_LEN(type_dist); i++) {
        igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY_PTR(type_dist)[i]));
    }

    igraph_destroy(graph);
    igraph_preference_game(graph, NUM2INT(nodes), NUM2INT(types),
                           &type_distv,
                           pref_matrixm,
                           NULL,
                           directed == Qtrue ? 1: 0,
                           loops == Qtrue ? 1 : 0);

    igraph_vector_destroy(&type_distv);

    return new_graph;


}
/* call-seq:
 *   IGraph::GenerateRandom.citing_cited_type_game(nodes,types,pref,edges_per_step_directed) -> IGraph
 *
 * This game is similar to igraph_cited_type_game() but here the category of
 * the citing vertex is also considered.
 *
 * An evolving citation network is modeled here, a single vertex and its
 * edges_per_step citation are added in each time step. The odds the a given
 * vertex is cited by the new vertex depends on the category of both the
 * citing and the cited vertex and is given in the pref matrix. The categories
 * of the citing vertex correspond to the rows, the categories of the cited
 * vertex to the columns of this matrix. Ie. the element in row i and column
 * j gives the probability that a j vertex is cited, if the category of the
 * citing vertex is i.
 *
 * Note that this function might generate networks with multiple edges if
 * edges_per_step is greater than one. You might want to call
 * igraph_simplify() on the result to remove multiple edges.
 *
 * nodes: The number of vertices in the network.
 *
 * types: A numeric IGraphMatrix of length nodes, containing the categories
 * of the vertices. The categories are numbered from zero.
 *
 * pref: The preference IGraphMatrix, a square matrix is required, both the
 * number of rows and columns should be the maximum element in types plus
 * one (types are numbered from zero).
 *
 * edges_per_step: Integer constant, the number of edges to add in each time
 * step.
 *
 * directed: Logical constant, whether to create a directed network.
 */
VALUE cIGraph_citing_cited_type_game(VALUE self, VALUE nodes, VALUE types, VALUE pref, VALUE e_per_s, VALUE directed) {

    igraph_t *graph;
    VALUE new_graph;
    igraph_vector_t typev;
    igraph_matrix_t *prefm;
    int i;

    new_graph = cIGraph_alloc(cIGraph);
    Data_Get_Struct(new_graph, igraph_t, graph);
    Data_Get_Struct(pref, igraph_matrix_t, prefm);

    igraph_vector_init(&typev,0);

    for(i=0; i<RARRAY_LEN(types); i++) {
        igraph_vector_push_back(&typev,NUM2INT(RARRAY_PTR(types)[i]));
    }

    /*printf("ok\n");*/

    igraph_destroy(graph);
    igraph_citing_cited_type_game(graph, NUM2INT(nodes),
                                  &typev,
                                  prefm,
                                  NUM2INT(e_per_s),
                                  directed == Qtrue ? 1: 0);

    /*printf("death\n");*/

    igraph_vector_destroy(&typev);

    return new_graph;


}
Esempio n. 24
0
static gboolean _tgengraph_hasSelfLoop(TGenGraph* g, igraph_integer_t vertexIndex) {
    TGEN_ASSERT(g);
    gboolean isLoop = FALSE;

    igraph_vector_t* resultNeighborVertices = g_new0(igraph_vector_t, 1);
    gint result = igraph_vector_init(resultNeighborVertices, 0);

    if(result == IGRAPH_SUCCESS) {
        result = igraph_neighbors(g->graph, resultNeighborVertices, vertexIndex, IGRAPH_OUT);
        if(result == IGRAPH_SUCCESS) {
            glong nVertices = igraph_vector_size(resultNeighborVertices);
            for (gint i = 0; i < nVertices; i++) {
                igraph_integer_t dstVertexIndex = igraph_vector_e(resultNeighborVertices, i);
                if(vertexIndex == dstVertexIndex) {
                    isLoop = TRUE;
                    break;
                }
            }
        }
    }

    igraph_vector_destroy(resultNeighborVertices);
    g_free(resultNeighborVertices);
    return isLoop;
}
int main() {
  
  igraph_matrix_t A;
  igraph_vector_t values;
  igraph_matrix_t vectors;
  int i, j;
  igraph_eigen_which_t which;

  igraph_rng_seed(igraph_rng_default(), 42 * 42);
  
  igraph_matrix_init(&A, DIM, DIM);
  igraph_matrix_init(&vectors, 0, 0);
  igraph_vector_init(&values, 0);

  /* All eigenvalues and eigenvectors */

  for (i=0; i<DIM; i++) {
    for (j=i; j<DIM; j++) {
      MATRIX(A, i, j) = MATRIX(A, j, i) = 
	igraph_rng_get_integer(igraph_rng_default(), 1, 10);
    }
  }

  which.pos=IGRAPH_EIGEN_LM;
  which.howmany=5;
  igraph_eigen_matrix_symmetric(&A, /*sA=*/ 0, /*fun=*/ 0, DIM, /*extra=*/ 0,
				IGRAPH_EIGEN_LAPACK, &which, /*options=*/ 0,
				/*storage=*/ 0, &values, &vectors);
  igraph_vector_print(&values);
  check_ev(&A, &values, &vectors);

  which.howmany=8;
  igraph_eigen_matrix_symmetric(&A, /*sA=*/ 0, /*fun=*/ 0, DIM, /*extra=*/ 0,
				IGRAPH_EIGEN_LAPACK, &which, /*options=*/ 0,
				/*storage=*/ 0, &values, &vectors);
  igraph_vector_print(&values);
  check_ev(&A, &values, &vectors);

  which.pos=IGRAPH_EIGEN_BE;
  which.howmany=5;
  igraph_eigen_matrix_symmetric(&A, /*sA=*/ 0, /*fun=*/ 0, DIM, /*extra=*/ 0,
				IGRAPH_EIGEN_LAPACK, &which, /*options=*/ 0,
				/*storage=*/ 0, &values, &vectors);
  igraph_vector_print(&values);
  check_ev(&A, &values, &vectors);

  which.pos=IGRAPH_EIGEN_SM;
  which.howmany=5;
  igraph_eigen_matrix_symmetric(&A, /*sA=*/ 0, /*fun=*/ 0, DIM, /*extra=*/ 0,
				IGRAPH_EIGEN_LAPACK, &which, /*options=*/ 0,
				/*storage=*/ 0, &values, &vectors);
  igraph_vector_print(&values);
  check_ev(&A, &values, &vectors);
  
  igraph_vector_destroy(&values);
  igraph_matrix_destroy(&vectors);
  igraph_matrix_destroy(&A);  

  return 0;
}
Esempio n. 26
0
VALUE cIGraph_community_fastgreedy(VALUE self){

  igraph_t *graph;

  igraph_vector_t modularity;
  igraph_matrix_t *merges = malloc(sizeof(igraph_matrix_t));

  int i;

  VALUE modularity_a, res;

  Data_Get_Struct(self, igraph_t, graph);

  igraph_matrix_init(merges,0,0);
  igraph_vector_init(&modularity,0);

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

  modularity_a = rb_ary_new();
  for(i=0;i<igraph_vector_size(&modularity);i++){
    rb_ary_push(modularity_a,rb_float_new(VECTOR(modularity)[i]));
  }

  res = rb_ary_new3(2,
		    Data_Wrap_Struct(cIGraphMatrix, 0, 
				     cIGraph_matrix_free, merges),
		    modularity_a);

  igraph_vector_destroy(&modularity);

  return res;

}
Esempio n. 27
0
VALUE cIGraph_modularity(VALUE self, VALUE groups){

  igraph_t *graph;
  igraph_real_t value;
  igraph_vector_t membership;

  VALUE group;

  int i,j;

  Data_Get_Struct(self, igraph_t, graph);

  igraph_vector_init(&membership,igraph_vcount(graph));

  for(i=0;i<RARRAY_LEN(groups);i++){
    group = RARRAY_PTR(groups)[i];
    for(j=0;j<RARRAY_LEN(group);j++){
      igraph_vector_set(&membership,
			cIGraph_get_vertex_id(self,RARRAY_PTR(group)[j]),i);
    }
  }

  igraph_modularity(graph,&membership,&value,NULL);
  
  igraph_vector_destroy(&membership);

  return rb_float_new(value);

}
Esempio n. 28
0
int igraph_inclist_init(const igraph_t *graph, 
			      igraph_inclist_t *il, 
			      igraph_neimode_t mode) {
  long int i;

  if (mode != IGRAPH_IN && mode != IGRAPH_OUT && mode != IGRAPH_ALL) {
    IGRAPH_ERROR("Cannot create incidence list view", IGRAPH_EINVMODE);
  }

  if (!igraph_is_directed(graph)) { mode=IGRAPH_ALL; }

  il->length=igraph_vcount(graph);
  il->incs=igraph_Calloc(il->length, igraph_vector_t);
  if (il->incs == 0) {
    IGRAPH_ERROR("Cannot create incidence list view", IGRAPH_ENOMEM);
  }

  IGRAPH_FINALLY(igraph_inclist_destroy, il);  
  for (i=0; i<il->length; i++) {
    IGRAPH_ALLOW_INTERRUPTION();
    IGRAPH_CHECK(igraph_vector_init(&il->incs[i], 0));
    IGRAPH_CHECK(igraph_incident(graph, &il->incs[i], i, mode));
  }
  
  IGRAPH_FINALLY_CLEAN(1);
  return 0;
}
Esempio n. 29
0
int main() {
  
  igraph_t g;
  igraph_integer_t result;
  igraph_integer_t from, to;
  igraph_vector_t path;
  igraph_rng_t rng;
  igraph_rng_init(&rng, &igraph_rngtype_mt19937);
  
  igraph_barabasi_game(&g, 30, /*power=*/ 1, 30, 0, 0, /*A=*/ 1, 
		       IGRAPH_DIRECTED, IGRAPH_BARABASI_BAG, 
		       /*start_from=*/ 0, &rng);
  igraph_diameter(&g, &result, 0, 0, 0, IGRAPH_UNDIRECTED, 1);
  
/*   printf("Diameter: %li\n", (long int) result); */
  
  igraph_destroy(&g);

  igraph_ring(&g, 10, IGRAPH_DIRECTED, 0, 0);
  igraph_vector_init(&path, 0);
  igraph_diameter(&g, &result, &from, &to, &path, IGRAPH_DIRECTED, 1);
  printf("diameter: %li, from %li to %li\n", (long int) result,
	 (long int) from, (long int) to);
  print_vector(&path);
  
  igraph_vector_destroy(&path);
  igraph_destroy(&g);
  igraph_rng_destroy(&rng);

  return 0;
}
Esempio n. 30
0
VALUE cIGraph_community_spinglass_single(VALUE self, VALUE weights, VALUE vertex, VALUE spins, VALUE update_rule, VALUE gamma){

  igraph_t *graph;

  igraph_vector_t weights_vec;
  igraph_vector_t community;
  igraph_real_t cohesion;
  igraph_real_t adhesion;

  VALUE group;
  VALUE res;

  int i;

  Data_Get_Struct(self, igraph_t, graph);

  igraph_vector_init(&community,0);

  igraph_vector_init(&weights_vec,RARRAY_LEN(weights));
  for(i=0;i<RARRAY_LEN(weights);i++){
    VECTOR(weights_vec)[i] = NUM2DBL(RARRAY_PTR(weights)[i]);
  }

  igraph_community_spinglass_single(graph,
				    igraph_vector_size(&weights_vec) > 0 ? &weights_vec : NULL,
				    cIGraph_get_vertex_id(self, vertex),   
				    &community, &cohesion, &adhesion,
				    NULL, NULL,
				    NUM2INT(spins),NUM2INT(update_rule),
				    NUM2DBL(gamma));
  
  group = rb_ary_new();

  for(i=0;i<igraph_vector_size(&community);i++){
    rb_ary_push(group,cIGraph_get_vertex_object(self, i));
  }

  res = rb_ary_new3(3,group,
		    rb_float_new(cohesion),
		    rb_float_new(adhesion));

  igraph_vector_destroy(&community);
  igraph_vector_destroy(&weights_vec);

  return res;

}