1
假设我有一个图形,每个边都包含一个字符。从一个顶点,我想要获得特定字符的特定边界。由于边缘容器可以设置为一个集合或一个哈希集合,我假设有一种方法可以做到这一点,而无需迭代顶点的外边缘。我还假设/希望边缘容器被键入边缘包含的类型。在boost图形库中,我如何获得顶点的特定外边缘而不迭代该顶点的所有外边缘?
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
typedef boost::adjacency_list<setS, vecS, directedS, std::string, char> MyGraph;
typedef boost::graph_traits<MyGraph>::vertex_descriptor Vertex;
typedef boost::graph_traits<MyGraph>::edge_descriptor Edge;
MyGraph g;
//setup
add_vertex(std::string("xxx"), g);
Vertex currentVertex = g.vertex_set()[0];
Vertex endVertex = add_vertex(std::string("yyy"), g);
add_edge(currentVertex, endVertex, 'i', g);
//later...
//Now I want that edge containing the letter 'i'.
//out_edges returns a pair of edge iterators.
std::pair<iterator, iterator> iterators = out_edges(currentVertex, g); // do not want!
Edge iEdge = how_do_I_get_This?(currentVertex, g); // want!
有没有办法做到这一点,或者是通过out-edges迭代唯一的选择?
更新:
我认为这将使我的容器。
std::set<?> edges = g.out_edge_list(currentVertex);
现在我弄不清楚是什么了?模板类型是。
UPDATE2:
这似乎编译,但我需要一个edge_descriptor的,而不是一个edge_property传递给目标。
std::set<boost::detail::stored_edge_property<long unsigned int, char> > edges = fGraph.out_edge_list(currentVertex);
UPDATE3:
想我并不需要一个边描述符。得到我需要这样的:
std::set<boost::detail::stored_edge_property<long unsigned int, char> > edges = fGraph.out_edge_list(currentVertex);
std::_Rb_tree_const_iterator<boost::detail::stored_edge_property<long unsigned int, char> > edge = edges.find(*i);
Vertex target = edge.get_target();
这一切编译和似乎工作,但它是巨大的丑陋。
其实,我想要的是什么:给定一个顶点,找到一个标“我”这个顶点散发出边。所以边缘e = get_specific_out_vertex(顶点,g,'i');.我的更新#3设法做到这一点,但以一种丑陋的方式。我已经将边缘配置为一个集合,所以希望对于每个顶点来说,只能有一个'i'边缘。 – marathon 2014-10-29 16:12:26