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 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<!--
-- Copyright (c) 2005 Trustees of Indiana University
--
-- Distributed under the Boost Software License, Version 1.0.
-- (See accompanying file LICENSE_1_0.txt or copy at
-- http://www.boost.org/LICENSE_1_0.txt)
-->
<head>
<title>Compressed Sparse Row Graph</title>
<STYLE TYPE="text/css">
<!--
.indent
{
padding-left: 50pt;
padding-right: 50pt;
}
-->
</STYLE>
<script language="JavaScript" type="text/JavaScript">
<!--
function address(host, user) {
var atchar = '@';
var thingy = user+atchar+host;
thingy = '<a hre' + 'f=' + "mai" + "lto:" + thingy + '>' + user+atchar+host + '</a>';
document.write(thingy);
}
//-->
</script>
</head>
<body>
<IMG SRC="../../../boost.png"
ALT="C++ Boost" width="277" height="86"></img>
<h1>Compressed Sparse Row Graph</h1>
<p>The class template <code>compressed_sparse_row_graph</code> is
a graph class that uses the compact Compressed Sparse Row (CSR)
format to store directed graphs. While CSR graphs have much less
overhead than many other graph formats (e.g., <a
href="adjacency_list.html"><code>adjacency_list</code></a>), they
do not provide any mutability: one cannot add or remove vertices
or edges from a CSR graph. Use this format in high-performance
applications or for very large graphs that you do not need to
change.</p>
<p>The CSR format stores vertices and edges in separate arrays,
with the indices into these arrays corresponding to the identifier
for the vertex or edge, respectively. The edge array is sorted by
the source of each edge, but contains only the targets for the
edges. The vertex array stores offsets into the edge array,
providing the offset of the first edge outgoing from each
vertex. Iteration over the out-edges for the <i>i</i><sup>th</sup>
vertex in the graph is achieved by
visiting <tt>edge_array[vertex_array[i]]</tt>, <tt>edge_array[vertex_array[i]+1]</tt>,
..., <tt>edge_array[vertex_array[i+1]]</tt>. This format minimizes
memory use to <i>O(n + m)</i>, where <i>n</i> and <i>m</i> are the
number of vertices and edges, respectively. The constants
multiplied by <i>n</i> and <i>m</i> are based on the size of the
integers needed to represent indices into the edge and vertex
arrays, respectively, which can be controlled using
the <a href="#template-parms">template parameters</a>.</p>
<ul>
<li><a href="#synopsis">Synopsis</a></li>
<li><a href="#where">Where Defined</a></li>
<li><a href="#models">Models</a></li>
<li><a href="#template-parms">Template parameters</a></li>
<li><a href="#properties">Properties</a></li>
<li><a href="#member-functions">Member functions</a>
<ul>
<li><a href="#constructors">Constructors</a></li>
<li><a href="#mutators">Mutators</a></li>
<li><a href="#property-access">Property access</a></li>
</ul></li>
<li><a href="#non-members">Non-member functions</a>
<ul>
<li><a href="#vertex-access">Vertex access</a></li>
<li><a href="#edge-access">Edge access</a></li>
<li><a href="#property-map-accessors">Property map accessors</a></li>
<li><a href="#incremental-construction-functions">Incremental construction functions</a></li>
</ul></li>
<li><a href="#example">Example</a></li>
</ul>
<a name="synopsis"></a><h2>Synopsis</h2>
<pre>
namespace boost {
template<typename <a href="#Directed">Directed</a> = directedS, typename <a href="#VertexProperty">VertexProperty</a> = void,
typename <a href="#EdgeProperty">EdgeProperty</a> = void, typename <a href="#GraphProperty">GraphProperty</a> = no_property,
typename <a href="#Vertex">Vertex</a> = std::size_t, typename <a href="#EdgeIndex">EdgeIndex</a> = Vertex>
class compressed_sparse_row_graph
{
public:
<i>// <a href="#constructors">Graph constructors</a></i>
<a href="#default-const">compressed_sparse_row_graph</a>();
template<typename InputIterator>
<a href="#edge-const">compressed_sparse_row_graph</a>(InputIterator edge_begin, InputIterator edge_end,
vertices_size_type numverts,
edges_size_type numedges = 0,
const GraphProperty& prop = GraphProperty());
template<typename InputIterator, typename EdgePropertyIterator>
<a href="#edge-prop-const">compressed_sparse_row_graph</a>(InputIterator edge_begin, InputIterator edge_end,
EdgePropertyIterator ep_iter,
vertices_size_type numverts,
edges_size_type numedges = 0,
const GraphProperty& prop = GraphProperty());
template<typename Graph, typename VertexIndexMap>
<a href="#graph-const">compressed_sparse_row_graph</a>(const Graph& g, const VertexIndexMap& vi,
vertices_size_type numverts,
edges_size_type numedges);
template<typename Graph, typename VertexIndexMap>
compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi);
template<typename Graph>
explicit <a href="#graph-const">compressed_sparse_row_graph</a>(const Graph& g);
<i>// <a href="#mutators">Graph mutators</a></i>
template<typename Graph, typename VertexIndexMap>
void <a href="#assign">assign</a>(const Graph& g, const VertexIndexMap& vi,
vertices_size_type numverts, edges_size_type numedges);
template<typename Graph, typename VertexIndexMap>
void <a href="#assign">assign</a>(const Graph& g, const VertexIndexMap& vi);
template<typename Graph>
void <a href="#assign">assign</a>(const Graph& g);
<i>// <a href="#property-access">Property Access</a></i>
VertexProperty& <a href="#vertex-subscript">operator[]</a>(vertex_descriptor v);
const VertexProperty& <a href="#vertex-subscript">operator[]</a>(vertex_descriptor v) const;
EdgeProperty& <a href="#edge-subscript">operator[]</a>(edge_descriptor v);
const EdgeProperty& <a href="#edge-subscript">operator[]</a>(edge_descriptor v) const;
};
<i>// <a href="IncidenceGraph.html">Incidence Graph requirements</a></i>
vertex_descriptor source(edge_descriptor, const compressed_sparse_row_graph&);
vertex_descriptor target(edge_descriptor, const compressed_sparse_row_graph&);
std::pair<out_edge_iterator, out_edge_iterator>
out_edges(vertex_descriptor, const compressed_sparse_row_graph&);
degree_size_type out_degree(vertex_descriptor v, const compressed_sparse_row_graph&);
<i>// <a href="AdjacencyGraph.html">Adjacency Graph requirements</a></i>
std::pair<adjacency_iterator, adjacency_iterator>
adjacent_vertices(vertex_descriptor, const compressed_sparse_row_graph&);
<i>// <a href="VertexListGraph.html">Vertex List Graph requirements</a></i>
std::pair<vertex_iterator, vertex_iterator> vertices(const compressed_sparse_row_graph&);
vertices_size_type num_vertices(const compressed_sparse_row_graph&);
<i>// <a href="EdgeListGraph.html">Edge List Graph requirements</a></i>
std::pair<edge_iterator, edge_iterator> edges(const compressed_sparse_row_graph&);
edges_size_type num_edges(const compressed_sparse_row_graph&);
<i>// <a href="#vertex-access">Vertex access</a></i>
vertex_descriptor <a href="#vertex">vertex</a>(vertices_size_type i, const compressed_sparse_row_graph&);
<i>// <a href="#edge-access">Edge access</a></i>
std::pair<out_edge_iterator, out_edge_iterator>
<a href="#edge_range">edge_range</a>(vertex_descriptor u, vertex_descriptor v, const compressed_sparse_row_graph&);
std::pair<edge_descriptor, bool>
<a href="#edge">edge</a>(vertex_descriptor u, vertex_descriptor v, const compressed_sparse_row_graph&);
edge_descriptor <a href="#edge_from_index">edge_from_index</a>(edges_size_type i, const compressed_sparse_row_graph&);
<i>// <a href="#property-map-accessors">Property map accessors</a></i>
template<typename <a href="./PropertyTag.html">PropertyTag</a>>
property_map<compressed_sparse_row_graph, PropertyTag>::type
<a href="#get">get</a>(PropertyTag, compressed_sparse_row_graph& g)
template<typename <a href="./PropertyTag.html">PropertyTag</a>>
property_map<compressed_sparse_row_graph, Tag>::const_type
<a href="#get">get</a>(PropertyTag, const compressed_sparse_row_graph& g)
template<typename <a href="./PropertyTag.html">PropertyTag</a>, class X>
typename property_traits<property_map<compressed_sparse_row_graph, PropertyTag>::const_type>::value_type
<a href="#get-x">get</a>(PropertyTag, const compressed_sparse_row_graph& g, X x)
template<typename <a href="./PropertyTag.html">PropertyTag</a>, class X, class Value>
void <a href="#put-x">put</a>(PropertyTag, const compressed_sparse_row_graph& g, X x, const Value& value);
template<typename <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>>
typename graph_property<compressed_sparse_row_graph, GraphPropertyTag>::type&
<a href="#get_property">get_property</a>(compressed_sparse_row_graph& g, GraphPropertyTag);
template<typename <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>>
typename graph_property<compressed_sparse_row_graph, GraphPropertyTag>::type const &
<a href="#get_property">get_property</a>(const compressed_sparse_row_graph& g, GraphPropertyTag);
template<typename <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>>
void <a href="#set_property">set_property</a>(const compressed_sparse_row_graph& g, GraphPropertyTag,
const typename graph_property<compressed_sparse_row_graph, GraphPropertyTag>::type& value);
<i>// <a href="#incremental-construction-functions">Incremental construction functions</a></i>
template<typename Graph>
vertex_descriptor <a href=#add_vertex">add_vertex</a>(compressed_sparse_row_graph& g);
template<typename Graph>
vertex_descriptor <a href=#add_vertices">add_vertices</a>(vertices_size_type count, compressed_sparse_row_graph& g);
template<typename Graph>
edge_descriptor <a href=#add_edge">add_vertices</a>(vertex_descriptor src, vertex_descriptor tgt, compressed_sparse_row_graph& g);
} <i>// end namespace boost</i>
</pre>
<a name="where"></a><h2>Where Defined</h2>
<p><code><<a href="../../../boost/graph/compressed_sparse_row_graph.hpp">boost/graph/compressed_sparse_row_graph.hpp</a>></code></p>
<a name="models"></a><h2>Models</h2>
<p>The <tt>compressed_sparse_row_graph</tt> class template models
(i.e., implements the requirements of) many of the
BGL <a href="graph_concepts.html">graph concepts</a>, allowing it
to be used with most of the BGL algorithms. In particular, it
models the following specific graph concepts:</p>
<ul>
<li><a href="Graph.html">Graph</a></li>
<li><a href="IncidenceGraph.html">IncidenceGraph</a></li>
<li><a href="AdjacencyGraph.html">AdjacencyGraph</a></li>
<li><a href="VertexListGraph.html">VertexListGraph</a></li>
<li><a href="EdgeListGraph.html">EdgeListGraph</a></li>
<li><a href="PropertyGraph.html">PropertyGraph</a></li>
</ul>
<a name="template-parms"></a><h2>Template Parameters</h2>
<p>The <tt>compressed_sparse_row_graph</tt> class has several
template parameters that can customize the layout in memory and
what properties are attached to the graph itself. All
parameters have defaults, so users interested only in the
structure of a graph can use the
type <tt>compressed_sparse_row_graph<></tt> and ignore
the parameters.</p>
<b>Parameters</b>
<br>
<br>
<a name="Directed"></a><code>Directed</code>
<blockquote>
A selector that determines whether the graph will be directed,
bidirectional or undirected. At this time, the CSR graph type
only supports directed graphs, so this value must
be <code>boost::directedS</code>.<br>
<b>Default</b>: <code>boost::directedS</code>
</blockquote>
<a name="VertexProperty"></a><code>VertexProperty</code>
<blockquote>
A class type that will be
attached to each vertex in the graph. If this value
is <code>void</code>, no properties will be attached to
the vertices of the graph.<br>
<b>Default</b>: <code>void</code>
</blockquote>
<a name="EdgeProperty"></a><code>EdgeProperty</code>
<blockquote>
A class type that will be attached to each edge in the graph. If
this value is <code>void</code>, no properties will be
attached to the edges of the graph.<br>
<b>Default</b>: <code>void</code>
</blockquote>
<a name="GraphProperty"></a><code>GraphProperty</code>
<blockquote>
A nested set
of <code>property</code> templates that describe the
properties of the graph itself. If this value
is <code>no_property</code>, no properties will be attached to
the graph.<br>
<b>Default</b>: <code>no_property</code>
</blockquote>
<a name="Vertex"></a><code>Vertex</code>
<blockquote>
An unsigned integral type that will be
used as both the index into the array of vertices and as the
vertex descriptor itself. Larger types permit the CSR graph to
store more vertices; smaller types reduce the storage required
per vertex.<br>
<b>Default</b>: <code>std::size_t</code>
</blockquote>
<a name="EdgeIndex"></a><code>EdgeIndex</code>
<blockquote>
An unsigned integral type that will be used as the index into
the array of edges. As with the <code>Vertex</code> parameter,
larger types permit more edges whereas smaller types reduce
the amount of storage needed per
edge. The <code>EdgeIndex</code> type shall not be smaller
than the <code>Vertex</code> type, but it may be larger. For
instance, <code>Vertex</code> may be a 16-bit integer
(allowing 32,767 vertices in the graph)
whereas <code>EdgeIndex</code> could then be a 32-bit integer
to allow a complete graph to be stored in the CSR format.<br>
<b>Default</b>: <code>Vertex</code>
</blockquote>
<a name="properties"></a><h2>Interior Properties</h2>
<p> The <tt>compressed_sparse_row_graph</tt> allows properties to
be attached to its vertices, edges, or to the graph itself by way
of its <a href="#template-parms">template parameters</a>. These
properties may be accessed via
the <a href="#property-access">member</a>
and <a href="#property-map-accessors">non-member</a> property
access functions, using the <a href="bundles.html">bundled
properties</a> scheme.</p>
<p>The CSR graph provides two kinds of built-in
properties: <tt>vertex_index</tt>, which maps from vertices to
values in <tt>[0, n)</tt> and <tt>edge_index</tt>, which maps
from edges to values in <tt>[0, m)</tt>, where <tt>n</tt>
and <tt>m</tt> are the number of vertices and edges in the graph,
respectively. </p>
<a name="member-functions"></a><h2>Member Functions</h2>
<a name="constructors"></a><h3>Constructors</h3>
<pre><a name="default-const"></a>
compressed_sparse_row_graph();
</pre>
<p class="indent">Constructs a graph with no vertices or edges.</p>
<hr></hr>
<pre><a name="edge-const"></a>
template<typename InputIterator>
compressed_sparse_row_graph(InputIterator edge_begin, InputIterator edge_end,
vertices_size_type numverts,
edges_size_type numedges = 0,
const GraphProperty& prop = GraphProperty());
</pre>
<p class="indent">
Constructs a graph with <code>numverts</code> vertices whose
edges are specified by the iterator range <code>[edge_begin,
edge_end)</code>. The <tt>InputIterator</tt> must be a model of
<a
href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>
whose <code>value_type</code> is an <code>std::pair</code> of
integer values. These integer values are the source and target
vertices for the edges, and must fall within the range <code>[0,
numverts)</code>. The edges in <code>[edge_begin,
edge_end)</code> must be sorted so that all edges originating
from vertex <i>i</i> preceed any edges originating from all
vertices <i>j</i> where <i>j > i</i>.
</p>
<p class="indent">
The value <code>numedges</code>, if provided, tells how many
edges are in the range <code>[edge_begin, edge_end)</code> and
will be used to preallocate data structures to save both memory
and time during construction.
</p>
<p class="indent">
The value <code>prop</code> will be used to initialize the graph
property.
</p>
<hr></hr>
<pre><a name="edge-prop-const"></a>
template<typename InputIterator, typename EdgePropertyIterator>
compressed_sparse_row_graph(InputIterator edge_begin, InputIterator edge_end,
EdgePropertyIterator ep_iter,
vertices_size_type numverts,
edges_size_type numedges = 0,
const GraphProperty& prop = GraphProperty());
</pre>
<p class="indent">
This constructor constructs a graph with <code>numverts</code>
vertices and the edges provided in the iterator range
<code>[edge_begin, edge_end)</code>. Its semantics are identical
to the <a href="#edge-const">edge range constructor</a>, except
that edge properties are also initialized. The type
<tt>EdgePropertyIterator</tt> must be a model of the <a
href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>
concept whose <tt>value_type</tt> is convertible to
<tt>EdgeProperty</tt>. The iterator range <tt>[ep_iter, ep_ter +
m)</tt> will be used to initialize the properties on the edges
of the graph, where <tt>m</tt> is distance from
<tt>edge_begin</tt> to <tt>edge_end</tt>.
</p>
<hr></hr>
<pre><a name="#graph-const"></a>
template<typename Graph, typename VertexIndexMap>
compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi,
vertices_size_type numverts,
edges_size_type numedges);
template<typename Graph, typename VertexIndexMap>
compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi);
template<typename Graph>
explicit compressed_sparse_row_graph(const Graph& g);
</pre>
<p class="indent">
Calls the <a href="#assign"><tt>assign</tt></a> function with
all of the arguments it is given.
</p>
<hr></hr>
<a name="mutators"></a><h3>Mutators</h3>
<pre><a name="assign"></a>
template<typename Graph, typename VertexIndexMap>
void assign(const Graph& g, const VertexIndexMap& vi,
vertices_size_type numverts, edges_size_type numedges);
template<typename Graph, typename VertexIndexMap>
void assign(const Graph& g, const VertexIndexMap& vi);
template<typename Graph>
void assign(const Graph& g);
</pre>
<p class="indent">
Clears the CSR graph and builds a CSR graph in place from the
structure of another graph. The graph type <tt>Graph</tt> must
be a model of <a href="IncidenceGraph.html">IncidenceGraph</a>
and have a <tt>vertex(i, g)</tt> function that retrieves the
<i>i</i><sup>th</sup> vertex in the graph.
<br><b>Parameters</b>
<ul>
<li><tt>g</tt>: The incoming graph.</li>
<li><tt>vi</tt>: A map from vertices to indices. If not
provided, <tt>get(vertex_index, g)</tt> will be used.</li>
<li><tt>numverts</tt>: The number of vertices in the graph
<tt>g</tt>. If not provided, <tt>Graph</tt> must be a model of
<a href="VertexListGraph.html">VertexListGraph</a>.</li>
<li><tt>numedges</tt>: The number of edges in the graph
<tt>g</tt>. If not provided, <tt>Graph</tt> must be a model of
<a href="EdgeListGraph.html">EdgeListGraph</a>.</li>
</ul>
</p>
<hr></hr>
<a name="property-access"></a><h3>Property Access</h3>
<pre><a name="vertex-subscript"></a>
VertexProperty& operator[](vertex_descriptor v);
const VertexProperty& operator[](vertex_descriptor v) const;
</pre>
<p class="indent">
Retrieves the property value associated with vertex
<tt>v</tt>. Only valid when <tt>VertexProperty</tt> is a class
type that is not <tt>no_property</tt>.
</p>
<hr></hr>
<pre><a name="edge-subscript">
EdgeProperty& operator[](edge_descriptor v);
const EdgeProperty& operator[](edge_descriptor v) const;
</pre>
<p class="indent">
Retrieves the property value associated with edge
<tt>v</tt>. Only valid when <tt>EdgeProperty</tt> is a class
type that is not <tt>no_property</tt>.
</p>
<hr></hr>
<a name="non-members"></a><h2>Non-member Functions</h2>
<a name="vertex-access"></a><h3>Vertex access</h3>
<pre><a name="vertex"></a>
vertex_descriptor vertex(vertices_size_type i, const compressed_sparse_row_graph&);
</pre>
<p class="indent">
Retrieves the <i>i</i><sup>th</sup> vertex in the graph in
constant time.
</p>
<hr></hr>
<a name="edge-access"></a><h3>Edge access</h3>
<pre><a name="edge_range"></a>
std::pair<out_edge_iterator, out_edge_iterator>
edge_range(vertex_descriptor u, vertex_descriptor v, const compressed_sparse_row_graph&);
</pre>
<p class="indent">
Returns all edges from <tt>u</tt> to <tt>v</tt>. Requires time
linear in the number of edges outgoing from <tt>u</tt>.
</p>
<hr></hr>
<pre><a name="edge"></a>
std::pair<edge_descriptor, bool>
edge(vertex_descriptor u, vertex_descriptor v, const compressed_sparse_row_graph&);
</pre>
<p class="indent">
If there exists an edge <i>(u, v)</i> in the graph, returns the
descriptor for that edge and <tt>true</tt>; otherwise, the
second value in the pair will be <tt>false</tt>. If multiple
edges exist from <tt>u</tt> to <tt>v</tt>, the first edge will
be returned; use <a href="#edge_range"><tt>edge_range</tt></a>
to retrieve all edges.
</p>
<hr></hr>
<pre><a name="edge_from_index"></a>
edge_descriptor edge_from_index(edges_size_type i, const compressed_sparse_row_graph&);
</pre>
<p class="indent">
Returns the <i>i</i><sup>th</sup> edge in the graph. This
operation requires logarithmic time in the number of vertices.
</p>
<hr></hr>
<h3><a name="property-map-accessors">Property Map Accessors</a></h3>
<pre><a name="get"></a>
template<typename <a href="./PropertyTag.html">PropertyTag</a>>
property_map<compressed_sparse_row_graph, PropertyTag>::type
get(PropertyTag, compressed_sparse_row_graph& g)
template<typename <a href="./PropertyTag.html">PropertyTag</a>>
property_map<compressed_sparse_row_graph, Tag>::const_type
get(PropertyTag, const compressed_sparse_row_graph& g)
</pre>
<p class="indent">
Returns the property map object for the vertex property
specified by <TT>PropertyTag</TT>. The <TT>PropertyTag</TT> must
be a member pointer to access one of the fields in
<tt>VertexProperty</tt> or <tt>EdgeProperty</tt>.
</p>
<hr></hr>
<pre><a name="get-x"></a>
template<typename <a href="./PropertyTag.html">PropertyTag</a>, class X>
typename property_traits<property_map<compressed_sparse_row_graph, PropertyTag>::const_type>::value_type
get(PropertyTag, const compressed_sparse_row_graph& g, X x)
</pre>
<p class="indent">
This returns the property value for <tt>x</tt>, where <tt>x</tt>
is either a vertex or edge descriptor.
</p>
<hr></hr>
<pre><a name="put-x"></a>
template<typename <a href="./PropertyTag.html">PropertyTag</a>, class X, class Value>
void put(PropertyTag, const compressed_sparse_row_graph& g, X x, const Value& value);
</pre>
<p class="indent">
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<property_map<compressed_sparse_row_graph,
PropertyTag>::type>::value_type</tt>
</p>
<hr></hr>
<pre><a name="get_property"></a>
template<typename <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>>
typename graph_property<compressed_sparse_row_graph, GraphPropertyTag>::type&
get_property(compressed_sparse_row_graph& g, GraphPropertyTag);
template<typename <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>>
typename graph_property<compressed_sparse_row_graph, GraphPropertyTag>::type const &
get_property(const compressed_sparse_row_graph& g, GraphPropertyTag);
</pre>
<p class="indent">
Return the property specified by <tt>GraphPropertyTag</tt> that
is attached to the graph object <tt>g</tt>.
</p>
<hr></hr>
<pre><a name="set_property"></a>
template<typename <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>>
void set_property(const compressed_sparse_row_graph& g, GraphPropertyTag,
const typename graph_property<compressed_sparse_row_graph, GraphPropertyTag>::type& value);
</pre>
<p class="indent">
Set the property specified by <tt>GraphPropertyTag</tt> that
is attached to the graph object <tt>g</tt>.
</p>
<hr></hr>
<h3><a name="incremental-construction-functions">Incremental construction functions</a></h3>
<pre><a name="add_vertex"></a>
vertex_descriptor add_vertex(compressed_sparse_row_graph& g)
</pre>
<p class="indent">
Add a new vertex to the end of the graph <tt>g</tt>, and return a
descriptor for that vertex. The new vertex will be greater than any of
the previous vertices in <tt>g</tt>.
</p>
<hr></hr>
<pre><a name="add_vertices"></a>
vertex_descriptor add_vertices(vertices_size_type count, compressed_sparse_row_graph& g)
</pre>
<p class="indent">
Add <tt>count</tt> new vertices to the end of the graph <tt>g</tt>, and
return a descriptor for the smallest new vertex. The new vertices will
be greater than any of the previous vertices in <tt>g</tt>.
</p>
<hr></hr>
<pre><a name="add_edge"></a>
edge_descriptor add_edge(vertex_descriptor src, vertex_descriptor tgt, compressed_sparse_row_graph& g)
</pre>
<p class="indent">
Add a new edge from <tt>src</tt> to <tt>tgt</tt> in the graph <tt>g</tt>,
and return a descriptor for it. There must not be an edge in <tt>g</tt>
whose source vertex is greater than <tt>src</tt>. If the vertex
<tt>src</tt> has out edges before this operation is called, there must be
none whose target is larger than <tt>tgt</tt>.
</p>
<hr></hr>
<a name="example"></a><h2>Example</h2>
<br>[<a
href="../example/csr-example.cpp">libs/graph/example/csr-example.cpp</a>]
<p>We will use the <tt>compressed_sparse_row_graph</tt> graph
class to store a simple Web graph. In this web graph the vertices
represent web pages and the edges represent links from one web
page to another. With each web page we want to associate a URL, so
we initially create a <tt>WebPage</tt> class that stores the
URL. Then we can create our graph type by providing
<tt>WebPage</tt> as a parameter to the
<tt>compressed_sparse_row_graph</tt> class template.</p>
<pre>
class WebPage
{
public:
std::string url;
};
// ...
typedef compressed_sparse_row_graph<directedS, WebPage> WebGraph;
WebGraph g(&the_edges[0], &the_edges[0] + sizeof(the_edges)/sizeof(E), 6);
</pre>
<p>We can then set the properties on the vertices of the graph
using the <a href="bundles.html">bundled properties</a> syntax,
and display the edges for the user.</p>
<pre>
// Set the URLs of each vertex
int index = 0;
BGL_FORALL_VERTICES(v, g, WebGraph)
g[v].url = urls[index++];
// Output each of the links
std::cout << "The web graph:" << std::endl;
BGL_FORALL_EDGES(e, g, WebGraph)
std::cout << " " << g[source(e, g)].url << " -> " << g[target(e, g)].url
<< std::endl;
</pre>
<p>See the <a href="../example/csr-example.cpp">complete example
source</a> for other operations one can perform with a
<tt>compressed_sparse_row_graph</tt>.</p>
<br>
<HR>
<TABLE>
<TR valign=top>
<TD nowrap>Copyright © 2005</TD><TD>
<A HREF="http://www.boost.org/people/doug_gregor.html">Doug Gregor</A>, Indiana University (<script language="Javascript">address("cs.indiana.edu", "dgregor")</script>)<br>
Jeremiah Willcock, Indiana University (<script language="Javascript">address("osl.iu.edu", "jewillco")</script>)<br>
<A HREF=http://www.osl.iu.edu/~lums>Andrew Lumsdaine</A>,
Indiana University (<script language="Javascript">address("osl.iu.edu", "lums")</script>)
</TD></TR></TABLE>
</body>
</html>
|