int initIgraph(int *m){ igraph_t g; igraph_matrix_t mat; long int i, j; igraph_matrix_init(&mat, numNodos, numNodos); for (i=0; i<numNodos; i++) for (j=0; j<numNodos; j++) MATRIX(mat, i, j) = m[i+numNodos*j]; igraph_i_set_attribute_table(&igraph_cattribute_table); igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_UPPER, 0, /*loops=*/ 1); //print(&g); FILE *stp; stp = fopen("/home/john/git/primAlgorithm/grafo2.gml", "w"); if (stp==0) { printf("Problema abriendo archivo de grafo\n"); return EXIT_FAILURE; } igraph_write_graph_gml(&g, stp, 0, "gml Test"); fclose(stp); igraph_destroy(&g); return EXIT_SUCCESS; }
int main() { igraph_t graph; FILE *ifile = fopen("cattr_bool_bug.graphml", "r"); if (!ifile) { printf("Cannot open input file"); return 1; } igraph_i_set_attribute_table(&igraph_cattribute_table); igraph_read_graph_graphml(&graph, ifile, 0); fclose(ifile); check_attr(&graph, 10); igraph_to_directed(&graph, IGRAPH_TO_DIRECTED_ARBITRARY); check_attr(&graph, 20); if (GAB(&graph, "loops")) { return 2; } igraph_destroy(&graph); return 0; }
int main() { igraph_t g; igraph_vector_t y; /* turn on attribute handling */ igraph_i_set_attribute_table(&igraph_cattribute_table); /* Create a graph, add some attributes and save it as a GraphML file */ igraph_famous(&g, "Petersen"); SETGAS(&g, "name", "Petersen's graph"); SETGAN(&g, "vertices", igraph_vcount(&g)); SETGAN(&g, "edges", igraph_ecount(&g)); igraph_vector_init_seq(&y, 1, igraph_vcount(&g)); SETVANV(&g, "id", &y); igraph_vector_destroy(&y); SETVAS(&g, "name", 0, "foo"); SETVAS(&g, "name", 1, "foobar"); igraph_vector_init_seq(&y, 1, igraph_ecount(&g)); SETEANV(&g, "id", &y); igraph_vector_destroy(&y); SETEAS(&g, "name", 0, "FOO"); SETEAS(&g, "name", 1, "FOOBAR"); igraph_write_graph_gml(&g, stdout, 0, ""); igraph_write_graph_graphml(&g, stdout); igraph_destroy(&g); return 0; }
TEgraphMF::TEgraphMF() { igraph_i_set_attribute_table(&igraph_cattribute_table); cacheValid=false; e=0.1; recalculationDelay=60; defaultBW=1; te_thread= NULL; }
int main() { igraph_i_set_attribute_table(&igraph_cattribute_table); if (test_graph_from_leda_tutorial()) return 1; if (!IGRAPH_FINALLY_STACK_EMPTY) { printf("Finally stack still has %d elements.\n", IGRAPH_FINALLY_STACK_SIZE()); return 4; } return 0; }
int main(int argc, char* argv[]) { if(argc != 2) { printf("USAGE: %s path/to/file.graphml.xml\n", argv[0]); return -1; } char* fileName = argv[1]; igraph_attribute_table_t* oldHandler = igraph_i_set_attribute_table(&igraph_cattribute_table); FILE* graphFile = fopen(fileName, "r"); if(!graphFile) { printf("error opening graph file at %s\n", fileName); return -2; } igraph_t graph; time_t start = time(NULL); int r = igraph_read_graph_graphml(&graph, graphFile, 0); time_t end = time(NULL); fclose(graphFile); if(r != IGRAPH_SUCCESS) { printf("error loading graph file at %s\n", fileName); r = -3; } else { printf("successfully loaded graph file at %s in %li seconds\n", fileName, (long int)(end-start)); r = 0; } printf("graph has %li vertices and %li edges\n", (long int)igraph_vcount(&graph), (long int)igraph_ecount(&graph)); igraph_integer_t largestCliqueSize = 0; start = time(NULL); r = igraph_clique_number(&graph, &largestCliqueSize); end = time(NULL); if(r != IGRAPH_SUCCESS) { printf("error computing igraph_clique_number\n"); r = -4; } else { printf("igraph_clique_number = %i in %li seconds\n", (int) largestCliqueSize, (long int)(end-start)); r = 0; } start = time(NULL); igraph_destroy(&graph); end = time(NULL); printf("igraph_destroy finished in %li seconds\n", (long int)end-start); return r; }
int main() { igraph_t g; igraph_strvector_t names; igraph_i_set_attribute_table(&igraph_cattribute_table); /* save a simple ring graph */ igraph_ring(&g, 10, IGRAPH_DIRECTED, 0 /* mutual */, 1 /* circular */); igraph_write_graph_pajek(&g, stdout); /* add some vertex attributes */ igraph_strvector_init(&names, 0); igraph_strvector_add(&names, "A"); igraph_strvector_add(&names, "B"); igraph_strvector_add(&names, "C"); igraph_strvector_add(&names, "D"); igraph_strvector_add(&names, "E"); igraph_strvector_add(&names, "F"); igraph_strvector_add(&names, "G"); igraph_strvector_add(&names, "H"); igraph_strvector_add(&names, "I"); igraph_strvector_add(&names, "J"); SETVASV(&g, "id", &names); igraph_strvector_destroy(&names); /* save the graph with vertex names */ igraph_write_graph_pajek(&g, stdout); igraph_strvector_init(&names, 0); igraph_strvector_add(&names, "square"); igraph_strvector_add(&names, "square"); igraph_strvector_add(&names, "square"); igraph_strvector_add(&names, "square"); igraph_strvector_add(&names, "escaping spaces"); igraph_strvector_add(&names, "square"); igraph_strvector_add(&names, "square"); igraph_strvector_add(&names, "escaping \\backslashes\\"); igraph_strvector_add(&names, "square"); igraph_strvector_add(&names, "escaping \"quotes\""); SETVASV(&g, "shape", &names); igraph_strvector_destroy(&names); /* save the graph with escaped shapes */ igraph_write_graph_pajek(&g, stdout); /* destroy the graph */ igraph_destroy(&g); return 0; }
int main() { igraph_t g; /* init the attributes in igraph */ igraph_i_set_attribute_table(&igraph_cattribute_table); /* read a graph on stdin */ assert(ggen_read_graph(&g,stdin) == 0); /* output it to stdout */ assert(ggen_write_graph(&g,stdout) == 0); return 0; }
int GraphRepresentation::buildIGraphTopology() { int source_vertex_id, destination_vertex_id; igraph_i_set_attribute_table(&igraph_cattribute_table); igraph_empty(&igraph, 0, true); //cout << "iGraph: number of nodes: " << dm->number_of_nodes << endl; //cout << "iGraph: number number_of_connections nodes: " << dm->number_of_connections << endl; for (int i = 0; i < dm->network_nodes.size(); i++) { NetworkNode *nn = dm->network_nodes[i]; for (int j = 0; j < nn->connections.size(); j++) { NetworkConnection *nc = nn->connections[j]; map <string, int>::iterator index_it; /*find that node - if exists*/ index_it = reverse_node_index.find(nc->src_label); /*check if the source node exists in the reverse index*/ if (index_it == reverse_node_index.end()) { /*it does not exist...add it*/ source_vertex_id = igraph_vcount(&igraph); igraph_add_vertices(&igraph, 1, 0); reverse_node_index.insert(pair<string, int>(nc->src_label, source_vertex_id)); igraph_cattribute_VAS_set(&igraph, "NODEID", source_vertex_id, nc->src_label.c_str()); //cout << "added node " << nc->src_label << " in the igraph" << endl; } else { source_vertex_id = (*index_it).second; } index_it = reverse_node_index.find(nc->dst_label); /*check if the destination node exists in the reverse index*/ if (index_it == reverse_node_index.end()) { /*it does not exist...add it*/ destination_vertex_id = igraph_vcount(&igraph); igraph_add_vertices(&igraph, 1, 0); reverse_node_index.insert(pair<string, int>(nc->dst_label, destination_vertex_id)); igraph_cattribute_VAS_set(&igraph, "NODEID", destination_vertex_id, nc->dst_label.c_str()); //cout << "added node " << nc->dst_label << " in the igraph" << endl; } else { destination_vertex_id = (*index_it).second; } /*add an edge in the graph*/ igraph_add_edge(&igraph, source_vertex_id, destination_vertex_id); igraph_cattribute_EAS_set(&igraph, "LID", igraph_ecount(&igraph) - 1, nc->LID.to_string().c_str()); reverse_edge_index.insert(pair<string, int>(nc->LID.to_string(), igraph_ecount(&igraph) - 1)); } } for (int i = 0; i < dm->network_nodes.size(); i++) { NetworkNode *nn = dm->network_nodes[i]; igraph_cattribute_VAS_set(&igraph, "iLID", i, nn->iLid.to_string().c_str()); } }
int main() { igraph_t graph; igraph_t full, tree; igraph_hrg_t hrg; igraph_t dendrogram; // int i, j; // igraph_vector_t neis; igraph_rng_seed(igraph_rng_default(), 42); // We need attributes igraph_i_set_attribute_table(&igraph_cattribute_table); igraph_full(&full, 10, /*directed=*/ 0, /*loops=*/ 0); igraph_tree(&tree, 15, /*children=*/ 2, /*type=*/ IGRAPH_TREE_UNDIRECTED); igraph_disjoint_union(&graph, &full, &tree); igraph_add_edge(&graph, 0, 10); igraph_destroy(&full); igraph_destroy(&tree); // Fit igraph_hrg_init(&hrg, igraph_vcount(&graph)); igraph_hrg_fit(&graph, &hrg, /*start=*/ 0, /*steps=*/ 0); // Create a graph from it igraph_hrg_dendrogram(&dendrogram, &hrg); // Print the tree, with labels // igraph_vector_init(&neis, 0); // for (i=0; i<igraph_vcount(&graph)-1; i++) { // printf("Vertex # %2i, ", (int) (i+igraph_vcount(&graph))); // igraph_neighbors(&dendrogram, &neis, i+igraph_vcount(&graph), IGRAPH_OUT); // printf("left: # %2i, right: # %2i, ", (int) VECTOR(neis)[0], // (int) VECTOR(neis)[1]); // printf("prob: %6.2g\n", // VAN(&dendrogram, "probability", i+igraph_vcount(&graph))); // } // igraph_vector_destroy(&neis); igraph_destroy(&dendrogram); igraph_hrg_destroy(&hrg); igraph_destroy(&graph); return 0; }
int* readGrafo(){ int *grafo; igraph_matrix_t gMatrix; igraph_t g; igraph_i_set_attribute_table(&igraph_cattribute_table); FILE *ifile; ifile=fopen("/home/john/git/primAlgorithm/celegansneural.gml"/*"/home/john/git/primAlgorithm/grafo.gml"*/, "r"); if (ifile==0) { printf("Problema abriendo archivo de grafo\n"); return NULL; } igraph_read_graph_gml(&g, ifile); fclose(ifile); numNodos = igraph_vcount(&g); grafo = malloc(numNodos*numNodos*sizeof(int)); igraph_matrix_init(&gMatrix,numNodos,numNodos); igraph_get_adjacency(&g,&gMatrix,IGRAPH_GET_ADJACENCY_BOTH,1); igraph_vector_t el; int ii, jj, n; igraph_vector_init(&el, 0); igraph_get_edgelist(&g, &el, 0); n = igraph_ecount(&g); memset(grafo,INT_MAX2,numNodos*numNodos*sizeof(int)); for (ii=0, jj=0; ii<n; ii++, jj+=2) { grafo[((long)VECTOR(el)[jj])+numNodos*((long)VECTOR(el)[jj+1])] = (int)EAN(&g, "weight", ii); grafo[((long)VECTOR(el)[jj+1])+numNodos*((long)VECTOR(el)[jj])] = (int)EAN(&g, "weight", ii); } printf("\nNumero de nodos %d",numNodos); igraph_vector_destroy(&el); igraph_destroy(&g); return grafo; }
int main() { igraph_t g; FILE *ifile; int i, n; /* turn on attribute handling */ igraph_i_set_attribute_table(&igraph_cattribute_table); ifile=fopen("bipartite.net", "r"); if (!ifile) { return 5; } igraph_read_graph_pajek(&g, ifile); fclose(ifile); if (igraph_vcount(&g) != 13 || igraph_ecount(&g) != 11 || igraph_is_directed(&g)) { return 6; } for (i=0, n=igraph_vcount(&g); i<n; i++) { printf("%i ", (int) VAN(&g, "type", i)); } igraph_destroy(&g); return 0; }
static void fit_rvine_trees(igraph_t **trees, const gsl_matrix *data, const dml_vine_weight_t weight, const dml_vine_trunc_t trunc, const dml_copula_indeptest_t indeptest, const double indeptest_level, const dml_copula_type_t *types, const size_t types_size, const dml_copula_select_t select, const gsl_rng *rng) { size_t m, n; igraph_t *graph; igraph_vector_t *graph_weight; dml_copula_t *copula; gsl_vector *x; igraph_integer_t e; // Edge id. igraph_integer_t a, aa, ab, b, ba, bb; // Vertex id. gsl_vector *u = NULL, *v = NULL; igraph_integer_t Cea, Ceb; gsl_vector_short *Ue, *Ua, *Ub; size_t k; dml_measure_t *measure; double tree_aic, copula_aic; gsl_permutation *perm, *rank, *u_rank = NULL, *v_rank = NULL; igraph_i_set_attribute_table(&igraph_cattribute_table); m = data->size1; n = data->size2; graph = g_malloc(sizeof(igraph_t)); graph_weight = g_malloc(sizeof(igraph_vector_t)); perm = gsl_permutation_alloc(m); for (k = 0; k < n - 1; k++) { // Tree index. if (k == 0) { igraph_full(graph, n, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS); // Assign the observations to the nodes. for (size_t i = 0; i < n; i++) { // Variable and node index. x = gsl_vector_alloc(m); gsl_matrix_get_col(x, data, i); // Results of the h-function of the copula assigned to the // edge that corresponds to this vertex in the previous tree. // h for the h-function with its arguments in order and // hrev for the h-function with its arguments reversed. In the // first tree both are equal to the observations of the // corresponding variable, in the rest of the trees they differ. SETVAP(graph, "h", i, x); SETVAP(graph, "hrev", i, x); gsl_sort_vector_index(perm, x); rank = gsl_permutation_alloc(m); gsl_permutation_inverse(rank, perm); // Ranks of the h and hrev vectors. SETVAP(graph, "hrank", i, rank); SETVAP(graph, "hrevrank", i, rank); } for (e = 0; e < igraph_ecount(graph); e++) { igraph_edge(graph, e, &a, &b); // Variables "connected" by this edge. Ue = gsl_vector_short_calloc(n); gsl_vector_short_set(Ue, a, 1); gsl_vector_short_set(Ue, b, 1); SETEAP(graph, "Ue", e, Ue); // Conditioned set. SETEAN(graph, "Cea", e, a + 1); SETEAN(graph, "Ceb", e, b + 1); Cea = EAN(graph, "Cea", e); Ceb = EAN(graph, "Ceb", e); // Calculate the weight of the edge. u = VAP(graph, "h", a); v = VAP(graph, "h", b); u_rank = VAP(graph, "hrank", a); v_rank = VAP(graph, "hrank", b); // The conditioned set is ordered to make the order of the // arguments in the bivariate copulas unique as suggested in // Czado, C. (2010) Pair-Copula Constructions of Multivariate // Copulas. In Jaworski, P. and Durante, F. and Hardle, W. K. // and Rychlik, T. (eds.) Copula Theory and Its Applications, // Springer-Verlag, 93-109. if (Cea < Ceb) { rvine_set_weight(graph, weight, e, u, v, u_rank, v_rank); } else { rvine_set_weight(graph, weight, e, v, u, v_rank, u_rank); } } } else { igraph_empty(graph, n - k, IGRAPH_UNDIRECTED); // Adding all "possible" edges. for (a = 0; a < igraph_vcount(graph) - 1; a++) { for (b = a + 1; b < igraph_vcount(graph); b++) { igraph_edge(trees[k - 1], a, &aa, &ab); igraph_edge(trees[k - 1], b, &ba, &bb); // Checking the proximity condition. if (aa == ba || aa == bb || ab == ba || ab == bb) { igraph_add_edge(graph, a, b); igraph_get_eid(graph, &e, a, b, IGRAPH_UNDIRECTED, 1); // Variables "connected" by this edge and conditioned set. Ua = EAP(trees[k - 1], "Ue", a); Ub = EAP(trees[k - 1], "Ue", b); Ue = gsl_vector_short_calloc(n); for (size_t i = 0; i < n; i++) { gsl_vector_short_set(Ue, i, gsl_vector_short_get(Ua, i) | gsl_vector_short_get(Ub, i)); if (gsl_vector_short_get(Ua, i) && !gsl_vector_short_get(Ub, i)) { SETEAN(graph, "Cea", e, i + 1); } if (gsl_vector_short_get(Ub, i) && !gsl_vector_short_get(Ua, i)) { SETEAN(graph, "Ceb", e, i + 1); } } SETEAP(graph, "Ue", e, Ue); } } } // Compute pseudo-observations and edge weights. for (a = 0; a < igraph_vcount(graph); a++) { // See the comment in the code for the first tree. SETVAP(graph, "h", a, NULL); SETVAP(graph, "hrev", a, NULL); SETVAP(graph, "hrank", a, NULL); SETVAP(graph, "hrevrank", a, NULL); } for (e = 0; e < igraph_ecount(graph); e++) { igraph_edge(graph, e, &a, &b); Cea = EAN(graph, "Cea", e); Ceb = EAN(graph, "Ceb", e); // Assign u and u_rank. if ((Cea == EAN(trees[k - 1], "Cea", a) && (EAN(trees[k - 1], "Cea", a) < EAN(trees[k - 1], "Ceb", a))) || (Cea != EAN(trees[k - 1], "Cea", a) && (EAN(trees[k - 1], "Cea", a) > EAN(trees[k - 1], "Ceb", a)))) { u = VAP(graph, "h", a); if (u == NULL) { copula = EAP(trees[k - 1], "copula", a); measure = EAP(trees[k - 1], "measure", a); u = gsl_vector_alloc(m); dml_copula_h(copula, measure->x, measure->y, u); SETVAP(graph, "h", a, u); gsl_sort_vector_index(perm, u); rank = gsl_permutation_alloc(m); gsl_permutation_inverse(rank, perm); SETVAP(graph, "hrank", a, rank); } u_rank = VAP(graph, "hrank", a); } if ((Cea == EAN(trees[k - 1], "Cea", a) && (EAN(trees[k - 1], "Cea", a) > EAN(trees[k - 1], "Ceb", a))) || (Cea != EAN(trees[k - 1], "Cea", a) && (EAN(trees[k - 1], "Cea", a) < EAN(trees[k - 1], "Ceb", a)))) { u = VAP(graph, "hrev", a); if (u == NULL) { copula = EAP(trees[k - 1], "copula", a); measure = EAP(trees[k - 1], "measure", a); u = gsl_vector_alloc(m); dml_copula_h(copula, measure->y, measure->x, u); SETVAP(graph, "hrev", a, u); gsl_sort_vector_index(perm, u); rank = gsl_permutation_alloc(m); gsl_permutation_inverse(rank, perm); SETVAP(graph, "hrevrank", a, rank); } u_rank = VAP(graph, "hrevrank", a); } // Assign v and v_rank. if ((Ceb == EAN(trees[k - 1], "Cea", b) && (EAN(trees[k - 1], "Cea", b) < EAN(trees[k - 1], "Ceb", b))) || (Ceb != EAN(trees[k - 1], "Cea", b) && (EAN(trees[k - 1], "Cea", b) > EAN(trees[k - 1], "Ceb", b)))) { v = VAP(graph, "h", b); if (v == NULL) { copula = EAP(trees[k - 1], "copula", b); measure = EAP(trees[k - 1], "measure", b); v = gsl_vector_alloc(m); dml_copula_h(copula, measure->x, measure->y, v); SETVAP(graph, "h", b, v); gsl_sort_vector_index(perm, v); rank = gsl_permutation_alloc(m); gsl_permutation_inverse(rank, perm); SETVAP(graph, "hrank", b, rank); } v_rank = VAP(graph, "hrank", b); } if ((Ceb == EAN(trees[k - 1], "Cea", b) && (EAN(trees[k - 1], "Cea", b) > EAN(trees[k - 1], "Ceb", b))) || (Ceb != EAN(trees[k - 1], "Cea", b) && (EAN(trees[k - 1], "Cea", b) < EAN(trees[k - 1], "Ceb", b)))) { v = VAP(graph, "hrev", b); if (v == NULL) { copula = EAP(trees[k - 1], "copula", b); measure = EAP(trees[k - 1], "measure", b); v = gsl_vector_alloc(m); dml_copula_h(copula, measure->y, measure->x, v); SETVAP(graph, "hrev", b, v); gsl_sort_vector_index(perm, v); rank = gsl_permutation_alloc(m); gsl_permutation_inverse(rank, perm); SETVAP(graph, "hrevrank", b, rank); } v_rank = VAP(graph, "hrevrank", b); } // Set the weight of the edge. The arguments are ordered here. // The order determines the x and y fields of measure. if (Cea < Ceb) { rvine_set_weight(graph, weight, e, u, v, u_rank, v_rank); } else { rvine_set_weight(graph, weight, e, v, u, v_rank, u_rank); } } } // Compute the minimum weight spanning tree. trees[k] = g_malloc(sizeof(igraph_t)); igraph_vector_init(graph_weight, igraph_ecount(graph)); EANV(graph, "weight", graph_weight); igraph_minimum_spanning_tree_prim(graph, trees[k], graph_weight); igraph_vector_destroy(graph_weight); tree_aic = 0; for (e = 0; e < igraph_ecount(trees[k]); e++) { igraph_edge(trees[k], e, &a, &b); Cea = EAN(trees[k], "Cea", e); Ceb = EAN(trees[k], "Ceb", e); measure = EAP(trees[k], "measure", e); // Assign a bivariate copula to the edge. if (Cea < Ceb) { copula = dml_copula_select(measure->x, measure->y, measure, indeptest, indeptest_level, types, types_size, select, rng); // Get information for the truncation of the vine. if (trunc == DML_VINE_TRUNC_AIC) { dml_copula_aic(copula, measure->x, measure->y, &copula_aic); tree_aic += copula_aic; } } else { copula = dml_copula_select(measure->y, measure->x, measure, indeptest, indeptest_level, types, types_size, select, rng); // Get information for the truncation of the vine. if (trunc == DML_VINE_TRUNC_AIC) { dml_copula_aic(copula, measure->y, measure->x, &copula_aic); tree_aic += copula_aic; } } SETEAP(trees[k], "copula", e, copula); } igraph_destroy(graph); // Check if the vine should be truncated. if (trunc == DML_VINE_TRUNC_AIC && tree_aic >= 0) { // Free the memory used for the last tree. rvine_tree_cleanup(trees[k]); for (e = 0; e < igraph_ecount(trees[k]); e++) { copula = EAP(trees[k], "copula", e); dml_copula_free(copula); } igraph_destroy(trees[k]); g_free(trees[k]); trees[k] = NULL; break; } if (k > 0) rvine_tree_cleanup(trees[k - 1]); } // Cleanup the last tree if the vine was completely estimated. // If the vine was truncated, the last tree will be freed in // the function vine_fit_rvine, because the rvine_trees_to_vine // function needs some attributes of its edges. if (k == n - 1) { rvine_tree_cleanup(trees[n - 2]); } g_free(graph_weight); g_free(graph); gsl_permutation_free(perm); }
static void rvine_trees_to_vine(dml_vine_t *vine, igraph_t **trees) { size_t n = vine->dim; size_t *order_inv; gsl_vector_short *B; igraph_integer_t Cea, Ceb; size_t x = 0, x_hat = 0, x_hat_hat = 0; // Initialized to avoid GCC warnings. dml_copula_t *copula = NULL; // Initialized to avoid GCC warnings. igraph_integer_t e; // Edge id. igraph_integer_t a, b, aa, ab, ba, bb; // Vertex id. igraph_t **last_trees = NULL; igraph_t *graph = NULL; gsl_vector_short *Ue, *Ua, *Ub; // Set the number of trees of the vines. vine->trees = n - 1; while (trees[vine->trees - 1] == NULL) vine->trees--; // Nothing to do for vines without trees. if (vine->trees == 0) return; // Selecting a structure for the trees that were truncated. // Is this really necessary? Think a better solution. if (vine->trees != n - 1) { igraph_i_set_attribute_table(&igraph_cattribute_table); last_trees = g_malloc_n(n - 1 - vine->trees, sizeof(igraph_t *)); graph = g_malloc(sizeof(igraph_t)); for (size_t k = vine->trees; k < n - 1; k++) { // Tree index. igraph_empty(graph, n - k, IGRAPH_UNDIRECTED); // Adding all "possible" edges. for (a = 0; a < igraph_vcount(graph) - 1; a++) { for (b = a + 1; b < igraph_vcount(graph); b++) { // Checking the proximity condition. igraph_edge(k <= vine->trees ? trees[k - 1] : last_trees[k - 1 - vine->trees], a, &aa, &ab); igraph_edge(k <= vine->trees ? trees[k - 1] : last_trees[k - 1 - vine->trees], b, &ba, &bb); if (aa == ba || aa == bb || ab == ba || ab == bb) { igraph_add_edge(graph, a, b); igraph_get_eid(graph, &e, a, b, IGRAPH_UNDIRECTED, 1); // Variables "connected" by this edge and conditioned set. Ua = EAP(k <= vine->trees ? trees[k - 1] : last_trees[k - 1 - vine->trees], "Ue", a); Ub = EAP(k <= vine->trees ? trees[k - 1] : last_trees[k - 1 - vine->trees], "Ue", b); Ue = gsl_vector_short_calloc(n); for (size_t i = 0; i < n; i++) { gsl_vector_short_set(Ue, i, gsl_vector_short_get(Ua, i) | gsl_vector_short_get(Ub, i)); if (gsl_vector_short_get(Ua, i) && !gsl_vector_short_get(Ub, i)) { SETEAN(graph, "Cea", e, i + 1); } if (gsl_vector_short_get(Ub, i) && !gsl_vector_short_get(Ua, i)) { SETEAN(graph, "Ceb", e, i + 1); } } SETEAP(graph, "Ue", e, Ue); } } } // Compute the minimum weight spanning tree. last_trees[k - vine->trees] = g_malloc(sizeof(igraph_t)); igraph_minimum_spanning_tree_unweighted(graph, last_trees[k - vine->trees]); igraph_destroy(graph); } } order_inv = g_malloc0_n(n, sizeof(size_t)); B = gsl_vector_short_calloc(n); // for loop in line 2. for (size_t i = 0; i < n - 1; i++) { if (trees[n - i - 2] == NULL) { for (e = 0; e < igraph_ecount(last_trees[n - i - 2 - vine->trees]); e++) { x = EAN(last_trees[n - i - 2 - vine->trees], "Cea", e); x_hat = EAN(last_trees[n - i - 2 - vine->trees], "Ceb", e); if (!gsl_vector_short_get(B, x - 1) && !gsl_vector_short_get(B, x_hat - 1)) { x_hat = 0; copula = NULL; break; } } } else { for (e = 0; e < igraph_ecount(trees[n - i - 2]); e++) { x = EAN(trees[n - i - 2], "Cea", e); x_hat = EAN(trees[n - i - 2], "Ceb", e); if (!gsl_vector_short_get(B, x - 1) && !gsl_vector_short_get(B, x_hat - 1)) { copula = EAP(trees[n - i - 2], "copula", e); break; } } } // Line 4. gsl_vector_short_set(B, x - 1, 1); vine->order[n - i - 1] = x - 1; order_inv[x - 1] = n - i; vine->matrix[i][i] = x; vine->matrix[i + 1][i] = x_hat; vine->copulas[i + 1][i] = copula; // for loop in line 5. for (size_t k = i + 2; k < n; k++) { if (trees[n - k - 1] != NULL) { for (e = 0; e < igraph_ecount(trees[n - k - 1]); e++) { Cea = EAN(trees[n - k - 1], "Cea", e); Ceb = EAN(trees[n - k - 1], "Ceb", e); if (x == Cea) { x_hat_hat = Ceb; if (!gsl_vector_short_get(B, x_hat_hat - 1)) { // The pseudocode of the algorithm does not included // this check. Invalid matrices were generated when // x_hat_hat is set to an index already assigned // to a diagonal entry. copula = EAP(trees[n - k - 1], "copula", e); break; } } else if (x == Ceb) { x_hat_hat = Cea; if (!gsl_vector_short_get(B, x_hat_hat - 1)) { // Ibdem to the previous comment. copula = EAP(trees[n - k - 1], "copula", e); break; } } } vine->matrix[k][i] = x_hat_hat; vine->copulas[k][i] = copula; } } } for (size_t i = 0; i < n; i++) { if (!gsl_vector_short_get(B, i)) { vine->matrix[n - 1][n - 1] = i + 1; vine->order[0] = i; order_inv[i] = 1; break; } } // Reorder the variables. The simulation algorithm assumes that the // diagonal entries of the R-vine matrix are ordered from n to 1. for (size_t i = 0; i < n; i++) { for (size_t j = 0; j <= i; j++) { if (vine->matrix[i][j] > 0) { vine->matrix[i][j] = order_inv[vine->matrix[i][j] - 1]; } } } if (vine->trees != n - 1) { for (size_t i = 0; i < n - 1 - vine->trees; i++) { for (e = 0; e < igraph_ecount(last_trees[i]); e++) { Ue = EAP(last_trees[i], "Ue", e); gsl_vector_short_free(Ue); } DELEA(last_trees[i], "Ue"); igraph_destroy(last_trees[i]); g_free(last_trees[i]); } g_free(last_trees); g_free(graph); } g_free(order_inv); gsl_vector_short_free(B); }
int main(int argc, char* argv[]) { igraph_i_set_attribute_table(&igraph_cattribute_table); char * in_graph_fn; char * out_graph_fn; if (argc < 3) { printf("[ERROR] usage: mm-writer in_graph_fn out_graph_fn\n"); exit(-1); } else { in_graph_fn = &argv[1][0]; out_graph_fn = &argv[2][0]; } igraph_t g; FILE *ifile, *ofile; ifile = fopen(in_graph_fn, "r"); if (ifile == 0) { return 10; } igraph_read_graph_graphml(&g, ifile, 0); fclose(ifile); igraph_to_directed(&g, IGRAPH_TO_DIRECTED_ARBITRARY); printf("The graph stats:\n"); printf("Vertices: %li\n", (long int) igraph_vcount(&g)); printf("Edges: %li\n", (long int) igraph_ecount(&g)); printf("Directed: %i\n", (int) igraph_is_directed(&g)); ofile = fopen(out_graph_fn, "w"); if (ofile == 0) { return 10; } // Write MM format fprintf(ofile, "%li %li %li\n", (long int) igraph_vcount(&g), (long int) igraph_vcount(&g), (long int) igraph_ecount(&g)); igraph_integer_t to; igraph_integer_t from; igraph_integer_t eid; igraph_real_t weight; for (eid = 0; eid < (long int) igraph_ecount(&g); eid++) { igraph_edge(&g, eid, &from, &to); weight = igraph_cattribute_EAN(&g, "weight",eid); // TODO: time fprintf(ofile, "%i %i %f\n", from, to, weight); //printf("Edge %i => %i --> %i\n", eid, from, to); //printf("Edge %i has weight %f\n", eid, igraph_cattribute_EAN(&g, "weight",eid)); // TODO: time } // For all. TODO: time #if 0 igraph_es_t eids; igraph_es_all(&eids, IGRAPH_EDGEORDER_ID); // Order edges igraph_vector_t result; igraph_vector_init(&result, (int long) igraph_ecount(&g)); igraph_cattribute_EANV(&g, "weight", eids, &result); igraph_integer_t i; for (i = 0; i < (int long) igraph_ecount(&g); i++) printf("Edge %i value: %f\n", i, VECTOR(result)[i]); // Free memory igraph_es_destroy(&eids); igraph_vector_destroy(&result); #endif igraph_destroy(&g); fclose(ofile); return 0; }
void LayoutBuilder::produce(AbstractPetriNetBuilder *builder){ if(!attrTableAttached){ igraph_i_set_attribute_table(&igraph_cattribute_table); attrTableAttached = true; } size_t V = places.size() + transitions.size(); size_t E = inArcs.size() + outArcs.size(); igraph_t graph; // Create a directed graph igraph_empty(&graph, V, true); // Create vector with all edges igraph_vector_t edges; igraph_vector_init(&edges, E * 2); // Add edges to vector int i = 0; for(ArcIter it = inArcs.begin(); it != inArcs.end(); it++){ VECTOR(edges)[i++] = numberFromName(it->start); VECTOR(edges)[i++] = numberFromName(it->end); } for(ArcIter it = outArcs.begin(); it != outArcs.end(); it++){ VECTOR(edges)[i++] = numberFromName(it->start); VECTOR(edges)[i++] = numberFromName(it->end); } // Add the edges to graph igraph_add_edges(&graph, &edges, 0); // Delete the vector with edges igraph_vector_destroy(&edges); // Arrays to store result in double posx[V]; double posy[V]; // Provide current positions, if they're used at all if(startFromCurrentPositions){ int i = 0; for(PlaceIter it = places.begin(); it != places.end(); it++){ posx[i] = it->x; posy[i] = it->y; igraph_cattribute_VAN_set(&graph, "id", i, i); i++; } for(TransitionIter it = transitions.begin(); it != transitions.end(); it++){ posx[i] = it->x; posy[i] = it->y; igraph_cattribute_VAN_set(&graph, "id", i, i); i++; } } // Decompose the graph, and layout subgraphs induvidually igraph_vector_ptr_t subgraphs; igraph_vector_ptr_init(&subgraphs, 0); igraph_decompose(&graph, &subgraphs, IGRAPH_WEAK, -1, 0); // Offset for places subgraphs double offsetx = 0; double offsety = 0; // Layout, translate and extract results for each subgraph for(int i = 0; i < igraph_vector_ptr_size(&subgraphs); i++){ //Get the subgraph igraph_t* subgraph = (igraph_t*)VECTOR(subgraphs)[i]; // Allocate result matrix igraph_matrix_t sublayout; igraph_matrix_init(&sublayout, 0, 0); // Vertex selector and iterator igraph_vs_t vs; igraph_vit_t vit; // Select all and create iterator igraph_vs_all(&vs); igraph_vit_create(subgraph, vs, &vit); // Initialize sublayout, using original positions if(startFromCurrentPositions){ // Count vertices int vertices = 0; // Iterator over vertices to count them, hacked but it works while(!IGRAPH_VIT_END(vit)){ vertices++; IGRAPH_VIT_NEXT(vit); } //Reset vertex iterator IGRAPH_VIT_RESET(vit); // Resize sublayout igraph_matrix_resize(&sublayout, vertices, 2); // Iterator over vertices while(!IGRAPH_VIT_END(vit)){ int subindex = (int)IGRAPH_VIT_GET(vit); int index = (int)igraph_cattribute_VAN(subgraph, "id", subindex); MATRIX(sublayout, subindex, 0) = posx[index]; MATRIX(sublayout, subindex, 1) = posy[index]; IGRAPH_VIT_NEXT(vit); } //Reset vertex iterator IGRAPH_VIT_RESET(vit); } igraph_layout_kamada_kawai(subgraph, &sublayout, 1000, ((double)V)/4.0, 10, 0.99, V*V, startFromCurrentPositions); // Other layout algorithms with reasonable parameters //igraph_layout_kamada_kawai(subgraph, &sublayout, 1000, ((double)V)/4.0, 10, 0.99, V*V, startFromCurrentPositions); //igraph_layout_grid_fruchterman_reingold(subgraph, &sublayout, 500, V, V*V, 1.5, V*V*V, V*V/4, startFromCurrentPositions); //igraph_layout_fruchterman_reingold(subgraph, &sublayout, 500, V, V*V, 1.5, V*V*V, startFromCurrentPositions, NULL); //igraph_layout_lgl(subgraph, &sublayout, 150, V, V*V, 1.5, V*V*V, sqrt(V), -1); //Find min and max values: double minx = DBL_MAX, miny = DBL_MAX, maxx = -DBL_MAX, maxy = -DBL_MAX; //Iterator over all vertices while(!IGRAPH_VIT_END(vit)){ int subindex = (int)IGRAPH_VIT_GET(vit); double x = MATRIX(sublayout, subindex, 0) * factor; double y = MATRIX(sublayout, subindex, 1) * factor; minx = minx < x ? minx : x; miny = miny < y ? miny : y; maxx = maxx > x ? maxx : x; maxy = maxy > y ? maxy : y; IGRAPH_VIT_NEXT(vit); } //Reset vertex iterator IGRAPH_VIT_RESET(vit); // Compute translation double tx = margin - minx; double ty = margin - miny; // Decide whether to put it below or left of current content if(maxx - minx + offsetx < maxy - miny + offsety){ tx += offsetx; offsetx += maxx - minx + margin; if(offsety < maxy - miny + margin) offsety = maxy - miny + margin; }else{ ty += offsety; offsety += maxy - miny + margin; if(offsetx < maxx - minx + margin) offsetx = maxx - minx + margin; } // Translate and extract results while(!IGRAPH_VIT_END(vit)){ int subindex = (int)IGRAPH_VIT_GET(vit); int index = (int)igraph_cattribute_VAN(subgraph, "id", subindex); double x = MATRIX(sublayout, subindex, 0) * factor; double y = MATRIX(sublayout, subindex, 1) * factor; posx[index] = x + tx; posy[index] = y + ty; IGRAPH_VIT_NEXT(vit); } // Destroy iterator and selector igraph_vit_destroy(&vit); igraph_vs_destroy(&vs); // Destroy the sublayout igraph_matrix_destroy(&sublayout); // Destroy subgraph igraph_destroy(subgraph); free(VECTOR(subgraphs)[i]); } // Remove the attributes igraph_cattribute_remove_v(&graph, "id"); // Destroy the graph igraph_destroy(&graph); // Insert results i = 0; for(PlaceIter it = places.begin(); it != places.end(); it++){ it->x = posx[i]; it->y = posy[i]; i++; } for(TransitionIter it = transitions.begin(); it != transitions.end(); it++){ it->x = posx[i]; it->y = posy[i]; i++; } // Produce variables for(VarIter it = vars.begin(); it != vars.end(); it++) builder->addVariable(it->name, it->initialValue, it->range); for(BoolVarIter it = boolVars.begin(); it != boolVars.end(); it++) builder->addBoolVariable(it->name, it->initialValue); for(PlaceIter it = places.begin(); it != places.end(); it++) builder->addPlace(it->name, it->tokens, it->x, it->y); for(TransitionIter it = transitions.begin(); it != transitions.end(); it++) builder->addTransition(it->name, it->conditions, it->assignments, it->x, it->y); for(ArcIter it = inArcs.begin(); it != inArcs.end(); it++) builder->addInputArc(it->start, it->end, it->weight); for(ArcIter it = outArcs.begin(); it != outArcs.end(); it++) builder->addInputArc(it->start, it->end, it->weight); //Reset builder state (just in case some idoit decides to reuse it! vars.clear(); boolVars.clear(); places.clear(); transitions.clear(); inArcs.clear(); outArcs.clear(); }
int main(int argc, char** argv) { int response; igraph_t graph; igraph_vector_ptr_t complist; iclust_collection * collection = NULL; time_t time_start, time_end; /* turn on attribute handling */ igraph_i_set_attribute_table(&igraph_cattribute_table); double minimal_weight; unsigned int maximal_steps_delimieter; char graphncol[1024], logconfig[1024]; Config *cfg = ConfigNew(); const char * configuration = getopt_configfile(argc, argv, "./graphtocluster.conf"); massert((ConfigReadFile(configuration, &cfg) == CONFIG_OK), "Configuration file is not readable"); ConfigReadString(cfg, "sources", "graphncol", graphncol, sizeof(graphncol), 0); ConfigReadString(cfg, "sources", "logconfig", logconfig, sizeof(logconfig), 0); ConfigReadDouble(cfg, "limits", "minimal_weight", &minimal_weight, 0); ConfigReadUnsignedInt(cfg, "limits", "maximal_steps_delimieter", &maximal_steps_delimieter, 1); massert((maximal_steps_delimieter > 0), "Delimiter can not be equal to zero"); ConfigFree(cfg); logger_init(logconfig, "graphtocluster"); logger_info("File:\t configuration %s", configuration); logger_info("File:\t configuration logger %s", logconfig); logger_info("File:\t ncol graph source %s", graphncol); logger_info("Min:\t edge weight %f", minimal_weight); logger_info("Max:\t step delimeter %u", maximal_steps_delimieter); FILE *graph_source = fopen(graphncol, "r"); response = igraph_read_graph_ncol(&graph, graph_source, NULL, true, IGRAPH_ADD_WEIGHTS_YES, 0); massert((response == IGRAPH_SUCCESS), "Can not read a graph"); logger_info("Count:\t edges at start: %d", igraph_ecount(&graph)); fclose(graph_source); time(&time_start); igraph_edges_remove_by(&graph, "weight", minimal_weight, double_lt); time(&time_end); logger_info("Time:\t remove edges: %f", difftime(time_end, time_start)); logger_info("Count:\t edges after remove: %d", igraph_ecount(&graph)); response = igraph_vector_ptr_init(&complist, 0); massert((response == IGRAPH_SUCCESS), "Can not initialize vector pointer"); response = igraph_decompose(&graph, &complist, IGRAPH_WEAK, -1, 0); massert((response == IGRAPH_SUCCESS), "Can not decompose graph"); unsigned int n = igraph_vector_ptr_size(&complist); collection = iclust_collection_new(); massert((collection != NULL), "Cluster collection object can not be empty"); time(&time_start); for (unsigned int i = 0; i < n; i++) { igraph_t *subgraph = VECTOR(complist)[i]; massert((subgraph != NULL), "Subgraph object can not be empty"); iclust_collection_fill_leading_eigenvector(collection, subgraph, (i + 1), maximal_steps_delimieter); igraph_destroy(subgraph); } time(&time_end); logger_info("Time:\t cluster: %f", difftime(time_end, time_start)); /* Sort collection by cluster id to be * able to build a second column correct*/ time(&time_start); iclust_collection_sort(collection); time(&time_end); logger_info("Time:\t cluster sorting: %f", difftime(time_end, time_start)); unsigned long cluster_index = 1, cluster = 0; for (unsigned long i = 0; i < collection->length; i++) { iclust_collection_element * element = collection->collection[i]; massert((element != NULL), "Cluster collection element object can not be empty"); if (element->cluster != cluster) { cluster = element->cluster; cluster_index = 0; } printf("%lu\t%lu\t%s\n", cluster, ++cluster_index, element->name); } iclust_collection_destroy(collection); igraph_vector_ptr_destroy(&complist); igraph_destroy(&graph); logger_destroy(); return EXIT_SUCCESS; }
void Init_igraph(){ //Modules VALUE cIGraph_generate; VALUE cIGraph_genrandom; VALUE cIGraph_connectivity; VALUE cIGraph_mincuts; VALUE cIGraph_layout; VALUE cIGraph_clique; VALUE cIGraph_indyver; VALUE cIGraph_isomor; VALUE cIGraph_motifs; VALUE cIGraph_sorting; VALUE cIGraph_filewrite; VALUE cIGraph_fileread; VALUE cIGraph_community; VALUE cIGraph_shortestpaths; VALUE cIGraph_neighborhoodm; VALUE cIGraph_components; VALUE cIGraph_closenessm; VALUE cIGraph_spanning; VALUE cIGraph_transitivitym; VALUE cIGraph_spectral; VALUE cIGraph_kcore; VALUE cIGraph_otherop; VALUE cIGraph_randomise; igraph_i_set_attribute_table(&cIGraph_attribute_table); igraph_set_error_handler(cIGraph_error_handler); igraph_set_warning_handler(cIGraph_warning_handler); cIGraph = rb_define_class("IGraph", rb_cObject); cIGraphError = rb_define_class("IGraphError", rb_eRuntimeError); rb_define_alloc_func(cIGraph, cIGraph_alloc); rb_define_method(cIGraph, "initialize", cIGraph_initialize, -1); rb_define_method(cIGraph, "initialize_copy", cIGraph_init_copy, 1); rb_include_module(cIGraph, rb_mEnumerable); /* Functions for deterministically generating graphs. */ cIGraph_generate = rb_define_module_under(cIGraph, "Generate"); rb_include_module(cIGraph, cIGraph_generate); rb_define_singleton_method(cIGraph_generate, "adjacency", cIGraph_adjacency, 2); /* in cIGraph_generators_deterministic.c */ rb_define_singleton_method(cIGraph_generate, "star", cIGraph_star, 3); /* in cIGraph_generators_deterministic.c */ rb_define_singleton_method(cIGraph_generate, "lattice", cIGraph_lattice, 4); /* in cIGraph_generators_deterministic.c */ rb_define_singleton_method(cIGraph_generate, "ring", cIGraph_ring, 4); /* in cIGraph_generators_deterministic.c */ rb_define_singleton_method(cIGraph_generate, "tree", cIGraph_tree, 3); /* in cIGraph_generators_deterministic.c */ rb_define_singleton_method(cIGraph_generate, "full", cIGraph_full, 3); /* in cIGraph_generators_deterministic.c */ rb_define_singleton_method(cIGraph_generate, "atlas", cIGraph_atlas, 1); /* in cIGraph_generators_deterministic.c */ rb_define_singleton_method(cIGraph_generate, "extended_chordal_ring", cIGraph_extended_chordal_ring, 2); /* in cIGraph_generators_deterministic.c */ /* Functions for randomly generating graphs. */ cIGraph_genrandom = rb_define_module_under(cIGraph, "GenerateRandom"); rb_include_module(cIGraph, cIGraph_genrandom); rb_define_singleton_method(cIGraph_genrandom, "grg_game", cIGraph_grg_game, 3); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "barabasi_game", cIGraph_barabasi_game, 4); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "nonlinear_barabasi_game", cIGraph_nonlinear_barabasi_game, 6); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "erdos_renyi_game", cIGraph_erdos_renyi_game, 5); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "watts_strogatz_game", cIGraph_watts_strogatz_game, 4); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "degree_sequence_game", cIGraph_degree_sequence_game, 2); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "growing_random_game", cIGraph_growing_random_game, 4); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "callaway_traits_game", cIGraph_callaway_traits_game, 6); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "establishment_game", cIGraph_establishment_game, 6); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "preference_game", cIGraph_preference_game, 6); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "asymmetric_preference_game", cIGraph_asymmetric_preference_game, 5); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "recent_degree_game", cIGraph_recent_degree_game, 7); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "barabasi_aging_game", cIGraph_barabasi_aging_game, 11); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "recent_degree_aging_game", cIGraph_recent_degree_aging_game, 9); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "cited_type_game", cIGraph_cited_type_game, 5); /* in cIGraph_generators_random.c */ rb_define_singleton_method(cIGraph_genrandom, "citing_cited_type_game", cIGraph_citing_cited_type_game, 5); /* in cIGraph_generators_random.c */ rb_define_method(cIGraph, "[]", cIGraph_get_edge_attr, 2); /* in cIGraph_attribute_handler.c */ rb_define_method(cIGraph, "[]=", cIGraph_set_edge_attr, 3); /* in cIGraph_attribute_handler.c */ rb_define_alias (cIGraph, "get_edge_attr", "[]"); rb_define_alias (cIGraph, "set_edge_attr", "[]="); rb_define_method(cIGraph, "attributes", cIGraph_graph_attributes, 0); /* in cIGraph_attribute_handler.c */ rb_define_method(cIGraph, "each_vertex", cIGraph_each_vertex, 0); /* in cIGraph_iterators.c */ rb_define_method(cIGraph, "each_edge", cIGraph_each_edge, 1); /* in cIGraph_iterators.c */ rb_define_method(cIGraph, "each_edge_eid", cIGraph_each_edge_eid,1); /* in cIGraph_iterators.c */ rb_define_alias (cIGraph, "each", "each_vertex"); rb_define_method(cIGraph, "vertices", cIGraph_all_v, 0); /* in cIGraph_selectors.c */ rb_define_method(cIGraph, "adjacent_vertices", cIGraph_adj_v, 2); /* in cIGraph_selectors.c */ rb_define_method(cIGraph, "nonadjacent_vertices", cIGraph_nonadj_v, 2); /* in cIGraph_selectors.c */ rb_define_alias (cIGraph, "all_vertices", "vertices"); rb_define_method(cIGraph, "edges", cIGraph_all_e, 1); /* in cIGraph_selectors.c */ rb_define_method(cIGraph, "adjacent_edges", cIGraph_adj_e, 2); /* in cIGraph_selectors.c */ rb_define_alias (cIGraph, "all_edges", "edges"); rb_define_method(cIGraph, "vcount", cIGraph_vcount, 0); /* in cIGraph_basic_query.c */ rb_define_method(cIGraph, "ecount", cIGraph_ecount, 0); /* in cIGraph_basic_query.c */ rb_define_method(cIGraph, "edge", cIGraph_edge, 1); /* in cIGraph_basic_query.c */ rb_define_method(cIGraph, "get_eid", cIGraph_get_eid, 2); /* in cIGraph_basic_query.c */ rb_define_method(cIGraph, "neighbours", cIGraph_neighbors, 2); /* in cIGraph_basic_query.c */ rb_define_method(cIGraph, "adjacent", cIGraph_adjacent, 2); /* in cIGraph_basic_query.c */ rb_define_method(cIGraph, "degree", cIGraph_degree, 3); /* in cIGraph_basic_query.c */ rb_define_method(cIGraph, "is_directed?", cIGraph_is_directed, 0); /* in cIGraph_basic_query.c */ rb_define_alias (cIGraph, "is_directed", "is_directed?"); rb_define_alias (cIGraph, "neighbors", "neighbours"); rb_define_method(cIGraph, "add_edges", cIGraph_add_edges, -1); /* in cIGraph_add_delete.c */ rb_define_method(cIGraph, "add_vertices", cIGraph_add_vertices, 1); /* in cIGraph_add_delete.c */ rb_define_method(cIGraph, "add_edge", cIGraph_add_edge, -1); /* in cIGraph_add_delete.c */ rb_define_method(cIGraph, "add_vertex", cIGraph_add_vertex, 1); /* in cIGraph_add_delete.c */ rb_define_method(cIGraph, "delete_edge", cIGraph_delete_edge, 2); /* in cIGraph_add_delete.c */ rb_define_method(cIGraph, "delete_vertex", cIGraph_delete_vertex, 1); /* in cIGraph_add_delete.c */ rb_define_method(cIGraph, "are_connected", cIGraph_are_connected,2); /* in cIGraph_basic_properties.c */ rb_define_alias (cIGraph, "are_connected?", "are_connected"); rb_define_method(cIGraph, "to_directed", cIGraph_to_directed, 1); /* in cIGraph_direction.c */ rb_define_method(cIGraph, "to_undirected", cIGraph_to_undirected, 1); /* in cIGraph_direction.c */ /* These methods randomise a graph by rewiring the edges. */ cIGraph_randomise = rb_define_module_under(cIGraph, "Randomise"); rb_include_module(cIGraph, cIGraph_randomise); rb_define_method(cIGraph_randomise, "rewire_edges", cIGraph_rewire_edges, 1); /* in cIGraph_randomisation.c */ rb_define_method(cIGraph_randomise, "rewire", cIGraph_rewire, 1); /* in cIGraph_randomisation.c */ /* Functions for calculating the shortest path through a graph */ cIGraph_shortestpaths = rb_define_module_under(cIGraph, "ShortestPaths"); rb_include_module(cIGraph, cIGraph_shortestpaths); rb_define_method(cIGraph_shortestpaths, "shortest_paths", cIGraph_shortest_paths, 2); /* in cIGraph_shortest_paths.c */ rb_define_method(cIGraph_shortestpaths, "get_shortest_paths", cIGraph_get_shortest_paths, 3); /* in cIGraph_shortest_paths.c */ rb_define_method(cIGraph_shortestpaths, "get_all_shortest_paths", cIGraph_get_all_shortest_paths, 3); /* in cIGraph_shortest_paths.c */ rb_define_method(cIGraph_shortestpaths, "average_path_length", cIGraph_average_path_length, 2); /* in cIGraph_shortest_paths.c */ rb_define_method(cIGraph_shortestpaths, "diameter", cIGraph_diameter, 2); /* in cIGraph_shortest_paths.c */ rb_define_method(cIGraph_shortestpaths, "girth", cIGraph_girth, 0); /* in cIGraph_shortest_paths.c */ rb_define_method(cIGraph_shortestpaths, "dijkstra_shortest_paths", cIGraph_dijkstra_shortest_paths, 3); /* in cIGraph_dijkstra.c */ /* Functions for querying the neighborhood of vertices */ cIGraph_neighborhoodm = rb_define_module_under(cIGraph, "Neighborhood"); rb_include_module(cIGraph, cIGraph_neighborhoodm); rb_define_method(cIGraph_neighborhoodm, "neighbourhood_size", cIGraph_neighborhood_size, 3); /* in cIGraph_vertex_neighbourhood.c */ rb_define_method(cIGraph_neighborhoodm, "neighbourhood", cIGraph_neighborhood, 3); /* in cIGraph_vertex_neighbourhood.c */ rb_define_method(cIGraph_neighborhoodm, "neighbourhood_graphs", cIGraph_neighborhood_graphs, 3); /* in cIGraph_vertex_neighbourhood.c */ rb_define_alias (cIGraph_neighborhoodm, "neighborhood_size", "neighbourhood_size"); rb_define_alias (cIGraph_neighborhoodm, "neighborhood", "neighbourhood"); rb_define_alias (cIGraph_neighborhoodm, "neighborhood_graphs", "neighbourhood_graphs"); rb_define_method(cIGraph_neighborhoodm, "connect_neighborhood", cIGraph_connect_neighborhood, 2); /* in cIGraph_generators_deterministic.c */ /* Functions for splitting the graph into components */ cIGraph_components = rb_define_module_under(cIGraph, "Components"); rb_include_module(cIGraph, cIGraph_components); rb_define_method(cIGraph_components, "subcomponent", cIGraph_subcomponent, 2); /* in cIGraph_components.c */ rb_define_method(cIGraph_components, "subgraph", cIGraph_subgraph, 1); /* in cIGraph_components.c */ rb_define_method(cIGraph_components, "clusters", cIGraph_clusters, 1); /* in cIGraph_components.c */ rb_define_method(cIGraph_components, "decompose", cIGraph_decompose, -1); /* in cIGraph_components.c */ /* Graph centrality functions */ cIGraph_closenessm = rb_define_module_under(cIGraph, "Closeness"); rb_include_module(cIGraph, cIGraph_closenessm); rb_define_method(cIGraph_closenessm, "closeness", cIGraph_closeness, 2); /* in cIGraph_centrality.c */ rb_define_method(cIGraph_closenessm, "betweenness", cIGraph_betweenness, 2); /* in cIGraph_centrality.c */ rb_define_method(cIGraph_closenessm, "edge_betweenness", cIGraph_edge_betweenness, 1); /* in cIGraph_centrality.c */ rb_define_method(cIGraph_closenessm, "pagerank", cIGraph_pagerank, 5); /* in cIGraph_centrality.c */ rb_define_method(cIGraph_closenessm, "constraint", cIGraph_constraint, -1); /* in cIGraph_centrality.c */ rb_define_method(cIGraph_closenessm, "maxdegree", cIGraph_maxdegree, 3); /* in cIGraph_centrality.c */ /* Minimum spanning tree functions */ cIGraph_spanning = rb_define_module_under(cIGraph, "Spanning"); rb_include_module(cIGraph, cIGraph_spanning); rb_define_method(cIGraph_spanning, "minimum_spanning_tree_unweighted", cIGraph_minimum_spanning_tree_unweighted, 0); /* in cIGraph_spanning.c */ rb_define_method(cIGraph_spanning, "minimum_spanning_tree_prim", cIGraph_minimum_spanning_tree_prim, 1); /* in cIGraph_spanning.c */ /* Graph transitivity functions */ cIGraph_transitivitym = rb_define_module_under(cIGraph, "Transitivity"); rb_include_module(cIGraph, cIGraph_transitivitym); rb_define_method(cIGraph_transitivitym, "transitivity", cIGraph_transitivity, 0); /* in cIGraph_transitivity.c */ rb_define_method(cIGraph_transitivitym, "transitivity_local", cIGraph_transitivity_local, 1); /* in cIGraph_transitivity.c */ rb_define_method(cIGraph_transitivitym, "transitivity_avglocal", cIGraph_transitivity_avglocal, 0); /* in cIGraph_transitivity.c */ /* Functions for the Laplacian matrix. */ cIGraph_spectral = rb_define_module_under(cIGraph, "Spectral"); rb_include_module(cIGraph, cIGraph_spectral); rb_define_method(cIGraph_spectral, "laplacian", cIGraph_laplacian, 1); /* in cIGraph_spectral.c */ /* Functions for finding the coreness of a graph */ cIGraph_kcore = rb_define_module_under(cIGraph, "KCores"); rb_include_module(cIGraph, cIGraph_kcore); rb_define_method(cIGraph_kcore, "coreness", cIGraph_coreness, 1); /* in cIGraph_kcores.c */ /* Other general graph operations */ cIGraph_otherop = rb_define_module_under(cIGraph, "OtherOperations"); rb_include_module(cIGraph, cIGraph_otherop); rb_define_method(cIGraph_otherop, "density", cIGraph_density, 1); /* in cIGraph_other_ops.c */ rb_define_method(cIGraph_otherop, "simplify", cIGraph_simplify, 2); /* in cIGraph_other_ops.c */ rb_define_method(cIGraph_otherop, "reciprocity", cIGraph_reciprocity, 1); /* in cIGraph_other_ops.c */ rb_define_method(cIGraph_otherop, "bibcoupling", cIGraph_bibcoupling, 1); /* in cIGraph_other_ops.c */ rb_define_method(cIGraph_otherop, "cocitation", cIGraph_cocitation, 1); /* in cIGraph_other_ops.c */ rb_define_method(cIGraph_otherop, "get_adjacency", cIGraph_get_adjacency, 1); /* in cIGraph_other_ops.c */ /* Clique finding functions */ cIGraph_clique = rb_define_module_under(cIGraph, "Cliques"); rb_include_module(cIGraph, cIGraph_clique); rb_define_method(cIGraph_clique, "cliques", cIGraph_cliques, 2); /* in cIGraph_cliques.c */ rb_define_method(cIGraph_clique, "largest_cliques", cIGraph_largest_cliques, 0); /* in cIGraph_cliques.c */ rb_define_method(cIGraph_clique, "maximal_cliques", cIGraph_maximal_cliques, 0); /* in cIGraph_cliques.c */ rb_define_method(cIGraph_clique, "clique_number", cIGraph_clique_number, 0); /* in cIGraph_cliques.c */ /* Independent vertex set finding functions */ cIGraph_indyver = rb_define_module_under(cIGraph, "IndependentVertexSets"); rb_include_module(cIGraph, cIGraph_indyver); rb_define_method(cIGraph_indyver, "independent_vertex_sets", cIGraph_independent_vertex_sets, 2); /* in cIGraph_independent_vertex_sets.c */ rb_define_method(cIGraph_indyver, "largest_independent_vertex_sets", cIGraph_largest_independent_vertex_sets, 0); /* in cIGraph_independent_vertex_sets.c */ rb_define_method(cIGraph_indyver, "maximal_independent_vertex_sets", cIGraph_maximal_independent_vertex_sets, 0); /* in cIGraph_independent_vertex_sets.c */ rb_define_method(cIGraph_indyver, "independence_number", cIGraph_independence_number, 0); /* in cIGraph_independent_vertex_sets.c */ /* Functions for isomorphism and isoclasses */ cIGraph_isomor = rb_define_module_under(cIGraph, "Isomorphism"); rb_include_module(cIGraph, cIGraph_isomor); rb_define_method(cIGraph_isomor, "isomorphic", cIGraph_isomorphic, 1); /* in cIGraph_isomorphism.c */ rb_define_method(cIGraph_isomor, "isomorphic_vf2", cIGraph_isomorphic_vf2, 1); /* in cIGraph_isomorphism.c */ rb_define_method(cIGraph_isomor, "isoclass", cIGraph_isoclass, 0); /* in cIGraph_isomorphism.c */ rb_define_method(cIGraph_isomor, "isoclass_subgraph", cIGraph_isoclass_subgraph, 1); /* in cIGraph_isomorphism.c */ rb_define_singleton_method(cIGraph_generate, "isoclass_create", cIGraph_isoclass_create, 3); /* in cIGraph_isomorphism.c */ /* Motif finding functions */ cIGraph_motifs = rb_define_module_under(cIGraph, "Motifs"); rb_include_module(cIGraph, cIGraph_motifs); rb_define_method(cIGraph_motifs, "motifs_randesu", cIGraph_motifs_randesu, 2); /* in cIGraph_motif.c */ rb_define_method(cIGraph_motifs, "motifs_randesu_no", cIGraph_motifs_randesu_no, 2); /* in cIGraph_motif.c */ rb_define_method(cIGraph_motifs, "motifs_randesu_estimate", cIGraph_motifs_randesu_estimate, 4); /* in cIGraph_motif.c */ /* Graph sorting functions. */ cIGraph_sorting = rb_define_module_under(cIGraph, "Sorting"); rb_include_module(cIGraph, cIGraph_sorting); rb_define_method(cIGraph_sorting, "topological_sorting", cIGraph_topological_sorting, 1); /* in cIGraph_topological_sort.c */ /* Functions for reading graphs from files */ cIGraph_fileread = rb_define_module_under(cIGraph, "FileRead"); rb_include_module(cIGraph, cIGraph_fileread); #ifdef __APPLE__ rb_define_singleton_method(cIGraph_fileread, "read_graph_edgelist", cIGraph_unavailable_method, -1); rb_define_singleton_method(cIGraph_fileread, "read_graph_graphml", cIGraph_unavailable_method, -1); rb_define_singleton_method(cIGraph_fileread, "read_graph_ncol", cIGraph_unavailable_method, -1); rb_define_singleton_method(cIGraph_fileread, "read_graph_lgl", cIGraph_unavailable_method, -1); rb_define_singleton_method(cIGraph_fileread, "read_graph_dimacs", cIGraph_unavailable_method, -1); rb_define_singleton_method(cIGraph_fileread, "read_graph_graphdb", cIGraph_unavailable_method, -1); rb_define_singleton_method(cIGraph_fileread, "read_graph_gml", cIGraph_unavailable_method, -1); rb_define_singleton_method(cIGraph_fileread, "read_graph_pajek", cIGraph_unavailable_method, -1); #else rb_define_singleton_method(cIGraph_fileread, "read_graph_edgelist", cIGraph_read_graph_edgelist, 2); /* in cIGraph_file.c */ rb_define_singleton_method(cIGraph_fileread, "read_graph_graphml", cIGraph_read_graph_graphml, 2); /* in cIGraph_file.c */ rb_define_singleton_method(cIGraph_fileread, "read_graph_ncol", cIGraph_read_graph_ncol, 5); /* in cIGraph_file.c */ rb_define_singleton_method(cIGraph_fileread, "read_graph_lgl", cIGraph_read_graph_lgl, 3); /* in cIGraph_file.c */ rb_define_singleton_method(cIGraph_fileread, "read_graph_dimacs", cIGraph_read_graph_dimacs, 2); /* in cIGraph_file.c */ rb_define_singleton_method(cIGraph_fileread, "read_graph_graphdb", cIGraph_read_graph_graphdb, 2); /* in cIGraph_file.c */ rb_define_singleton_method(cIGraph_fileread, "read_graph_gml", cIGraph_read_graph_gml, 1); /* in cIGraph_file.c */ rb_define_singleton_method(cIGraph_fileread, "read_graph_pajek", cIGraph_read_graph_pajek, 2); /* in cIGraph_file.c */ #endif /* Functions for writing graphs to files */ cIGraph_filewrite = rb_define_module_under(cIGraph, "FileWrite"); rb_include_module(cIGraph, cIGraph_filewrite); #ifdef __APPLE__ rb_define_method(cIGraph_filewrite, "write_graph_edgelist", cIGraph_unavailable_method, -1); rb_define_method(cIGraph_filewrite, "write_graph_graphml", cIGraph_unavailable_method, -1); rb_define_method(cIGraph_filewrite, "write_graph_gml", cIGraph_unavailable_method, -1); rb_define_method(cIGraph_filewrite, "write_graph_ncol", cIGraph_unavailable_method, -1); rb_define_method(cIGraph_filewrite, "write_graph_lgl", cIGraph_unavailable_method, -1); rb_define_method(cIGraph_filewrite, "write_graph_dimacs", cIGraph_unavailable_method, -1); rb_define_method(cIGraph_filewrite, "write_graph_pajek", cIGraph_unavailable_method, -1); #else rb_define_method(cIGraph_filewrite, "write_graph_edgelist", cIGraph_write_graph_edgelist, 1); /* in cIGraph_file.c */ rb_define_method(cIGraph_filewrite, "write_graph_graphml", cIGraph_write_graph_graphml, 1); /* in cIGraph_file.c */ rb_define_method(cIGraph_filewrite, "write_graph_gml", cIGraph_write_graph_gml, 1); /* in cIGraph_file.c */ rb_define_method(cIGraph_filewrite, "write_graph_ncol", cIGraph_write_graph_ncol, 3); /* in cIGraph_file.c */ rb_define_method(cIGraph_filewrite, "write_graph_lgl", cIGraph_write_graph_lgl, 4); /* in cIGraph_file.c */ rb_define_method(cIGraph_filewrite, "write_graph_dimacs", cIGraph_write_graph_dimacs, 4); /* in cIGraph_file.c */ rb_define_method(cIGraph_filewrite, "write_graph_pajek", cIGraph_write_graph_pajek, 1); /* in cIGraph_file.c */ #endif /* Graph layout functions */ cIGraph_layout = rb_define_module_under(cIGraph, "Layout"); rb_include_module(cIGraph, cIGraph_layout); rb_define_method(cIGraph_layout, "layout_random", cIGraph_layout_random, 0); /* in cIGraph_layout.c */ rb_define_method(cIGraph_layout, "layout_circle", cIGraph_layout_circle, 0); /* in cIGraph_layout.c */ rb_define_method(cIGraph_layout, "layout_fruchterman_reingold", cIGraph_layout_fruchterman_reingold, 6); /* in cIGraph_layout.c */ rb_define_method(cIGraph_layout, "layout_kamada_kawai", cIGraph_layout_kamada_kawai, 5); /* in cIGraph_layout.c */ rb_define_method(cIGraph_layout, "layout_reingold_tilford", cIGraph_layout_reingold_tilford, 1); /* in cIGraph_layout.c */ rb_define_method(cIGraph_layout, "layout_reingold_tilford_circular", cIGraph_layout_reingold_tilford_circular, 1); /* in cIGraph_layout.c */ rb_define_method(cIGraph_layout, "layout_grid_fruchterman_reingold", cIGraph_layout_grid_fruchterman_reingold, 7); /* in cIGraph_layout.c */ rb_define_method(cIGraph_layout, "layout_lgl", cIGraph_layout_lgl, 7); /* in cIGraph_layout.c */ rb_define_method(cIGraph_layout, "layout_random_3d", cIGraph_layout_random_3d, 0); /* in cIGraph_layout3d.c */ rb_define_method(cIGraph_layout, "layout_sphere", cIGraph_layout_sphere, 0); /* in cIGraph_layout3d.c */ rb_define_method(cIGraph_layout, "layout_fruchterman_reingold_3d", cIGraph_layout_fruchterman_reingold_3d, 5); /* in cIGraph_layout3d.c */ rb_define_method(cIGraph_layout, "layout_kamada_kawai_3d", cIGraph_layout_kamada_kawai_3d, 5); /* in cIGraph_layout3d.c */ rb_define_singleton_method(cIGraph_layout, "layout_merge_dla", cIGraph_layout_merge_dla, 2); /* in cIGraph_layout.c */ /* Minimum cuts related functions */ cIGraph_mincuts = rb_define_module_under(cIGraph, "MinimumCuts"); rb_include_module(cIGraph, cIGraph_mincuts); rb_define_method(cIGraph_mincuts, "maxflow_value", cIGraph_maxflow_value, 3); /* in cIGraph_min_cuts.c */ rb_define_method(cIGraph_mincuts, "st_mincut_value", cIGraph_st_mincut_value, 3); /* in cIGraph_min_cuts.c */ rb_define_method(cIGraph_mincuts, "mincut_value", cIGraph_mincut_value, 1); /* in cIGraph_min_cuts.c */ rb_define_method(cIGraph_mincuts, "mincut", cIGraph_mincut, 1); /* in cIGraph_min_cuts.c */ /* Vertex and edge connectivity functions */ cIGraph_connectivity = rb_define_module_under(cIGraph, "Connectivity"); rb_include_module(cIGraph, cIGraph_connectivity); rb_define_method(cIGraph_connectivity, "st_edge_connectivity", cIGraph_st_edge_connectivity, 2); /* in cIGraph_connectivity.c */ rb_define_method(cIGraph_connectivity, "edge_connectivity", cIGraph_edge_connectivity, 0); /* in cIGraph_connectivity.c */ rb_define_method(cIGraph_connectivity, "st_vertex_connectivity", cIGraph_st_vertex_connectivity, 3); /* in cIGraph_connectivity.c */ rb_define_method(cIGraph_connectivity, "vertex_connectivity", cIGraph_vertex_connectivity, 0); /* in cIGraph_connectivity.c */ rb_define_method(cIGraph_connectivity, "edge_disjoint_paths", cIGraph_edge_disjoint_paths, 2); /* in cIGraph_connectivity.c */ rb_define_method(cIGraph_connectivity, "vertex_disjoint_paths", cIGraph_vertex_disjoint_paths, 2); /* in cIGraph_connectivity.c */ rb_define_method(cIGraph_connectivity, "adhesion", cIGraph_adhesion, 0); /* in cIGraph_connectivity.c */ rb_define_method(cIGraph_connectivity, "cohesion", cIGraph_cohesion, 0); /* in cIGraph_connectivity.c */ /* Community and modularity related functions */ cIGraph_community = rb_define_module_under(cIGraph, "Community"); rb_include_module(cIGraph, cIGraph_community); rb_define_method(cIGraph_community, "modularity", cIGraph_modularity, 1); /* in cIGraph_community.c */ rb_define_method(cIGraph_community, "community_to_membership", cIGraph_community_to_membership, 3); /* in cIGraph_community.c */ rb_define_method(cIGraph_community, "community_spinglass", cIGraph_community_spinglass, 8); /* in cIGraph_community.c */ rb_define_method(cIGraph_community, "community_spinglass_single", cIGraph_community_spinglass_single, 5); /* in cIGraph_community.c */ rb_define_method(cIGraph_community, "community_leading_eigenvector", cIGraph_community_leading_eigenvector, 1); /* in cIGraph_community.c */ rb_define_method(cIGraph_community, "community_leading_eigenvector_naive", cIGraph_community_leading_eigenvector_naive, 1); /* in cIGraph_community.c */ rb_define_method(cIGraph_community, "community_leading_eigenvector_step", cIGraph_community_leading_eigenvector_step, 2); /* in cIGraph_community.c */ rb_define_method(cIGraph_community, "community_walktrap", cIGraph_community_walktrap, 2); /* in cIGraph_community.c */ rb_define_method(cIGraph_community, "community_edge_betweenness", cIGraph_community_edge_betweenness, 1); /* in cIGraph_community.c */ rb_define_method(cIGraph_community, "community_eb_get_merges", cIGraph_community_eb_get_merges, 1); /* in cIGraph_community.c */ rb_define_method(cIGraph_community, "community_fastgreedy", cIGraph_community_fastgreedy, 0); /* in cIGraph_community.c */ rb_define_const(cIGraph, "VERSION", rb_str_new2("0.9.1")); rb_define_const(cIGraph, "EDGEORDER_ID", INT2NUM(1)); rb_define_const(cIGraph, "EDGEORDER_FROM", INT2NUM(2)); rb_define_const(cIGraph, "EDGEORDER_TO", INT2NUM(3)); rb_define_const(cIGraph, "OUT", INT2NUM(1)); rb_define_const(cIGraph, "IN", INT2NUM(2)); rb_define_const(cIGraph, "ALL", INT2NUM(3)); rb_define_const(cIGraph, "TOTAL", INT2NUM(4)); rb_define_const(cIGraph_components, "WEAK", INT2NUM(1)); rb_define_const(cIGraph_components, "STRONG", INT2NUM(2)); rb_define_const(cIGraph, "ARBITRARY", INT2NUM(0)); rb_define_const(cIGraph, "MUTUAL", INT2NUM(1)); rb_define_const(cIGraph, "EACH", INT2NUM(0)); rb_define_const(cIGraph, "COLLAPSE", INT2NUM(1)); rb_define_const(cIGraph_otherop, "GET_ADJACENCY_UPPER", INT2NUM(0)); rb_define_const(cIGraph_otherop, "GET_ADJACENCY_LOWER", INT2NUM(1)); rb_define_const(cIGraph_otherop, "GET_ADJACENCY_BOTH", INT2NUM(2)); rb_define_const(cIGraph, "ERDOS_RENYI_GNP", INT2NUM(0)); rb_define_const(cIGraph, "ERDOS_RENYI_GNM", INT2NUM(1)); rb_define_const(cIGraph_generate, "ADJ_DIRECTED", INT2NUM(0)); rb_define_const(cIGraph_generate, "ADJ_UNDIRECTED", INT2NUM(1)); rb_define_const(cIGraph_generate, "ADJ_MAX", INT2NUM(2)); rb_define_const(cIGraph_generate, "ADJ_MIN", INT2NUM(3)); rb_define_const(cIGraph_generate, "ADJ_PLUS", INT2NUM(4)); rb_define_const(cIGraph_generate, "ADJ_UPPER", INT2NUM(5)); rb_define_const(cIGraph_generate, "ADJ_LOWER", INT2NUM(6)); rb_define_const(cIGraph_generate, "STAR_OUT", INT2NUM(0)); rb_define_const(cIGraph_generate, "STAR_IN", INT2NUM(1)); rb_define_const(cIGraph_generate, "STAR_UNDIRECTED", INT2NUM(2)); rb_define_const(cIGraph_generate, "TREE_OUT", INT2NUM(0)); rb_define_const(cIGraph_generate, "TREE_IN", INT2NUM(1)); rb_define_const(cIGraph_generate, "TREE_UNDIRECTED", INT2NUM(2)); rb_define_const(cIGraph_connectivity, "VCONN_NEI_ERROR", INT2NUM(0)); rb_define_const(cIGraph_connectivity, "VCONN_NEI_INFINITY", INT2NUM(1)); rb_define_const(cIGraph_connectivity, "VCONN_NEI_IGNORE", INT2NUM(2)); rb_define_const(cIGraph_community, "SPINCOMM_UPDATE_SIMPLE", INT2NUM(0)); rb_define_const(cIGraph_community, "SPINCOMM_UPDATE_CONFIG", INT2NUM(1)); /* This class wraps the igraph matrix type. It can be created from and * converted to an Array of Ruby Arrays. */ cIGraphMatrix = rb_define_class("IGraphMatrix", rb_cObject); rb_define_alloc_func(cIGraphMatrix, cIGraph_matrix_alloc); rb_define_method(cIGraphMatrix, "initialize", cIGraph_matrix_initialize, -1); /* in cIGraph_matrix.c */ rb_define_method(cIGraphMatrix, "initialize_copy", cIGraph_matrix_init_copy, 1); /* in cIGraph_matrix.c */ //rb_define_singleton_method(cIGraphMatrix, "[]", cIGraph_matrix_initialize, -1); rb_include_module(cIGraphMatrix, rb_mEnumerable); rb_define_method (cIGraphMatrix, "each", cIGraph_matrix_each,0); /* in cIGraph_matrix.c */ rb_define_method(cIGraphMatrix, "[]", cIGraph_matrix_get, 2); /* in cIGraph_matrix.c */ rb_define_method(cIGraphMatrix, "[]=", cIGraph_matrix_set, 3); /* in cIGraph_matrix.c */ rb_define_method(cIGraphMatrix, "size", cIGraph_matrix_size, 0); /* in cIGraph_matrix.c */ rb_define_method(cIGraphMatrix, "nrow", cIGraph_matrix_nrow, 0); /* in cIGraph_matrix.c */ rb_define_method(cIGraphMatrix, "ncol", cIGraph_matrix_ncol, 0); /* in cIGraph_matrix.c */ rb_define_method(cIGraphMatrix, "max", cIGraph_matrix_max, 0); /* in cIGraph_matrix.c */ rb_define_method(cIGraphMatrix, "*", cIGraph_matrix_scale, 1); /* in cIGraph_matrix.c */ rb_define_method(cIGraphMatrix, "to_a", cIGraph_matrix_toa, 0); /* in cIGraph_matrix.c */ }
TMIgraph::TMIgraph() { igraph_i_set_attribute_table(&igraph_cattribute_table); igraph_empty(&graph, 0, true); }
int main(void) { // This needs to be done *first*. See igraph doc for why. igraph_i_set_attribute_table(&igraph_cattribute_table); printf("sizeof(int)=%d sizeof(long)=%d sizeof(igraph_integer_t)=%d\n", (int) sizeof(int), (int) sizeof(long), (int) sizeof(igraph_integer_t)); pause(); printf("Loading graph from file...\n"); FILE* f = fopen("donnees/arretes.test", "r"); //FILE* f = fopen("graph_a.ncol", "r"); igraph_t gr; igraph_read_graph_ncol(&gr, f, NULL, 1, 0, 0); fclose(f); f = NULL; long vcount = igraph_vcount(&gr); long ecount = igraph_ecount(&gr); printf("Main graph: |V| = %ld, |E| = %ld\n", vcount, ecount); pause(); // get connected components printf("Computing connected components...\n"); igraph_vector_t membership; igraph_vector_t csize; igraph_integer_t cnum = 0; igraph_vector_init(&membership, 1); igraph_vector_init(&csize, 1); igraph_clusters(&gr, &membership, &csize, &cnum, IGRAPH_STRONG); printf("There are %ld connected components.\n", (long) cnum); // work with connected components { printf("Writing connected components to file...\n"); // open file FILE* filout = fopen("groupes", "w"); long membership_size = igraph_vector_size(&membership); if (membership_size != vcount) { fprintf(stderr, "FATAL ERROR: membership_size != vcount\n"); exit(1); } for (long i = 0; i < membership_size; i++) { fprintf(filout, "%ld\t%s\n", // connected component id: (long) igraph_vector_e(&membership , i), // veretex name: igraph_cattribute_VAS(&gr, "name", i)); } fclose(filout); filout = NULL; printf("Connected components written.\n"); } pause(); // free connected components igraph_vector_destroy(&membership); igraph_vector_destroy(&csize); // free main graph igraph_destroy(&gr); printf("Program ends.\n"); pause(); return 0; }
int main(int argc, char *argv[]) { if (argc == 2) { char *inputFile = malloc(sizeof(char)*50); inputFile = (char *) argv[1]; // Funzione che crea una tabella di attributi da assegnare agli argomenti del grafo. // Concretamente, essa viene chiamata per una visualizzazione più immediata del risultato del SAT Solver. igraph_i_set_attribute_table(&igraph_cattribute_table); // Chiamata alla funzione presente nel file "file.c", che legge un file e crea un grafo orientato. igraph_t g; graph myGraph = {g, malloc(sizeof(int)*100000)}; myGraph = openFile_and_createGraph(inputFile); cnf myCNF = {malloc(sizeof(char)*999999999), 0, 0, 0}; myCNF.expr[0] = '\0'; // Assegnazione necessaria per il corretto funzionamento di "strcat()". cnf cnfdf = {malloc(sizeof(char)*999999999), 0, 0, 0}; // Chiamata alla funzione presente nel file "createCNF.c", la quale chiama altre funzioni e calcola la CNF. myCNF = createCNF(myCNF, myGraph); preferredExtension myPE = {malloc(sizeof(char)*999999999), 0}; myPE.ep[0] = '\0'; // Assegnazione necessaria per il corretto funzionamento di "strcat()". int num_variables = 3*(igraph_vcount(&(myGraph.graph))); int last_comp_found[num_variables]; int ret_value = 0, pref_cand; // Enumerating the preferred extensions of an Argumentation Framework. do { strcpy(cnfdf.expr, myCNF.expr); cnfdf.num_clauses = myCNF.num_clauses; pref_cand = 0; do { cnfdf.undec_args = 0; cnfdf.not_in_args = 0; ret_value = glucoseSAT(cnfdf.expr, num_variables, cnfdf.num_clauses, last_comp_found); if (ret_value == 10) { pref_cand = 1; cnfdf = firstIf(cnfdf, ret_value, num_variables, last_comp_found, myGraph); } } while (ret_value == 10 && cnfdf.undec_args == 1); if (pref_cand == 1) { myCNF = secondIf(myCNF, num_variables, last_comp_found, myGraph, myPE); myPE.num_extensions++; } } while (pref_cand == 1); if (strlen(myPE.ep) == 0) strcat(myPE.ep, "{}"); printf("%s", myPE.ep); igraph_destroy(&(myGraph.graph)); } else { printf("Missing input file.\n"); printf("###Running\n"); printf("./IgraphSAT <inputfile>\n"); } return 0; }
TGenGraph* tgengraph_new(gchar* path) { if(!path || !g_file_test(path, G_FILE_TEST_IS_REGULAR|G_FILE_TEST_EXISTS)) { tgen_critical("path '%s' to tgen config graph is not valid or does not exist", path); return NULL; } TGenGraph* g = g_new0(TGenGraph, 1); g->magic = TGEN_MAGIC; g->actions = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)tgenaction_unref); g->weights = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); g->graphPath = path ? _tgengraph_getHomePath(path) : NULL; GError* error = NULL; gboolean exists = g_file_test(g->graphPath, G_FILE_TEST_IS_REGULAR|G_FILE_TEST_EXISTS); if(!exists) { error = g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, "graph file does not exist at path '%s'", g->graphPath); } if(!error && g->graphPath) { tgen_lock(); /* use the built-in C attribute handler */ igraph_attribute_table_t* oldHandler = igraph_i_set_attribute_table(&igraph_cattribute_table); g->graph = _tgengraph_loadNewGraph(g->graphPath); if(!g->graph) { error = g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, "unable to read graph at path '%s'", g->graphPath); } /* parse edges first for choose, needs hash table of weights filled for error handling */ if(!error) { error = _tgengraph_parseGraphProperties(g); } if(!error) { error = _tgengraph_parseGraphEdges(g); } if(!error) { error = _tgengraph_parseGraphVertices(g); } /* replace the old handler */ igraph_i_set_attribute_table(oldHandler); tgen_unlock(); } if(error) { tgen_critical("error (%i) while loading graph: %s", error->code, error->message); g_error_free(error); tgengraph_free(g); return NULL; } tgen_message("successfully loaded graphml file '%s' and validated actions: " "graph is %s with %u %s, %u %s, and %u %s", g->graphPath, g->isConnected ? "weakly connected" : "disconnected", (guint)g->clusterCount, g->clusterCount == 1 ? "cluster" : "clusters", (guint)g->vertexCount, g->vertexCount == 1 ? "vertex" : "vertices", (guint)g->edgeCount, g->edgeCount == 1 ? "edge" : "edges"); return g; }
int main() { igraph_t g, g2; igraph_attribute_combination_t comb; igraph_i_set_attribute_table(&igraph_cattribute_table); igraph_small(&g, 4, IGRAPH_DIRECTED, 0, 1, 0, 1, 0, 1, 1, 2, 2, 3, -1); SETEAB(&g, "type", 0, 1); SETEAB(&g, "type", 1, 1); SETEAB(&g, "type", 2, 0); SETEAB(&g, "type", 3, 0); SETEAB(&g, "type", 4, 1); /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_SUM, "type", IGRAPH_ATTRIBUTE_COMBINE_FIRST, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "", IGRAPH_ATTRIBUTE_COMBINE_LAST, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, "type", IGRAPH_ATTRIBUTE_COMBINE_LAST, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, "type", IGRAPH_ATTRIBUTE_COMBINE_SUM, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, "type", IGRAPH_ATTRIBUTE_COMBINE_PROD, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, "type", IGRAPH_ATTRIBUTE_COMBINE_MIN, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, "type", IGRAPH_ATTRIBUTE_COMBINE_MAX, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, "type", IGRAPH_ATTRIBUTE_COMBINE_MEAN, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, "type", IGRAPH_ATTRIBUTE_COMBINE_MEDIAN, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout, /*prefixattr=*/ 1); igraph_destroy(&g2); /* ****************************************************** */ igraph_destroy(&g); return 0; }
int main() { igraph_t g; igraph_matrix_t mat; int m[4][4] = { { 0, 1, 2, 0 }, { 2, 0, 0, 1 }, { 0, 0, 1, 0 }, { 0, 1, 0, 0 } }; long int i, j; igraph_matrix_init(&mat, 4, 4); for (i=0; i<4; i++) for (j=0; j<4; j++) MATRIX(mat, i, j) = m[i][j]; igraph_i_set_attribute_table(&igraph_cattribute_table); /* [ 0 1 2 0 ] [ 2 0 0 1 ] [ 0 0 1 0 ] [ 0 1 0 0 ] */ igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_DIRECTED, 0); print(&g); igraph_destroy(&g); /* [ 0 1 2 0 ] [ - 0 0 1 ] [ - - 1 0 ] [ - - - 0 ] */ igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_UPPER, 0); print(&g); igraph_destroy(&g); /* [ 0 - - - ] [ 2 0 - - ] [ 0 0 1 - ] [ 0 1 0 0 ] */ igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_LOWER, 0); print(&g); igraph_destroy(&g); /* [ 0 1 0 0 ] [ 1 0 0 1 ] [ 0 0 1 0 ] [ 0 1 0 0 ] */ igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_MIN, 0); print(&g); igraph_destroy(&g); /* [ 0 2 2 0 ] [ 2 0 0 1 ] [ 2 0 1 0 ] [ 0 1 0 0 ] */ igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_MAX, 0); print(&g); igraph_destroy(&g); /* [ 0 3 2 0 ] [ 3 0 0 2 ] [ 2 0 1 0 ] [ 0 2 0 0 ] */ igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_PLUS, 0); print(&g); igraph_destroy(&g); igraph_matrix_destroy(&mat); if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 1; return 0; }
int main() { igraph_t g, g2; igraph_vector_t weight; igraph_attribute_combination_t comb; igraph_i_set_attribute_table(&igraph_cattribute_table); igraph_small(&g, 4, IGRAPH_DIRECTED, 0, 1, 0, 1, 0, 1, 1, 2, 2, 3, -1); igraph_vector_init_seq(&weight, 1, igraph_ecount(&g)); SETEANV(&g, "weight", &weight); igraph_vector_destroy(&weight); /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_SUM, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_PROD, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_MIN, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_MAX, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_FIRST, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_LAST, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_MEAN, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_FUNCTION, mf, "", IGRAPH_ATTRIBUTE_COMBINE_IGNORE, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout); igraph_destroy(&g2); /* ****************************************************** */ /* ****************************************************** */ igraph_copy(&g2, &g); igraph_attribute_combination(&comb, "", IGRAPH_ATTRIBUTE_COMBINE_MEAN, IGRAPH_NO_MORE_ATTRIBUTES); igraph_simplify(&g2, /*multiple=*/ 1, /*loops=*/ 1, &comb); igraph_attribute_combination_destroy(&comb); igraph_write_graph_graphml(&g2, stdout); igraph_destroy(&g2); /* ****************************************************** */ igraph_destroy(&g); return 0; }
int main(int argc,char** argv) { int c; int option_index = 0; int status = 0; // parse options while(1) { c = getopt_long(argc, argv, short_opts,long_options, &option_index); if(c == -1) break; switch(c) { case 0: break; case 'r': rngfname = optarg; break; case 'o': outfname = optarg; break; case 'i': infname = optarg; break; case 'n': name = optarg; break; case 'h': ask_help = 1; break; case 'V': ask_version =1; break; case 'f': logfname = optarg; break; case 'l': logval = optarg; break; default: fprintf(stderr,"ggen bug: someone forgot how to write a switch\n"); exit(EXIT_FAILURE); case '?': fprintf(stderr,"ggen bug: getopt failed miserably\n"); exit(EXIT_FAILURE); } } // forget the parsed part of argv argc -= optind; argv = &(argv[optind]); if(ask_full_help) { print_full_help(); exit(EXIT_SUCCESS); } if(ask_version) { print_version(); exit(EXIT_SUCCESS); } if(argc == 0) { print_help(general_help); exit(EXIT_FAILURE); } // initialize logging if(logfname != NULL) { logfile = fopen(logfname,"w"); if(!logfile) { fprintf(stderr,"failed to open file %s for logging, using stderr instead\n",logfname); logfile = stderr; logfname = NULL; } } else logfile = stderr; status = log_init(logfile,"ggen"); if(status) { fprintf(stderr,"error during log initialization\n"); exit(EXIT_FAILURE); } // now set level according to options unsigned long l; if(logval != NULL) { status = s2ul(logval,&l); if(status) { warning("Cannot convert log level option to int\n"); l = LOG_NORMAL; } else if(l < LOG_QUIET || l > LOG_DEBUG) { warning("Incorrect log level value, must be between %d and %d\n",LOG_QUIET,LOG_DEBUG); l = LOG_NORMAL; } } else l = LOG_NORMAL; log_filter_above((enum log_level)l); normal("Logging facility initialized\n"); // initialize igraph attributes for all commands igraph_i_set_attribute_table(&igraph_cattribute_table); // find the command to launch info("Searching for command %s\n",argv[0]); for(int i = 0; i < ARRAY_SIZE(cmd_table); i++) { struct first_lvl_cmd *c = cmd_table+i; if(!strcmp(c->name,argv[0])) { argc--; argv++; status = handle_first_lvl(argc,argv,c); goto end; } } status = EXIT_FAILURE; error("Command not found\n"); end: // close logging normal("Closing log\n"); if(logfname) { fclose(logfile); } return status; }
int main() { igraph_t g, g2; FILE *ifile; igraph_vector_t gtypes, vtypes, etypes; igraph_strvector_t gnames, vnames, enames; long int i; igraph_vector_t y; igraph_strvector_t id; char str[20]; /* turn on attribute handling */ igraph_i_set_attribute_table(&igraph_cattribute_table); ifile=fopen("LINKS.NET", "r"); if (ifile==0) { return 10; } igraph_read_graph_pajek(&g, ifile); fclose(ifile); igraph_vector_init(>ypes, 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, >ypes, &vnames, &vtypes, &enames, &etypes); /* List attribute names and types */ printf("Graph attributes: "); for (i=0; i<igraph_strvector_size(&gnames); i++) { printf("%s (%i) ", STR(gnames, i), (int)VECTOR(gtypes)[i]); } printf("\n"); printf("Vertex attributes: "); for (i=0; i<igraph_strvector_size(&vnames); i++) { printf("%s (%i) ", STR(vnames, i), (int)VECTOR(vtypes)[i]); } printf("\n"); printf("Edge attributes: "); for (i=0; i<igraph_strvector_size(&enames); i++) { printf("%s (%i) ", STR(enames, i), (int)VECTOR(etypes)[i]); } printf("\n"); print_attributes(&g); /* Copying a graph */ igraph_copy(&g2, &g); print_attributes(&g2); igraph_destroy(&g2); /* Adding vertices */ igraph_add_vertices(&g, 3, 0); print_attributes(&g); /* Adding edges */ igraph_add_edge(&g, 1, 1); igraph_add_edge(&g, 2, 5); igraph_add_edge(&g, 3, 6); print_attributes(&g); /* Deleting vertices */ igraph_delete_vertices(&g, igraph_vss_1(1)); igraph_delete_vertices(&g, igraph_vss_1(4)); print_attributes(&g); /* Deleting edges */ igraph_delete_edges(&g, igraph_ess_1(igraph_ecount(&g)-1)); igraph_delete_edges(&g, igraph_ess_1(0)); print_attributes(&g); /* Set graph attributes */ SETGAN(&g, "id", 10); if (GAN(&g, "id") != 10) { return 11; } SETGAS(&g, "name", "toy"); if (strcmp(GAS(&g, "name"), "toy")) { return 12; } /* Delete graph attributes */ DELGA(&g, "id"); DELGA(&g, "name"); igraph_cattribute_list(&g, &gnames, 0,0,0,0,0); if (igraph_strvector_size(&gnames) != 0) { return 14; } /* Delete vertex attributes */ DELVA(&g, "x"); DELVA(&g, "shape"); DELVA(&g, "xfact"); DELVA(&g, "yfact"); igraph_cattribute_list(&g, 0,0, &vnames, 0,0,0); if (igraph_strvector_size(&vnames) != 2) { return 15; } /* Delete edge attributes */ igraph_cattribute_list(&g, 0,0,0,0,&enames,0); i=igraph_strvector_size(&enames); DELEA(&g, "hook1"); DELEA(&g, "hook2"); DELEA(&g, "label"); igraph_cattribute_list(&g, 0,0,0,0,&enames,0); if (igraph_strvector_size(&enames) != i-3) { return 16; } /* Set vertex attributes */ SETVAN(&g, "y", 0, -1); SETVAN(&g, "y", 1, 2.1); if (VAN(&g, "y", 0) != -1 || VAN(&g, "y", 1) != 2.1) { return 17; } SETVAS(&g, "id", 0, "foo"); SETVAS(&g, "id", 1, "bar"); if (strcmp(VAS(&g, "id", 0), "foo") || strcmp(VAS(&g, "id", 1), "bar")) { return 18; } /* Set edge attributes */ SETEAN(&g, "weight", 2, 100.0); SETEAN(&g, "weight", 0, -100.1); if (EAN(&g, "weight", 2) != 100.0 || EAN(&g, "weight", 0) != -100.1) { return 19; } SETEAS(&g, "color", 2, "RED"); SETEAS(&g, "color", 0, "Blue"); if (strcmp(EAS(&g, "color", 2), "RED") || strcmp(EAS(&g, "color", 0), "Blue")) { return 20; } /* Set vector attributes as vector */ igraph_vector_init(&y, igraph_vcount(&g)); igraph_vector_fill(&y, 1.23); SETVANV(&g, "y", &y); igraph_vector_destroy(&y); for (i=0; i<igraph_vcount(&g); i++) { if (VAN(&g, "y", i) != 1.23) { return 21; } } igraph_vector_init_seq(&y, 0, igraph_vcount(&g)-1); SETVANV(&g, "foobar", &y); igraph_vector_destroy(&y); for (i=0; i<igraph_vcount(&g); i++) { if (VAN(&g, "foobar", i) != i) { return 22; } } igraph_strvector_init(&id, igraph_vcount(&g)); for (i=0; i<igraph_vcount(&g); i++) { snprintf(str, sizeof(str)-1, "%li", i); igraph_strvector_set(&id, i, str); } SETVASV(&g, "foo", &id); igraph_strvector_destroy(&id); for (i=0; i<igraph_vcount(&g); i++) { printf("%s ", VAS(&g, "foo", i)); } printf("\n"); igraph_strvector_init(&id, igraph_vcount(&g)); for (i=0; i<igraph_vcount(&g); i++) { snprintf(str, sizeof(str)-1, "%li", i); igraph_strvector_set(&id, i, str); } SETVASV(&g, "id", &id); igraph_strvector_destroy(&id); for (i=0; i<igraph_vcount(&g); i++) { printf("%s ", VAS(&g, "id", i)); } printf("\n"); /* Set edge attributes as vector */ igraph_vector_init(&y, igraph_ecount(&g)); igraph_vector_fill(&y, 12.3); SETEANV(&g, "weight", &y); igraph_vector_destroy(&y); for (i=0; i<igraph_ecount(&g); i++) { if (EAN(&g, "weight", i) != 12.3) { return 23; } } igraph_vector_init_seq(&y, 0, igraph_ecount(&g)-1); SETEANV(&g, "foobar", &y); igraph_vector_destroy(&y); for (i=0; i<igraph_ecount(&g); i++) { if (VAN(&g, "foobar", i) != i) { return 24; } } igraph_strvector_init(&id, igraph_ecount(&g)); for (i=0; i<igraph_ecount(&g); i++) { snprintf(str, sizeof(str)-1, "%li", i); igraph_strvector_set(&id, i, str); } SETEASV(&g, "foo", &id); igraph_strvector_destroy(&id); for (i=0; i<igraph_ecount(&g); i++) { printf("%s ", EAS(&g, "foo", i)); } printf("\n"); igraph_strvector_init(&id, igraph_ecount(&g)); for (i=0; i<igraph_ecount(&g); i++) { snprintf(str, sizeof(str)-1, "%li", i); igraph_strvector_set(&id, i, str); } SETEASV(&g, "color", &id); igraph_strvector_destroy(&id); for (i=0; i<igraph_ecount(&g); i++) { printf("%s ", EAS(&g, "color", i)); } printf("\n"); /* Delete all remaining attributes */ DELALL(&g); igraph_cattribute_list(&g, &gnames, >ypes, &vnames, &vtypes, &enames, &etypes); if (igraph_strvector_size(&gnames) != 0 || igraph_strvector_size(&vnames) != 0 || igraph_strvector_size(&enames) != 0) { return 25; } /* Destroy */ igraph_vector_destroy(>ypes); igraph_vector_destroy(&vtypes); igraph_vector_destroy(&etypes); igraph_strvector_destroy(&gnames); igraph_strvector_destroy(&vnames); igraph_strvector_destroy(&enames); igraph_destroy(&g); return 0; }
//------------------------------------------------------------------------------------------------- int main(int argc, char **argv) { igraph_set_error_handler(igraph_error_handler_printignore); igraph_i_set_attribute_table(&igraph_cattribute_table); drawingcontrol=1; runningcontrol=0; cleared=1; graphisloaded=0; newgraph=1; usesteady=0; ispii=0; haveout=0; isrelaxed=0; havecstop=0; isdissipating=0; //RANDOM NUMBER GENERATOR INITIALISE init_genrand(0); //srand(3); //preloaded graph: { latticedim=2; latticeside=5; istoro=1; islattice=1; isclustered=0; israndomER1=0; generatelattice(2,5,1,0,0,0,0); //inizializations igraph_matrix_init(&state, 0, 0); igraph_matrix_init(&density, 0, 0); igraph_matrix_init(&densityold,0,0); igraph_matrix_init(&statenew, 0, 0); igraph_matrix_init(&flux, 0, 0); igraph_matrix_init(&loss, 0, 0); beginner=(nodesnumber/2); InitialStateTAS(beginner,0,totrun); igraph_vector_init(&gain,nodesnumber); graphisloaded=1; newgraph=1; haveloadedstate=0; drnodes=1; drlinks=1; drfluxes=0; } havepath=0; sprintf(path,"No path"); logDebug("\n DEFAULT ADJ MATRIX:\n"); print_matrix_ur(&admatrix,stdout); printf("\n"); printf("\n"); rewrite=1; CreateMyWindow(); //Fl::add_timeout(1.0,mainidle_cb); Fl::add_idle(mainidle_cb, 0); Fl::run(); histdist.Clear(); igraph_destroy(&graph); igraph_destroy(&sgraph); igraph_matrix_destroy(&admatrix); igraph_matrix_destroy(&layout); igraph_matrix_destroy(&density); igraph_matrix_destroy(&densityold); igraph_matrix_destroy(&state); igraph_matrix_destroy(&loadedstate); igraph_matrix_destroy(&statenew); igraph_matrix_destroy(&flux); igraph_vector_destroy(&gain); igraph_matrix_destroy(&loss); igraph_vector_destroy(&statstate); igraph_matrix_destroy(&estates); closeout(); return 0; }
int main(int argc, char **argv) { igraph_t g; igraph_error_handler_t* oldhandler; igraph_warning_handler_t* oldwarnhandler; int result; FILE *ifile, *ofile; igraph_i_set_attribute_table(&igraph_cattribute_table); /* GraphML */ ifile=fopen("test.gxl", "r"); if (ifile==0) { return 10; } oldhandler=igraph_set_error_handler(igraph_error_handler_ignore); oldwarnhandler=igraph_set_warning_handler(custom_warning_handler); if ((result=igraph_read_graph_graphml(&g, ifile, 0))) { /* maybe it is simply disabled at compile-time */ if (result == IGRAPH_UNIMPLEMENTED) return 77; return 1; } igraph_set_error_handler(oldhandler); fclose(ifile); /* Write it back */ ofile=fopen("test2.gxl", "w"); /* If we can't create the test file, just skip the test */ if (ofile) { if ((result=igraph_write_graph_graphml(&g, ofile, /*prefixattr=*/ 1))) { return 1; } fclose(ofile); unlink("test2.gxl"); } dump_graph("The directed graph:\n", &g); igraph_destroy(&g); /* The same with undirected graph */ ifile=fopen("test.gxl", "r"); if ((result=igraph_read_graph_graphml(&g, ifile, 0))) { return 1; } fclose(ifile); dump_graph("The undirected graph:\n", &g); igraph_destroy(&g); /* Test a GraphML file with default attributes */ ifile=fopen("graphml-default-attrs.xml", "r"); if ((result=igraph_read_graph_graphml(&g, ifile, 0))) { return 1; } fclose(ifile); dump_graph("The directed graph:\n", &g); dump_vertex_attribute_bool("type", &g); dump_vertex_attribute_string("gender", &g); dump_vertex_attribute_numeric("age", &g); dump_vertex_attribute_bool("retired", &g); igraph_destroy(&g); /* Test a GraphML file with namespaces */ ifile=fopen("graphml-namespace.xml", "r"); if ((result=igraph_read_graph_graphml(&g, ifile, 0))) { return 1; } fclose(ifile); dump_graph("The undirected graph:\n", &g); igraph_destroy(&g); /* Restore the old warning handler */ igraph_set_warning_handler(oldwarnhandler); /* There were sometimes problems with this file */ /* Only if called from R though, and only on random occasions, once in every ten reads. Do testing here doesn't make much sense, but if we have the file then let's do it anyway. */ ifile=fopen("graphml-hsa05010.xml", "r"); igraph_read_graph_graphml(&g, ifile, 0); fclose(ifile); igraph_destroy(&g); return 0; }