File: write_graphml.html

package info (click to toggle)
boost1.35 1.35.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 203,856 kB
  • ctags: 337,867
  • sloc: cpp: 938,683; xml: 56,847; ansic: 41,589; python: 18,999; sh: 11,566; makefile: 664; perl: 494; yacc: 456; asm: 353; csh: 6
file content (258 lines) | stat: -rw-r--r-- 12,860 bytes parent folder | download
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
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.3.3: http://docutils.sourceforge.net/" />
<title>Boost write_graphml</title>
<link rel="stylesheet" href="default.css" type="text/css" />
</head>
<body>
<h1 class="title"><a class="reference" href="../../../index.htm"><img align="middle" alt="Boost" src="../../../boost.png" /></a> <tt class="literal"><span class="pre">write_graphml</span></tt></h1>
<div class="document" id="logo-write-graphml">
<pre class="literal-block">
template&lt;typename Graph&gt;
void
write_graphml(std::ostream&amp; out, const Graph&amp; g, const dynamic_properties&amp; dp, 
              bool ordered_vertices=false);

template&lt;typename Graph, typename VertexIndexMap&gt;
void
write_graphml(std::ostream&amp; out, const Graph&amp; g, VertexIndexMap vertex_index,
              const dynamic_properties&amp; dp, bool ordered_vertices=false);
</pre>
<p>This is to write a BGL graph object into an output stream in the
<a class="reference" href="http://graphml.graphdrawing.org/">graphml</a> format.  Both overloads of <tt class="literal"><span class="pre">write_graphml</span></tt> will emit all of
the properties stored in the <a class="reference" href="../../property_map/doc/dynamic_property_map.html">dynamic_properties</a> object, thereby
retaining the properties that have been read in through the dual
function <a class="reference" href="read_graphml.html">read_graphml</a>. The second overload must be used when the
graph doesn't have an internal vertex index map, which must then be
supplied with the appropriate parameter.</p>
<div class="contents topic" id="contents">
<p class="topic-title first"><a name="contents">Contents</a></p>
<ul class="simple">
<li><a class="reference" href="#where-defined" id="id2" name="id2">Where Defined</a></li>
<li><a class="reference" href="#parameters" id="id3" name="id3">Parameters</a></li>
<li><a class="reference" href="#example" id="id4" name="id4">Example</a></li>
<li><a class="reference" href="#see-also" id="id5" name="id5">See Also</a></li>
<li><a class="reference" href="#notes" id="id6" name="id6">Notes</a></li>
</ul>
</div>
<div class="section" id="where-defined">
<h1><a class="toc-backref" href="#id2" name="where-defined">Where Defined</a></h1>
<p><tt class="literal"><span class="pre">&lt;boost/graph/graphml.hpp&gt;</span></tt></p>
</div>
<div class="section" id="parameters">
<h1><a class="toc-backref" href="#id3" name="parameters">Parameters</a></h1>
<dl>
<dt>OUT: <tt class="literal"><span class="pre">std::ostream&amp;</span> <span class="pre">out</span></tt></dt>
<dd>A standard <tt class="literal"><span class="pre">std::ostream</span></tt> object.</dd>
<dt>IN: <tt class="literal"><span class="pre">VertexListGraph&amp;</span> <span class="pre">g</span></tt> </dt>
<dd>A directed or undirected graph.  The
graph's type must be a model of <a class="reference" href="VertexListGraph.html">VertexListGraph</a>. If the graph
doesn't have an internal <tt class="literal"><span class="pre">vertex_index</span></tt> property map, one
must be supplied with the vertex_index parameter.</dd>
<dt>IN: <tt class="literal"><span class="pre">VertexIndexMap</span> <span class="pre">vertex_index</span></tt></dt>
<dd>A vertex property map containing the indexes in the range
[0,num_vertices(g)].</dd>
<dt>IN: <tt class="literal"><span class="pre">dynamic_properties&amp;</span> <span class="pre">dp</span></tt></dt>
<dd>Contains all of the vertex and edge properties that should be
emitted by the graphml writer.</dd>
<dt>IN: <tt class="literal"><span class="pre">bool</span> <span class="pre">ordered_vertices</span></tt></dt>
<dd>This tells whether or not the order of the vertices from vertices(g)
matches the order of the indexes. If <tt class="literal"><span class="pre">true</span></tt>, the <tt class="literal"><span class="pre">parse.nodeids</span></tt>
graph attribute will be set to <tt class="literal"><span class="pre">canonical</span></tt>. Otherwise it will be
set to <tt class="literal"><span class="pre">free</span></tt>.</dd>
</dl>
</div>
<div class="section" id="example">
<h1><a class="toc-backref" href="#id4" name="example">Example</a></h1>
<p>This example demonstrates using BGL-graphml interface to write 
a BGL graph into a graphml format file.</p>
<pre class="literal-block">
enum files_e { dax_h, yow_h, boz_h, zow_h, foo_cpp,
               foo_o, bar_cpp, bar_o, libfoobar_a,
               zig_cpp, zig_o, zag_cpp, zag_o,
               libzigzag_a, killerapp, N };
const char* name[] = { &quot;dax.h&quot;, &quot;yow.h&quot;, &quot;boz.h&quot;, &quot;zow.h&quot;, &quot;foo.cpp&quot;,
                       &quot;foo.o&quot;, &quot;bar.cpp&quot;, &quot;bar.o&quot;, &quot;libfoobar.a&quot;,
                       &quot;zig.cpp&quot;, &quot;zig.o&quot;, &quot;zag.cpp&quot;, &quot;zag.o&quot;,
                       &quot;libzigzag.a&quot;, &quot;killerapp&quot; };

