File: reverse_graph.html

package info (click to toggle)
boost 1.27.0-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 19,908 kB
  • ctags: 26,546
  • sloc: cpp: 122,225; ansic: 10,956; python: 4,412; sh: 855; yacc: 803; makefile: 257; perl: 165; lex: 90; csh: 6
file content (414 lines) | stat: -rw-r--r-- 11,043 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<HTML>
<!--
  --  (C) Copyright David Abrahams and Jeremy Siek 2000. Permission to copy,
  --  use, modify, sell and distribute this software is granted provided this
  --  copyright notice appears in all copies. This software is provided
  --  "as is" without express or implied warranty, and with no claim as
  --  to its suitability for any purpose.
  -->
<Head>
<Title>Boost Graph Library: Reverse Graph Adaptor</Title>
<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" 
        ALINK="#ff0000"> 
<IMG SRC="../../../c++boost.gif" 
     ALT="C++ Boost" width="277" height="86"> 

<BR Clear>



<H1><A NAME="sec:reverse-graph-adaptor"></A>
</h1>
<pre>
reverse_graph&lt;<a href="./BidirectionalGraph.html">BidirectionalGraph</a>, GraphReference&gt;
</pre>

The <tt>reverse_graph</tt> adaptor flips the in-edges and out-edges of
a <a href="./BidirectionalGraph.html">BidirectionalGraph</a>,
effectively transposing the graph. The construction of the
<tt>reverse_graph</tt> is constant time, providing a highly efficient
way to obtain a transposed-view of a graph.


<H3>Example</H3>

The example from <a
href="../example/reverse-graph-eg.cpp"><tt>examples/reverse-graph-eg.cpp</tt></a>.

<pre>
int
main()
{
  typedef boost::adjacency_list&lt; 
    boost::vecS, boost::vecS, boost::bidirectionalS,
  &gt; Graph;
  
  Graph G(5);
  boost::add_edge(0, 2, G);
  boost::add_edge(1, 1, G);
  boost::add_edge(1, 3, G);
  boost::add_edge(1, 4, G);
  boost::add_edge(2, 1, G);
  boost::add_edge(2, 3, G);
  boost::add_edge(2, 4, G);
  boost::add_edge(3, 1, G);
  boost::add_edge(3, 4, G);
  boost::add_edge(4, 0, G);
  boost::add_edge(4, 1, G);

  std::cout &lt;&lt; &quot;original graph:&quot; &lt;&lt; std::endl;
  boost::print_graph(G, boost::get(boost::vertex_index, G));

  std::cout &lt;&lt; std::endl &lt;&lt; &quot;reversed graph:&quot; &lt;&lt; std::endl;
  boost::print_graph(boost::make_reverse_graph(G), 
                     boost::get(boost::vertex_index, G));


  return 0;
}
</pre>
The output is:
<pre>
original graph:
0 --&gt; 2 
1 --&gt; 1 3 4 
2 --&gt; 1 3 4 
3 --&gt; 1 4 
4 --&gt; 0 1 

reversed graph:
0 --&gt; 4 
1 --&gt; 1 2 3 4 
2 --&gt; 0 
3 --&gt; 1 2 
4 --&gt; 1 2 3 
</pre>

<H3>Template Parameters</H3>

<P>
<TABLE border>
<TR>
<th>Parameter</th><th>Description</th><th>Default</th>
</tr>

<TR><TD><TT>BidirectionalGraph</TT></TD>
<TD>The graph type to be adapted.</TD>
<TD>&nbsp;</TD>
</TR>

<TR><TD><TT>GraphReference</TT></TD>
<TD>This type should be <tt>const&nbsp;BidirectionalGraph&amp;</tt>
if you want to create a const reverse graph, or <tt>BidirectionalGraph&amp;</tt> if you want to create a non-const reverse graph.</TD>
<TD><tt>const&nbsp;BidirectionalGraph&amp;</tt></TD>
</TR>


</table>


<H3>Model of</H3>

<P>
<a href="./BidirectionalGraph.html">BidirectionalGraph</a>
and optionally
<a href="./VertexListGraph.html">VertexListGraph</a>
and <a href="./PropertyGraph.html">PropertyGraph</a>


<H3>Where Defined</H3>

<P>
<a href="../../../boost/graph/reverse_graph.hpp"><TT>boost/graph/reverse_graph.hpp</TT></a>


<H2>Associated Types</H2>

<hr>

<tt>graph_traits&lt;reverse_graph&gt;::vertex_descriptor</tt>
<br><br>
The type for the vertex descriptors associated with the
<TT>reverse_graph</TT>.

<hr>

<tt>graph_traits&lt;reverse_graph&gt;::edge_descriptor</tt>
<br><br>
The type for the edge descriptors associated with the
<TT>reverse_graph</TT>.

