GraphLibrary  0.0.1
A simple library that implements various graph algorithms.
 All Classes Namespaces Files Functions Variables Typedefs Macros
SpectralPlacing.hpp
Go to the documentation of this file.
1 #ifndef SPECTRAL_PLACING_HPP
2 #define SPECTRAL_PLACING_HPP
3 
4 #include "../structures/Graph.hpp"
6 #include "LaplacianSTL.hpp"
7 
8 namespace gl
9 {
10 namespace algorithm
11 {
12 
17 template <class Graph>
19 {
20  // compute graph laplacian matrix
21  auto laplacian = gl::algorithm::LaplacianSTL(g);
22  // compute x/y positions
23  auto pos = gl::algorithm::PositionsFromLaplacian(laplacian);
24 
25  for (typename Graph::idx_t i = 0; i < g.numNodes(); ++i)
26  {
27  g.updateNode(i, std::make_pair(pos.first[i], pos.second[i]));
28  }
29 }
30 
31 } // namespace algorithm
32 } // namespace gl
33 
34 #endif
std::pair< std::vector< float >, std::vector< float > > PositionsFromLaplacian(std::vector< float > laplacian, double factor=5.0)
Compute Positions from Laplacian using BLAS routine.
Definition: PositionsFromLaplacian.hpp:26
gl::index_type idx_t
Index type.
Definition: Graph.hpp:44
Stores and implements a Graph.
Definition: Graph.hpp:39
std::vector< float > LaplacianSTL(const Graph< S, STORAGE, DIR > &g)
Compute the Laplacian Matrix of a graph in an STL vector.
Definition: LaplacianSTL.hpp:21
idx_t numNodes() const
Returns the number of nodes currently in the graph.
Definition: Graph.hpp:406
void SpectralPlacing(Graph &g)
Compute node 2D positions using spectral placing.
Definition: SpectralPlacing.hpp:18
void updateNode(const idx_t &id, const std::string &label, const val_t &capacity, const gl::Color &color, const std::pair< float, float > &position)
Updates node properties. Parameter "id" mandatory, the rest optional.
Definition: Graph.hpp:1200