write_graphml.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
  7. <title>Boost write_graphml</title>
  8. <link rel="stylesheet" href="../../../rst.css" type="text/css" />
  9. </head>
  10. <body>
  11. <div class="document" id="logo-write-graphml">
  12. <h1 class="title"><a class="reference external" href="../../../index.htm"><img align="middle" alt="Boost" class="align-middle" src="../../../boost.png" /></a> <tt class="docutils literal"><span class="pre">write_graphml</span></tt></h1>
  13. <!-- Copyright (C) 2006 Tiago de Paula Peixoto <tiago@forked.de>
  14. Distributed under the Boost Software License, Version 1.0. (See
  15. accompanying file LICENSE_1_0.txt or copy at
  16. http://www.boost.org/LICENSE_1_0.txt)
  17. Authors: Tiago de Paula Peixoto -->
  18. <pre class="literal-block">
  19. template&lt;typename Graph&gt;
  20. void
  21. write_graphml(std::ostream&amp; out, const Graph&amp; g, const dynamic_properties&amp; dp,
  22. bool ordered_vertices=false);
  23. template&lt;typename Graph, typename VertexIndexMap&gt;
  24. void
  25. write_graphml(std::ostream&amp; out, const Graph&amp; g, VertexIndexMap vertex_index,
  26. const dynamic_properties&amp; dp, bool ordered_vertices=false);
  27. </pre>
  28. <p>This is to write a BGL graph object into an output stream in the
  29. <a class="reference external" href="http://graphml.graphdrawing.org/">GraphML</a> format. Both overloads of <tt class="docutils literal"><span class="pre">write_graphml</span></tt> will emit all of
  30. the properties stored in the <a class="reference external" href="../../property_map/doc/dynamic_property_map.html">dynamic_properties</a> object, thereby
  31. retaining the properties that have been read in through the dual
  32. function <a class="reference external" href="read_graphml.html">read_graphml</a>. The second overload must be used when the
  33. graph doesn't have an internal vertex index map, which must then be
  34. supplied with the appropriate parameter.</p>
  35. <div class="contents topic" id="contents">
  36. <p class="topic-title first">Contents</p>
  37. <ul class="simple">
  38. <li><a class="reference internal" href="#where-defined" id="id2">Where Defined</a></li>
  39. <li><a class="reference internal" href="#parameters" id="id3">Parameters</a></li>
  40. <li><a class="reference internal" href="#example" id="id4">Example</a></li>
  41. <li><a class="reference internal" href="#see-also" id="id5">See Also</a></li>
  42. <li><a class="reference internal" href="#notes" id="id6">Notes</a></li>
  43. </ul>
  44. </div>
  45. <div class="section" id="where-defined">
  46. <h1><a class="toc-backref" href="#id2">Where Defined</a></h1>
  47. <p><tt class="docutils literal"><span class="pre">&lt;boost/graph/graphml.hpp&gt;</span></tt></p>
  48. </div>
  49. <div class="section" id="parameters">
  50. <h1><a class="toc-backref" href="#id3">Parameters</a></h1>
  51. <dl class="docutils">
  52. <dt>OUT: <tt class="docutils literal"><span class="pre">std::ostream&amp;</span> <span class="pre">out</span></tt></dt>
  53. <dd>A standard <tt class="docutils literal"><span class="pre">std::ostream</span></tt> object.</dd>
  54. <dt>IN: <tt class="docutils literal"><span class="pre">VertexListGraph&amp;</span> <span class="pre">g</span></tt></dt>
  55. <dd>A directed or undirected graph. The
  56. graph's type must be a model of <a class="reference external" href="VertexListGraph.html">VertexListGraph</a>. If the graph
  57. doesn't have an internal <tt class="docutils literal"><span class="pre">vertex_index</span></tt> property map, one
  58. must be supplied with the vertex_index parameter.</dd>
  59. <dt>IN: <tt class="docutils literal"><span class="pre">VertexIndexMap</span> <span class="pre">vertex_index</span></tt></dt>
  60. <dd>A vertex property map containing the indexes in the range
  61. [0,num_vertices(g)].</dd>
  62. <dt>IN: <tt class="docutils literal"><span class="pre">dynamic_properties&amp;</span> <span class="pre">dp</span></tt></dt>
  63. <dd>Contains all of the vertex, edge, and graph properties that should be
  64. emitted by the GraphML writer.</dd>
  65. <dt>IN: <tt class="docutils literal"><span class="pre">bool</span> <span class="pre">ordered_vertices</span></tt></dt>
  66. <dd>This tells whether or not the order of the vertices from vertices(g)
  67. matches the order of the indexes. If <tt class="docutils literal"><span class="pre">true</span></tt>, the <tt class="docutils literal"><span class="pre">parse.nodeids</span></tt>
  68. graph attribute will be set to <tt class="docutils literal"><span class="pre">canonical</span></tt>. Otherwise it will be
  69. set to <tt class="docutils literal"><span class="pre">free</span></tt>.</dd>
  70. </dl>
  71. </div>
  72. <div class="section" id="example">
  73. <h1><a class="toc-backref" href="#id4">Example</a></h1>
  74. <p>This example demonstrates using BGL-GraphML interface to write
  75. a BGL graph into a GraphML format file.</p>
  76. <pre class="literal-block">
  77. enum files_e { dax_h, yow_h, boz_h, zow_h, foo_cpp,
  78. foo_o, bar_cpp, bar_o, libfoobar_a,
  79. zig_cpp, zig_o, zag_cpp, zag_o,
  80. libzigzag_a, killerapp, N };
  81. const char* name[] = { &quot;dax.h&quot;, &quot;yow.h&quot;, &quot;boz.h&quot;, &quot;zow.h&quot;, &quot;foo.cpp&quot;,
  82. &quot;foo.o&quot;, &quot;bar.cpp&quot;, &quot;bar.o&quot;, &quot;libfoobar.a&quot;,
  83. &quot;zig.cpp&quot;, &quot;zig.o&quot;, &quot;zag.cpp&quot;, &quot;zag.o&quot;,
  84. &quot;libzigzag.a&quot;, &quot;killerapp&quot; };
  85. int main(int,char*[])
  86. {
  87. typedef pair&lt;int,int&gt; Edge;
  88. Edge used_by[] = {
  89. Edge(dax_h, foo_cpp), Edge(dax_h, bar_cpp), Edge(dax_h, yow_h),
  90. Edge(yow_h, bar_cpp), Edge(yow_h, zag_cpp),
  91. Edge(boz_h, bar_cpp), Edge(boz_h, zig_cpp), Edge(boz_h, zag_cpp),
  92. Edge(zow_h, foo_cpp),
  93. Edge(foo_cpp, foo_o),
  94. Edge(foo_o, libfoobar_a),
  95. Edge(bar_cpp, bar_o),
  96. Edge(bar_o, libfoobar_a),
  97. Edge(libfoobar_a, libzigzag_a),
  98. Edge(zig_cpp, zig_o),
  99. Edge(zig_o, libzigzag_a),
  100. Edge(zag_cpp, zag_o),
  101. Edge(zag_o, libzigzag_a),
  102. Edge(libzigzag_a, killerapp)
  103. };
  104. const int nedges = sizeof(used_by)/sizeof(Edge);
  105. typedef adjacency_list&lt; vecS, vecS, directedS,
  106. property&lt; vertex_color_t, string &gt;,
  107. property&lt; edge_weight_t, int &gt;
  108. &gt; Graph;
  109. Graph g(used_by, used_by + nedges, N);
  110. graph_traits&lt;Graph&gt;::vertex_iterator v, v_end;
  111. for (boost::tie(v,v_end) = vertices(g); v != v_end; ++v)
  112. put(vertex_color_t(), g, *v, name[*v]);
  113. graph_traits&lt;Graph&gt;::edge_iterator e, e_end;
  114. for (boost::tie(e,e_end) = edges(g); e != e_end; ++e)
  115. put(edge_weight_t(), g, *e, 3);
  116. dynamic_properties dp;
  117. dp.property(&quot;name&quot;, get(vertex_color_t(), g));
  118. dp.property(&quot;weight&quot;, get(edge_weight_t(), g));
  119. write_graphml(std::cout, g, dp, true);
  120. }
  121. </pre>
  122. <p>The output will be:</p>
  123. <pre class="literal-block">
  124. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  125. &lt;graphml xmlns=&quot;http://graphml.graphdrawing.org/xmlns/graphml&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://graphml.graphdrawing.org/xmlns/graphml http://graphml.graphdrawing.org/xmlns/graphml/graphml-attributes-1.0rc.xsd&quot;&gt;
  126. &lt;key id=&quot;key0&quot; for=&quot;node&quot; attr.name=&quot;name&quot; attr.type=&quot;string&quot; /&gt;
  127. &lt;key id=&quot;key1&quot; for=&quot;edge&quot; attr.name=&quot;weight&quot; attr.type=&quot;int&quot; /&gt;
  128. &lt;graph id=&quot;G&quot; edgedefault=&quot;directed&quot; parse.nodeids=&quot;canonical&quot; parse.edgeids=&quot;canonical&quot; parse.order=&quot;nodesfirst&quot;&gt;
  129. &lt;node id=&quot;n0&quot;&gt;
  130. &lt;data key=&quot;key0&quot;&gt;dax.h&lt;/data&gt;
  131. &lt;/node&gt;
  132. &lt;node id=&quot;n1&quot;&gt;
  133. &lt;data key=&quot;key0&quot;&gt;yow.h&lt;/data&gt;
  134. &lt;/node&gt;
  135. &lt;node id=&quot;n2&quot;&gt;
  136. &lt;data key=&quot;key0&quot;&gt;boz.h&lt;/data&gt;
  137. &lt;/node&gt;
  138. &lt;node id=&quot;n3&quot;&gt;
  139. &lt;data key=&quot;key0&quot;&gt;zow.h&lt;/data&gt;
  140. &lt;/node&gt;
  141. &lt;node id=&quot;n4&quot;&gt;
  142. &lt;data key=&quot;key0&quot;&gt;foo.cpp&lt;/data&gt;
  143. &lt;/node&gt;
  144. &lt;node id=&quot;n5&quot;&gt;
  145. &lt;data key=&quot;key0&quot;&gt;foo.o&lt;/data&gt;
  146. &lt;/node&gt;
  147. &lt;node id=&quot;n6&quot;&gt;
  148. &lt;data key=&quot;key0&quot;&gt;bar.cpp&lt;/data&gt;
  149. &lt;/node&gt;
  150. &lt;node id=&quot;n7&quot;&gt;
  151. &lt;data key=&quot;key0&quot;&gt;bar.o&lt;/data&gt;
  152. &lt;/node&gt;
  153. &lt;node id=&quot;n8&quot;&gt;
  154. &lt;data key=&quot;key0&quot;&gt;libfoobar.a&lt;/data&gt;
  155. &lt;/node&gt;
  156. &lt;node id=&quot;n9&quot;&gt;
  157. &lt;data key=&quot;key0&quot;&gt;zig.cpp&lt;/data&gt;
  158. &lt;/node&gt;
  159. &lt;node id=&quot;n10&quot;&gt;
  160. &lt;data key=&quot;key0&quot;&gt;zig.o&lt;/data&gt;
  161. &lt;/node&gt;
  162. &lt;node id=&quot;n11&quot;&gt;
  163. &lt;data key=&quot;key0&quot;&gt;zag.cpp&lt;/data&gt;
  164. &lt;/node&gt;
  165. &lt;node id=&quot;n12&quot;&gt;
  166. &lt;data key=&quot;key0&quot;&gt;zag.o&lt;/data&gt;
  167. &lt;/node&gt;
  168. &lt;node id=&quot;n13&quot;&gt;
  169. &lt;data key=&quot;key0&quot;&gt;libzigzag.a&lt;/data&gt;
  170. &lt;/node&gt;
  171. &lt;node id=&quot;n14&quot;&gt;
  172. &lt;data key=&quot;key0&quot;&gt;killerapp&lt;/data&gt;
  173. &lt;/node&gt;
  174. &lt;edge id=&quot;e0&quot; source=&quot;n0&quot; target=&quot;n4&quot;&gt;
  175. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  176. &lt;/edge&gt;
  177. &lt;edge id=&quot;e1&quot; source=&quot;n0&quot; target=&quot;n6&quot;&gt;
  178. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  179. &lt;/edge&gt;
  180. &lt;edge id=&quot;e2&quot; source=&quot;n0&quot; target=&quot;n1&quot;&gt;
  181. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  182. &lt;/edge&gt;
  183. &lt;edge id=&quot;e3&quot; source=&quot;n1&quot; target=&quot;n6&quot;&gt;
  184. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  185. &lt;/edge&gt;
  186. &lt;edge id=&quot;e4&quot; source=&quot;n1&quot; target=&quot;n11&quot;&gt;
  187. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  188. &lt;/edge&gt;
  189. &lt;edge id=&quot;e5&quot; source=&quot;n2&quot; target=&quot;n6&quot;&gt;
  190. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  191. &lt;/edge&gt;
  192. &lt;edge id=&quot;e6&quot; source=&quot;n2&quot; target=&quot;n9&quot;&gt;
  193. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  194. &lt;/edge&gt;
  195. &lt;edge id=&quot;e7&quot; source=&quot;n2&quot; target=&quot;n11&quot;&gt;
  196. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  197. &lt;/edge&gt;
  198. &lt;edge id=&quot;e8&quot; source=&quot;n3&quot; target=&quot;n4&quot;&gt;
  199. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  200. &lt;/edge&gt;
  201. &lt;edge id=&quot;e9&quot; source=&quot;n4&quot; target=&quot;n5&quot;&gt;
  202. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  203. &lt;/edge&gt;
  204. &lt;edge id=&quot;e10&quot; source=&quot;n5&quot; target=&quot;n8&quot;&gt;
  205. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  206. &lt;/edge&gt;
  207. &lt;edge id=&quot;e11&quot; source=&quot;n6&quot; target=&quot;n7&quot;&gt;
  208. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  209. &lt;/edge&gt;
  210. &lt;edge id=&quot;e12&quot; source=&quot;n7&quot; target=&quot;n8&quot;&gt;
  211. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  212. &lt;/edge&gt;
  213. &lt;edge id=&quot;e13&quot; source=&quot;n8&quot; target=&quot;n13&quot;&gt;
  214. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  215. &lt;/edge&gt;
  216. &lt;edge id=&quot;e14&quot; source=&quot;n9&quot; target=&quot;n10&quot;&gt;
  217. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  218. &lt;/edge&gt;
  219. &lt;edge id=&quot;e15&quot; source=&quot;n10&quot; target=&quot;n13&quot;&gt;
  220. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  221. &lt;/edge&gt;
  222. &lt;edge id=&quot;e16&quot; source=&quot;n11&quot; target=&quot;n12&quot;&gt;
  223. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  224. &lt;/edge&gt;
  225. &lt;edge id=&quot;e17&quot; source=&quot;n12&quot; target=&quot;n13&quot;&gt;
  226. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  227. &lt;/edge&gt;
  228. &lt;edge id=&quot;e18&quot; source=&quot;n13&quot; target=&quot;n14&quot;&gt;
  229. &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
  230. &lt;/edge&gt;
  231. &lt;/graph&gt;
  232. &lt;/graphml&gt;
  233. </pre>
  234. </div>
  235. <div class="section" id="see-also">
  236. <h1><a class="toc-backref" href="#id5">See Also</a></h1>
  237. <p>_read_graphml</p>
  238. </div>
  239. <div class="section" id="notes">
  240. <h1><a class="toc-backref" href="#id6">Notes</a></h1>
  241. <blockquote>
  242. <ul class="simple">
  243. <li>Note that you can use GraphML file write facilities without linking
  244. against the <tt class="docutils literal"><span class="pre">boost_graph</span></tt> library.</li>
  245. </ul>
  246. </blockquote>
  247. </div>
  248. </div>
  249. <div class="footer">
  250. <hr class="footer" />
  251. Generated on: 2009-06-12 00:41 UTC.
  252. Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
  253. </div>
  254. </body>
  255. </html>