<hr>

<tt>graph_traits&lt;reverse_graph&gt;::vertex_iterator</tt>
<br><br>
The type for the iterators returned by <TT>vertices()</TT>.

<hr>

<tt>graph_traits&lt;reverse_graph&gt;::edge_iterator</tt>
<br><br>
The type for the iterators returned by <TT>edges()</TT>.

<hr>


<tt>graph_traits&lt;reverse_graph&gt;::out_edge_iterator</tt>
<br><br>
The type for the iterators returned by <TT>out_edges()</TT>.

<hr>

<tt>graph_traits&lt;reverse_graph&gt;::adjacency_iterator</tt>
<br><br>
The type for the iterators returned by <TT>adjacent_vertices()</TT>.

<hr>

<tt>graph_traits&lt;reverse_graph&gt;::directed_category</tt>
<br><br>
Provides information about whether the graph is
directed (<TT>directed_tag</TT>) or undirected
(<TT>undirected_tag</TT>).

<hr>

<tt>graph_traits&lt;reverse_graph&gt;::edge_parallel_category</tt>
<br><br>
This describes whether the graph class allows the insertion of
parallel edges (edges with the same source and target). The two tags
are <TT>allow_parallel_edge-_tag</TT> and
<TT>disallow_parallel_edge_tag</TT>. The
<TT>setS</TT> and <TT>hash_setS</TT> variants disallow
parallel edges while the others allow parallel edges.

<hr>

<tt>graph_traits&lt;reverse_graph&gt;::vertices_size_type</tt>
<br><br>
The type used for dealing with the number of vertices in the graph.

<hr>

<tt>graph_traits&lt;reverse_graph&gt;::edge_size_type</tt>
<br><br>
The type used for dealing with the number of edges in the graph.

<hr>

<tt>graph_traits&lt;reverse_graph&gt;::degree_size_type</tt>
<br><br>
The type used for dealing with the number of edges incident to a vertex
in the graph.

<hr>

<tt>property_map&lt;reverse_graph, PropertyTag&gt;::type</tt><br>
and<br>
<tt>property_map&lt;reverse_graph, PropertyTag&gt;::const_type</tt>
<br><br>
The property map type for vertex or edge properties in the graph. The
specific property is specified by the <TT>PropertyTag</TT> template argument,
and must match one of the properties specified in the
<TT>VertexProperty</TT> or <TT>EdgeProperty</TT> for the graph.

<hr>


<H2>Member Functions</H2>

<hr>

<pre>
reverse_graph(BidirectoinalGraph&amp;&nbsp;g)
</pre>
Constructor. Create a reversed (transposed) view of the graph <tt>g</tt>.

<hr>

<H2>Non-Member Functions</H2>

<hr>

<pre>
template <class BidirectionalGraph>
reverse_graph<BidirectionalGraph>
make_reverse_graph(BidirectionalGraph&amp; g)
</pre>
Helper function for creating a <tt>reverse_graph</tt>.

<hr>

<pre>
std::pair&lt;vertex_iterator,&nbsp;vertex_iterator&gt;
vertices(const reverse_graph&amp; g)
</pre>
Returns an iterator-range providing access to the vertex set of graph
<tt>g</tt>.

<hr>

<pre>
std::pair&lt;out_edge_iterator,&nbsp;out_edge_iterator&gt;
out_edges(vertex_descriptor&nbsp;v, const&nbsp;reverse_graph&amp;&nbsp;g)
</pre>
Returns an iterator-range providing access to the out-edges of vertex
<tt>v</tt> in graph <tt>g</tt>. These out-edges correspond to the
in-edges of the adapted graph.

<hr>

<pre>
std::pair&lt;in_edge_iterator,&nbsp;in_edge_iterator&gt;
in_edges(vertex_descriptor&nbsp;v, const&nbsp;reverse_graph&amp;&nbsp;g)
</pre>
Returns an iterator-range providing access to the in-edges of vertex
<tt>v</tt> in graph <tt>g</tt>. These in-edges correspond to the
out edges of the adapted graph.

<hr>

<pre>
std::pair&lt;adjacency_iterator,&nbsp;adjacency__iterator&gt;
adjacent_vertices(vertex_descriptor&nbsp;v, const&nbsp;reverse_graph&amp;&nbsp;g)
</pre>
Returns an iterator-range providing access to the adjacent vertices of vertex
<tt>v</tt> in graph <tt>g</tt>.

<hr>

<pre>
vertex_descriptor
source(edge_descriptor&nbsp;e, const&nbsp;reverse_graph&amp;&nbsp;g)
</pre>
Returns the source vertex of edge <tt>e</tt>.

<hr>

