1 ============================
2 |(logo)|__ ``write_graphml``
3 ============================
5 .. Copyright (C) 2006 Tiago de Paula Peixoto <tiago@forked.de>
7 Distributed under the Boost Software License, Version 1.0. (See
8 accompanying file LICENSE_1_0.txt or copy at
9 http://www.boost.org/LICENSE_1_0.txt)
11 Authors: Tiago de Paula Peixoto
13 .. |(logo)| image:: ../../../boost.png
21 template<typename Graph>
23 write_graphml(std::ostream& out, const Graph& g, const dynamic_properties& dp,
24 bool ordered_vertices=false);
26 template<typename Graph, typename VertexIndexMap>
28 write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index,
29 const dynamic_properties& dp, bool ordered_vertices=false);
31 This is to write a BGL graph object into an output stream in the
32 GraphML_ format. Both overloads of ``write_graphml`` will emit all of
33 the properties stored in the dynamic_properties_ object, thereby
34 retaining the properties that have been read in through the dual
35 function read_graphml_. The second overload must be used when the
36 graph doesn't have an internal vertex index map, which must then be
37 supplied with the appropriate parameter.
43 ``<boost/graph/graphml.hpp>``
48 OUT: ``std::ostream& out``
49 A standard ``std::ostream`` object.
51 IN: ``VertexListGraph& g``
52 A directed or undirected graph. The
53 graph's type must be a model of VertexListGraph_. If the graph
54 doesn't have an internal ``vertex_index`` property map, one
55 must be supplied with the vertex_index parameter.
57 IN: ``VertexIndexMap vertex_index``
58 A vertex property map containing the indexes in the range
62 IN: ``dynamic_properties& dp``
63 Contains all of the vertex, edge, and graph properties that should be
64 emitted by the GraphML writer.
66 IN: ``bool ordered_vertices``
67 This tells whether or not the order of the vertices from vertices(g)
68 matches the order of the indexes. If ``true``, the ``parse.nodeids``
69 graph attribute will be set to ``canonical``. Otherwise it will be
77 This example demonstrates using BGL-GraphML interface to write
78 a BGL graph into a GraphML format file.
82 enum files_e { dax_h, yow_h, boz_h, zow_h, foo_cpp,
83 foo_o, bar_cpp, bar_o, libfoobar_a,
84 zig_cpp, zig_o, zag_cpp, zag_o,
85 libzigzag_a, killerapp, N };
86 const char* name[] = { "dax.h", "yow.h", "boz.h", "zow.h", "foo.cpp",
87 "foo.o", "bar.cpp", "bar.o", "libfoobar.a",
88 "zig.cpp", "zig.o", "zag.cpp", "zag.o",
89 "libzigzag.a", "killerapp" };
93 typedef pair<int,int> Edge;
95 Edge(dax_h, foo_cpp), Edge(dax_h, bar_cpp), Edge(dax_h, yow_h),
96 Edge(yow_h, bar_cpp), Edge(yow_h, zag_cpp),
97 Edge(boz_h, bar_cpp), Edge(boz_h, zig_cpp), Edge(boz_h, zag_cpp),
100 Edge(foo_o, libfoobar_a),
101 Edge(bar_cpp, bar_o),
102 Edge(bar_o, libfoobar_a),
103 Edge(libfoobar_a, libzigzag_a),
104 Edge(zig_cpp, zig_o),
105 Edge(zig_o, libzigzag_a),
106 Edge(zag_cpp, zag_o),
107 Edge(zag_o, libzigzag_a),
108 Edge(libzigzag_a, killerapp)
111 const int nedges = sizeof(used_by)/sizeof(Edge);
113 typedef adjacency_list< vecS, vecS, directedS,
114 property< vertex_color_t, string >,
115 property< edge_weight_t, int >
117 Graph g(used_by, used_by + nedges, N);
119 graph_traits<Graph>::vertex_iterator v, v_end;
120 for (tie(v,v_end) = vertices(g); v != v_end; ++v)
121 put(vertex_color_t(), g, *v, name[*v]);
123 graph_traits<Graph>::edge_iterator e, e_end;
124 for (tie(e,e_end) = edges(g); e != e_end; ++e)
125 put(edge_weight_t(), g, *e, 3);
127 dynamic_properties dp;
128 dp.property("name", get(vertex_color_t(), g));
129 dp.property("weight", get(edge_weight_t(), g));
131 write_graphml(std::cout, g, dp, true);
139 <?xml version="1.0" encoding="UTF-8"?>
140 <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">
141 <key id="key0" for="node" attr.name="name" attr.type="string" />
142 <key id="key1" for="edge" attr.name="weight" attr.type="int" />
143 <graph id="G" edgedefault="directed" parse.nodeids="canonical" parse.edgeids="canonical" parse.order="nodesfirst">
145 <data key="key0">dax.h</data>
148 <data key="key0">yow.h</data>
151 <data key="key0">boz.h</data>
154 <data key="key0">zow.h</data>
157 <data key="key0">foo.cpp</data>
160 <data key="key0">foo.o</data>
163 <data key="key0">bar.cpp</data>
166 <data key="key0">bar.o</data>
169 <data key="key0">libfoobar.a</data>
172 <data key="key0">zig.cpp</data>
175 <data key="key0">zig.o</data>
178 <data key="key0">zag.cpp</data>
181 <data key="key0">zag.o</data>
184 <data key="key0">libzigzag.a</data>
187 <data key="key0">killerapp</data>
189 <edge id="e0" source="n0" target="n4">
190 <data key="key1">3</data>
192 <edge id="e1" source="n0" target="n6">
193 <data key="key1">3</data>
195 <edge id="e2" source="n0" target="n1">
196 <data key="key1">3</data>
198 <edge id="e3" source="n1" target="n6">
199 <data key="key1">3</data>
201 <edge id="e4" source="n1" target="n11">
202 <data key="key1">3</data>
204 <edge id="e5" source="n2" target="n6">
205 <data key="key1">3</data>
207 <edge id="e6" source="n2" target="n9">
208 <data key="key1">3</data>
210 <edge id="e7" source="n2" target="n11">
211 <data key="key1">3</data>
213 <edge id="e8" source="n3" target="n4">
214 <data key="key1">3</data>
216 <edge id="e9" source="n4" target="n5">
217 <data key="key1">3</data>
219 <edge id="e10" source="n5" target="n8">
220 <data key="key1">3</data>
222 <edge id="e11" source="n6" target="n7">
223 <data key="key1">3</data>
225 <edge id="e12" source="n7" target="n8">
226 <data key="key1">3</data>
228 <edge id="e13" source="n8" target="n13">
229 <data key="key1">3</data>
231 <edge id="e14" source="n9" target="n10">
232 <data key="key1">3</data>
234 <edge id="e15" source="n10" target="n13">
235 <data key="key1">3</data>
237 <edge id="e16" source="n11" target="n12">
238 <data key="key1">3</data>
240 <edge id="e17" source="n12" target="n13">
241 <data key="key1">3</data>
243 <edge id="e18" source="n13" target="n14">
244 <data key="key1">3</data>
257 - Note that you can use GraphML file write facilities without linking
258 against the ``boost_graph`` library.
260 .. _GraphML: http://graphml.graphdrawing.org/
261 .. _dynamic_properties: ../../property_map/doc/dynamic_property_map.html
262 .. _read_graphml: read_graphml.html
263 .. _VertexListGraph: VertexListGraph.html