boost::is_adjacent()は、グラフ内において2つの頂点が隣り合っているかを判定する関数です。
この関数は
namespace boost { template <class Graph, class Vertex> bool is_adjacent(Graph& g, Vertex a, Vertex b); }
サンプル:
#include <iostream> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/graph_utility.hpp> #include <boost/assign/list_of.hpp> #include <boost/detail/lightweight_test.hpp> typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS> Graph; typedef std::pair<int, int> Edge; enum { A, B, C, D, E, N }; const int vertex_count = N; int main() { const std::vector<Edge> edges = boost::assign::list_of<Edge> (A, B)(B, E) (A, C)(C, E) (A, D)(D, E) ; const Graph g(edges.begin(), edges.end(), vertex_count); BOOST_TEST(boost::is_adjacent(g, A, B)); BOOST_TEST(boost::is_adjacent(g, B, E)); BOOST_TEST(boost::is_adjacent(g, A, C)); BOOST_TEST(boost::is_adjacent(g, C, E)); BOOST_TEST(boost::is_adjacent(g, A, D)); BOOST_TEST(boost::is_adjacent(g, D, E)); BOOST_TEST(!boost::is_adjacent(g, A, E)); BOOST_TEST(!boost::is_adjacent(g, B, C)); BOOST_TEST(!boost::is_adjacent(g, B, D)); BOOST_TEST(!boost::is_adjacent(g, C, D)); return boost::report_errors(); }