int main(void) { //Seed the Random number generator srand((unsigned)time(0)); int i,j ; struct point pt; float distances1[500] = {0}; float distances2[500] = {0}; //Two Random Walks runTrial(500, distances1, 'U'); graph_new(LINE, distances1, 500, "legend=1st Walk, xlabel=Step Number, ylabel=Distance from the origin"); runTrial(500, distances2, 'U'); graph_new(LINE, distances2, 500, "legend=2nd Walk, xlabel=Step Number, ylabel=Distance from the origin, title=2 Random Walks"); graph_show(); //Simulate 300 Random Walks with 500 steps each simulate(300,500); simulateEW(300,500); simulateBiased(300,500); graph_show(); return 0; }
graph_s *border_graph(msw_s *ms) { graph_s *n = graph_new(); int *r = ms->revealed; int *graph_perm = malloc(ms->g->nodes * sizeof(int)); int j = 0; for(int i = 0; i < ms->g->nodes;i++){ if (r[i] == 0){ graph_add_node(n,ms->g->node_list[i]); graph_perm[i]=j; j++; } } int neighb; for(int i = 0; i < ms->g->nodes;i++){ for(int j = 0; j < ms->g->neighb_count[i]; j++){ neighb = ms->g->neighb_list[i][j]; if (r[i] > 0 && r[neighb] == 0){ graph_add_arc(n,graph_perm[neighb],i); } } } free(graph_perm); return n; }
void graph_test() { graphData* d = graphData_new( 10 ); graph* g = graph_new( g, 0, 0, 320, 240, 1.f, 1.f ); mem_free( g ); mem_free( d ); }
game_t *game_new(int graph_type, int g_p1, int g_p2, mpq_t p_c) { game_t *game = (game_t *)g_malloc(sizeof(game_t)); game->graph = graph_new(graph_type, g_p1, g_p2); mpq_init(game->s); mpq_set_si(game->s, S_MIN, 1); mpq_init(game->t); mpq_set_si(game->t, T_MIN, 1); mpq_init(game->p_c); mpq_set(game->p_c, p_c); game->initial_config = (int *)g_malloc(sizeof(int) * game->graph->n); game->current_config = (int *)g_malloc(sizeof(int) * game->graph->n); game->next_config = (int *)g_malloc(sizeof(int) * game->graph->n); int i; for(i = 0; i < game->graph->n; ++i) { game->initial_config[i] = 0; game->current_config[i] = 0; game->next_config[i] = 0; } return game; }
/** * @brief construct test graph #1 * * +------->t/2----->------>x/4 * | |^ / |^ * | || / || * s/1------ ||---/-->----+ || * | || / \ || * | V| / \V| * +------->y/3------------>z/5 * */ static GRAPH_T* graph_1_get (void) { GRAPH_T* g; g = graph_new (GRAPH_DIRECTED_T, GRAPH_INT_T); fprintf (stderr, "* inserting e1(1,2)\n"); graph_add_i (g, "e1", 1, NULL, 2, NULL, 10, DS_TRUE); fprintf (stderr, "* inserting e2(1,3)\n"); graph_add_i (g, "e2", 1, NULL, 3, NULL, 5, DS_TRUE); fprintf (stderr, "* inserting e3(2,4)\n"); graph_add_i (g, "e3", 2, NULL, 4, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e4(2,3)\n"); graph_add_i (g, "e4", 2, NULL, 3, NULL, 2, DS_TRUE); fprintf (stderr, "* inserting e5(3,2)\n"); graph_add_i (g, "e5", 3, NULL, 2, NULL, 3, DS_TRUE); fprintf (stderr, "* inserting e6(3,4)\n"); graph_add_i (g, "e6", 3, NULL, 4, NULL, 9, DS_TRUE); fprintf (stderr, "* inserting e7(3,5)\n"); graph_add_i (g, "e7", 3, NULL, 5, NULL, 2, DS_TRUE); fprintf (stderr, "* inserting e8(4,5)\n"); graph_add_i (g, "e8", 4, NULL, 5, NULL, 4, DS_TRUE); fprintf (stderr, "* inserting e9(5,4)\n"); graph_add_i (g, "e9", 5, NULL, 4, NULL, 6, DS_TRUE); fprintf (stderr, "* inserting e10(5,1)\n"); graph_add_i (g, "e10", 5, NULL, 1, NULL, 7, DS_TRUE); return g; }
void simulateEW(int numSims, int numSteps) { int sim; float lastPointX[numSims]; float lastPointY[numSims]; float average[numSteps]; memset(average,0,numSteps * sizeof(float)); int step; for (sim = 0; sim < numSims; sim++) { struct point final_xy; final_xy = runTrial(numSteps, average, 'L'); //Add to the average array lastPointX[sim] = final_xy.x; lastPointY[sim] = final_xy.y; } for (step=0; step < numSteps; step++) average[step] = average[step] / (float) numSims; graph_new(LINE, average, numSteps, "legend=EW Walk,title=Repititive Simulations,xlabel=Step Number,ylabel=Distance(averaged)"); graph_xy(SCATTER,lastPointX,lastPointY, numSims, "legend=End Points(EW Walk), title=Last Point in each Trial, xlabel=x-coordinate, ylabel=y-coordinate"); printf("Final Distance EW:%f\n", average[numSteps - 1] ); }
/** * @brief construct test graph #4 * */ static GRAPH_T* graph_4_get (void) { GRAPH_T* g; g = graph_new (GRAPH_DIRECTED_T, GRAPH_INT_T); /* insert edge start */ fprintf (stderr, "* inserting e1(1,2)\n"); graph_add_i (g, "e1", 1, NULL, 2, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e2(2,3)\n"); graph_add_i (g, "e2", 2, NULL, 3, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e3(3,4)\n"); graph_add_i (g, "e3", 3, NULL, 4, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e4(4,5)\n"); graph_add_i (g, "e4", 4, NULL, 5, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e5(5,1)\n"); graph_add_i (g, "e5", 5, NULL, 1, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e6(3,5)\n"); graph_add_i (g, "e6", 3, NULL, 5, NULL, 2, DS_TRUE); fprintf (stderr, "* inserting e7(3,1)\n"); graph_add_i (g, "e7", 3, NULL, 1, NULL, 1, DS_TRUE); /* insert edge end */ return g; }
int main(int argc, char ** argv) { if(argc == 2){ Graph * g = graph_new(4, 4, 0); Path * d; Mst * m; int i, src; if(graph_file_insert(g, argv[1])){ printf("Graph loaded from file\n"); m = graph_mst_kruskal(g); printf("\nMST calulated using Kruskal's algorithm: \n"); for(i =0; i < m->e; i++) printf("%d --%d-- %d\n", m->edge[i].src, m->edge[i].weight, m->edge[i].dest); printf("\n"); src = 2; d = graph_dijkstra(g, src); printf("\nShortest distance from: %d to\n", src); for(i =0; i < (g->V); i++) if(d->distance[i] != INT_MAX && d->distance[i] != INT_MIN) printf("%d: %d\n", i, d->distance[i]); } else printf("Specified parameters of graph do not match that from given file\n"); } else printf("Usage : ./example <filename.txt>\n"); return 0; }
graph_t* MatrixToGraph(double *adjac_mtx_ptr, int iGraphOrder) { int i, j, idx; graph_t *ptrGraph; /* Initialize the graph that we want to return. */ ptrGraph = graph_new(iGraphOrder); /* Loop through the adjacency matrix to create the graph. We assume * that the adjacency matrix is symmetric and only consider the super- * diagonals of the matrix. */ /* The indexing here seems flipped, but it's due to the translation * between MATLAB and C element ordering. */ for (j = 0; j < iGraphOrder; j++) for (i = j + 1; i < iGraphOrder; i++) { /* The matrix adj_mtx is stored as a 1-dimensional array, so * we must convert the coordinate (i, j) to the corresponding * 1-dimensional index. */ idx = j + i * iGraphOrder; /* If the entry of the adjacency matrix is a 1, we want to add * an edge to our graph. */ if(adjac_mtx_ptr[idx] == 1) GRAPH_ADD_EDGE(ptrGraph, i, j); } /* Just to be cautios, ensure that we've produced a valid graph. */ ASSERT(graph_test(ptrGraph, NULL)); return ptrGraph; }
graph_t *KCoreGraph::subgraph(IntStack *vset) { assert(!vset->empty()); graph_t *g = graph_new(maxsize()); IntStack *nb; int val,preval,val2,preval2; val = vset->head(); preval = val-1; while (val != preval) { nb = neighbourhoods.at(val); if (!nb->empty()) { val2 = nb->head(); preval2 = val2-1; while (val2 != preval2) { if ((val > val2) && vset->contain(val2)) GRAPH_ADD_EDGE(g,val,val2); preval2 = val2; val2 = nb->next(preval2); } } preval = val; val = vset->next(preval); } return g; };
/** * This routine creates an NxM graph and returns it to the user. * * @param [in] N the number of rows in the matrix * @param [in] M the numner of columns in the matrix * @return A valid GRAPH_T* if successful, NULL otherwise */ GRAPH_T* matrix_create ( const unsigned long N, const unsigned long M ) { unsigned long vid; //unsigned long tmp; #define label "edge" GRAPH_T* matrix; if (NULL == (matrix = graph_new (GRAPH_UNDIRECTED_T, GRAPH_INT_T))) return NULL; for (vid = 1; vid <= N*M; vid++) /**< generate integer vertex indices */ { /**< creating the left-right edges */ if (vid%M != 1) graph_add_i (matrix, label, vid, NULL, vid-1, NULL, 1, DS_TRUE); /**< creating the right edge */ //if (vid%M != 0) // graph_add_i (matrix, label, vid, NULL, vid+1, NULL, 1, DS_TRUE); /**< creating the up edge */ //if (vid > M) // graph_add_i (matrix, label, vid, NULL, vid-M, NULL, 1, DS_TRUE); /**< creating the up-down edge */ if (vid <= (M*(N-1))) graph_add_i (matrix, label, vid, NULL, vid+M, NULL, 1, DS_TRUE); } return matrix; }
/** * @brief Testing construction of a directed graph. * * 1-->2 ->3-->>4 * | | / | / | * | |/ |/ | * v v v v * 5 6--->7--->8 * | * | * V * 9 */ void tc_directed_main (void) { GRAPH_T* g; void* vtx; EDGE_T* e; char* ctx = NULL; unsigned long no = 0; fprintf (stderr, "graph test #1\n"); g = graph_new (GRAPH_DIRECTED_T, GRAPH_INT_T); fprintf (stderr, "* inserting e1(1,2)\n"); graph_add_i (g, "e1", 1, NULL, 2, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e2(1,5)\n"); graph_add_i (g, "e2", 1, NULL, 5, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e3(2,6)\n"); graph_add_i (g, "e3", 2, NULL, 6, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e4(6,7)\n"); graph_add_i (g, "e4", 6, NULL, 7, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e5(3,7)\n"); graph_add_i (g, "e5", 3, NULL, 7, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e6(3,4)\n"); graph_add_i (g, "e6", 3, NULL, 4, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e7(7,8)\n"); graph_add_i (g, "e7", 7, NULL, 8, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e8(4,8)\n"); graph_add_i (g, "e8", 4, NULL, 8, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e9(6,3)\n"); graph_add_i (g, "e9", 6, NULL, 3, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e10(7,4)\n"); graph_add_i (g, "e10", 7, NULL, 4, NULL, 1, DS_TRUE); if (GPH_ERR_EDGE_EXISTS == graph_add_i (g, "e11", 4, NULL, 7, NULL, 1, DS_TRUE)) fprintf (stderr, "edge exists\n"); fprintf (stderr, "* inserting e10(7,4)\n"); graph_add_i (g, "e12", 6, NULL, 9, NULL, 1, DS_TRUE); fprintf (stderr, "Done inserting edges\n"); tc_graph_edge_print (g); tc_graph_vertex_print (g); vertex_print_3 (g); //return (0); printf ("DDDD\n"); vtx = graph_vertex_find_i (g, 6); printf ("DDDD = %lu\n", ((VTX_D_T*)vtx)->no); while (no < ((VTX_D_T*)vtx)->no) { e = graph_vertex_next_edge_get (g, vtx, &ctx); DEBUG_EDGE_PRINT_I(g,e); no++; } fprintf (stderr, "Starting BFS\n"); bfs (g, 6, bfs_directed_func); fprintf (stderr, "Starting DFS\n"); dfs (g, 2, bfs_directed_func); }
int cook_web(string_list_ty *wlp) { int retval; graph_ty *gp; graph_build_status_ty gb_status; /* * set interrupts to catch * * Note that tee(1) [see listing.c] must ignore them * for the generated messages to appear in the log file. */ trace(("cook(wlp = %08lX)\n{\n", wlp)); desist_enable(); /* * Build the dependency graph. */ retval = 0; gp = graph_new(); gb_status = graph_build_list(gp, wlp, graph_build_preference_error, 0); if (option_test(OPTION_REASON)) graph_print_statistics(gp); switch (gb_status) { case graph_build_status_error: retval = 1; break; case graph_build_status_backtrack: /* assert(0); */ retval = 1; break; case graph_build_status_success: break; } /* * Walk the dependency graph. */ if (retval == 0) graph_walk_web(gp); /* * Release any resources held by the graph. */ graph_delete(gp); /* * Return the result to the caller. */ trace(("return %d;\n", retval)); trace(("}\n")); return retval; }
int main(int argc,char *argv[]) { int num_houses,num_schools; int u,v,weight; if(scanf("%d %d",&num_houses,&num_schools) != 2) { printError(); } Graph *g = graph_new(num_houses+num_schools); g->num_houses = num_houses; g->num_schools = num_schools; g->number_of_vertices = num_houses+num_schools; while(scanf("%d %d %d",&u,&v,&weight) == 3) { if(u < 0 || v < 0 || u>=(g->number_of_vertices) || v>=(g->number_of_vertices) || weight < 0){ printError(); } else { // the 0 represents unvisted graph_add_edge(g,u,v,0); graph_add_edge(g,v,u,0); //adding weights g->vertices[u].edges[g->vertices[u].num_edges-1].weight = weight; g->vertices[v].edges[g->vertices[v].num_edges-1].weight = weight; } } // checking if graph is connected if(!graph_check_connected(g,0)) { fprintf(stderr, "Graph is not connected\n"); exit(EXIT_FAILURE); } Universe *Uni = create_all_sets(g->num_schools,g->num_houses); //running Dijkstra on each school vertex for(int i=num_houses;i<g->number_of_vertices;i++) { Dijkstra(g,i,Uni,min_func); } setCover(Uni,g->num_houses); free_graph(g); return 0; }
static void draw_chart (CutPDFReport *report, CutRunContext *run_context) { GogGraph *graph; graph = graph_new("Test result report", run_context); cairo_translate(report->context, 100, 50); gog_graph_render_to_cairo(graph, report->context, 400, 300); g_object_unref(graph); }
graph_t *mkGraphABCDE() { graph_t *g = graph_new(streq); graph_add_node(g, strdup("A")); graph_add_node(g, strdup("B")); graph_add_node(g, strdup("C")); graph_add_node(g, strdup("D")); graph_add_node(g, strdup("E")); return g; }
int main(int argc, char** argv) { int ncpu = (int)sysconf(_SC_NPROCESSORS_ONLN); #ifdef DEBUG printf ("Configured for %d CPU\n",ncpu); #endif Graph *graph = graph_new (1024); if (argc > 0){ read_case_file (graph, argv [1]); } int num_threads = ncpu + 1; nodes = graph_get_nodes (graph); num_nodes = graph_get_num_nodes (graph); int i; for (i = 0;i<num_nodes;i++){ qsort (&nodes[i]->edges[0], nodes[i]->num_edges, sizeof (GraphEdge*), cmp_edges_by_weight); } int elem_per_thread = (num_nodes / num_threads) + 1; int **arr = malloc (sizeof (int*) * num_threads); for (i = 0; i < num_threads; i++){ arr[i] = malloc (sizeof (int) * (elem_per_thread + 2)); arr[i][0] = i; arr[i][1] = 0; } for (i = 0; i < num_nodes; i++){ int y = i % num_threads; int x = arr[y][1] + 2; arr[y][x] = i; arr[y][1] = arr[y][1] + 1; } pthread_t tids[num_threads]; for (i = 0; i < num_threads;i++){ pthread_create (&tids[i], NULL, &pthread_main, arr[i]); } for (i = 0; i < num_threads; i++){ pthread_join (tids[i], NULL); } if (best_found_path) print_solution (best_found_path); return 0; }
void bfs_main (void) { GRAPH_T* g; void* vtx; EDGE_T* e; char* ctx = NULL; unsigned long no = 0; fprintf (stderr, "[START] breadth-first search test \n"); g = graph_new (GRAPH_UNDIRECTED_T, GRAPH_INT_T); fprintf (stderr, "* inserting e1(1,2)\n"); graph_add_i (g, "e1", 1, NULL, 2, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e2(1,5)\n"); graph_add_i (g, "e2", 1, NULL, 5, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e3(2,6)\n"); graph_add_i (g, "e3", 2, NULL, 6, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e4(6,7)\n"); graph_add_i (g, "e4", 6, NULL, 7, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e5(3,7)\n"); graph_add_i (g, "e5", 3, NULL, 7, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e6(3,4)\n"); graph_add_i (g, "e6", 3, NULL, 4, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e7(7,8)\n"); graph_add_i (g, "e7", 7, NULL, 8, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e8(4,8)\n"); graph_add_i (g, "e8", 4, NULL, 8, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e9(6,3)\n"); graph_add_i (g, "e9", 6, NULL, 3, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e10(7,4)\n"); graph_add_i (g, "e10", 7, NULL, 4, NULL, 1, DS_TRUE); if (GPH_ERR_EDGE_EXISTS == graph_add_i (g, "e10", 4, NULL, 7, NULL, 1, DS_TRUE)) fprintf (stderr, "edge exists\n"); fprintf (stderr, "Done inserting edges\n"); //graph_edge_print (g); //graph_vertex_print (g); vertex_print_2 (g); vtx = graph_vertex_find_i (g, 7); while (no < ((VTX_UD_T*)vtx)->no) { e = graph_vertex_next_edge_get (g, vtx, &ctx); DEBUG_EDGE_PRINT_I(g,e); no++; } fprintf (stderr, "Starting BFS\n"); bfs (g, 2, bfs_vertex_func); fprintf (stderr, "Starting DFS\n"); dfs (g, 2, bfs_vertex_func); fprintf (stderr, "[END] breadth-first search test \n"); }
int main(void) { int d = 0; int i = 0; int x = 0; graph my_graph = NULL; if (1 == scanf("%d", &d)) { my_graph = graph_new(d); } while (2 == scanf("%d%d", &i, &x)) { graph_add_edge(my_graph, i, x); } /* graph my_graph = graph_new(8); graph_bi_add_edge(my_graph, 0, 1); graph_bi_add_edge(my_graph, 0, 4); graph_bi_add_edge(my_graph, 1, 0); graph_bi_add_edge(my_graph, 1, 5); graph_bi_add_edge(my_graph, 2, 3); graph_bi_add_edge(my_graph, 2, 5); graph_bi_add_edge(my_graph, 2, 6); graph_bi_add_edge(my_graph, 3, 2); graph_bi_add_edge(my_graph, 3, 6); graph_bi_add_edge(my_graph, 3, 7); graph_bi_add_edge(my_graph, 4, 0); graph_bi_add_edge(my_graph, 5, 1); graph_bi_add_edge(my_graph, 5, 2); graph_bi_add_edge(my_graph, 5, 6); graph_bi_add_edge(my_graph, 6, 2); graph_bi_add_edge(my_graph, 6, 3); graph_bi_add_edge(my_graph, 6, 5); graph_bi_add_edge(my_graph, 6, 7); graph_bi_add_edge(my_graph, 7, 3); graph_bi_add_edge(my_graph, 7, 6); */ graph_dfs(my_graph); graph_print(my_graph); graph_free(my_graph); return EXIT_SUCCESS; }
/** * @brief construct test graph #2 * */ static GRAPH_T* graph_2_get (void) { GRAPH_T* g; g = graph_new (GRAPH_DIRECTED_T, GRAPH_INT_T); fprintf (stderr, "* inserting e1(1,2)\n"); graph_add_i (g, "e1", 1, NULL, 2, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e2(1,3)\n"); graph_add_i (g, "e2", 1, NULL, 3, NULL, 3, DS_TRUE); fprintf (stderr, "* inserting e3(1,11)\n"); graph_add_i (g, "e3", 1, NULL, 11, NULL, 1, DS_TRUE); //fprintf (stderr, "* inserting e4(2,4)\n"); //graph_add_i (g, "e4", 2, NULL, 4, NULL, 10, DS_TRUE); fprintf (stderr, "* inserting e5(2,7)\n"); graph_add_i (g, "e5", 2, NULL, 7, NULL, 2, DS_TRUE); fprintf (stderr, "* inserting e6(3,5)\n"); graph_add_i (g, "e6", 3, NULL, 5, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e7(3,4)\n"); graph_add_i (g, "e7", 3, NULL, 4, NULL, 4, DS_TRUE); //fprintf (stderr, "* inserting e8(4,3)\n"); //graph_add_i (g, "e8", 4, NULL, 3, NULL, 4, DS_TRUE); fprintf (stderr, "* inserting e9(4,8)\n"); graph_add_i (g, "e9", 4, NULL, 8, NULL, 2, DS_TRUE); fprintf (stderr, "* inserting e10(4,9)\n"); graph_add_i (g, "e10", 4, NULL, 9, NULL, 6, DS_TRUE); fprintf (stderr, "* inserting e11(5,6)\n"); graph_add_i (g, "e11", 5, NULL, 6, NULL, 2, DS_TRUE); fprintf (stderr, "* inserting e12(6,4)\n"); graph_add_i (g, "e12", 6, NULL, 4, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e13(6,9)\n"); graph_add_i (g, "e13", 6, NULL, 9, NULL, 5, DS_TRUE); fprintf (stderr, "* inserting e14(7,3)\n"); graph_add_i (g, "e14", 7, NULL, 3, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e15(7,10)\n"); graph_add_i (g, "e15", 7, NULL, 10, NULL, 1, DS_TRUE); fprintf (stderr, "* inserting e16(8,9)\n"); graph_add_i (g, "e16", 8, NULL, 9, NULL, 2, DS_TRUE); fprintf (stderr, "* inserting e17(10,4)\n"); graph_add_i (g, "e17", 10, NULL, 4, NULL, 2, DS_TRUE); fprintf (stderr, "* inserting e18(10,8)\n"); graph_add_i (g, "e18", 10, NULL, 8, NULL, 2, DS_TRUE); fprintf (stderr, "* inserting e19(11,5)\n"); graph_add_i (g, "e19", 11, NULL, 5, NULL, 1, DS_TRUE); return g; }
int main(int argc, char *argv[]) { struct graph *g = graph_new(); if (g) { graph_join(g, 12, 34); graph_join(g, 34, 12); graph_join(g, 11, 9); graph_join(g, 9, 100); graph_join(g, 25, 89); graph_join(g, 100, 100); graph_dump(g); graph_destroy(g); } return 0; }
Quark *graph_next(Quark *project) { Quark *f, *g; if (!project) { return NULL; } f = frame_new(project); g = graph_new(f); if (g && number_of_graphs(project) == 1) { Project *pr = project_get_data(project); pr->cg = g; } return g; }
// ----------------------------------------------------------------------------- PyObject* graph_create_spanning_tree(PyObject* self, PyObject* pyobject) { INIT_SELF_GRAPH(); Graph* g; if(is_NodeObject(pyobject)) g = so->_graph->create_spanning_tree(((NodeObject*)pyobject)->_node); else { GraphDataPyObject a(pyobject); g = so->_graph->create_spanning_tree(&a); } if(g == NULL) { PyErr_SetString(PyExc_TypeError, "Graph Type does not match"); return NULL; } return (PyObject*)graph_new(g); }
END_TEST int main() { g = graph_new(); mu_run_test(test_add_nodes); mu_run_test(test_edge); graph_toNeato(g, "graph.dot"); printf("Fichier .dot en sortie : graph.dot\n"); graph_free(g); mu_summary(); return __tests_failed; }
int main(int argc, char **argv) { GRAPH *g = graph_new(NODES_MAX); int i; names = calloc(NODES_MAX, sizeof(char **)); srand(time(NULL)); for (i = 0; i < NODES_MAX; i++) graph_add_node(g); for (i = 0; i < NODES_MAX; i++) { graph_add_link(g, i, i / 4, 1, 1); } fprintf(stderr, "Found %i nodes\n", determine_links(g, 0)); return 0; }
int main(void) { float data[POINTS]; int i; for (i = 0; i < POINTS; ++i) { //Generate a lognormal random variate with underlying normal parameters as //mean = 0 and standard deviation = 1 data[i] = lognormal(1.0, 0.5); } graph_init(); graph_new(HIST, data, POINTS, "xlabel=value,ylabel=prbability,title=Lognormal Distribution"); graph_show(); }
/* Convert an igraph graph to a Cliquer graph */ static void igraph_to_cliquer(const igraph_t *ig, graph_t **cg) { igraph_integer_t vcount, ecount; int i; if (igraph_is_directed(ig)) IGRAPH_WARNING("Edge directions are ignored for clique calculations"); vcount = igraph_vcount(ig); ecount = igraph_ecount(ig); *cg = graph_new(vcount); for (i=0; i < ecount; ++i) { long s, t; s = IGRAPH_FROM(ig, i); t = IGRAPH_TO(ig, i); if (s != t) GRAPH_ADD_EDGE(*cg, s, t); } }
static g_graph mv_cnf_to_graph(mv_cnf input) { register unsigned int ix, iy, iz = 0; g_graph result = graph_new(); for (ix = 0; ix < input->clauses->sz; ix++) { graph_node_add(result, graph_node_new(ix)); } for (ix = 0; ix < input->clauses->sz; ix++) { for (iy = ix + 1; iy < input->clauses->sz; iy++) { if (mv_clause_shares_variables(input->clauses->arr[ix], input->clauses->arr[iy]) > 0) { graph_edge_add(result, graph_edge_new(iz++, ix, iy)); } } } return result; }
int main(int argc, char *argv[]) { int v1; int v2; graph g; char option; int size = 0; graph_t type = DIRECTED; const char *optstring = "s:"; while((option = getopt(argc, argv, optstring)) != EOF) { switch(option) { case 's': size = atoi(optarg); break; default: printf("input the number of vertices\n"); return EXIT_FAILURE; } } g = graph_new(size); while(2==scanf("%d%d", &v1, &v2)) { g = graph_add_edge(g, v1, v2, type); } /** g = graph_add_edge(g, 0, 1, type); g = graph_add_edge(g, 0, 4, type); g = graph_add_edge(g, 5, 1, type); g = graph_add_edge(g, 5, 2, type); g = graph_add_edge(g, 5, 6, type); g = graph_add_edge(g, 6, 2, type); g = graph_add_edge(g, 6, 3, type); g = graph_add_edge(g, 6, 7, type); g = graph_add_edge(g, 3, 2, type); g = graph_add_edge(g, 3, 7, type); */ graph_print(g); graph_dfs(g); g = graph_free(g); return EXIT_SUCCESS; }
int main() { int t; int s; for(s=0;s<10;s++) { int width = (lrand48()%8)+1; graph_t*g = graph_new(width*width); for(t=0;t<width*width;t++) { int x = t%width; int y = t/width; int w = 1; #define R (lrand48()%32) if(x>0) graph_add_edge(&g->nodes[t], &g->nodes[t-1], R, R); if(x<width-1) graph_add_edge(&g->nodes[t], &g->nodes[t+1], R, R); if(y>0) graph_add_edge(&g->nodes[t], &g->nodes[t-width], R, R); if(y<width-1) graph_add_edge(&g->nodes[t], &g->nodes[t+width], R, R); } int x = graph_maxflow(g, &g->nodes[0], &g->nodes[width*width-1]); printf("max flow: %d\n", x); graph_delete(g); } }