C++ Boost图形库:获取边描述符或通过int类型的索引访问边

C++ Boost图形库:获取边描述符或通过int类型的索引访问边,c++,boost,graph,C++,Boost,Graph,我是一个BGL新手,有一个(可能)简单的问题:我有一个有向图,并对边使用捆绑属性,其中一个是int类型的索引。知道唯一索引后,我希望获得该边的相应边描述符,以便对其执行操作。以下示例总结了我的问题: #include <boost/graph/adjacency_list.hpp> struct EdgeProperties { EdgeProperties(): distance(10), time_limit(5) {}; int index; int

我是一个BGL新手,有一个(可能)简单的问题:我有一个有向图,并对边使用捆绑属性,其中一个是int类型的索引。知道唯一索引后,我希望获得该边的相应边描述符,以便对其执行操作。以下示例总结了我的问题:

#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);
}
#包括
结构边属性{
EdgeProperties():距离(10),时限(5){};
整数指数;
整数距离;
整数时间限制;
};
typedef boost::邻接列表图;
int main(){
图形;
边属性边属性1、边属性2、边属性3、边属性4;
//定义边特性
边1.index=0;
边2.index=1;
边3.index=2;
边4.index=3;
//向图形添加边
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);
//从(int)索引获取顶点描述符:
int顶点_指数=2;
boost::graph\u traits::vertex\u描述符v=boost::vertex(顶点索引,图);
//我想从(int)索引属性中获取边描述符:
//以下操作不起作用:
boost::graph\u traits::edge\u描述符e=boost::edge(edge\u prop1.index,graph);
}
我也读过关于房产地图的书,但找不到解决我问题的办法。我更喜欢内部属性。
有没有一种方法可以通过bundle属性将唯一的int-type索引分配给边,并通过这些int-type值访问边?

遗憾的是,我不认为
boost::graph
在这里有直接的帮助

首先,没有基于边属性的字段查找边(或顶点)的机制-BGL保留任何此类映射,并且您拥有的“索引”字段完全用于您的目的

其次,还有
boost::edges
函数,该函数返回图的所有边的迭代器范围。我认为您可以将VEC作为边缘容器类型传递给邻接列表模板,然后查看此范围,但根据要求,迭代器只需要是多个传递输入迭代器,而实现正是这样做的——即使将VEC作为边缘类型,您也不能进行随机访问

因此,似乎实现您想要的唯一方法是保持您自己的
无顺序映射
从索引到边描述符