| Home | Libraries | People | FAQ | More

## Function kamada_kawai_spring_layout

boost::kamada_kawai_spring_layout — Kamada-Kawai spring layout for connected, undirected graphs.

## Synopsis

    template<typename Topology, typename Graph, typename PositionMap, typename WeightMap, typename T,
             bool EdgeOrSideLength, typename Done, typename VertexIndexMap,
             typename DistanceMatrix, typename SpringStrengthMatrix,
             typename PartialDerivativeMap>
      bool kamada_kawai_spring_layout(const Graph & g, PositionMap position,
                                      WeightMap weight,
                                      const Topology& space,
                                      unspecified edge_or_side_length, Done done,
                                      typename property_traits< WeightMap >::value_type spring_constant,
                                      VertexIndexMap index,
                                      DistanceMatrix distance,
                                      SpringStrengthMatrix spring_strength,
                                      PartialDerivativeMap partial_derivatives);
    template<typename Topology, typename Graph, typename PositionMap, typename WeightMap, typename T,
             bool EdgeOrSideLength, typename Done, typename VertexIndexMap>
      bool kamada_kawai_spring_layout(const Graph & g, PositionMap position,
                                      WeightMap weight,
                                      const Topology& space,
                                      unspecified edge_or_side_length, Done done,
                                      typename property_traits< WeightMap >::value_type spring_constant,
                                      VertexIndexMap index);
    template<typename Topology, typename Graph, typename PositionMap, typename WeightMap, typename T,
             bool EdgeOrSideLength, typename Done>
      bool kamada_kawai_spring_layout(const Graph & g, PositionMap position,
                                      WeightMap weight,
                                      const Topology& space,
                                      unspecified edge_or_side_length, Done done,
                                      typename property_traits< WeightMap >::value_type spring_constant = typename property_traits< WeightMap >::value_type(1));
    template<typename Topology, typename Graph, typename PositionMap, typename WeightMap, typename T,
             bool EdgeOrSideLength>
      bool kamada_kawai_spring_layout(const Graph & g, PositionMap position,
                                      WeightMap weight,
                                      const Topology& space,
                                      unspecified edge_or_side_length);

## Where Defined

boost/graph/kamada_kawai_spring_layout.hpp

## Description

This algorithm [57] performs graph layout (in two dimensions) for connected, undirected graphs. It operates by relating the layout of graphs to a dynamic spring system and minimizing the energy within that system. The strength of a spring between two vertices is inversely proportional to the square of the shortest distance (in graph terms) between those two vertices. Essentially, vertices that are closer in the graph-theoretic sense (i.e., by following edges) will have stronger springs and will therefore be placed closer together.

Prior to invoking this algorithm, it is recommended that the vertices be placed along the vertices of a regular n-sided polygon via `circle_layout`.

Returns: `true` if layout was successful or `false` if a negative weight cycle was detected or the graph is disconnected.

## Parameters

IN: `const Graph& g`

> The graph, whose type `Graph` must model the VertexListGraph, EdgeListGraph, and IncidenceGraph concepts. The graph must be undirected and connected.
> Python: This parameter is named `graph` in Python.

OUT: `PositionMap position`

> This property map is used to store the position of each vertex. The type `PositionMap` must be a model of Writable Property Map, with the graph's vertex descriptor type as its key type and `Topology::point_type` as its value type.
> Python: The position map must be a `vertex_point2d_map` for the graph.
> Python default: `graph.get_vertex_point2d_map("position")`

IN: `weight_map(WeightMap w_map)`

> The weight or ``length'' of each edge in the graph. The weights must all be non-negative, and the algorithm will throw a `negative_edge` exception is one of the edges is negative. The type `WeightMap` must be a model of Readable Property Map. The edge descriptor type of the graph needs to be usable as the key type for the weight map. The value type for this map must be the same as the value type of the distance map.
> Default: `get(edge_weight, g)`
> Python: Must be an `edge_double_map` for the graph.
> Python default: `graph.get_edge_double_map("weight")`

IN: `const Topology& space`

> The topology used to lay out the vertices. This parameter describes both the size and shape of the layout area, as well as its dimensionality; up to three dimensions are supported by the current implementation. Topologies are described in more detail (with a list of BGL-provided topologies) in separate documentation.

IN: `EdgeOrSideLength edge_or_side_length`

> Provides either the unit length `e` of an edge in the layout or the length of a side `s` of the display area, and must be either `boost::edge_length(e)` or `boost::side_length(s)` , respectively. Python: In Python, this value always refers to the side length and may only be a `double`.

IN: `Done done`

> A 4-argument function object that is passed the current value of delta_p (i.e., the energy of vertex `p` ), the vertex `p` , the graph `g` , and a boolean flag indicating whether `delta_p` is the maximum energy in the system (when `true` ) or the energy of the vertex being moved. Default: `layout_tolerance` instantiated over the value type of the weight map.
> Python: Any callable Python object with an appropriate signature suffices.

IN: `typename property_traits<WeightMap>::value_type spring_constant`

> The constant multiplied by each spring's strength. Larger values create systems with more energy that can take longer to stabilize; smaller values create systems with less energy that stabilize quickly but do not necessarily result in pleasing layouts.
> Default: 1.

IN: `VertexIndexMap index`

> As a mapping from vertices to index values between 0 and `num_vertices(g)` .
> Default:`get(vertex_index,g)`. Note: if you use this default, make sure your graph has an internal `vertex_index` property. For example, `adjacenty_list` with `VertexList=listS` does not have an internal `vertex_index` property.
> Python: Unsupported parameter.

UTIL/OUT: `DistanceMap distance`

> This parameter will be used to store the distance from every vertex to every other vertex, which is computed in the first stages of the algorithm. This value's type must be a model of `BasicMatrix` with value type equal to the value type of the weight map.
> Default: A vector of vectors.
> Python: Unsupported parameter.

UTIL/OUT: `SpringStrengthMatrix spring_strength`

> This matrix will be used to store the strength of the spring between every pair of vertices. This value's type must be a model of BasicMatrix with value type equal to the value type of the weight map.
> Default: A vector of vectors of the value type of the weight map.
> Python: Unsupported parameter.

UTIL: `PartialDerivativeMap partial_derivatives`

> A property map that will be used to store the partial derivatives of each vertex with respect to the vertex's current coordinates. coordinates. This must be a Read/Write Property Map whose value type is `Topology::point_difference_type`. The default is an iterator property map built using the graph's vertex index map.
> Default: An `iterator_property_map` created from an `std::vector` of `Topology::point_difference_type`.
> Python: Unsupported parameter.

Python IN: `bool progressive`

> When `false`, performs layout of the graph on a circle before running the Kamada-Kawai algorithm. If `true`, the algorithm is executing starting with the vertex configuration in the `position` map.
> Default: `False`.

Copyright © 2004, 2010 Trustees of Indiana University | Douglas Gregor, Indiana University (dgregor -at cs.indiana.edu) Andrew Lumsdaine, Indiana University (lums@osl.iu.edu)