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