random_graph_layout :: Boost.Graph Documentation

# `random_graph_layout`

Places the vertices of a graph at random locations within a given topology.

Complexity: O(|V|)
Defined in: `<boost/graph/random_layout.hpp>`

## Example

    #include <boost/graph/adjacency_list.hpp>
    #include <boost/graph/random_layout.hpp>
    #include <boost/graph/topology.hpp>
    #include <iostream>
    #include <vector>

    using namespace boost;
    using Point = rectangle_topology<>::point_type;
    using Graph = adjacency_list<vecS, vecS, undirectedS>;

    int main() {
        Graph g(5);
        add_edge(0, 1, g); add_edge(1, 2, g);
        add_edge(2, 3, g); add_edge(3, 4, g);

        minstd_rand gen(42);
        rectangle_topology<> topology(gen, 0.0, 0.0, 100.0, 100.0);

        std::vector<Point> positions(num_vertices(g));
        auto pos_map = make_iterator_property_map(
            positions.begin(), get(vertex_index, g));

        random_graph_layout(g, pos_map, topology);

        for (auto v : make_iterator_range(vertices(g)))
            std::cout << "vertex " << v << ": ("
                      << positions[v][0] << ", " << positions[v][1] << ")\n";
    }

    vertex 0: (0.0944073, 57.1363)
    vertex 1: (25.6809, 44.7674)
    vertex 2: (65.4139, 96.697)
    vertex 3: (62.8985, 71.6352)
    vertex 4: (4.20589, 22.7523)

### Positional version

    template<typename Graph, typename PositionMap, typename Topology>
    void random_graph_layout(
        const Graph& g,
        PositionMap position_map,
        const Topology& space);

Direction | Parameter | Description
--- | --- | ---
IN | `const Graph& g` | The graph object on which the algorithm will be applied. The type `Graph` must be a model of Vertex And Edge List Graph.
IN/OUT | `PositionMap position_map` | The property map that stores the position of each vertex. The type `PositionMap` must be a model of Lvalue Property Map such that the vertex descriptor type of `Graph` is convertible to its key type. Its value type must be `Topology::point_type`, representing the coordinates of the vertex.
IN | `const Topology& space` | The topology used to lay out the vertices. This parameter describes both the size and shape of the layout area and provides a random number generator used to create random positions within the space. Topologies are described in more detail (with a list of BGL-provided topologies) in separate documentation.