// (C) Copyright 2008-2009 SDML (www.sdml.info) // // Use, modification and distribution is subject to 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) // Copyright Andrew Sutton 2007 // // Use, modification and distribution are subject to 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) #ifndef BOOST_FCA_WRITE_GRAPHVIZ_HPP #define BOOST_FCA_WRITE_GRAPHVIZ_HPP #include #include #include namespace boost { namespace fca { template void write_graphviz(std::ostream& os, const Lattice& lat) { using namespace std; using namespace boost; // Useful types typedef typename Lattice::graph_type Graph; typedef typename graph_traits::vertex_descriptor Vertex; typedef typename graph_traits::edge_descriptor Edge; typedef typename graph_traits::vertex_iterator VertexIterator; typedef typename graph_traits::edge_iterator EdgeIterator; typedef typename property_map::type IndexMap; typedef typename Lattice::concept_type Concept; typedef typename Lattice::object_set ObjectSet; typedef typename Lattice::attribute_set AttributeSet; typedef typename Lattice::object_type ObjectType; typedef typename Lattice::attribute_type AttributeType; const Graph& g = lat.graph(); IndexMap indices = get(vertex_index, g); os << "digraph G {" << endl; os << " rankdir = BT;" << endl; os << " node [shape=box];" << endl; // Start by writing all vertices... pair verts = vertices(g); for(; verts.first != verts.second; ++verts.first) { const Concept& c = *g[*verts.first].value; const ObjectSet& cobjs = c.objects(); const AttributeSet& catts = c.attributes(); os << " " << get(indices, *verts.first) << " ["; // Build a label for the vertex. stringstream ss; ss << "atts { "; copy(begin(catts), end(catts), ostream_iterator(ss, " ")); ss << "}\\n"; ss << "objs { "; copy(begin(cobjs), end(cobjs), ostream_iterator(ss, " ")); ss << "}"; os << "label=\"" << ss.str() << "\""; os << "];" << endl; } // Now, write all the edges (by index) pair eds = edges(g); for( ; eds.first != eds.second; ++eds.first) { Edge e = *eds.first; Vertex u = source(e, g), v = target(e, g); os << get(indices, u) << " -> " << get(indices, v) << ";" << endl; } os << "}" << endl; } } /* namespace fca */ } /* namespace boost */ #endif