| 1 | // Copyright 2006 Trustees of Indiana University |
| 2 | |
| 3 | // Use, modification and distribution is subject to the Boost Software |
| 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 5 | // http://www.boost.org/LICENSE_1_0.txt) |
| 6 | |
| 7 | // A simple example of using read_graphviz to load a GraphViz Dot textual |
| 8 | // graph into a BGL adjacency_list graph |
| 9 | |
| 10 | // Author: Ronald Garcia |
| 11 | |
| 12 | #include <boost/graph/graphviz.hpp> |
| 13 | #include <boost/graph/adjacency_list.hpp> |
| 14 | #include <string> |
| 15 | #include <sstream> |
| 16 | |
| 17 | using namespace boost; |
| 18 | using namespace std; |
| 19 | |
| 20 | int main() |
| 21 | { |
| 22 | // Vertex properties |
| 23 | typedef property< vertex_name_t, std::string, |
| 24 | property< vertex_color_t, float > > |
| 25 | vertex_p; |
| 26 | // Edge properties |
| 27 | typedef property< edge_weight_t, double > edge_p; |
| 28 | // Graph properties |
| 29 | typedef property< graph_name_t, std::string > graph_p; |
| 30 | // adjacency_list-based type |
| 31 | typedef adjacency_list< vecS, vecS, directedS, vertex_p, edge_p, graph_p > |
| 32 | graph_t; |
| 33 | |
| 34 | // Construct an empty graph and prepare the dynamic_property_maps. |
| 35 | graph_t graph(0); |
| 36 | dynamic_properties dp; |
| 37 | |
| 38 | property_map< graph_t, vertex_name_t >::type name = get(p: vertex_name, g&: graph); |
| 39 | dp.property(name: "node_id" , property_map_: name); |
| 40 | |
| 41 | property_map< graph_t, vertex_color_t >::type mass |
| 42 | = get(p: vertex_color, g&: graph); |
| 43 | dp.property(name: "mass" , property_map_: mass); |
| 44 | |
| 45 | property_map< graph_t, edge_weight_t >::type weight |
| 46 | = get(p: edge_weight, g&: graph); |
| 47 | dp.property(name: "weight" , property_map_: weight); |
| 48 | |
| 49 | // Use ref_property_map to turn a graph property into a property map |
| 50 | boost::ref_property_map< graph_t*, std::string > gname( |
| 51 | get_property(g&: graph, tag: graph_name)); |
| 52 | dp.property(name: "name" , property_map_: gname); |
| 53 | |
| 54 | // Sample graph as an std::istream; |
| 55 | std::istringstream gvgraph( |
| 56 | "digraph { graph [name=\"graphname\"] a c e [mass = 6.66] }" ); |
| 57 | |
| 58 | bool status = read_graphviz(in&: gvgraph, graph, dp, node_id: "node_id" ); |
| 59 | |
| 60 | return status ? EXIT_SUCCESS : EXIT_FAILURE; |
| 61 | } |
| 62 | |