-1

I'm struggling with dijkstra_shortest_paths() usage. Here is a code snippet which gives tons of compilation error output :

Vertex_t s = *departIter; /* VertexIterator_t departIter */

std::vector<Vertex_t> p( boost::num_vertices( this->m_g ) ); /* Graph_t m_g; */
std::vector<EdgeProperties_t> d( boost::num_vertices( this->m_g ) );

dijkstra_shortest_paths(
    this->m_g, s, predecessor_map(&p[0]).distance_map(&d[0])
);

And here are the typedefs used in my code :

struct EdgeProperties_t {
   EdgeProperties_t( float fWeight ) : m_fWeight( fWeight ) { }
   EdgeProperties_t( ) : m_fWeight( static_cast<float>(0.0) ) { }
   float m_fWeight;
};

struct VertexProperties_t {
   std::string m_sName;
};

typedef adjacency_list<
    vecS, listS, undirectedS, VertexProperties_t, EdgeProperties_t
> Graph_t;

typedef boost::graph_traits<Graph_t>::vertex_descriptor Vertex_t;
typedef boost::graph_traits<Graph_t>::vertex_iterator VertexIterator_t;

Can anybody point me what could be wrong with it? My eyes seem to be soaped :(.

Dmitry
  • 1,912
  • 2
  • 18
  • 29
  • 1
    WHAT is the problem? compile error? runtime error? wrong behaviour? – zoska Oct 03 '14 at 16:39
  • It's all about compile time error as stated. Seems to be a problem with template resolution but I can't identify it... – Dmitry Oct 04 '14 at 19:05
  • You won't get any answer. You didn't show error message and you didn't create a Minimal, Complete, and Verifiable example. – zoska Oct 06 '14 at 08:50

3 Answers3

0

It is difficult to help without a self-contained source listing to play with, but I think one problem is that you need to supply a vertex index map.

First, though, std::vector<EdgeProperties_t> d(/*...*/); is not correct. The types of values in the distance map should be CopyAssignable to sums of edge weights. In this case, float will work.

I was trying to modify BGL's dijkstra-example.cpp using your graph typedefs and I ran into:

...
In file included from dijkstra-example.cpp:7:
/usr/local/include/boost/graph/dijkstra_shortest_paths.hpp:613:8: error: no
      matching function for call to 'choose_const_pmap'
       choose_const_pmap(get_param(params, vertex_index), g, vertex_index),
       ^~~~~~~~~~~~~~~~~
dijkstra-example.cpp:57:3: note: in instantiation of function template
      specialization
      'boost::dijkstra_shortest_paths,
      boost::adj_list_edge_property_map,
      boost::edge_weight_t, boost::no_property>' requested here
  dijkstra_shortest_paths(g, s,
  ^
/usr/local/include/boost/graph/named_function_params.hpp:305:3: note: candidate
      template ignored: substitution failure [with Param =
      boost::param_not_found, Graph = boost::adjacency_list, PropertyTag = boost::vertex_index_t]
  choose_const_pmap(const Param& p, const Graph& g, PropertyTag tag)
  ^
3 errors generated.

.. which indicates that BGL is having trouble getting the vertex index for a vertex. To fix this problem, you could specify a vertex_index_map named parameter to dijkstra_shortest_paths().

Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
0

The solution I found for my case is the following code snipped :

Vertex_t startVertex = *departIter;
std::vector<Vertex_t> p( graphSize );
std::vector<float> d( graphSize );

dijkstra_shortest_paths(this->m_g, startVertex, predecessor_map(&p[0]).distance_map(&d[0]));

and the following typedefs :

typedef adjacency_list< listS,
                        vecS,
                        undirectedS,
                        property < vertex_name_t, std::string >,
                        property < edge_weight_t, float > > Graph_t;
typedef boost::graph_traits<Graph_t>::vertex_descriptor Vertex_t;

A thing that if you interchange listS and vecS in the Graph_t definition you'll face with a lot of compilation issues. Hope it would help someone...

Dmitry
  • 1,912
  • 2
  • 18
  • 29
0

Try out this, if it's still actual

#include <string>
#include <vector>
#include <boost/config.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/filtered_graph.hpp>

//using namespace boost;

struct EdgeProperties_t {
   EdgeProperties_t( float fWeight ) : m_fWeight( fWeight ) { }
   EdgeProperties_t( ) : m_fWeight( static_cast<float>(0.0) ) { }
   float m_fWeight;
};
struct VertexProperties_t {
   std::string m_sName;
};

typedef boost::adjacency_list<boost::vecS, boost::listS, boost::undirectedS, VertexProperties_t, EdgeProperties_t> Graph_t;
typedef boost::graph_traits<Graph_t>::vertex_descriptor Vertex_t;
typedef boost::graph_traits<Graph_t>::vertex_iterator VertexIterator_t;

int main(int argc, char *argv[])
{
    Graph_t m_g;
    //here you should fill your graph....

    VertexIterator_t departIter = vertices(m_g).first; //iterator should point to first fertex in you graph
    Vertex_t s = *departIter;

    std::vector<Vertex_t> p( boost::num_vertices(m_g));
    std::vector<float> d( boost::num_vertices(m_g)); //here you should use type of a field, not a structure itself

    boost::dijkstra_shortest_paths(m_g, s, boost::weight_map(get(&VertexProperties_t::m_sName, m_g))
                                   .predecessor_map(&p[0])
                                   .distance_map(&d[0]));
}
Artem Zaytsev
  • 1,621
  • 20
  • 19