1 #ifndef GL_LAPLACIAN_STL_HPP
2 #define GL_LAPLACIAN_STL_HPP
4 #include "../structures/Graph.hpp"
15 #ifndef DOXYGEN_SHOULD_SKIP_THIS
16 template <
class S,
class STORAGE,
class DIR, GL_ENABLE_IF_DIRECTED_T>
18 #ifdef DOXYGEN_SHOULD_SKIP_THIS
19 template <
class class SCALAR,
class STORAGE_KIND,
class DIRECTION>
23 using matrix_t = std::vector<float>;
25 matrix_t matrix (numNodes*numNodes,0);
36 matrix[it->source()*numNodes+it->dest()] -= 1;
42 #ifndef DOXYGEN_SHOULD_SKIP_THIS
43 template <
class S,
class STORAGE,
class DIR, GL_ENABLE_IF_MATRIX_UNDIRECTED_T>
46 using matrix_t = std::vector<float>;
48 matrix_t matrix (numNodes*numNodes,0);
59 matrix[it->source()*numNodes+it->dest()] -= 1;
60 matrix[it->dest()*numNodes+it->source()] -= 1;
66 template <
class S,
class STORAGE,
class DIR, GL_ENABLE_IF_LIST_UNDIRECTED_T>
67 std::vector<float>
LaplacianSTL(
const Graph<S,STORAGE,DIR>& g)
69 using matrix_t = std::vector<float>;
70 auto numNodes = g.numNodes();
71 matrix_t matrix (numNodes*numNodes,0);
74 for (
typename Graph<S,STORAGE,DIR>::idx_t i = 0; i < numNodes; i++)
76 matrix[i*numNodes+i] = g.getNodeOutDegree(i);
80 for (
auto it = g.edge_cbegin(); it != g.edge_cend(); it++)
82 matrix[it->source()*numNodes+it->dest()] -= 1;
87 #endif // DOXYGEN_SHOULD_SKIP_THIS
93 #endif // GL_LAPLACIAN_STL_HPP
ConstEdgeIterator edge_cbegin() const
ConstEdgeIterator to the first edge.
Definition: Graph.hpp:967
gl::index_type idx_t
Index type.
Definition: Graph.hpp:44
Stores and implements a Graph.
Definition: Graph.hpp:39
idx_t getNodeOutDegree(const idx_t &id) const
Gets the in-degree of a node (i.e. count of all outgoing edges).
Definition: Graph.hpp:1316
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
ConstEdgeIterator edge_cend() const
ConstEdgeIterator to the last edge.
Definition: Graph.hpp:989
idx_t numNodes() const
Returns the number of nodes currently in the graph.
Definition: Graph.hpp:406