あめだまふぁくとりー

Boost.Graphとかできますん

バグ(directed_graph, undirected_graph)

BGLにはadjacency_listをラップしたdirected_graph,undirected_graphクラスがあるんだけどバグを発見(Version 1.48.0です).

#include <boost/graph/directed_graph.hpp>
#include <boost/graph/undirected_graph.hpp>

using namespace boost;

int main()
{
	directed_graph<> dg(5);
	graph_traits<directed_graph<> >::vertex_descriptor
		dv = vertex(3, dg); // エラー

	undirected_graph<> ug(5);
	graph_traits<undirected_graph<> >::vertex_descriptor
		uv = vertex(3, ug); // エラー

	return 0;
}

どちらも関数vertex内でadjacency_listに対応する関数vertexを呼ぶんだけど最初の引数を渡し忘れている.

--- directed_graph.hpp
+++ directed_graph.hpp (bug fixed)
@@ -410,7 +410,7 @@
 typename DIRECTED_GRAPH::vertex_descriptor
 vertex(typename DIRECTED_GRAPH::vertices_size_type n,
        DIRECTED_GRAPH const& g)
-{ return vertex(g.impl()); }
+{ return vertex(n, g.impl()); }
 
 template <DIRECTED_GRAPH_PARAMS>
 std::pair<typename DIRECTED_GRAPH::edge_descriptor, bool>
--- undirected_graph.hpp
+++ undirected_graph.hpp (bug fixed)
@@ -413,7 +413,7 @@
 typename UNDIRECTED_GRAPH::vertex_descriptor
 vertex(typename UNDIRECTED_GRAPH::vertices_size_type n,
        UNDIRECTED_GRAPH const& g)
-{ return vertex(g.impl()); }
+{ return vertex(n, g.impl()); }
 
 template <UNDIRECTED_GRAPH_PARAMS>
 std::pair<typename UNDIRECTED_GRAPH::edge_descriptor, bool>

まぁどちらのクラスもほとんど使わないんですけどね.