Hello All,
I am completely new to using BGL and STL. I know the concept of STL
but had never used it before. I have to implement an algorithm for my thesis
and I am trying to use BGL for that. I have made use of Dijkstra's algorithm
that is inbuilt in BGL. Below is the code, which is similar to that in the
reference manual with few changes.
#include <iostream>
#include
#include
#include
#include
using namespace std;
using namespace boost;
/*struct flow_t
{
typedef edge_property_tag kind;
};
struct capacity_t
{
typedef edge_property_tag kind;
};
namespace boost
{
enum edge_flow_t { edge_flow};
enum edge_capacity_t {edge_capacity};
BOOST_INSTALL_PROPERTY(edge,capacity);
} */
int main()
{
typedef property > VertexProperty;
// typedef property Cap;
typedef property EdgeProperty;
typedef adjacency_list < listS, vecS, directedS,
VertexProperty, EdgeProperty > graph_t;
typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor;
// typedef graph_traits < graph_t >::edge_descriptor edge_descriptor;
typedef std::pair Edge;
const int num_nodes = 5;
enum nodes { A, B, C, D, E };
char name[] = "ABCDE";
Edge edge_array[] = { Edge(A, B), Edge(A, C), Edge(B, E), Edge(C, B),
Edge(C, D), Edge(D, E)
// , Edge(D, E), Edge(E, A), Edge(E, B)
};
int weights[] = { 4, 1, 3, 2, 2, 3};
int num_arcs = sizeof(edge_array) / sizeof(Edge);
graph_t g( edge_array, edge_array+num_arcs, weights, num_nodes);
std::vector p(num_vertices(g));
std::vector<int> d(num_vertices(g));
vertex_descriptor s= vertex(A,g);
dijkstra_shortest_paths(g,s,predecessor_map(&p[0]).distance_map(&d[0]));
// std::cout<<"timepass"<::vertex_iterator vi,vend;
for(tie(vi,vend)=vertices(g);vi!=vend;++vi)
{
std::cout<<"distance("<::vertex_iterator i,iend;
// std::cout<<"testing iterators "< p1(num_vertices(g));
std::vector<int> d1(num_vertices(g));
dijkstra_shortest_paths(g,s1,predecessor_map(&p1[0]).distance_map(&d1[0]));
std::cout<<"Distaces and Parents"<::vertex_iterator i1,end1;
for(tie(i1,end1)=vertices(g);i1!=end1;++i1)
{
std::cout<<"distance("<