2014-10-03 22 views
-1

dijkstra_shortest_paths() 사용법에 어려움을 겪고 있습니다. 형식 정의 내 코드에 사용되는 여기BGL : dijkstra_shortest_paths 사용법

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]) 
); 

그리고 :

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; 

아무도 날 포인트 그것은 문제가 될 수있는 것을 여기에 컴파일 오류 출력의 톤을 제공하는 코드는? 내 눈

+1

실제의 경우, – zoska

+0

모든 것이 컴파일 시간 오류입니다. 템플릿 해상도에 문제가있는 것 같지만 식별 할 수는 없습니다 ... – Dmitry

+0

아무런 답을 얻지 못할 것입니다. 오류 메시지가 표시되지 않았고 Minimal, Complete 및 Verifiable 예제를 만들지 않았습니다. – zoska

답변

0

과 재생 목록 자체에 포함 된 소스없이 도움이 어렵다. :(비누 칠 것 같다,하지만 한 가지 문제는 당신이 정점 인덱스 맵을 제공 할 필요가 있다고 생각합니다.

우선 하지만, std::vector<EdgeProperties_t> d(/*...*/);이 올바르지 않습니다. 거리 맵의 값의 유형은 에지 가중치의 합에 CopyAssignable해야한다.이 경우, float가 작동합니다.

나는 당신의 그래프 형식 정의와 I를 사용하여 BGL의 dijkstra-example.cpp을 수정하려고했다 응했다 :

 
... 
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. 

.. 이것은 BGL이 정점에 대한 정점 인덱스를 얻는 데 문제가 있음을 나타냅니다. 이 문제를 해결하려면 dijkstra_shortest_paths()에 명명 된 매개 변수 인 vertex_index_map을 지정할 수 있습니다.

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])); 

다음과 같은 형식 정의 :

0

내 경우에 발견 된 솔루션은 다음 냈다 코드

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; 

일 당신은 Graph_t 정의에 나열하고 vecS인가를 교환하는 경우 많은 편집 문제에 직면하게 될 것입니다. 이 문제가 무엇 여전히

#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])); 
} 
0

이 밖으로 시도 ... 누군가 도움이 될 희망? 컴파일 오류? 런타임 에러? 잘못된 행동?