void graph_get_rec_rgg(graph *g, int vertices, double width, double r, double *x, double *y, well1024 *rng) { graph_init(g, vertices); const double length = 1.0 / width; // A = l * w so l = 1 / w for (int i = 0; i < vertices; ++i) { x[i] = well1024_next_double(rng) * length; y[i] = well1024_next_double(rng) * width; } double d; for (int i = 0; i < vertices; ++i) { for (int j = 0; j < vertices; ++j) { const double a = x[i] - x[j]; const double b = y[i] - y[j]; d = hypot(a, b); if (d < r) { graph_add_edge(g, i, j, r - d); } } } }
void set_costs(t_anthill *anthill) { int i; t_room *target; target = anthill->target; target->gcost = 0; target->visited = 1; set_ncosts(target); while (!check_costs(anthill) && target) { i = 0; if (!target->neighbours[i]) target = target->next; while (target && target->neighbours[i]) { if (target->neighbours[i]->visited == 0) set_ncosts(target->neighbours[i]); ++i; } if (target && target->neighbours[0]) target = find_next_target(target); } anthill->rooms = graph_init(anthill->rooms); }
static void init(void) { /* Initialize debugging module (allow kprintf(), etc.) */ // kdbg_init(); /* Initialize system timer */ timer_init(); /* * XXX: Arduino has a single UART port that was previously * initialized for debugging purpose. * In order to activate the serial driver you should disable * the debugging module. */ /* Initialize UART0 */ ser_init(&serial, SER_UART0); /* Configure UART0 to work at 115.200 bps */ ser_setbaudrate(&serial, 115200); /* Enable all the interrupts now the basic stuff is initialised */ IRQ_ENABLE; // set clock up using last values from eeprom rtc_init(); // read a few more values out of eeprom and init the display etc load_eeprom_values(); ui_init(); measure_init(); control_init(); rpm_init(); graph_init(); log_init(); }
/* * main() * funcao principal */ int main() { int i, vertices, edges, n, id=0; vertex v, w, art[MAXV]; Graph g; while(scanf("%d %d", &vertices, &edges)>0 && vertices>0) { /* input */ g = graph_init(vertices); while(edges--) { scanf("%d %d", &v, &w); graph_newedge(g, v-1, w-1); } /* processamento */ graph_findarts(g, art, &n); adjust(art, &n); /* output */ printf("Teste %d\n", ++id); if(n>0) { for(i=0; i<n; i++) printf("%d ", art[i]+1); printf("\n\n"); } else printf("nenhum\n\n"); graph_release(g); } return 0; }
int main(int argc, char **args) { s_graph graph; graph_init(&graph, 6); for (int i = 0; i < 6; i++) { graph_set_vertex(&graph, i, i); } graph_set_arccell(&graph, 0, 2, 10); graph_set_arccell(&graph, 0, 4, 30); graph_set_arccell(&graph, 0, 5, 100); graph_set_arccell(&graph, 1, 2, 5); graph_set_arccell(&graph, 2, 3, 50); graph_set_arccell(&graph, 3, 5, 10); graph_set_arccell(&graph, 4, 3, 20); graph_set_arccell(&graph, 4, 5, 60); graph_display(&graph); graph_shortest_path(&graph); graph_destroy(&graph); return 0; }
int main(int argc, char **args) { s_graph graph; graph_init(&graph, 5); for (int i = 0; i < 5; i++) { graph_set_vertex(&graph, i, i); } graph_set_arccell(&graph, 0, 1, 15); graph_set_arccell(&graph, 1, 4, 71); graph_set_arccell(&graph, 1, 3, 23); graph_set_arccell(&graph, 3, 4, 42); graph_set_arccell(&graph, 2, 4, 36); graph_set_arccell(&graph, 2, 0, 27); graph_set_arccell(&graph, 3, 3, 61); graph_set_arccell(&graph, 2, 1, 92); graph_display(&graph); graph_destroy(&graph); return 0; }
/** Calculates the shortest path from one version to another. * The shortest path is defined as the path with the smallest combined * size, not the length of the path. * @param handle the context handle * @param deltas the list of alpm_delta_t * objects that a file has * @param to the file to start the search at * @param path the pointer to a list location where alpm_delta_t * objects that * have the smallest size are placed. NULL is set if there is no path * possible with the files available. * @return the size of the path stored, or LONG_MAX if path is unfindable */ off_t _alpm_shortest_delta_path(alpm_handle_t *handle, alpm_list_t *deltas, const char *to, alpm_list_t **path) { alpm_list_t *bestpath = NULL; alpm_list_t *vertices; off_t bestsize = LONG_MAX; if(deltas == NULL) { *path = NULL; return bestsize; } _alpm_log(handle, ALPM_LOG_DEBUG, "started delta shortest-path search for '%s'\n", to); vertices = graph_init(deltas, 0); graph_init_size(handle, vertices); dijkstra(vertices); bestsize = shortest_path(vertices, to, &bestpath); _alpm_log(handle, ALPM_LOG_DEBUG, "delta shortest-path search complete : '%jd'\n", (intmax_t)bestsize); alpm_list_free_inner(vertices, _alpm_graph_free); alpm_list_free(vertices); *path = bestpath; return bestsize; }
void graph_get_llrgg(graph *g, int vertices, double r, double *x, double *y, well1024 *rng) { graph_init(g, vertices); for (int i = 0; i < vertices; ++i) { x[i] = well1024_next_double(rng); y[i] = well1024_next_double(rng); } double d; for (int i = 0; i < vertices; ++i) { for (int j = 0; j < vertices; ++j) { if (i != j) { const double a = x[i] - x[j]; const double b = y[i] - y[j]; d = hypot(a, b); if (d < r) { graph_add_edge(g, i, j, r - d); } } } } }
void init(void) { mapy_init(); ddl_init(); vga_font = LoadResourceFont("BOLDCZ"); default_font = vga_font; icones = LoadResourceFont("IKONY"); graph_init(1); curcolor = RGB555(24,24,24);memcpy(charcolors,flat_color(0x0000),sizeof(charcolors)); init_events(100); curfont = default_font; register_ms_cursor(LoadResourceFont("SIPKA.HI")); init_mysky(); // hranice_mysky(0,0,639,479); add_task(1024,key_test); send_message(E_ADD,E_STATUS_LINE,status_line); send_message(E_STATUS_LINE,E_ADD,E_IDLE,all_status); send_message(E_STATUS_LINE,E_ADD,E_IDLE,status_mem_info); send_message(E_STATUS_LINE,E_ADD,E_IDLE,show_time); send_message(E_ADD,E_TIMER,pc_metter); send_message(E_ADD,E_KEYBOARD,exit_key); send_message(E_ADD,E_PRGERROR,prg_error); signal(SIGILL,raise_error_conv); signal(SIGSEGV,raise_error_conv); install_gui(); redraw_desktop();do_events(); send_message(E_ADD,E_MOUSE,main_menu); msg_box_font = vga_font; msg_icn_font = icones; ukaz_mysku(); update_mysky(); }
static alpm_list_t *find_unused(alpm_list_t *deltas, const char *to, off_t quota) { alpm_list_t *unused = NULL; alpm_list_t *vertices; alpm_list_t *i; vertices = graph_init(deltas, 1); for(i = vertices; i; i = i->next) { alpm_graph_t *v = i->data; alpm_delta_t *vdelta = v->data; if(strcmp(vdelta->to, to) == 0) { v->weight = vdelta->download_size; } } dijkstra(vertices); for(i = vertices; i; i = i->next) { alpm_graph_t *v = i->data; alpm_delta_t *vdelta = v->data; if(v->weight > quota) { unused = alpm_list_add(unused, vdelta->delta); } } alpm_list_free_inner(vertices, _alpm_graph_free); alpm_list_free(vertices); return unused; }
void setup_algorithms(graph_t *g) { static void *vdata[10]; graph_init(g, 10, vdata, !GRAPH_DIRECTED); graph_add_update_edge(g, 0, 3, (void *)1); graph_add_update_edge(g, 0, 9, (void *)2); graph_add_update_edge(g, 1, 2, (void *)3); graph_add_update_edge(g, 1, 3, (void *)4); graph_add_update_edge(g, 2, 8, (void *)5); graph_add_update_edge(g, 2, 9, (void *)6); graph_add_update_edge(g, 3, 4, (void *)7); graph_add_update_edge(g, 3, 6, (void *)8); graph_add_update_edge(g, 3, 9, (void *)9); graph_add_update_edge(g, 4, 5, (void *)10); graph_add_update_edge(g, 5, 6, (void *)11); graph_add_update_edge(g, 5, 7, (void *)12); graph_add_update_edge(g, 7, 8, (void *)13); graph_add_update_edge(g, 8, 9, (void *)14); ck_assert_int_eq(g->edges_number, 14); }
/*! * general init function * \version 1.0 * \date Sept 2007 * \author Elie */ void init() { unsigned int i; option.default_set_value = SET_COST; option.default_node_value = HOST_COST; option.start_time = time(NULL); //rand i = time(NULL); srand(i); //init tree; root = NULL; tree = NULL; last_branch = NULL; tree_init(); //stat initi bzero(&stat, sizeof(t_stat)); //init strategy strategy = NULL; //init formula formula = NULL; //player init admin = malloc(sizeof(t_player)); bzero(admin, sizeof(t_player)); admin->name = ADMIN_NAME; admin->target = -1; admin->target_succ = UNSET; admin->rule_status = UNSET; incident = malloc(sizeof(t_player)); bzero(incident, sizeof(t_player)); incident->name = INCIDENT_NAME; incident->target = -1; incident->target_succ = UNSET; incident->rule_status = UNSET; //init graph graph_init(); //init penality penality = NULL; //parse game file parse(option.filename); //preprocessing game to statically optimize it preprocessor(); }
//! int main(int argc, char *argv[]) { if (argc != 5) { fprintf(stderr, "Usage: gep_test <config_file> <input_samples_file> <output_samples_file> <enable_graphics>\n"); exit(0); } gep_short_params_t *short_params = createDefaultParams(); const char *arg_config_filename = argv[1]; const char *arg_input_samples_filename = argv[2]; const char *arg_output_samples_filename = argv[3]; const char *arg_enable_graphics_str = argv[4]; readConfigFile(arg_config_filename, short_params); strncpy(short_params->input_samples_filename, arg_input_samples_filename, sizeof(short_params->input_samples_filename)); strncpy(short_params->output_samples_filename, arg_output_samples_filename, sizeof(short_params->output_samples_filename)); sscanf(arg_enable_graphics_str, "%d", &graph_enabled); gep_ctx = GEP_CreateContext(short_params, &stat_params); if (signal(SIGUSR1, gep_sigterm_handler) == SIG_ERR) { fprintf(stderr, "Can't setup SIGUSR1 hanlder\n"); } last_frame_rendered = simulation_started = last_output_printed = getTimeNs(); if (graph_enabled) { graph_init(argc, argv); pthread_t gep_thread; int status = pthread_create(&gep_thread, NULL, gep_run_routine, NULL); if (0 != status) { fprintf(stderr, "Can't create GEP thread!\n"); exit(-1); } glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS); glutMainLoop(); pthread_join(gep_thread, NULL); } else { GEP_Run(gep_ctx, stat_callback); } GEP_DestroyContext(gep_ctx); free(short_params); return 0; }
int main () { int i, data; int v_id[V_COUNT]; DfsVertex *dfs_vs[V_COUNT]; Graph graph; DfsVertex *dfs_vertex; List ordered; ListElmt *element; graph_init (&graph, &match, NULL); for (i = 0; i < V_COUNT; i++) { v_id[i] = i; if ((dfs_vertex = (DfsVertex *) malloc (sizeof(DfsVertex))) == NULL) return -1; dfs_vertex->data = &v_id[i]; dfs_vertex->color = white; dfs_vs[i] = dfs_vertex; graph_ins_vertex (&graph, (void *) dfs_vertex); /* printf ("vertex[%d] addr=%d\n", i, (void *) &vertex[i]); */ } printf ("graph vcount=%d\n", graph_vcount (&graph)); /* Graph as in figure 11.8 Network hops. */ /* graph_ins_edge (&graph, (void *) dfs_vs[0], (void *) dfs_vs[1]); */ graph_ins_edge (&graph, (void *) dfs_vs[0], (void *) dfs_vs[2]); graph_ins_edge (&graph, (void *) dfs_vs[2], (void *) dfs_vs[1]); graph_ins_edge (&graph, (void *) dfs_vs[1], (void *) dfs_vs[3]); /* graph_ins_edge (&graph, (void *) dfs_vs[2], (void *) dfs_vs[4]); */ graph_ins_edge (&graph, (void *) dfs_vs[3], (void *) dfs_vs[4]); graph_ins_edge (&graph, (void *) dfs_vs[4], (void *) dfs_vs[5]); graph_ins_edge (&graph, (void *) dfs_vs[1], (void *) dfs_vs[6]); printf ("graph ecount=%d\n", graph_ecount (&graph)); dfs (&graph, &ordered); printf ("size of ordered list=%d\n", list_size (&ordered)); for (element = list_head (&ordered); element != NULL; element = list_next (element)) { dfs_vertex = (list_data (element)); printf ("vertex id=%d,\tcolour=%d\n", *(int *) dfs_vertex->data, (int) dfs_vertex->color); } list_destroy (&ordered); graph_destroy (&graph); return 0; }
int main(){ /*初始化*/ Graph *graph = graph_init(); /*struct Path *add_edge(struct Graph *graph, int from, int to, int dut); *from&to:一条边的两个顶点。from为起点,to为终点。from和to可为任意整数. *dut:边的权值,不可大于INF即16777216。 */ add_edge(graph, 1, 2, 7); add_edge(graph, 2, 1, 7); add_edge(graph, 1, 3, 9); add_edge(graph, 3, 1, 9); add_edge(graph, 1, 6, 14); add_edge(graph, 6, 1, 14); add_edge(graph, 2, 3, 10); add_edge(graph, 3, 2, 10); add_edge(graph, 3, 6, 2); add_edge(graph, 6, 3, 2); add_edge(graph, 3, 4, 11); add_edge(graph, 4, 3, 11); add_edge(graph, 5, 6, 9); add_edge(graph, 6, 5, 9); add_edge(graph, 4, 5, 6); add_edge(graph, 5, 4, 6); add_edge(graph, 4, 7, 8); add_edge(graph, 7, 4, 8); add_edge(graph, 6, 7, 4); add_edge(graph, 7, 6, 4); add_edge(graph, 5, 7, 2); add_edge(graph, 7, 5, 2); /* *road_min(struct Graph *grap, int from, int to); *返回from--->to之间的最短路径————一个单向链表。 */ int from = 1; int to = 5; Path *path = road_min(graph, from, to); Path *tmp; while(path){ tmp = path->next; if(tmp) printf("%d->", path->node->id); else printf("%d->", path->node->id); path = tmp; } printf("%d\n", to); /*销毁*/ graph_destroy(graph); return 0; }
graph_p graph_random(uint32_t v, uint32_t e) { graph_p g = graph_init(v); return g; for (uint32_t i = 0; i < e; i++) { edge_t e; e.v = rand() % v; e.w = rand() % v; graph_insert_edge(g, e); } }
void spawn_editor(char *dosline) { // deinstall_mouse_handler(); closemode(); system(dosline); graph_init(1); // install_mouse_handler(); // hranice_mysky(0,0,639,479); redraw_desktop(); }
void graph_get_star(graph *g, int vertices) { graph_init(g, vertices); for (int u = 0; u < vertices; ++u) { graph_add_edge(g, u, u, 1.0); graph_add_sym_edges(g, u, 0, 1.0); } }
graph_p graph_copy(graph_p g) { graph_p ng = NULL; ng = graph_init(g->v); ng->e = g->e; for (uint32_t i = 0; i < g->v; i++) { for (uint32_t j = 0; j < g->v; j++) { ng->adj[i][j] = g->adj[i][j]; } } return ng; }
void graph_get_rec_crgg(graph *g, int vertices, double width, double r, double *x, double *y, well1024 *rng) { graph_init(g, vertices); graph_get_rec_rgg(g, vertices, width, r, x, y, rng); while (graph_strongly_connected(g) == FALSE) { graph_free(g); graph_get_rec_rgg(g, vertices, width, r, x, y, rng); } }
void graph_get_complete(graph *g, int vertices) { graph_init(g, vertices); for (int i = 0; i < vertices; ++i) { for (int j = 0; j < vertices; ++j) { graph_add_edge(g, i, j, 1.0); } } }
int main(int argc, char **argv){ // user didn't specify the input file name containing the graph structure if(argc != 2){ printf("Usage: ./main <file_name>..\n"); return(1); } FILE *fpr = NULL; char line[LEN]; int i, j, node_value, edges, list_value, weight; int num_nodes = 8; graph *gr = NULL; // graph initialization gr = graph_init(num_nodes); if(gr == NULL){ return(1); } // open the file again fpr = open_file(argv[1], "r"); i = 0; while(fscanf(fpr, "%d %d", &node_value, &edges) != EOF){ gr->nodes[i]->value = node_value; // read all the node adjacent to the current one for(j = 0; j<edges; j++){ fscanf(fpr, "%d %d", &list_value, &weight); gr = graph_add_node(gr, i, list_value, weight); if(gr == NULL){ return(1); } } i++; } fclose(fpr); //print_graph(gr); //depth_first_search(gr, 0); //breadth_first_search(gr); dijkstra(gr, 0); for(j=0; j<gr->num_nodes; j++){ printf("Node: %d\tweight: %d\n", gr->nodes[j]->value, gr->nodes[j]->distance); } return (0); }
void graph_get_circle(graph *g, int vertices) { graph_init(g, vertices); graph_add_edge(g, vertices - 1, vertices - 1, 1.0); graph_add_sym_edges(g, 0, vertices - 1, 1.0); for (int u = 0; u < vertices - 1; ++u) { graph_add_edge(g, u, u, 1.0); graph_add_sym_edges(g, u, u + 1, 1.0); } }
void HyperReader_init(void) {CloseCur(); ClrScr(); puts("\nWelcome to the HyperReader 2000"); puts("========================================="); read_ini(); alloc_mem(); read_HZK(); graph_init(); image(); CloseCur(); read_file(); read_LabelFile(); }
int main (int argc, char **argv) { int next; // initialise program arguments { char *p = SERVER_NAME = argv[0]; while ((p = strchr(p, '/')) != NULL) SERVER_NAME = ++p; arg_c = argc; arg_v = argv; } set_server_type(); display_title(); usercheck(); malloc_init(); /* 一番最初に実行する必要がある */ db_init(); signals_init(); timer_init(); socket_init(); plugins_init(); do_init(argc,argv); graph_init(); plugin_event_trigger("Athena_Init"); while (runflag) { next = do_timer(gettick_nocache()); do_sendrecv(next); #ifndef TURBO do_parsepacket(); #endif } plugin_event_trigger("Athena_Final"); graph_final(); do_final(); timer_final(); plugins_final(); socket_final(); db_final(); malloc_final(); return 0; }
void process_input(graph_t *graph) { assert(graph != NULL); int node_count, i; node_t *node; scanf("%d", &node_count); graph_init(graph, node_count); for (i = 0; i < node_count; ++i) { node = &graph->nodes[i]; scanf("%d %lf %lf", &node->number, &node->pos_x, &node->pos_y); } }
/* init_graph: * Initialize attributes. We always do the minimum required by * libcommon. If fill is true, we use init_nop (neato -n) to * read in attributes relevant to the layout. */ static void init_graph(Agraph_t * g, boolean fill) { int d; graph_init(g, FALSE); d = late_int(g, agfindattr(g, "dim"), 2, 2); if (d != 2) { fprintf(stderr, "Error: graph %s has dim = %d (!= 2)\n", g->name, d); exit(1); } Ndim = GD_ndim(g) = 2; init_node_edge(g); if (fill && init_nop(g, 0)) { exit(1); } }
int main() { unsigned int iseed = (unsigned int)time(NULL); srand(iseed); graph g1; graph_init(&g1); graph_init_infectious(&g1); graph_init_ring(&g1, 1); graph_rewire(&g1, 0.05); //graph_print_adjacency(&g1); graph_destroy(&g1); return 0; }
int * determine_max_clique(Graph * graph, int vertex_num, tuple * deg_vert, int * lower_bound) { int i; pair result; int * members; for(i = 0; i < vertex_num; i++) { graph_init(graph, vertex_num); result = dsatur(graph, deg_vert, vertex_num, i); if (result.clique > *lower_bound) { *lower_bound = result.clique; members = result.members; continue; } free(result.members); } return members; }
int main(int argc, char **argv) { int width, height; double colour[3]; struct wav_file *wav; float samples[CHUNK_SIZE]; int sample_count; struct graph *gr; cairo_surface_t *surface; /* Validate and parse command-line arguments */ if(parse_arguments(argc, argv, &width, &height, colour) != 0) return 1; /* Open input file */ if( !(wav = wav_open(argv[1]))) { fprintf(stderr, "Unable to open input audio file %s\n", argv[1]); return 1; } /* Buffer all samples from input file. */ gr = graph_init(); while((sample_count = wav_read_samples(wav, samples, CHUNK_SIZE)) > 0) graph_buffer_samples(gr, samples, sample_count); /* Close input file */ wav_close(wav); /* Draw graph and output to PNG file using Cairo */ surface = graph_draw(gr, width, height, colour); if(cairo_surface_write_to_png(surface, argv[2]) != CAIRO_STATUS_SUCCESS) { fprintf(stderr, "Error writing graph to PNG file\n"); return 1; } graph_surface_destroy(surface); graph_destroy(gr); return 0; }