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;The output is:
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 --> ACreating the graph of Figure 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;The output is:
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
Parameter | Description | Default |
---|---|---|
Directed | A selector to choose whether the graph is directed or undirected. The options are directedS and undirectedS. | directedS |
VertexProperty | for specifying internal property storage. | no_property |
EdgeProperty | for specifying internal property storage. | no_property |
GraphProperty | for specifying property storage for the graph object. | no_property |
adjacency_matrix(vertices_size_type n, const GraphProperty& p = GraphProperty())Creates a graph object with n vertices and zero edges.
template <typename EdgeIterator> adjacency_matrix(EdgeIterator first, EdgeIterator last, vertices_size_type n, const GraphProperty& p = GraphProperty())Creates a graph object with n vertices with the edges specified in the edge list given by the range [first, last). The value type of the EdgeIterator must be a std::pair, where the type in the pair is an integer type. The integers will correspond to vertices, and they must all fall in the range of [0, n).
template <typename EdgeIterator, typename EdgePropertyIterator> adjacency_matrix(EdgeIterator first, EdgeIterator last, EdgePropertyIterator ep_iter, vertices_size_type n, const GraphProperty& p = GraphProperty())Creates a graph object with n vertices, with the edges specified in the edge list given by the range [first, last). The value type of the EdgeIterator must be a std::pair, where the type in the pair is an integer type. The integers will correspond to vertices, and they must all fall in the range of [0, n). The value_type of the ep_iter should be EdgeProperty.
std::pair<vertex_iterator, vertex_iterator> vertices(const adjacency_matrix& g)Returns an iterator-range providing access to the vertex set of graph g.
std::pair<edge_iterator, edge_iterator> edges(const adjacency_matrix& g);Returns an iterator-range providing access to the edge set of graph g.
std::pair<adjacency_iterator, adjacency_iterator> adjacent_vertices(vertex_descriptor v, const adjacency_matrix& g)Returns an iterator-range providing access to the vertices adjacent to vertex v in graph g.
std::pair<out_edge_iterator, out_edge_iterator> out_edges(vertex_descriptor v, const adjacency_matrix& g)Returns an iterator-range providing access to the out-edges of vertex v in graph g. If the graph is undirected, this iterator-range provides access to all edges incident on vertex v.
vertex_descriptor source(edge_descriptor e, const adjacency_matrix& g)Returns the source vertex of edge e.
vertex_descriptor target(edge_descriptor e, const adjacency_matrix& g)Returns the target vertex of edge e.
degree_size_type out_degree(vertex_descriptor u, const adjacency_matrix& g)Returns the number of edges leaving vertex u.
std::pair<in_edge_iterator, in_edge_iterator> in_edges(vertex_descriptor v, const adjacency_matrix& g)Returns an iterator-range providing access to the in-edges of vertex v in graph g. If the graph is undirected, this iterator-range provides access to all edges incident on vertex v.
degree_size_type in_degree(vertex_descriptor u, const adjacency_matrix& g)Returns the number of edges entering vertex u.
vertices_size_type num_vertices(const adjacency_matrix& g)Returns the number of vertices in the graph g.
edges_size_type num_edges(const adjacency_matrix& g)Returns the number of edges in the graph g.
vertex_descriptor vertex(vertices_size_type n, const adjacency_matrix& g)Returns the nth vertex in the graph's vertex list.
std::pair<edge_descriptor, bool> edge(vertex_descriptor u, vertex_descriptor v, const adjacency_matrix& g)Returns the edge connecting vertex u to vertex v in graph g.
std::pair<edge_descriptor, bool> add_edge(vertex_descriptor u, vertex_descriptor v, adjacency_matrix& g)Adds edge (u,v) to the graph and returns the edge descriptor for the new edge. If the edge is already in the graph then a duplicate will not be added and the bool flag will be false. This operation does not invalidate any of the graph's iterators or descriptors.
std::pair<edge_descriptor, bool> add_edge(vertex_descriptor u, vertex_descriptor v, const EdgeProperty& p, adjacency_matrix& g)Adds edge (u,v) to the graph and attaches p as the value of the edge's internal property storage. Also see the previous add_edge() member function for more details.
void remove_edge(vertex_descriptor u, vertex_descriptor v, adjacency_matrix& g)Removes the edge (u,v) from the graph.
void remove_edge(edge_descriptor e, adjacency_matrix& g)Removes the edge e from the graph. This is equivalent to calling remove_edge(source(e, g), target(e, g), g).
void clear_vertex(vertex_descriptor u, adjacency_matrix& g)Removes all edges to and from vertex u. The vertex still appears in the vertex set of the graph.
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)Returns the property map object for the vertex property specified by Property. The Property must match one of the properties specified in the graph's VertexProperty template argument.
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)This returns the property value for x, which is either a vertex or edge descriptor.
template <typename Property, typename X, typename Value> void put(Property, const adjacency_matrix& g, X x, const Value& value)This sets the property value for x to value. x is either a vertex or edge descriptor. Value must be convertible to 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)Return the property specified by GraphProperty that is attached to the graph object g. The property_value traits class is defined in boost/pending/property.hpp.
template <typename GraphProperty, typename GraphProperty> const typename property_value<GraphProperty, GraphProperty>::type& get_property(const adjacency_matrix& g, GraphProperty)Return the property specified by GraphProperty that is attached to the graph object g. The property_value traits class is defined in boost/pending/property.hpp.