int DIJKSTRA1(const graph &G, node s, const edge_array<double> &cost, node_array<double> &dist,edge_array<bool> &b) { node_pq<double> PQ(G); node_pq<double> rPQ(G); node_array<double> rdist(G); node_list perm; int vvc=0; node v; edge e; node t=G.choose_node(); cout<<"\n\nTarget is:"; G.print_node(t); forall_nodes(v,G) { if(v==s) dist[v]=0; else dist[v]=MAXDOUBLE; PQ.insert(v,dist[v]); } while(!PQ.empty()){ node u=PQ.del_min(); if(u==t || perm.member(u)) { cout<<"\n\nTarget reached in forward search"<<endl; cout<<"common node:"; G.print_node(u); break; } perm.append(u); forall_out_edges(e,u) { v=target(e); double c=dist[u] + cost[e]; if(c<dist[v] && b[e]==1) { vvc++; PQ.decrease_p(v,c); dist[v]=c;} } }
int dijk_orig(const graph &G,const edge_array<int>& cost, node s, node t,FILE *fp_p,node_array<int>& number) { node_pq<double> PQ(G); node v; edge e; node_array<double> dist(G); node_list perm; fprintf(fp_p,"\n"); forall_nodes(v,G) { if (v == s) dist[v] = 0; else dist[v] = MAXDOUBLE; PQ.insert(v,dist[v]); } int vertexVisitCnt = 0; while ( !PQ.empty() ) { node u = PQ.del_min(); //G.print_node(u); //Oops: All the vertices are not reachable from given source if( dist[u] == MAXDOUBLE ) { PQ.clear(); break; } vertexVisitCnt++; //Dijk Mod: If target is reached break if( /*u == t ||*/ perm.member(u) ) { break; } //G.print_node(u); G.print_node(u); fprintf(fp_p,"%d\t",number[u]); perm.append(u); forall_out_edges(e,u) { v = target(e); double c = dist[u] + cost[e]; if ( c < dist[v] ) { G.print_node(v); PQ.decrease_p(v,c); dist[v] = c; } } }