VALUE cIGraph_community_walktrap(VALUE self, VALUE weights, VALUE steps){ igraph_t *graph; igraph_vector_t weights_vec; 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(&weights_vec,0); igraph_vector_init(&modularity,0); for(i=0;i<RARRAY_LEN(weights);i++){ VECTOR(weights_vec)[i] = NUM2DBL(RARRAY_PTR(weights)[i]); } igraph_community_walktrap(graph, igraph_vector_size(&weights_vec) > 0 ? &weights_vec : NULL, NUM2INT(steps),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(&weights_vec); igraph_vector_destroy(&modularity); return res; }
int igraph_i_maximum_bipartite_matching_unweighted_relabel(const igraph_t* graph, const igraph_vector_bool_t* types, igraph_vector_t* labels, igraph_vector_long_t* match, igraph_bool_t smaller_set) { long int i, j, n, no_of_nodes = igraph_vcount(graph), matched_to; igraph_dqueue_long_t q; igraph_vector_t neis; debug("Running global relabeling.\n"); /* Set all the labels to no_of_nodes first */ igraph_vector_fill(labels, no_of_nodes); /* Allocate vector for neighbors */ IGRAPH_VECTOR_INIT_FINALLY(&neis, 0); /* Create a FIFO for the BFS and initialize it with the unmatched rows * (i.e. members of the larger set) */ IGRAPH_CHECK(igraph_dqueue_long_init(&q, 0)); IGRAPH_FINALLY(igraph_dqueue_long_destroy, &q); for (i = 0; i < no_of_nodes; i++) { if (VECTOR(*types)[i] != smaller_set && VECTOR(*match)[i] == -1) { IGRAPH_CHECK(igraph_dqueue_long_push(&q, i)); VECTOR(*labels)[i] = 0; } } /* Run the BFS */ while (!igraph_dqueue_long_empty(&q)) { long int v = igraph_dqueue_long_pop(&q); long int w; IGRAPH_CHECK(igraph_neighbors(graph, &neis, (igraph_integer_t) v, IGRAPH_ALL)); n = igraph_vector_size(&neis); for (j = 0; j < n; j++) { w = (long int) VECTOR(neis)[j]; if (VECTOR(*labels)[w] == no_of_nodes) { VECTOR(*labels)[w] = VECTOR(*labels)[v] + 1; matched_to = VECTOR(*match)[w]; if (matched_to != -1 && VECTOR(*labels)[matched_to] == no_of_nodes) { IGRAPH_CHECK(igraph_dqueue_long_push(&q, matched_to)); VECTOR(*labels)[matched_to] = VECTOR(*labels)[w] + 1; } } } } igraph_dqueue_long_destroy(&q); igraph_vector_destroy(&neis); IGRAPH_FINALLY_CLEAN(2); return IGRAPH_SUCCESS; }
void igraph_i_free_vectorlist(igraph_vector_ptr_t *list) { long int i, n=igraph_vector_ptr_size(list); for (i=0; i<n; i++) { igraph_vector_t *v=VECTOR(*list)[i]; if (v) { igraph_vector_destroy(v); igraph_Free(v); } } igraph_vector_ptr_destroy(list); }
int igraph_i_maximal_or_largest_cliques_or_indsets(const igraph_t *graph, igraph_vector_ptr_t *res, igraph_integer_t *clique_number, igraph_bool_t keep_only_largest, igraph_bool_t complementer) { igraph_i_max_ind_vsets_data_t clqdata; long int no_of_nodes = igraph_vcount(graph), i; if (igraph_is_directed(graph)) IGRAPH_WARNING("directionality of edges is ignored for directed graphs"); clqdata.matrix_size=no_of_nodes; clqdata.keep_only_largest=keep_only_largest; if (complementer) IGRAPH_CHECK(igraph_adjlist_init_complementer(graph, &clqdata.adj_list, IGRAPH_ALL, 0)); else IGRAPH_CHECK(igraph_adjlist_init(graph, &clqdata.adj_list, IGRAPH_ALL)); IGRAPH_FINALLY(igraph_adjlist_destroy, &clqdata.adj_list); clqdata.IS = igraph_Calloc(no_of_nodes, igraph_integer_t); if (clqdata.IS == 0) IGRAPH_ERROR("igraph_i_maximal_or_largest_cliques_or_indsets failed", IGRAPH_ENOMEM); IGRAPH_FINALLY(igraph_free, clqdata.IS); IGRAPH_VECTOR_INIT_FINALLY(&clqdata.deg, no_of_nodes); for (i=0; i<no_of_nodes; i++) VECTOR(clqdata.deg)[i] = igraph_vector_size(igraph_adjlist_get(&clqdata.adj_list, i)); clqdata.buckets = igraph_Calloc(no_of_nodes+1, igraph_set_t); if (clqdata.buckets == 0) IGRAPH_ERROR("igraph_maximal_or_largest_cliques_or_indsets failed", IGRAPH_ENOMEM); IGRAPH_FINALLY(igraph_i_free_set_array, clqdata.buckets); for (i=0; i<no_of_nodes; i++) IGRAPH_CHECK(igraph_set_init(&clqdata.buckets[i], 0)); if (res) igraph_vector_ptr_clear(res); /* Do the show */ clqdata.largest_set_size=0; IGRAPH_CHECK(igraph_i_maximal_independent_vertex_sets_backtrack(graph, res, &clqdata, 0)); /* Cleanup */ for (i=0; i<no_of_nodes; i++) igraph_set_destroy(&clqdata.buckets[i]); igraph_adjlist_destroy(&clqdata.adj_list); igraph_vector_destroy(&clqdata.deg); igraph_free(clqdata.IS); igraph_free(clqdata.buckets); IGRAPH_FINALLY_CLEAN(4); if (clique_number) *clique_number = clqdata.largest_set_size; return 0; }
int print_and_destroy(igraph_vector_ptr_t *ptr) { long int i, n=igraph_vector_ptr_size(ptr); for (i=0; i<n; i++) { igraph_vector_t *v=VECTOR(*ptr)[i]; igraph_vector_print(v); igraph_vector_destroy(v); igraph_free(v); } igraph_vector_ptr_destroy(ptr); return 0; }
void igraph_i_cohesive_blocks_free3(igraph_vector_ptr_t *ptr) { long int i, n=igraph_vector_ptr_size(ptr); for (i=0; i<n; i++) { igraph_vector_t *v=VECTOR(*ptr)[i]; if (v) { igraph_vector_destroy(v); igraph_free(v); } } }
int print_and_destroy(igraph_vector_ptr_t *cliques) { int i, n=igraph_vector_ptr_size(cliques); sort_cliques(cliques); for (i=0; i<n; i++) { igraph_vector_t *v=VECTOR(*cliques)[i]; igraph_vector_print(v); igraph_vector_destroy(v); } igraph_vector_ptr_destroy_all(cliques); return 0; }
void igraph_i_cliques_free_res(igraph_vector_ptr_t *res) { long i, n; n = igraph_vector_ptr_size(res); for (i=0; i<n; i++) { if (VECTOR(*res)[i] != 0) { igraph_vector_destroy(VECTOR(*res)[i]); igraph_free(VECTOR(*res)[i]); } } igraph_vector_ptr_clear(res); }
VALUE cIGraph_community_leading_eigenvector_naive(VALUE self, VALUE steps){ igraph_t *graph; igraph_vector_t membership; igraph_matrix_t *merges = malloc(sizeof(igraph_matrix_t)); igraph_arpack_options_t arpack_opt; igraph_arpack_options_init(&arpack_opt); int i,groupid,max_groupid; VALUE groups, group, res; Data_Get_Struct(self, igraph_t, graph); igraph_matrix_init(merges,0,0); igraph_vector_init(&membership,0); igraph_community_leading_eigenvector_naive(graph,merges,&membership, NUM2INT(steps), &arpack_opt); max_groupid = 0; for(i=0;i<igraph_vector_size(&membership);i++){ if(VECTOR(membership)[i] > max_groupid) max_groupid = VECTOR(membership)[i]; } groups = rb_ary_new(); for(i=0;i<max_groupid+1;i++){ rb_ary_push(groups,rb_ary_new()); } for(i=0;i<igraph_vector_size(&membership);i++){ groupid = VECTOR(membership)[i]; if(groupid == -1) groupid = 0; group = RARRAY_PTR(groups)[groupid]; rb_ary_push(group,cIGraph_get_vertex_object(self, i)); } res = rb_ary_new3(2,groups, Data_Wrap_Struct(cIGraphMatrix, 0, cIGraph_matrix_free, merges)); igraph_vector_destroy(&membership); return res; }
void iterate(igraph_t *graph, double th) { igraph_integer_t x, y, z = -1.0, xy; xy = rand() % (int) igraph_ecount(graph); igraph_edge(graph, xy, &x, &y); //flip increasing orientation with pr 1/2 if(rand() % 2) { igraph_integer_t buffer = y; y = x; x = buffer; } igraph_vector_t degrees; igraph_vector_init(°rees, 1); all_degrees(graph, °rees); double d_mean = get_d_mean(graph); double random = 1.0 * rand() / RAND_MAX; int w; double total = 0.0; double denom = get_denom(graph, °rees, th, x, y); for(w = 0; w < igraph_vector_size(°rees); w++) { if(w != (int) x && w != (int) y) { total += f(VECTOR(degrees)[w], d_mean, th) / denom; if(random < total) { z = (igraph_integer_t) w; break; } } } igraph_vector_destroy(°rees); if(z > -.5) { igraph_es_t es; igraph_es_1(&es, xy); igraph_delete_edges(graph, es); igraph_es_destroy(&es); igraph_add_edge(graph, x, z); } }
/** * \ingroup python_interface_edgeseq * Returns the indices of the edges in this edge sequence */ PyObject* igraphmodule_EdgeSeq_get_indices(igraphmodule_EdgeSeqObject* self, void* closure) { igraphmodule_GraphObject *gr = self->gref; igraph_vector_t es; PyObject *result; if (igraph_vector_init(&es, 0)) { igraphmodule_handle_igraph_error(); return 0; } if (igraph_es_as_vector(&gr->g, self->es, &es)) { igraphmodule_handle_igraph_error(); igraph_vector_destroy(&es); return 0; } result = igraphmodule_vector_t_to_PyList(&es, IGRAPHMODULE_TYPE_INT); igraph_vector_destroy(&es); return result; }
int igraph_vector_order1(const igraph_vector_t* v, igraph_vector_t* res, igraph_real_t nodes) { long int edges=igraph_vector_size(v); igraph_vector_t ptr; igraph_vector_t rad; long int i, j; assert(v!=NULL); assert(v->stor_begin != NULL); IGRAPH_VECTOR_INIT_FINALLY(&ptr, nodes+1); IGRAPH_VECTOR_INIT_FINALLY(&rad, edges); IGRAPH_CHECK(igraph_vector_resize(res, edges)); for (i=0; i<edges; i++) { long int radix=v->stor_begin[i]; if (VECTOR(ptr)[radix]!=0) { VECTOR(rad)[i]=VECTOR(ptr)[radix]; } VECTOR(ptr)[radix]=i+1; } j=0; for (i=0; i<nodes+1; i++) { if (VECTOR(ptr)[i] != 0) { long int next=VECTOR(ptr)[i]-1; res->stor_begin[j++]=next; while (VECTOR(rad)[next] != 0) { next=VECTOR(rad)[next]-1; res->stor_begin[j++]=next; } } } igraph_vector_destroy(&ptr); igraph_vector_destroy(&rad); IGRAPH_FINALLY_CLEAN(2); return 0; }
VALUE cIGraph_community_eb_get_merges(VALUE self, VALUE edges){ igraph_t *graph; igraph_matrix_t *res = malloc(sizeof(igraph_matrix_t)); igraph_vector_t edges_vec; igraph_vector_t bridges_vec; VALUE result,bridges_a; int i; Data_Get_Struct(self, igraph_t, graph); igraph_matrix_init(res,0,0); igraph_vector_init(&edges_vec,0); igraph_vector_init(&bridges_vec,0); for(i=0;i<RARRAY_LEN(edges);i++){ igraph_vector_push_back(&edges_vec,NUM2INT(RARRAY_PTR(edges)[i])); } igraph_community_eb_get_merges(graph,&edges_vec,res,&bridges_vec); 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])); } igraph_vector_destroy(&bridges_vec); igraph_vector_destroy(&edges_vec); result = rb_ary_new3(2, Data_Wrap_Struct(cIGraphMatrix, 0, cIGraph_matrix_free, res), bridges_a); return result; }
int igraph_is_connected_weak(const igraph_t *graph, igraph_bool_t *res) { long int no_of_nodes=igraph_vcount(graph); char *already_added; igraph_vector_t neis=IGRAPH_VECTOR_NULL; igraph_dqueue_t q=IGRAPH_DQUEUE_NULL; long int i, j; if (no_of_nodes == 0) { *res = 1; return IGRAPH_SUCCESS; } already_added=igraph_Calloc(no_of_nodes, char); if (already_added==0) { IGRAPH_ERROR("is connected (weak) failed", IGRAPH_ENOMEM); } IGRAPH_FINALLY(free, already_added); /* TODO: hack */ IGRAPH_DQUEUE_INIT_FINALLY(&q, 10); IGRAPH_VECTOR_INIT_FINALLY(&neis, 0); /* Try to find at least two clusters */ already_added[0]=1; IGRAPH_CHECK(igraph_dqueue_push(&q, 0)); j=1; while ( !igraph_dqueue_empty(&q)) { long int actnode=(long int) igraph_dqueue_pop(&q); IGRAPH_ALLOW_INTERRUPTION(); IGRAPH_CHECK(igraph_neighbors(graph, &neis, (igraph_integer_t) actnode, IGRAPH_ALL)); for (i=0; i <igraph_vector_size(&neis); i++) { long int neighbor=(long int) VECTOR(neis)[i]; if (already_added[neighbor] != 0) { continue; } IGRAPH_CHECK(igraph_dqueue_push(&q, neighbor)); j++; already_added[neighbor]++; } } /* Connected? */ *res = (j == no_of_nodes); igraph_Free(already_added); igraph_dqueue_destroy(&q); igraph_vector_destroy(&neis); IGRAPH_FINALLY_CLEAN(3); return 0; }
std::vector<double> Graph::betweenness() const { igraph_vector_t results; igraph_vs_t allnods; std::vector<double> bet; igraph_vector_init(&results, size); igraph_vector_null(&results); igraph_vs_all(&allnods); igraph_betweenness(graph, &results, allnods, false); bet.insert(bet.begin(), VECTOR(results), VECTOR(results) + size); igraph_vector_destroy(&results); igraph_vs_destroy(&allnods); return bet; }
std::vector<double> Graph::closeness() const { igraph_vector_t results; igraph_vs_t allnods; std::vector<double> clos; igraph_vector_init(&results, size); igraph_vector_null(&results); igraph_vs_all(&allnods); igraph_closeness(graph, &results, allnods, IGRAPH_IN); clos.insert(clos.begin(), VECTOR(results), VECTOR(results) + size); igraph_vector_destroy(&results); igraph_vs_destroy(&allnods); return clos; }
int main() { igraph_t g; igraph_vector_ptr_t vecs, evecs; long int i; igraph_vs_t vs; igraph_ring(&g, 10, IGRAPH_DIRECTED, 0, 1); igraph_vector_ptr_init(&vecs, 5); igraph_vector_ptr_init(&evecs, 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); VECTOR(evecs)[i] = calloc(1, sizeof(igraph_vector_t)); igraph_vector_init(VECTOR(evecs)[i], 0); } igraph_vs_vector_small(&vs, 1, 3, 5, 2, 1, -1); igraph_get_shortest_paths(&g, &vecs, &evecs, 0, vs, IGRAPH_OUT); check_evecs(&g, &vecs, &evecs, 10); 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_destroy(VECTOR(evecs)[i]); free(VECTOR(evecs)[i]); } igraph_vector_ptr_destroy(&vecs); igraph_vector_ptr_destroy(&evecs); igraph_vs_destroy(&vs); igraph_destroy(&g); if (!IGRAPH_FINALLY_STACK_EMPTY) return 1; return 0; }
static double sumDegree(const igraph_t *g) { int i; double result = 0.0; igraph_vector_t v; igraph_vector_init(&v, 0); igraph_degree(g, &v, igraph_vss_all(), IGRAPH_ALL, IGRAPH_NO_LOOPS); for (i = 0; i<igraph_vector_size(&v); i++) { result += VECTOR(v)[ (long int)i ]; } igraph_vector_destroy(&v); return result; }
/* call-seq: * igraph.motifs_randesu_estimate(size,cut,samplen,samplev) * */ VALUE cIGraph_motifs_randesu_estimate(VALUE self, VALUE size, VALUE cuts, VALUE samplen, VALUE samplev){ igraph_t *graph; igraph_vector_t cutsv; igraph_vector_t vidv; igraph_integer_t res; int i; if(samplev != Qnil){ igraph_vector_init(&vidv,0); //Convert an array of vertices to a vector of vertex ids igraph_vector_init_int(&vidv,0); cIGraph_vertex_arr_to_id_vec(self,samplev,&vidv); } Data_Get_Struct(self, igraph_t, graph); igraph_vector_init(&cutsv,0); for(i=0;i<RARRAY_LEN(cuts);i++){ igraph_vector_push_back(&cutsv,NUM2DBL(RARRAY_PTR(cuts)[i])); } if(samplev == Qnil){ igraph_motifs_randesu_estimate(graph,&res,NUM2INT(size), &cutsv,NUM2INT(samplen),NULL); } else { igraph_motifs_randesu_estimate(graph,&res,NUM2INT(size), &cutsv,NUM2INT(samplen),&vidv); } igraph_vector_destroy(&cutsv); if(samplev != Qnil){ igraph_vector_destroy(&vidv); } return INT2NUM(res); }
std::vector<int> Graph::degrees() { igraph_vector_t results; igraph_vs_t allnds; std::vector<int> degs; igraph_vs_all(&allnds); igraph_vector_init(&results, size); igraph_vector_null(&results); igraph_degree(graph, &results, allnds, IGRAPH_ALL, IGRAPH_NO_LOOPS); degs.insert(degs.begin(), VECTOR(results), VECTOR(results)+size); igraph_vector_destroy(&results); igraph_vs_destroy(&allnds); return degs; }
int igraph_is_minimal_separator(const igraph_t *graph, const igraph_vs_t candidate, igraph_bool_t *res) { long int no_of_nodes=igraph_vcount(graph); igraph_vector_bool_t removed; igraph_dqueue_t Q; igraph_vector_t neis; long int candsize; igraph_vit_t vit; IGRAPH_CHECK(igraph_vit_create(graph, candidate, &vit)); IGRAPH_FINALLY(igraph_vit_destroy, &vit); candsize=IGRAPH_VIT_SIZE(vit); IGRAPH_CHECK(igraph_vector_bool_init(&removed, no_of_nodes)); IGRAPH_FINALLY(igraph_vector_bool_destroy, &removed); IGRAPH_CHECK(igraph_dqueue_init(&Q, 100)); IGRAPH_FINALLY(igraph_dqueue_destroy, &Q); IGRAPH_VECTOR_INIT_FINALLY(&neis, 0); /* Is it a separator at all? */ IGRAPH_CHECK(igraph_i_is_separator(graph, &vit, -1, res, &removed, &Q, &neis, no_of_nodes)); if (!(*res)) { /* Not a separator at all, nothing to do, *res is already set */ } else if (candsize == 0) { /* Nothing to do, minimal, *res is already set */ } else { /* General case, we need to remove each vertex from 'candidate' * and check whether the remainder is a separator. If this is * false for all vertices, then 'candidate' is a minimal * separator. */ long int i; for (i=0, *res=0; i<candsize && (!*res); i++) { igraph_vector_bool_null(&removed); IGRAPH_CHECK(igraph_i_is_separator(graph, &vit, i, res, &removed, &Q, &neis, no_of_nodes)); } (*res) = (*res) ? 0 : 1; /* opposite */ } igraph_vector_destroy(&neis); igraph_dqueue_destroy(&Q); igraph_vector_bool_destroy(&removed); igraph_vit_destroy(&vit); IGRAPH_FINALLY_CLEAN(4); return 0; }
int main(int argc,char** argv) { igraph_vector_t *lp; igraph_t g; // all ggen methods should fail on incorrect arguments assert(ggen_analyze_longest_path(NULL) == NULL); // an empty graph as a longest path of zero igraph_empty(&g,10,1); lp = ggen_analyze_longest_path(&g); assert(lp != NULL); assert(igraph_vector_size(lp) == 0); igraph_destroy(&g); igraph_vector_destroy(lp); free((void *)lp); // a full dag as a longest path of containing all vertices igraph_full_citation(&g,10,1); lp = ggen_analyze_longest_path(&g); assert(lp != NULL); assert(igraph_vector_size(lp) == 10); igraph_destroy(&g); igraph_vector_destroy(lp); free((void *)lp); // a simple graph should work too // graph is 0 -> 1 -> 2 and 0 -> 2 igraph_small(&g,10,1,0,1,1,2,0,2,-1); lp = ggen_analyze_longest_path(&g); assert(lp != NULL); assert(igraph_vector_size(lp) == 3); igraph_destroy(&g); igraph_vector_destroy(lp); free((void *)lp); return 0; }
int main() { igraph_t g; igraph_vector_t edges; igraph_vector_t vids; igraph_integer_t class; igraph_vector_init_int_end(&edges, -1, 0,1, 1,3, 1,4, 1,6, 3,1, 4,1, 4,2, 6,4, 6,5, 7,8, 8,7, 7,9, 9,7, 8,9, 9,8, -1); igraph_create(&g, &edges, 0, IGRAPH_DIRECTED); igraph_vector_destroy(&edges); igraph_vector_init_int_end(&vids, -1, 1,4,6, -1); igraph_isoclass_subgraph(&g, &vids, &class); printf("class: %i\n", (int)class); igraph_vector_destroy(&vids); igraph_vector_init_int_end(&vids, -1, 0,1,3, -1); igraph_isoclass_subgraph(&g, &vids, &class); printf("class: %i\n", (int)class); igraph_vector_destroy(&vids); igraph_vector_init_int_end(&vids, -1, 7,8,9, -1); igraph_isoclass_subgraph(&g, &vids, &class); printf("class: %i\n", (int)class); igraph_vector_destroy(&vids); igraph_vector_init_int_end(&vids, -1, 0,2,5, -1); igraph_isoclass_subgraph(&g, &vids, &class); printf("class: %i\n", (int)class); igraph_vector_destroy(&vids); igraph_destroy(&g); return 0; }
/* call-seq: * graph.pagerank(vs,mode,niter,eps,damping) -> Array * * Returns an Array of PageRank measures for the vertices * in the graph. mode defines whether directed paths or considered for * directed graphs. */ VALUE cIGraph_pagerank(VALUE self, VALUE vs, VALUE directed, VALUE niter, VALUE eps, VALUE damping){ igraph_t *graph; igraph_vs_t vids; igraph_vector_t vidv; igraph_vector_t res; int i; VALUE pagerank = rb_ary_new(); igraph_bool_t dir = 0; if(directed == Qtrue) dir = 1; //vector to hold the results of the degree calculations igraph_vector_init_int(&res,0); Data_Get_Struct(self, igraph_t, graph); //Convert an array of vertices to a vector of vertex ids 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); igraph_pagerank_old(graph,&res,vids,dir, NUM2INT(niter),NUM2DBL(eps),NUM2DBL(damping),0); for(i=0;i<igraph_vector_size(&res);i++){ rb_ary_push(pagerank,rb_float_new(VECTOR(res)[i])); } igraph_vector_destroy(&vidv); igraph_vector_destroy(&res); igraph_vs_destroy(&vids); return pagerank; }
int main() { igraph_t graph; igraph_vector_t order, order_out, father, dist; long int i,n,c; scanf("%li %li",&n,&c); fp=fopen("qwe.txt","w+"); fclose(fp); igraph_tree(&graph,(igraph_integer_t) n,(igraph_integer_t) 3, IGRAPH_TREE_OUT); fp=fopen("qwe.txt","a+"); igraph_vector_init(&order, 0); igraph_vector_init(&order_out, 0); igraph_vector_init(&father, 0); igraph_vector_init(&dist, 0); /* Test the callback */ for(i=0;i<10;i++) { printf("Iteration starts here\n"); dfs_d(&graph, /*root=*/ 0, /*neimode=*/ IGRAPH_ALL, /*unreachable=*/ 1, &order, 0, 0, &dist, &dfs_callback, &dfs_callback, 0); fprintf(fp,"\n"); igraph_vector_print(&order); igraph_vector_print(&dist); } //printf("\n"); igraph_destroy(&graph); igraph_vector_destroy(&order); igraph_vector_destroy(&order_out); igraph_vector_destroy(&father); igraph_vector_destroy(&dist); fclose(fp); return 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_ptr_t result; igraph_es_t es; igraph_integer_t omega; long int i, j, n; const int params[] = {4, -1, 2, 2, 0, 0, -1, -1}; igraph_set_warning_handler(warning_handler_ignore); igraph_vector_ptr_init(&result, 0); igraph_full(&g, 6, 0, 0); igraph_es_pairs_small(&es, 0, 0, 1, 0, 2, 3, 5, -1); igraph_delete_edges(&g, es); igraph_es_destroy(&es); for (j=0; j<sizeof(params)/(2*sizeof(params[0])); j++) { if (params[2*j+1] != 0) { igraph_cliques(&g, &result, params[2*j], params[2*j+1]); } else { igraph_largest_cliques(&g, &result); } n = igraph_vector_ptr_size(&result); printf("%ld cliques found\n", (long)n); canonicalize_list(&result); for (i=0; i<n; i++) { igraph_vector_t* v = (igraph_vector_t*) igraph_vector_ptr_e(&result,i); print_vector(v); igraph_vector_destroy(v); free(v); } } igraph_clique_number(&g, &omega); printf("omega=%ld\n", (long)omega); test_callback(&g); igraph_destroy(&g); igraph_tree(&g, 5, 2, IGRAPH_TREE_OUT); igraph_cliques(&g, &result, 5, 5); if (igraph_vector_ptr_size(&result) != 0) return 1; igraph_destroy(&g); igraph_vector_ptr_destroy(&result); return 0; }
void infomap_weighted_test(const igraph_t * g, const igraph_vector_t *weights){ igraph_vector_t membership; igraph_real_t codelength = 1000; igraph_vector_init(&membership, 0); igraph_community_infomap(/*in */ g, /*e_weight=*/ weights, NULL, /*nb_trials=*/5, /*out*/ &membership, &codelength); if(igraph_vcount(g) > 500) show_results_lite(&membership, codelength); else show_results(&membership, codelength); igraph_vector_destroy(&membership); }
int test_normalized_laplacian(igraph_bool_t dir) { igraph_t g; igraph_matrix_t m; igraph_vector_t vec; igraph_matrix_init(&m, 1, 1); igraph_bool_t ok = 1; /* Undirected graph, no loop or multiple edges */ igraph_ring(&g, 5, dir, 0, 1); igraph_laplacian(&g, &m, 1); ok = ok && check_laplacian(&g, &m); /* Add some loop edges */ igraph_vector_init_real(&vec, 4, 1.0, 1.0, 2.0, 2.0); igraph_add_edges(&g, &vec, 0); igraph_vector_destroy(&vec); igraph_laplacian(&g, &m, 1); ok = ok && check_laplacian(&g, &m); /* Duplicate some edges */ igraph_vector_init_real(&vec, 4, 1.0, 2.0, 3.0, 4.0); igraph_add_edges(&g, &vec, 0); igraph_vector_destroy(&vec); igraph_laplacian(&g, &m, 1); ok = ok && check_laplacian(&g, &m); igraph_destroy(&g); igraph_matrix_destroy(&m); if (ok) printf("OK\n"); return !ok; }
int main() { igraph_t g; igraph_vector_t v; int ret; /* without edges */ igraph_empty(&g, 5, IGRAPH_DIRECTED); igraph_add_vertices(&g, 2, 0); igraph_add_vertices(&g, 3, 0); igraph_add_vertices(&g, 1, 0); igraph_add_vertices(&g, 4, 0); if (igraph_vcount(&g) != 15) { return 1; } igraph_delete_vertices(&g, igraph_vss_1(2)); if (igraph_vcount(&g) != 14) { return 2; } igraph_destroy(&g); igraph_vector_init(&v, 8); VECTOR(v)[0]=0; VECTOR(v)[1]=1; VECTOR(v)[2]=1; VECTOR(v)[3]=2; VECTOR(v)[4]=2; VECTOR(v)[5]=3; VECTOR(v)[6]=2; VECTOR(v)[7]=2; igraph_create(&g, &v, 0, 0); igraph_vector_destroy(&v); /* resize vector */ igraph_delete_vertices(&g, igraph_vss_1(2)); if (igraph_vcount(&g) != 3) { return 3; } if (igraph_ecount(&g) != 1) { return 4; } /* error test */ igraph_set_error_handler(igraph_error_handler_ignore); ret=igraph_delete_vertices(&g, igraph_vss_1(3)); if (ret != IGRAPH_EINVVID) { return 5; } igraph_destroy(&g); return 0; }