int main() { readGraph(); displayListAdjacency(); BFS(); displayQueue(); return(0); };
Graph::Graph(string inFileName) { NE=0; NN=0; inputFileName = inFileName; cout<<"Trying to open and read graph file: "<<inputFileName<<endl; readGraph(); }
// ----------------------------------------------- Main -------------------------------------------- int main(int argc, char **argv){ Graph G; char filename[BUFFSIZE]; int source, destination; double elapsed_time; clock_t start, end; // Parsing arguments switch(argc){ case(4): if((sscanf(argv[2], "%d", &source) != 1) || (sscanf(argv[3], "%d", &destination) != 1)){ printf("Inputs must be integers.\n"); exit(1); } case(3): VERBOSE = 1; case(2): sscanf(argv[1], "%s", filename); break; default: printf("Wrong number of arguments.\n"); exit(1); } // Reading Graph G = readGraph(filename); // Printing graphs information printf("-------------------------------------------------------\n"); printf("There are %d nodes and %d edges!\n", G->V, G->E); printf("There are %d nodes and %d edges on the 'residual' network!\n", 2*G->V, 4*G->E + 2*G->V); printf("-------------------------------------------------------\n"); // If there is a defined pair of nodes only compute its path if(argc == 4){ if(EdmondsKarp(G, source, destination + NETSIZE)) findNodes(G, source, destination); // Else, compute all of them }else{ start = clock(); for(source = 0; source < NETSIZE; source++) for(destination = source + 1; destination < NETSIZE; destination++) if(source != destination) if(EdmondsKarp(G, source, destination + NETSIZE)) findNodes(G, source, destination); end = clock(); elapsed_time = (double)(end - start)/CLOCKS_PER_SEC; printResult(G); printf("Algorithm takes %f seconds\n", elapsed_time); printf("-------------------------------------------------------\n"); } // Free Memory allocated previously memoryCheck(G); exit(0); }
int main(){ int numGraphs = 0 ; scanf("%d",&numGraphs); int i = 0 ; for ( i = 0 ; i < numGraphs ; i++ ){ readGraph(); } }
int main() { GraphInfo gi; gi = readGraph("series.txt", LIST); writeGraph(gi); gi = readGraph("statesContig.txt", LIST); writeGraph(gi); printf("Successors of NC: "); int NCnum = vertexNum(gi, "NC"); int* vsucc = successors(gi->graph, NCnum); for (int i = 0; vsucc[i] != -1; i++) printf(" %s ", gi->vertnames[i]); printf("\n"); return 0; }
// // graph // // Program reads a text file that describes a graph. It // then performs a depth-first search of the graph from // the graph's 0 vertex, and reports the edges in the // DFS tree. // int main(int argc, char **argv) { FILE *gf; int **G, n, i, *pred, *other; int some = 0; if (argc < 2) { usage(argv[0],NULL); return -1; } else { gf = fopen(argv[1],"r"); if (gf == NULL) { usage(argv[0],argv[1]); return -1; } // read the graph file G = readGraph(gf,&n); // perform the search pred = dfs(0,G,n); // report the DFS tree printf("{"); for (i=1; i<n; i++) { if (pred[i] >= 0) { if (some) { printf(","); } printf("(%d,%d)",i,pred[i]); some = 1; } } printf("}\n"); some = 0; // perform the search pred = bfs(0,G,n); // report the BFS frontiers printf("{"); for (i=1; i<n; i++) { if (pred[i] >= 0) { if (some) { printf(","); } printf("(%d,%d)",i,pred[i]); some = 1; } } printf("}\n"); return 0; } }
int EdmondMatching::main(){ int n; n=readGraph(); findMaximumMatching(n); for (int i=0; i<n; i++){ for (int j=i+1; j<n; j++) if (g[i][j]==matched) printf("%d %d\n",i+1,j+1); } return 0; }
void toposort2(char * filepath) { GraphInfo gi = readGraph(filepath, MATRIX); // DN's implementation supports precessors only for MATRIX Graph g = gi->graph; int numV = numVerts(g); /* YOUR CODE GOES HERE */ }
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; }
int main() { int T; scanf("%d", &T); for (int ica = 0; ica < T; ++ica) { readGraph(); for (int i = 1; i <= n; ++i) p[i] = i; memset(vis+1, false, sizeof(bool)*n); scanf("%d%d", &u, &v); printf("%d\n", tarjan(root)); } return 0; }
int main(int argc, char *argv[]) { Graph G; G = readGraph(stdin); if (G == NULL) printf("Invalid graph\n"); else { printf("Graph:\n"); showGraph(G); printf("\n"); printf("# connected components = %d\n", nComponents(G)); } return 0; }
int main(int argc, char** argv) { LonestarStart(argc, argv, name, desc, url); srand(-1); MetisGraph metisGraph; GGraph graph; metisGraph.setGraph(&graph); bool directed = true; if(mtxInput){ readMetisGraph(&metisGraph, filename.c_str()); }else{ readGraph(&metisGraph, filename.c_str(), weighted, directed); } partition(&metisGraph, numPartitions); verify(&metisGraph); }
int main() { int source = 109; int drain = 609; Graph graph = readGraph(); int maxOutFlow = 0; int maxInFlow = 0; for (int u = 0; u < vertexCount; u++) { if(graph.getCost(source, u) > 0) maxOutFlow += graph.getCost(source, u); if(graph.getCost(u, drain) > 0) maxInFlow += graph.getCost(u, drain); } std::cout<<"Maximal flow: "<<fordFulkerson(graph, source, drain)<<std::endl; std::cout<<"Maximal out flow: "<<maxOutFlow<<std::endl; std::cout<<"Maximal in flow: "<<maxInFlow<<std::endl; return 0; }
int main(int argc, char** argv) { if(argc<3) { printf("Usage: serial [filename (.gr)] [filename (.ss)]\n"); exit(-1); } long long vNum, eNum; char* graphfile = argv[1]; char* specfile = argv[2]; List *edgelist, *sourcelist; edgelist = readGraph(graphfile, &vNum, &eNum); sourceList = readSource(specfile); return 0; }
int main(int argc, char *argv[]) { Graph g; readGraph(g, argv[1]); std::cout << "Starting pagerank" << "\n"; if(atoi(argv[2]) > 0) { try { g.start(atoi(argv[2])); } catch(std::out_of_range & ex) { std::cout << ex.what() << std::endl; } } else std::cout << "Invalid thread count\n"; //g.print(); g.printRank(); }
int main() { int j; int start_node = 1; readGraph(); displayMatrixAdjacency(); visited[ start_node ] = 1; DFS2( start_node ); displaySol2(); return(0); };
int main(int argc, char const *argv[]) { /* code */ char* line = NULL; size_t bytes = 0; int* solveSet = NULL, k = 0; Graph* graph = NULL; while(getline(&line, &bytes, stdin) != EOF) { graph = readGraph(line); k = solveVertexCover_SAT(graph, solveSet); printSolveSet(solveSet, k); free(solveSet); solveSet = NULL; destroyGraph(&graph); } return 0; }
int main(int argc, char * argv[]){ if (argc < 2){ printf("Incorrect usage: must enter filename\n"); exit (1); } Graph g = readGraph(argv[1]); showGraph(g); printf("\n"); // TASK 1 printf("TASK 1\n"); showGraphLabels(g); printf("\n"); showData(g); printf("\n"); // TASK 2 printf("TASK 2\n"); int *dfsOrdered = malloc(numV(g) * sizeof(Vertex)); dfSearch2(g, dfsOrdered); int i; for(i=0;i< cnt;i++){ Vertex v = dfsOrdered[i]; showVertexData(g,v); } printf("\n"); // TASK 3 printf("TASK 3\n"); printf("\nFlying all over the world\n"); //Uncomment out this line when you get to task 3 getFlights(g,dfsOrdered); free(dfsOrdered); destroyGraph(g); return 0; }
int main() { char* filepath; GraphInfo gi; filepath = "series.txt"; gi = readGraph(filepath, MATRIX); printf("Topological sort by predecessor technique %s\n", filepath); toposort2(gi); printf("\nTopological sort by DFS technique %s\n", filepath); gi = readGraph(filepath, MATRIX); // MUST read again or clone original since toposort2 deletes topocycle(gi); filepath = "LevitinTopo.txt"; gi = readGraph(filepath, MATRIX); printf("Topological sort by predecessor technique %s\n", filepath); toposort2(gi); printf("\nTopological sort by DFS technique %s\n", filepath); topocycle(readGraph(filepath, MATRIX)); filepath = "prereqs.txt"; gi = readGraph(filepath, MATRIX); printf("\nTopological sort by predecessor technique %s\n", filepath); toposort2(gi); printf("\nTopological sort by DFS technique %s\n", filepath); topocycle(readGraph(filepath, MATRIX)); filepath = "prereqCatch22.txt"; printf("\nCyclic graph %s\n", filepath); topocycle(readGraph(filepath, LIST)); /* NOTE: not disposing of the graphs */ return 0; }
int main(int argc, char *argv[]) { std::cerr << "reading graph..."; Eigen::SparseMatrix<double> g = readGraph(std::string(argv[1])); std::cerr << "done." << std::endl; #if DEBUG std::cout << "Adjacency Matrix" << std::endl; std::cout << g << std::endl; #endif std::vector<C_tuple*> C; std::cerr << "getting C vector..."; getC(g, C); std::cerr << "sorting..."; __gnu_parallel::sort(C.begin(), C.end(), C_tuple_compare); //std::sort(C.begin(), C.end(), C_tuple_compare); std::cerr << "done." << std::endl; #if DEBUG for (uint64_t i = 0; i < C.size(); i++) { std::cout << C[i]->i << ", " << C[i]->j << ", " << C[i]->value<< std::endl; } #endif std::cerr << "creating T..."; node* root = createT(g, C); std::cerr << "done." << std::endl; #if DEBUG //postorder(printNode, root); levelorder(printNode, root); node* left = root->leftChild; while (left->leftChild) left = left->leftChild; node* right = root->rightChild; while (right->rightChild) right = right->rightChild; node* lca = LCA(left, right); std::cout << "lca for " << left->vertex << ", " << right->vertex << ": " << lca->vertex << std::endl; left = right->parent->leftChild; lca = LCA(left, right); std::cout << "lca for " << left->vertex << ", " << right->vertex << ": " << lca->vertex << std::endl; #endif std::cerr << "counting vertices and edges..."; countVerticesAndEdges(g, root); std::cerr << "done." << std::endl; std::cerr << "computing density..."; computeDensity(root); std::cerr << "done." << std::endl; #if DEBUG std::cout << "\nPrinting after the countVerticesAndEdges\n" << std::endl; postorder(printNode, root); #endif std::cerr << "extracting subgraphs..."; extractSubgraphs(root, 0.75); std::cerr << "done." << std::endl; }
SigDenseSet * outInside(int flag,char *initial_filename,char *cluster_filename,float par_out_in,SigDenseSet *sds){ Graph *g,*tg; SigDense *sd; Node *node, *tnode; char line[MAXLINE]; char clusterName[10]; char edgesNumber[10]; char dump[10]; int orig_degree=0; g=readGraph(initial_filename); //kataskeui tou arxikou grafou if(flag==0){ //einai i proti methodos pou efarmozetai, diavasma apo to intermediate arxeio sds = initSigDenseSet(); FILE *fp = fopen(cluster_filename, "r"); if(fp == NULL){ cout<<"File "<<cluster_filename<< " could not be opened in density function"<<endl; system("pause"); } while(fgets(line, MAXLINE, fp)){ if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = STREND; sscanf (line,"%s %s %s",clusterName,dump,edgesNumber); //diavazei tin proti grammi tou kathe cluster tg=readCluster(fp, edgesNumber); //(format:#cluster : #edges) //cout<<"elegxos tou cluster "<<tg->nodes->label<<endl; for(tnode=tg->nodes;tnode!=NULL;tnode=tnode->next){ //ipologismos tou sinolikou degree ton korifon pou apoteloun ton cluster for(node=g->nodes;node!=NULL;node=node->next){ // if(strcmp(node->label,tnode->label)==0){ orig_degree+=node->degree; break; } } } //cout<<"exoume kai leme: orig_degree= "<<orig_degree<<" kai ta in= "<<tg->edgecount<<endl<<(float)tg->edgecount/(float)orig_degree<<endl; if((float)(tg->edgecount/(float)orig_degree)>=par_out_in){ //elegxos an einai piknos i oxi o cluster. SigDense *sd = new SigDense(); // an nai apothikeuse allios katestrepse sd->sg = tg; insertSigDense(sds, sd); orig_degree=0; } else{ destroyGraph(tg); orig_degree=0; } } fclose (fp); } else if(flag==1){ //den einai i proti methodos pou efarmozetai, opote idi exei dimiourgithei lista sds for (sd = sds->first->next; sd != NULL; sd=sd->next){ for(tnode=sd->sg->nodes;tnode!=NULL;tnode=tnode->next){ //ipologismos tou sinolikou degree ton korifon pou apoteloun ton cluster for(node=g->nodes;node!=NULL;node=node->next){ // if(strcmp(node->label,tnode->label)==0){ orig_degree+=node->degree; break; } } } if(sd->sg->nodecount<2 || (float)sd->sg->edgecount/orig_degree<par_out_in){ //elegxos sd->prev->next=sd->next; // an oxi, parekampse ton. PROSOXI!!dimiourgia skoupidion(den svino) if(sd->next!=NULL) sd->next->prev=sd->prev; } orig_degree=0; } } else{ cout<<"The flag is WRONG in density function"<<endl; system("pause"); } return sds; }
SigDenseSet * bestneighbor(int flag,char *initial_filename,char *cluster_filename,float par_bestneighb,SigDenseSet *sds){ Graph *g,*tg; SigDense *sd; Node *node, *tnode,*nnode,*tnode2; char line[MAXLINE]; char clusterName[10]; char edgesNumber[10]; char dump[10]; int orig_degree=0,r,numb_neigh,exist,good_neigh; float score; Edge *edge,*nedge; g=readGraph(initial_filename); //kataskeui tou arxikou grafou Node **neighborlist = new Node*[g->nodecount]; for(r=0;r<g->nodecount;r++){ neighborlist[r]=NULL; } if(flag==0){ //einai i proti methodos pou efarmozetai, diavasma apo to intermediate arxeio sds = initSigDenseSet(); FILE *fp = fopen(cluster_filename, "r"); if(fp == NULL){ cout<<"File "<<cluster_filename<< " could not be opened in density function"<<endl; system("pause"); } while(fgets(line, MAXLINE, fp)){ if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = STREND; sscanf (line,"%s %s %s",clusterName,dump,edgesNumber); //diavazei tin proti grammi tou kathe cluster tg=readCluster(fp, edgesNumber); //(format:#cluster : #edges) numb_neigh=0;exist=0;score=0;good_neigh=0; for(tnode=tg->nodes;tnode!=NULL;tnode=tnode->next){ //euresi ton geitonon ston arxiko grafo for(node=g->nodes;node!=NULL;node=node->next){ // if(strcmp(node->label,tnode->label)==0){ for(edge=node->edges;edge!=NULL;edge=edge->next){ nnode=edge->partner; for(r=0;r<numb_neigh;r++){//elegxos mipos exei xanasinatithei o geitonas if(strcmp(neighborlist[r]->label,nnode->label)==0){ exist=1; break; } } for(tnode2=tg->nodes;tnode2!=NULL;tnode2=tnode2->next){//elegxos mipos o geitonas anikei ston grafo if(strcmp(nnode->label,tnode2->label)==0){ exist=1; break; } } if(exist==0){//an oxi, ton prosthetoume ston pinaka geitonon kai vlepoume an einai best neighborlist[numb_neigh]=nnode; for(nedge=neighborlist[numb_neigh]->edges;nedge!=NULL;nedge=nedge->next){//ipologismos ton "kalon" edges for(tnode2=tg->nodes;tnode2!=NULL;tnode2=tnode2->next){ if(strcmp(nedge->partner->label,tnode2->label)==0){ score++; break; } } } if(score/neighborlist[numb_neigh]->degree>=par_bestneighb){//an mas kanei, vazoume part=1 neighborlist[numb_neigh]->part=1; good_neigh++; // cout<<"enas kalos komvos einai o: "<< neighborlist[numb_neigh]->label<< "me degree"<<neighborlist[numb_neigh]->degree<<endl;system("pause"); } numb_neigh++; score=0; } exist=0; } break; } } } for(r=0;r<numb_neigh;r++){ //prosthetoume tous kalous geitones ston cluster if(neighborlist[r]->part==1){ Node *new_node; new_node=addNode(tg,neighborlist[r]->label); } } tnode=tg->nodes; for(r=0;r<good_neigh;r++){//cout<<"ok "<<tnode->label<<endl;system("pause"); // prosthetoume tis edges gia tous kainourgious komvous for(node=g->nodes;node!=NULL;node=node->next){//cout<<"ok2"<<endl;system("pause"); // if(strcmp(node->label,tnode->label)==0){//cout<<"ok3"<<endl;system("pause"); for(edge=node->edges;edge!=NULL;edge=edge->next){//cout<<"ok4"<<endl;system("pause"); for(tnode2=tg->nodes;tnode2!=NULL;tnode2=tnode2->next){//cout<<"ok5"<<endl;system("pause"); if(strcmp(edge->partner->label,tnode2->label)==0){//cout<<"ok6"<<endl;system("pause"); addEdge(tg,tnode,tnode2,edge->weight); addEdge(tg,tnode2,tnode,edge->weight); } } } break; } } tnode=tnode->next; } if(g->nodecount!=0){ SigDense *sd = new SigDense(); // apothikeuse to ipoloipo ton clusters sti lista sd->sg = tg; insertSigDense(sds, sd); } } fclose(fp); } else if(flag==1){ //den einai i proti methodos pou efarmozetai, opote idi exei dimiourgithei lista sds for (sd = sds->first->next; sd != NULL; sd=sd->next){ numb_neigh=0;exist=0;score=0;good_neigh=0; for(tnode=sd->sg->nodes;tnode!=NULL;tnode=tnode->next){ //euresi ton geitonon ston arxiko grafo for(node=g->nodes;node!=NULL;node=node->next){ // if(strcmp(node->label,tnode->label)==0){ for(edge=node->edges;edge!=NULL;edge=edge->next){ nnode=edge->partner; for(r=0;r<numb_neigh;r++){//elegxos mipos exei xanasinatithei o geitonas if(strcmp(neighborlist[r]->label,nnode->label)==0){ exist=1; break; } } for(tnode2=sd->sg->nodes;tnode2!=NULL;tnode2=tnode2->next){//elegxos mipos o geitonas anikei ston grafo if(strcmp(nnode->label,tnode2->label)==0){ exist=1; break; } } if(exist==0){//an oxi, ton prosthetoume ston pinaka geitonon kai vlepoume an einai best neighborlist[numb_neigh]=nnode; for(nedge=neighborlist[numb_neigh]->edges;nedge!=NULL;nedge=nedge->next){//ipologismos ton "kalon" edges for(tnode2=sd->sg->nodes;tnode2!=NULL;tnode2=tnode2->next){ if(strcmp(nedge->partner->label,tnode2->label)==0){ score++; break; } } } if(score/neighborlist[numb_neigh]->degree>=par_bestneighb){//an mas kanei, vazoume part=1 neighborlist[numb_neigh]->part=1; good_neigh++; // cout<<"enas kalos komvos einai o: "<< neighborlist[numb_neigh]->label<< "me degree"<<neighborlist[numb_neigh]->degree<<endl;system("pause"); } numb_neigh++; score=0; } exist=0; } break; } } } for(r=0;r<numb_neigh;r++){ //prosthetoume tous kalous geitones ston cluster if(neighborlist[r]->part==1){ Node *new_node; new_node=addNode(sd->sg,neighborlist[r]->label); } } tnode=sd->sg->nodes; for(r=0;r<good_neigh;r++){//cout<<"ok "<<tnode->label<<endl;system("pause"); // prosthetoume tis edges gia tous kainourgious komvous for(node=g->nodes;node!=NULL;node=node->next){//cout<<"ok2"<<endl;system("pause"); // if(strcmp(node->label,tnode->label)==0){//cout<<"ok3"<<endl;system("pause"); for(edge=node->edges;edge!=NULL;edge=edge->next){//cout<<"ok4"<<endl;system("pause"); for(tnode2=sd->sg->nodes;tnode2!=NULL;tnode2=tnode2->next){//cout<<"ok5"<<endl;system("pause"); if(strcmp(edge->partner->label,tnode2->label)==0){//cout<<"ok6"<<endl;system("pause"); addEdge(sd->sg,tnode,tnode2,edge->weight); addEdge(sd->sg,tnode2,tnode,edge->weight); } } } break; } } tnode=tnode->next; } } } else{ cout<<"The flag is WRONG in density function"<<endl; system("pause"); } delete neighborlist; return sds; }
int main(int argc, char * argv[]){ Agent agents[NUM_DETECTIVES+1]; if(argc < 4){ printf("Incorrect usage: please enter filename1 filename2 maxCycles\n"); exit(0); } int maxCycles = atoi(argv[3]); int cycle = 0; int seed = time(NULL); if(argc == 5) seed = atoi(argv[4]); srand(seed); Graph g = readGraph(argv[1]); #ifdef DEBUG show(g); #endif initialiseAgents(argv[2],agents,maxCycles,g); #ifdef DEBUG stats(cycle,agents); #endif char command[MAXLINE]; printf("\nPOLICE ACADEMY 1927"); printf("\n\nRed alert! A thief is on the run.\n"); printf("Agents, to your cars. You have %d hours.\n\n",maxCycles); display(cycle,agents,g); if(checkGameState(agents,g,cycle,maxCycles) != CONTINUE){ freeResources(agents,g); return 0; } printf("Enter command: "); scanf("%s",command); while (strcmp(command,"quit") != 0){ if(strcmp(command,"display") == 0){ display(cycle,agents,g); }else if(strcmp(command,"run") == 0){ cycle = run(cycle,maxCycles,agents,g); }else if(strcmp(command,"step") == 0){ cycle = step(cycle,agents,g,maxCycles); }else if(strcmp(command,"stats") == 0){ stats(cycle,agents); }else if(strcmp(command,"map") == 0){ show(g); printf("\n"); } if(cycle < 0) break; printf("Enter command: "); scanf("%s",command); } freeResources(agents,g); return 0; }
int main(int argc, char **argv ) { /* This is the shortest path project for CPSC424/524. Author: Bo Song, Yale University Date: 4/25/2016 Credits: This program is based on the description provided by Andrew Sherman */ double wct0, wct1, total_time, cput; char* sourceFile, * graphFile; int count[8]; #pragma omp parallel printf("num of threads = %d\n", omp_get_num_threads()); for(int i = 0; i < 8; i++) count[i] = 0; for(int i = 0; i < 8; i++) loopCount[i] = 0; for(int i = 0; i < 8; i++) updateCount[i] = 0; if(argc != 3) { printf("serial <graphfile> <sourcefile>\n"); return -1; } graphFile = argv[1]; sourceFile = argv[2]; timing(&wct0, &cput); printf("reading graph...\n"); readGraph(graphFile); printf("reading source...\n"); readSource(sourceFile); // print_adj_list(adj_listhead, N); #pragma omp parallel #pragma omp for schedule(static, 1) for(int i = 0; i < num_sources; i++) { count[omp_get_thread_num()]++; moore(sources[i]); } timing(&wct1, &cput); //get the end time total_time = wct1 - wct0; printf("Message printed by master: Total elapsed time is %f seconds.\n",total_time); // free resources for(int i = 1; i <= N; i++) { adj_node* node = adj_listhead[i]; while(node) { adj_node* next = node->next; free(node); node = next; } } printf("Load balance among threads: "); long long sumLoop = 0, sumUpdate = 0; for(int i = 0; i < 8; i++) { printf("%d ", count[i]); sumLoop += loopCount[i]; sumUpdate += updateCount[i]; } printf("portion = %f", (float)sumUpdate / sumLoop); printf("\n"); free(sources); }
int main(int argc, char **argv) { // define defaults arguments.outfile = ""; arguments.directed = false; arguments.action = 0; arguments.type = 0; arguments.infectiousProbability = -1; arguments.contactChance = -1; arguments.kVal = -1; arguments.infectiousPeriod = -1; arguments.simulDuration = -1; arguments.weighted = false; //printf("%c %c %f %f %d %d %d", arguments.action, arguments.type, arguments.infectiousProbability, arguments.contactChance, arguments.kVal, arguments.infectiousPeriod, arguments.simulDuration); argp_parse(&argp, argc, argv, 0, 0, &arguments); // TODO: see how to use argp to do this /*if (argc != 2) { fprintf(stderr, "Usage: %s <graphFile>\n", argv[0]); fprintf(stderr, "<graphFile>: Name of graph to test\n"); exit(1); }*/ clock_t t1, t2; t1 = clock(); readGraph(arguments.graph_path, arguments.directed, arguments.weighted); t1 = clock() - t1; // Done reading t2 = clock(); char *temp = (char *)malloc(strlen(arguments.graph_path)+1); strcpy(temp, arguments.graph_path); char *tok = strtok(temp, "/"); if ((tok = strtok(NULL, "/")) != NULL) { tok = strtok(tok, "."); } else { tok = strtok((char *)arguments.graph_path, "."); } char choice = arguments.action; if (choice == 0) { printf("[a]nalyze graph or [r]un simulation: "); scanf("%c", &choice); } if (choice == 'a') graphStats(tok); else runSimulation(tok); free(temp); free(graph); t2 = clock() - t2; // Done processing printf("\nGraph Read Runtime: %lu clicks (%.3f seconds)\n", t1, (((float)t1)/CLOCKS_PER_SEC)); printf("Graph Process Runtime: %lu clicks (%.3f seconds)\n", t2, (((float)t2)/CLOCKS_PER_SEC)); printf("Total Runtime: %lu clicks (%.3f seconds)\n", t1+t2, (((float)t1+t2)/CLOCKS_PER_SEC)); return 0; }
int main(int argc, char **argv) { char **inputNameTable, **name, inputFileName[STRING_SIZE], outputFileName[STRING_SIZE], effectifFileName[STRING_SIZE], outputPrefix[STRING_SIZE], outputFileNameRand[STRING_SIZE], buffer[STRING_SIZE], inputFileNameModel[STRING_SIZE], *tmp, option[256]; FILE *fi, *fo, *fs; int i, j, t, sizeTable, singleF = 0; TypeMultiGraph *graph, *gtmp; TypeGraph **tableGraph, *g; TypePartition part, *tablePart; double alpha = 1.; for(i=0; i<256; i++) option[i] = 0; sprintf(outputFileName, "%s.%s", NAME_OUTPUT, EXT_OUTPUT); tableGraph = (TypeGraph**) malloc((argc+3)*sizeof(TypeGraph*)); inputNameTable = (char**) malloc((argc+3)*sizeof(char*)); sizeTable = 0; for(i=1; i<argc && *(argv[i]) == '-'; i++) { for(j=1; argv[i][j] != '\0'; j++) option[argv[i][j]] = 1; if(option['o']) { option['o'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%s", outputFileName) == 1) i++; else exitProg(ErrorArgument, "a file name is required after option -f"); } if(option['s']) { option['s'] = 0; singleF = 1; } if(option['p']) { option['p'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%lf", &alpha) == 1) i++; else exitProg(ErrorArgument, "a real number is required after option -p"); } if(option['m']) { option['m'] = 0; if(!(sscanf(argv[i+1], "%s", inputFileName) == 1)) exitProg(ErrorArgument, "wrong file name"); i++; inputNameTable[sizeTable] = (char*) malloc((strlen(inputFileName)+1)*sizeof(char)); strcpy(inputNameTable[sizeTable], inputFileName); printf("Reading file %s\n", inputNameTable[sizeTable]); if(fi = fopen(inputNameTable[sizeTable], "r")) { tableGraph[sizeTable++] = readMatrixGraph(fi); fclose(fi); } else exitProg(ErrorReading, inputNameTable[sizeTable]); } if(option['h']) { option['h'] = 0; printf("%s\n", HELPMESSAGE); exit(0); } } for(j=i; j<argc; j++) { if(!(sscanf(argv[j], "%s", inputFileName) == 1)) exitProg(ErrorArgument, "wrong file name"); inputNameTable[sizeTable] = (char*) malloc((strlen(inputFileName)+1)*sizeof(char)); strcpy(inputNameTable[sizeTable], inputFileName); printf("Reading file %s\n", inputNameTable[sizeTable]); if(fi = fopen(inputNameTable[sizeTable], "r")) { tableGraph[sizeTable] = readGraph(fi); fclose(fi); } else exitProg(ErrorReading, inputNameTable[sizeTable]); fixEdgeGraph(tableGraph[sizeTable]); printf("%d nodes\n", tableGraph[sizeTable]->sizeGraph); sizeTable++; } if(sizeTable <= 0) exitProg(ErrorArgument, "at least one graph is required."); strcpy(outputPrefix, outputFileName); if((tmp = strrchr(outputPrefix, '.')) != NULL) tmp[0] = '\0'; graph = toMultiGraph(tableGraph, sizeTable); part = getPartition(graph, LouvainType, &alpha); tableGraph[sizeTable] = sumMultiGraph(graph); inputNameTable[sizeTable] = (char*) malloc((strlen("Sum")+1)*sizeof(char)); strcpy(inputNameTable[sizeTable], "Sum"); sizeTable++; tableGraph[sizeTable] = unionMultiGraph(graph); inputNameTable[sizeTable] = (char*) malloc((strlen("Union")+1)*sizeof(char)); strcpy(inputNameTable[sizeTable], "Union"); sizeTable++; tableGraph[sizeTable] = interMultiGraph(graph); inputNameTable[sizeTable] = (char*) malloc((strlen("Intersection")+1)*sizeof(char)); strcpy(inputNameTable[sizeTable], "Intersection"); sizeTable++; name = (char**) malloc(sizeTable*sizeof(char*)); for(t=0; t<sizeTable; t++) { char *tmp; if((tmp = strrchr(inputNameTable[t], '.')) != NULL) tmp[0] = '\0'; if((tmp=strrchr(inputNameTable[t], '/')) == NULL) tmp = inputNameTable[t]; else tmp++; name[t] = (char*) malloc((strlen(tmp)+1)*sizeof(char)); strcpy(name[t], tmp); // printf("name[%d]\t%s\n", t, name[t]); } tablePart = (TypePartition*) malloc(sizeTable*sizeof(TypePartition)); if(singleF) { TypeMultiGraph *gtmp; gtmp = (TypeMultiGraph*) malloc(sizeof(TypeMultiGraph)); gtmp->sizeTable = 1; gtmp->edge = (TypeEdgeG***) malloc(sizeof(TypeEdgeG**)); gtmp->present = (int**) malloc(sizeof(int*)); gtmp->present[0] = (int*) malloc(graph->sizeGraph*sizeof(int)); for(i=0; i<graph->sizeGraph; i++) gtmp->present[0][i] = 1; for(t=0; t<sizeTable; t++) { char output[STRING_SIZE], *tmp; fillMultiOne(tableGraph[t], gtmp); sprintf(output, "%s_%s.%s", outputPrefix, name[t], EXT_OUTPUT); printf("Computing %s\n", output); tablePart[t] = getPartition(gtmp, LouvainType, &alpha); if(fo = fopen(output, "w")) { fprintPartitionClustNSee(fo, &(tablePart[t]), gtmp->name); fclose(fo); } else exitProg(ErrorWriting, output); } free((void*)gtmp->present[0]); free((void*)gtmp->present); free((void*)gtmp->edge); free((void*)gtmp); } if(fo = fopen(outputFileName, "w")) { fprintPartitionClustNSee(fo, &part, graph->name); fclose(fo); } else exitProg(ErrorWriting, outputFileName); sprintf(effectifFileName, "%s_effectif.csv", outputPrefix); if(fo = fopen(effectifFileName, "w")) { int **eff, c, t, *cs; eff = getEdgesNumbers(&part, graph); cs = getClassSize(&part); fprintf(fo, "\tSize"); for(t=0; t<graph->sizeTable; t++) fprintf(fo, "\t%s", name[t]); fprintf(fo, "\n"); for(c=0; c<part.sizeAtom; c++) { fprintf(fo, "ClusterID:%d", c+1); fprintf(fo, "\t%d", cs[c]); for(t=0; t<graph->sizeTable; t++) { fprintf(fo, "\t%d", eff[c][t]); } fprintf(fo, "\n"); } fclose(fo); for(c=0; c<part.sizeAtom; c++) free((void*)eff[c]); free((void*)eff); free((void*)cs); } else exitProg(ErrorWriting, effectifFileName); if(singleF) { for(t=sizeTable-3; t<sizeTable; t++) { sprintf(effectifFileName, "%s_%s_effectif.csv", outputPrefix, name[t]); if((fo = fopen(effectifFileName, "w"))) { int **eff, c, t, *cs; eff = getEdgesNumbers(&(tablePart[sizeTable-1]), graph); cs = getClassSize(&(tablePart[sizeTable-1])); fprintf(fo, "\tSize"); for(t=0; t<graph->sizeTable; t++) fprintf(fo, "\t%s", name[t]); fprintf(fo, "\n"); for(c=0; c<tablePart[sizeTable-1].sizeAtom; c++) { fprintf(fo, "ClusterID:%d", c+1); fprintf(fo, "\t%d", cs[c]); for(t=0; t<graph->sizeTable; t++) { fprintf(fo, "\t%d", eff[c][t]); } fprintf(fo, "\n"); } fclose(fo); for(c=0; c<tablePart[sizeTable-1].sizeAtom; c++) free((void*)eff[c]); free((void*)eff); free((void*)cs); } else exitProg(ErrorWriting, effectifFileName); sprintf(effectifFileName, "%s_%s_graph.csv", outputPrefix, name[t]); if((fo = fopen(effectifFileName, "w"))) { fprintGraph(fo, tableGraph[t]); } else exitProg(ErrorWriting, effectifFileName); } } if(singleF) { int tl, tc; char *tmp; sprintf(outputFileNameRand, "%s_Rand.csv", outputPrefix); if(fo = fopen(outputFileNameRand, "w")) { char *tmp; fprintf(fo,"All\t%lf\n", comparePartDiff(correctedRandIndex, &(part), graph->name, &(part), graph->name)); for(tl=0; tl<sizeTable; tl++) { fprintf(fo, "%s\t%lf", name[tl], comparePartDiff(correctedRandIndex, &(part), graph->name, &(tablePart[tl]), tableGraph[tl]->name)); for(tc=0; tc<=tl; tc++) fprintf(fo, "\t%lf", comparePartDiff(correctedRandIndex, &(tablePart[tc]), tableGraph[tc]->name, &(tablePart[tl]), tableGraph[tl]->name)); fprintf(fo, "\n"); } fprintf(fo, "\tAll"); for(tl=0; tl<sizeTable; tl++) { fprintf(fo, "\t%s", name[tl]); } fprintf(fo, "\n"); fclose(fo); } else exitProg(ErrorWriting, outputFileNameRand); } for(t=0; t<sizeTable; t++) { freeGraph(tableGraph[t]); free((void*) name[t]); free((void*) inputNameTable[t]); } free((void*) tableGraph); free((void*) name); free((void*) inputNameTable); exit(0); return 0; }