static THD_FUNCTION(ThreadGRAPH, arg) { (void)arg; chRegSetThreadName("Graph"); while (true) { updateGraphData(current_mA, 0); updateGraphData(loadvoltage, 1); updateGraphData(((current_mA*loadvoltage)/1000), 2); if (activeGraph == 0) { displayGraph(ghContainerGraphC, 0); } if (activeGraph == 1) { displayGraph(ghContainerGraphV, 1); } if (activeGraph == 2) { displayGraph(ghContainerGraphW, 2); } if (activeGraph == 3) { displayGraph(ghContainerGraphCV_1, 0); displayGraph(ghContainerGraphCV_2, 1); } chThdSleepMilliseconds(GRAPH_Refresh); } }
int main(){ Graph *G = NULL; int n; printf("Enter the number of nodes in the graph: "); scanf("%d",&n); //Generate a graph consisting of n nodes. G = createGraph(n,DIRECTED); //Add new edges addEdge(G,0,4); addEdge(G,0,1); addEdge(G,1,3); addEdge(G,1,2); addEdge(G,1,4); addEdge(G,1,0); addEdge(G,2,3); addEdge(G,2,1); addEdge(G,3,2); addEdge(G,3,4); addEdge(G,3,1); addEdge(G,4,1); addEdge(G,4,0); addEdge(G,4,3); displayGraph(G); system("pause"); return 0; }
int main() { int g ; stack s ; initialize_s(&s); printf("\nGive a goal state"); scanf("%d",&g); readGraph(); displayGraph(); if(!BSF(&s, 0, g)) printf("\nGoal state %d not found", g); printf("\n" ); return 0; }
main() { struct Vertex *V; V=NULL; wtd=NONWEIGHTED; printf("\n**Input Graph**\n"); buildGraph(&V); printf("\n***Graph Display***"); displayGraph(V); freeGraph(&V); }
int main(int argc, char **argv) { random_init(); Graph *g = makeRandomGraph<Graph>(10, 11); g->write_dot_file("/tmp/graph.dot"); DfsSearch search(g); search.search_from(0); search.print_order(); BfsSearch s(g); s.search_from(0); s.print_order(); displayGraph("/tmp/graph.dot"); return 0; }
void DataPlot::createPoints(const QString& rawdata) { QString working = rawdata; QString line = ""; QStringList datalines = rawdata.split("\n", QString::SkipEmptyParts); plotDataPoints.clear(); foreach (line, datalines) { if(!loadPlotDataPoints(line)) return; } displayGraph(plotDataPoints); }
//Main int main(){ Graph *G1; int node; G1 = createGraph(5); addEdge(G1,0,1); addEdge(G1,1,2); addEdge(G1,2,3); addEdge(G1,3,4); //addEdge(G1,2,4); //addEdge(G1,3,4); //addEdge(G1,4,0); displayGraph(G1); //printf("Find the degree of the node: "); //scanf("%d", &node); //printf("degree(%d) = %d\n", node, degree(G1, node)); int a, b; printf("Find the distance of the nodes: "); scanf("%d %d", &a, &b); printf("Distance(%d, %d) = %d\n", a, b, distance(G1, a, b)); return 0; }
bool processMenu(int choice) { string name; switch(choice-1) { case CREATE_NODE: createNode(); break; case DELETE_NODE: deleteNode(); break; case CREATE_RELATION: createRelation(); break; case DELETE_RELATION: deleteRelation(); break; case SAVE_GRAPH: saveGraph(); break; case LOAD_GRAPH: loadGraph(); break; case DISPLAY_GRAPH: displayGraph(); break; case RUN_PRIM: runPrim(); break; case QUIT: return true; break; default: cout << "Invalid input" << endl; cout << endl; break; } return false; }
int main() { printf("Starting tests...\n"); test_creatememory(); Graph_p undir_graph = test_createGraph(UNDIRECTED); test_addGraphElement(undir_graph, 0, 26); // 20 should pass 6 should require memory reallocation test_addEdge(undir_graph, 0, 1, 1); test_addEdge(undir_graph, 0, 4, 2); test_addEdge(undir_graph, 1, 2, 3); test_addEdge(undir_graph, 1, 3, 4); test_addEdge(undir_graph, 1, 4, 5); test_addEdge(undir_graph, 2, 3, 6); test_addEdge(undir_graph, 3, 4, 7); test_createGraphPage(undir_graph); test_addGraphElement(undir_graph, 1, 6); // Add 6 more - should pass now test_addEdge(undir_graph, 4, 0, 8); test_addEdge(undir_graph, 13, 0, 9); test_addEdge(undir_graph, 13, 0, 10); test_addEdge(undir_graph, 5, 0, 11); test_addEdge(undir_graph, 6, 0, 12); test_addEdge(undir_graph, 7, 0, 13); test_addEdge(undir_graph, 8, 0, 14); test_addEdge(undir_graph, 9, 0, 15); test_addEdge(undir_graph, 13, 0, 9); // duplicate test_addEdge(undir_graph, 10, 0, 16); test_addEdge(undir_graph, 11, 0, 17); test_addEdge(undir_graph, 13, 0, 9); // duplicate test_addEdge(undir_graph, 12, 0, 18); //get edges of Node(0) /* Graph_p dir_graph = createGraph(DIRECTED,"./default_d_db.gdb"); assert(dir_graph != NULL); result = addGraphElement(dir_graph, &(c[0])); assert(result == OK); result = addGraphElement(dir_graph, &(c[1])); assert(result == OK); result = addGraphElement(dir_graph, &(c[2])); assert(result == OK); result = addGraphElement(dir_graph, &(c[3])); assert(result == OK); result = addGraphElement(dir_graph, &(c[4])); assert(result == OK); result = addEdge(dir_graph, 0, 1, NULL); assert(result == OK); result = addEdge(dir_graph, 0, 4, NULL); assert(result == OK); result = addEdge(dir_graph, 1, 2, NULL); assert(result == OK); result = addEdge(dir_graph, 1, 3, NULL); assert(result == OK); result = addEdge(dir_graph, 1, 4, NULL); assert(result == OK); result = addEdge(dir_graph, 2, 3, NULL); assert(result == OK); result = addEdge(dir_graph, 3, 4, NULL); assert(result == OK); */ printf("\nUNDIRECTED GRAPH"); displayGraph(undir_graph); destroyGraph(undir_graph); //printf("\nDIRECTED GRAPH"); //displayGraph(dir_graph); //destroyGraph(dir_graph); return 0; }
int main(int argc, char const *argv[]) { int running = 1, cost = 0, i, j; char input[BUFFER_SIZE], *aft; char vertex, dest, option; Graph *g = NULL; createGraph(&g); #ifdef DEV insertVertex(g, 'a'); insertVertex(g, 'b'); insertVertex(g, 'c'); insertVertex(g, 'd'); insertVertex(g, 'e'); insertVertex(g, 'f'); insertEdge(g, 'a', 'b', 100); insertEdge(g, 'a', 'c', 300); insertEdge(g, 'a', 'a', 100); insertEdge(g, 'd', 'b', 70); insertEdge(g, 'f', 'c', 10); insertEdge(g, 'a', 'f', 10); insertEdge(g, 'a', 'f', 20); insertEdge(g, 'a', 'a', 100); displayGraph(g); greedySearch(g, 'a'); destroyGraph(g); #else while (running) { memset(input, 0, BUFFER_SIZE); printf("\n1 - inserir vertice\n"); printf("2 - inserir aresta\n"); printf("3 - remover vertice\n"); printf("4 - remover aresta\n"); printf("5 - imprimir grafo\n"); printf("6 - Busca Gulosa\n"); printf("7 - sair\n"); printf("\n$"); scanf(" %c", &option); switch (option) { case '1': printf("Digite um id para o novo no (apenas um caracter)\n"); printf(">>"); scanf(" %c", &vertex); if (!insertVertex(g, vertex)) { printf("Vertice inserido!\n"); printf("Digite os vizinhos (exemplo:b10 c20 d30) obs: caso o valor nao seja indicado o default sera 0\n"); getchar(); fgets(input, BUFFER_SIZE, stdin); for(i = 0; i < strlen(input); i++) { if(isalpha(input[i])) { dest = input[i]; for(j = i+1; j <= strlen(input); j++) { if(isdigit(input[j])) { cost = strtod(&input[j], &aft); i = (aft - input) -1; if(!insertEdge(g, vertex, dest, cost)) printf("Aresta inserida [%c] - [%c] com custo %d!\n", vertex, dest, cost); break; } if(isalpha(input[j]) || input[j] == '\0') { if(!insertEdge(g, vertex, dest, 0)) printf("Aresta inserida [%c] - [%c] com custo 0!\n", vertex, dest); break; } } } } } break; case '2': printf("Digite um par de vertices e um custo para a nova aresta (exemplo: A B 100)\n"); printf(">>"); scanf(" %c %c %d", &vertex, &dest, &cost); if(!insertEdge(g, vertex, dest, cost)) printf("Aresta inserida!\n"); break; case '3': printf("Digite o id do vertice a ser deletado\n"); printf(">>"); scanf(" %c", &vertex); if(!removeVertex(g, vertex)) printf("vertice removido\n"); break; case '4': printf("Digite o par de vertices e o custo da aresta (exemplo: A B 100)\n"); printf(">>"); scanf(" %c %c %d", &vertex, &dest, &cost); if(!removeEdge(g, vertex, dest, cost)) printf("aresta removida!\n"); break; case '5': displayGraph(g); break; case '6': printf("Digite um vertice para inicio da busca\n"); printf(">>"); scanf(" %c", &vertex); greedySearch(g, vertex); break; case '7': printf("Ate logo\n"); running = 0; destroyGraph(g); break; default: printf("Opcao invalida\n"); break; } } #endif return 0; }
int main() { FILE* fin = NULL; char c, fileName[20]; int i; do { printf ("\n <<<<<<<<<<<<<<<<<<<<<< MENU >>>>>>>>>>>>>>>>>>>>>>\n\n"); printf ("\n 1. Generate a new test file AND display it;"); printf ("\n 2. Generate a new test file WITHOUT displaying it;\n"); printf ("\n 3. Load an existing test file AND display it;"); printf ("\n 4. Load an existing test file WITHOUT displaying it;\n"); printf ("\n 5. Exit the program.\n"); printf ("\n Choose an option ('c' to clear screen): "); scanf (" %c", &c); if (c == 'c') { for (i = 0; i < 100; i++) { printf ("\n"); } } else if (c == '1') { printf ("\nGenerate a new test file and display it. Input its name:\n"); scanf ("%s", fileName); graphGenerator (fileName); displayGraph (fin, fileName); } else if (c == '2') { printf ("\nGenerate a new test file. Input its name:\n"); scanf ("%s", fileName); graphGenerator (fileName); } else if (c == '3') { printf ("\nLoad an existing test file and display it. Input its name:\n"); scanf ("%s", fileName); displayGraph (fin, fileName); } else if (c == '4') { printf ("\nLoad an existing test file. Input its name:\n"); scanf ("%s", fileName); } else if (c == '5') { exit(1); } else { printf ("\nThe key you pressed is not a valid option. Please press 1, 2, 3, 4 or 5.\n\n"); } if (c == '1' || c == '2' || c == '3' || c == '4') { fin = fopen (fileName, "r"); if (fin == NULL) { perror ("\n\tError opening file\n"); } else { int nodes; double beta; printf ("\nDefine the damping factor (best between 0.8 and 0.9): "); scanf ("%lf", &beta); double **M = loadGraph (fin, nodes); M = createMatrix_M (M, nodes, beta); double **B = createMatrix_B (nodes, beta); M = matrixSum (M, B, nodes); deallocMatrix <double> (B, nodes); // printf("\n Matrix A = M + B \n"); displayMatrix (M, nodes, nodes); // powerIteration (M, nodes, beta); fclose (fin); } } } while (true); return 0; }