我是一名 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);
}
我也阅读了有关属性映射的信息,但找不到解决我的问题的方法。我会比较喜欢捆绑属性 http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/bundles.html超过内部属性。
有没有一种方法可以通过捆绑属性将唯一的 int 类型索引分配给边并通过这些 int 类型值访问边?