subgraph.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <HTML>
  2. <!--
  3. Copyright (c) Jeremy Siek 2000
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <Head>
  9. <Title>Boost Graph Library: Subgraph</Title>
  10. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  11. ALINK="#ff0000">
  12. <IMG SRC="../../../boost.png"
  13. ALT="C++ Boost" width="277" height="86">
  14. <BR Clear>
  15. <H1><A NAME="sec:subgraph-class"></A>
  16. <pre>
  17. subgraph&lt;Graph&gt;
  18. </pre>
  19. </h1>
  20. <!--The space consumption of the <tt>subgraph</tt> is quite high.
  21. We should change subgraph from representing induced subgraphs to just
  22. normal subgraphs (from talk with Steven North). -->
  23. <p>
  24. The subgraph class provides a mechanism for keeping track of a graph
  25. and its subgraphs. A graph <i>G'</i> is a <i>subgraph</i> of a graph
  26. <i>G</i> if the vertex set of <i>G'</i> is a subset of the vertex set
  27. of <i>G</i> and if the edge set of <i>G'</i> is a subset of the edge
  28. set of <i>G</i>. That is, if <i>G'=(V',E')</i> and <i>G=(V,E)</i>,
  29. then <i>G'</i> is a subgraph of <i>G</i> if <i>V'</i> is a subset of
  30. <i>V</i> and <i>E</i> is a subset of <i>E'</i>. An <i>induced
  31. subgraph</i> is a subgraph formed by specifying a set of vertices
  32. <i>V'</i> and then selecting all of the edges from the original graph
  33. that connect two vertices in <i>V'</i>. So in this case <i>E' = {(u,v)
  34. in E: u,v in V'}</i>. Figure 1 shows a graph <i>G<sub>0</sub></i> and
  35. two subgraphs <i>G<sub>1</sub></i> and <i>G<sub>2</sub></i>. The edge
  36. set for <i>G<sub>1</sub></i> is <i>E<sub>1</sub> = { (E,F), (C,F)
  37. }</i> and the edge set for <i>G<sub>2</sub></i> is <i>E<sub>2</sub> =
  38. { (A,B) }</i>. Edges such as <i>(E,B)</i> and <i>(F,D)</i> that cross
  39. out of a subgraph are not in the edge set of the subgraph.
  40. </p>
  41. <P></P>
  42. <DIV ALIGN="center"><A NAME="fig:subgraph-tree"></A>
  43. <TABLE>
  44. <CAPTION ALIGN="BOTTOM"><STRONG>Figure 1:</STRONG> A graph with nested subgraphs, maintained in a tree structure.</CAPTION>
  45. <TR><TD><IMG SRC="./figs/subgraph.gif"></TD>
  46. <TD><IMG SRC="./figs/subgraph-tree.gif"></TD></TR>
  47. </TABLE>
  48. </DIV><P></P>
  49. <p>The <tt>subgraph</tt> class implements induced subgraphs. The main graph
  50. and its subgraphs are maintained in a tree data structure. The main
  51. graph is the root, and subgraphs are either children of the root or of
  52. other subgraphs. All of the nodes in this tree, including the root
  53. graph, are instances of the <tt>subgraph</tt> class. The
  54. <tt>subgraph</tt> implementation ensures that each node in the tree is
  55. an induced subgraph of its parent. The <tt>subgraph</tt> class
  56. implements the BGL graph interface, so each subgraph object can be
  57. treated as a graph.</p>
  58. <h3>Example</h3>
  59. The full source code for this example is in
  60. <tt>example/subgraph.cpp</tt>. To create a graph and subgraphs, first
  61. create the root graph object. Here we use <tt>adjacency_list</tt> as
  62. the underlying graph implementation. The underlying graph type is
  63. required to have <tt>vertex_index</tt> and <tt>edge_index</tt>
  64. internal properties, so we add an edge index property to the adjacency
  65. list. We do not need to add a vertex index property because that is
  66. built in to the <tt>adjacency_list</tt>. We will be building the graph
  67. and subgraphs in Figure 1, so we will need a total of six vertices.
  68. <pre>
  69. typedef adjacency_list_traits&lt; vecS, vecS, directedS &gt; Traits;
  70. typedef subgraph&lt; adjacency_list&lt; vecS, vecS, directedS,
  71. no_property, property&lt; edge_index_t, int &gt; &gt; &gt; Graph;
  72. const int N = 6;
  73. Graph G0(N);
  74. enum { A, B, C, D, E, F}; // for conveniently referring to vertices in G0
  75. </pre>
  76. Next we create two empty subgraph objects, specifying <tt>G0</tt> as
  77. their parent.
  78. <pre>
  79. Graph& G1 = G0.create_subgraph(), G2 = G0.create_subgraph();
  80. enum { A1, B1, C1 }; // for conveniently referring to vertices in G1
  81. enum { A2, B2 }; // for conveniently referring to vertices in G2
  82. </pre>
  83. We can add vertices from the root graph to the subgraphs using the
  84. <tt>add_vertex</tt> function. Since the graph implementation is
  85. <tt>adjacency_list</tt> with <tt>VertexList=vecS</tt>, we can use the
  86. integers (or in this case enums) in the range <i>[0,6)</i> as vertex
  87. descriptors.
  88. <pre>
  89. add_vertex(C, G1); // global vertex C becomes local A1 for G1
  90. add_vertex(E, G1); // global vertex E becomes local B1 for G1
  91. add_vertex(F, G1); // global vertex F becomes local C1 for G1
  92. add_vertex(A, G2); // global vertex A becomes local A2 for G2
  93. add_vertex(B, G2); // global vertex B becomes local B2 for G2
  94. </pre>
  95. Next we can add edges to the main graph using the usual
  96. <tt>add_edge</tt> function.
  97. <pre>
  98. add_edge(A, B, G0);
  99. add_edge(B, C, G0);
  100. add_edge(B, D, G0);
  101. add_edge(E, B, G0);
  102. add_edge(E, F, G0);
  103. add_edge(F, D, G0);
  104. </pre>
  105. We can also add edges to subgraphs such as <tt>G1</tt> using the
  106. <tt>add_edge</tt> function. Each subgraph has its own vertex and edge
  107. descriptors, which we call <i>local</i> descriptors. We refer to root
  108. graph's vertex and edge descriptors as the <i>global</i>
  109. descriptors. Above, we used global vertex descriptors to add vertices
  110. to the graph. However, most <tt>subgraph</tt> functions work with
  111. local descriptors. So in the following call to <tt>add_edge</tt> we
  112. add the edge <tt>(A1,C1)</tt> (or numerically <tt>(0,2)</tt>) which is
  113. the local version (for subgraph <tt>G1</tt>) of the global edge
  114. <tt>(C,F)</tt> (or numerically <tt>(2,5)</tt>). Adding an edge to a
  115. subgraph causes the edge to also be added to all of its ancestors in
  116. the subgraph tree to ensure that the subgraph property is maintained.
  117. <pre>
  118. add_edge(A1, C1, G1); // (A1,C1) is subgraph G1 local indices
  119. // for the global edge (C,F).
  120. </pre>
  121. <!----------------------------->
  122. <h3>Where Defined</h3>
  123. <tt>boost/graph/subgraph.hpp</tt>
  124. <!----------------------------->
  125. <h3>Template Parameters</h3>
  126. <P>
  127. <TABLE border>
  128. <TR>
  129. <th>Parameter</th><th>Description</th>
  130. </tr>
  131. <tr><td><tt>Graph</tt> </td>
  132. <td> A graph type modeling <a href="VertexMutableGraph.html">VertexMutableGraph</a>
  133. and <a href="EdgeMutableGraph.html">EdgeMutableGraph</a>. Also
  134. the graph must have internal <tt>vertex_index</tt> and
  135. <tt>edge_index</tt> properties. The vertex indices must be maintained
  136. automatically by the graph, whereas the edge indices will be
  137. assigned by the <tt>subgraph</tt> class implementation. </td>
  138. </tr>
  139. </table>
  140. <!----------------------------->
  141. <h3>Model Of</h3>
  142. <tt>subgraph</tt> is a model of <a href="VertexMutableGraph.html">VertexMutableGraph</a>. Also, if
  143. the <tt>Graph</tt> type models <a href="VertexListGraph.html">VertexListGraph</a>,
  144. <a href="EdgeListGraph.html">EdgeListGraph</a> and/or <a href="BidirectionalGraph.html">BidirectionalGraph</a>, then
  145. <tt>subgraph&lt;Graph&gt;</tt> will also models these concepts.
  146. <!----------------------------->
  147. <h3>Associated Types</h3>
  148. If the graph is the root of the subgraph tree, then the vertex and
  149. edge descriptors are both the local descriptors for the root graph,
  150. and they are the global descriptors. If the graph is not the root,
  151. then the descriptors are local descriptors for the subgraph.
  152. The subgraph iterators are the same iterator types as the iterators of
  153. the underlying <tt>Graph</tt> type.
  154. <hr>
  155. <pre>
  156. graph_traits&lt;subgraph&gt;::vertex_descriptor
  157. </pre>
  158. The type for the vertex descriptors.
  159. (Required by <a href="Graph.html">Graph</a>.)
  160. <hr>
  161. <pre>
  162. graph_traits&lt;subgraph&gt;::edge_descriptor
  163. </pre>
  164. The type for the edge descriptors.
  165. (Required by <a href="Graph.html">Graph</a>.)
  166. <hr>
  167. <pre>
  168. graph_traits&lt;subgraph&gt;::vertex_iterator
  169. </pre>
  170. The type for the iterators returned by <tt>vertices</tt>.
  171. (Required by <a href="VertexListGraph.html">VertexListGraph</a>.)
  172. <hr>
  173. <pre>
  174. graph_traits&lt;subgraph&gt;::edge_iterator
  175. </pre>
  176. The type for the iterators returned by <tt>edges</tt>.
  177. (Required by <a href="EdgeListGraph.html">EdgeListGraph</a>.)
  178. <hr>
  179. <pre>
  180. graph_traits&lt;subgraph&gt;::out_edge_iterator
  181. </pre>
  182. The type for the iterators returned by <tt>out_edges</tt>.
  183. (Required by <a href="IncidenceGraph.html">IncidenceGraph</a>.)
  184. <hr>
  185. <pre>
  186. graph_traits&lt;subgraph&gt;::in_edge_iterator
  187. </pre>
  188. The <tt>in_edge_iterator</tt> is the
  189. iterator type returned by the <tt>in_edges</tt> function.
  190. (Required by <a href="BidirectionalGraph.html">BidirectionalGraph</a>.)
  191. <hr>
  192. <pre>
  193. graph_traits&lt;subgraph&gt;::adjacency_iterator
  194. </pre>
  195. The type for the iterators returned by <tt>adjacent_vertices</tt>.
  196. (Required by <a href="AdjacencyGraph.html">AdjacencyGraph</a>.)
  197. <hr>
  198. <pre>
  199. graph_traits&lt;subgraph&gt;::directed_category
  200. </pre>
  201. Provides information about whether the graph is directed
  202. (<tt>directed_tag</tt>) or undirected (<tt>undirected_tag</tt>).
  203. (Required by <a href="Graph.html">Graph</a>.)
  204. <hr>
  205. <pre>
  206. graph_traits&lt;subgraph&gt;::edge_parallel_category
  207. </pre>
  208. This describes whether the graph class allows the insertion of
  209. parallel edges (edges with the same source and target), which
  210. depends on the underlying <tt>Graph</tt> class. The two tags are
  211. <tt>allow_parallel_edge_tag</tt> and
  212. <tt>disallow_parallel_edge_tag</tt>.
  213. (Required by <a href="Graph.html">Graph</a>.)
  214. <hr>
  215. <pre>
  216. graph_traits&lt;subgraph&gt;::vertices_size_type
  217. </pre>
  218. The type used for dealing with the number of vertices in
  219. the graph.
  220. (Required by <a href="VertexListGraph.html">VertexListGraph</a>.)
  221. <hr>
  222. <pre>
  223. graph_traits&lt;subgraph&gt;::edges_size_type
  224. </pre>
  225. The type used for dealing with the number of edges in the graph.
  226. (Required by <a href="EdgeListGraph.html">EdgeListGraph</a>.)
  227. <hr>
  228. <pre>
  229. graph_traits&lt;subgraph&gt;::degree_size_type
  230. </pre>
  231. The type used for dealing with the number of out-edges of a vertex.
  232. (Required by <a href="IncidenceGraph.html">IncidenceGraph</a>.)
  233. <hr>
  234. <pre>
  235. property_map&lt;subgraph, PropertyTag&gt;::type
  236. property_map&lt;subgraph, PropertyTag&gt;::const_type
  237. </pre>
  238. The map type for vertex or edge properties in the graph. The
  239. specific property is specified by the <tt>PropertyTag</tt> template
  240. argument, and must match one of the properties specified in the
  241. <tt>VertexProperty</tt> or <tt>EdgeProperty</tt> for the graph.
  242. (Required by <a href="PropertyGraph.html">PropertyGraph</a>.)
  243. <hr>
  244. <pre>
  245. subgraph::children_iterator
  246. </pre>
  247. The iterator type for accessing the children subgraphs of the graph.
  248. <!----------------------------->
  249. <h3>Member Functions</h3>
  250. <hr>
  251. <pre>
  252. subgraph(vertices_size_type n, const GraphProperty&amp; p = GraphProperty())
  253. </pre>
  254. Creates the root graph object with <tt>n</tt> vertices and zero edges.
  255. <hr>
  256. <pre>
  257. subgraph&lt;Graph&gt;& create_subgraph();
  258. </pre>
  259. Creates an empty subgraph object whose parent is <i>this</i>
  260. graph.
  261. <hr>
  262. <pre>
  263. template &lt;typename VertexIterator&gt;
  264. subgraph&lt;Graph&gt;&amp;
  265. create_subgraph(VertexIterator first, VertexIterator last)
  266. </pre>
  267. Creates a subgraph object with the specified vertex set. The
  268. edges of the subgraph are induced by the vertex set. That is,
  269. every edge in the parent graph (which is <i>this</i> graph) that
  270. connects two vertices in the subgraph will be added to the
  271. subgraph.
  272. <hr>
  273. <pre>
  274. vertex_descriptor local_to_global(vertex_descriptor u_local) const
  275. </pre>
  276. Converts a local vertex descriptor to the corresponding global
  277. vertex descriptor.
  278. <hr>
  279. <pre>
  280. vertex_descriptor global_to_local(vertex_descriptor u_global) const
  281. </pre>
  282. Converts a global vertex descriptor to the corresponding local
  283. vertex descriptor.
  284. <hr>
  285. <pre>
  286. edge_descriptor local_to_global(edge_descriptor e_local) const
  287. </pre>
  288. Converts a local edge descriptor to the corresponding global edge
  289. descriptor.
  290. <hr>
  291. <pre>
  292. edge_descriptor global_to_local(edge_descriptor u_global) const
  293. </pre>
  294. Converts a global edge descriptor to the corresponding local edge
  295. descriptor.
  296. <hr>
  297. <pre>
  298. std::pair&lt;vertex_descriptor, bool&gt; find_vertex(vertex_descriptor u_global) const
  299. </pre>
  300. If vertex <i>u</i> is in this subgraph, the function returns the local
  301. vertex descriptor that corresponds to the global vertex descriptor
  302. <tt>u_global</tt> as the first part of the pair and <tt>true</tt> for
  303. the second part of the pair. If vertex <i>u</i> is not in the subgraph
  304. then this function returns false in the second part of the
  305. pair.
  306. <hr>
  307. <pre>
  308. subgraph& root()
  309. </pre>
  310. Returns the root graph of the subgraph tree.
  311. <hr>
  312. <pre>
  313. bool is_root() const
  314. </pre>
  315. Return <tt>true</tt> if the graph is the root of the subgraph tree,
  316. and returns <tt>false</tt> otherwise.
  317. <hr>
  318. <pre>
  319. subgraph& parent()
  320. </pre>
  321. Returns the parent graph.
  322. <hr>
  323. <pre>
  324. std::pair&lt;children_iterator, children_iterator&gt; children() const
  325. </pre>
  326. Return an iterator pair for accessing the children subgraphs.
  327. <!----------------------------->
  328. <h3>Nonmember Functions</h3>
  329. The functionality of <tt>subgraph</tt> depends on the
  330. <tt>Graph</tt> type. For example, if <tt>Graph</tt> in a
  331. <a href="BidirectionalGraph.html">BidirectionalGraph</a> and supports <tt>in_edges</tt>, then so
  332. does <tt>subgraph</tt>. Here we list all the functions that
  333. <tt>subgraph</tt> could possibly support given a <tt>Graph</tt>
  334. type that is a model of <a href="VertexListGraph.html">VertexListGraph</a>, <a href="EdgeListGraph.html">EdgeListGraph</a> and
  335. <a href="BidirectionalGraph.html">BidirectionalGraph</a>. If the <tt>Graph</tt> type that you use
  336. with <tt>subgraph</tt> does not model these concepts and supports
  337. fewer functions, then the <tt>subgraph</tt> will also support
  338. fewer functions and some of the functions listed below will not be
  339. implemented.
  340. <hr>
  341. <pre>
  342. std::pair&lt;vertex_iterator, vertex_iterator&gt;
  343. vertices(const subgraph&amp; g)
  344. </pre>
  345. Returns an iterator range providing access to the vertex set of subgraph <i>g</i>.
  346. (Required by <a href="VertexListGraph.html">VertexListGraph</a>.)
  347. <hr>
  348. <pre>
  349. std::pair&lt;edge_iterator, edge_iterator&gt;
  350. edges(const subgraph&amp; g)
  351. </pre>
  352. Returns an iterator range providing access to the edge set of subgraph <i>g</i>.
  353. (Required by <a href="EdgeListGraph.html">EdgeListGraph</a>.)
  354. <hr>
  355. <pre>
  356. std::pair&lt;adjacency_iterator, adjacency_iterator&gt;
  357. adjacent_vertices(vertex_descriptor u_local, const subgraph&amp; g)
  358. </pre>
  359. Returns an iterator range providing access to the vertices
  360. adjacent to
  361. vertex <i>u</i> in subgraph <i>g</i>.
  362. (Required by <a href="AdjacencyGraph.html">AdjacencyGraph</a>.)
  363. <hr>
  364. <pre>
  365. std::pair&lt;out_edge_iterator, out_edge_iterator&gt;
  366. out_edges(vertex_descriptor u_local, const subgraph&amp; g)
  367. </pre>
  368. Returns an iterator range providing access to the out-edges of
  369. vertex <i>u</i> in subgraph <i>g</i>. If the graph is undirected, this
  370. iterator range provides access to all edge incident on
  371. vertex <i>u</i>.
  372. (Required by <a href="IncidenceGraph.html">IncidenceGraph</a>.)
  373. <hr>
  374. <pre>
  375. std::pair&lt;in_edge_iterator, in_edge_iterator&gt;
  376. in_edges(vertex_descriptor v_local, const subgraph&amp; g)
  377. </pre>
  378. Returns an iterator range providing access to the in-edges of
  379. vertex
  380. <i>v</i> in subgraph <i>g</i>.
  381. (Required by <a href="BidirectionalGraph.html">BidirectionalGraph</a>.)
  382. <hr>
  383. <pre>
  384. vertex_descriptor
  385. source(edge_descriptor e_local, const subgraph&amp; g)
  386. </pre>
  387. Returns the source vertex of edge <i>e</i> in subgraph <i>g</i>.
  388. (Required by <a href="IncidenceGraph.html">IncidenceGraph</a>.)
  389. <hr>
  390. <pre>
  391. vertex_descriptor
  392. target(edge_descriptor e_local, const subgraph&amp; g)
  393. </pre>
  394. Returns the target vertex of edge <i>e</i> in subgraph <i>g</i>.
  395. (Required by <a href="IncidenceGraph.html">IncidenceGraph</a>.)
  396. <hr>
  397. <pre>
  398. degree_size_type
  399. out_degree(vertex_descriptor u_local, const subgraph&amp; g)
  400. </pre>
  401. Returns the number of edges leaving vertex <i>u</i> in subgraph <i>g</i>.
  402. (Required by <a href="IncidenceGraph.html">IncidenceGraph</a>.)
  403. <hr>
  404. <pre>
  405. degree_size_type in_degree(vertex_descriptor u_local, const subgraph&amp; g)
  406. </pre>
  407. Returns the number of edges entering vertex <i>u</i> in subgraph <i>g</i>.
  408. (Required by <a href="BidirectionalGraph.html">BidirectionalGraph</a>.)
  409. <hr>
  410. <pre>
  411. vertices_size_type num_vertices(const subgraph&amp; g)
  412. </pre>
  413. Returns the number of vertices in the subgraph <i>g</i>.
  414. (Required by <a href="VertexListGraph.html">VertexListGraph</a>.)
  415. <hr>
  416. <pre>
  417. edges_size_type num_edges(const subgraph&amp; g)
  418. </pre>
  419. Returns the number of edges in the subgraph <i>g</i>. (Required by
  420. <a href="EdgeListGraph.html">EdgeListGraph</a>.)
  421. <hr>
  422. <pre>
  423. vertex_descriptor vertex(vertices_size_type n, const subgraph&amp; g)
  424. </pre>
  425. Returns the <i>n</i>th vertex in the subgraph's vertex list.
  426. <hr>
  427. <pre>
  428. std::pair&lt;edge_descriptor, bool&gt;
  429. edge(vertex_descriptor u_local, vertex_descriptor v_local, const subgraph&amp; g)
  430. </pre>
  431. Returns the edge connecting vertex <i>u</i> to vertex <i>v</i> in subgraph <i>g</i>.
  432. (Required by <a href="AdjacencyMatrix.html">AdjacencyMatrix</a>.)
  433. <hr>
  434. <pre>
  435. std::pair&lt;edge_descriptor, bool&gt;
  436. add_edge(vertex_descriptor u_local, vertex_descriptor v_local, subgraph&amp; g)
  437. </pre>
  438. Adds edge <i>(u,v)</i> to the subgraph <i>g</i> and to all of the subgraph's
  439. ancestors in the subgraph tree. This function returns the edge
  440. descriptor for the new edge. If the edge is already in the graph
  441. then a duplicate will not be added and the Boolean flag will be
  442. false.
  443. (Required by <a href="EdgeMutableGraph.html">EdgeMutableGraph</a>.)
  444. <hr>
  445. <pre>
  446. std::pair&lt;edge_descriptor, bool&gt;
  447. add_edge(vertex_descriptor u_local, vertex_descriptor v_local,
  448. const EdgeProperty&amp; p, subgraph&amp; g)
  449. </pre>
  450. Adds edge <i>(u,v)</i> to the graph and attaches <tt>p</tt> as the value
  451. of the edge's internal property storage. Also see the previous
  452. <tt>add_edge</tt> member function for more details.
  453. <hr>
  454. <pre>
  455. void remove_edge(vertex_descriptor u_local, vertex_descriptor v_local,
  456. subgraph&amp; g)
  457. </pre>
  458. Removes the edge <i>(u,v)</i> from the subgraph and from all of the
  459. ancestors of <tt>g</tt> in the subgraph tree.
  460. (Required by <a href="EdgeMutableGraph.html">EdgeMutableGraph</a>.)
  461. <hr>
  462. <pre>
  463. void remove_edge(edge_descriptor e_local, subgraph&amp; g)
  464. </pre>
  465. Removes the edge <tt>e</tt> from the subgraph and from all of the
  466. ancestors of <tt>g</tt> in the subgraph tree.
  467. (Required by <a href="EdgeMutableGraph.html">EdgeMutableGraph</a>.)
  468. <hr>
  469. <pre>
  470. vertex_descriptor
  471. add_vertex(subgraph&amp; g)
  472. </pre>
  473. Adds a vertex to the subgraph and returns the vertex descriptor
  474. for the new vertex. The vertex is also added to all ancestors of
  475. <tt>g</tt> in the subgraph tree to maintain the subgraph property.
  476. (Required by <a href="VertexMutableGraph.html">VertexMutableGraph</a>.)
  477. <hr>
  478. <pre>
  479. vertex_descriptor
  480. add_vertex(vertex_descriptor u_global, subgraph&amp; g)
  481. </pre>
  482. Adds the vertex <i>u</i> from the root graph to the subgraph <tt>g</tt>.
  483. (Required by <a href="VertexMutableGraph.html">VertexMutableGraph</a>.)
  484. <hr>
  485. <pre>
  486. template &lt;class PropertyTag&gt;
  487. property_map&lt;subgraph, PropertyTag&gt;::type
  488. get(PropertyTag, subgraph&amp; g)
  489. template &lt;class PropertyTag&gt;
  490. property_map&lt;subgraph, PropertyTag&gt;::const_type
  491. get(PropertyTag, const subgraph&amp; g)
  492. </pre>
  493. Returns the property map object for the vertex or edge property
  494. specified by <tt>PropertyTag</tt>. The <tt>PropertyTag</tt> must match one
  495. of the properties specified in the graph's <tt>PropertyTag</tt>
  496. template argument. Vertex and edge properties are shared by all
  497. subgraphs, so changes to a property through a local vertex
  498. descriptor for one subgraph will change the property for the
  499. global vertex descriptor, and therefore for all other subgraphs.
  500. However, the key type for a subgraph's property map is a subgraph-local
  501. vertex or edge descriptor.
  502. (Required by <a href="PropertyGraph.html">PropertyGraph</a>.)
  503. <hr>
  504. <pre>
  505. template &lt;class PropertyTag, class Key&gt;
  506. typename property_traits&lt;
  507. typename property_map&lt;subgraph, PropertyTag&gt;::const_type
  508. &gt;::value_type
  509. get(PropertyTag, const subgraph&amp; g, Key k_local)
  510. </pre>
  511. This returns the property value for the key <tt>k_local</tt>, which
  512. is either a local vertex or local edge descriptor. See the above
  513. <tt>get</tt> function
  514. for more information about the property maps.
  515. (Required by <a href="PropertyGraph.html">PropertyGraph</a>.)
  516. <hr>
  517. <pre>
  518. template &lt;class PropertyTag, class Key, class Value&gt;
  519. void
  520. put(PropertyTag, const subgraph&amp; g, Key k_local, const Value& value)
  521. </pre>
  522. This sets the property value for the key <tt>k_local</tt> to
  523. <tt>value</tt>. <tt>k_local</tt> is either a local vertex or local
  524. edge descriptor. <tt>Value</tt> must be convertible to
  525. <tt>typename
  526. property_traits&lt;property_map&lt;adjacency_matrix,
  527. PropertyTag&gt;::type&gt;::value_type</tt>.
  528. (Required by <a href="PropertyGraph.html">PropertyGraph</a>.)
  529. <hr>
  530. <pre>
  531. template &lt;class GraphProperties, class GraphPropertyTag&gt;
  532. typename property_value&lt;GraphProperties, GraphPropertyTag&gt;::type&amp;
  533. get_property(subgraph&amp; g, GraphPropertyTag);
  534. </pre>
  535. Return the property specified by <tt>GraphPropertyTag</tt> that is attached
  536. to the subgraph object <tt>g</tt>. The <tt>property_value</tt> traits class
  537. is defined in <tt>boost/pending/property.hpp</tt>.
  538. <hr>
  539. <pre>
  540. template &lt;class GraphProperties, class GraphPropertyTag&gt;
  541. const typename property_value&lt;GraphProperties, GraphPropertyTag&gt;::type&amp;
  542. get_property(const subgraph&amp; g, GraphPropertyTag);
  543. </pre>
  544. Return the property specified by <tt>GraphPropertyTag</tt> that is
  545. attached to the subgraph object <tt>g</tt>. The <tt>property_value</tt>
  546. traits class is defined in <tt>boost/pending/property.hpp</tt>.
  547. <hr>
  548. <h2>Notes</h2>
  549. The subgraph template requires the underlying graph type to supply vertex and
  550. edge index properties. However, there is no default constructor of any adjacency
  551. list that satisfies both of these requirements. This is especially true of graphs
  552. using <a href="bundles.html">bundled properties</a>, or any adjacency list whose
  553. vertex set is selected by anything other that <tt>vecS</tt>.
  554. However, this problem can be overcome by embedding your bundled (or otherwise)
  555. properties into a <tt>property</tt> that contains an appropriate index. For
  556. example:
  557. <pre>
  558. struct my_vertex { ... };
  559. typedef property&lt;vertex_index_t, std::size_t, my_vertex&gt; vertex_prop;
  560. struct my_edge { ... };
  561. typedef property&lt;edge_index_t, std::size_t, my_edge&gt; edge_prop;
  562. typedef adjacency_list&lt;vecS, listS, undirectedS, vertex_prop, edge_prop&gt; Graph;
  563. typedef subgraph&lt;Graph&gt; Subgraph;
  564. </pre>