adjacency_matrix<Directed, VertexProperty, EdgeProperty, GraphProperty, Allocator>
enum { A, B, C, D, E, F, N }; const char* name = "ABCDEF"; typedef boost::adjacency_matrix<boost::directedS> Graph; Graph g(N); add_edge(B, C, g); add_edge(B, F, g); add_edge(C, A, g); add_edge(C, C, g); add_edge(D, E, g); add_edge(E, D, g); add_edge(F, A, g); std::cout << "vertex set: "; boost::print_vertices(g, name); std::cout << std::endl; std::cout << "edge set: "; boost::print_edges(g, name); std::cout << std::endl; std::cout << "out-edges: " << std::endl; boost::print_graph(g, name); std::cout << std::endl;输出为
vertex set: A B C D E F edge set: (B,C) (B,F) (C,A) (C,C) (D,E) (E,D) (F,A) out-edges: A --> B --> C F C --> A C D --> E E --> D F --> A创建 图 2 的图。
enum { A, B, C, D, E, F, N }; const char* name = "ABCDEF"; typedef boost::adjacency_matrix<boost::undirectedS> UGraph; UGraph ug(N); add_edge(B, C, ug); add_edge(B, F, ug); add_edge(C, A, ug); add_edge(D, E, ug); add_edge(F, A, ug); std::cout << "vertex set: "; boost::print_vertices(ug, name); std::cout << std::endl; std::cout << "edge set: "; boost::print_edges(ug, name); std::cout << std::endl; std::cout << "incident edges: " << std::endl; boost::print_graph(ug, name); std::cout << std::endl;输出为
vertex set: A B C D E F edge set: (C,A) (C,B) (E,D) (F,A) (F,B) incident edges: A <--> C F B <--> C F C <--> A B D <--> E E <--> D F <--> A B
参数 | 描述 | 默认值 |
---|---|---|
Directed | 一个选择器,用于选择图是有向的还是无向的。选项有directedS和undirectedS. | directedS |
VertexProperty | 用于指定内部属性存储。 | no_property |
EdgeProperty | 用于指定内部属性存储。 | no_property |
GraphProperty | 用于指定图对象的属性存储。 | no_property |
adjacency_matrix(vertices_size_type n, const GraphProperty& p = GraphProperty())创建一个具有n个顶点和零条边的图对象。
template <typename EdgeIterator> adjacency_matrix(EdgeIterator first, EdgeIterator last, vertices_size_type n, const GraphProperty& p = GraphProperty())创建一个具有n个顶点,边由范围给定的边列表指定[first, last)。的value类型EdgeIterator必须是std::pair,其中pair中的类型是整数类型。整数将对应于顶点,并且它们都必须在[0, n).
template <typename EdgeIterator, typename EdgePropertyIterator> adjacency_matrix(EdgeIterator first, EdgeIterator last, EdgePropertyIterator ep_iter, vertices_size_type n, const GraphProperty& p = GraphProperty())创建一个具有n个顶点,边由范围给定的边列表指定[first, last)。的value类型EdgeIterator必须是std::pair,其中pair中的类型是整数类型。整数将对应于顶点,并且它们都必须在[0, n)。该value_type的ep_iter应该是EdgeProperty.
std::pair<vertex_iterator, vertex_iterator> vertices(const adjacency_matrix& g)返回一个迭代器范围,提供对图的顶点集的访问g.
std::pair<edge_iterator, edge_iterator> edges(const adjacency_matrix& g);返回一个迭代器范围,提供对图的边集的访问g.
std::pair<adjacency_iterator, adjacency_iterator> adjacent_vertices(vertex_descriptor v, const adjacency_matrix& g)返回一个迭代器范围,提供对顶点v在图中的邻接顶点的访问g.
std::pair<out_edge_iterator, out_edge_iterator> out_edges(vertex_descriptor v, const adjacency_matrix& g)返回一个迭代器范围,提供对顶点v在图中的邻接顶点的访问g的出边的访问。如果图是无向图,则此迭代器范围提供对顶点上的所有关联边的访问v.
vertex_descriptor source(edge_descriptor e, const adjacency_matrix& g)返回边e.
vertex_descriptor target(edge_descriptor e, const adjacency_matrix& g)返回边e.
degree_size_type out_degree(vertex_descriptor u, const adjacency_matrix& g)返回离开顶点u.
std::pair<in_edge_iterator, in_edge_iterator> in_edges(vertex_descriptor v, const adjacency_matrix& g)返回一个迭代器范围,提供对顶点v在图中的邻接顶点的访问g的出边的访问。如果图是无向图,则此迭代器范围提供对顶点上的所有关联边的访问v.
degree_size_type in_degree(vertex_descriptor u, const adjacency_matrix& g)返回进入顶点u.
vertices_size_type num_vertices(const adjacency_matrix& g)返回图中的顶点数g.
edges_size_type num_edges(const adjacency_matrix& g)返回图中的边数g.
vertex_descriptor vertex(vertices_size_type n, const adjacency_matrix& g)返回图中顶点列表中的第 n 个顶点。
std::pair<edge_descriptor, bool> edge(vertex_descriptor u, vertex_descriptor v, const adjacency_matrix& g)返回连接顶点u到顶点v在图中的邻接顶点的访问g.
std::pair<edge_descriptor, bool> add_edge(vertex_descriptor u, vertex_descriptor v, adjacency_matrix& g)添加边(u,v)到图中,并返回新边的边描述符。如果边已在图中,则不会添加重复项,并且bool标志将为false。此操作不会使图的任何迭代器或描述符失效。
std::pair<edge_descriptor, bool> add_edge(vertex_descriptor u, vertex_descriptor v, const EdgeProperty& p, adjacency_matrix& g)添加边(u,v)到图中,并将p作为边内部属性存储的值附加。另请参阅之前的add_edge()成员函数以获取更多详细信息。
void remove_edge(vertex_descriptor u, vertex_descriptor v, adjacency_matrix& g)从图中移除边(u,v)。
void remove_edge(edge_descriptor e, adjacency_matrix& g)从图中移除边e从图中移除。这等效于调用remove_edge(source(e, g), target(e, g), g).
void clear_vertex(vertex_descriptor u, adjacency_matrix& g)移除所有到顶点和来自顶点的边u。顶点仍然出现在图的顶点集中。
template <typename Property> property_map<adjacency_matrix, Property>::type get(Property, adjacency_matrix& g) template <typename Property> property_map<adjacency_matrix, Property>::const_type get(Property, const adjacency_matrix& g)返回由Property。该Property指定的顶点属性的属性映射对象,必须与图的VertexProperty模板参数中指定的属性之一匹配。
template <typename Property, typename X> typename property_traits< typename property_map<adjacency_matrix, Property>::const_type >::value_type get(Property, const adjacency_matrix& g, X x)这将返回x的属性值,它既可以是顶点描述符也可以是边描述符。
template <typename Property, typename X, typename Value> void put(Property, const adjacency_matrix& g, X x, const Value& value)这将属性值设置为x到value. x,它既可以是顶点描述符也可以是边描述符。Value必须可转换为typename property_traits<property_map<adjacency_matrix, Property>::type>::value_type.
template <typename GraphProperty, typename GraphProperty> typename property_value<GraphProperty, GraphProperty>::type& get_property(adjacency_matrix& g, GraphProperty)返回由GraphProperty指定的属性,该属性附加到图对象g。该property_value特性类在boost/pending/property.hpp.
template <typename GraphProperty, typename GraphProperty> const typename property_value<GraphProperty, GraphProperty>::type& get_property(const adjacency_matrix& g, GraphProperty)返回由GraphProperty指定的属性,该属性附加到图对象g。该property_value特性类在boost/pending/property.hpp.