void main() { init_graph(); cleardevice(); game_pack_intro(); do { init_graph(); choice = 1; select_game(); switch(choice) { case 1 : game_snake(); break; case 2 : game_snake_war(); break; case 3 : game_tetris(); break; case 4 : game_tank_shot(); break; default: break; } delay(2000); }while(choice != 0); game_pack_outro(); getch(); closegraph(); }
/* * This happend to be our first approuch to get the maximum matching. * THe results are pretty satisfatory and the code complexity isnt that bad at all */ Graph* maximal_matching(Graph* g) { Graph* m = (Graph*) malloc(sizeof(Graph)); Graph* matching = (Graph*) malloc(sizeof(Graph)); init_graph(m, g->vertex_count); init_graph(matching, g->vertex_count); int i; int j; // Make a copy of the graph ignoring loops for (i = 0 ; i < g->vertex_count ; i++) for (j = 0 ; j < g->vertex_count ; j++) if (i != j) m->arcs[i][j] = g->arcs[i][j]; Vertex* v = (Vertex*) malloc(g->vertex_count * sizeof(Vertex)); get_ordered_vertex(m, v); int saturated[m->vertex_count]; for (i = 0 ; i < m->vertex_count ; i++) saturated[i] = 0; for (i = 0 ; i < m->vertex_count ; i++) { m->vertex[i].degree = get_vertex_degree(m, i); } int* adj; for (i = 0 ; i < m->vertex_count ; i++) { int v1 = v[i].vertex; int v2; if (saturated[v1] == 0) { adj = get_adjacency(m, v1); if (adj[0] > 0) { v2 = adj[1]; for (j = 2 ; j <= adj[0] ; j++) { if (m->vertex[adj[j]].degree < m->vertex[v2].degree) v2 = adj[j]; } insert_arc(matching, v1, v2, m->arcs[v1][v2]); free(adj); saturated[v1] = 1; saturated[v2] = 1; for (j = 0 ; j < m->vertex_count ; j++) { remove_arc(m, v1, j); remove_arc(m, v2, j); } } } } return matching; }
/*recebe o nome do arquivo que contem a definicao do probelma e constroi o grafo correspondente*/ Graph le_entrada(char* nome_entrada){ FILE* input = fopen(nome_entrada, "r"); /*abre arquivo de entrada*/ int n; /*numero de vertices*/ Vertex origem, destino, u, v; Graph g; double cost, demanda; if(input == NULL){ puts("O arquivo passado como argumento nao exite!"); exit(-2); } fscanf(input, "%d", &n);/*le o numero de vertices*/ fscanf(input, "%d", &origem); /*le o vertice de origem*/ fscanf(input, "%d", &destino); /*le o vertice de destino*/ fscanf(input, "%lf", &demanda); /*le a quantidade de produto escoada*/ /*inicializa a rede*/ g = init_graph(n, origem, destino, demanda); while(fscanf(input, "%d %d %lf", &u,&v,&cost) != EOF){ /*equanto o arquivo nao acabar, le vertice_origem, vertice_destino e custo_aresta*/ add_arc(g,u,v,cost,0); /*adiciona arco lido na rede*/ } fclose(input); printf("A configuracao presente em %s foi lida com sucesso.\n", nome_entrada); return g; /*retona o grafo descrito pela entrada*/ }
void main(void) { int *g[GRAPH_ITEM_NUM]; int vs[VERTEX_NUM][VERTEX_PROPERTY]; int es[EDGE_NUM][EDGE_PROPERTY]; int cs[CELL_NUM][CELL_PROPERTY]; char *fname = "graph-kadai.dat"; int num_of_vertex = 8; int vid, v1, v2, eid; init_graph(g, vs, es, cs); read_data(g, fname); printf("Edge Data\n"); pr_edge_all(g); printf("Vertex Data\n"); pr_vertex_all(g); printf("最早結合点時刻\n"); calc_earliest_node_times(g, es, vs, num_of_vertex); printf("最遅結合点時刻\n"); calc_latest_node_times(g, es, vs, num_of_vertex); printf("クリティカルパス\n"); trace_critical_path(g, es, vs, num_of_vertex); }
int main(int argc,char** argv) { int opt = DEFAULT; if (argc < 2) { printf("USAGE : \t %s fic.data\n",argv[0]); exit(-1); } FILE *fd = fopen(argv[1],"r"); if (fd == NULL) { printf("Inexistant file"); exit(-1); } if (argv[2] != NULL) { if (strcmp(argv[2],"-v") == 0) { printf("VERBOSE MODE SET\n"); opt = 1; } } // Initialize graph with the given file in argument init_graph(fd,opt); // Computer links and nodes compute_links_and_nodes(g,argv[1]); // Compute degrees compute_degrees(argv[1]); if (fclose(fd)) perror("fclose error"); return 1; }
int main(int argc, char **argv) { t_struck s; t_pc *proc; unsigned long long i[3]; if (argc == 1) ft_usage(); init_struct(&s); proc = NULL; check_valid_file(&s, argv, 0); map_gen(&s, &proc, -1, i); s.pro = &proc; if (s.rep & GRAPH) { init_graph(&s); mlx_hook(s.img.win, 2, (1l << 0), key_functions, &s); mlx_hook(s.img.menu, 2, (1l << 0), key_functions, &s); s.rep ^= STOP; mlx_loop_hook(s.img.mlx, aff_graph, &s); mlx_loop(s.img.mlx); } else launching_vm(&s); return (0); }
int main(int argc, char* argv[]) { struct marsopts opts = init(argc, argv); Agraph_t* g = agread(opts.fin, (Agdisc_t*)NULL); Agnode_t* n; mat z; init_graph(g); z = mars(g, opts); mat_scalar_mult(z, opts.scale); if(opts.viewer) { viewer(argc, argv); } else { for(n = agfstnode(g); n; n = agnxtnode(g,n)) { int id = getid(n); char* s = pos_to_str(&z->m[mindex(id, 0, z)], z->c); agset(n,"pos",s); free(s); } agwrite(g, opts.fout); } mat_free(z); clean_up(g); agclose(g); return 0; }
bool validTree(int n, vector<pair<int, int>>& edges) { //check 1: number of edges == n-1???? if (edges.size() != n-1) return false; //check 2: from one node, can we visit all other nodes, visit count == n? //init graph graph g = init_graph(n, edges); queue<int> q; q.push(0); unordered_set<int> visited; visited.insert(0); int count = 0; while (!q.empty()) { int node = q.front(); q.pop(); count++; for (int nb: g[node]) { if (visited.count(nb)) continue; visited.insert(nb); q.push(nb); } } return count == n; }
int16_t make_graph() // // This procedure constructs the graph of (shortened) Ed_lines // of given component. // // ON ENTER: Line presentation of turned raster. // ON EXIT : Shortened lines and graph of their connectivity. // { Z = &string; if (!init_list()) return -1; // make initial list of lines max_line = n_lines; order_list(); // order of initial list and making one side links in it first_line = 0; init_graph(); // initialization of graph n_verts = 0; while (n_lines) { if (!merge_split()) return -1; // find merging or splitting line and // make separation of first line in list */ n_verts++; first_line = Ed_lines[first_line].next; // to next line in list n_lines = max_line - n_verts; } return n_verts; }
/* add a node to g by iterating through the list, returning if the node is found, and if not, adding it to the end */ graph_t *add_node(graph_t *g, const node_t *node) { if(g) { list_t *n = (list_t *)malloc(sizeof(list_t)); n->data = (void *) node; list_t *temp = g->nodes; /* make temp point to last list_t in g->nodes */ if(temp) { while(temp->next) { if(temp->data == node) return g; temp = temp->next; } temp->next = n; } else { g->nodes = n; } n->previous = temp; n->next = NULL; g->count++; } else { g = init_graph(); add_node(g, node); } return g; }
//******************************************************************** // 1998-09-16 - Created //******************************************************************** // init: Calls all other initiation routines //******************************************************************** int init( int argc , char *argv[] ) { init_default(); if( !init_appl() ) { Return( FALSE ); } if( !init_graph() ) { Return( FALSE ); } if( !init_rsc() ) { Return( FALSE ); } load_config(); #ifdef USE_MENU if( !open_menu( menu_tree , 1 ) ) { sprintf(tempvar.errorstring, MENU_ERROR ); alertbox( 1 , tempvar.errorstring ); #ifdef LOGGING Log( LOG_INIT , "Could not open menu-system!!!!\n" ); #endif Return FALSE ; } #endif if( !tempvar.registered ) { open_dialog( &info_win , NULL ); } else { open_dialog( &main_win , NULL ); } Return TRUE ; }
graph_t *graph_copy(const graph_t *src) { graph_t *g = init_graph(); list_t *temp; for(temp = src->nodes; temp; temp = temp->next) add_node(g, temp->data); return g; }
static void lavfi_process(struct mp_filter *f) { struct lavfi *c = f->priv; if (!c->initialized) init_graph(c); while (c->initialized) { bool a = read_output_pads(c); bool b = feed_input_pads(c); if (!a && !b) break; } // Start over on format changes or EOF draining. if (c->draining_recover) { // Wait until all outputs got EOF. bool all_eof = true; for (int n = 0; n < c->num_out_pads; n++) all_eof &= c->out_pads[n]->buffer_is_eof; if (all_eof) { MP_VERBOSE(c, "recovering all eof\n"); free_graph(c); mp_filter_internal_mark_progress(c->f); } } if (c->failed) mp_filter_internal_mark_failed(c->f); }
int main() { while (true) { scanf("%d", &n); if (n == 0) break; scanf("%d", &m); int ans = 0; init_graph(); for (int i = 0; i < n; ++i) pv[i] = true; for (int i = 0; i < m; ++i) { int u, v, w; scanf("%d%d%d", &u, &v, &w); --u; --v; ans += w; if (w < g[u][v]) g[u][v] = g[v][u] = w; pv[u] = !pv[u]; pv[v] = !pv[v]; } ans += cost_euler_cycle(); printf("%d\n", ans); } return 0; }
graph_t *graph_plus_node(const graph_t *g, const node_t *n) { graph_t *copy; if(g) copy = graph_copy(g); else copy = init_graph(); add_node(copy, n); return copy; }
/** * Resize method that calls Dijkstra algorithm for each Vertex inside * the Vertexes set of the Graph */ void graph_shortest_path(PPMImage *image, int *path) { Graph graph; init_graph(&graph, image); pri_queue_t priq_s; priq_init(&priq_s, graph.list_size); int i, x, y, dest; Energy *distance = calloc(graph.list_size, sizeof(Energy)); int *previous = calloc(graph.list_size, sizeof(int)); Energy shortest_distance; shortest_distance = ENERGY_MAX; for(x = 0; x < image->width; x++) { i = XY2POS(image, x, image->height - 1); dest = dijkstra(&graph, i, &priq_s, distance, previous, shortest_distance); #ifdef OPT_GRAPH_SHORTEST_PATH_BREAK if(dest == BREAK) continue; else #endif if(dest < 0) { fprintf(stderr, "There is no path\n"); exit(EXIT_FAILURE); } if (distance[dest] < shortest_distance) { shortest_distance = distance[dest]; y = 0; while(dest != i) { path[y++] = POS2X(dest, image); dest = previous[dest]; } path[y] = POS2X(i, image); // assert path length ASSERT_TRUE(y == image->height - 1, fprintf(stderr, "ASSERT: Path length error (must to be %d): %d\n", image->height - 1, y) ); } } priq_free(&priq_s); free_graph(&graph); free(distance); free(previous); }
int main (int argc, char *argv []) { init_graph(); context = zmq_init (1); send_hashes = zmq_socket (context, ZMQ_PUSH); zmq_connect (send_hashes, "tcp://localhost:5557"); recv_hashes = zmq_socket (context, ZMQ_SUB); zmq_connect (recv_hashes, "tcp://localhost:5556"); recv_work = zmq_socket (context, ZMQ_REP); int wport = zsocket_bind(recv_work, "tcp://*:*"); printf("Waiting for work on port %i\n",wport); recv_ctrl = zmq_socket (context, ZMQ_PULL); int cport = zsocket_bind(recv_ctrl, "tcp://*:*"); printf("Waiting for controlmessages on port %i\n",cport); char *filter = ""; zmq_setsockopt (recv_hashes, ZMQ_SUBSCRIBE, filter, strlen (filter)); pthread_t worker; pthread_create (&worker, NULL, update_hashes, (void*) &context); pthread_t stats; pthread_create (&stats, NULL, print_stats, NULL); printf("starting\n"); // enqueue(root,digest); // while (1) { work_hard(); count++; } running = 0; printf("%d %d\n",count,count_elements()); printf("Hit: %d Cache: %d\n",hit,cache); zmq_close (send_hashes); zmq_close (recv_hashes); zmq_term (context); return 0; }
void init(Graph graph[15]){ static int flg = 0; //DxLib関係初期化 init_Dx(); //画像関係初期化(1回のみ) if (flg != 1){ init_graph(graph); flg = 1; } }
void main() { int i, j, k1, k2, w, count; Set *s_visited; Graph *g = init_graph(10); for(i = 0; i < 10; i++) { k1 = (int) rand() % 10; k2 = (int) rand() % 10; w = (int) rand() % 100 + 1; add_edge(g, k1, k2, w); } graph_display(g); mst_krushkal(g); }
void init(Graph graph[15], Picture handle[15]){ static int flg = 0; //DxLib関係初期化 init_Dx(); //画像関係初期化(1回のみ) if (flg != 1){ init_graph(graph,handle); flg = 1; } }
int8_t probe(uint8_t depth) { outstanding_seq++; nrk_time_get(&last_activity); LOG("starting: orig "); LOGP("%d", this_node_id); LOGA(" seq "); LOGP("%d", outstanding_seq); LOGA(" depth "); LOGP("%d\r\n", depth); init_graph(&network); print_graph(&network); discovered_seq = outstanding_seq; // origin starts discovered return broadcast_request(this_node_id, outstanding_seq, depth, 0 /* attempt */); }
void input_graph(int weight[][MAXNODES]) { int e1,e2,w; char next_edge = 'y'; init_graph(weight); printf("input edge and weight in order (e1,e2,w) \n"); while(next_edge == 'y' || next_edge =='Y') { scanf("%d%d%d",&e1,&e2,&w); join(weight,e1,e2,w); printf("input next_edge (y/n)\n"); scanf(" %c",&next_edge); } }
void test_graph() { Graph graph; init_graph(&graph, DIRECTED); add_verts(&graph, 6); add_edge(&graph, 0, 1); add_edge(&graph, 0, 2); add_edge(&graph, 1, 3); add_edge(&graph, 1, 2); add_edge(&graph, 3, 4); add_edge(&graph, 4, 5); std::cout << "Number of vertices: " << graph.nvertices << std::endl; std::cout << "Number of edges: " << graph.nedges << std::endl; std::cout << "Route from 0 to 5? " << (is_route(&graph, 2, 5) == true ? "yes" : "no") << std::endl; }
void main() { int i, j, k1, k2, w, count; Set *s_visited; Graph *g = init_graph(10); for(i = 0; i < 10; i++) { k1 = (int) rand() % 10; k2 = (int) rand() % 10; w = (int) rand() % 100 + 1; add_edge(g, k1, k2, w); } graph_display(g); s_visited = set_create(); printf("Depth first traveral\n***********************\n"); depth_first_traversal(g, 0, s_visited); }
int main() { int i, ll; scanf("%d", &n); init_graph(); ll = toposort(); if (ll > 0) printf("%d", a[l[0]]); for (i = 1; i < ll; ++i) { printf(" %d", a[l[i]]); } printf("\n"); return 0; }
int main() { init_graph(); //p_hop_t *get_hop_counts(uint8_t *count); UNIT_TEST_RUN(empty_hop); UNIT_TEST_RUN(null_hop); UNIT_TEST_RUN(cyclic_hop); UNIT_TEST_RUN(no_hop); UNIT_TEST_RUN(omnidirectional_hop); //void purge(); UNIT_TEST_RUN(empty_purge); UNIT_TEST_RUN(delete_and_decrement_purge); return EXIT_SUCCESS; }
void city_tour() { graph h; edge *elist; int nedge; init_graph(&h); h.read_node_attr = read_cityname; h.write_node_attr = write_cityname; h.read_edge_attr = read_distance; h.write_edge_attr = write_distance; if (read_graph(FILENAME, &h)) { print_graph(stdout, &h); elist = (edge *) malloc(sizeof(edge) * (number_of_nodes(&h) - 1)); nedge = mst_kruskal(&h, elist, get_distance); } }
void MaxFlowSegmentation::compute2d(void) { if(edgesbuilt==false) { init_graph(); build_statistics(); build_terminals(); build_edges2d(); //edgesbuilt = true; } double flow = g->maxflow(); //printf("Flow = %f\n", flow); //printf("Minimum cut:\n"); //delete[] image_data; //delete g; }
int main() { int x,y; scanf("%d%d%d",&n,&m,&hole); for(int i=0;i<hole;i++) { scanf("%d%d",&x,&y); board[y-1][x-1]=true; } if((n*m-hole)&1) { printf("NO"); return 0; } point=(n*m+1)/2; init_graph(); if(max_match()==((n*m-hole)>>1)) printf("YES\n"); else printf("NO\n");
int main() { int i,a,b,c; scanf("%d %d",&n,&m); init_graph(); for(i=1;i<=m;i++) { scanf("%d %d %d",&a,&b,&c); add_edge(a,b,c); } vs=1; Dijkstra(); if(dist[n]==maxw) printf("-1"); else printf("%d",dist[n]); return 0; }