distributed_adjacency_list.rst 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  1. .. Copyright (C) 2004-2008 The Trustees of Indiana University.
  2. Use, modification and distribution is subject to the Boost Software
  3. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. http://www.boost.org/LICENSE_1_0.txt)
  5. =================================
  6. |Logo| Distributed Adjacency List
  7. =================================
  8. .. contents::
  9. Introduction
  10. ------------
  11. The distributed adjacency list implements a graph data structure using
  12. an adjacency list representation. Its interface and behavior are
  13. roughly equivalent to the Boost Graph Library's adjacency_list_
  14. class template. However, the distributed adjacency list partitions the
  15. vertices of the graph across several processes (which need not share
  16. an address space). Edges outgoing from any vertex stored by a process
  17. are also stored on that process, except in the case of undirected
  18. graphs, where either the source or the target may store the edge.
  19. ::
  20. template<typename OutEdgeListS, typename ProcessGroup, typename VertexListS,
  21. typename DirectedS, typename VertexProperty, typename EdgeProperty,
  22. typename GraphProperty, typename EdgeListS>
  23. class adjacency_list<OutEdgeListS,
  24. distributedS<ProcessGroup, VertexListS>,
  25. DirectedS, VertexProperty,
  26. EdgeProperty, GraphProperty, EdgeListS>;
  27. Defining a Distributed Adjacency List
  28. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. To create a distributed adjacency list, first determine the
  30. representation of the graph in a single address space using these
  31. guidelines_. Next, replace the vertex list selector (``VertexListS``)
  32. with an instantiation of distributedS_, which includes:
  33. - Selecting a `process group`_ type that represents the various
  34. coordinating processes that will store the distributed graph. For
  35. example, the `MPI process group`_.
  36. - A selector indicating how the vertex lists in each process will be
  37. stored. Only the ``vecS`` and ``listS`` selectors are well-supported
  38. at this time.
  39. The following ``typedef`` defines a distributed adjacency list
  40. containing directed edges. The vertices in the graph will be
  41. distributed over several processes, using the MPI process group
  42. for communication. In each process, the vertices and outgoing edges
  43. will be stored in STL vectors. There are no properties attached to the
  44. vertices or edges of the graph.
  45. ::
  46. using namespace boost;
  47. typedef adjacency_list<vecS,
  48. distributedS<parallel::mpi::bsp_process_group, vecS>,
  49. directedS>
  50. Graph;
  51. Distributed Vertex and Edge Properties
  52. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. Vertex and edge properties for distributed graphs mirror their
  54. counterparts for non-distributed graphs. With a distributed graph,
  55. however, vertex and edge properties are stored only in the process
  56. that owns the vertex or edge.
  57. The most direct way to attach properties to a distributed graph is to
  58. create a structure that will be attached to each of the vertices and
  59. edges of the graph. For example, if we wish to model a simplistic map
  60. of the United States interstate highway system, we might state that
  61. the vertices of the graph are cities and the edges are highways, then
  62. define the information that we maintain for each city and highway:
  63. ::
  64. struct City {
  65. City() { }
  66. City(const std::string& name, const std::string& mayor = "Unknown", int population = 0)
  67. : name(name), mayor(mayor), population(population) { }
  68. std::string name;
  69. std::string mayor;
  70. int population;
  71. // Serialization support is required!
  72. template<typename Archiver>
  73. void serialize(Archiver& ar, const unsigned int /*version*/) {
  74. ar & name & mayor & population;
  75. }
  76. };
  77. struct Highway {
  78. Highway() { }
  79. Highway(const std::string& name, int lanes, int miles_per_hour, int length)
  80. : name(name), lanes(lanes), miles_per_hour(miles_per_hour), length(length) { }
  81. std::string name;
  82. int lanes;
  83. int miles_per_hour;
  84. int length;
  85. // Serialization support is required!
  86. template<typename Archiver>
  87. void serialize(Archiver& ar, const unsigned int /*version*/) {
  88. ar & name & lanes & miles_per_hour & length;
  89. }
  90. };
  91. To create a distributed graph for a road map, we supply ``City`` and
  92. ``Highway`` as the fourth and fifth parameters to ``adjacency_list``,
  93. respectively:
  94. ::
  95. typedef adjacency_list<vecS,
  96. distributedS<parallel::mpi::bsp_process_group, vecS>,
  97. directedS,
  98. City, Highway>
  99. RoadMap;
  100. Property maps for internal properties retain their behavior with
  101. distributed graphs via `distributed property maps`_, which automate
  102. communication among processes so that ``put`` and ``get`` operations
  103. may be applied to non-local vertices and edges. However, for
  104. distributed adjacency lists that store vertices in a vector
  105. (``VertexListS`` is ``vecS``), the automatic ``vertex_index``
  106. property map restricts the domain of ``put`` and ``get`` operations
  107. to vertices local to the process executing the operation. For example,
  108. we can create a property map that accesses the length of each highway
  109. as follows:
  110. ::
  111. RoadMap map; // distributed graph instance
  112. typedef property_map<RoadMap, int Highway::*>::type
  113. road_length = get(&Highway::length, map);
  114. Now, one can access the length of any given road based on its edge
  115. descriptor ``e`` with the expression ``get(road_length, e)``,
  116. regardless of which process stores the edge ``e``.
  117. Named Vertices
  118. ~~~~~~~~~~~~~~
  119. The vertices of a graph typically correspond to named entities within
  120. the application domain. In the road map example from the previous
  121. section, the vertices in the graph represent cities. The distributed
  122. adjacency list supports named vertices, which provides an implicit
  123. mapping from the names of the vertices in the application domain
  124. (e.g., the name of a city, such as "Bloomington") to the actual vertex
  125. descriptor stored within the distributed graph (e.g., the third vertex
  126. on processor 1). By enabling support for named vertices, one can refer
  127. to vertices by name when manipulating the graph. For example, one can
  128. add a highway from Indianapolis to Chicago:
  129. ::
  130. add_edge("Indianapolis", "Chicago", Highway("I-65", 4, 65, 151), map);
  131. The distributed adjacency list will find vertices associated with the
  132. names "Indianapolis" and "Chicago", then add an edge between these
  133. vertices that represents I-65. The vertices may be stored on any
  134. processor, local or remote.
  135. To enable named vertices, specialize the ``internal_vertex_name``
  136. property for the structure attached to the vertices in your
  137. graph. ``internal_vertex_name`` contains a single member, ``type``,
  138. which is the type of a function object that accepts a vertex property
  139. and returns the name stored within that vertex property. In the case
  140. of our road map, the ``name`` field contains the name of each city, so
  141. we use the ``member`` function object from the `Boost.MultiIndex`_
  142. library to extract the name, e.g.,
  143. ::
  144. namespace boost { namespace graph {
  145. template<>
  146. struct internal_vertex_name<City>
  147. {
  148. typedef multi_index::member<City, std::string, &City::name> type;
  149. };
  150. } }
  151. That's it! One can now refer to vertices by name when interacting with
  152. the distributed adjacency list.
  153. What happens when one uses the name of a vertex that does not exist?
  154. For example, in our ``add_edge`` call above, what happens if the
  155. vertex named "Indianapolis" has not yet been added to the graph? By
  156. default, the distributed adjacency list will throw an exception if a
  157. named vertex does not yet exist. However, one can customize this
  158. behavior by specifying a function object that constructs an instance
  159. of the vertex property (e.g., ``City``) from just the name of the
  160. vertex. This customization occurs via the
  161. ``internal_vertex_constructor`` trait. For example, using the
  162. ``vertex_from_name`` template (provided with the Parallel BGL), we can
  163. state that a ``City`` can be constructed directly from the name of the
  164. city using its second constructor:
  165. ::
  166. namespace boost { namespace graph {
  167. template<>
  168. struct internal_vertex_constructor<City>
  169. {
  170. typedef vertex_from_name<City> type;
  171. };
  172. } }
  173. Now, one can add edges by vertex name freely, without worrying about
  174. the explicit addition of vertices. The ``mayor`` and ``population``
  175. fields will have default values, but the graph structure will be
  176. correct.
  177. Building a Distributed Graph
  178. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  179. Once you have determined the layout of your graph type, including the
  180. specific data structures and properties, it is time to construct an
  181. instance of the graph by adding the appropriate vertices and
  182. edges. Construction of distributed graphs can be slightly more
  183. complicated than construction of normal, non-distributed graph data
  184. structures, because one must account for both the distribution of the
  185. vertices and edges and the multiple processes executing
  186. concurrently. There are three main ways to construct distributed
  187. graphs:
  188. 1. *Sequence constructors*: if your data can easily be generated by a
  189. pair of iterators that produce (source, target) pairs, you can use the
  190. sequence constructors to build the distributed graph in parallel. This
  191. method is often preferred when creating benchmarks, because random
  192. graph generators like the sorted_erdos_renyi_iterator_ create the
  193. appropriate input sequence. Note that one must provide the same input
  194. iterator sequence on all processes. This method has the advantage that
  195. the sequential graph-building code is identical to the parallel
  196. graph-building code. An example constructing a random graph this way:
  197. ::
  198. typedef boost::sorted_erdos_renyi_iterator<boost::minstd_rand, Graph> ERIter;
  199. boost::minstd_rand gen;
  200. unsigned long n = 1000000; // 1M vertices
  201. Graph g(ERIter(gen, n, 0.00005), ERIter(), n);
  202. 2. *Adding edges by vertex number*: if you are able to map your
  203. vertices into values in the random [0, *n*), where *n* is the number
  204. of vertices in the distributed graph. Use this method rather than the
  205. sequence constructors when your algorithm cannot easily be moved into
  206. input iterators, or if you can't replicate the input sequence. For
  207. example, you might be reading the graph from an input file:
  208. ::
  209. Graph g(n); // initialize with the total number of vertices, n
  210. if (process_id(g.process_group()) == 0) {
  211. // Only process 0 loads the graph, which is distributed automatically
  212. int source, target;
  213. for (std::cin >> source >> target)
  214. add_edge(vertex(source, g), vertex(target, g), g);
  215. }
  216. // All processes synchronize at this point, then the graph is complete
  217. synchronize(g.process_group());
  218. 3. *Adding edges by name*: if you are using named vertices, you can
  219. construct your graph just by calling ``add_edge`` with the names of
  220. the source and target vertices. Be careful to make sure that each edge
  221. is added by only one process (it doesn't matter which process it is),
  222. otherwise you will end up with multiple edges. For example, in the
  223. following program we read edges from the standard input of process 0,
  224. adding those edges by name. Vertices and edges will be created and
  225. distributed automatically.
  226. ::
  227. Graph g;
  228. if (process_id(g.process_group()) == 0) {
  229. // Only process 0 loads the graph, which is distributed automatically
  230. std:string source, target;
  231. for(std::cin >> source >> target)
  232. add_edge(source, target, g);
  233. }
  234. // All processes synchronize at this point, then the graph is complete
  235. synchronize(g.process_group());
  236. Graph Concepts
  237. ~~~~~~~~~~~~~~
  238. The distributed adjacency list models the Graph_ concept, and in
  239. particular the `Distributed Graph`_ concept. It also models the
  240. `Incidence Graph`_ and `Adjacency Graph`_ concept, but restricts the
  241. input domain of the operations to correspond to local vertices
  242. only. For instance, a process may only access the outgoing edges of a
  243. vertex if that vertex is stored in that process. Undirected and
  244. bidirectional distributed adjacency lists model the `Bidirectional
  245. Graph`_ concept, with the same domain restrictions. Distributed
  246. adjacency lists also model the `Mutable Graph`_ concept (with domain
  247. restrictions; see the Reference_ section), `Property Graph`_ concept,
  248. and `Mutable Property Graph`_ concept.
  249. Unlike its non-distributed counterpart, the distributed adjacency
  250. list does **not** model the `Vertex List Graph`_ or `Edge List
  251. Graph`_ concepts, because one cannot enumerate all vertices or edges
  252. within a distributed graph. Instead, it models the weaker
  253. `Distributed Vertex List Graph`_ and `Distributed Edge List Graph`_
  254. concepts, which permit access to the local edges and vertices on each
  255. processor. Note that if all processes within the process group over
  256. which the graph is distributed iterator over their respective vertex
  257. or edge lists, all vertices and edges will be covered once.
  258. Reference
  259. ---------
  260. Since the distributed adjacency list closely follows the
  261. non-distributed adjacency_list_, this reference documentation
  262. only describes where the two implementations differ.
  263. Where Defined
  264. ~~~~~~~~~~~~~
  265. <boost/graph/distributed/adjacency_list.hpp>
  266. Associated Types
  267. ~~~~~~~~~~~~~~~~
  268. ::
  269. adjacency_list::process_group_type
  270. The type of the process group over which the graph will be
  271. distributed.
  272. -----------------------------------------------------------------------------
  273. adjacency_list::distribution_type
  274. The type of distribution used to partition vertices in the graph.
  275. -----------------------------------------------------------------------------
  276. adjacency_list::vertex_name_type
  277. If the graph supports named vertices, this is the type used to name
  278. vertices. Otherwise, this type is not present within the distributed
  279. adjacency list.
  280. Member Functions
  281. ~~~~~~~~~~~~~~~~
  282. ::
  283. adjacency_list(const ProcessGroup& pg = ProcessGroup());
  284. adjacency_list(const GraphProperty& g,
  285. const ProcessGroup& pg = ProcessGroup());
  286. Construct an empty distributed adjacency list with the given process
  287. group (or default) and graph property (or default).
  288. -----------------------------------------------------------------------------
  289. ::
  290. adjacency_list(vertices_size_type n, const GraphProperty& p,
  291. const ProcessGroup& pg, const Distribution& distribution);
  292. adjacency_list(vertices_size_type n, const ProcessGroup& pg,
  293. const Distribution& distribution);
  294. adjacency_list(vertices_size_type n, const GraphProperty& p,
  295. const ProcessGroup& pg = ProcessGroup());
  296. adjacency_list(vertices_size_type n,
  297. const ProcessGroup& pg = ProcessGroup());
  298. Construct a distributed adjacency list with ``n`` vertices,
  299. optionally providing the graph property, process group, or
  300. distribution. The ``n`` vertices will be distributed via the given
  301. (or default-constructed) distribution. This operation is collective,
  302. requiring all processes with the process group to execute it
  303. concurrently.
  304. -----------------------------------------------------------------------------
  305. ::
  306. template <class EdgeIterator>
  307. adjacency_list(EdgeIterator first, EdgeIterator last,
  308. vertices_size_type n,
  309. const ProcessGroup& pg = ProcessGroup(),
  310. const GraphProperty& p = GraphProperty());
  311. template <class EdgeIterator, class EdgePropertyIterator>
  312. adjacency_list(EdgeIterator first, EdgeIterator last,
  313. EdgePropertyIterator ep_iter,
  314. vertices_size_type n,
  315. const ProcessGroup& pg = ProcessGroup(),
  316. const GraphProperty& p = GraphProperty());
  317. template <class EdgeIterator>
  318. adjacency_list(EdgeIterator first, EdgeIterator last,
  319. vertices_size_type n,
  320. const ProcessGroup& process_group,
  321. const Distribution& distribution,
  322. const GraphProperty& p = GraphProperty());
  323. template <class EdgeIterator, class EdgePropertyIterator>
  324. adjacency_list(EdgeIterator first, EdgeIterator last,
  325. EdgePropertyIterator ep_iter,
  326. vertices_size_type n,
  327. const ProcessGroup& process_group,
  328. const Distribution& distribution,
  329. const GraphProperty& p = GraphProperty());
  330. Construct a distributed adjacency list with ``n`` vertices and with
  331. edges specified in the edge list given by the range ``[first, last)``. The
  332. ``EdgeIterator`` must be a model of InputIterator_. The value type of the
  333. ``EdgeIterator`` must be a ``std::pair``, where the type in the pair is an
  334. integer type. The integers will correspond to vertices, and they must
  335. all fall in the range of ``[0, n)``. When provided, ``ep_iter``
  336. refers to an edge property list ``[ep_iter, ep_iter + m)`` contains
  337. properties for each of the edges.
  338. This constructor is a collective operation and must be executed
  339. concurrently by each process with the same argument list. Most
  340. importantly, the edge lists provided to the constructor in each process
  341. should be equivalent. The vertices will be partitioned among the
  342. processes according to the ``distribution``, with edges placed on the
  343. process owning the source of the edge. Note that this behavior
  344. permits sequential graph construction code to be parallelized
  345. automatically, regardless of the underlying distribution.
  346. -----------------------------------------------------------------------------
  347. ::
  348. void clear()
  349. Removes all of the edges and vertices from the local graph. To
  350. eliminate all vertices and edges from the graph, this routine must be
  351. executed in all processes.
  352. -----------------------------------------------------------------------------
  353. ::
  354. process_group_type& process_group();
  355. const process_group_type& process_group() const;
  356. Returns the process group over which this graph is distributed.
  357. -----------------------------------------------------------------------------
  358. ::
  359. distribution_type& distribution();
  360. const distribution_type& distribution() const;
  361. Returns the distribution used for initial placement of vertices.
  362. -----------------------------------------------------------------------------
  363. ::
  364. template<typename VertexProcessorMap>
  365. void redistribute(VertexProcessorMap vertex_to_processor);
  366. Redistributes the vertices (and, therefore, the edges) of the
  367. graph. The property map ``vertex_to_processor`` provides, for each
  368. vertex, the process identifier indicating where the vertex should be
  369. moved. Once this collective routine has completed, the distributed
  370. graph will reflect the new distribution. All vertex and edge
  371. descsriptors and internal and external property maps are invalidated
  372. by this operation.
  373. -----------------------------------------------------------------------------
  374. ::
  375. template<typename OStreamConstructibleArchive>
  376. void save(std::string const& filename) const;
  377. template<typename IStreamConstructibleArchive>
  378. void load(std::string const& filename);
  379. Serializes the graph to a Boost.Serialization archive.
  380. ``OStreamConstructibleArchive`` and ``IStreamConstructibleArchive``
  381. are models of Boost.Serialization *Archive* with the extra
  382. requirement that they can be constructed from a ``std::ostream``
  383. and ``std::istream``.
  384. ``filename`` names a directory that will hold files for
  385. the different processes.
  386. Non-Member Functions
  387. ~~~~~~~~~~~~~~~~~~~~
  388. ::
  389. std::pair<vertex_iterator, vertex_iterator>
  390. vertices(const adjacency_list& g);
  391. Returns an iterator-range providing access to the vertex set of graph
  392. ``g`` stored in this process. Each of the processes that contain ``g``
  393. will get disjoint sets of vertices.
  394. -----------------------------------------------------------------------------
  395. ::
  396. std::pair<edge_iterator, edge_iterator>
  397. edges(const adjacency_list& g);
  398. Returns an iterator-range providing access to the edge set of graph
  399. ``g`` stored in this process.
  400. -----------------------------------------------------------------------------
  401. ::
  402. std::pair<adjacency_iterator, adjacency_iterator>
  403. adjacent_vertices(vertex_descriptor u, const adjacency_list& g);
  404. Returns an iterator-range providing access to the vertices adjacent to
  405. vertex ``u`` in graph ``g``. The vertex ``u`` must be local to this process.
  406. -----------------------------------------------------------------------------
  407. ::
  408. std::pair<out_edge_iterator, out_edge_iterator>
  409. out_edges(vertex_descriptor u, const adjacency_list& g);
  410. Returns an iterator-range providing access to the out-edges of vertex
  411. ``u`` in graph ``g``. If the graph is undirected, this iterator-range
  412. provides access to all edges incident on vertex ``u``. For both
  413. directed and undirected graphs, for an out-edge ``e``, ``source(e, g)
  414. == u`` and ``target(e, g) == v`` where ``v`` is a vertex adjacent to
  415. ``u``. The vertex ``u`` must be local to this process.
  416. -----------------------------------------------------------------------------
  417. ::
  418. std::pair<in_edge_iterator, in_edge_iterator>
  419. in_edges(vertex_descriptor v, const adjacency_list& g);
  420. Returns an iterator-range providing access to the in-edges of vertex
  421. ``v`` in graph ``g``. This operation is only available if
  422. ``bidirectionalS`` was specified for the ``Directed`` template
  423. parameter. For an in-edge ``e``, ``target(e, g) == v`` and ``source(e,
  424. g) == u`` for some vertex ``u`` that is adjacent to ``v``, whether the
  425. graph is directed or undirected. The vertex ``v`` must be local to
  426. this process.
  427. -----------------------------------------------------------------------------
  428. ::
  429. degree_size_type
  430. out_degree(vertex_descriptor u, const adjacency_list& g);
  431. Returns the number of edges leaving vertex ``u``. Vertex ``u`` must
  432. be local to the executing process.
  433. -----------------------------------------------------------------------------
  434. ::
  435. degree_size_type
  436. in_degree(vertex_descriptor u, const adjacency_list& g);
  437. Returns the number of edges entering vertex ``u``. This operation is
  438. only available if ``bidirectionalS`` was specified for the
  439. ``Directed`` template parameter. Vertex ``u`` must be local to the
  440. executing process.
  441. -----------------------------------------------------------------------------
  442. ::
  443. vertices_size_type
  444. num_vertices(const adjacency_list& g);
  445. Returns the number of vertices in the graph ``g`` that are stored in
  446. the executing process.
  447. -----------------------------------------------------------------------------
  448. ::
  449. edges_size_type
  450. num_edges(const adjacency_list& g);
  451. Returns the number of edges in the graph ``g`` that are stored in the
  452. executing process.
  453. -----------------------------------------------------------------------------
  454. ::
  455. vertex_descriptor
  456. vertex(vertices_size_type n, const adjacency_list& g);
  457. Returns the ``n``th vertex in the graph's vertex list, according to the
  458. distribution used to partition the graph. ``n`` must be a value
  459. between zero and the sum of ``num_vertices(g)`` in each process (minus
  460. one). Note that it is not necessarily the case that ``vertex(0, g) ==
  461. *num_vertices(g).first``. This function is only guaranteed to be
  462. accurate when no vertices have been added to or removed from the
  463. graph after its initial construction.
  464. -----------------------------------------------------------------------------
  465. ::
  466. std::pair<edge_descriptor, bool>
  467. edge(vertex_descriptor u, vertex_descriptor v,
  468. const adjacency_list& g);
  469. Returns an edge connecting vertex ``u`` to vertex ``v`` in graph
  470. ``g``. For bidirectional and undirected graphs, either vertex ``u`` or
  471. vertex ``v`` must be local; for directed graphs, vertex ``u`` must be
  472. local.
  473. -----------------------------------------------------------------------------
  474. ::
  475. std::pair<out_edge_iterator, out_edge_iterator>
  476. edge_range(vertex_descriptor u, vertex_descriptor v,
  477. const adjacency_list& g);
  478. TODO: Not implemented. Returns a pair of out-edge iterators that give
  479. the range for all the parallel edges from ``u`` to ``v``. This function only
  480. works when the ``OutEdgeList`` for the ``adjacency_list`` is a container that
  481. sorts the out edges according to target vertex, and allows for
  482. parallel edges. The ``multisetS`` selector chooses such a
  483. container. Vertex ``u`` must be stored in the executing process.
  484. Structure Modification
  485. ~~~~~~~~~~~~~~~~~~~~~~
  486. ::
  487. unspecified add_edge(vertex_descriptor u, vertex_descriptor v, adjacency_list& g);
  488. unspecified add_edge(vertex_name_type u, vertex_descriptor v, adjacency_list& g);
  489. unspecified add_edge(vertex_descriptor u, vertex_name_type v, adjacency_list& g);
  490. unspecified add_edge(vertex_name_type u, vertex_name_type v, adjacency_list& g);
  491. Adds edge ``(u,v)`` to the graph. The return type itself is
  492. unspecified, but the type can be copy-constructed and implicitly
  493. converted into a ``std::pair<edge_descriptor,bool>``. The edge
  494. descriptor describes the added (or found) edge. For graphs that do not
  495. allow parallel edges, if the edge
  496. is already in the graph then a duplicate will not be added and the
  497. ``bool`` flag will be ``false``. Also, if u and v are descriptors for
  498. the same vertex (creating a self loop) and the graph is undirected,
  499. then the edge will not be added and the flag will be ``false``. When
  500. the flag is ``false``, the returned edge descriptor points to the
  501. already existing edge.
  502. The parameters ``u`` and ``v`` can be either vertex descriptors or, if
  503. the graph uses named vertices, the names of vertices. If no vertex
  504. with the given name exists, the internal vertex constructor will be
  505. invoked to create a new vertex property and a vertex with that
  506. property will be added to the graph implicitly. The default internal
  507. vertex constructor throws an exception.
  508. -----------------------------------------------------------------------------
  509. ::
  510. unspecified add_edge(vertex_descriptor u, vertex_descriptor v, const EdgeProperties& p, adjacency_list& g);
  511. unspecified add_edge(vertex_name_type u, vertex_descriptor v, const EdgeProperties& p, adjacency_list& g);
  512. unspecified add_edge(vertex_descriptor u, vertex_name_type v, const EdgeProperties& p, adjacency_list& g);
  513. unspecified add_edge(vertex_name_type u, vertex_name_type v, const EdgeProperties& p, adjacency_list& g);
  514. Adds edge ``(u,v)`` to the graph and attaches ``p`` as the value of the edge's
  515. internal property storage. See the previous ``add_edge()`` member
  516. function for more details.
  517. -----------------------------------------------------------------------------
  518. ::
  519. void
  520. remove_edge(vertex_descriptor u, vertex_descriptor v,
  521. adjacency_list& g);
  522. Removes the edge ``(u,v)`` from the graph. If the directed selector is
  523. ``bidirectionalS`` or ``undirectedS``, either the source or target
  524. vertex of the graph must be local. If the directed selector is
  525. ``directedS``, then the source vertex must be local.
  526. -----------------------------------------------------------------------------
  527. ::
  528. void
  529. remove_edge(edge_descriptor e, adjacency_list& g);
  530. Removes the edge ``e`` from the graph. If the directed selector is
  531. ``bidirectionalS`` or ``undirectedS``, either the source or target
  532. vertex of the graph must be local. If the directed selector is
  533. ``directedS``, then the source vertex must be local.
  534. -----------------------------------------------------------------------------
  535. ::
  536. void remove_edge(out_edge_iterator iter, adjacency_list& g);
  537. This has the same effect as ``remove_edge(*iter, g)``. For directed
  538. (but not bidirectional) graphs, this will be more efficient than
  539. ``remove_edge(*iter, g)``.
  540. -----------------------------------------------------------------------------
  541. ::
  542. template <class Predicate >
  543. void remove_out_edge_if(vertex_descriptor u, Predicate predicate,
  544. adjacency_list& g);
  545. Removes all out-edges of vertex ``u`` from the graph that satisfy the
  546. predicate. That is, if the predicate returns ``true`` when applied to an
  547. edge descriptor, then the edge is removed. The vertex ``u`` must be local.
  548. The affect on descriptor and iterator stability is the same as that of
  549. invoking remove_edge() on each of the removed edges.
  550. -----------------------------------------------------------------------------
  551. ::
  552. template <class Predicate >
  553. void remove_in_edge_if(vertex_descriptor v, Predicate predicate,
  554. adjacency_list& g);
  555. Removes all in-edges of vertex ``v`` from the graph that satisfy the
  556. predicate. That is, if the predicate returns true when applied to an
  557. edge descriptor, then the edge is removed. The vertex ``v`` must be local.
  558. The affect on descriptor and iterator stability is the same as that of
  559. invoking ``remove_edge()`` on each of the removed edges.
  560. This operation is available for undirected and bidirectional
  561. adjacency_list graphs, but not for directed.
  562. -----------------------------------------------------------------------------
  563. ::
  564. template <class Predicate>
  565. void remove_edge_if(Predicate predicate, adjacency_list& g);
  566. Removes all edges from the graph that satisfy the predicate. That is,
  567. if the predicate returns true when applied to an edge descriptor, then
  568. the edge is removed.
  569. The affect on descriptor and iterator stability is the same as that
  570. of invoking ``remove_edge()`` on each of the removed edges.
  571. -----------------------------------------------------------------------------
  572. ::
  573. vertex_descriptor add_vertex(adjacency_list& g);
  574. Adds a vertex to the graph and returns the vertex descriptor for the
  575. new vertex. The vertex will be stored in the local process. This
  576. function is not available when using named vertices.
  577. -----------------------------------------------------------------------------
  578. ::
  579. unspecified add_vertex(const VertexProperties& p, adjacency_list& g);
  580. unspecified add_vertex(const vertex_name_type& p, adjacency_list& g);
  581. Adds a vertex to the graph with the specified properties. If the graph
  582. is using vertex names, the vertex will be added on whichever process
  583. "owns" that name. Otherwise, the vertex will be stored in the local
  584. process. Note that the second constructor will invoke the
  585. user-customizable internal vertex constructor, which (by default)
  586. throws an exception when it sees an unknown vertex.
  587. The return type is of unspecified type, but can be copy-constructed
  588. and can be implicitly converted into a vertex descriptor.
  589. -----------------------------------------------------------------------------
  590. ::
  591. void clear_vertex(vertex_descriptor u, adjacency_list& g);
  592. Removes all edges to and from vertex ``u``. The vertex still appears
  593. in the vertex set of the graph.
  594. The affect on descriptor and iterator stability is the same as that of
  595. invoking ``remove_edge()`` for all of the edges that have ``u`` as the source
  596. or target.
  597. This operation is not applicable to directed graphs, because the
  598. incoming edges to vertex ``u`` are not known.
  599. -----------------------------------------------------------------------------
  600. ::
  601. void clear_out_edges(vertex_descriptor u, adjacency_list& g);
  602. Removes all out-edges from vertex ``u``. The vertex still appears in
  603. the vertex set of the graph.
  604. The affect on descriptor and iterator stability is the same as that of
  605. invoking ``remove_edge()`` for all of the edges that have ``u`` as the
  606. source.
  607. This operation is not applicable to undirected graphs (use
  608. ``clear_vertex()`` instead).
  609. -----------------------------------------------------------------------------
  610. ::
  611. void clear_in_edges(vertex_descriptor u, adjacency_list& g);
  612. Removes all in-edges from vertex ``u``. The vertex still appears in
  613. the vertex set of the graph.
  614. The affect on descriptor and iterator stability is the same as that of
  615. invoking ``remove_edge()`` for all of the edges that have ``u`` as the
  616. target.
  617. This operation is only applicable to bidirectional graphs.
  618. -----------------------------------------------------------------------------
  619. ::
  620. void remove_vertex(vertex_descriptor u, adjacency_list& g);
  621. Remove vertex ``u`` from the vertex set of the graph. It is assumed
  622. that there are no edges to or from vertex ``u`` when it is
  623. removed. One way to make sure of this is to invoke ``clear_vertex()``
  624. beforehand. The vertex ``u`` must be stored locally.
  625. Property Map Accessors
  626. ~~~~~~~~~~~~~~~~~~~~~~
  627. ::
  628. template <class PropertyTag>
  629. property_map<adjacency_list, PropertyTag>::type
  630. get(PropertyTag, adjacency_list& g);
  631. template <class PropertyTag>
  632. property_map<adjacency_list, Tag>::const_type
  633. get(PropertyTag, const adjacency_list& g);
  634. Returns the property map object for the vertex property specified by
  635. ``PropertyTag``. The ``PropertyTag`` must match one of the properties
  636. specified in the graph's ``VertexProperty`` template argument. The
  637. returned property map will be a `distributed property map`_.
  638. -----------------------------------------------------------------------------
  639. ::
  640. template <class PropertyTag , class X>
  641. typename property_traits<property_map<adjacency_list, PropertyTag>::const_type>::value_type
  642. get(PropertyTag, const adjacency_list& g, X x);
  643. This returns the property value for ``x``, where ``x`` is either a vertex or
  644. edge descriptor. The entity referred to by descriptor ``x`` must be
  645. stored in the local process.
  646. -----------------------------------------------------------------------------
  647. ::
  648. template <class PropertyTag , class X, class Value>
  649. void put(PropertyTag, const adjacency_list& g, X x, const Value& value);
  650. This sets the property value for ``x`` to value. ``x`` is either a
  651. vertex or edge descriptor. ``Value`` must be convertible to ``typename
  652. property_traits<property_map<adjacency_list,
  653. PropertyTag>::type>::value_type``.
  654. -----------------------------------------------------------------------------
  655. ::
  656. template <class GraphProperties, class GraphPropertyTag>
  657. typename graph_property<adjacency_list, GraphPropertyTag>::type&
  658. get_property(adjacency_list& g, GraphPropertyTag);
  659. template <class GraphProperties, class GraphPropertyTag >
  660. const typename graph_property<adjacency_list, GraphPropertyTag>::type&
  661. get_property(const adjacency_list& g, GraphPropertyTag);
  662. TODO: not implemented.
  663. Return the property specified by ``GraphPropertyTag`` that is attached
  664. to the graph object ``g``. The ``graph_property`` traits class is
  665. defined in ``boost/graph/adjacency_list.hpp``.
  666. -----------------------------------------------------------------------------
  667. Copyright (C) 2004 The Trustees of Indiana University.
  668. Copyright (C) 2007 Douglas Gregor
  669. Authors: Douglas Gregor and Andrew Lumsdaine
  670. .. |Logo| image:: pbgl-logo.png
  671. :align: middle
  672. :alt: Parallel BGL
  673. :target: http://www.osl.iu.edu/research/pbgl
  674. .. _adjacency_list: http://www.boost.org/libs/graph/doc/adjacency_list.html
  675. .. _guidelines: http://www.boost.org/libs/graph/doc/using_adjacency_list.html
  676. .. _process group: process_group.html
  677. .. _mpi process group: process_group.html
  678. .. _distributedS: distributedS.html
  679. .. _Graph: http://www.boost.org/libs/graph/doc/Graph.html
  680. .. _Distributed graph: DistributedGraph.html
  681. .. _Incidence Graph: http://www.boost.org/libs/graph/doc/IncidenceGraph.html
  682. .. _Adjacency Graph: http://www.boost.org/libs/graph/doc/AdjacencyGraph.html
  683. .. _Bidirectional Graph: http://www.boost.org/libs/graph/doc/BidirectionalGraph.html
  684. .. _Mutable Graph: http://www.boost.org/libs/graph/doc/MutableGraph.html
  685. .. _Property Graph: http://www.boost.org/libs/graph/doc/PropertyGraph.html
  686. .. _Mutable Property Graph: http://www.boost.org/libs/graph/doc/MutablePropertyGraph.html
  687. .. _Vertex List Graph: http://www.boost.org/libs/graph/doc/VertexListGraph.html
  688. .. _Edge List Graph: http://www.boost.org/libs/graph/doc/EdgeListGraph.html
  689. .. _Distribution: concepts/Distribution.html
  690. .. _distributed property map: distributed_property_map.html
  691. .. _distributed property maps: distributed_property_map.html
  692. .. _Distributed Vertex List Graph: DistributedVertexListGraph.html
  693. .. _Distributed Edge List Graph: DistributedEdgeListGraph.html
  694. .. _InputIterator: http://www.boost.org/doc/html/InputIterator.html
  695. .. _member: http://www.boost.org/libs/multi_index/doc/reference/key_extraction.html#member_synopsis
  696. .. _Boost.MultiIndex: http://www.boost.org/libs/multi_index/doc/index.html
  697. .. _sorted_erdos_renyi_iterator: http://www.boost.org/libs/graph/doc/sorted_erdos_renyi_gen.html