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 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
|
<HTML>
<!--
-- Copyright (c) Jeremy Siek 2000
--
-- 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>Boost Graph Library: Adjacency List</Title>
<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
ALINK="#ff0000">
<IMG SRC="../../../boost.png"
ALT="C++ Boost" width="277" height="86">
<BR Clear>
<H1><A NAME="sec:adjacency-list-class"></A>
<pre>
adjacency_list<OutEdgeList, VertexList, Directed,
VertexProperties, EdgeProperties,
GraphProperties, EdgeList>
</pre>
</H1>
<P>
The <TT>adjacency_list</TT> class implements a generalized adjacency
list graph structure. The template parameters provide many
configuration options so that you can pick a version of the class that
best meets your needs. An <a
href="graph_theory_review.html#sec:adjacency-list-representation">adjacency-list</a>
is basically a two-dimensional structure, where each element of the
first dimension represents a vertex, and each of the vertices contains
a one-dimensional structure that is its edge list. <a
href="#fig:adj-list-graph">Figure 1</a> shows an adjacency list
representation of a directed graph.
<P></P>
<DIV ALIGN="center"><A NAME="fig:adj-list-graph"></A><A NAME="1509"></A>
<TABLE>
<CAPTION ALIGN="BOTTOM"><STRONG>Figure 1:</STRONG> Adjacency List Representation of a Directed Graph.</CAPTION>
<TR><TD><IMG SRC="./figs/adj-matrix-graph2.gif" width="386" height="284"></TD>
<TD><IMG SRC="./figs/adj-list2.gif" width="62" height="122"></TD></TR>
</TABLE>
</DIV><P></P>
The
<TT>VertexList</TT> template parameter of the <TT>adjacency_list</TT>
class controls what kind of container is used to represent the outer
two-dimensional container. The <TT>OutEdgeList</TT> template parameter
controls what kind of container is used to represent the edge
lists. The choices for <TT>OutEdgeList</TT> and <TT>VertexList</TT> will
determine the space complexity of the graph structure, and will
determine the time complexity of the various graph operations. The
possible choices and tradeoffs are discussed in Section <A
HREF="./using_adjacency_list.html#sec:choosing-graph-type">Choosing
the <TT>Edgelist</TT> and <TT>VertexList</TT></A>.
<P>
The <TT>Directed</TT> template parameter controls whether the graph is
directed, undirected, or directed with access to both the in-edges and
out-edges (which we call bidirectional). The bidirectional graph takes
up twice the space (per edge) of a directed graph since each edge will
appear in both an out-edge and in-edge list. <a
href="#fig:undir-adj-list-graph">Figure 2</a> shows an adjacency list
representation of an undirected graph.
<P></P>
<DIV ALIGN="center"><A NAME="fig:undir-adj-list-graph"></A><A NAME="1509"></A>
<TABLE>
<CAPTION ALIGN="BOTTOM"><STRONG>Figure 2:</STRONG> Adjacency List Representation of an Undirected Graph.</CAPTION>
<TR><TD><IMG SRC="./figs/undir-adj-matrix-graph2.gif" width="260" height="240"></TD>
<TD><IMG SRC="./figs/undir-adj-list.gif" width="62" height="122"></TD></TR>
</TABLE>
</DIV><P></P>
<P>
A tutorial on how to use the <TT>adjacency_list</TT> class is in
Section <A HREF="./using_adjacency_list.html">Using
<TT>adjacency_list</TT></A>.
<P>
<H3>Example</H3>
<P>
The example in <a
href="../example/family-tree-eg.cpp"><tt>examples/family-tree-eg.cpp</tt></a>
shows how to represent a family tree with a graph.
<H3>Template Parameters</H3>
<P>
<TABLE border>
<TR>
<th>Parameter</th><th>Description</th><th>Default</th>
</tr>
<TR><TD><TT>OutEdgeList</TT></TD>
<TD>The selector for the container used to represent the
edge-list for each of the vertices.</TD>
<TD><TT>vecS</TT></TD>
</TR>
<TR>
<TD><TT>VertexList</TT></TD>
<TD>The selector for the container used to represent the
vertex-list of the graph.</TD>
<TD><TT>vecS</TT></TD>
</TR>
<TR>
<TD><TT>Directed</TT></TD>
<TD>A selector to choose whether the graph is directed, undirected, or directed with bidirectional edge access (access to both out-edges and in-edges). The options are <TT>directedS</TT>, <TT>undirectedS</TT>, and <TT>bidirectionalS</TT>.</TD>
<TD><TT>directedS</TT></TD>
</TR>
<TR>
<TD><TT>VertexProperties</TT></TD>
<TD>for specifying internal property storage.</TD>
<TD><TT>no_property</TT></TD>
</TR>
<TR>
<TD><TT>EdgeProperties</TT></TD>
<TD>for specifying internal property storage.</TD>
<TD><TT>no_property</TT></TD>
</TR>
<TR>
<TD><TT>GraphProperties</TT></TD>
<TD>for specifying property storage for the graph object.</TD>
<TD><TT>no_property</TT></TD>
</TR>
<TR><TD><TT>EdgeList</TT></TD>
<TD>The selector for the container used to represent the
edge-list for the graph.</TD>
<TD><TT>listS</TT></TD>
</TR>
</TABLE>
<P>
<H3>Model of</H3>
<P>
<a href="./VertexAndEdgeListGraph.html">VertexAndEdgeListGraph</a>,
<a href="./MutablePropertyGraph.html">MutablePropertyGraph</a>,
<a href="../../utility/CopyConstructible.html">CopyConstructible</a>,
<a href="../../utility/Assignable.html">Assignable</a>,
and <a href="../../serialization/doc/index.html">Serializable</a>.
<P>
<H3>Where Defined</H3>
<P>
<a href="../../../boost/graph/adjacency_list.hpp"><TT>boost/graph/adjacency_list.hpp</TT></a><br><br>
Also, the serialization functionality is in
<a href="../../../boost/graph/adj_list_serialize.hpp"><tt>boost/graph/adj_list_serialize.hpp</tt></a>.
<P>
<H2>Vertex and Edge Properties</H2>
<P>
Properties such as color, distance, weight, and user-defined
properties can be attached to the vertices and edges of the graph
using properties. The property values can be read from and written to
via the property maps provided by the graph. The property maps are
obtained via the <TT>get(property, g)</TT> function. How to use
properties is described in Section <A
HREF="./using_adjacency_list.html#sec:adjacency-list-properties">Internal
Properties </A>. The property maps are objects that implement the
interface defined in Section <A
HREF="../../property_map/property_map.html">Property Map
Concepts</A> or may be <a href="bundles.html">bundled properties</a>,
which have a more succinct syntax. The types of all property values
must be Copy Constructible, Assignable, and Default Constructible.
The property maps obtained from the
<TT>adjacency_list</TT> class are models of the <a
href="../../property_map/LvaluePropertyMap.html">Lvalue Property
Map</a> concept. If the <TT>adjacency_list</TT> is const,
then the property map is constant, otherwise the property
map is mutable.
<P>
If the <TT>VertexList</TT> of the graph is <TT>vecS</TT>, then the
graph has a builtin vertex indices accessed via the property map for
the <TT>vertex_index_t</TT> property. The indices fall in the range
<TT>[0, num_vertices(g))</TT> and are contiguous. When a vertex is
removed the indices are adjusted so that they retain these
properties. Some care must be taken when using these indices to access
exterior property storage. The property map for vertex index is a
model of <a href="../../property_map/ReadablePropertyMap.html">Readable
Property Map</a>.
<P>
<h2>Iterator and Descriptor Stability/Invalidation</h2>
Some care must be taken when changing the structure of a graph (via
adding or removing edges). Depending on the type of
<tt>adjacency_list</tt> and on the operation, some of the iterator or
descriptor objects that point into the graph may become invalid. For
example, the following code will result in undefined (bad) behavior:
<pre>
typedef adjacency_list<listS, vecS> Graph; <b>// VertexList=vecS</b>
Graph G(N);
<b>// Fill in the graph...</b>
<b>// Attempt to remove all the vertices. Wrong!</b>
graph_traits<Graph>::vertex_iterator vi, vi_end;
for (tie(vi, vi_end) = vertices(G); vi != vi_end; ++vi)
remove_vertex(*vi, G);
<b>// Remove all the vertices. This is still wrong!</b>
graph_traits<Graph>::vertex_iterator vi, vi_end, next;
tie(vi, vi_end) = vertices(G);
for (next = vi; vi != vi_end; vi = next) {
++next;
remove_vertex(*vi, G);
}
</pre>
The reason this is a problem is that we are invoking
<tt>remove_vertex()</tt>, which when used with an
<tt>adjacency_list</tt> where <tt>VertexList=vecS</tt>, invalidates
all iterators and descriptors for the graph (such as <tt>vi</tt> and
<tt>vi_end</tt>), thereby causing trouble in subsequent iterations of
the loop.
<p>
If we use a different kind of <tt>adjacency_list</tt>, where
<tt>VertexList=listS</tt>, then the iterators are not invalidated by
calling <tt>remove_vertex</tt> unless the iterator is pointing to the
actual vertex that was removed. The following code demonstrates this.
<pre>
typedef adjacency_list<listS, listS> Graph; <b>// VertexList=listS</b>
Graph G(N);
<b>// Fill in the graph...</b>
<b>// Attempt to remove all the vertices. Wrong!</b>
graph_traits<Graph>::vertex_iterator vi, vi_end;
for (tie(vi, vi_end) = vertices(G); vi != vi_end; ++vi)
remove_vertex(*vi, G);
<b>// Remove all the vertices. This is OK.</b>
graph_traits<Graph>::vertex_iterator vi, vi_end, next;
tie(vi, vi_end) = vertices(G);
for (next = vi; vi != vi_end; vi = next) {
++next;
remove_vertex(*vi, G);
}
</pre>
<p>
The stability issue also affects vertex and edge descriptors. For
example, suppose you use vector of vertex descriptors to keep track of
the parents (or predecessors) of vertices in a shortest paths tree
(see <a
href="../example/dijkstra-example.cpp"><tt>examples/dijkstra-example.cpp</tt></a>).
You create the parent vector with a call to
<tt>dijkstra_shortest_paths()</tt>, and then remove a vertex from the
graph. Subsequently you try to use the parent vector, but since all
vertex descriptors have become invalid, the result is incorrect.
<pre>
std::vector<Vertex> parent(num_vertices(G));
std::vector<Vertex> distance(num_vertices(G));
dijkstra_shortest_paths(G, s, distance_map(&distance[0]).
predecessor_map(&parent[0]));
remove_vertex(s, G); <b>// Bad idea! Invalidates vertex descriptors in parent vector.</b>
<b>// The following will produce incorrect results</b>
for(tie(vi, vend) = vertices(G); vi != vend; ++vi)
std::cout << p[*vi] << " is the parent of " << *vi << std::endl;
</pre>
<p>
Note that in this discussion iterator and descriptor invalidation is
concerned with the invalidation of iterators and descriptors that are
<b>not directly affected</b> by the operation. For example, performing
<tt>remove_edge(u, v, g)</tt> will always invalidate any edge
descriptor for <i>(u,v)</i> or edge iterator pointing to <i>(u,v)</i>,
regardless of the kind <tt>adjacency_list</tt>. In this discussion
of iterator and descriptor invalidation, we are only concerned with the
affect of <tt>remove_edge(u, v, g)</tt> on edge descriptors and
iterators that point to other edges (not <i>(u,v)</i>).
<p>
In general, if you want your vertex and edge descriptors to be stable
(never invalidated) then use <tt>listS</tt> or <tt>setS</tt> for the
<tt>VertexList</tt> and <tt>OutEdgeList</tt> template parameters of
<tt>adjacency_list</tt>. If you are not as concerned about descriptor
and iterator stability, and are more concerned about memory
consumption and graph traversal speed, use <tt>vecS</tt> for the
<tt>VertexList</tt> and/or <tt>OutEdgeList</tt> template parameters.
<p>
The following table summarizes which operations cause descriptors and
iterators to become invalid. In the table, <tt>EL</tt> is an
abbreviation for <tt>OutEdgeList</tt> and <tt>VL</tt> means
<tt>VertexList</tt>. The <b>Adj Iter</b> category includes the
<tt>out_edge_iterator</tt>, <tt>in_edge_iterator</tt>, and
<tt>adjacency_iterator</tt> types. A more detailed description of
descriptor and iterator invalidation is given in the documentation for
each operation.
<p>
<table border>
<CAPTION ALIGN="BOTTOM"><STRONG>Table:</STRONG>
Summary of Descriptor and Iterator Invalidation.
</CAPTION>
<tr> <th>Function</th> <th>Vertex Desc</th> <th>Edge Desc</th>
<th>Vertex Iter</th> <th>Edge Iter</th> <th>Adj Iter</th> </tr>
<tr>
<td><tt>add_edge()</tt></td> <td align=center><tt>OK</tt></td><td
align=center><tt>OK</tt></td><td align=center><tt>OK</tt></td><td
align=center><tt>EL=vecS &&<br> Directed=directedS</tt></td><td align=center><tt>EL=vecS</tt></td>
</tr>
<tr>
<td><tt>remove_edge()<br>remove_edge_if()<br>remove_out_edge_if()<br>remove_in_edge_if()<br>clear_vertex()</tt></td><td align=center><tt>OK</tt></td><td align=center><tt>OK</tt></td><td align=center><tt>OK</tt></td>
<td align=center><tt>EL=vecS &&<br> Directed=directedS</tt></td><td align=center><tt>EL=vecS</tt></td>
</tr>
<tr>
<td><tt>add_vertex()</tt></td><td align=center><tt>OK</tt></td><td
align=center><tt>OK</tt></td><td align=center><tt>OK</tt></td><td
align=center><tt>OK</tt></td><td align=center><tt>OK</tt></td>
</tr>
<tr>
<td><tt>remove_vertex()</tt></td><td align=center><tt>VL=vecS</tt></td><td align=center><tt>VL=vecS</tt></td><td align=center><tt>VL=vecS</tt></td><td align=center><tt>VL=vecS</tt></td><td align=center><tt>VL=vecS</tt></td>
</tr>
</table>
<H2>Associated Types</H2>
<hr>
<tt>graph_traits<adjacency_list>::vertex_descriptor</tt>
<br>
and
<br>
<tt>adjacency_list_traits<OutEdgeList, VertexList, Directed, EdgeList>::vertex_descriptor</tt>
<br><br>
The type for the vertex descriptors associated with the
<TT>adjacency_list</TT>.
<hr>
<tt>graph_traits<adjacency_list>::edge_descriptor</tt><br>
and<br>
<tt>adjacency_list_traits<OutEdgeList, VertexList, Directed, EdgeList>::edge_descriptor</tt>
<br><br>
The type for the edge descriptors associated with the
<TT>adjacency_list</TT>.
<hr>
<tt>graph_traits<adjacency_list>::vertex_iterator</tt>
<br><br>
The type for the iterators returned by <TT>vertices()</TT>.
When <tt>VertexList=vecS</tt> then the <tt>vertex_iterator</tt> models
<a
href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>. Otherwise
the <tt>vertex_iterator</tt> models <a
href="http://www.sgi.com/tech/stl/BidirectionalIterator.html">BidirectionalIterator</a>.
<hr>
<tt>graph_traits<adjacency_list>::edge_iterator</tt>
<br><br>
The type for the iterators returned by <TT>edges()</TT>.
The <tt>edge_iterator</tt> models <a
href="http://www.sgi.com/tech/stl/BidirectionalIterator.html">BidirectionalIterator</a>.
<hr>
<tt>graph_traits<adjacency_list>::out_edge_iterator</tt>
<br><br>
The type for the iterators returned by <TT>out_edges()</TT>.
When <tt>OutEdgeList=vecS</tt> then the <tt>out_edge_iterator</tt> models
<a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">
RandomAccessIterator</a>. When <tt>OutEdgeList=slistS</tt> then the
<tt>out_edge_iterator</tt> models <a
href="http://www.sgi.com/tech/stl/ForwardIterator.html">
ForwardIterator</a>. Otherwise the <tt>out_edge_iterator</tt> models
<a
href="http://www.sgi.com/tech/stl/BidirectionalIterator.html">
BidirectionalIterator</a>.
<hr>
<tt>graph_traits<adjacency_list>::adjacency_iterator</tt>
<br><br>
The type for the iterators returned by <TT>adjacent_vertices()</TT>.
The <tt>adjacency_iterator</tt> models the same iterator concept
as <tt>out_edge_iterator</tt>.
<hr>
<tt>adjacency_list::inv_adjacency_iterator</tt>
<br><br>
The type for the iterators returned by <TT>inv_adjacent_vertices()</TT>.
The <tt>inv_adjacency_iterator</tt> models the same iterator concept
as <tt>out_edge_iterator</tt>.
<hr>
<tt>graph_traits<adjacency_list>::directed_category</tt><br>
and<br>
<tt>adjacency_list_traits<OutEdgeList, VertexList, Directed, EdgeList>::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<adjacency_list>::edge_parallel_category</tt><br>
and<br>
<tt>adjacency_list_traits<OutEdgeList, VertexList, Directed, EdgeList>::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<adjacency_list>::vertices_size_type</tt><br>
and<br>
<tt>adjacency_list_traits<OutEdgeList, VertexList, Directed_list, EdgeList>::vertices_size_type</tt><br>
<br><br>
The type used for dealing with the number of vertices in the graph.
<hr>
<tt>graph_traits<adjacency_list>::edge_size_type</tt><br>
and<br>
<tt>adjacency_list_traits<OutEdgeList, VertexList, Directed_list, EdgeList>::edge_size_type</tt><br>
<br><br>
The type used for dealing with the number of edges in the graph.
<hr>
<tt>graph_traits<adjacency_list>::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<adjacency_list, Property>::type</tt><br>
and<br>
<tt>property_map<adjacency_list, Property>::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>Property</TT> template argument,
and must match one of the properties specified in the
<TT>VertexProperties</TT> or <TT>EdgeProperties</TT> for the graph.
<hr>
<tt>graph_property<adjacency_list, Property>::type</tt>
<br><br>
The property value type for the graph property specified by the
<tt>Property</tt> tag.
<hr>
<tt>adjacency_list::out_edge_list_selector</tt>
<br><br>
The type <tt>OutEdgeListS</tt>.
<hr>
<tt>adjacency_list::vertex_list_selector</tt>
<br><br>
The type <tt>VertexListS</tt>.
<hr>
<tt>adjacency_list::directed_selector</tt>
<br><br>
The type <tt>DirectedS</tt>.
<hr>
<tt>adjacency_list::edge_list_selector</tt>
<br><br>
The type <tt>EdgeListS</tt>.
<hr>
<H2>Member Functions</H2>
<hr>
<pre>
adjacency_list(const GraphProperty& p = GraphProperty())
</pre>
Default constructor. Creates an empty graph object with zero vertices
and zero edges.
<hr>
<pre>
adjacency_list(const adjacency_list& x)
</pre>
Copy constructor. Creates a new graph that is a copy of graph
<tt>x</tt>, including the edges, vertices, and properties.
<hr>
<pre>
adjacency_list& operator=(const adjacency_list& x)
</pre>
Assignment operator. Makes this graph a copy of graph
<tt>x</tt>, including the edges, vertices, and properties.
<hr>
<pre>
adjacency_list(vertices_size_type n,
const GraphProperty& p = GraphProperty())
</pre>
Creates a graph object with <TT>n</TT> vertices and zero edges.
<hr>
<a name="sec:iterator-constructor">
<pre>
template <class EdgeIterator>
adjacency_list(EdgeIterator first, EdgeIterator last,
vertices_size_type n,
edges_size_type m = 0,
const GraphProperty& p = GraphProperty())
</pre>
Creates a graph object with <TT>n</TT> vertices and with the edges
specified in the edge list given by the range <TT>[first, last)</TT>.
The <tt>EdgeIterator</tt> must be a model of <a
href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
The value type of the <TT>EdgeIterator</TT> must be a
<TT>std::pair</TT>, 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 <TT>[0, n)</TT>.
</a>
<hr>
<pre>
template <class EdgeIterator, class EdgePropertyIterator>
adjacency_list(EdgeIterator first, EdgeIterator last,
EdgePropertyIterator ep_iter,
vertices_size_type n,
vertices_size_type m = 0,
const GraphProperty& p = GraphProperty())
</pre>
Creates a graph object with <TT>n</TT> vertices and with the edges
specified in the edge list given by the range <TT>[first, last)</TT>.
The <tt>EdgeIterator</tt> and <tt>EdgePropertyIterator</tt> must be a
model of <a
href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
The value type of the <TT>EdgeIterator</TT> must be a
<TT>std::pair</TT>, 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 <TT>[0, n)</TT>. The <TT>value_type</TT> of the
<TT>ep_iter</TT> should be <TT>EdgeProperties</TT>.
<hr>
<pre>
void clear()
</pre>
Remove all of the edges and vertices from the graph.
<hr>
<pre>
void swap(adjacency_list& x)
</pre>
Swap the vertices, edges, and properties of this graph with the
vertices, edges, and properties of graph <tt>x</tt>.
<hr>
<P>
<H2>Non-Member Functions</H2>
<h4>Structure Access</h4>
<hr>
<pre>
std::pair<vertex_iterator, vertex_iterator>
vertices(const adjacency_list& g)
</pre>
Returns an iterator-range providing access to the vertex set of graph
<tt>g</tt>.
<hr>
<pre>
std::pair<edge_iterator, edge_iterator>
edges(const adjacency_list& g)
</pre>
Returns an iterator-range providing access to the edge set of graph
<tt>g</tt>.
<hr>
<pre>
std::pair<adjacency_iterator, adjacency_iterator>
adjacent_vertices(vertex_descriptor u, const adjacency_list& g)
</pre>
Returns an iterator-range providing access to the vertices adjacent to
vertex <tt>u</tt> in graph <tt>g</tt>. For example, if <tt>u -> v</tt>
is an edge in the graph, then <tt>v</tt> will be in this iterator-range.
<hr>
<pre>
std::pair<inv_adjacency_iterator, inv_adjacency_iterator>
inv_adjacent_vertices(vertex_descriptor u, const adjacency_list& g)
</pre>
Returns an iterator-range providing access to the vertices in graph
<tt>g</tt> to which <tt>u</tt> is adjacent. (<tt>inv</tt> is for
inverse.) For example, if <tt>v -> u</tt> is an edge in the graph,
then <tt>v</tt> will be in this iterator range. This function is only
available for bidirectional and undirected <tt>adjacency_list</tt>'s.
<hr>
<pre>
std::pair<out_edge_iterator, out_edge_iterator>
out_edges(vertex_descriptor u, const adjacency_list& g)
</pre>
Returns an iterator-range providing access to the out-edges of vertex
<tt>u</tt> in graph <tt>g</tt>. If the graph is undirected, this
iterator-range provides access to all edges incident on vertex
<tt>u</tt>. For both directed and undirected graphs, for an out-edge
<tt>e</tt>, <tt>source(e, g) == u</tt> and <tt>target(e, g) == v</tt>
where <tt>v</tt> is a vertex adjacent to <tt>u</tt>.
<hr>
<pre>
std::pair<in_edge_iterator, in_edge_iterator>
in_edges(vertex_descriptor v, const adjacency_list& g)
</pre>
Returns an iterator-range providing access to the in-edges of vertex
<tt>v</tt> in graph <tt>g</tt>. This operation is only available if
<TT>bidirectionalS</TT> was specified for the <TT>Directed</TT>
template parameter. For an in-edge <tt>e</tt>, <tt>target(e, g) == v</tt>
and <tt>source(e, g) == u</tt> for some vertex <tt>u</tt> that is
adjacent to <tt>v</tt>, whether the graph is directed or undirected.
<hr>
<pre>
vertex_descriptor
source(edge_descriptor e, const adjacency_list& g)
</pre>
Returns the source vertex of edge <tt>e</tt>.
<hr>
<pre>
vertex_descriptor
target(edge_descriptor e, const adjacency_list& g)
</pre>
Returns the target vertex of edge <tt>e</tt>.
<hr>
<pre>
degree_size_type
out_degree(vertex_descriptor u, const adjacency_list& g)
</pre>
Returns the number of edges leaving vertex <tt>u</tt>.
<hr>
<pre>
degree_size_type
in_degree(vertex_descriptor u, const adjacency_list& 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 adjacency_list& g)
</pre>
Returns the number of vertices in the graph <tt>g</tt>.
<hr>
<pre>
edges_size_type
num_edges(const adjacency_list& g)
</pre>
Returns the number of edges in the graph <tt>g</tt>.
<hr>
<pre>
vertex_descriptor
vertex(vertices_size_type n, const adjacency_list& g)
</pre>
Returns the nth vertex in the graph's vertex list.
<hr>
<pre>
std::pair<edge_descriptor, bool>
edge(vertex_descriptor u, vertex_descriptor v,
const adjacency_list& g)
</pre>
Returns an edge connecting vertex <tt>u</tt> to vertex <tt>v</tt> in
graph <tt>g</tt>.
<hr>
<pre>
std::pair<out_edge_iterator, out_edge_iterator>
edge_range(vertex_descriptor u, vertex_descriptor v,
const adjacency_list& g)
</pre>
Returns a pair of out-edge iterators that give the range for
all the parallel edges from <tt>u</tt> to <tt>v</tt>. This
function only works when the <tt>OutEdgeList</tt> for the
<tt>adjacency_list</tt> is a container that sorts the
out edges according to target vertex, and allows for
parallel edges. The <tt>multisetS</tt> selector chooses
such a container.
<hr>
<h4>Structure Modification</h4>
<hr>
<pre>
std::pair<edge_descriptor, bool>
add_edge(vertex_descriptor u, vertex_descriptor v,
adjacency_list& g)
</pre>
Adds edge <i>(u,v)</i> to the graph and returns the edge descriptor
for the new edge. For graphs that do not allow parallel edges, if the
edge is already in the graph then a duplicate will not be added and
the <TT>bool</TT> flag will be <TT>false</TT>. When the flag is
<TT>false</TT>, the
returned edge descriptor points to the already existing edge.
<p>
The placement of the new edge in the out-edge list is in general
unspecified, though ordering of the out-edge list can be accomplished
through the choice of <tt>OutEdgeList</tt>.
If the <tt>VertexList</tt> selector is
<tt>vecS</tt>, and if either vertex descriptor <tt>u</tt> or
<tt>v</tt> (which are integers) has a value greater than the current
number of vertices in the graph, the graph is enlarged so that the
number of vertices is <tt>std::max(u,v) + 1</tt>.
<p>
If the <TT>OutEdgeList</TT> selector is <TT>vecS</TT> then this operation
will invalidate any <tt>out_edge_iterator</tt> for vertex
<i>u</i>. This also applies if the <TT>OutEdgeList</TT> is a user-defined
container that invalidates its iterators when <TT>push(container,
x)</TT> is invoked (see Section <A
HREF="./using_adjacency_list.html#sec:custom-storage">Customizing the
Adjacency List Storage</A>). If the graph is also bidirectional then
any <tt>in_edge_iterator</tt> for <i>v</i> is also invalidated. If
instead the graph is undirected then any <tt>out_edge_iterator</tt>
for <i>v</i> is also invalidated. If instead the graph is directed,
then <tt>add_edge()</tt> also invalidates any <tt>edge_iterator</tt>.
<hr>
<pre>
std::pair<edge_descriptor, bool>
add_edge(vertex_descriptor u, vertex_descriptor v,
const EdgeProperties& p,
adjacency_list& g)
</pre>
Adds edge <i>(u,v)</i> to the graph and attaches <TT>p</TT> as the
value of the edge's internal property storage. Also see the previous
<TT>add_edge()</TT> member function for more details.
<hr>
<pre>
void remove_edge(vertex_descriptor u, vertex_descriptor v,
adjacency_list& g)
</pre>
Removes the edge <i>(u,v)</i> from the graph.
<p>
This operation causes any outstanding edge descriptors or iterators
that point to edge <i>(u,v)</i> to become invalid. In addition, if
the <TT>OutEdgeList</TT> selector is <TT>vecS</TT> then this operation
will invalidate any iterators that point into the edge-list for vertex
<i>u</i> and also for vertex <i>v</i> in the undirected and
bidirectional case. Also, for directed graphs this invalidates any
<tt>edge_iterator</tt>.
<hr>
<pre>
void remove_edge(edge_descriptor e, adjacency_list& g)
</pre>
Removes the edge <tt>e</tt> from the graph. This differs from the
<tt>remove_edge(u, v, g)</tt> function in the case of a
multigraph. This <tt>remove_edge(e, g)</tt> function removes a single
edge, whereas the <tt>remove_edge(u, v, g)</tt> function removes all
edges <i>(u,v)</i>.
<p>
This operation invalidates any outstanding edge descriptors and
iterators for the same edge pointed to by descriptor <tt>e</tt>. In
addition, this operation will invalidate any iterators that point into
the edge-list for the <tt>target(e, g)</tt>. Also, for directed
graphs this invalidates any <tt>edge_iterator</tt> for the graph.
<hr>
<pre>
void remove_edge(out_edge_iterator iter, adjacency_list& g)
</pre>
This has the same effect as <tt>remove_edge(*iter, g)</tt>. The
difference is that this function has constant time complexity
in the case of directed graphs, whereas <tt>remove_edge(e, g)</tt>
has time complexity <i>O(E/V)</i>.
<hr>
<pre>
template <class <a href="http://www.sgi.com/tech/stl/Predicate.html">Predicate</a>>
void remove_out_edge_if(vertex_descriptor u, Predicate predicate,
adjacency_list& g)
</pre>
Removes all out-edges of vertex <i>u</i> from the graph that satisfy
the <tt>predicate</tt>. That is, if the predicate returns true when
applied to an edge descriptor, then the edge is removed.
<p>
The affect on descriptor and iterator stability is the same as that of
invoking <tt>remove_edge()</tt> on each of the removed edges.
<hr>
<pre>
template <class <a
href="http://www.sgi.com/tech/stl/Predicate.html">Predicate</a>>
void remove_in_edge_if(vertex_descriptor v, Predicate predicate,
adjacency_list& g)
</pre>
Removes all in-edges of vertex <i>v</i> from the graph that satisfy
the <tt>predicate</tt>. That is, if the predicate returns true when
applied to an edge descriptor, then the edge is removed.
<p>
The affect on descriptor and iterator stability is the
same as that of invoking <tt>remove_edge()</tt> on each of the
removed edges.
<p>
This operation is available for undirected and bidirectional
<tt>adjacency_list</tt> graphs, but not for directed.
<hr>
<pre>
template <class <a href="http://www.sgi.com/tech/stl/Predicate.html">Predicate</a>>
void remove_edge_if(Predicate predicate, adjacency_list& g)
</pre>
Removes all edges from the graph that satisfy
the <tt>predicate</tt>. That is, if the predicate returns true when
applied to an edge descriptor, then the edge is removed.
<p>
The affect on descriptor and iterator stability is the same as that of
invoking <tt>remove_edge()</tt> on each of the removed edges.
<hr>
<a name="sec:add-vertex">
<pre>
vertex_descriptor
add_vertex(adjacency_list& g)
</pre>
Adds a vertex to the graph and returns the vertex descriptor for the
new vertex.
</a>
<hr>
<pre>
vertex_descriptor
add_vertex(const VertexProperties& p,
adjacency_list& g)
</pre>
Adds a vertex to the graph with the specified properties. Returns the
vertex descriptor for the new vertex.
</a>
<hr>
<pre>
void clear_vertex(vertex_descriptor u, adjacency_list& g)
</pre>
Removes all edges to and from vertex <i>u</i>. The vertex still appears
in the vertex set of the graph.
<p>
The affect on descriptor and iterator stability is the
same as that of invoking <tt>remove_edge()</tt> for all of
the edges that have <tt>u</tt> as the source or target.
<hr>
<pre>
void clear_out_edges(vertex_descriptor u, adjacency_list& g)
</pre>
Removes all out-edges from vertex <i>u</i>. The vertex still appears
in the vertex set of the graph.
<p>
The affect on descriptor and iterator stability is the
same as that of invoking <tt>remove_edge()</tt> for all of
the edges that have <tt>u</tt> as the source.
<p>
This operation is not applicable to undirected graphs
(use <tt>clear_vertex()</tt> instead).
<hr>
<pre>
void clear_in_edges(vertex_descriptor u, adjacency_list& g)
</pre>
Removes all in-edges from vertex <i>u</i>. The vertex still appears
in the vertex set of the graph.
<p>
The affect on descriptor and iterator stability is the
same as that of invoking <tt>remove_edge()</tt> for all of
the edges that have <tt>u</tt> as the target.
<p>
This operation is only applicable to bidirectional graphs.
<hr>
<pre>
void remove_vertex(vertex_descriptor u, adjacency_list& g)
</pre>
Remove vertex <i>u</i> from the vertex set of the graph. It is assumed
that there are no edges to or from vertex <i>u</i> when it is removed.
One way to make sure of this is to invoke <TT>clear_vertex()</TT>
beforehand.
<p>
If the <TT>VertexList</TT> template parameter of the
<TT>adjacency_list</TT> was <TT>vecS</TT>, then all vertex
descriptors, edge descriptors, and iterators for the graph are
invalidated by this operation. The builtin
<tt>vertex_index_t</tt> property for each vertex is renumbered so that
after the operation the vertex indices still form a contiguous range
<TT>[0, num_vertices(g))</TT>. If you are using external property
storage based on the builtin vertex index, then the external storage
will need to be adjusted. Another option is to not use the builtin
vertex index, and instead use a property to add your own vertex index
property. If you need to make frequent use of the
<TT>remove_vertex()</TT> function the <TT>listS</TT> selector is a
much better choice for the <TT>VertexList</TT> template parameter.
<hr>
<h4><a name="property-map-accessors">Property Map Accessors</a></h4>
<hr>
<pre>
template <class <a href="./PropertyTag.html">PropertyTag</a>>
property_map<adjacency_list, PropertyTag>::type
get(PropertyTag, adjacency_list& g)
template <class <a href="./PropertyTag.html">PropertyTag</a>>
property_map<adjacency_list, Tag>::const_type
get(PropertyTag, const adjacency_list& 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 <class <a href="./PropertyTag.html">PropertyTag</a>, class X>
typename property_traits<property_map<adjacency_list, PropertyTag>::const_type>::value_type
get(PropertyTag, const adjacency_list& g, X x)
</pre>
This returns the property value for <tt>x</tt>, where <tt>x</tt> is either
a vertex or edge descriptor.
<hr>
<pre>
template <class <a href="./PropertyTag.html">PropertyTag</a>, class X, class Value>
void
put(PropertyTag, const adjacency_list& g, X x, const Value& 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<property_map<adjacency_list, PropertyTag>::type>::value_type</tt>
<hr>
<pre>
template <class GraphProperties, class <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>>
typename graph_property<adjacency_list, GraphPropertyTag>::type&
get_property(adjacency_list& g, GraphPropertyTag);
</pre>
Return the property specified by <tt>GraphPropertyTag</tt> that is
attached to the graph object <tt>g</tt>. The <tt>graph_property</tt>
traits class is defined in <a
href="../../../boost/graph/adjacency_list.hpp"><tt>boost/graph/adjacency_list.hpp</tt></a>.
<hr>
<pre>
template <class GraphProperties, class <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>>
const typename graph_property<adjacency_list, GraphPropertyTag>::type&
get_property(const adjacency_list& g, GraphPropertyTag);
</pre>
Return the property specified by <tt>GraphPropertyTag</tt> that is
attached to the graph object <tt>g</tt>. The <tt>graph_property</tt>
traits class is defined in <a
href="../../../boost/graph/adjacency_list.hpp"><tt>boost/graph/adjacency_list.hpp</tt></a>.
<!-- add the shortcut property functions -->
<hr>
<h4><a name="serialization">Serialization</a></h4>
<hr>
<pre>
template<class <a href="../../serialization/doc/archives.html#saving_interface">SavingArchive</a>>
SavingArchive& operator<<(SavingArchive& ar, const adjacency_list& graph);
</pre>
Serializes the graph into the archive. Requires the vertex and edge properties of the
graph to be <a href="../../serialization/doc/index.html">Serializable</a>.
<br>
Include <a href="../../../boost/graph/adj_list_serialize.hpp"><tt>boost/graph/adj_list_serialize.hpp</tt></a>.
<hr>
<pre>
template<class <a href="../../serialization/doc/archives.html#loading_interface">LoadingArchive</a>>
LoadingArchive& operator>>(LoadingArchive& ar, const adjacency_list& graph);
</pre>
Reads the graph from the archive. Requires the vertex and edge properties of the
graph to be <a href="../../serialization/doc/index.html">Serializable</a>.
<br>
Include <a href="../../../boost/graph/adj_list_serialize.hpp"><tt>boost/graph/adj_list_serialize.hpp</tt></a>.
<hr>
<h3>See Also</h3>
<a href="./adjacency_list_traits.html"><tt>adjacency_list_traits</tt></a>,
<a href="./property_map.html"><tt>property_map</tt></a>,
<a href="./graph_traits.html"><tt>graph_traits</tt></a>
<br>
<HR>
<TABLE>
<TR valign=top>
<TD nowrap>Copyright © 2000-2001</TD><TD>
<A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>,
Indiana University (<A
HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
<A HREF="http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee</A>, Indiana University (<A HREF="mailto:llee@cs.indiana.edu">llee@cs.indiana.edu</A>)<br>
<A HREF=http://www.osl.iu.edu/~lums>Andrew Lumsdaine</A>,
Indiana University (<A
HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
</TD></TR></TABLE>
</BODY>
</HTML>
<!-- LocalWords: gif ALT OutEdgeList EdgeList VertexList html VertexProperties EdgeProperties
-->
<!-- LocalWords: GraphPropertyTag cpp enum ai cout endl VertexAndEdgeListGraph
-->
<!-- LocalWords: MutablePropertyGraph hpp const ReadablePropertyMap listS num
-->
<!-- LocalWords: ReadWritePropertyMap vecS dijkstra ucs pre Adj Iter Desc ep
-->
<!-- LocalWords: EdgeIterator EdgePropertyIterator iter bool edge's IDs siek
-->
<!-- LocalWords: multigraph typename htm Univ Quan Lumsdaine
-->
|