/* recover path for the given destination recursively */ void recoverPath(int parent[], int des) { if (parent[des] == des) { printf("%d", des); } else { recoverPath(parent, parent[des]); printf("-%d", des); } }
int main() { /* use adjacent matrix to store the undirected graph */ int V; char *adj = NULL; int *parent = NULL; int src, des; /* the vertices to calculate shortest path */ char command[2]; /* read the first character as the command. * until EOF */ while (scanf("%s", command) == 1) { char c = command[0]; switch (c) { case 'V': case 'v': /* start a new graph, need to reset adjacent matrix */ scanf("%d", &V); if (V <= 0) { printf("Error: number of vertices must be positive.\n"); break; } else { /* dynamic create the array for adjacent matrix * and parent array */ if (adj != NULL) { /* free the old one */ free(adj); free(parent); } adj = (char *)malloc(sizeof(char) * V * V); parent = (int *)malloc(sizeof(int) * V); if (adj == NULL || parent == NULL) { printf("Error: could not allocate memory for arrays.\n"); exit(-1); } } break; case 'E': case 'e': /* load edges for the current graph */ memset(adj, 0, V * V); readEdges(V, adj); break; case 's': case 'S': /* display shortest path between vertices */ scanf("%d %d", &src, &des); if (src < 0 || src >= V || des < 0 || des >= V) { printf("Error: either vertex %d or %d is invalid.\n", src, des); break; } memset(parent, -1, sizeof(int) * V); BFS(V, adj, parent, src, des); if (parent[des] == -1) { /* no path found, display an error */ printf("Error: no path is found between %d and %d.\n", src, des); } else { recoverPath(parent, des); printf("\n"); } break; default: printf("Error: Not valid input"); } } if (adj != NULL) { /* free the dynamic array */ free(adj); free(parent); } return 0; }
void Aligner::alignPartGreedy(){ vector<pair<string,string>> multiread; vector<uNumber> path; string read,header,corrected; bool overlapFound(false); while(!readFile.eof()){ readMutex.lock(); { getReads(multiread,10000); } readMutex.unlock(); for(uint i(0);i<multiread.size();++i){ overlapFound=false; header=multiread[i].first; read=multiread[i].second; if(pathOption){ path=alignReadGreedyPath(read,overlapFound,errorsMax,false); }else{ path=alignReadGreedy(read,overlapFound,errorsMax,false); } if(path.size()!=0){ if(correctionMode){ //if(true){ corrected=(recoverPath(path,read.size())); // pathFile<<header<<'\n'; // pathFile<<corrected<<'\n'; header+='\n'+corrected+'\n'; pathMutex.lock(); { fwrite((header).c_str(), sizeof(char), header.size(), pathFilef); } pathMutex.unlock(); }else{ // pathFile<<header<<'\n'; header+='\n'+printPath(path);; pathMutex.lock(); { fwrite((header).c_str(), sizeof(char), header.size(), pathFilef); } pathMutex.unlock(); } }else{ if(false){ noOverlapMutex.lock(); { noOverlapFile<<header<<'\n'<<read<<'\n'; } noOverlapMutex.unlock(); }else{ header+='\n'+read+'\n'; notMappedMutex.lock(); { // notMappedFile<<header<<'\n'<<read<<'\n'; fwrite(header.c_str(), sizeof(char), header.size(), notMappedFilef); // notMappedFile<<readNumber<<'\n'; // cout<<header<<'\n'<<read<<'\n'; } notMappedMutex.unlock(); } } } // if(iter++%10==0){ // cout<<"Read : "<<readNumber<<endl; // cout<<"No Overlap : "<<noOverlapRead<<" Percent : "<<(100*float(noOverlapRead))/readNumber<<endl; // cout<<"Got Overlap : "<<alignedRead+notAligned<<" Percent : "<<(100*float(alignedRead+notAligned))/readNumber<<endl; // cout<<"Overlap and Aligned : "<<alignedRead<<" Percent : "<<(100*float(alignedRead))/(alignedRead+notAligned)<<endl; // cout<<"Overlap but no aligne: "<<notAligned<<" Percent : "<<(100*float(notAligned))/(alignedRead+notAligned)<<endl; // auto end=chrono::system_clock::now();auto waitedFor=end-startChrono; // cout<<"Reads/seconds : "<<readNumber/(chrono::duration_cast<chrono::seconds>(waitedFor).count()+1)<<endl; // // cout<<"Overlap per reads : "<<(overlaps)/(alignedRead+notAligned)<<endl; // cout<<endl; // } } }