123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <?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.6: http://docutils.sourceforge.net/" />
- <title>Boost write_graphml</title>
- <link rel="stylesheet" href="../../../rst.css" type="text/css" />
- </head>
- <body>
- <div class="document" id="logo-write-graphml">
- <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>
- <!-- Copyright (C) 2006 Tiago de Paula Peixoto <tiago@forked.de>
- Distributed under the Boost Software License, Version 1.0. (See
- accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt)
- Authors: Tiago de Paula Peixoto -->
- <pre class="literal-block">
- template<typename Graph>
- void
- write_graphml(std::ostream& out, const Graph& g, const dynamic_properties& dp,
- bool ordered_vertices=false);
- template<typename Graph, typename VertexIndexMap>
- void
- write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index,
- const dynamic_properties& dp, bool ordered_vertices=false);
- </pre>
- <p>This is to write a BGL graph object into an output stream in the
- <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
- the properties stored in the <a class="reference external" 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 external" 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">Contents</p>
- <ul class="simple">
- <li><a class="reference internal" href="#where-defined" id="id2">Where Defined</a></li>
- <li><a class="reference internal" href="#parameters" id="id3">Parameters</a></li>
- <li><a class="reference internal" href="#example" id="id4">Example</a></li>
- <li><a class="reference internal" href="#see-also" id="id5">See Also</a></li>
- <li><a class="reference internal" href="#notes" id="id6">Notes</a></li>
- </ul>
- </div>
- <div class="section" id="where-defined">
- <h1><a class="toc-backref" href="#id2">Where Defined</a></h1>
- <p><tt class="docutils literal"><span class="pre"><boost/graph/graphml.hpp></span></tt></p>
- </div>
- <div class="section" id="parameters">
- <h1><a class="toc-backref" href="#id3">Parameters</a></h1>
- <dl class="docutils">
- <dt>OUT: <tt class="docutils literal"><span class="pre">std::ostream&</span> <span class="pre">out</span></tt></dt>
- <dd>A standard <tt class="docutils literal"><span class="pre">std::ostream</span></tt> object.</dd>
- <dt>IN: <tt class="docutils literal"><span class="pre">VertexListGraph&</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 external" href="VertexListGraph.html">VertexListGraph</a>. If the graph
- doesn't have an internal <tt class="docutils literal"><span class="pre">vertex_index</span></tt> property map, one
- must be supplied with the vertex_index parameter.</dd>
- <dt>IN: <tt class="docutils 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="docutils literal"><span class="pre">dynamic_properties&</span> <span class="pre">dp</span></tt></dt>
- <dd>Contains all of the vertex, edge, and graph properties that should be
- emitted by the GraphML writer.</dd>
- <dt>IN: <tt class="docutils 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="docutils literal"><span class="pre">true</span></tt>, the <tt class="docutils literal"><span class="pre">parse.nodeids</span></tt>
- graph attribute will be set to <tt class="docutils literal"><span class="pre">canonical</span></tt>. Otherwise it will be
- set to <tt class="docutils literal"><span class="pre">free</span></tt>.</dd>
- </dl>
- </div>
- <div class="section" id="example">
- <h1><a class="toc-backref" href="#id4">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[] = { "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" };
- int main(int,char*[])
- {
- typedef pair<int,int> 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< vecS, vecS, directedS,
- property< vertex_color_t, string >,
- property< edge_weight_t, int >
- > Graph;
- Graph g(used_by, used_by + nedges, N);
- graph_traits<Graph>::vertex_iterator v, v_end;
- for (boost::tie(v,v_end) = vertices(g); v != v_end; ++v)
- put(vertex_color_t(), g, *v, name[*v]);
- graph_traits<Graph>::edge_iterator e, e_end;
- for (boost::tie(e,e_end) = edges(g); e != e_end; ++e)
- put(edge_weight_t(), g, *e, 3);
- dynamic_properties dp;
- dp.property("name", get(vertex_color_t(), g));
- dp.property("weight", get(edge_weight_t(), g));
- write_graphml(std::cout, g, dp, true);
- }
- </pre>
- <p>The output will be:</p>
- <pre class="literal-block">
- <?xml version="1.0" encoding="UTF-8"?>
- <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">
- <key id="key0" for="node" attr.name="name" attr.type="string" />
- <key id="key1" for="edge" attr.name="weight" attr.type="int" />
- <graph id="G" edgedefault="directed" parse.nodeids="canonical" parse.edgeids="canonical" parse.order="nodesfirst">
- <node id="n0">
- <data key="key0">dax.h</data>
- </node>
- <node id="n1">
- <data key="key0">yow.h</data>
- </node>
- <node id="n2">
- <data key="key0">boz.h</data>
- </node>
- <node id="n3">
- <data key="key0">zow.h</data>
- </node>
- <node id="n4">
- <data key="key0">foo.cpp</data>
- </node>
- <node id="n5">
- <data key="key0">foo.o</data>
- </node>
- <node id="n6">
- <data key="key0">bar.cpp</data>
- </node>
- <node id="n7">
- <data key="key0">bar.o</data>
- </node>
- <node id="n8">
- <data key="key0">libfoobar.a</data>
- </node>
- <node id="n9">
- <data key="key0">zig.cpp</data>
- </node>
- <node id="n10">
- <data key="key0">zig.o</data>
- </node>
- <node id="n11">
- <data key="key0">zag.cpp</data>
- </node>
- <node id="n12">
- <data key="key0">zag.o</data>
- </node>
- <node id="n13">
- <data key="key0">libzigzag.a</data>
- </node>
- <node id="n14">
- <data key="key0">killerapp</data>
- </node>
- <edge id="e0" source="n0" target="n4">
- <data key="key1">3</data>
- </edge>
- <edge id="e1" source="n0" target="n6">
- <data key="key1">3</data>
- </edge>
- <edge id="e2" source="n0" target="n1">
- <data key="key1">3</data>
- </edge>
- <edge id="e3" source="n1" target="n6">
- <data key="key1">3</data>
- </edge>
- <edge id="e4" source="n1" target="n11">
- <data key="key1">3</data>
- </edge>
- <edge id="e5" source="n2" target="n6">
- <data key="key1">3</data>
- </edge>
- <edge id="e6" source="n2" target="n9">
- <data key="key1">3</data>
- </edge>
- <edge id="e7" source="n2" target="n11">
- <data key="key1">3</data>
- </edge>
- <edge id="e8" source="n3" target="n4">
- <data key="key1">3</data>
- </edge>
- <edge id="e9" source="n4" target="n5">
- <data key="key1">3</data>
- </edge>
- <edge id="e10" source="n5" target="n8">
- <data key="key1">3</data>
- </edge>
- <edge id="e11" source="n6" target="n7">
- <data key="key1">3</data>
- </edge>
- <edge id="e12" source="n7" target="n8">
- <data key="key1">3</data>
- </edge>
- <edge id="e13" source="n8" target="n13">
- <data key="key1">3</data>
- </edge>
- <edge id="e14" source="n9" target="n10">
- <data key="key1">3</data>
- </edge>
- <edge id="e15" source="n10" target="n13">
- <data key="key1">3</data>
- </edge>
- <edge id="e16" source="n11" target="n12">
- <data key="key1">3</data>
- </edge>
- <edge id="e17" source="n12" target="n13">
- <data key="key1">3</data>
- </edge>
- <edge id="e18" source="n13" target="n14">
- <data key="key1">3</data>
- </edge>
- </graph>
- </graphml>
- </pre>
- </div>
- <div class="section" id="see-also">
- <h1><a class="toc-backref" href="#id5">See Also</a></h1>
- <p>_read_graphml</p>
- </div>
- <div class="section" id="notes">
- <h1><a class="toc-backref" href="#id6">Notes</a></h1>
- <blockquote>
- <ul class="simple">
- <li>Note that you can use GraphML file write facilities without linking
- against the <tt class="docutils literal"><span class="pre">boost_graph</span></tt> library.</li>
- </ul>
- </blockquote>
- </div>
- </div>
- <div class="footer">
- <hr class="footer" />
- Generated on: 2009-06-12 00:41 UTC.
- 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.
- </div>
- </body>
- </html>
|