int main(int,char*[])
{
    typedef pair&lt;int,int&gt; Edge;
    Edge used_by[] = {
        Edge(dax_h, foo_cpp), Edge(dax_h, bar_cpp), Edge(dax_h, yow_h),
        Edge(yow_h, bar_cpp), Edge(yow_h, zag_cpp),
        Edge(boz_h, bar_cpp), Edge(boz_h, zig_cpp), Edge(boz_h, zag_cpp),
        Edge(zow_h, foo_cpp),
        Edge(foo_cpp, foo_o),
        Edge(foo_o, libfoobar_a),
        Edge(bar_cpp, bar_o),
        Edge(bar_o, libfoobar_a),
        Edge(libfoobar_a, libzigzag_a),
        Edge(zig_cpp, zig_o),
        Edge(zig_o, libzigzag_a),
        Edge(zag_cpp, zag_o),
        Edge(zag_o, libzigzag_a),
        Edge(libzigzag_a, killerapp)
     };

    const int nedges = sizeof(used_by)/sizeof(Edge);

    typedef adjacency_list&lt; vecS, vecS, directedS,
        property&lt; vertex_color_t, string &gt;,
        property&lt; edge_weight_t, int &gt;
        &gt; Graph;
    Graph g(used_by, used_by + nedges, N);

    graph_traits&lt;Graph&gt;::vertex_iterator v, v_end;
    for (tie(v,v_end) = vertices(g); v != v_end; ++v)
        put(vertex_color_t(), g, *v, name[*v]);

    graph_traits&lt;Graph&gt;::edge_iterator e, e_end;
    for (tie(e,e_end) = edges(g); e != e_end; ++e)
        put(edge_weight_t(), g, *e, 3);

    dynamic_properties dp;
    dp.property(&quot;name&quot;, get(vertex_color_t(), g));
    dp.property(&quot;weight&quot;, get(edge_weight_t(), g));

    write_graphml(std::cout, g, dp, true);
 }
</pre>
<p>The output will be:</p>
<pre class="literal-block">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&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;
  &lt;key id=&quot;key0&quot; for=&quot;node&quot; attr.name=&quot;name&quot; attr.type=&quot;string&quot; /&gt;
  &lt;key id=&quot;key1&quot; for=&quot;edge&quot; attr.name=&quot;weight&quot; attr.type=&quot;int&quot; /&gt;
  &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;
    &lt;node id=&quot;n0&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;dax.h&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n1&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;yow.h&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n2&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;boz.h&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n3&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;zow.h&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n4&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;foo.cpp&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n5&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;foo.o&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n6&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;bar.cpp&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n7&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;bar.o&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n8&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;libfoobar.a&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n9&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;zig.cpp&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n10&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;zig.o&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n11&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;zag.cpp&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n12&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;zag.o&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n13&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;libzigzag.a&lt;/data&gt;
    &lt;/node&gt;
    &lt;node id=&quot;n14&quot;&gt;
      &lt;data key=&quot;key0&quot;&gt;killerapp&lt;/data&gt;
    &lt;/node&gt;
    &lt;edge id=&quot;e0&quot; source=&quot;n0&quot; target=&quot;n4&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e1&quot; source=&quot;n0&quot; target=&quot;n6&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e2&quot; source=&quot;n0&quot; target=&quot;n1&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e3&quot; source=&quot;n1&quot; target=&quot;n6&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e4&quot; source=&quot;n1&quot; target=&quot;n11&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e5&quot; source=&quot;n2&quot; target=&quot;n6&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e6&quot; source=&quot;n2&quot; target=&quot;n9&quot;&gt;
       &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e7&quot; source=&quot;n2&quot; target=&quot;n11&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e8&quot; source=&quot;n3&quot; target=&quot;n4&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e9&quot; source=&quot;n4&quot; target=&quot;n5&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e10&quot; source=&quot;n5&quot; target=&quot;n8&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e11&quot; source=&quot;n6&quot; target=&quot;n7&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e12&quot; source=&quot;n7&quot; target=&quot;n8&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e13&quot; source=&quot;n8&quot; target=&quot;n13&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e14&quot; source=&quot;n9&quot; target=&quot;n10&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e15&quot; source=&quot;n10&quot; target=&quot;n13&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e16&quot; source=&quot;n11&quot; target=&quot;n12&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e17&quot; source=&quot;n12&quot; target=&quot;n13&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
    &lt;edge id=&quot;e18&quot; source=&quot;n13&quot; target=&quot;n14&quot;&gt;
      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
    &lt;/edge&gt;
  &lt;/graph&gt;
&lt;/graphml&gt;
</pre>
</div>
<div class="section" id="see-also">
<h1><a class="toc-backref" href="#id5" name="see-also">See Also</a></h1>
<p>_read_graphml</p>
</div>
<div class="section" id="notes">
<h1><a class="toc-backref" href="#id6" name="notes">Notes</a></h1>
<blockquote>
<ul class="simple">
<li>Note that you can use graphml file write facilities without linking
against the <tt class="literal"><span class="pre">boost_graph</span></tt> library.</li>
</ul>
</blockquote>
</div>
</div>
<hr class="footer" />
<div class="footer">
<a class="reference" href="write_graphml.rst">View document source</a>.
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
</div>
</body>
</html>