void print_graph(CELL* inicio) { if(inicio->type.operador == '@') { if(inicio->left != NULL) { print_graph(inicio->left); } if(inicio->right != NULL) { if(inicio->right->type.operador == '@') { printf("("); } print_graph(inicio->right); if(inicio->right->type.operador == '@') { printf(")"); } } } else if (inicio->id == 'o') { printf("%c",inicio->type.operador); } else if(inicio->id == 'n') { printf("%d", (int)inicio->type.number); } }
int main() { Node *root, *aux; int size, check = 1, number, temp, num1, num2; clock_t c2, c1; float _time; scanf("%s", input); transform_input(); printf("(%s)\n", input); size = strlen(input); root = make_graph(0, size - 1); printf("Original Graph:\n"); print_graph(root); printf("\n"); printf("Start..\n"); c1 = clock(); root = reduce_graph(root, 0); c2 = clock(); _time = (c2 - c1)*1000/CLOCKS_PER_SEC; printf("\n\nEnd!\n"); printf("Reduced Graph:\n"); print_graph(root); printf("\nTempo de redução: %dhs %dmin %dseg %dmiliseg\n\n", (((int) _time)/1000)/3600, ((((int) _time)/1000)%3600)/60, ((((int) _time)/1000)%3600)%60, ((int) _time) - (((int) _time)/1000)*1000); printf("\n"); return 0; }
int main(int argc, char* argv[]) { Adjacency_Matrix* g = (Adjacency_Matrix*) malloc(sizeof(Adjacency_Matrix)); Adjacency_Matrix* tp; int* adjacency; empty_graph(g); int option, v, a1, a2; do { menu(); scanf("%d", &option); switch (option) { case INSERT_VERTEX: printf("How many vertex would you like to insert? "); scanf("%d", &v); insert_vertex(g, v); break; case REMOVE_VERTEX: printf("Which vertex would you like to remove? "); scanf("%d", &v); remove_vertex(g, v); break; case INSERT_ARC: printf("First vertex: "); scanf("%d", &a1); printf("Second vertex: "); scanf("%d", &a2); insert_arc(g, a1, a2, 1); break; case REMOVE_ARC: printf("First vertex: "); scanf("%d", &a1); printf("Second vertex: "); scanf("%d", &a2); remove_arc(g, a1, a2); break; case VERTEX_ADJACENCY: printf("Which vertex would you like to verify adjacency?"); scanf("%d", &v); adjacency = get_adjacency(g, v); print_adjacency(adjacency); free(adjacency); pause(); break; case TRANSPOSE_GRAPH: tp = transpose_graph(g); print_graph(tp); free(tp); pause(); break; case PRINT_GRAPH: print_graph(g); pause(); break; } } while (option != EXIT); return 0; }
//Exit screen void interface_exit() { screen_clear(); screen_frame_create(); print_graph("Are you sure you want to exit the program?",250,250); print_graph("Press 'Enter' to exit",320,266); SDL_RenderPresent(ren); }
gboolean te_graph_trigger(gpointer user_data) { enum transition_status graph_rc = -1; if (transition_graph == NULL) { crm_debug("Nothing to do"); return TRUE; } crm_trace("Invoking graph %d in state %s", transition_graph->id, fsa_state2string(fsa_state)); switch (fsa_state) { case S_STARTING: case S_PENDING: case S_NOT_DC: case S_HALT: case S_ILLEGAL: case S_STOPPING: case S_TERMINATE: return TRUE; break; default: break; } if (transition_graph->complete == FALSE) { int limit = transition_graph->batch_limit; transition_graph->batch_limit = throttle_get_total_job_limit(limit); graph_rc = run_graph(transition_graph); transition_graph->batch_limit = limit; /* Restore the configured value */ print_graph(LOG_DEBUG_3, transition_graph); if (graph_rc == transition_active) { crm_trace("Transition not yet complete"); return TRUE; } else if (graph_rc == transition_pending) { crm_trace("Transition not yet complete - no actions fired"); return TRUE; } if (graph_rc != transition_complete) { crm_warn("Transition failed: %s", transition_status(graph_rc)); print_graph(LOG_NOTICE, transition_graph); } } crm_debug("Transition %d is now complete", transition_graph->id); transition_graph->complete = TRUE; notify_crmd(transition_graph); return TRUE; }
gboolean te_graph_trigger(gpointer user_data) { enum transition_status graph_rc = -1; if (transition_graph == NULL) { crm_debug("Nothing to do"); return TRUE; } crm_debug_2("Invoking graph %d in state %s", transition_graph->id, fsa_state2string(fsa_state)); switch (fsa_state) { case S_STARTING: case S_PENDING: case S_NOT_DC: case S_HALT: case S_ILLEGAL: case S_STOPPING: case S_TERMINATE: return TRUE; break; default: break; } if (transition_graph->complete == FALSE) { graph_rc = run_graph(transition_graph); print_graph(LOG_DEBUG_3, transition_graph); if (graph_rc == transition_active) { crm_debug_3("Transition not yet complete"); return TRUE; } else if (graph_rc == transition_pending) { crm_debug_3("Transition not yet complete - no actions fired"); return TRUE; } if (graph_rc != transition_complete) { crm_err("Transition failed: %s", transition_status(graph_rc)); print_graph(LOG_WARNING, transition_graph); } } crm_info("Transition %d is now complete", transition_graph->id); transition_graph->complete = TRUE; notify_crmd(transition_graph); return TRUE; }
int main() { // named vertices auto const A = V { 1 }; auto const B = V { 2 }; // construct the graph auto e = std::vector<E> { { A, 3 }, { B, 4 } }; auto g = G { std::begin(e), std::end(e), 4 }; print_graph(g); collapse_vertices(B, A, g); print_graph(g); }
main() { int G[20][20],no_of_nodes,mst[20][20]; printf("Enter no.of nodes:"); scanf("%d",&no_of_nodes); create_graph(G,no_of_nodes); printf("---Original graph---\n"); print_graph(G,no_of_nodes); MST_kruskal(G,no_of_nodes,mst); printf("----Mst---\n"); print_graph(mst,no_of_nodes); }
void unitTestDfs() { { Graph g(5, false); print_graph(g); g.insert(1, 2); print_graph(g); g.insert(1, 3); print_graph(g); g.insert(1, 4); print_graph(g); g.insert(2, 3); print_graph(g); g.insert(3, 5); print_graph(g); g.insert(4, 1); print_graph(g); g.insert(5, 2); print_graph(g); dfs(g, 1); } }
int main(int argc,char *argv[]) { read_graph(argv[1]); printf("Main print\n"); print_graph(); int smallestOutDegree = smallestOutDegreeSearch(getAllNodeIndexs()); char *name = mygraph->table[smallestOutDegree].name; int largestOutDegree = largestOutDegreeSearch(getAllNodeIndexs()); char *name1 = mygraph->table[largestOutDegree].name; int smallestInDegree = smallestInDegreeSearch(getAllNodeIndexs()); char *name2 = mygraph->table[smallestInDegree].name; int largestInDegree = largestInDegreeSearch(getAllNodeIndexs()); char *name3 = mygraph->table[largestInDegree].name; printf("The smallest outdegree: %d \t Name: %s(%dth)\n" , mygraph->table[smallestOutDegree].outdegree, name, smallestOutDegree); printf("The largest outdegree: %d \t Name: %s(%dth)\n\n" , mygraph->table[largestOutDegree].outdegree , name1, largestOutDegree); printf("The smallest indegree: %d \t Name: %s(%dth)\n" , mygraph->table[smallestInDegree].indegree , name2, smallestInDegree); printf("The largest indegree: %d \t Name: %s(%dth)\n" , mygraph->table[largestInDegree].indegree , name3, largestInDegree ); return(0); }//main
void main(){ Graph *G; G = (Graph *)malloc(sizeof(Graph)); printf("Enter the number of nodes :"); scanf("%d", &(G->v)); G->arr = (AdjList *)malloc(((G->v) + 1)*sizeof(AdjList)); int i; for(i = 1; i <= (G->v); i++) (G->arr[i]).head = NULL; printf("Enter '1 2' for an edge between nodes 1 and 2\n"); printf("Enter '0 0' to exit\n"); for(;;) { printf("Enter the edges\n"); int n1, n2; scanf ("%d %d", &n1, &n2); if((n1 <= (G->v) && n1 > 0) && (n2 <= (G->v) && n2 > 0)) G = addEdge(G, n1, n2); else { printf("Input Stop\n"); break; } } print_graph(G); DFS(G); dfs_check(G); }
int main() { graph g; read_graph(&g, 0); dijkstra(&g, 0); print_graph(&g); }
int main(int argc, char *argv[]) { FILE *f; char buf[LINE]; int n = 0; int n1, n2; srand(time(NULL)); f = fopen(argv[1], "r"); if (f == NULL) return errno; while (fgets(buf, LINE, f)) { load_node(buf, &nodes[n]); n++; } fclose(f); max_nodes = num_nodes = n; while (num_nodes > 2) { pick_edge(&n1, &n2); merge_nodes(n1, n2); } print_graph(); return 0; }
void handle_discover_response(pkt_t *pkt) { node_id_t origin = pkt->payload[PKT_RESPONSE_ORIGIN_OFFSET]; uint8_t seq = pkt->payload[PKT_RESPONSE_SEQ_OFFSET]; nrk_time_t delay; uint8_t attempt; if (!IS_VALID_NODE_ID(origin)) { LOG("WARN: invalid origin in response: "); LOGP("%d\r\n", origin); return; } LOG("response: orig "); LOGP("%u", origin); LOGA(" seq "); LOGP("%u", seq); LOGA(" src "); LOGP("%u", pkt->src); LOGA(": "); nrk_time_get(&last_activity); if (origin == this_node_id) { LOGA("reached origin\r\n"); add_path_to_graph(pkt); print_graph(&network); } else { /* we're not the destination: forward to gateway */ attempt = 0; do { forward_response(pkt, attempt); choose_delay(&delay, &discover_req_delay); nrk_wait(delay); } while (++attempt < discover_send_attempts); } }
// 1 color a 3 node, 2 edge graph // the node with the most edges should be spilled void test_chaitin_spill() { DEBUG_PRINT("\ntest_chaitin_spill:\n"); DEBUG_PRINT(" creating graph...\n"); graph* g = create_graph(); vertex* a = graph_add_vertex(g, 'a'); vertex* b = graph_add_vertex(g, 'b'); vertex* c = graph_add_vertex(g, 'c'); graph_add_edge(a, b); graph_add_edge(a, c); assert(a->color == -1); assert(b->color == -1); assert(c->color == -1); DEBUG_PRINT(" coloring graph...\n"); color_graph(g, 1); #ifdef DEBUG print_graph(g); #endif assert(a->color == -1); // spilled node assert(b->color == 0); assert(c->color == 0); destroy_graph(g); printf("+ algorithm test (spill) passed!\n"); }
int8_t cmd_rftop(uint8_t argc, char **argv) { node_id_t out_node, in_node; bool exists = false; uint8_t i, j; if (!(argc == 1 || argc == 3)) { OUT("usage: rftop [<out_node> <in_node>]\r\n"); return NRK_ERROR; } if (argc == 3) { /* create or destroy an edge */ out_node = atoi(argv[1]); in_node = atoi(argv[2]); for (i = 0; i < network.degree[out_node]; ++i) { if (network.edges[out_node][i].v == in_node) { exists = true; break; } } if (exists) { /* then, remove it */ for (j = i; j < network.degree[out_node] - 1; ++j) network.edges[out_node][j].v = network.edges[out_node][j + 1].v; network.degree[out_node]--; } else { network.edges[out_node][network.degree[out_node]++].v = in_node; } } else { print_graph(&network); } return NRK_OK; }
int main(void) { out("starting ...\n"); std::cout << " DFS " << std::endl; int N; //test cases scanf("%d\n", &N); out("N %d\n",N); int ord = 0; while(N-- > 0) { char * buff = NULL; graphtp g; size_t n; int m; //nodes scanf("%d\n", &m); out("m %d\n",m); int counter = 0; while(counter++ < m && getline(&buff, &n, stdin) != -1 ) { out("this is buff ='%s'\n", buff); char * tok = strtok(buff, " \n\t"); out("this is node ='%s'\n", tok); if(tok == NULL) { printf("Error in input file"); exit(1); } vi e; tok = strtok(NULL, " \n\t"); while(tok > 0) { int nodeto = atoi(tok); if(nodeto < m) { out("red tok='%s'\n", tok); e.push_back(nodeto); } else { printf("ERROR: node %d outside of range (max %d)\n", nodeto,m); } tok = strtok(NULL, " \n\t"); } g.push_back(e); out("size of g %d\n",g.size()); } printf("Case %d:\n", ++ord); print_graph(g); DFS_recursive(g); std::cout << std::endl; } return 0; }
int main(void) { graph g; read_graph(&g, TRUE); print_graph(&g); strong_components(&g); return 0; }
int main() { LGraph *G = createGraphEx(); print_graph(G); //Kruskal(*G); prim(*G, 0); return 0; }
int main () { create_graph(5); print_graph(); path = malloc(n * sizeof (int)); set = calloc(n, sizeof (int)); hamiltonian(0); return 0; }
void print_graph(Node* node) { if (node->left) { printf("("); print_graph(node->left); printf(")"); } if (node->type != '@'){ if (node->type == 'n') printf("%d", node->number); else printf("%c", node->type); } if (node->right) { printf("("); print_graph(node->right); printf(")"); } }
int main() { int result; init(); result = yyparse(); if (!result) print_graph(); return result; }
/* parent depends on dep which is satisfied by pkg */ static void print(const char *parentname, const char *pkgname, const char *depname, tdepth *depth, int last) { if(graphviz) { print_graph(parentname, pkgname, depname); } else { print_text(pkgname, depname, depth, last); } }
int main(void) { graph g; read_graph(&g, FALSE); print_graph(&g); articulation_vertices(&g); return 0; }
main() { graph g; read_graph(&g,FALSE); print_graph(&g); connected_components(&g); }
void notify_crmd(crm_graph_t *graph) { HA_Message *cmd = NULL; int log_level = LOG_DEBUG; const char *op = CRM_OP_TEABORT; int pending_callbacks = num_cib_op_callbacks(); stop_te_timer(transition_timer); if(pending_callbacks != 0) { crm_warn("Delaying completion until all CIB updates complete"); return; } CRM_CHECK(graph->complete, graph->complete = TRUE); switch(graph->completion_action) { case tg_stop: op = CRM_OP_TECOMPLETE; log_level = LOG_INFO; break; case tg_abort: case tg_restart: op = CRM_OP_TEABORT; break; case tg_shutdown: crm_info("Exiting after transition"); if (mainloop != NULL && g_main_is_running(mainloop)) { g_main_quit(mainloop); return; } exit(LSB_EXIT_OK); } te_log_action(log_level, "Transition %d status: %s - %s", graph->id, op, crm_str(graph->abort_reason)); print_graph(LOG_DEBUG_3, graph); cmd = create_request( op, NULL, NULL, CRM_SYSTEM_DC, CRM_SYSTEM_TENGINE, NULL); if(graph->abort_reason != NULL) { ha_msg_add(cmd, "message", graph->abort_reason); } send_ipc_message(crm_ch, cmd); crm_msg_del(cmd); graph->abort_reason = NULL; graph->completion_action = tg_restart; }
void usage_command(int argc, const char ** argv, FILE * dbFile) { cmd_flags * flags = cmd_flags_parse("-s time -e time -d string", argc, argv); if (flags == NULL) { return; } db_filter filter = db_filter_from_flags(flags); cmd_flags_free(flags); db * database = db_read_filtered(dbFile, filter); if (database == NULL) { fprintf(stderr, "failed to read database.\n"); return; } if (database->count == 0) { db_free(database); printf("nothing to graph.\n"); return; } db_sort(database); int bufferSize = 16; int valueCount = 0; double * values = (double *)malloc(sizeof(double) * bufferSize); unsigned long long currentMinute = database->entries[0].timestamp; double currentValue = 0; int i; for (i = 0; i < database->count; ++i) { db_entry entry = database->entries[i]; while (entry.timestamp >= currentMinute+60) { if (valueCount == bufferSize) { bufferSize *= 2; values = realloc(values, bufferSize * sizeof(double)); } values[valueCount++] = currentValue; currentValue = 0; currentMinute += 60; } currentValue += (double)entry.size; } if (valueCount == bufferSize) { bufferSize += 1; values = realloc(values, bufferSize * sizeof(double)); } values[valueCount++] = currentValue; printf("Data usage (spanning %lf hours):\n", (double)valueCount / 60); print_graph(values, valueCount); free(values); db_free(database); }
int main(int argn, char *argv[]) { graph_t g; read_graph(&g, FALSE); print_graph(&g); dijkstra(&g, 0); if(argn > 1) { find_path(0, atoi(argv[1])); } }
int main() { srand(time(NULL)); struct ID_table ID; input( &ID ); produce_ID( &ID ); print_graph( &ID ); //print_result( &ID ); printf("%s\n", KNRM); return 0; }
void main() { Graph* pG; // 自定义"图"(输入矩阵队列) //pG = create_graph(); // 采用已有的"图" pG = create_example_graph(); print_graph(*pG); // 打印图 DFSTraverse(*pG); // 深度优先遍历 BFS(*pG); // 广度优先遍历 }