0

I have been loosely following this example, this one, and this stack overflow post to try to apply Dijkstra's algorithm to find the cost of the shortest path between two nodes.

If I try to follow the first example, I get an error with the typedef statement for NameMap. This error is cryptic, verbose, and I don't quite know what to do with it.

If I try to follow the second example (copy-pasted from the Boost documentation!!) it does not compile. The error is even more cryptic and verbose.

The third one (the stack overflow post) relies on the same typedef as the first one.

Is this user error? It probably is, but how should I interpret an error message that spawns from the library code?

Update 1

I am using g++ (Debian 4.8.2-21) 4.8.2 from debian testing.

Update 2

Here is a condensed version of the source code that doesn't work. There are two lines prefaced by "// The following line causes an error" are the ones in question.

Update 3 I have changed

typedef adjacency_list<listS, vecS, directedS, allow_parallel_edge_tag, EdgeWeightProperty> Graph;

typedef adjacency_list<listS, vecS, directedS, no_property            , EdgeWeightProperty> Graph;
Community
  • 1
  • 1
charmoniumQ
  • 5,214
  • 5
  • 33
  • 51
  • Which compiler/platform are you in? just tried your second example with g++ (4.8.2)/linux and it compiled no problems. – jsantander May 23 '14 at 04:49
  • 1
    @jsantander Looks like GCC to me (`__gnu_cxx` in the compiler errors). The examples work fine, the problem is that his code only "loosely follows" the example...a bit too loosely, it seems. – T.C. May 23 '14 at 05:32
  • g++ (Debian 4.8.2-21) 4.8.2 – charmoniumQ May 23 '14 at 12:20

1 Answers1

1

Your first attempt didn't define a property with the vertex_name_t tag (or pass it as a adjacency_list template parameter), so when you try to create a property_map with that tag the compiler emits an error.

Your code:

typedef property<edge_weight_t, Weight> EdgeWeightProperty;
typedef boost::adjacency_list<listS, vecS, directedS, allow_parallel_edge_tag, EdgeWeightProperty> Graph;
                                                  //  ^ What's this?

The example code you cited:

typedef boost::property<boost::edge_weight_t, Weight> WeightProperty;
typedef boost::property<boost::vertex_name_t, std::string> NameProperty;  // <-- not in your code
typedef boost::adjacency_list < boost::listS, boost::vecS, boost::directedS, NameProperty, WeightProperty > Graph;
                                                                         //  ^ Used here

I have no idea why you are passing allow_parallel_edge_tag as a template parameter. If I'm reading the documentation correctly, that struct is designed for parallel_edge_traits specializations when you are using custom container types.

Edit: The second case is actually easy to diagnose once you have the code. Going through the error messages emitted by the compiler, we look for reasons why the compiler didn't select the 3-parameter overload for dijkstra_shortest_paths. A lot of the messages merely tells you that it rejected overloads with about a dozen parameters - as it should!

Now, this error message (emitted by g++ using Coliru) is pertinent, because it tells you why compiler rejected the three-parameter version:

In file included from main.cpp:5:0:
/usr/local/include/boost/graph/dijkstra_shortest_paths.hpp:602:3: note: void boost::
dijkstra_shortest_paths(const VertexListGraph&, typename boost::graph_traits<Graph>::
vertex_descriptor, const boost::bgl_named_params<T, Tag, Base>&) [ /* irrelevant stuff
telling you how it deduced the template parameters here */ ] <near match>
   dijkstra_shortest_paths
   ^
/usr/local/include/boost/graph/dijkstra_shortest_paths.hpp:602:3: note:   no known conversion for
 argument 2 from 'long int [6]' to 'boost::graph_traits<boost::adjacency_list<boost::listS, 
boost::vecS, boost::directedS, boost::no_property, boost::property<boost::edge_weight_t, long int> > 
>::vertex_descriptor {aka long unsigned int}'

You passed s, the array containing source vertices, as the second parameter designating the starting vertex, when you should have passed v0, and the compiler is rightfully complaining that it cannot convert an array of longs to a single vertex.

T.C.
  • 133,968
  • 17
  • 288
  • 421
  • [here](http://pastebin.com/1Qvw1vKt) is a 70-line condensed version of my code. It should compile. Uncomment any line marked with "// The following line causes an error" and it should burst into flames. – charmoniumQ May 23 '14 at 12:50
  • @Sam The first case is the same: you are passing `no_property` as the VertexProperties template parameter, and then attempting to use `vertex_name_t` in `NameMap` (which you do not actually use). I've updated my answer with your second case. – T.C. May 23 '14 at 14:11
  • Thank you. Now it compiles. I will read more about this mysterious `NameProperty` value. – charmoniumQ May 23 '14 at 21:57