【发布时间】:2016-05-20 01:17:07
【问题描述】:
我是一个 BGL 新手,有一个(可能)简单的问题:我有一个有向图并使用捆绑属性作为边,其中一个是 int 类型的索引。知道唯一索引后,我想获取该边缘的相应 edge_descriptor 以便对其执行操作。下面的例子总结了我的问题:
#include <boost/graph/adjacency_list.hpp>
struct EdgeProperties {
EdgeProperties(): distance(10), time_limit(5) {};
int index;
int distance;
int time_limit;
};
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, EdgeProperties> Graph;
int main() {
Graph graph;
EdgeProperties edge_prop1, edge_prop2, edge_prop3, edge_prop4;
// Define edge properties
edge_prop1.index = 0;
edge_prop2.index = 1;
edge_prop3.index = 2;
edge_prop4.index = 3;
// Add edges to graph
boost::add_edge(0, 1, edge_prop1, graph);
boost::add_edge(0, 2, edge_prop2, graph);
boost::add_edge(1, 3, edge_prop3, graph);
boost::add_edge(2, 3, edge_prop4, graph);
// Get vertex_descriptor from an (int) index:
int vertex_index = 2;
boost::graph_traits<Graph>::vertex_descriptor v = boost::vertex(vertex_index, graph);
// I would like to get an edge_descriptor from an (int) index property:
// The following DOES NOT work:
boost::graph_traits<Graph>::edge_descriptor e = boost::edge(edge_prop1.index, graph);
}
我也阅读了有关属性映射的信息,但找不到我的问题的解决方案。我更喜欢bundled properties 而不是内部属性。 有没有办法通过捆绑属性将唯一的 int 类型索引分配给边缘并通过这些 int 类型值访问边缘?
【问题讨论】: