相关疑难解决方法(0)

具有VertexList的Dijkstra最短路径=增强图中的ListS

我对Boost图表很新.我试图调整一个例子来找到使用VertexList = vecS的Dijkstra最短路径算法.我将顶点容器更改为ListS.我了解到,如果我们使用listS,我们必须提供自己的vertex_index才能使算法正常工作.

int main(int, char *[])
{
  typedef float Weight;
  typedef boost::property<boost::edge_weight_t, Weight> WeightProperty;
  typedef boost::property<boost::vertex_name_t, std::string> NameProperty;
  typedef boost::property<boost::vertex_index_t, int> IndexProperty;

  typedef boost::adjacency_list < boost::listS, boost::listS, boost::directedS,
  NameProperty, WeightProperty > Graph;

  typedef boost::graph_traits < Graph >::vertex_descriptor Vertex;
  typedef boost::graph_traits <Graph>::vertex_iterator Viter;

  typedef boost::property_map < Graph, boost::vertex_index_t >::type IndexMap;
  typedef boost::property_map < Graph, boost::vertex_name_t >::type NameMap;

  typedef boost::iterator_property_map < Vertex*, IndexMap, Vertex, Vertex& > PredecessorMap;
  typedef boost::iterator_property_map < Weight*, IndexMap, Weight, Weight& > DistanceMap;

  Graph g;


  Vertex v0 = …
Run Code Online (Sandbox Code Playgroud)

c++ boost graph dijkstra

9
推荐指数
2
解决办法
6443
查看次数

BGL dijkstra_shortest_path算法方法不接受我的色彩映射外部属性

我一直试图让升级图lib的dijkstra_shortest_paths编译大约一个星期,现在没有用.我试图使用外部属性映射来模板化方法所需的不同命名参数.我的图形使用顶点和边缘的捆绑属性,我已经能够成功构建图形.我会告诉你我的代码:

// vertex bundled properties
struct BusStop
{
    unsigned int id; //used for creating vertex index property map
    string name;
    Location* pLocation;
};

// edge bundled properties:
struct Route
{
    string routeName;
    BusType type;
    float distance; 
};
Run Code Online (Sandbox Code Playgroud)

这是我的图表声明:

typedef boost::adjacency_list<boost::vecS, boost::setS, boost::undirectedS, BusStop, Route> BusRouteGraph;

这是我尝试在给定图形上执行dijkstra最短路径的方法:

template<typename Graph>
bool shortestPathSearch(Graph& g, typename   
  boost::graph_traits<Graph>::vertex_descriptor src,
  typename boost::graph_traits<Graph>::vertex_descriptor dest)
{
    bool bPathFound = false;
    VertexIndexMap index_map = get(&BusStop::id, g);

    // Initialize index_map
    typedef typename graph_traits<Graph>::vertex_iterator V_Iter;
    V_Iter v_iter, v_iter_end;
    int c = …
Run Code Online (Sandbox Code Playgroud)

c++ boost-graph

4
推荐指数
1
解决办法
1672
查看次数

标签 统计

c++ ×2

boost ×1

boost-graph ×1

dijkstra ×1

graph ×1