<pre>
vertex_descriptor
target(edge_descriptor&nbsp;e, const&nbsp;reverse_graph&amp;&nbsp;g)
</pre>
Returns the target vertex of edge <tt>e</tt>.

<hr>

<pre>
degree_size_type
out_degree(vertex_descriptor&nbsp;u, const&nbsp;reverse_graph&amp;&nbsp;g)
</pre>
Returns the number of edges leaving vertex <tt>u</tt>.

<hr>

<pre>
degree_size_type
in_degree(vertex_descriptor&nbsp;u, const&nbsp;reverse_graph&amp;&nbsp;g)
</pre>
Returns the number of edges entering vertex <tt>u</tt>. This operation
is only available if <TT>bidirectionalS</TT> was specified for
the <TT>Directed</TT> template parameter.

<hr>

<pre>
vertices_size_type
num_vertices(const reverse_graph&amp; g)
</pre>
Returns the number of vertices in the graph <tt>g</tt>.

<hr>

<pre>
vertex_descriptor
vertex(vertices_size_type&nbsp;n, const&nbsp;reverse_graph&amp;&nbsp;g)
</pre>
Returns the nth vertex in the graph's vertex list.

<hr>

<pre>
std::pair&lt;edge_descriptor, bool&gt;
edge(vertex_descriptor&nbsp;u, vertex_descriptor&nbsp;v,
     const&nbsp;reverse_graph&amp;&nbsp;g)
</pre>
Returns the edge connecting vertex <tt>u</tt> to vertex <tt>v</tt> in
graph <tt>g</tt>.

<hr>

<pre>
template &lt;class <a href="./PropertyTag.html">PropertyTag</a>&gt;
property_map&lt;reverse_graph, PropertyTag&gt;::type
get(PropertyTag, reverse_graph&amp; g)

template &lt;class <a href="./PropertyTag.html">PropertyTag</a>&gt;
property_map&lt;reverse_graph, Tag&gt;::const_type
get(PropertyTag, const reverse_graph&amp; g)
</pre>
Returns the property map object for the vertex property specified by
<TT>PropertyTag</TT>. The <TT>PropertyTag</TT> must match one of the
properties specified in the graph's <TT>VertexProperty</TT> template
argument.

<hr>

<pre>
template &lt;class <a href="./PropertyTag.html">PropertyTag</a>, class X&gt;
typename property_traits&lt;property_map&lt;reverse_graph, PropertyTag&gt;::const_type&gt;::value_type
get(PropertyTag, const reverse_graph&amp; g, X x)
</pre>
This returns the property value for <tt>x</tt>, which is either
a vertex or edge descriptor.
<hr>

<pre>
template &lt;class <a href="./PropertyTag.html">PropertyTag</a>, class X, class Value&gt;
void
put(PropertyTag, const reverse_graph&amp; g, X x, const Value&amp; value)
</pre>
This sets the property value for <tt>x</tt> to
<tt>value</tt>. <tt>x</tt> is either a vertex or edge descriptor.
<tt>Value</tt> must be convertible to
<tt>typename property_traits&lt;property_map&lt;reverse_graph, PropertyTag&gt;::type&gt::value_type</tt>

<hr>

<pre>
template &lt;class GraphProperties, class <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>&gt;
typename property_value&lt;GraphProperties, GraphPropertyTag&gt;::type&amp;
get_property(reverse_graph&amp; g, GraphPropertyTag);
</pre>
Return the property specified by <tt>GraphPropertyTag</tt> that is
attached to the graph object <tt>g</tt>. The <tt>property_value</tt>
traits class is defined in <a
href="../../../boost/pending/property.hpp"><tt>boost/pending/property.hpp</tt></a>.

<hr>

<pre>
template &lt;class GraphProperties, class <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>&gt;
const typename property_value&lt;GraphProperties, GraphPropertyTag&gt;::type&amp;
get_property(const reverse_graph&amp; g, GraphPropertyTag);
</pre>
Return the property specified by <tt>GraphPropertyTag</tt> that is
attached to the graph object <tt>g</tt>.  The <tt>property_value</tt>
traits class is defined in <a
href="../../../boost/pending/property.hpp"><tt>boost/pending/property.hpp</tt></a>.

<hr>

<br>
<HR>
<TABLE>
<TR valign=top>
<TD nowrap>Copyright &copy 2000-2001</TD><TD>
<a HREF="../../../people/dave_abrahams.htm">Dave Abrahams</a>
(<A HREF="mailto:david.abrahams@rcn.com">david.abrahams@rcn.com</A>)<br>
<A HREF="../../../people/jeremy_siek.htm">Jeremy Siek</A>,
Indiana University (<A
HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
</TD></TR></TABLE>

</BODY>
</HTML>