/* * graph_combine_vertices */ int graph_combine_vertices(const graph_t *graph, const vector_int *membership, graph_t *res) { int ec = graph_edges_count(graph); vector_int new_edges; vector_int_init(&new_edges, 2 * ec); int from, to, nef, net; int eid = 0; for (int i = 0; i < ec; i++) { graph_edge(graph, i, &from, &to); nef = VECTOR(*membership)[from]; net = VECTOR(*membership)[to]; if (nef == net || nef < 0 || net < 0) continue; VECTOR(new_edges)[2*eid+0] = nef; VECTOR(new_edges)[2*eid+1] = net; eid++; } eid--; vector_int_resize(&new_edges, 2 * eid); new_graph(res, &new_edges, 0, graph->directed); graph_remove_multi_edges(res); return 0; }
/* * graph_neighbor_subgraph - calculate the @subgraph consists of the neighbors of vertex @s * used for calculate the local efficiency. * * @neis: neighbors' id */ int graph_neighbor_subgraph(const graph_t *graph, graph_t *subgraph, vector_int *neis, int s, graph_neimode_t mode) { int vc = graph_vertices_count(graph); graph_neighbors(graph, neis, s, mode); vector_int edges; vector_int_init(&edges, 0); vector_int neis2; vector_int_init(&neis2, 0); int v, w; for (int i = 0; i < vector_int_size(neis); i++) { v = VECTOR(*neis)[i]; if (v == s) continue; graph_neighbors(graph, &neis2, v, GRAPH_OUT); for (int j = 0; j < vector_int_size(&neis2); j++) { w = VECTOR(neis2)[j]; if (w == s || w == v) continue; int wid = vector_int_whereis(neis, w); if (-1 != wid) { vector_int_push_back(&edges, i); vector_int_push_back(&edges, wid); } } } new_graph(subgraph, &edges, vector_int_size(neis), graph_is_directed(graph)); vector_int_destroy(&neis2); vector_int_destroy(&edges); return 0; }
t_graph* prim(t_graph *g, int s){ if(g==NULL||s<0 || s>g->maxv) return NULL; int i; t_graph* ret = new_graph(g->maxv); t_edge* temp = (t_edge*)malloc(sizeof(t_edge)); t_heap* theHeap = newHeap(g->maxv); for(i=0;i<g->maxv;i++) g->vertices[i].visited = FALSE; g->vertices[s].visited = TRUE; printf("%s\n",g->vertices[s].name); for(i=0;i<g->maxv;i++){ if(g->am[s][i]!=0){ add_edge(ret,s,i,g->am[s][i]); addMinElement(theHeap,(void*)new_edge(s,i,g->am[s][i]),&eecomp); } } while(theHeap->current_size>0){ temp = (t_edge*)popMinHeap(theHeap,&eecomp); g->vertices[temp->dst].visited = TRUE; printf("%s\n",g->vertices[temp->dst].name); for(i=0;i<(g->maxv);i++){ if(g->am[temp->dst][i]!=0&&g->vertices[i].visited ==FALSE){ addMinElement(theHeap,(void*)new_edge(temp->dst,i,g->am[temp->dst][i]),&eecomp); add_edge(ret,temp->dst,i,g->am[temp->dst][i]); } } } return ret; }
t_graph* new_digraph(int n) { t_graph* g; g=new_graph(n); g->digraph=TRUE; return g; }
/* Abre el archivo `filename` y crea un grafo con la lista de adyacencia * inscrita en el. Cada linea del archivo debe cumplir la siguiente expresion * regular (con BL como el BUFFER_LEN): '\d{1,BL}:( \d{1,BL})*\n' * Retorno: Un grafo G (descrito en structures.h)*/ struct graph *file_to_graph(const char * filename) { char ch = '\0', buffer[BUFFER_LEN] = ""; // Se puede calcular por el nro de lineas. unsigned int i, id, size, *tmp; struct list *last_list; struct node *last_node; struct graph *G; FILE *fp = fopen(filename, "r"); if(fp == NULL){ fprintf(stderr,"No se puede leer el archivo \"%s\".\n", filename); return NULL; } size = count_lines(fp); G = new_graph(size); IDC = (int*) calloc(size, sizeof(int)); ODC = (int*) malloc(size * sizeof(int)); while (1) { i = 0; do { ch = getc(fp); if (ch == EOF) { fclose(fp); return G; } else if (ch == ':') { id = atoi(buffer); last_list = new_list(); ch = getc(fp); if (ch == '\n'){ break; } i = 0; memset(buffer, 0, BUFFER_LEN); } else if (ch == ' ' || ch == '\n') { tmp = (int *) malloc(sizeof(int)); buffer[i] = '\0'; *tmp = atoi(buffer); list_add(last_list, tmp); IDC[*tmp]++; i = 0; memset(buffer, 0, BUFFER_LEN); } else { buffer[i++] = ch; } } while (ch != '\n'); ODC[id] = last_list->size; last_node = new_node(id, last_list); graph_add_node(G, last_node); last_node = NULL; last_list = NULL; } }
void print_lua_graph(struct text_object *obj, char *p, int p_max_size) { double per; if (!p_max_size) return; if (llua_getnumber(obj->data.s, &per)) { new_graph(obj, p, p_max_size, per); } }
int main() { srandom(time(0)); graph_t a; vector_int v1; vector_int_init_value_end(&v1, -1, 1,5, 2,5, 1,2, 2,1, 0,3, 0,2, 3,4, 3,6, 4,6, 6,4, -1,7, -1); new_graph(&a, &v1, 0, GRAPH_DIRECTED); print_graph_vectors(&a, stdout); printf("ec=%d\t",graph_edges_count(&a)); printf("vc=%d\n",graph_vertices_count(&a)); int vc = graph_vertices_count(&a); vector_int mem; vector_int_init(&mem, vc); vector_int_fill(&mem, -1); vector_int cs; vector_int_init(&cs, 0); int cc; graph_clusters_strong(&a,&mem,&cs,&cc); printf("mem:"); print_vector_int(&mem, stdout); printf("<<<combine vertices\n"); graph_t b; graph_combine_vertices(&a, &mem, &b); print_graph_vectors(&b, stdout); printf("ec=%d\t",graph_edges_count(&b)); printf("vc=%d\n",graph_vertices_count(&b)); double re; printf(">>>>randomly attack\n"); re = graph_fault_propagation(&b, 0.3, 0.2, GRAPH_ATK_RANDOM); printf("random re=%f\n",re); printf(">>>>outgoing based attack\n"); re = graph_fault_propagation(&b, 0.3, 0.2, GRAPH_ATK_OUTGOING); printf("outgoing re=%f\n",re); printf(">>>>incoming based attack\n"); re = graph_fault_propagation(&b, 0.3, 0.2, GRAPH_ATK_INCOMING); printf("incoming re=%f\n",re); vector_int inf; vector_int_init(&inf, 0); int cascading_nodes_count = graph_cascading_nodes_count(&b, &inf, 0.3, 0.2, GRAPH_ATK_RANDOM); assert(cascading_nodes_count == vector_int_sum(&inf)); vector_int_destroy(&inf); vector_int_destroy(&mem); vector_int_destroy(&cs); vector_int_destroy(&v1); graph_destroy(&b); graph_destroy(&a); return 0; }
int main() { graph *G = new_graph(7); add_edge(1, 2, G); add_edge(2, 3, G); add_edge(3, 5, G); add_edge(2, 4, G); add_edge(4, 6, G); print_graph(G); graph_DFS(1, G); return 0; }
} END_TEST START_TEST(test_graph_get_node) { kld_graph_t * g = (kld_graph_t *) new_graph(); kld_graph_node_t * n1 = (kld_graph_node_t *) new_graph_node(g); kld_graph_node_t * n2 = (kld_graph_node_t *) new_graph_node(g); kld_graph_node_t * gn1 = (kld_graph_node_t *) graph_get_node(g, 0); kld_graph_node_t * gn2 = (kld_graph_node_t *) graph_get_node(g, 1); fail_if(gn1 != n1, "Incorrect node returned."); fail_if(gn2 != n2, "Incorrect node returned."); } END_TEST
void print_execgraph(struct text_object *obj, char *p, int p_max_size) { double barnum; struct execi_data *ed = obj->data.opaque; if (!ed) return; read_exec(ed->cmd, p, p_max_size, 1); barnum = get_barnum(p); if (barnum >= 0) { new_graph(obj, p, p_max_size, round_to_int(barnum)); } }
graph *revert(state_inf_fwd *R, int size) { int i; graph *G=new_graph(size); for(i=0; i<size; i++) { if (R[i].go_1 == R[i].go_2) { insert_edge(G, R[i].go_1, i); } else { insert_edge(G, R[i].go_1, i); insert_edge(G, R[i].go_2, i); } }; return G; }
} END_TEST START_TEST(test_graph_remove_edge) { kld_graph_t * g = (kld_graph_t *) new_graph(); int data = 1; int * data_ref = &data; kld_graph_node_t * n1 = (kld_graph_node_t *) new_graph_node(g); kld_graph_node_t * n2 = (kld_graph_node_t *) new_graph_node(g); graph_insert_edge(g, n1, n2, data_ref); graph_remove_edge(g, n1, n2); kld_graph_edge_t * e = (kld_graph_edge_t *) graph_get_edge(g, n1, n2); fail_if(e != NULL, "Edge should be NULL after inserting and then removing it."); } END_TEST
int main(int argc, char ** argv){ FILE * inputfile; if(argc != 2){ printf("USAGE: %s input_parsed_file\n", argv[0]); return 1; } inputfile=fopen(argv[1], "r"); authors_dict = new_hash_table(AUTHORS_HASH_DIM, author_node); artcl_graph = new_graph(article_node); read_file(inputfile); fclose(inputfile); interface(); return 0; }
graph_t * copy_graph (graph_t *g){ graph_t *newg = NULL; char **app; /* array di stringhe per la chiamata a new_graph */ int i, j, error = FALSE; if( !g ){ /* se il grafo da copiare non esiste è inutile continuare */ errno = EINVAL; return NULL; } if( !(g->node) ){ MALLOC_IF( newg, sizeof(graph_t), UNO) newg->size = g->size; return newg; } MALLOC_IF( app, sizeof(char *), g->size) for(i = ZERO; i < (g->size); i++){ if( !(MALLOC( app[i], sizeof(char), LLABEL) ) ){ for(j = ZERO; j < i; j++) free(app[j]); free(app); return NULL; } strcpy( app[i], ((g->node)+i)->label ); } if( (newg = new_graph(g->size,app)) ){ /* se la copia del grafo (copia dell'array di nodi) avviene con successo */ if( !(newg = copy_adj(newg,g)) ){ /* faccio una copia delle liste di adiacenza di g */ error = TRUE; free_graph(&newg); } /* per non lasciare a metà la copia del grafo*/ } for(i = ZERO; i < (g->size); i++) /* app non mi serve più */ free(app[i]); free(app); if(error) return NULL; return newg; }
} END_TEST START_TEST(test_graph_insert_edge) { kld_graph_t * g = (kld_graph_t *) new_graph(); int data = 1; int * data_ref = &data; kld_graph_node_t * n1 = (kld_graph_node_t *) new_graph_node(g); kld_graph_node_t * n2 = (kld_graph_node_t *) new_graph_node(g); graph_insert_edge(g, n1, n2, data_ref); kld_graph_edge_t * e = (kld_graph_edge_t *) graph_get_edge(g, n1, n2); fail_if(e == NULL, "Edge is NULL after inserting it."); fail_if(e->data == NULL, "Edge data is NULL after inserting it."); fail_if(e->data != data_ref, "Edge data is not the expected value."); } END_TEST
Graph *read_graph(FILE *fp) { int number, count = 0; Vertex **vlist = NULL; while (fscanf(fp, " %d ->", &number) > 0) { int label; int weight; int direction; count += 1; vlist = realloc(vlist, count * sizeof *vlist); Vertex *curVertex = new_vertex(number); vlist[count - 1] = curVertex; while (fscanf(fp, " [%d %d %d]", &label, &weight, &direction) > 0) { add_adjacency_vertex_with_direction(curVertex, label, weight, direction); } } return new_graph(count, vlist); }
/* 1 --- 3 --- 5 * /| |\ _/| * / | |_\/ | * 0 | _/| \ | 7 * \ | _/ | \ | / * \|/ | \|/ * 2 --- 4 --- 6 */ graph_t * make_a_graph(bool is_directed){ int is_weighted = false; int n = 8; graph_t *g = new_graph(n, is_weighted, is_directed); graph_add_edge(g, 0, 1); graph_add_edge(g, 0, 2); graph_add_edge(g, 1, 2); graph_add_edge(g, 1, 3); graph_add_edge(g, 2, 4); graph_add_edge(g, 2, 5); graph_add_edge(g, 3, 4); graph_add_edge(g, 3, 5); graph_add_edge(g, 3, 6); graph_add_edge(g, 4, 6); graph_add_edge(g, 5, 6); graph_add_edge(g, 6, 7); return g; }
static void print_diskiograph_dir(struct text_object *obj, int dir, char *p, int p_max_size) { struct diskio_stat *diskio = obj->data.opaque; double val; if (!diskio) return; if (!p_max_size) return; if (dir < 0) val = diskio->current_read; else if (dir == 0) val = diskio->current; else val = diskio->current_write; new_graph(obj, p, p_max_size, val); }
void print_execigraph(struct text_object *obj, char *p, int p_max_size) { struct execi_data *ed = obj->data.opaque; if (!ed) return; if (time_to_update(ed)) { double barnum; read_exec(ed->cmd, p, p_max_size, 1); barnum = get_barnum(p); if (barnum >= 0.0) { ed->barnum = barnum; } ed->last_update = current_update_time; } new_graph(obj, p, p_max_size, (int) (ed->barnum)); }
static flowgraph_t * flow_build_graph (function_t *func) { sblock_t *sblock = func->sblock; flowgraph_t *graph; flownode_t *node; sblock_t *sb; int i; int pass = 0; graph = new_graph (); graph->func = func; func->graph = graph; for (sb = sblock; sb; sb = sb->next) graph->num_nodes++; // + 2 for the uninitialized dummy head block and the live dummy end block graph->nodes = malloc ((graph->num_nodes + 2) * sizeof (flownode_t *)); for (i = 0, sb = sblock; sb; i++, sb = sb->next) graph->nodes[i] = flow_make_node (sb, i, func); // Create the dummy node for detecting uninitialized variables node = flow_make_node (0, graph->num_nodes, func); graph->nodes[graph->num_nodes] = node; // Create the dummy node for making global vars live at function exit node = flow_make_node (0, graph->num_nodes + 1, func); graph->nodes[graph->num_nodes + 1] = node; do { if (pass > 1) internal_error (0, "too many unreachable node passes"); flow_find_successors (graph); flow_make_edges (graph); flow_build_dfst (graph); if (options.block_dot.flow) dump_dot (va ("flow-%d", pass), graph, dump_dot_flow); pass++; } while (flow_remove_unreachable_nodes (graph)); flow_find_predecessors (graph); flow_find_dominators (graph); flow_find_loops (graph); return graph; }
} END_TEST START_TEST(test_graph_get_edge) { kld_graph_t * g = (kld_graph_t *) new_graph(); int data = 1; int * data_ref = &data; kld_graph_node_t * n1 = (kld_graph_node_t *) new_graph_node(g); kld_graph_node_t * n2 = (kld_graph_node_t *) new_graph_node(g); graph_insert_edge(g, n1, n2, data_ref); kld_graph_edge_t * e = (kld_graph_edge_t *) graph_get_edge(g, n1, n2); kld_graph_edge_t * e2 = (kld_graph_edge_t *) graph_get_edge(g, n2, n1); fail_if(e == NULL, "Incorrect edge returned."); fail_if(e->data == NULL, "Incorrect edge data returned."); fail_if(e->data != data_ref, "Incorrect edge data returned."); fail_if(e2 != NULL, "Incorrect edge returned."); } END_TEST
int graph_subgraph(const graph_t *graph, graph_t *subgraph, graph_vs_t vids) { int vc = graph_vertices_count(graph); int ec = graph_edges_count(graph); vector_int vss; vector_int_init(&vss, vc); vector_int_fill(&vss, -1); int i,j,u,v; graph_vit_t vit; graph_vit_create(graph, vids, &vit); int nvc = GRAPH_VIT_SIZE(vit); for (GRAPH_VIT_RESET(vit), i=0; !GRAPH_VIT_END(vit); GRAPH_VIT_NEXT(vit), i++) { int vid = GRAPH_VIT_GET(vit); VECTOR(vss)[vid] = i; } graph_vit_destroy(&vit); int nec = 0; vector_int new_edges; vector_int_init(&new_edges, 2 * ec); for (int eid = 0; eid < ec; eid++) { graph_edge(graph, eid, &i, &j); u = VECTOR(vss)[i]; v = VECTOR(vss)[j]; if (-1 == u || -1 == v) continue; VECTOR(new_edges)[2*nec+0] = u; VECTOR(new_edges)[2*nec+1] = v; nec++; } vector_int_resize(&new_edges, 2 * nec); new_graph(subgraph, &new_edges, nvc, graph_is_directed(graph)); vector_int_destroy(&new_edges); vector_int_destroy(&vss); return 0; }
t_graph* prim( t_graph* g, int s) { t_graph *mst; int count, i; t_pQueue *pq; t_edge *min; if(g!=NULL && s>=0 && s < (g->v)) { mst = new_graph(g->v); pq = new_priorityCap(g->e); for(i=0; i<g->v;i++) add_vertex(mst, g->vertices[i].name); mst->vertices[s].visited = TRUE; for(i=0; i< g->v;i++) { if(i!=s && g->am[s][i]!=INF) enqueue(pq, (void*) (finde(g, i ,s, g->am[s][i])),&eecomp) ; } count = 0; while (count<g->v) { for(min=dequeue(pq, &eecomp);min!=NULL && !(mst->vertices[min->dst].visited);min=dequeue(pq, &eecomp)) ; if(min!= NULL) { mst->vertices[min->dst].visited = TRUE; add_edge(mst, min->src, min->dst, min->weight); count++; for(i=0; i< g->v;i++) { if(i!=s && g->am[s][i]!=INF) enqueue(pq, (void*) (finde(g, i, s, g->am[s][i])),&eecomp) ; } } } free(pq); free(min); return mst; } }
} END_TEST START_TEST(test_graph_node_neighbors) { kld_graph_t * g = (kld_graph_t *) new_graph(); int data = 1; kld_graph_node_t * n1 = (kld_graph_node_t *) new_graph_node(g); kld_graph_node_t * n2 = (kld_graph_node_t *) new_graph_node(g); kld_graph_node_t * n3 = (kld_graph_node_t *) new_graph_node(g); kld_vector_t * v = new_vector(); vector_append(v, NULL); vector_append(v, &data); vector_append(v, NULL); matrix_append_row(g->adj_matrix, v); kld_vector_t * v2 = new_vector(); vector_append(v2, &data); vector_append(v2, NULL); vector_append(v2, NULL); matrix_append_row(g->adj_matrix, v2); kld_vector_t * v3 = new_vector(); vector_append(v3, NULL); vector_append(v3, NULL); vector_append(v3, NULL); matrix_append_row(g->adj_matrix, v3); fail_if(graph_is_empty(g), "Graph should not be empty upon initialization"); kld_vector_t * nbrs1 = (kld_vector_t *) graph_node_neighbors(g, n1); kld_vector_t * nbrs2 = (kld_vector_t *) graph_node_neighbors(g, n2); kld_vector_t * nbrs3 = (kld_vector_t *) graph_node_neighbors(g, n3); fail_if(vector_get(nbrs1, 0) != n2, "After appending an edge from n1 to n2 in the graph, it should mark n2 as a neighbor of n1."); fail_if(vector_get(nbrs2, 0) != n1, "After appending an edge from n2 to n1 in the graph, it should mark n1 as a neighbor of n2."); fail_if(!vector_is_empty(nbrs3), "After appending null edges to the graph, it should have no neighbors"); } END_TEST
int main() { int vc = 9334; int ec = 26841; vector_int edges; vector_int_init(&edges, ec * 2); srand((int)time(0)); int src = -1, dst = -1; for (int i = 0, ei = 0; i < ec; i++,ei+=2) { src = (int)(rand() % vc); dst = (int)(rand() % vc); while (src == dst) { src = (int)(rand() % vc); dst = (int)(rand() % vc); } VECTOR(edges)[ei] = src; VECTOR(edges)[ei+1] = dst; } graph_t a; new_graph(&a, &edges, vc, 1); assert(vc == graph_vertices_count(&a)); assert(ec == graph_edges_count(&a)); printf("reciprocal = %f \n", graph_reciprocal(&a)); int min, max, sum; double ave; graph_degree_minmax_avesum(&a, &min, &max, &ave, &sum, GRAPH_OUT, GRAPH_NO_LOOPS); printf("minout=%d\nmaxout=%d\n\n",min,max); printf("sum=%d\nave=%f\n\n\n",sum,ave); graph_degree_minmax_avesum(&a, &min, &max, &ave, &sum, GRAPH_IN, GRAPH_NO_LOOPS); printf("minin=%d\nmaxin=%d\n\n\n",min,max); printf("sum=%d\nave=%f\n\n\n",sum,ave); FILE * f = fopen("a.sif","w"); print_edge(&edges, f); fclose(f); //print_graph_ct(&a, GRAPH_OUT, stdout); }
} END_TEST START_TEST(test_graph_node_is_adjacent) { kld_graph_t * g = (kld_graph_t *) new_graph(); int data = 1; kld_graph_node_t * n1 = (kld_graph_node_t *) new_graph_node(g); kld_graph_node_t * n2 = (kld_graph_node_t *) new_graph_node(g); kld_vector_t * v = new_vector(); vector_append(v, NULL); vector_append(v, &data); matrix_append_row(g->adj_matrix, v); kld_vector_t * v2 = new_vector(); vector_append(v2, &data); vector_append(v2, NULL); matrix_append_row(g->adj_matrix, v2); fail_if(graph_is_empty(g), "Graph should not be empty upon initialization"); fail_if(!graph_node_is_adjacent(g, n1, n2), "Nodes are not adjacent when expected to be"); } END_TEST
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; }
int main(int argc, char **argv) { t_graph *g = new_graph(6); int *d; int i, j; int **f; t_graph *mst; add_vertex(g, "s"); add_vertex(g, "o"); add_vertex(g, "p"); add_vertex(g, "q"); add_vertex(g, "r"); add_vertex(g, "t"); add_edge(g, 0, 1, 3); add_edge(g, 0, 2, 3); add_edge(g, 1, 2, 2); add_edge(g, 1, 3, 3); add_edge(g, 2, 4, 2); add_edge(g, 3, 4, 4); add_edge(g, 3, 5, 2); add_edge(g, 4, 5, 3); dfs(g); bfs(g); show_am(g); show_edges(g); d = dijkstra(g, 0); for (i = 0; i < g->v; i++) { if (d[i] != INF) printf("%d ",d[i]); else printf("%s ","I"); } printf("%s", "\n"); free(d); d = shortestPath(g, 0); for (i = 0; i < g->v; i++) { if (d[i] != -1) printf("%s ", g->vertices[d[i]].name); else printf("%s ", "NA"); printf("%c ",' '); } printf("%s","\n"); f = floyd(g); for (i = 0; i < g->v; i++) { for (j = 0; j < g->v; j++) { if (f[i][j] != INF) printf("%d", f[i][j]); else printf("%s", "I"); printf("%c", ' '); } printf("%s", " \n"); } free(f); // kruskal and prim should be used on undirected graphs printf("\n"); mst = kruskal(g); show_edges(mst); free(mst); printf("\n\n\n"); // // mst = prim(g, 0); //show_edges(mst); //free(mst); /* // FF should only be used on digraphs mst = fordFulkerson(g, 0, 5); show_am(mst); show_edges(mst); printf("%s", " \n \n"); for (i = 0; i < g->v; i++) { for (j = 0; j < g->v ; j++) { if ((i != j) && (g->am[i][j] != INF)) { printf("%d ", mst->am[j][i]); printf("%c ",'/'); printf("%d ",g->am[i][j]); printf("%c ",' '); } else { printf("%s ", "0/0 "); } } printf("%s ", " \n "); } free(mst);*/ free(g); return 0; }
int main(int argc, char *argv[]) { int nv, ne, i, ind1, ind2, len; double mf; FILE *fp, *fp_meas; int tt; char str1[256] = ""; char *sg; char *ms_f; char *of; int legacy = 0; int ii = 1; sf *sf; if (argc < 4) { printf( "Usage: exampleProgram nameSizeGraph nameFileValues outputFile \n"); exit(-1); } if (argc >= 4){ if (!strcmp("-l",argv[ii])){ legacy = 1; ii++; printf("Legacy output mode\n"); } } sg = argv[ii++]; ms_f = argv[ii++]; of = argv[ii++]; if ((fp = fopen(sg, "r")) == NULL) { printf("Error (Reading): unable to open .size!\n"); return (0); } if ((fp_meas = fopen(ms_f, "r")) == NULL) { printf("Error (Reading): unable to open measuring function file!\n"); return (0); } tt = fscanf(fp, "%d\n %d\n", &nv, &ne); Graph *G = new_graph(nv); for (i = 0; i < nv; i++) { tt = fscanf(fp_meas, "%lf", &mf); graph_add_node(G,mf); } printf("Done\n"); int x, y; for (i = 0; i < ne; i++) { tt = fscanf(fp, "%d %d \n", &ind1, &ind2); x = ind1; y = ind2; add_new_edge_graph(G,x,y); } fclose(fp); fclose(fp_meas); sf = newDeltaStarReductionAlgorithm(G); printf("Delta star reduction: done\n"); destroy_graph(G); write_ang_pt(sf, of, legacy); printf("Sf printed\n"); sf_destroy(sf); return 0; }
} END_TEST START_TEST(test_graph_is_empty) { kld_graph_t * g = (kld_graph_t *) new_graph(); fail_if(!graph_is_empty(g), "Graph is not empty upon initialization"); } END_TEST