Boost logo

Boost Users :

From: TC MA (maottawa3_at_[hidden])
Date: 2004-11-10 16:53:45


This is a newbie question.
Do boost graph library support an vertex with x, y
coordinates?
i.e. typedef std::pair<int, int> Vertex;

I modify the dijkstra-example.cpp sample program in
the libs/graph/example directory but it fails to
compile.

// new dijkstra-example.cpp
int
main(int, char *[])
{
  typedef adjacency_list < listS, vecS, directedS,
    no_property, property < edge_weight_t, int > >
graph_t;
  typedef graph_traits < graph_t >::vertex_descriptor
vertex_descriptor;
  typedef graph_traits < graph_t >::edge_descriptor
edge_descriptor;
  typedef std::pair<int, int> Vertex;
  typedef std::pair<Vertex, Vertex> Edge;

  const int num_nodes = 5;
  enum nodes { A, B, C, D, E };
  char name[] = "ABCDE";
  Vertex a = Vertex(0, 0);
  Vertex b = Vertex(1, 2);
  Vertex c = Vertex(2, 2);

  Edge edge_array[] = { Edge(a, b), Edge(a, c) };
  int weights[] = { 1, 200 };
  int num_arcs = sizeof(edge_array) / sizeof(Edge);

  graph_t g(edge_array, edge_array + num_arcs,
weights, num_nodes);
  property_map<graph_t, edge_weight_t>::type weightmap
= get(edge_weight, g);

  std::vector<vertex_descriptor> 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 << "distances and parents:" << std::endl;
  graph_traits < graph_t >::vertex_iterator vi, vend;
  for (tie(vi, vend) = vertices(g); vi != vend; ++vi)
{
    std::cout << "distance(" << name[*vi] << ") = " <<
d[*vi] << ", ";
    std::cout << "parent(" << name[*vi] << ") = " <<
name[p[*vi]] << std::
      endl;
  }
  std::cout << std::endl;

  return EXIT_SUCCESS;
}

// compile output is:

bjam
...found 518 targets...
...updating 4 targets...
gcc-C++-action
/home/tcma/cpp/boosttcma/libs/graph/dijkstra-example.test/gcc/debug/inlining-on/dijkstra-example.o
/home/tcma/cpp/boost_1_31_0/boost/graph/detail/adjacency_list.hpp:
In constructor `boost::vec_adj_list_impl<Graph,
Config, Base>::vec_adj_list_impl(typename
Config::vertices_size_type, EdgeIterator,
EdgeIterator, EdgePropertyIterator) [with EdgeIterator
= main(int, char**)::Edge*, EdgePropertyIterator =
int*, Graph = boost::adjacency_list<boost::listS,
boost::vecS, boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>, Config =
boost::detail::adj_list_gen<boost::adjacency_list<boost::listS,
boost::vecS, boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>, boost::vecS, boost::listS,
boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>::config, Base =
boost::directed_graph_helper<boost::detail::adj_list_gen<boost::adjacency_list<boost::listS,
boost::vecS, boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>, boost::vecS, boost::listS,
boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>::config>]':
/home/tcma/cpp/boost_1_31_0/boost/graph/adjacency_list.hpp:363:
  instantiated from
`boost::adjacency_list<OutEdgeListS, VertexListS,
DirectedS, VertexProperty, EdgeProperty,
GraphProperty,
EdgeListS>::adjacency_list(EdgeIterator, EdgeIterator,
EdgePropertyIterator, typename
boost::detail::adj_list_gen<boost::adjacency_list<OutEdgeListS,
VertexListS, DirectedS, VertexProperty, EdgeProperty,
GraphProperty, EdgeListS>, VertexListS, OutEdgeListS,
DirectedS, VertexProperty, EdgeProperty,
GraphProperty, EdgeListS>::type::vertices_size_type,
typename
boost::detail::adj_list_gen<boost::adjacency_list<OutEdgeListS,
VertexListS, DirectedS, VertexProperty, EdgeProperty,
GraphProperty, EdgeListS>, VertexListS, OutEdgeListS,
DirectedS, VertexProperty, EdgeProperty,
GraphProperty, EdgeListS>::type::edges_size_type,
const GraphProperty&) [with EdgeIterator = main(int,
char**)::Edge*, EdgePropertyIterator = int*,
OutEdgeListS = boost::listS, VertexListS =
boost::vecS, DirectedS = boost::directedS,
VertexProperty = boost::no_property, EdgeProperty =
boost::property<boost::edge_weight_t, int,
boost::no_property>, GraphProperty =
boost::no_property, EdgeListS = boost::listS]'
/home/tcma/cpp/boosttcma/libs/graph/dijkstra-example.cpp:146:
  instantiated from here
