void myGraph::findAllPathesBetweenTwoNodes(int source, int target, int totalnode, int totaledge, vector<vector<int>> GRAPH, vector<vector<int>> &pathVector) { //sort the path from smallest length to longest set<vector<int>> pathInfoSet; vector<vector<int>> pathVector_t; vector<int>path; path.push_back(source); queue<vector<int> >q; q.push(path); int count=0; while(!q.empty()) { path=q.front(); q.pop(); int last_nodeof_path=path[path.size()-1]; if(last_nodeof_path==target) { vector<int> pathInfo; pathInfo.push_back(path.size()); pathInfo.push_back(count); pathInfoSet.insert(pathInfo); pathVector_t.push_back(path); //a valid path count++; } for(int i=0;i<GRAPH[last_nodeof_path].size();++i) { if(isadjacency_node_not_present_in_current_path(GRAPH[last_nodeof_path][i],path)) { vector<int>new_path(path.begin(),path.end()); new_path.push_back(GRAPH[last_nodeof_path][i]); q.push(new_path); } } } for(set<vector<int>>::iterator it=pathInfoSet.begin(); it!=pathInfoSet.end(); it++) { vector<int> item = *it; pathVector.push_back(pathVector_t[item[1]]); } }
int RT_BFS_1(Graph &G, int source, std::ofstream & outputfile2, int * cost) { std::vector<int> path; path.push_back(source); std::queue<std::vector<int> >q; q.push(path); std::map <int, unsigned int> flag1, vertex_to_index; std::map <int, bool> flag2; int ii = 0; // for each vertex in the graph for (auto aa : G.graphVector) { // set source to vertex distance to infinity flag1.insert(std::make_pair(aa.ID, 9999)); // set vertex as not visited flag2.insert(std::make_pair(aa.ID, false)); vertex_to_index.insert(std::make_pair(aa.ID, ii++)); } int deepness = 1; // loop until queue is empty while (!q.empty()) { // get a path from the queue path = q.front(); q.pop(); // get the last node in the path int last_nodeof_path = path[path.size() - 1]; // print out the current path to the file //print_path(path, outputfile2); int grp_pos = last_nodeof_path; // loop through all the vertex's edges for (auto it : G.graphVector[grp_pos].edges) { // get the connected vertex id int v_id = std::get<2>(it).get_Vertex_ID(); // get the index of the vertex int index_id = vertex_to_index.find(v_id)->second; // if the vertex distance is greater than the path size if (flag1.find(v_id)->second >= path.size()) { // if the vertex is not in the current path and has not been visited then add to queue if (isadjacency_node_not_present_in_current_path(index_id, path) && flag2.find(v_id)->second == false) { // copy the current path vector into a new one std::vector<int> new_path(path.begin(), path.end()); // add the new vertex new_path.push_back(index_id); // push the new path on the queue q.push(new_path); // set the distance to the vertex to the path size flag1[v_id] = path.size(); cost[v_id] = path.size(); } } } flag2.find(G.graphVector[grp_pos].ID)->second = true; deepness++; } //std::cout << "\nRT_BFS finished Process \n ------------"; return 1; }