Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/graph/doc/reverse_graph.html @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 10.9 KB
Line 
1<HTML>
2<!--
3  --  (C) Copyright David Abrahams and Jeremy Siek 2000.
4  --
5  -- Distributed under the Boost Software License, Version 1.0.
6  -- (See accompanying file LICENSE_1_0.txt or copy at
7  -- http://www.boost.org/LICENSE_1_0.txt)
8  -->
9<Head>
10<Title>Boost Graph Library: Reverse Graph Adaptor</Title>
11<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" 
12        ALINK="#ff0000"> 
13<IMG SRC="../../../boost.png" 
14     ALT="C++ Boost" width="277" height="86"> 
15
16<BR Clear>
17
18
19
20<H1><A NAME="sec:reverse-graph-adaptor"></A>
21</h1>
22<pre>
23reverse_graph&lt;<a href="./BidirectionalGraph.html">BidirectionalGraph</a>, GraphReference&gt;
24</pre>
25
26The <tt>reverse_graph</tt> adaptor flips the in-edges and out-edges of
27a <a href="./BidirectionalGraph.html">BidirectionalGraph</a>,
28effectively transposing the graph. The construction of the
29<tt>reverse_graph</tt> is constant time, providing a highly efficient
30way to obtain a transposed-view of a graph.
31
32
33<H3>Example</H3>
34
35The example from <a
36href="../example/reverse-graph-eg.cpp"><tt>examples/reverse-graph-eg.cpp</tt></a>.
37
38<pre>
39int
40main()
41{
42  typedef boost::adjacency_list&lt; 
43    boost::vecS, boost::vecS, boost::bidirectionalS,
44  &gt; Graph;
45 
46  Graph G(5);
47  boost::add_edge(0, 2, G);
48  boost::add_edge(1, 1, G);
49  boost::add_edge(1, 3, G);
50  boost::add_edge(1, 4, G);
51  boost::add_edge(2, 1, G);
52  boost::add_edge(2, 3, G);
53  boost::add_edge(2, 4, G);
54  boost::add_edge(3, 1, G);
55  boost::add_edge(3, 4, G);
56  boost::add_edge(4, 0, G);
57  boost::add_edge(4, 1, G);
58
59  std::cout &lt;&lt; &quot;original graph:&quot; &lt;&lt; std::endl;
60  boost::print_graph(G, boost::get(boost::vertex_index, G));
61
62  std::cout &lt;&lt; std::endl &lt;&lt; &quot;reversed graph:&quot; &lt;&lt; std::endl;
63  boost::print_graph(boost::make_reverse_graph(G),
64                     boost::get(boost::vertex_index, G));
65
66
67  return 0;
68}
69</pre>
70The output is:
71<pre>
72original graph:
730 --&gt; 2
741 --&gt; 1 3 4
752 --&gt; 1 3 4
763 --&gt; 1 4
774 --&gt; 0 1
78
79reversed graph:
800 --&gt; 4
811 --&gt; 1 2 3 4
822 --&gt; 0
833 --&gt; 1 2
844 --&gt; 1 2 3
85</pre>
86
87<H3>Template Parameters</H3>
88
89<P>
90<TABLE border>
91<TR>
92<th>Parameter</th><th>Description</th><th>Default</th>
93</tr>
94
95<TR><TD><TT>BidirectionalGraph</TT></TD>
96<TD>The graph type to be adapted.</TD>
97<TD>&nbsp;</TD>
98</TR>
99
100<TR><TD><TT>GraphReference</TT></TD>
101<TD>This type should be <tt>const&nbsp;BidirectionalGraph&amp;</tt>
102if you want to create a const reverse graph, or <tt>BidirectionalGraph&amp;</tt> if you want to create a non-const reverse graph.</TD>
103<TD><tt>const&nbsp;BidirectionalGraph&amp;</tt></TD>
104</TR>
105
106
107</table>
108
109
110<H3>Model of</H3>
111
112<P>
113<a href="./BidirectionalGraph.html">BidirectionalGraph</a>
114and optionally
115<a href="./VertexListGraph.html">VertexListGraph</a>
116and <a href="./PropertyGraph.html">PropertyGraph</a>
117
118
119<H3>Where Defined</H3>
120
121<P>
122<a href="../../../boost/graph/reverse_graph.hpp"><TT>boost/graph/reverse_graph.hpp</TT></a>
123
124
125<H2>Associated Types</H2>
126
127<hr>
128
129<tt>graph_traits&lt;reverse_graph&gt;::vertex_descriptor</tt>
130<br><br>
131The type for the vertex descriptors associated with the
132<TT>reverse_graph</TT>.
133
134<hr>
135
136<tt>graph_traits&lt;reverse_graph&gt;::edge_descriptor</tt>
137<br><br>
138The type for the edge descriptors associated with the
139<TT>reverse_graph</TT>.
140
141<hr>
142
143<tt>graph_traits&lt;reverse_graph&gt;::vertex_iterator</tt>
144<br><br>
145The type for the iterators returned by <TT>vertices()</TT>.
146
147<hr>
148
149<tt>graph_traits&lt;reverse_graph&gt;::edge_iterator</tt>
150<br><br>
151The type for the iterators returned by <TT>edges()</TT>.
152
153<hr>
154
155
156<tt>graph_traits&lt;reverse_graph&gt;::out_edge_iterator</tt>
157<br><br>
158The type for the iterators returned by <TT>out_edges()</TT>.
159
160<hr>
161
162<tt>graph_traits&lt;reverse_graph&gt;::adjacency_iterator</tt>
163<br><br>
164The type for the iterators returned by <TT>adjacent_vertices()</TT>.
165
166<hr>
167
168<tt>graph_traits&lt;reverse_graph&gt;::directed_category</tt>
169<br><br>
170Provides information about whether the graph is
171directed (<TT>directed_tag</TT>) or undirected
172(<TT>undirected_tag</TT>).
173
174<hr>
175
176<tt>graph_traits&lt;reverse_graph&gt;::edge_parallel_category</tt>
177<br><br>
178This describes whether the graph class allows the insertion of
179parallel edges (edges with the same source and target). The two tags
180are <TT>allow_parallel_edge-_tag</TT> and
181<TT>disallow_parallel_edge_tag</TT>. The
182<TT>setS</TT> and <TT>hash_setS</TT> variants disallow
183parallel edges while the others allow parallel edges.
184
185<hr>
186
187<tt>graph_traits&lt;reverse_graph&gt;::vertices_size_type</tt>
188<br><br>
189The type used for dealing with the number of vertices in the graph.
190
191<hr>
192
193<tt>graph_traits&lt;reverse_graph&gt;::edge_size_type</tt>
194<br><br>
195The type used for dealing with the number of edges in the graph.
196
197<hr>
198
199<tt>graph_traits&lt;reverse_graph&gt;::degree_size_type</tt>
200<br><br>
201The type used for dealing with the number of edges incident to a vertex
202in the graph.
203
204<hr>
205
206<tt>property_map&lt;reverse_graph, PropertyTag&gt;::type</tt><br>
207and<br>
208<tt>property_map&lt;reverse_graph, PropertyTag&gt;::const_type</tt>
209<br><br>
210The property map type for vertex or edge properties in the graph. The
211specific property is specified by the <TT>PropertyTag</TT> template argument,
212and must match one of the properties specified in the
213<TT>VertexProperty</TT> or <TT>EdgeProperty</TT> for the graph.
214
215<hr>
216
217
218<H2>Member Functions</H2>
219
220<hr>
221
222<pre>
223reverse_graph(BidirectionalGraph&amp;&nbsp;g)
224</pre>
225Constructor. Create a reversed (transposed) view of the graph <tt>g</tt>.
226
227<hr>
228
229<H2>Non-Member Functions</H2>
230
231<hr>
232
233<pre>
234template &lt;class BidirectionalGraph&gt;
235reverse_graph&lt;BidirectionalGraph, BidirectionalGraph&amp;&gt;
236make_reverse_graph(BidirectionalGraph&amp; g);
237
238template &lt;class BidirectionalGraph&gt;
239reverse_graph&lt;BidirectionalGraph, const BidirectionalGraph&amp;&gt;
240make_reverse_graph(const BidirectionalGraph&amp; g)
241
242</pre>
243Helper function for creating a <tt>reverse_graph</tt>.
244
245<hr>
246
247<pre>
248std::pair&lt;vertex_iterator,&nbsp;vertex_iterator&gt;
249vertices(const reverse_graph&amp; g)
250</pre>
251Returns an iterator-range providing access to the vertex set of graph
252<tt>g</tt>.
253
254<hr>
255
256<pre>
257std::pair&lt;out_edge_iterator,&nbsp;out_edge_iterator&gt;
258out_edges(vertex_descriptor&nbsp;v, const&nbsp;reverse_graph&amp;&nbsp;g)
259</pre>
260Returns an iterator-range providing access to the out-edges of vertex
261<tt>v</tt> in graph <tt>g</tt>. These out-edges correspond to the
262in-edges of the adapted graph.
263
264<hr>
265
266<pre>
267std::pair&lt;in_edge_iterator,&nbsp;in_edge_iterator&gt;
268in_edges(vertex_descriptor&nbsp;v, const&nbsp;reverse_graph&amp;&nbsp;g)
269</pre>
270Returns an iterator-range providing access to the in-edges of vertex
271<tt>v</tt> in graph <tt>g</tt>. These in-edges correspond to the
272out edges of the adapted graph.
273
274<hr>
275
276<pre>
277std::pair&lt;adjacency_iterator,&nbsp;adjacency__iterator&gt;
278adjacent_vertices(vertex_descriptor&nbsp;v, const&nbsp;reverse_graph&amp;&nbsp;g)
279</pre>
280Returns an iterator-range providing access to the adjacent vertices of vertex
281<tt>v</tt> in graph <tt>g</tt>.
282
283<hr>
284
285<pre>
286vertex_descriptor
287source(edge_descriptor&nbsp;e, const&nbsp;reverse_graph&amp;&nbsp;g)
288</pre>
289Returns the source vertex of edge <tt>e</tt>.
290
291<hr>
292
293<pre>
294vertex_descriptor
295target(edge_descriptor&nbsp;e, const&nbsp;reverse_graph&amp;&nbsp;g)
296</pre>
297Returns the target vertex of edge <tt>e</tt>.
298
299<hr>
300
301<pre>
302degree_size_type
303out_degree(vertex_descriptor&nbsp;u, const&nbsp;reverse_graph&amp;&nbsp;g)
304</pre>
305Returns the number of edges leaving vertex <tt>u</tt>.
306
307<hr>
308
309<pre>
310degree_size_type
311in_degree(vertex_descriptor&nbsp;u, const&nbsp;reverse_graph&amp;&nbsp;g)
312</pre>
313Returns the number of edges entering vertex <tt>u</tt>. This operation
314is only available if <TT>bidirectionalS</TT> was specified for
315the <TT>Directed</TT> template parameter.
316
317<hr>
318
319<pre>
320vertices_size_type
321num_vertices(const reverse_graph&amp; g)
322</pre>
323Returns the number of vertices in the graph <tt>g</tt>.
324
325<hr>
326
327<pre>
328vertex_descriptor
329vertex(vertices_size_type&nbsp;n, const&nbsp;reverse_graph&amp;&nbsp;g)
330</pre>
331Returns the nth vertex in the graph's vertex list.
332
333<hr>
334
335<pre>
336std::pair&lt;edge_descriptor, bool&gt;
337edge(vertex_descriptor&nbsp;u, vertex_descriptor&nbsp;v,
338     const&nbsp;reverse_graph&amp;&nbsp;g)
339</pre>
340Returns the edge connecting vertex <tt>u</tt> to vertex <tt>v</tt> in
341graph <tt>g</tt>.
342
343<hr>
344
345<pre>
346template &lt;class <a href="./PropertyTag.html">PropertyTag</a>&gt;
347property_map&lt;reverse_graph, PropertyTag&gt;::type
348get(PropertyTag, reverse_graph&amp; g)
349
350template &lt;class <a href="./PropertyTag.html">PropertyTag</a>&gt;
351property_map&lt;reverse_graph, Tag&gt;::const_type
352get(PropertyTag, const reverse_graph&amp; g)
353</pre>
354Returns the property map object for the vertex property specified by
355<TT>PropertyTag</TT>. The <TT>PropertyTag</TT> must match one of the
356properties specified in the graph's <TT>VertexProperty</TT> template
357argument.
358
359<hr>
360
361<pre>
362template &lt;class <a href="./PropertyTag.html">PropertyTag</a>, class X&gt;
363typename property_traits&lt;property_map&lt;reverse_graph, PropertyTag&gt;::const_type&gt;::value_type
364get(PropertyTag, const reverse_graph&amp; g, X x)
365</pre>
366This returns the property value for <tt>x</tt>, which is either
367a vertex or edge descriptor.
368<hr>
369
370<pre>
371template &lt;class <a href="./PropertyTag.html">PropertyTag</a>, class X, class Value&gt;
372void
373put(PropertyTag, const reverse_graph&amp; g, X x, const Value&amp; value)
374</pre>
375This sets the property value for <tt>x</tt> to
376<tt>value</tt>. <tt>x</tt> is either a vertex or edge descriptor.
377<tt>Value</tt> must be convertible to
378<tt>typename property_traits&lt;property_map&lt;reverse_graph, PropertyTag&gt;::type&gt::value_type</tt>
379
380<hr>
381
382<pre>
383template &lt;class GraphProperties, class <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>&gt;
384typename property_value&lt;GraphProperties, GraphPropertyTag&gt;::type&amp;
385get_property(reverse_graph&amp; g, GraphPropertyTag);
386</pre>
387Return the property specified by <tt>GraphPropertyTag</tt> that is
388attached to the graph object <tt>g</tt>. The <tt>property_value</tt>
389traits class is defined in <a
390href="../../../boost/pending/property.hpp"><tt>boost/pending/property.hpp</tt></a>.
391
392<hr>
393
394<pre>
395template &lt;class GraphProperties, class <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>&gt;
396const typename property_value&lt;GraphProperties, GraphPropertyTag&gt;::type&amp;
397get_property(const reverse_graph&amp; g, GraphPropertyTag);
398</pre>
399Return the property specified by <tt>GraphPropertyTag</tt> that is
400attached to the graph object <tt>g</tt>.  The <tt>property_value</tt>
401traits class is defined in <a
402href="../../../boost/pending/property.hpp"><tt>boost/pending/property.hpp</tt></a>.
403
404<hr>
405
406<br>
407<HR>
408<TABLE>
409<TR valign=top>
410<TD nowrap>Copyright &copy 2000-2001</TD><TD>
411<a HREF="../../../people/dave_abrahams.htm">Dave Abrahams</a>
412(<A HREF="mailto:david.abrahams@rcn.com">david.abrahams@rcn.com</A>)<br>
413<A HREF="../../../people/jeremy_siek.htm">Jeremy Siek</A>,
414Indiana University (<A
415HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
416</TD></TR></TABLE>
417
418</BODY>
419</HTML> 
Note: See TracBrowser for help on using the repository browser.