/home/tcma/cpp/boost_1_31_0/boost/graph/detail/adjacency_list.hpp:1904:
error: no matching function for call to
`add_edge(main(int, char**)::Vertex&, main(int,
char**)::Vertex&, int&,
boost::adjacency_list<boost::listS, boost::vecS,
boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>&)'
/home/tcma/cpp/boost_1_31_0/boost/graph/detail/adjacency_list.hpp:599:
note: candidates are: std::pair<typename
boost::directed_graph_helper<Config>::edge_descriptor,
bool> boost::add_edge(typename
Config::vertex_descriptor, typename
Config::vertex_descriptor, const typename
Config::edge_property_type&,
boost::directed_graph_helper<Config>&) [with Config =
boost::detail::adj_list_gen<boost::adjacency_list<boost::listS,
boost::vecS, boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>, boost::vecS, boost::listS,
boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>::config]
/home/tcma/cpp/boost_1_31_0/boost/graph/detail/adjacency_list.hpp:1987:
note: std::pair<typename
Config::edge_descriptor, bool>
boost::add_edge(typename Config::vertex_descriptor,
typename Config::vertex_descriptor, const typename
Config::edge_property_type&,
boost::vec_adj_list_impl<G, C, B>&) [with Graph =
boost::adjacency_list<boost::listS, boost::vecS,
boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>, Config =
boost::detail::adj_list_gen<boost::adjacency_list<boost::listS,
boost::vecS, boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>, boost::vecS, boost::listS,
boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>::config, Base =
boost::directed_graph_helper<boost::detail::adj_list_gen<boost::adjacency_list<boost::listS,
boost::vecS, boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>, boost::vecS, boost::listS,
boost::directedS, boost::no_property,
boost::property<boost::edge_weight_t, int,
boost::no_property>, boost::no_property,
boost::listS>::config>]

    set -e
    g++ -c -Wall -ftemplate-depth-100 -g -O0
-Wno-inline -I"../../../bin/boost/libs/random/test"
-I "/home/tcma/cpp/boost_1_31_0" -o
"/home/tcma/cpp/boosttcma/libs/graph/dijkstra-example.test/gcc/debug/inlining-on/dijkstra-example.o"

"/home/tcma/cpp/boosttcma/libs/graph/dijkstra-example.cpp"
    /usr/bin/objcopy --set-section-flags
.debug_str=contents,debug
"/home/tcma/cpp/boosttcma/libs/graph/dijkstra-example.test/gcc/debug/inlining-on/dijkstra-example.o"

...failed gcc-C++-action
/home/tcma/cpp/boosttcma/libs/graph/dijkstra-example.test/gcc/debug/inlining-on/dijkstra-example.o...
...removing
/home/tcma/cpp/boosttcma/libs/graph/dijkstra-example.test/gcc/debug/inlining-on/dijkstra-example.o
...skipped
</home/tcma/cpp/boosttcma/libs/graph/dijkstra-example.test/gcc/debug/inlining-on>/home/tcma/cpp/boosttcma/libs/graph/dijkstra-example
for lack of
</home/tcma/cpp/boosttcma/libs/graph/dijkstra-example.test/gcc/debug/inlining-on>dijkstra-example.o...
...skipped
</home/tcma/cpp/boosttcma/libs/graph/dijkstra-example.test/gcc/debug/inlining-on>/home/tcma/cpp/boosttcma/libs/graph/dijkstra-example.run
for lack of
</home/tcma/cpp/boosttcma/libs/graph/dijkstra-example.test/gcc/debug/inlining-on>/home/tcma/cpp/boosttcma/libs/graph/dijkstra-example...
...failed updating 1 target...
...skipped 3 targets...

______________________________________________________________________
Post your free ad now! http://personals.yahoo.ca


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net