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