I have a Graph Represented With Following Code :
typedef adjacency_list < vecS, vecS, directedS, property < vertex_name_t, idType >, property < edge_weight_t, double > > graph_t;
how to feed My Graph into Dijkstra Algorithm in Boost, I mean how to extract the Properties from My Graph (which is thousands of Vertices and Edges) to Feed Dijkstra Parameters.
The Output of The Algorithm in The Example is the Shortest Path between one node in The Graph, and The rest Nodes, so How I can Get Only The Shortest Path Between My Source and Target Node Only ? should I filter the Output result to build My Shortest Path Vector ?
//===========================================================================
MyAlgorithm::MyAlgorithm(graph_t AnyGraph, Vertex VSource){// Parameters Constructor
MyGraph = AnyGraph;
vector<Vertex> p(num_vertices(AnyGraph));
// for(auto j = p.begin(); j != p.end(); ++j)
// cout <<"P["<< *j<<"] = "<<p[*j]<<endl;
vector<double> d(num_vertices(AnyGraph));
// for(auto j2 = d.begin(); j2 != d.end(); ++(j2))
// cout <<"d ["<< *(j2)<<"] = "<<d[*(j2)]<<endl;
//===========================================================================
//Dijkstra_Algorithm
//===========================================================================
cout<<"Before\t"<<endl;
dijkstra_shortest_paths(AnyGraph, VSource,
predecessor_map(boost::make_iterator_property_map(p.begin(), get(boost::vertex_index, AnyGraph))).
distance_map(boost::make_iterator_property_map(d.begin(), get(boost::vertex_index, AnyGraph))));
cout<<"After\t"<<endl;
//===========================================================================
}// End of Parameters Constructor
First, you can't use Dijkstra without a cost estimate for how close each node is.
That said, this problem is small enough that you can simply do a breadth-first search from the start for the best route to the target.
If you want to make it more efficient, you can do a search from both source and target at the same time, and find where they meet. Guaranteeing optimal is a little tricky, but that makes the search on average much quicker.