2
0
mirror of https://github.com/boostorg/graph.git synced 2026-01-29 19:42:11 +00:00
Files
graph/doc/read_graphviz.html
Douglas Gregor a6f984b406 Add Ron Garcia's new GraphViz parser.
[SVN r27250]
2005-02-08 18:58:24 +00:00

193 lines
11 KiB
HTML

<!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 read_graphviz</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">read_graphviz</span></tt></h1>
<div class="document" id="logo-read-graphviz">
<pre class="literal-block">
template &lt;typename MutableGraph&gt;
bool read_graphviz(std::istream&amp; in, MutableGraph&amp; graph,
dynamic_properties&amp; dp);
template &lt;typename MultiPassIterator, typename MutableGraph&gt;
bool read_graphviz(MultiPassIterator begin, MultiPassIterator end,
MutableGraph&amp; graph, dynamic_properties&amp; dp);
// Deprecated GraphViz readers
void read_graphviz(const std::string&amp; file, GraphvizDigraph&amp; g);
void read_graphviz(FILE* file, GraphvizDigraph&amp; g);
void read_graphviz(const std::string&amp; file, GraphvizGraph&amp; g);
void read_graphviz(FILE* file, GraphvizGraph&amp; g);
</pre>
<p>The <tt class="literal"><span class="pre">read_graphviz</span></tt> function interprets a graph described using the
<a class="reference" href="http://graphviz.org/">GraphViz</a> DOT language and builds a BGL graph that captures that
description. Using this function, you can initialize a graph using
data stored as text.</p>
<p>The DOT language can specify both directed and undirected graphs, and
<tt class="literal"><span class="pre">read_graphviz</span></tt> differentiates between the two. One must pass
<tt class="literal"><span class="pre">read_graphviz</span></tt> an undirected graph when reading an undirected graph;
the same is true for directed graphs. Furthermore, <tt class="literal"><span class="pre">read_graphviz</span></tt>
will throw an exception if it encounters parallel edges and cannot add
them to the graph.</p>
<p>To handle properties expressed in the DOT language, <tt class="literal"><span class="pre">read_graphviz</span></tt>
takes a <a class="reference" href="../../property_map/doc/dynamic_property_map.html">dynamic_properties</a> object and operates on its collection of
property maps. The reader passes all the properties encountered to
this object, using the GraphViz string keys as the property keys.
Furthermore, <tt class="literal"><span class="pre">read_graphviz</span></tt> stores node identifier names under the
property key &quot;node_id&quot;. The deprecated reading functions do not
support properties.</p>
<dl>
<dt>Requirements:</dt>
<dd><ul class="first last simple">
<li>The type of the graph must model the <a class="reference" href="MutableGraph.html">Mutable Graph</a> concept.</li>
<li>The type of the iterator must model the <a class="reference" href="../../iterator/index.html">Multi-Pass Iterator</a>
concept.</li>
<li>The property map value types must be default-constructible.</li>
</ul>
</dd>
</dl>
<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="#exceptions" id="id3" name="id3">Exceptions</a></li>
<li><a class="reference" href="#using-the-deprecated-graphviz-readers" id="id4" name="id4">Using the Deprecated GraphViz Readers</a></li>
<li><a class="reference" href="#notes" id="id5" name="id5">Notes</a></li>
<li><a class="reference" href="#see-also" id="id6" name="id6">See Also</a></li>
<li><a class="reference" href="#future-work" id="id7" name="id7">Future Work</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/graphviz.hpp&gt;</span></tt></p>
</div>
<div class="section" id="exceptions">
<h1><a class="toc-backref" href="#id3" name="exceptions">Exceptions</a></h1>
<pre class="literal-block">
struct graph_exception : public std::exception {
virtual ~graph_exception() throw();
virtual const char* what() const throw() = 0;
};
struct bad_parallel_edge : public graph_exception {
std::string from;
std::string to;
bad_parallel_edge(const std::string&amp;, const std::string&amp;);
virtual ~bad_parallel_edge() throw();
const char* what() const throw();
};
struct directed_graph_error : public graph_exception {
virtual ~directed_graph_error() throw();
virtual const char* what() const throw();
};
struct undirected_graph_error : public graph_exception {
virtual ~undirected_graph_error() throw();
virtual const char* what() const throw();
};
</pre>
<p>Under certain circumstances, <tt class="literal"><span class="pre">read_graphviz</span></tt> will throw one of the
above exceptions. The three concrete exceptions can all be caught
using the general <tt class="literal"><span class="pre">graph_exception</span></tt> moniker when greater precision
is not needed. In addition, all of the above exceptions derive from
the standard <tt class="literal"><span class="pre">std::exception</span></tt> for even more generalized error
handling.</p>
<p>The <tt class="literal"><span class="pre">bad_parallel_edge</span></tt> exception is thrown when an attempt to add a
parallel edge to the supplied MutableGraph fails. The DOT language
supports parallel edges, but some BGL-compatible graph types do not.
One example of such a graph is <tt class="literal"><span class="pre">boost::adjacency_list&lt;setS,vecS&gt;</span></tt>,
which allows at most one edge can between any two vertices.</p>
<p>The <tt class="literal"><span class="pre">directed_graph_error</span></tt> exception occurs when an undirected graph
type is passed to <tt class="literal"><span class="pre">read_graph</span></tt> but the textual representation of the
graph is directed, as indicated by the <tt class="literal"><span class="pre">digraph</span></tt> keyword in the DOT
language.</p>
<p>The <tt class="literal"><span class="pre">undirected_graph_error</span></tt> exception occurs when a directed graph
type is passed to <tt class="literal"><span class="pre">read_graph</span></tt> but the textual representation of the
graph is undirected, as indicated by the <tt class="literal"><span class="pre">graph</span></tt> keyword in the DOT
language.</p>
</div>
<div class="section" id="using-the-deprecated-graphviz-readers">
<h1><a class="toc-backref" href="#id4" name="using-the-deprecated-graphviz-readers">Using the Deprecated GraphViz Readers</a></h1>
<p>The deprecated readers do not provide exceptions on error (they
abort), they require the use of one of the predefined graph types
(<tt class="literal"><span class="pre">GraphvizDigraph</span></tt> or <tt class="literal"><span class="pre">GraphvizGraph</span></tt>), and they do not support
arbitrary properties. They will be removed in a future Boost version.</p>
<p>To use the deprecated GraphViz readers, you will need to build and
link against the &quot;bgl-viz&quot; library. The library can be built in two
ways:</p>
<blockquote>
<ol class="arabic simple">
<li>Follow the <a class="reference" href="../../../more/getting_started.html#Build_Install">Boost Jam Build Instructions</a> for the subdirectory
<tt class="literal"><span class="pre">libs/graph/build</span></tt>.</li>
<li>In the directory <tt class="literal"><span class="pre">libs/graph/src</span></tt>, use the provided Makefile
(for Unix-like systems).</li>
</ol>
</blockquote>
<p>Alternatively, you can just include the source files in
<tt class="literal"><span class="pre">libs/graph/src</span></tt> in your project or makefile.</p>
</div>
<div class="section" id="notes">
<h1><a class="toc-backref" href="#id5" name="notes">Notes</a></h1>
<blockquote>
<ul class="simple">
<li>The <tt class="literal"><span class="pre">read_graphviz</span></tt> function does not use any code from the
GraphViz distribution to interpret the DOT Language. Rather, the
implementation was based on documentation found on the GraphViz web
site, as well as experiments run using the dot application. The
resulting interpretation may be subtly different from dot for some
corner cases that are not well specified.</li>
<li><tt class="literal"><span class="pre">read_graphviz</span></tt> treats subgraphs as syntactic sugar. It does not
reflect subgraphs as actual entities in the BGL. Rather, they are
used to shorten some edge definitions as well as to give a subset
of all nodes or edges certain properties. For example, the
DOT graphs <tt class="literal"><span class="pre">digraph</span> <span class="pre">{</span> <span class="pre">a</span> <span class="pre">-&gt;</span> <span class="pre">subgraph</span> <span class="pre">{b</span> <span class="pre">-&gt;</span> <span class="pre">c}</span> <span class="pre">-&gt;</span> <span class="pre">e</span> <span class="pre">}</span></tt> and
<tt class="literal"><span class="pre">digraph</span> <span class="pre">{</span> <span class="pre">a</span> <span class="pre">-&gt;</span> <span class="pre">b</span> <span class="pre">-&gt;</span> <span class="pre">e</span> <span class="pre">;</span> <span class="pre">a</span> <span class="pre">-&gt;</span> <span class="pre">c</span> <span class="pre">-&gt;</span> <span class="pre">e</span> <span class="pre">;</span> <span class="pre">b</span> <span class="pre">-&gt;</span> <span class="pre">c}</span></tt> are equivalent.</li>
<li>Subgraph IDs refer to subgraphs defined earlier in the graph
description. Undefined subgraphs behave as empty subgraphs
(<tt class="literal"><span class="pre">{}</span></tt>).</li>
<li>On successful reading of a graph, every vertex and edge will have
an associated value for every respective edge and vertex property
encountered while interpreting the graph. These values will be set
using the <tt class="literal"><span class="pre">dynamic_properties</span></tt> object. Some properties may be
<tt class="literal"><span class="pre">put</span></tt> multiple times during the course of reading in order to
ensure the same semantics as the GraphViz tools. Those edges and
vertices that are not explicitly given a value for a property (and that
property has no default) will be
given the default constructed value of the value type. <strong>Be sure
that property map value types are default constructible.</strong></li>
</ul>
</blockquote>
</div>
<div class="section" id="see-also">
<h1><a class="toc-backref" href="#id6" name="see-also">See Also</a></h1>
<p><a class="reference" href="write-graphviz.html">write_graphviz</a></p>
</div>
<div class="section" id="future-work">
<h1><a class="toc-backref" href="#id7" name="future-work">Future Work</a></h1>
<blockquote>
<ul class="simple">
<li>Currently the parser relies upon lowercase language keywords
(i.e. &quot;graph&quot;, &quot;edge&quot;, etc.). The DOT Language specifies that they
are case-insensitive. This change should be easy given the proper
understanding of Spirit and some free time (hint hint!)</li>
<li>The parser currently does not handle continuation lines as defined
in the DOT Language. Some more sophisticated parsing of
identifier(so-called &quot;ID&quot; in the source) is required to support this.</li>
</ul>
</blockquote>
</div>
</div>
<hr class="footer" />
<div class="footer">
Generated on: 2005-02-08 18:51 UTC.
</div>
</body>
</html>