File: read_graphviz.cpp

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (61 lines) | stat: -rw-r--r-- 1,938 bytes parent folder | download | duplicates (8)
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
// Copyright 2006 Trustees of Indiana University

// 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)

// A simple example of using read_graphviz to load a GraphViz Dot textual
// graph into a BGL adjacency_list graph

// Author: Ronald Garcia

#include <boost/graph/graphviz.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <string>
#include <sstream>

using namespace boost;
using namespace std;

int main()
{
    // Vertex properties
    typedef property< vertex_name_t, std::string,
        property< vertex_color_t, float > >
        vertex_p;
    // Edge properties
    typedef property< edge_weight_t, double > edge_p;
    // Graph properties
    typedef property< graph_name_t, std::string > graph_p;
    // adjacency_list-based type
    typedef adjacency_list< vecS, vecS, directedS, vertex_p, edge_p, graph_p >
        graph_t;

    // Construct an empty graph and prepare the dynamic_property_maps.
    graph_t graph(0);
    dynamic_properties dp;

    property_map< graph_t, vertex_name_t >::type name = get(vertex_name, graph);
    dp.property("node_id", name);

    property_map< graph_t, vertex_color_t >::type mass
        = get(vertex_color, graph);
    dp.property("mass", mass);

    property_map< graph_t, edge_weight_t >::type weight
        = get(edge_weight, graph);
    dp.property("weight", weight);

    // Use ref_property_map to turn a graph property into a property map
    boost::ref_property_map< graph_t*, std::string > gname(
        get_property(graph, graph_name));
    dp.property("name", gname);

    // Sample graph as an std::istream;
    std::istringstream gvgraph(
        "digraph { graph [name=\"graphname\"]  a  c e [mass = 6.66] }");

    bool status = read_graphviz(gvgraph, graph, dp, "node_id");

    return status ? EXIT_SUCCESS : EXIT_FAILURE;
}