void test_graph_search_sccs() { GRAPH* graph = graph_create(); graph_add_edge(graph, 6, 0); graph_add_edge(graph, 3, 6); graph_add_edge(graph, 0, 3); graph_add_edge(graph, 8, 6); graph_add_edge(graph, 5, 8); graph_add_edge(graph, 2, 5); graph_add_edge(graph, 8, 2); graph_add_edge(graph, 7, 5); graph_add_edge(graph, 1, 7); graph_add_edge(graph, 4, 1); graph_add_edge(graph, 7, 4); GRAPH* reverse = graph_reverse(graph); GRAPH_SEARCH* graph_search1 = graph_search_create(reverse); graph_search_finish_times(reverse, graph_search1); graph_destroy(reverse); GRAPH_SEARCH* graph_search2 = graph_search_create(graph); graph_search_sccs(graph, graph_search2, graph_search1->finish_times); graph_search_destroy(graph_search1); graph_search_destroy(graph_search2); graph_destroy(graph); }
int main(int argc, char *argv[]) { /* setup */ char *path = "./data/ct/"; char *path2 = "/home/gyc/Sources/linux.doc/kernel/"; vector_char str; vector_char_init(&str,100); VECTOR(str)[0] = '\0'; SetupLexer(); dic_setup(); struct dictionary *dict = new_dictionary(10000); graph_t lkn; vector_int edges; catch_function_call_dir(path, dict, &edges); printf("capacity=%d,size=%d\n",dict_capacity(dict), dict_size(dict)); new_graph(&lkn, &edges, 0, GRAPH_DIRECTED); struct dictionary *filedict = new_dictionary(4); vector_funcP flist; vector_funcP_init_(&flist, dict_size(dict)); get_function_filename(path2, dict, filedict, &flist); printf("filedict: capacity=%d,size=%d\n",dict_capacity(filedict), dict_size(filedict)); /* reciprocal */ printf("reciprocal = %f \n", graph_reciprocal(&lkn)); vector_double res; vector_double_init(&res, 0); graph_betweenness(&lkn, &res, graph_vss_all(), GRAPH_DIRECTED); printf("betweenness directed:"); print_vector_double(&(res),stdout); vector_double_destroy(&res); /* degree */ graph_degree(&lkn, &edges, graph_vss_all(), GRAPH_OUT, GRAPH_NO_LOOPS); printf(">>>out, no loops"); int min, max, sum; double ave; graph_degree_minmax_avesum(&lkn, &min, &max, &ave, &sum, GRAPH_OUT, GRAPH_NO_LOOPS); printf("minout=%d\nmaxout=%d\nsumout=%d\naveout=%f\n",min,max,sum,ave); graph_degree_minmax_avesum(&lkn, &min, &max, &ave, &sum, GRAPH_IN, GRAPH_NO_LOOPS); printf("minin=%d\nmaxin=%d\nsumin=%d\navein=%f\n",min,max,sum,ave); /* fast community */ graph_reverse(&lkn); vector_int v1; vector_int_init(&v1,0); int ncom = 0; double modularity = graph_community_fastgreedy(&lkn, &v1, &ncom); printf("modularity = %f,ncom = %d\n",modularity,ncom); FILE *f = fopen("funccom.fc.xlsx","w"); fprintf(f, "comID\tname\n"); for (int i = 0; i < dict_size(dict);i++) { fprintf(f, "%d\t", VECTOR(v1)[i]); struct rb_node* e = dict_ele(dict, i); dic_traceback_string(e, &str); fprintf(f, "%s\n",VECTOR(str)); } fclose(f); f = fopen("comID.fc.xlsx","w"); output_com_filename(&flist, &v1, graph_vertices_count(&lkn), ncom, filedict, f); fclose(f); //print_vector_int(&v1, stdout); print_communities(&lkn, &v1, "community.fc.xlsx", "comedge.fc.xlsx"); vector_funcP_destroy(&flist); vector_int_destroy(&v1); vector_char_destroy(&str); vector_int_destroy(&edges); graph_destroy(&lkn); return 0; }